Skip to content

Commit 8178a0b

Browse files
committed
md2 ready
1 parent fa15ee8 commit 8178a0b

File tree

3 files changed

+55
-133
lines changed

3 files changed

+55
-133
lines changed

src/main/kotlin/assimp/format/md2/Md2FileData.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ object MD2 {
153153
* @param index Input index (0-161)
154154
* @return Receives the output normal */
155155
fun lookupNormalIndex(index: Int): AiVector3D {
156-
var i = index * 3
156+
var i = index
157157
if (i >= normals.size / 3) // make sure the normal index has a valid value
158158
i = normals.size / 3 - 1
159159
// flip z and y to become right-handed
160-
return AiVector3D(normals, i).apply { val t = z; z = y; y = t; }
160+
return AiVector3D(normals, i * 3).apply { val t = z; z = y; y = t; }
161161
}
162162

163163
val normals = floatArrayOf(

src/main/kotlin/assimp/format/md2/Md2Loader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class MD2Importer : BaseImporter() {
176176
helper.color = AiMaterial.Color(diffuse = AiColor3D(0.6f), specular = AiColor3D(0.6f), ambient = AiColor3D(0.05f))
177177
helper.name = AI_DEFAULT_MATERIAL_NAME
178178
val fileName = file.name.substringAfterLast('\\').substringBeforeLast('.')
179-
helper.textures.add(AiMaterial.Texture(file = "$fileName.bmp"))
179+
helper.textures.add(AiMaterial.Texture(file = "$fileName.bmp", type = AiTexture.Type.diffuse))
180180
}
181181

182182
// now read all triangles of the first frame, apply scaling and translation

src/test/kotlin/md2/`faerie md2`.kt

Lines changed: 52 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package md2
22

3-
import assimp.AiAnimBehaviour
4-
import assimp.Importer
5-
import assimp.collada
6-
import assimp.md2
3+
import assimp.*
74
import glm_.mat4x4.Mat4
85
import glm_.quat.Quat
96
import glm_.vec3.Vec3
@@ -22,132 +19,57 @@ class `faerie md2` : StringSpec() {
2219
file {
2320
with(Importer().readFile((md2 + file).uri)!!) {
2421

25-
// flags shouldBe 0
26-
//
27-
// with(rootNode) {
28-
// name shouldBe "Array Test 001"
29-
// transformation shouldBe Mat4(
30-
// 1f, 0f, 0f, 0f,
31-
// 0f, 0f, -1f, 0f,
32-
// 0f, 1f, 0f, 0f,
33-
// 0f, 0f, 0f, 1f)
34-
// parent shouldBe null
35-
// numChildren shouldBe 1
36-
//
37-
// with(children[0]) {
38-
// name shouldBe "Box001"
39-
// transformation shouldBe Mat4(
40-
// 1f, 5.235988e-08f, 0f, 0f,
41-
// -5.235988e-08f, 1f, 0f, 0f,
42-
// 0f, 0f, 1f, 0f,
43-
// 0f, 0f, 0f, 1f)
44-
// (parent === rootNode) shouldBe true
45-
// numChildren shouldBe 2
46-
//
47-
// with(children[0]) {
48-
// name shouldBe "Box001-Pivot"
49-
// transformation shouldBe Mat4(
50-
// 1f, 0f, 0f, 0f,
51-
// 0f, 1f, 0f, 0f,
52-
// 0f, 0f, 1f, 0f,
53-
// 0.185947001f, 0f, 0f, 1f)
54-
// (parent === rootNode.children[0]) shouldBe true
55-
// numChildren shouldBe 0
56-
//
57-
// numMeshes shouldBe 1
58-
// meshes[0] shouldBe 0
59-
// metaData shouldBe null
60-
// }
61-
//
62-
// with(children[1]) {
63-
// name shouldBe "Box002"
64-
// transformation shouldBe Mat4(
65-
// 1f, 5.235988e-08f, 0f, 0f,
66-
// -5.235988e-08f, 1f, 0f, 0f,
67-
// 0f, 0f, 1f, 0f,
68-
// 0f, 0f, 0f, 1f)
69-
// (parent === rootNode.children[0]) shouldBe true
70-
// numChildren shouldBe 2
71-
//
72-
// with(children[0]) {
73-
// name shouldBe "Box002-Pivot"
74-
// transformation shouldBe Mat4(
75-
// 1f, 0f, 0f, 0f,
76-
// 0f, 1f, 0f, 0f,
77-
// 0f, 0f, 1f, 0f,
78-
// 0.185947001f, 1.89182305f, 0f, 1f)
79-
// (parent === rootNode.children[0].children[1]) shouldBe true
80-
// numChildren shouldBe 0
81-
//
82-
// numMeshes shouldBe 1
83-
// meshes[0] shouldBe 1
84-
// metaData shouldBe null
85-
// }
86-
//
87-
// with(children[1]) {
88-
// name shouldBe "Box003"
89-
// transformation shouldBe Mat4(
90-
// 1f, 5.235988e-08f, 0f, 0f,
91-
// -5.235988e-08f, 1f, 0f, 0f,
92-
// 0f, 0f, 1f, 0f,
93-
// 0f, 0f, 0f, 1f)
94-
// (parent === rootNode.children[0].children[1]) shouldBe true
95-
// numChildren shouldBe 2
96-
//
97-
// // TODO continue?
98-
//
99-
// numMeshes shouldBe 0
100-
// meshes.isEmpty() shouldBe true
101-
// metaData shouldBe null
102-
// }
103-
//
104-
// numMeshes shouldBe 0
105-
// meshes.isEmpty() shouldBe true
106-
// metaData shouldBe null
107-
// }
108-
//
109-
// numMeshes shouldBe 0
110-
// meshes.isEmpty() shouldBe true
111-
// metaData shouldBe null
112-
// }
113-
// }
114-
//
115-
// numMeshes shouldBe 64
116-
//
117-
// with(meshes[0]) {
118-
//
119-
// primitiveTypes shouldBe 8
120-
// numVertices shouldBe 24
121-
// numFaces shouldBe 6
122-
//
123-
// vertices[0] shouldBe Vec3(-0.5f, -0.5f, 0f)
124-
// vertices[11] shouldBe Vec3(-0.5f, -0.5f, 1f)
125-
// vertices[23] shouldBe Vec3(-0.5f, 0.5f, 1f)
126-
//
127-
// normals[0] shouldBe Vec3(0f, 0f, -1f)
128-
// normals[11] shouldBe Vec3(0f, -1f, 0f)
129-
// normals[23] shouldBe Vec3(-1f, 0f, 0f)
130-
//
131-
// textureCoords[0][0][0] shouldBe 1f
132-
// textureCoords[0][0][1] shouldBe 0f
133-
// textureCoords[0][11][0] shouldBe 0f
134-
// textureCoords[0][11][1] shouldBe 1f
135-
// textureCoords[0][23][0] shouldBe 0f
136-
// textureCoords[0][23][1] shouldBe 1f
137-
//
138-
// for (i in 0..23 step 4) faces[i / 4] shouldBe mutableListOf(i, i + 1, i + 2, i + 3)
139-
//
140-
// name shouldBe "Box001Mesh"
141-
// }
142-
//
143-
// // for further mesh test, follow this issue, https://github.com/assimp/assimp/issues/1561
144-
//
145-
// numMaterials shouldBe 1
146-
//
147-
// with(materials[0]) {
148-
// color!!.diffuse shouldBe Vec3(0.600000024f)
149-
// name shouldBe "DefaultMaterial"
150-
// }
22+
flags shouldBe 0
23+
24+
with(rootNode) {
25+
name.isEmpty() shouldBe true
26+
transformation shouldBe Mat4()
27+
parent shouldBe null
28+
numChildren shouldBe 0
29+
children.isEmpty() shouldBe true
30+
31+
numMeshes shouldBe 1
32+
meshes[0] shouldBe 0
33+
}
34+
35+
with(meshes[0]) {
36+
37+
primitiveTypes shouldBe 4
38+
numVertices shouldBe 1962
39+
numFaces shouldBe 654
40+
41+
vertices[0] shouldBe Vec3(-9.96106529f, 26.6228905f, 6.63490105f)
42+
vertices[980] shouldBe Vec3(-1.92686939f, 13.9874496f, 4.68170929f)
43+
vertices[1961] shouldBe Vec3(-2.08440304f, 3.79757690f, 3.44811630f)
44+
45+
normals[0] shouldBe Vec3(-0.525731027f, 0f, -0.850651026f)
46+
normals[980] shouldBe Vec3(0.262865990f, 0.162459999f, 0.951056004f)
47+
normals[1961] shouldBe Vec3(-0.716566980f, 0.147621006f, 0.681717992f)
48+
49+
textureCoords[0][0][0] shouldBe 0.645454526f
50+
textureCoords[0][0][1] shouldBe 0.766839385f
51+
textureCoords[0][980][0] shouldBe 0.368181825f
52+
textureCoords[0][980][1] shouldBe 0.694300532f
53+
textureCoords[0][1961][0] shouldBe 0.836363614f
54+
textureCoords[0][1961][1] shouldBe 0.502590656f
55+
56+
for (i in 0..653 step 3) faces[i / 3] shouldBe mutableListOf(i, i + 1, i + 2)
57+
58+
name.isEmpty() shouldBe true
59+
}
60+
numMaterials shouldBe 1
61+
62+
with(materials[0]) {
63+
shadingModel shouldBe AiShadingMode.gouraud
64+
with(color!!) {
65+
diffuse shouldBe Vec3(0.600000024f)
66+
specular shouldBe Vec3(0.600000024f)
67+
ambient shouldBe Vec3(0.0500000007)
68+
}
69+
textures[0].type shouldBe AiTexture.Type.diffuse
70+
textures[0].file shouldBe "faerie.bmp"
71+
name shouldBe "DefaultMaterial"
72+
}
15173
//
15274
// numAnimations shouldBe 1
15375
//

0 commit comments

Comments
 (0)