Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top