ASE Loading textures

Hi

I’m back with more ASE loader Q’s.

I understand from other posts that ASE loader does not support Materials (light reflection etc)
I have accounted for this in my code.

I note however the ASE file format also has a “*BITMAP” tag - which points to my models textures

I was wondering does the ASE Loader support the loading and application of these Textures - or
do the textures have to be applied separately -
'cos when I load up my Model - there are no textures showing.

If these textures have to be applied manually - does anybody have some example code to extract the Shape3D
for each body part and apply the texture2D

Cheers

Rmdire

Still can’t find answers on this - as far as I can make out - the xith source code appears to load textures

in the mean time i’ve built this from other stuff I found on the forum - if anybody is interested - it just dumps a texture on the
object - maybe someone would have a better function?


	public void addTextureToBodyPart(Group group,String nodeName,URL texturePath)
	{
		//set up texture and appearance
	    Texture2D thisTexture = null;
	    thisTexture = loadtexture(texturePath);
	    Appearance thisAppearance = new Appearance();
	    thisAppearance.setTexture(thisTexture);
	    
		    // list of all the chillllders
		    java.util.List nodes = group.getChildren();
		    
		    for (int i = 0; i < nodes.size(); i++) 
		    {
			    SceneGraphObject obj = (SceneGraphObject) nodes.get(i);
			    
			    if (obj instanceof Shape3D) {
				  Shape3D sh = (Shape3D) obj;
				  
				     //is this the name of poor child we want to texture
				     //texturing children should be made illegal
				  if((group.getName()).equalsIgnoreCase(nodeName))
				      {sh.setAppearance(thisAppearance);}
			    }
			    else if (obj instanceof Group) 
			    {
				addTextureToBodyPart( (Group) obj,nodeName,texturePath);
			    }
		     }	
	}

Rmdire

this function is way too slow - don’t use it

does anybody else have any functions that they use to texture .ASE models - or am I the only one who is using this file format?

moment…:
Texture and Appearance is not the same!!!
The ASE-Loader creates Nodes with Appearances, that contain the Texture. It only uses the default setting for the Material, which handles Lightning and stuff.

so you’ll probably only have to do this:


    /** sets the Material of the given Shape */
    private void setMaterial(Shape3D s) {
        Material m = new Material(true);
        m.setAmbientColor(0.2f,0.2f,0.2f);
        m.setDiffuseColor(1,1,1);
        m.setSpecularColor(0.4f,0.4f,0.4f);
        if(s.getAppearance().getTextureUnitCount() == 0) m.setColorTarget(m.AMBIENT_AND_DIFFUSE);
        else  m.setColorTarget(m.NONE);
    	s.getAppearance().setMaterial(m);
    }
    /** This Method performs a DFS through all the Nodes contained in g */
    private void setMaterial(Group g) {
    	for(int i = 0; i < g.numChildren(); i++) {
    		Node n = g.getChild(i);
    		if(n instanceof Group) {
    			setMaterial((Group) n);
    		} 
    		else if(n instanceof Shape3D) {
    			setMaterial((Shape3D) n);
    		}
    	}
    }

Thanks arne,

Yep, I have been using these functions already - I got it from one of your previous posts.

But the model just shows up as white without any reflective feature,

This is why I was wondering if the ASE loading of textures is actually implemented.

actually what I’ve just done is move the textures out of the folder they should be in and tried to load the model in.
and its loaded without any “cannot find resource errors” - so theres my answer - textures are not working for the ASE loader.

is this correct?

Ahh that problem :smiley: I had it also :wink:
The ASE-Loader uses the TextureLoader to load textures, but it doesn’t register a path to the directory, where the textures are located. So it simply doesn’t find the texture. You’ll simply have to register the Path in TextureLoader before loading. I believe this should help.

Important: I believe the ASE-loader still uses TextureLoader and NOT TextureLoader2, so don’t register the path at the wrong loader :wink:

HI Arne -
Forgive my total ignorance - but I cant see how to access the ASELoader’s TextureLoader in order to set the path.

this is how I load in my ASE file:


                                          AseFile af = new AseFile();
		BufferedReader br = null;
		
		try {
			// Attempts to read the file normally
			br = new BufferedReader(new FileReader(path));
		
		} catch (IOException e) {
			// Attemts to read file from JAR
			URL url = this.getClass().getClassLoader().getResource(path);
			try {
				br = new BufferedReader(new InputStreamReader(url.openStream()));
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		
		AseReader r = new AseReader(br, af);
	
		af.parse(r);
				
	   
		namedNodes = new HashMap ();
		TransformGroup rootTG = af.getTransformGroupTree(namedNodes);

How should I access the ASELoader’s TextureLoader in order to set the path.

Cheers

Rmdire

When you call TextureLoader.getInstance() * it returns you a TextureLoader that’s saved as a static variable in TextureLoader. So it returns exactly the same TextureLoader for you as for the ASE loader (I’m talking here about identity). So when you change the TextureLoader you get by TextureLoader.getInstance() you’ll change the static variable, so you change the TextureLoader the ASE-Loader uses.

*I don’t if the method is called exactly TextureLoader.getInstance() or something different (with the same meaning ofcourse).

Thanks arne

this hasn’t worked either - must be summit up with the ASE exporter.

your help on the secrets of XITH is much appreciated though

Cheers

Rmdire