Skip to content

3D model not rendering correctly when applying texture in SceneView (Jetpack Compose Kotlin) #634

@rayan332

Description

@rayan332

I am using Jetpack Compose Kotlin with SceneView (implementation("io.github.sceneview:sceneview:2.3.0")). I am running on a physical device. If I load the 3D model without its texture, it displays correctly. But when I load it with the texture, the model does not render properly, even though the 3D model itself is completely clean and without issues. It seems there is a problem in the library.

Image Image Image Image

my Code :

// Filament 3D Engine
val engine = rememberEngine()

// Asset loaders
val modelLoader = rememberModelLoader(engine)
val materialLoader = rememberMaterialLoader(engine)
val environmentLoader = rememberEnvironmentLoader(engine)
val view = rememberView(engine)

// Créer la texture avec le bitmap inversé
val TexturePSG = ImageTexture.Builder()
.bitmap(
MainActivity.instance.assets.open(
"texture/texture.png"
).readBytes().decodeToImageBitmap().asAndroidBitmap()
)
.build(engine)

Scene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,

    // Core rendering components
    view = view,
    renderer = rememberRenderer(engine),
    scene = rememberScene(engine),

    // Asset loaders
    modelLoader = modelLoader,
    materialLoader = materialLoader,
    environmentLoader = environmentLoader,

    // Collision System
    collisionSystem = rememberCollisionSystem(view) ,

            // Add a direct light source (required for shadows)
    mainLightNode = rememberMainLightNode(engine) { intensity = 100_000.0f },

    // Set up environment lighting and skybox from an HDR file
    environment = rememberEnvironment(environmentLoader) {
        environmentLoader.createHDREnvironment(
            assetFileLocation = "environments/sky.hdr"
        )!!
    },

    // Configure camera position
    cameraNode = rememberCameraNode(engine) {
        position = Position(z = 4.0f)
    },

    // Enable user interaction with the camera
    cameraManipulator = rememberCameraManipulator(),

    // Add 3D models and objects to the scene
    childNodes = rememberNodes {
        // Add a glTF model
        add(
            ModelNode(
                // Create a single instance model from assets file
                modelInstance = modelLoader.createModelInstance(
                    assetFileLocation = "Tshert/a.glb"
                ),
                // Make the model fit into a 1 unit cube
                scaleToUnits = 1.0f
            ).apply {
                // Define the Texture
                this.setMaterialInstance(
                    materialInstance = materialLoader.createTextureInstance(
                        texture = TexturePSG
                    )
                )

            }
        )


    },


)

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions