Closed Somendra121 closed 1 month ago
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)
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) { Log.d("LoadTexture", "LoadTexture : @@@@@@@1 renderableInstance.size() : " + renderableInstances.size()); for (RenderableInstance renderableInstance : renderableInstances) { Texture.builder() .setSource(colorImageBitmap) .setSampler( Texture.Sampler.builder() .setWrapMode(Texture.Sampler.WrapMode.REPEAT) .build() ) .build() .thenAccept(texture -> { MaterialFactory.makeOpaqueWithTexture(context, texture) .thenAccept(material -> { material.setFloat("roughness", 0.5f); // Set roughness material.setFloat("ao", 1.0f); // Set AO Log.d("LoadTexture", "LoadTexture :@@@@@@2 renderableInstance.getMaterialsCount() : " + renderableInstance.getMaterialsCount());