SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
758 stars 151 forks source link

Fix ModelNode hierarchy #443

Closed aleyooop closed 3 months ago

aleyooop commented 3 months ago

Right now, ModelNode completely ignores entities without components, but these are often used to maintain specific scene hierarchy. That means files that use empty nodes to compensate transforms (like Sketchfab models) are not rendered correctly. This fix adds such nodes to the hierarchy and maintains any relative transforms. That was in place in the SceneView 2.0.0 implementation but, for some reason, was dropped in the new one.

init {
    // We use allChildEntities instead of entities because of this:
    // https://github.com/google/filament/discussions/6113
    nodes = entities.map { childEntity ->
        when {
            engine.renderableManager.hasComponent(childEntity) -> RenderableNode(
                engine,
                nodeManager,
                modelInstance,
                childEntity
            )
            engine.lightManager.hasComponent(childEntity) -> LightNode(
                engine,
                nodeManager,
                modelInstance,
                childEntity
            )
            engine.getCameraComponent(childEntity) != null -> CameraNode(
                engine,
                nodeManager,
                modelInstance,
                childEntity
            )
            else -> ChildNode(engine, nodeManager, modelInstance, childEntity)
        }
    }
}