Skip to content

Commit e8ab968

Browse files
kcoleybghgary
authored andcommitted
Add tests for materials and primitive attributes and lots of improvements
1 parent cdd894c commit e8ab968

32 files changed

+2367
-1919
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ So far, this project covers these requirements, with more to come:
1111
- Materials
1212
- Textures
1313
- Images
14+
- Material Alphas
15+
- Primitive Attributes
16+
- Texture Samplers
1417

1518
## What is the feature roadmap?
1619
Please refer to the [Feature Roadmap](https://github.com/bghgary/glTF-Asset-Generator/issues/63)
@@ -26,13 +29,11 @@ Please refer to the [Feature Roadmap](https://github.com/bghgary/glTF-Asset-Gene
2629

2730
## Where can I find the generated assets?
2831
* The generated assets wil be located in `glTF-Asset-Generator/Source/bin/Debug`, within their own subdirectories
29-
- i.e. Materials, PbrMetallicRoughness, Sampler
32+
- i.e. Materials, PbrMetallicRoughness, Sampler, etc.
3033

3134
* Alternatively, you can locate the pre-generated assets in the [generated-assets](https://github.com/bghgary/glTF-Asset-Generator/tree/generated-assets) branch
3235

3336

3437

3538

3639

37-
38-

Source/AssetGenerator.csproj

+23-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@
4949
<Reference Include="System.Xml" />
5050
</ItemGroup>
5151
<ItemGroup>
52+
<Compile Include="FileHelper.cs" />
53+
<Compile Include="Property.cs" />
5254
<Compile Include="Attributes.cs" />
55+
<Compile Include="ComboHelper.cs" />
5356
<Compile Include="Common.cs" />
5457
<Compile Include="Data.cs" />
58+
<Compile Include="Logs.cs" />
5559
<Compile Include="Program.cs" />
5660
<Compile Include="Properties\AssemblyInfo.cs" />
61+
<Compile Include="Runtime\Asset.cs" />
62+
<Compile Include="Runtime\Extras.cs" />
5763
<Compile Include="Runtime\GLTF.cs" />
5864
<Compile Include="Runtime\Image.cs" />
5965
<Compile Include="Runtime\Material.cs" />
@@ -64,15 +70,29 @@
6470
<Compile Include="Runtime\Sampler.cs" />
6571
<Compile Include="Runtime\Scene.cs" />
6672
<Compile Include="Runtime\Texture.cs" />
67-
<Compile Include="TestValues.cs" />
73+
<Compile Include="LogStringHelper.cs" />
74+
<Compile Include="Tests\Material.cs" />
75+
<Compile Include="Tests\Material_Alpha.cs" />
76+
<Compile Include="Tests\Material_MetallicRoughness.cs" />
77+
<Compile Include="Tests\Primitive_Attribute.cs" />
78+
<Compile Include="Tests\Texture_Sampler.cs" />
79+
<Compile Include="Test.cs" />
6880
</ItemGroup>
6981
<ItemGroup>
7082
<None Include="App.config" />
7183
<None Include="packages.config" />
7284
</ItemGroup>
73-
<ItemGroup />
7485
<ItemGroup>
75-
<Content Include="ImageDependencies\UVmap2017.png">
86+
<Content Include="ImageDependencies\lambert2_baseColor.png">
87+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
88+
</Content>
89+
<Content Include="ImageDependencies\lambert2_emissive.png">
90+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
91+
</Content>
92+
<Content Include="ImageDependencies\lambert2_normal.png">
93+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
94+
</Content>
95+
<Content Include="ImageDependencies\lambert2_occlusionRoughnessMetallic.png">
7696
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7797
</Content>
7898
</ItemGroup>

Source/AssetGeneratorTests/Runtime/GLTFTests.cs

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public void GLTFTest()
2222
public void BuildGLTFTest()
2323
{
2424
glTFLoader.Schema.Gltf gltf = new glTFLoader.Schema.Gltf();
25+
var asset = new Asset
26+
{
27+
Generator = "Unit Test",
28+
Copyright = "Unit Tester",
29+
};
30+
gltf.Asset = asset.ConvertToAsset();
2531
Data geometryData = new Data("test.bin");
2632
Runtime.GLTF wrapper = new GLTF();
2733
wrapper.BuildGLTF(ref gltf, geometryData);

Source/AssetGeneratorTests/Runtime/MeshPrimitiveTests.cs

+106-44
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ namespace AssetGenerator.Runtime.Tests
1111
[TestClass()]
1212
public class MeshPrimitiveTests
1313
{
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-
3014
[TestMethod()]
3115
public void GetMinMaxPositionsTest()
3216
{
@@ -44,38 +28,85 @@ public void GetMinMaxPositionsTest()
4428
}
4529

4630
[TestMethod()]
47-
public void GetMinMaxTextureCoordsTest()
31+
public void ConvertToMeshPrimitiveTest()
4832
{
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;
6542

6643
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);
6988

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();
72101

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);
75106
}
76107

77108
[TestMethod()]
78-
public void ConvertToMeshPrimitiveTest()
109+
public void IndicesTest()
79110
{
80111
List<glTFLoader.Schema.BufferView> bufferViews = new List<glTFLoader.Schema.BufferView>();
81112
List<glTFLoader.Schema.Accessor> accessors = new List<glTFLoader.Schema.Accessor>();
@@ -85,11 +116,42 @@ public void ConvertToMeshPrimitiveTest()
85116
List<glTFLoader.Schema.Image> images = new List<glTFLoader.Schema.Image>();
86117
glTFLoader.Schema.Buffer buffer = new glTFLoader.Schema.Buffer();
87118
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;
90120

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+
93155
}
94156
}
95157
}

Source/AssetGeneratorTests/Runtime/MeshTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public void ConvertToMeshTest()
3939
Mesh m = new Mesh();
4040

4141
int buffer_index = 0;
42-
int buffer_offset = 0;
4342

44-
m.ConvertToMesh(bufferViews, accessors, samplers, images, textures, materials, geometryData, ref buffer, buffer_index, buffer_offset);
43+
m.ConvertToMesh(bufferViews, accessors, samplers, images, textures, materials, geometryData, ref buffer, buffer_index);
4544
}
4645
}
4746
}

Source/Attributes.cs

+1-27
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,9 @@
33
namespace AssetGenerator
44
{
55
[AttributeUsage(AttributeTargets.Class)]
6-
public class AssetGroupAttribute : Attribute
6+
public class TestAttribute : System.Attribute
77
{
8-
public string Folder { get; private set; }
98

10-
public AssetGroupAttribute(string folder)
11-
{
12-
this.Folder = folder;
13-
}
149
}
1510

16-
[AttributeUsage(AttributeTargets.Method)]
17-
public class AssetAttribute : Attribute
18-
{
19-
public string Name { get; private set; }
20-
21-
public AssetAttribute(string name)
22-
{
23-
this.Name = name;
24-
}
25-
}
26-
27-
[AttributeUsage(AttributeTargets.Method, AllowMultiple =true)]
28-
public class ImageAttribute : Attribute
29-
{
30-
public string Name { get; private set; }
31-
32-
public ImageAttribute(string name)
33-
{
34-
this.Name = name;
35-
}
36-
}
3711
}

0 commit comments

Comments
 (0)