libgdx更改预纹理模型上的纹理 [英] libgdx changing the texture on a pre textured model

查看:150
本文介绍了libgdx更改预纹理模型上的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Blender中导出了一个模型,但是我希望某些实例使用不同的纹理

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);
    }
}

还有其他事情...

推荐答案

啊!

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);
        }
    }
}

我的错误是从material.size中减去1 !!! (模型中的最后一个材料恰好是最明显的材料,在很多情况下,我尝试了可能可行的其他事情(接受了最后一个材料)DoH!

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!!!

这篇关于libgdx更改预纹理模型上的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆