Texture issues and issues with CloneImportExport

Hi All,



Have looked around on the forum and have tried everything that I can think of.

I have only just started testing adding textures to some models I have been working on but have made a box in blender for testing







left one is using a texture state and the right is using the texture from the actual model file (exporting with hottbj)

Can’t figure out why they are showing up different



also if I try to clone the nodes with CloneImportExport it doesnt show the texture at all unless I apply the texture state and it displays the same as teh left one in the picture. Any ideas?


public synchronized void AddSceneObject(String ModelPath, String fileName, boolean isShared, Vector3f obLoc, Node AttachTo, boolean ShowBackFace, boolean ApplyAlpha, String TexturePath, String TextureName) {
        CheckArray();

        if (ShowBackFace) {
            cs.setCullFace(CullState.Face.None);
            cs.setEnabled(true);
        }

        Node tempNode = null;
        tempNode = (Node) sharedValues.nodeMasterManager.get2(fileName);

        if (tempNode == null) {
            System.out.println(fileName + " was null");
            tempNode = new Node(fileName + "-Master");

            if (fileName.equalsIgnoreCase("TeapotTest")) {
                tempNode.attachChild(new Teapot("testteapot" + SharedSceneObjectCount));
            } else {
                tempNode.attachChild((Node) LoadModel(ModelPath, fileName));
            }
            sharedValues.nodeMasterManager.set(fileName, tempNode);
        }
        if (tempNode == null) {
            //Node model is still null exit method
            return;
        }

        if (TexturePath != null && TextureName != null) {          
            texture = TextureManager.loadTexture(BasicGameState.class.getClassLoader().getResource(TexturePath + TextureName),
                    Texture.MinificationFilter.BilinearNearestMipMap,
                    Texture.MagnificationFilter.Bilinear);

            ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
            ts.setEnabled(true);
            ts.setTexture(texture,0);
        }

        if (isShared) {
            //SharedSceneObject[SharedSceneObjectCount] = new SharedNode(fileName + "-shared-" + SharedSceneObjectCount, tempNode);
            SharedSceneObject[SharedSceneObjectCount] = new SharedNode(fileName + "-shared-" + SharedSceneObjectCount, (Node) sharedValues.nodeMasterManager.get2(fileName));

            SharedSceneObject[SharedSceneObjectCount].setModelBound(new BoundingBox());
            SharedSceneObject[SharedSceneObjectCount].updateModelBound();
            SharedSceneObject[SharedSceneObjectCount].updateWorldBound();
            SharedSceneObject[SharedSceneObjectCount].setLocalTranslation(obLoc);

            if (ShowBackFace) {
                SharedSceneObject[SharedSceneObjectCount].setRenderState(cs);
            }
            if (ApplyAlpha) {
                SharedSceneObject[SharedSceneObjectCount].setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
            } else {
                SharedSceneObject[SharedSceneObjectCount].setRenderQueueMode(Renderer.QUEUE_OPAQUE);
            }

            if (TexturePath != null && TextureName != null && ts != null) {
                SharedSceneObject[SharedSceneObjectCount].setTextureCombineMode(TextureCombineMode.Replace);
                SharedSceneObject[SharedSceneObjectCount].clearRenderState(StateType.Texture);
                SharedSceneObject[SharedSceneObjectCount].setRenderState(ts);
            }
            SharedSceneObject[SharedSceneObjectCount].updateRenderState();
            SharedSceneObject[SharedSceneObjectCount].updateGeometricState(0, true);
            //SharedSceneObject[SharedSceneObjectCount].lockBounds();
            //SharedSceneObject[SharedSceneObjectCount].lockMeshes();
            AttachTo.attachChild(SharedSceneObject[SharedSceneObjectCount]);
            SharedSceneObjectCount++;
        } else {
            //uniqueSceneObject[uniqueSceneObjectCount] = tempNode;
            uniqueSceneObject[uniqueSceneObjectCount] = (Node) sharedValues.nodeMasterManager.getClone(fileName);
            uniqueSceneObject[uniqueSceneObjectCount].setModelBound(new BoundingBox());
            uniqueSceneObject[uniqueSceneObjectCount].updateModelBound();
            uniqueSceneObject[uniqueSceneObjectCount].updateWorldBound();
            uniqueSceneObject[uniqueSceneObjectCount].setLocalTranslation(obLoc);

            if (ShowBackFace) {
                uniqueSceneObject[uniqueSceneObjectCount].setRenderState(cs);
            }
            if (ApplyAlpha) {
                uniqueSceneObject[uniqueSceneObjectCount].setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
            } else {
                uniqueSceneObject[uniqueSceneObjectCount].setRenderQueueMode(Renderer.QUEUE_OPAQUE);
            }

            if (TexturePath != null && TextureName != null && ts != null) {
                uniqueSceneObject[uniqueSceneObjectCount].setTextureCombineMode(TextureCombineMode.Replace);
                uniqueSceneObject[uniqueSceneObjectCount].clearRenderState(StateType.Texture);
                uniqueSceneObject[uniqueSceneObjectCount].setRenderState(ts);
            }
            uniqueSceneObject[uniqueSceneObjectCount].updateRenderState();
            uniqueSceneObject[uniqueSceneObjectCount].updateGeometricState(0, true);
            //uniqueSceneObject[uniqueSceneObjectCount].lockBounds();
            //uniqueSceneObject[uniqueSceneObjectCount].lockMeshes();
            AttachTo.attachChild(uniqueSceneObject[uniqueSceneObjectCount]);
            uniqueSceneObjectCount++;
        }
    }



uniqueSceneObject is just an array of nodes
and SharedSceneObject is an array of SharedNode

NodeMasterManager

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MOTD.sharedlib;

import com.jme.scene.Node;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.RenderState.StateType;
import com.jme.util.CloneConfiguration;
import com.jme.util.CloneImportExport;

/**
 *
 * @author doug.austin
 */
public class NodeMasterManager {

    private CloneImportExport cloner;
    CloneConfiguration cc;
    public boolean setterLocked = false;
    public boolean ClearingList = false;
    int nodeLimit = 0;
    private int MasterCount = 0;
    private Node[] ObjectMaster;
    private String[] ObjectMasterID;

    public NodeMasterManager(int nodeLimit) {
        this.nodeLimit = nodeLimit;
        ClearList();
        cloner = new CloneImportExport();
        //cc = CloneConfiguration.SHARED_GEOM_BUFFER_CLONE;
        //cloner.applyConfiguration(cc);
    }

    public void getLimit() {
    }

    public synchronized void ClearList() {
        ClearingList = true;
        ObjectMaster = new Node[nodeLimit];
        ObjectMasterID = new String[nodeLimit];
        MasterCount = 0;
        ClearingList = false;
    }

    public void set(String fileName, Node node) {
        while (setterLocked && ClearingList) {
            //wait for lock to clear
            System.out.println("NodeMasterManager set blocked");
        }

        setterLocked = true;

        if (get2(fileName) == null) {
            CheckArray();

            if (cloner.saveClone(node)) {
                System.out.println(fileName + " added to master list");
                ObjectMasterID[MasterCount] = fileName;
                ObjectMaster[MasterCount] = (Node) cloner.loadClone();
                ObjectMaster[MasterCount].updateRenderState();
                MasterCount++;
            } else {
                System.out.println(fileName + " failed to add to master list");
            }
            //ObjectMaster[MasterCount] = node;
        }
        setterLocked = false;
    }

    public Node get2(String fileName) {
        while (setterLocked && ClearingList) {
            //wait for lock to clear
            System.out.println("NodeMasterManager get blocked");
        }

        for (int i = 0; i < MasterCount; i++) {
            if (ObjectMaster[i] != null) {
                if (ObjectMasterID[i].equalsIgnoreCase(fileName)) {
                    System.out.println(fileName + " was found in master list");
                    return ObjectMaster[i];
                }
            }
        }
        System.out.println(fileName + " was not found in master list");
        return null;
    }

    public synchronized Node getClone(String fileName) {
        while (setterLocked && ClearingList) {
            //wait for lock to clear
            System.out.println("NodeMasterManager getClone blocked");
        }

        Node tempNode;

        tempNode = get2(fileName);

        if (tempNode != null) {
            if (cloner.saveClone(tempNode)) {
                return (Node) cloner.loadClone();
            }
        }

        System.out.println("Clone is null");
        return null;
    }

    public void CheckArray() {
        if (MasterCount >= ObjectMaster.length) {
            ObjectMaster = expandNodeArray(ObjectMaster, 25);
            ObjectMasterID = expandStringArray(ObjectMasterID, 25);
        }
    }

    public Node[] expandNodeArray(Node[] ToExpand, int ExpandBy) {
        System.out.println("NodeMasterManager expandNodeArray: from " + ToExpand.length + " to " + (ToExpand.length + ExpandBy));

        Node[] TempArray;
        int newlength = (ToExpand.length + ExpandBy);
        TempArray = new Node[newlength];
        System.arraycopy(ToExpand, 0, TempArray, 0, ToExpand.length);
        return TempArray;
    }

    public String[] expandStringArray(String[] ToExpand, int ExpandBy) {
        System.out.println("NodeMasterManager expandStringArray: from " + ToExpand.length + " to " + (ToExpand.length + ExpandBy));

        String[] TempArray;
        int newlength = (ToExpand.length + ExpandBy);
        TempArray = new String[newlength];
        System.arraycopy(ToExpand, 0, TempArray, 0, ToExpand.length);
        return TempArray;
    }

    public synchronized CloneImportExport getClone2(String fileName) {
        while (setterLocked && ClearingList) {
            //wait for lock to clear
            System.out.println("NodeMasterManager getClone blocked");
        }

        Node tempNode;
        tempNode = get2(fileName);

        if (tempNode != null) {
            cloner.saveClone(tempNode);
            return cloner;
        }
        return null;
    }
}



Using JME 2.0.1

ok fixed the first problem, had to add a UVTex to the model in blender even though there was no texture set.



Looks a little funny because I had to make the cubes faces into triangles so that the shared nodes or cloning (cant remember which needed it) now the textures apply to the triangle parts not the full square, which I guess it what I would expect, any ideas how I may fix that?



also still need help with cloning models that have the texture applied in blender



Thanks



EDIT: ok they look better, coverted the triangles to quads created the UVtex then converted the quads to triangles again, texture looks fine.

So I can just apply the texture after loading the model if needed but would like to know if its possible to clone keeping the original model texture

ok have tried getting the texture from the model and applying it to the cloned node but that doesnt work



if I do



ts = (TextureState) node.getRenderState(StateType.Texture);
t = ts.getTexture();



I get a NullPointerException

is there something special you need to do before it registers that a texture applied from Blender
works if I dont clone it but I would like to clone the model Im at a loss with this