How to change texture of 3d model at runtime #510
-
Please let us know how to change texture of 3d model at runtime, in sceneform we use this code to change texture at runtime : ` public void LoadTexture(Context context, Bitmap colorImageBitmap) {
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I solved it as follows private fun createTextureFromBitmap(engine: Engine, bitmap: Bitmap): Texture {
val texture = Texture.Builder()
.width(bitmap.width)
.height(bitmap.height)
.levels(1)
.sampler(Texture.Sampler.SAMPLER_2D)
.format(Texture.InternalFormat.SRGB8_A8)
.build(engine)
val buffer = ByteBuffer.allocateDirect(bitmap.byteCount)
bitmap.copyPixelsToBuffer(buffer)
buffer.flip()
texture.setImage(
engine, 0, Texture.PixelBufferDescriptor(
buffer,
Texture.Format.RGBA,
Texture.Type.UBYTE
)
)
buffer.clear()
return texture
}
texture = createTextureFromBitmap(engine, bitmap)
(modelNodes[0] as ModelNode).materialInstances[0][0] = setBaseColorMap(texture) |
Beta Was this translation helpful? Give feedback.
I solved it as follows