Skip to content

Commit

Permalink
fixed collada light bug loading
Browse files Browse the repository at this point in the history
  • Loading branch information
elect86 committed May 11, 2018
1 parent 3a6c0d3 commit 11c9504
Show file tree
Hide file tree
Showing 8 changed files with 783 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/assimp/format/collada/ColladaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class ColladaParser(pFile: IOStream) {
if (event is StartElement) {
if (element.name_ == "light") {
// read ID. By now you probably know my opinion about this "specification"
val id = element["light"]!!
val id = element["id"]!!
val light = Light() // create an entry and store it in the library under its ID
mLightLibrary[id] = Light()
readLight(light)
Expand Down
13 changes: 7 additions & 6 deletions src/test/kotlin/assimp/collada/collada.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class collada : StringSpec() {
val path = "$models/Collada/"

init {
"anims full rot" { animFullRot(getResource("$path/anims_with_full_rotations_between_keys.DAE")) }
"cameras" { cameras(getResource("$path/cameras.dae")) }
"concave poly" { concavePoly(getResource("$path/ConcavePolygon.dae")) }
"treasure smooth" { treasure_smooth(getResource("$path/treasure_smooth.dae")) }
"treasure smooth Pretransform" { `treasure_smooth Pretransform`(getResource("$path/treasure_smooth.dae")) }
"color teapot spheres" { `color teapot spheres`(getResource("$path/color_teapot_spheres.dae")) }
// "anims full rot" { animFullRot(getResource("$path/anims_with_full_rotations_between_keys.DAE")) }
// "cameras" { cameras(getResource("$path/cameras.dae")) }
// "concave poly" { concavePoly(getResource("$path/ConcavePolygon.dae")) }
// "treasure smooth" { treasure_smooth(getResource("$path/treasure_smooth.dae")) }
// "treasure smooth Pretransform" { `treasure_smooth Pretransform`(getResource("$path/treasure_smooth.dae")) }
// "color teapot spheres" { `color teapot spheres`(getResource("$path/color_teapot_spheres.dae")) }
"color teapot spheres" { voyager(getResource("$path/voyager/voyager.dae")) }
}
}
290 changes: 290 additions & 0 deletions src/test/kotlin/assimp/collada/voyager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
package assimp.collada

import assimp.AiAnimBehaviour
import assimp.Importer
import glm_.mat4x4.Mat4
import glm_.quat.Quat
import glm_.vec3.Vec3
import io.kotlintest.shouldBe
import java.net.URL

object voyager {

operator fun invoke(url: URL) {

with(Importer().readFile(url)!!) {

flags shouldBe 0

// with(rootNode) {
// name shouldBe "Array Test 001"
// transformation shouldBe Mat4(
// 1f, 0f, 0f, 0f,
// 0f, 0f, -1f, 0f,
// 0f, 1f, 0f, 0f,
// 0f, 0f, 0f, 1f)
// parent shouldBe null
// numChildren shouldBe 1
//
// with(children[0]) {
// name shouldBe "Box001"
// transformation shouldBe Mat4(
// 1f, 5.235988e-08f, 0f, 0f,
// -5.235988e-08f, 1f, 0f, 0f,
// 0f, 0f, 1f, 0f,
// 0f, 0f, 0f, 1f)
// (parent === rootNode) shouldBe true
// numChildren shouldBe 2
//
// with(children[0]) {
// name shouldBe "Box001-Pivot"
// transformation shouldBe Mat4(
// 1f, 0f, 0f, 0f,
// 0f, 1f, 0f, 0f,
// 0f, 0f, 1f, 0f,
// 0.185947001f, 0f, 0f, 1f)
// (parent === rootNode.children[0]) shouldBe true
// numChildren shouldBe 0
//
// numMeshes shouldBe 1
// meshes[0] shouldBe 0
// metaData.isEmpty() shouldBe true
// }
//
// with(children[1]) {
// name shouldBe "Box002"
// transformation shouldBe Mat4(
// 1f, 5.235988e-08f, 0f, 0f,
// -5.235988e-08f, 1f, 0f, 0f,
// 0f, 0f, 1f, 0f,
// 0f, 0f, 0f, 1f)
// (parent === rootNode.children[0]) shouldBe true
// numChildren shouldBe 2
//
// with(children[0]) {
// name shouldBe "Box002-Pivot"
// transformation shouldBe Mat4(
// 1f, 0f, 0f, 0f,
// 0f, 1f, 0f, 0f,
// 0f, 0f, 1f, 0f,
// 0.185947001f, 1.89182305f, 0f, 1f)
// (parent === rootNode.children[0].children[1]) shouldBe true
// numChildren shouldBe 0
//
// numMeshes shouldBe 1
// meshes[0] shouldBe 1
// metaData.isEmpty() shouldBe true
// }
//
// with(children[1]) {
// name shouldBe "Box003"
// transformation shouldBe Mat4(
// 1f, 5.235988e-08f, 0f, 0f,
// -5.235988e-08f, 1f, 0f, 0f,
// 0f, 0f, 1f, 0f,
// 0f, 0f, 0f, 1f)
// (parent === rootNode.children[0].children[1]) shouldBe true
// numChildren shouldBe 2
//
// // TODO continue?
//
// numMeshes shouldBe 0
// meshes.isEmpty() shouldBe true
// metaData.isEmpty() shouldBe true
// }
//
// numMeshes shouldBe 0
// meshes.isEmpty() shouldBe true
// metaData.isEmpty() shouldBe true
// }
//
// numMeshes shouldBe 0
// meshes.isEmpty() shouldBe true
// metaData.isEmpty() shouldBe true
// }
// }

numMeshes shouldBe 6

// with(meshes[0]) {
//
// primitiveTypes shouldBe 8
// numVertices shouldBe 24
// numFaces shouldBe 6
//
// vertices[0] shouldBe Vec3(-0.5f, -0.5f, 0f)
// vertices[11] shouldBe Vec3(-0.5f, -0.5f, 1f)
// vertices[23] shouldBe Vec3(-0.5f, 0.5f, 1f)
//
// normals[0] shouldBe Vec3(0f, 0f, -1f)
// normals[11] shouldBe Vec3(0f, -1f, 0f)
// normals[23] shouldBe Vec3(-1f, 0f, 0f)
//
// textureCoords[0][0][0] shouldBe 1f
// textureCoords[0][0][1] shouldBe 0f
// textureCoords[0][11][0] shouldBe 0f
// textureCoords[0][11][1] shouldBe 1f
// textureCoords[0][23][0] shouldBe 0f
// textureCoords[0][23][1] shouldBe 1f
//
// for (i in 0..23 step 4) faces[i / 4] shouldBe mutableListOf(i, i + 1, i + 2, i + 3)
//
// name shouldBe "Box001Mesh"
// }
//
// // for further mesh test, follow this issue, https://github.com/assimp/assimp/issues/1561
//
// numMaterials shouldBe 1
//
// with(materials[0]) {
// color!!.diffuse shouldBe Vec3(0.600000024f)
// name shouldBe "DefaultMaterial"
// }
//
// numAnimations shouldBe 1
//
// with(animations[0]) {
//
// name shouldBe ""
// duration shouldBe 11.966667175292969
// ticksPerSecond shouldBe 1.0
// numChannels shouldBe 64
//
// with(channels[0]!!) {
// nodeName shouldBe "Box001"
// numPositionKeys shouldBe 5
// with(positionKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3()
// }
// with(positionKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3()
// }
// with(positionKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3()
// }
// numRotationKeys shouldBe 5
// with(rotationKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Quat(1f, 0f, 0f, 2.38497613e-08f)
// }
// with(rotationKeys[2]) {
// time shouldBe 6.0
// value shouldBe Quat(2.90066708e-07f, 0f, 0f, 1f)
// }
// with(rotationKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Quat(1f, 0f, 0f, 3.49691106e-07f)
// }
// numScalingKeys shouldBe 5
// with(scalingKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3(1f)
// }
// preState shouldBe AiAnimBehaviour.DEFAULT
// postState shouldBe AiAnimBehaviour.DEFAULT
// }
//
// with(channels[31]!!) {
// nodeName shouldBe "Box032"
// numPositionKeys shouldBe 5
// with(positionKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3()
// }
// with(positionKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3()
// }
// with(positionKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3()
// }
// numRotationKeys shouldBe 5
// with(rotationKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Quat(1f, 0f, 0f, 2.38497613e-08f)
// }
// with(rotationKeys[2]) {
// time shouldBe 6.0
// value shouldBe Quat(2.90066708e-07f, 0f, 0f, 1f)
// }
// with(rotationKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Quat(1f, 0f, 0f, 3.49691106e-07f)
// }
// numScalingKeys shouldBe 5
// with(scalingKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3(1f)
// }
// preState shouldBe AiAnimBehaviour.DEFAULT
// postState shouldBe AiAnimBehaviour.DEFAULT
// }
//
// with(channels[63]!!) {
// nodeName shouldBe "Box064"
// numPositionKeys shouldBe 5
// with(positionKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3()
// }
// with(positionKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3()
// }
// with(positionKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3()
// }
// numRotationKeys shouldBe 5
// with(rotationKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Quat(1f, 0f, 0f, 2.38497613e-08f)
// }
// with(rotationKeys[2]) {
// time shouldBe 6.0
// value shouldBe Quat(2.90066708e-07f, 0f, 0f, 1f)
// }
// with(rotationKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Quat(1f, 0f, 0f, 3.49691106e-07f)
// }
// numScalingKeys shouldBe 5
// with(scalingKeys[0]) {
// time shouldBe 0.033332999795675278
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[2]) {
// time shouldBe 6.0
// value shouldBe Vec3(1f)
// }
// with(scalingKeys[4]) {
// time shouldBe 11.966667175292969
// value shouldBe Vec3(1f)
// }
// preState shouldBe AiAnimBehaviour.DEFAULT
// postState shouldBe AiAnimBehaviour.DEFAULT
// }
// }
}
}
}
1 change: 1 addition & 0 deletions src/test/resources/models/Collada/voyager/copyright.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Model by NASA (http://nasa3d.arc.nasa.gov/models)
Loading

0 comments on commit 11c9504

Please sign in to comment.