Ase Loader Tutorial - Troubleshoot....

I have been trying the Ase Loader tutorial (Chp 7)
(this is specifically related to CrudeTank.java)
I get the following exception when I run it:

Exception in thread “main” com.xith3d.scenegraph.IllegalSceneGraphOperation: Ill
egal attempt to set the parent of this Node (name: ‘’, com.xith3d.scenegraph.Tra
nsformGroup@26d4f1) as it already has a parent (existing parent name: ‘Root’, co
m.xith3d.scenegraph.TransformGroup@1662dc8) and this would violate the directed
acyclic graph constraint of the scenegraph.
at com.xith3d.scenegraph.Node.setParent(Node.java:274)
at com.xith3d.scenegraph.Group.addChild(Group.java:96)
at CrudeTank.loadGeom(CrudeTank.java:102)
at CrudeTank.(CrudeTank.java:64)
at MeshWorks.(MeshWorks.java:85)
at MeshWorks.main(MeshWorks.java:68)

I haven’t changed anything in CrudeTank.java, though I am running it from my own main (MeshWorks.java) rather than the tutorial one. I also tried using the given main
(AseTest.java) with the same result.

I tried the google thing and came up with nothing.

I am not sure if I missed something along the way or what
Maybe the tutorial was written for an older version, and there is an incapatibility with the latest one I downloaded?

Anyways any help you can give me would be much appreciated :slight_smile:

ps: had fun with the rest of the tutorial, Great Job!

Cheers,
Ian

There is a topic about this issue in http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1089579666

As you can see, it still has no solution posted.I have been playing around with the code, and i took example from the xith3DTransformGroupTree example.It seems that you cant load the ASE nodes as childs in the code, if they have parent in the ASE file (i guess).I have succeed loading the ASE scene as a whole TransformGroup.

Anyway, it would be great if any of the developers (or the tutorial author) could bring a little help about whats wrong with the tutorial example, so we could learn more about the scenegraph, the ase files, and such. :slight_smile:

Hi,

I had the same problem and here is how I fixed it


public static BranchGroup loadASE(String path, String fileName)
      {
            TextureLoader.tf.registerPath(path);
            AseFile af = new AseFile();
            try
            {
                  AseReader ar = new AseReader(new BufferedReader(new FileReader(path + "\\" + fileName)));
                  af.parse(ar);
            }
            catch(IOException e)
            {
                  System.out.println("Error reading ASE file");
            }
            return af.getModel();
      }

a change was made which broke backward compatability and the tute needs updating.

Basically each node can only have one parent in Xith3d. The simple solution is to remove the child from the parent’s group before adding it to another one.

Eg.

I want to add a group “crudeTank” to my scene “scene”

crudeTank.removeFromParentGroup()
scene.addChild(crudetank());

Annoying it may be but it prevents you from getting a few nasty and very hard to find bugs in your code.

Edit: getModel returns a node with no parent (which is why it worked) - but the other methods such as the ones used in my tutorials actually return a tree (or chain) of TransformGroups. The problem is that you want to take a TG form the middle of the tree and add it to your scene - which is why you need to use the above method first.

Hope that helps,

Will.

Well, i suppose it helps, as a clue.I have not been able to find such a method ( removeFromParentGroup() ) in the node class.But i have seen that with groups you can access childs and remove them…so, once you have your node, you access the parent (as a group) and remove the child you want to assign to the new group.Here’s an example:

torso.addChild(removeParent((Node) nodes.get(“Torso”)));

And our remove parent method is:

public Node removeParent(Node n){

        Group Parent = (Group)n.getParent();
        Parent.removeChild(n);
        return n;

}

It works, maybe there’s a better solution that uses a killparent method that i havent found.Dunno.
Anyway, thanks Will and the others to help resolve this little problem :wink:

it should be there (in cvs that is).

CVS message:
https://xith3d.dev.java.net/servlets/ReadMsg?list=cvs&msgNo=362

Source file:
https://xith3d.dev.java.net/source/browse/xith3d/src/com/xith3d/scenegraph/Node.java

Don’t rely on the xith.org javadoc’s they may be out of date.

As you will see, the method is nothing special :slight_smile:


+    public void removeFromParentGroup() {
+      if (this.parent instanceof Group) {
+            ((Group) this.parent).removeChild(this);
+      }
+    }

Cheers,

Will.

Thanks Will for the help with that. It makes sense now.

:slight_smile:

i have been tring to use the getModel () and i got this run time exception
any one know how to fix it
here is my code:–>

import com.xith3d.loaders.ase.;
import com.xith3d.scenegraph.
;
import com.xith3d.test.;
// Renderer
import com.xith3d.render.
;
import com.xith3d.render.jogl.;
import com.xith3d.loaders.texture.
;

import javax.vecmath.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.IOException;

import java.net.URL;

public class CrudeTank {

private BranchGroup tri_legBG;
private AseFile af ;

public CrudeTank ()
{

	try
	{

		af = new AseFile();
		BufferedReader br = null;

		try
		{
			

			br = new BufferedReader(new FileReader("tri_leged.ASE"));
			tri_legBG = af.getModel("tri_legged.ase");


		}
		catch (IOException e)
		{
			
			URL url = this.getClass().getClassLoader().getResource("tri_leged.ASE");
			br = new BufferedReader(new InputStreamReader(url.openStream()));
		}

		AseReader r = new AseReader(br);
		af.parse(r);
	}


	catch (Exception e)
	{
		e.printStackTrace();
	}

	
	VirtualUniverse u = new VirtualUniverse();
	View v = new View();
	com.xith3d.scenegraph.Locale l = new com.xith3d.scenegraph.Locale();
	u.addLocale(l);
	u.addView(v);

	l.addBranchGraph(tri_legBG);

	Transform3D t3D = new Transform3D();
			t3D.rotXYZ(  (float)Math.PI/4,
							(float)Math.PI/5,
							(float)Math.PI/2);// this is not to dynamicly rotating the object but it is to put it in the angle
							// desired for example if you leave it at 0,0,0 then u will see a box not the 3d shape of a cube

	// we add the TransformGroup  to the BranchGroup
	TransformGroup tGroup = new TransformGroup(t3D);
	tri_legBG.addChild(tGroup);//transformGroup contain transform3d is added to the branchGroup

	// we compile the BranchGroup to turn it into Render Friendly
	tri_legBG.compile();



	RenderPeer rp = new RenderPeerImpl();
	CanvasPeer cp = rp.makeCanvas(null,640,480,32,false);
	Canvas3D canvas = new Canvas3D();
	canvas.set3DPeer(cp);
	v.addCanvas3D(canvas);


	v.getTransform().lookAt(
								new Vector3f(0,0,2.41f),                   // location of the eye "where u see it from"
								new Vector3f(0,0,0),					   // center of view
								new Vector3f(0,1,0));

	v.startView();
	System.out.println("done");


}

public static void main (String []args)
{

	new CrudeTank();
}

}

and this is the exception i get

java.lang.NullPointerException
at CrudeTank.(CrudeTank.java:93)
at CrudeTank.main(CrudeTank.java:151)
Exception in thread “main” java.lang.NullPointerException
at com.xith3d.scenegraph.Locale.addBranchGraph(Locale.java:103)
at CrudeTank.(CrudeTank.java:113)
at CrudeTank.main(CrudeTank.java:151)
Press any key to continue . . .

I have not used the ASELoader but it looks like something is not initialized in the correct order.

Try moving the line where you get the model a few lines down the code so it looks like this:

Atleast it looks a bit more like it could work… :wink: Then again i havent used the ASELoader so i dont know how its supposed to work.

Why don’t you simply use

BranchGroup bg = AseFile.getModel(“pathToYourModel”);

And don’t forget to add it to your scenegraph

hi
i tried the getModel () it compiled and when i run it nothing showed up on the screen
just black background window open with nothing in it
here is my code

import com.xith3d.loaders.ase.;
import com.xith3d.scenegraph.
;
import javax.vecmath.;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.IOException;
import com.xith3d.render.
;
import com.xith3d.render.jogl.;
import com.xith3d.loaders.texture.
;

import java.net.URL;

public class TriLegged
{

private BranchGroup tri_legBG;

public TriLegged ()
{

	try
	{


		/*
		 * Loads the ASE file
		 */
		AseFile af = new AseFile();

// BufferedReader br = null;

		try
		{
			// Attempts to read the file normally
	//		br = new BufferedReader(new FileReader("tri_legged.ASE"));
			tri_legBG = af.getModel("tri_legged.ASE");

		}
		catch (IOException e)
		{
			// Attemts to read file from JAR
			URL url = this.getClass().getClassLoader().getResource("tri_legged.ASE");
//			br = new BufferedReader(new InputStreamReader(url.openStream()));
		}

// AseReader r = new AseReader(br);
// af.parse®;

		tri_legBG = new BranchGroup ();



	}
	catch (Exception e)
	{
		e.printStackTrace();
	}

	VirtualUniverse u = new VirtualUniverse();
	View v = new View();
	Locale l = new Locale();
	u.addLocale(l);
	u.addView(v);

	TransformGroup tg = new TransformGroup ();
	tg.addChild(tri_legBG);
	l.addBranchGraph(tri_legBG);
	l.addBranchGraph(tri_legBG);

	RenderPeer rp = new RenderPeerImpl();
	CanvasPeer cp = rp.makeCanvas(null,300,200,32,false);
	Canvas3D canvas = new Canvas3D();
	canvas.set3DPeer(cp);
	canvas.setView(new View());
	v.addCanvas3D(canvas);
	v.getTransform().lookAt(new Vector3f(-250,150,-150),   new Vector3f(-0,0,150),    new Vector3f( 0, 10, 0));

	float tankAngle = 0;
	float turretAngle = 0;

	for (int i = 0;i < 500;i++) {
		if (i < 100 || (i > 200 && i < 300)) {
			tankAngle += 0.1f;
		} else if (i > 300) {
			tankAngle -= 0.1f;
		}

		if ((i > 100 && i < 160) || i > 350) {
			turretAngle -= 0.05f;
		} else if (i > 160 && i < 350) {
			turretAngle += 0.05f;
		}

		v.renderOnce(); // renders the scene

		{
			// Rotates the whole tank
			Transform3D tr = new Transform3D();
			tg.getTransform(tr);
			tr.rotY(tankAngle);
			tg.setTransform(tr);
		}


		// Sleeps some time
		try { Thread.sleep(50); } catch (Exception e) {e.printStackTrace();}
	}

	// loop forever
	for (;;) {
		v.renderOnce();
	}


}

public static void main (String [] args)
{
	new TriLegged();
}

}

thanks guys
i found it out very simple but my eyes were blind
here is the correction
public class TriLegged
{

private BranchGroup tri_legBG;

public TriLegged ()
{

  try
  {


     /*
      * Loads the ASE file
      */
     AseFile af = new AseFile();

// BufferedReader br = null;

     try
     {
        // Attempts to read the file normally
  //      br = new BufferedReader(new FileReader("tri_legged.ASE"));
        tri_legBG = af.getModel("tri_legged.ASE");

     }
     catch (IOException e)
     {
        // Attemts to read file from JAR
        URL url = this.getClass().getClassLoader().getResource("tri_legged.ASE");

// br = new BufferedReader(new InputStreamReader(url.openStream()));
}

// AseReader r = new AseReader(br);
// af.parse®;

// tri_legBG = new BranchGroup (); THIS IS WAS THE PROBLEM IT SHOULD BE TAKEN OUT WITH THE REST OF THE CODE AS IS
THANKS