libgdx changing the texture on a pre textured model

心已入冬 提交于 2020-01-16 03:27:25

问题


I've exported a model from blender but I want some instances to use a different texture

       if (x % 2 == 0) {
            shipInstance.materials.clear();
            shipInstance.materials.add(new Material());
            shipInstance.materials.get(0).set(new TextureAttribute(TextureAttribute.Diffuse, enemyTexture));

unfortunately doesn't work!

In a similar way I want to be able to change things like shininess and smoothing (I'm guessing you can change things like this that are using the default shader?)

I've also (later) tried this...

Material mat = shipInstance.materials.get(m);
for (Iterator<Attribute> ai = mat.iterator(); ai.hasNext();){
    Attribute att=ai.next();
    if (att.type==TextureAttribute.Diffuse) {
       ((TextureAttribute)att).textureDescription.set(enemyTexture,TextureFilter.Linear,TextureFilter.Linear,TextureWrap.ClampToEdge,TextureWrap.ClampToEdge);
    }
}

amongst other things...


回答1:


argh!

for(int m=0;m<shipInstance.materials.size;m++) {
    Material mat = shipInstance.materials.get(m);
    for (Iterator<Attribute> ai = mat.iterator(); ai.hasNext();){
        Attribute att=ai.next();                        
        if (att.type==TextureAttribute.Diffuse) {
            ((TextureAttribute)att).textureDescription.set(enemyTexture,TextureFilter.Linear,TextureFilter.Linear,TextureWrap.ClampToEdge,TextureWrap.ClampToEdge);
        }
    }
}

My mistake was to subtract 1 from materials.size !!! (the last material in the model happened to be the most obvious one, it was in many cases when I tried different things probably working (accept for the last material) DoH!!!



来源:https://stackoverflow.com/questions/23634804/libgdx-changing-the-texture-on-a-pre-textured-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!