[英]Programmatically change model texture libgdx
我正在制作一個游戲,我想根據相關數據更改模型上的紋理,但無論我怎樣,只要紋理發生變化,模型就會變得不可見,模型采用 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"
}
]
}
],
這是我最近的嘗試
self.getMaterial("default").clear();
self.getMaterial("default").set(self.getMaterial(extra.getString("item")).get(TextureAttribute.Diffuse));
我已經嘗試了通過在線搜索找到的所有內容,但都遇到了同樣的問題
原來未使用的材料沒有傳遞給模型實例我只需要修改模型然后創建和渲染模型實例
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.