[英]Programmatically change model texture libgdx
I'm making a game and I want to change the texture on a model depending on associated data but no matter what I as soon as the texture should change the model becomes invisible the model is in g3dj format here is the materials portion我正在制作一个游戏,我想根据相关数据更改模型上的纹理,但无论我怎样,只要纹理发生变化,模型就会变得不可见,模型采用 g3dj 格式,这里是材料部分
"materials":[
{
"id":"default",
"diffuse": [0.640000, 0.640000, 0.640000],
},
{
"id":"plant fibre",
"textures":[
{
"id": "Texture.001",
"filename": "graphics/plant fibre.png",
"type": "DIFFUSE"
}
]
},
{
"id":"logs",
"textures":[
{
"id": "Texture.001",
"filename": "graphics/logs.png",
"type": "DIFFUSE"
}
]
}
],
And here is my latest attempt这是我最近的尝试
self.getMaterial("default").clear();
self.getMaterial("default").set(self.getMaterial(extra.getString("item")).get(TextureAttribute.Diffuse));
I have already tried everything I found by searching online and it all had the same problem我已经尝试了通过在线搜索找到的所有内容,但都遇到了同样的问题
Turns out unused materials aren't passed to the modelInstance I just had to modify the model then create and render the modelInstance原来未使用的材料没有传递给模型实例我只需要修改模型然后创建和渲染模型实例
Ps: this always happens I get so fed up with something that I post a question here and then solve the problem within 24 hours Ps:这总是发生我对某些事情感到厌烦所以我在这里发布问题然后在 24 小时内解决问题
// trees
val loader: ObjLoader = ObjLoader()
tree = loader.loadModel(Gdx.files.internal("data/tree2.obj"))
treeInstance = ModelInstance(tree)
for (m in treeInstance!!.materials) {
println("material id: ${m.id}")
m.remove(ColorAttribute.Emissive)
if (m.id == "Leafs" || m.id == "Leafs2") {
m.set(ColorAttribute.createDiffuse(Color.FOREST))
} else {
m.set(ColorAttribute.createDiffuse(Color.BROWN))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.