Skip to content

Commit 14a2ec5

Browse files
committed
md5 first test ok
1 parent 26bfb18 commit 14a2ec5

File tree

4 files changed

+151
-17
lines changed

4 files changed

+151
-17
lines changed

src/main/kotlin/assimp/format/md5/MD5Loader.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,36 +253,22 @@ class MD5Importer : BaseImporter() {
253253
boneSrc.rotationQuat convertTo boneSrc.rotationQuatConverted
254254
}
255255

256-
fun AiQuaternion.rotate(v: AiVector3D): AiVector3D {
257-
val q2 = AiQuaternion(0f, v)
258-
val qinv = AiQuaternion(this).apply { conjugate_() }
259-
260-
times_(q2).times_(qinv)
261-
return AiVector3D(x, y, z)
262-
}
263-
264256
var pvi = 0
265257
for (it in src.vertices) {
266258
// compute the final vertex position from all single weights
267259
val pv = AiVector3D()
268260
mesh.vertices.add(pv)
269261
// there are models which have weights which don't sum to 1 ...
270262
var sum = 0f
271-
var jub = it.firstWeight
272-
var w = jub
273-
while (w < jub + it.numWeights) {
263+
for(w in it.firstWeight until it.firstWeight + it.numWeights)
274264
sum += src.weights[w].weight
275-
++w
276-
}
277265
if (sum == 0f) {
278266
logger.error { "MD5MESH: The sum of all vertex bone weights is 0" }
279267
continue
280268
}
281269

282270
// process bone weights
283-
jub = it.firstWeight
284-
w = jub
285-
while (w < jub + it.numWeights) {
271+
for(w in it.firstWeight until it.firstWeight + it.numWeights) {
286272
if (w >= src.weights.size) throw Error("MD5MESH: Invalid weight index")
287273

288274
val desc = src.weights[w]
@@ -299,7 +285,6 @@ class MD5Importer : BaseImporter() {
299285

300286
val bone = mesh.bones[boneSrc.map]
301287
bone.weights.add(AiVertexWeight(pvi, newWeight))
302-
++w
303288
}
304289
pvi++
305290
}
@@ -344,6 +329,14 @@ TODO()
344329
}
345330
}
346331

332+
fun AiQuaternion.rotate(v: AiVector3D): AiVector3D {
333+
val q2 = AiQuaternion(0f, v)
334+
val qinv = AiQuaternion(this).apply { conjugate_() }
335+
336+
val q = times(q2).times_(qinv)
337+
return AiVector3D(q.x, q.y, q.z)
338+
}
339+
347340
/** Load a *.MD5ANIM file. */
348341
fun loadMD5AnimFile() {
349342
val file = file + "md5anim"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package assimp.md5
2+
3+
import assimp.AiShadingMode
4+
import assimp.AiTexture
5+
import assimp.Importer
6+
import glm_.mat4x4.Mat4
7+
import glm_.vec3.Vec3
8+
import io.kotlintest.matchers.shouldBe
9+
10+
object boarMan {
11+
12+
operator fun invoke(fileName: String) {
13+
14+
with(Importer().readFile(fileName)!!) {
15+
16+
flags shouldBe 0
17+
18+
// with(rootNode) {
19+
// name shouldBe "<MD5_Root>"
20+
// transformation shouldBe Mat4(
21+
// 1f, 0f, 0f, 0f,
22+
// 0f, 0f, -1f, 0f,
23+
// 0f, 1f, 0f, 0f,
24+
// 0f, 0f, 0f, 1f)
25+
// parent shouldBe null
26+
// numChildren shouldBe 2
27+
//
28+
// with(children[0]) {
29+
// name shouldBe "<MD5_Mesh>"
30+
// transformation shouldBe Mat4()
31+
// (parent === rootNode) shouldBe true
32+
// numChildren shouldBe 0
33+
//
34+
// numMeshes shouldBe 1
35+
// meshes[0] shouldBe 0
36+
// }
37+
//
38+
// with(children[1]) {
39+
// name shouldBe "<MD5_Hierarchy>"
40+
// transformation shouldBe Mat4()
41+
// (parent === rootNode) shouldBe true
42+
// numChildren shouldBe 1
43+
//
44+
// with(children[0]) {
45+
// name shouldBe "origin"
46+
// transformation shouldBe Mat4()
47+
// (parent === rootNode.children[1]) shouldBe true
48+
// numChildren shouldBe 1
49+
//
50+
// with(children[0]) {
51+
// name shouldBe "root"
52+
// transformation shouldBe Mat4(
53+
// 0.000780999660f, 1.78813934e-07f, 0.999999702f, 0.000000000f,
54+
// -0.999999702f, 1.19209290e-07f, 0.000781029463f, 0.000000000f,
55+
// -1.78813934e-07f, -1.00000000f, 1.19209290e-07f, 0.000000000f,
56+
// 0.000000000f, 0.000000000f, 0.000000000f, 1.00000000f)
57+
// (parent === rootNode.children[1].children[0]) shouldBe true
58+
// numChildren shouldBe 1
59+
//
60+
// with(children[0]) {
61+
// name shouldBe "joint1"
62+
// transformation shouldBe Mat4(
63+
// 0.000781089126f, -0.999999702f, -2.96912894e-08f, 0.000000000f,
64+
// 0.999999642f, 0.000781059265f, 1.19302342e-07f, 0.000000000f,
65+
// -5.95347665e-08f, -8.94821568e-08f, 0.999999940f, 0.000000000f,
66+
// 31.9803429f, 3.81097198e-06f, 3.81233167e-06f, 1.00000000f)
67+
// (parent === rootNode.children[1].children[0].children[0]) shouldBe true
68+
// numChildren shouldBe 0
69+
// numMeshes shouldBe 0
70+
// }
71+
//
72+
// numMeshes shouldBe 0
73+
// }
74+
//
75+
// numMeshes shouldBe 0
76+
// }
77+
//
78+
// numMeshes shouldBe 0
79+
// }
80+
//
81+
// numMeshes shouldBe 0
82+
// }
83+
//
84+
// with(meshes[0]) {
85+
//
86+
// primitiveTypes shouldBe 4
87+
// numVertices shouldBe 36
88+
// numFaces shouldBe 12
89+
//
90+
// vertices[0] shouldBe Vec3(32.0000038f, 31.9999943f,-32.0000153f)
91+
// vertices[5] shouldBe Vec3(-32.0000000f, -31.9999924f, 32.0000038f)
92+
// vertices[11] shouldBe Vec3(31.9999981f, -32.0000000f, 32.0000000f)
93+
//
94+
// textureCoords[0][0][0] shouldBe 0.187500000f
95+
// textureCoords[0][0][1] shouldBe 1.25000000f
96+
// textureCoords[0][5][0] shouldBe -0.312500000f
97+
// textureCoords[0][5][1] shouldBe 1.25000000f
98+
// textureCoords[0][11][0] shouldBe 0.250000000f
99+
// textureCoords[0][11][1] shouldBe 1.50000000f
100+
//
101+
// faces[0] shouldBe mutableListOf(0, 1, 2)
102+
// faces[5] shouldBe mutableListOf(11, 29, 28)
103+
// faces[11] shouldBe mutableListOf(23, 35, 34)
104+
//
105+
// name.isEmpty() shouldBe true
106+
// }
107+
//
108+
// numMaterials shouldBe 1
109+
//
110+
// with(materials[0]) {
111+
// textures[0].file shouldBe ""
112+
// }
113+
}
114+
}
115+
}

src/test/kotlin/assimp/md5/md5.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import io.kotlintest.specs.StringSpec
1111
class md5 : StringSpec() {
1212

1313
val path = models + "/MD5/"
14+
val path_ = modelsNonBsd + "/MD5/"
1415

1516
init {
1617
"simple cube" { simpleCube(path + "SimpleCube.md5mesh") }
18+
"boar man" { boarMan(path_ + "BoarMan.md5mesh") }
1719
}
1820
}

src/test/kotlin/assimp/md5/simpleCube.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ object simpleCube {
8181
numMeshes shouldBe 0
8282
}
8383

84+
with(meshes[0]) {
85+
86+
primitiveTypes shouldBe 4
87+
numVertices shouldBe 36
88+
numFaces shouldBe 12
89+
90+
vertices[0] shouldBe Vec3(32.0000038f, 31.9999943f,-32.0000153f)
91+
vertices[5] shouldBe Vec3(-32.0000000f, -31.9999924f, 32.0000038f)
92+
vertices[11] shouldBe Vec3(31.9999981f, -32.0000000f, 32.0000000f)
93+
94+
textureCoords[0][0][0] shouldBe 0.187500000f
95+
textureCoords[0][0][1] shouldBe 1.25000000f
96+
textureCoords[0][5][0] shouldBe -0.312500000f
97+
textureCoords[0][5][1] shouldBe 1.25000000f
98+
textureCoords[0][11][0] shouldBe 0.250000000f
99+
textureCoords[0][11][1] shouldBe 1.50000000f
100+
101+
faces[0] shouldBe mutableListOf(0, 1, 2)
102+
faces[5] shouldBe mutableListOf(11, 29, 28)
103+
faces[11] shouldBe mutableListOf(23, 35, 34)
104+
105+
name.isEmpty() shouldBe true
106+
}
107+
84108
numMaterials shouldBe 1
85109

86110
with(materials[0]) {

0 commit comments

Comments
 (0)