-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework node3d graph and gltf loading to optimize model reuse and inst…
…ancing
- Loading branch information
Showing
17 changed files
with
311 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
276 changes: 153 additions & 123 deletions
276
core/src/commonMain/kotlin/com/littlekt/file/gltf/GltfModelGenerator.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 1 addition & 22 deletions
23
core/src/commonMain/kotlin/com/littlekt/graphics/g3d/Model.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,7 @@ | ||
package com.littlekt.graphics.g3d | ||
|
||
import com.littlekt.math.Mat4 | ||
|
||
/** | ||
* @author Colton Daily | ||
* @date 11/24/2024 | ||
*/ | ||
open class Model : Node3D() { | ||
val nodes = mutableMapOf<String, Node3D>() | ||
val meshes = mutableMapOf<String, MeshNode>() | ||
val skins = mutableListOf<Skin>() | ||
|
||
val instances = mutableListOf<ModelInstance>() | ||
|
||
fun createModelInstance(): ModelInstance { | ||
val modelInstance = ModelInstance(this) | ||
meshes.values.forEach { mesh -> | ||
val meshInstance = VisualInstance() | ||
meshInstance.globalTransform = Mat4().set(mesh.globalTransform) | ||
mesh.addInstance(meshInstance) | ||
modelInstance += meshInstance | ||
modelInstance.meshInstances += meshInstance | ||
} | ||
instances += modelInstance | ||
return modelInstance | ||
} | ||
} | ||
class Model(val primitives: List<MeshPrimitive>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/commonMain/kotlin/com/littlekt/graphics/g3d/Scene.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.littlekt.graphics.g3d | ||
|
||
/** | ||
* @author Colton Daily | ||
* @date 1/17/2025 | ||
*/ | ||
open class Scene : Node3D() { | ||
var modelInstances = mutableListOf<ModelInstance>() | ||
var skins = mutableListOf<Skin>() | ||
|
||
fun createInstance(): Scene { | ||
val newInstance = Scene() | ||
val newModelInstances = modelInstances.map { it.createInstance() } | ||
newInstance.modelInstances += newModelInstances | ||
newModelInstances.forEach { newInstance += it } | ||
newInstance.skins = skins.toMutableList() | ||
return newInstance | ||
} | ||
} |
Oops, something went wrong.