@@ -11,22 +11,6 @@ namespace AssetGenerator.Runtime.Tests
11
11
[ TestClass ( ) ]
12
12
public class MeshPrimitiveTests
13
13
{
14
- [ TestMethod ( ) ]
15
- public void GetMinMaxNormalsTest ( )
16
- {
17
- List < Vector3 > normals = new List < Vector3 >
18
- {
19
- new Vector3 ( 0.0f , 0.0f , 1.0f ) ,
20
- new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
21
- new Vector3 ( 0.0f , 0.0f , - 1.0f )
22
- } ;
23
- MeshPrimitive meshPrim = new MeshPrimitive ( ) ;
24
- meshPrim . Normals = normals ;
25
- Vector3 [ ] minMaxNormals = meshPrim . GetMinMaxNormals ( ) ;
26
- Assert . AreEqual ( new Vector3 ( 0.0f , 0.0f , - 1.0f ) , minMaxNormals [ 0 ] ) ;
27
- Assert . AreEqual ( new Vector3 ( 0.0f , 0.0f , 1.0f ) , minMaxNormals [ 1 ] ) ;
28
- }
29
-
30
14
[ TestMethod ( ) ]
31
15
public void GetMinMaxPositionsTest ( )
32
16
{
@@ -44,38 +28,85 @@ public void GetMinMaxPositionsTest()
44
28
}
45
29
46
30
[ TestMethod ( ) ]
47
- public void GetMinMaxTextureCoordsTest ( )
31
+ public void ConvertToMeshPrimitiveTest ( )
48
32
{
49
- List < List < Vector2 > > triangleTextureCoordSets = new List < List < Vector2 > >
50
- {
51
- new List < Vector2 >
52
- {
53
- new Vector2 ( 0.0f , 1.0f ) ,
54
- new Vector2 ( 0.5f , 1.0f ) ,
55
- new Vector2 ( 0.25f , 0.0f )
56
- } ,
57
- new List < Vector2 >
58
- {
59
- new Vector2 ( 0.5f , 1.0f ) ,
60
- new Vector2 ( 1.0f , 1.0f ) ,
61
- new Vector2 ( 0.75f , 0.0f )
62
- }
63
-
64
- } ;
33
+ List < glTFLoader . Schema . BufferView > bufferViews = new List < glTFLoader . Schema . BufferView > ( ) ;
34
+ List < glTFLoader . Schema . Accessor > accessors = new List < glTFLoader . Schema . Accessor > ( ) ;
35
+ List < glTFLoader . Schema . Texture > textures = new List < glTFLoader . Schema . Texture > ( ) ;
36
+ List < glTFLoader . Schema . Material > materials = new List < glTFLoader . Schema . Material > ( ) ;
37
+ List < glTFLoader . Schema . Sampler > samplers = new List < glTFLoader . Schema . Sampler > ( ) ;
38
+ List < glTFLoader . Schema . Image > images = new List < glTFLoader . Schema . Image > ( ) ;
39
+ glTFLoader . Schema . Buffer buffer = new glTFLoader . Schema . Buffer ( ) ;
40
+ Data geometryData = new Data ( "test.bin" ) ;
41
+ int bufferIndex = 0 ;
65
42
66
43
MeshPrimitive meshPrim = new MeshPrimitive ( ) ;
67
- meshPrim . TextureCoordSets = triangleTextureCoordSets ;
68
- List < Vector2 [ ] > minMaxTextureCoordSets = meshPrim . GetMinMaxTextureCoords ( ) ;
44
+ meshPrim . ConvertToMeshPrimitive ( bufferViews , accessors , samplers , images , textures , materials , geometryData , ref buffer , bufferIndex ) ;
45
+ }
46
+ [ TestMethod ( ) ]
47
+ public void GetMorphTargetsTest ( )
48
+ {
49
+ var positions = new List < Vector3 >
50
+ {
51
+ new Vector3 ( 1.0f , 0.0f , 0.0f ) ,
52
+ new Vector3 ( - 1.0f , 0.0f , 0.0f ) ,
53
+ new Vector3 ( 0.0f , 1.0f , 0.0f ) ,
54
+ } ;
55
+ var positions2 = new List < Vector3 >
56
+ {
57
+ new Vector3 ( 1.0f , 0.0f , 0.0f ) ,
58
+ new Vector3 ( - 1.0f , 0.0f , 0.0f ) ,
59
+ new Vector3 ( 1.0f , 1.0f , 0.0f ) ,
60
+ } ;
61
+ var normals = new List < Vector3 >
62
+ {
63
+ new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
64
+ new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
65
+ new Vector3 ( 0.0f , 0.0f , - 1.0f )
66
+ } ;
67
+ List < glTFLoader . Schema . BufferView > bufferViews = new List < glTFLoader . Schema . BufferView > ( ) ;
68
+ List < glTFLoader . Schema . Accessor > accessors = new List < glTFLoader . Schema . Accessor > ( ) ;
69
+ List < glTFLoader . Schema . Texture > textures = new List < glTFLoader . Schema . Texture > ( ) ;
70
+ List < glTFLoader . Schema . Material > materials = new List < glTFLoader . Schema . Material > ( ) ;
71
+ List < glTFLoader . Schema . Sampler > samplers = new List < glTFLoader . Schema . Sampler > ( ) ;
72
+ List < glTFLoader . Schema . Image > images = new List < glTFLoader . Schema . Image > ( ) ;
73
+ glTFLoader . Schema . Buffer buffer = new glTFLoader . Schema . Buffer ( ) ;
74
+ Data geometryData = new Data ( "test.bin" ) ;
75
+ int bufferIndex = 0 ;
76
+ MeshPrimitive meshPrim = new MeshPrimitive
77
+ {
78
+ Positions = positions ,
79
+ Normals = normals
80
+ } ;
81
+ MeshPrimitive morphTarget = new MeshPrimitive
82
+ {
83
+ Positions = positions2 ,
84
+ Normals = normals
85
+ } ;
86
+ List < MeshPrimitive > morphTargets = new List < MeshPrimitive > ( ) ;
87
+ morphTargets . Add ( morphTarget ) ;
69
88
70
- Assert . AreEqual ( minMaxTextureCoordSets [ 0 ] [ 0 ] , new Vector2 ( 0.0f , 0.0f ) ) ;
71
- Assert . AreEqual ( minMaxTextureCoordSets [ 0 ] [ 1 ] , new Vector2 ( 0.5f , 1.0f ) ) ;
89
+ meshPrim . MorphTargets = morphTargets ;
90
+ meshPrim . morphTargetWeight = 0 ;
91
+ Mesh mesh = new Mesh ( ) ;
92
+ mesh . AddPrimitive ( meshPrim ) ;
93
+ glTFLoader . Schema . Mesh m = mesh . ConvertToMesh ( bufferViews , accessors , samplers , images , textures , materials , geometryData , ref buffer , bufferIndex ) ;
94
+ Assert . IsTrue ( m . Primitives [ 0 ] . Targets . Count ( ) > 0 ) ;
95
+ Assert . IsTrue ( m . Weights . Count ( ) > 0 ) ;
96
+ }
97
+ [ TestMethod ( ) ]
98
+ public void ColorAttributeEnumTest ( )
99
+ {
100
+ MeshPrimitive meshPrimitive = new MeshPrimitive ( ) ;
72
101
73
- Assert . AreEqual ( minMaxTextureCoordSets [ 1 ] [ 0 ] , new Vector2 ( 0.5f , 0.0f ) ) ;
74
- Assert . AreEqual ( minMaxTextureCoordSets [ 1 ] [ 1 ] , new Vector2 ( 1.0f , 1.0f ) ) ;
102
+ meshPrimitive . ColorComponentType = MeshPrimitive . ColorComponentTypeEnum . FLOAT ;
103
+ meshPrimitive . ColorType = MeshPrimitive . ColorTypeEnum . VEC3 ;
104
+ Assert . AreEqual ( meshPrimitive . ColorComponentType , MeshPrimitive . ColorComponentTypeEnum . FLOAT ) ;
105
+ Assert . AreEqual ( meshPrimitive . ColorType , MeshPrimitive . ColorTypeEnum . VEC3 ) ;
75
106
}
76
107
77
108
[ TestMethod ( ) ]
78
- public void ConvertToMeshPrimitiveTest ( )
109
+ public void IndicesTest ( )
79
110
{
80
111
List < glTFLoader . Schema . BufferView > bufferViews = new List < glTFLoader . Schema . BufferView > ( ) ;
81
112
List < glTFLoader . Schema . Accessor > accessors = new List < glTFLoader . Schema . Accessor > ( ) ;
@@ -85,11 +116,42 @@ public void ConvertToMeshPrimitiveTest()
85
116
List < glTFLoader . Schema . Image > images = new List < glTFLoader . Schema . Image > ( ) ;
86
117
glTFLoader . Schema . Buffer buffer = new glTFLoader . Schema . Buffer ( ) ;
87
118
Data geometryData = new Data ( "test.bin" ) ;
88
- int buffer_index = 0 , buffer_offset = 0 ;
89
- glTFLoader . Schema . Buffer bufer = new glTFLoader . Schema . Buffer ( ) ;
119
+ int bufferIndex = 0 ;
90
120
91
- MeshPrimitive meshPrim = new MeshPrimitive ( ) ;
92
- meshPrim . ConvertToMeshPrimitive ( bufferViews , accessors , samplers , images , textures , materials , geometryData , ref buffer , buffer_index , buffer_offset , true , false , false ) ;
121
+ MeshPrimitive meshPrimitive = new MeshPrimitive ( ) ;
122
+ meshPrimitive . Positions = new List < Vector3 >
123
+ {
124
+ new Vector3 ( 0.0f , 0.0f , 0.0f ) ,
125
+ new Vector3 ( - 1.0f , 0.0f , 0.0f ) ,
126
+ new Vector3 ( - 1.0f , 1.0f , 0.0f ) ,
127
+ new Vector3 ( 0.0f , 1.0f , 0.0f )
128
+ } ;
129
+ meshPrimitive . Normals = new List < Vector3 >
130
+ {
131
+ new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
132
+ new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
133
+ new Vector3 ( 0.0f , 0.0f , - 1.0f ) ,
134
+ new Vector3 ( 0.0f , 0.0f , - 1.0f )
135
+ } ;
136
+ meshPrimitive . Indices = new List < int >
137
+ {
138
+ 0 , 1 , 3 , 1 , 2 , 3
139
+ } ;
140
+ meshPrimitive . TextureCoordSets = new List < List < Vector2 > >
141
+ {
142
+ new List < Vector2 >
143
+ {
144
+ new Vector2 ( 0.0f , 1.0f ) ,
145
+ new Vector2 ( 1.0f , 1.0f ) ,
146
+ new Vector2 ( 1.0f , 0.0f ) ,
147
+ new Vector2 ( 0.0f , 0.0f )
148
+ }
149
+ } ;
150
+ glTFLoader . Schema . MeshPrimitive sMeshPrimitive = meshPrimitive . ConvertToMeshPrimitive ( bufferViews , accessors , samplers , images , textures , materials , geometryData , ref buffer , bufferIndex ) ;
151
+ Assert . AreEqual ( sMeshPrimitive . Indices , 2 ) ; // indices is third bufferview, or index 2
152
+ Assert . AreEqual ( accessors [ 2 ] . Count , 6 ) ; // should be siz index values
153
+
154
+
93
155
}
94
156
}
95
157
}
0 commit comments