Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 12:10:51 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Problems with AseLoader
Pages: [1] 2 3
Print
Author Topic: Problems with AseLoader  (Read 4979 times)
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« on: 28. December 2006, 10:15:19 pm »

im newish to this, i have the latest cooker, where do i find this ase example, im stuck on a problem.

Created a humanoid character in 3dmax  added bones ( head to toe ) exported as obj / ase (i have both files)
created a chracter class like the tankase example but when i run i get athis error:

Exception in thread "main" java.lang.IllegalArgumentException: This Node already has a parent.
        at org.xith3d.scenegraph.GroupNode.addChild(GroupNode.java:142)

the error id from this line

 Bone_Head.addChild((Node)nodes.get("Bone_Head"));

anyhelp will be appreciated.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 28. December 2006, 10:49:07 pm »

Could you maybe provide the complete stacktrace?
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #2 on: 29. December 2006, 12:19:35 am »

that was quick, thanks its a very short error so i know i must be doing something wrong.

Compiling 1 source file to D:\javaOpengl\BoxingGame\build\classes
compile:
run:
Exception in thread "main" java.lang.IllegalArgumentException: This Node already has a parent.
        at org.xith3d.scenegraph.GroupNode.addChild(GroupNode.java:142)
        at boxinggame.Boxer.LoadObjectFile(Boxer.java:94)
        at boxinggame.Boxer.<init>(Boxer.java:81)
        at boxinggame.DarosGym.createScene(DarosGym.java:44)
        at boxinggame.DarosGym.<init>(DarosGym.java:37)
        at boxinggame.DarosGym.main(DarosGym.java:136)
BUILD SUCCESSFUL (total time: 5 seconds)
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 29. December 2006, 12:44:06 am »

Hmmm... It doesn't seem to have something to do with the AseLoader. Is is possible, to quote more of your source code? I'm quite sure you're doing something wrong, but I can't see, what, without (parts of) your code.

Marvin
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #4 on: 29. December 2006, 06:21:45 am »

here is the boxer.java class


package boxinggame;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import org.xith3d.loaders.models.impl.obj.*;
import org.xith3d.loaders.models.impl.ase.*;
import org.xith3d.scenegraph.*;

public class Boxer
{
    private String BoxersName;
    private BranchGroup Bone_Head;
    private BranchGroup Bone_Neck;
    private BranchGroup Bone_Upper_Back;
    private BranchGroup Bone_Lower_Back;
   
    private BranchGroup Bone_R_Hip;
    private BranchGroup Bone_R_Thigh;
    private BranchGroup Bone_R_Shin;
    private BranchGroup Bone_R_Foot;
    private BranchGroup Bone_R_Toe;
    private BranchGroup Bone_R_Shoulder;
    private BranchGroup Bone_R_Bicep;
    private BranchGroup Bone_R_ForeArm;
    private BranchGroup Bone_R_Hand;
   
    private BranchGroup Bone_L_Hip;
    private BranchGroup Bone_L_Thigh;
    private BranchGroup Bone_L_Shin;
    private BranchGroup Bone_L_Foot;
    private BranchGroup Bone_L_Toe;
    private BranchGroup Bone_L_Shoulder;
    private BranchGroup Bone_L_Bicep;
    private BranchGroup Bone_L_ForeArm;
    private BranchGroup Bone_L_Hand;
    private AseModel BoxerASEModel;
    private OBJModel BoxerOBJModel;
 
   
   
    /** Creates a new instance of Boxer */
    public Boxer(String name)
    {
        BoxersName = name;
        Bone_Head = new BranchGroup() ;
        Bone_Neck = new BranchGroup()  ;
        Bone_Upper_Back = new BranchGroup()  ;
        Bone_Lower_Back = new BranchGroup()  ;

        Bone_R_Hip  = new BranchGroup()  ;
        Bone_R_Thigh  = new BranchGroup()  ;
        Bone_R_Shin = new BranchGroup () ;
        Bone_R_Foot = new BranchGroup()  ;
        Bone_R_Toe = new BranchGroup()  ;
        Bone_R_Shoulder = new BranchGroup() ;
        Bone_R_Bicep = new BranchGroup()  ;
        Bone_R_ForeArm  = new BranchGroup()  ;
        Bone_R_Hand  = new BranchGroup () ;

        Bone_L_Hip = new BranchGroup()  ;
        Bone_L_Thigh = new BranchGroup()  ;
        Bone_L_Shin = new BranchGroup () ;
        Bone_L_Foot = new BranchGroup() ;
        Bone_L_Toe   = new BranchGroup () ;
        Bone_L_Shoulder = new BranchGroup()  ;
        Bone_L_Bicep = new BranchGroup() ;
        Bone_L_ForeArm = new BranchGroup()  ;
        Bone_L_Hand = new BranchGroup()  ;
             
        LoadObjectFile();
    }
   
    private void LoadObjectFile()
    {
        try
        {
            BoxerASEModel = new AseLoader().loadModel ("./model/boxer.ASE");
       Map nodes = BoxerASEModel.getNamedObjects();
           
            //BoxerOBJModel = new OBJLoader().loadModel( "./model/boxer.obj" );
            //Map nodes = BoxerOBJModel.getNamedObjects();
                     
            Bone_Head.addChild((Node)nodes.get("Bone_Head"));
            Bone_Neck.addChild((Node)nodes.get("Bone_Neck"));
            Bone_Upper_Back.addChild((Node)nodes.get("Bone_Upper_Back"));
            Bone_Lower_Back.addChild((Node)nodes.get("Bone_Lower_Back"));
           
            Bone_L_Hip.addChild((Node)nodes.get("Bone_L_Hip"));
            Bone_L_Thigh.addChild((Node)nodes.get("Bone_L_Thigh"));
            Bone_L_Shin.addChild((Node)nodes.get("Bone_L_Shin"));
            Bone_L_Foot.addChild((Node)nodes.get("Bone_L_Foot"));
            Bone_L_Toe.addChild((Node)nodes.get("Bone_L_Toe"));
           
            Bone_L_Shoulder.addChild((Node)nodes.get("Bone_L_Shoulder"));
            Bone_L_Bicep.addChild((Node)nodes.get("Bone_L_Bicep"));
            Bone_L_ForeArm.addChild((Node)nodes.get("Bone_L_ForeArm"));
            Bone_L_Hand.addChild((Node)nodes.get("Bone_L_Hand"));
           
            Bone_R_Hip.addChild((Node)nodes.get("Bone_R_Hip"));
            Bone_R_Thigh.addChild((Node)nodes.get("Bone_R_Thigh"));
            Bone_R_Shin.addChild((Node)nodes.get("Bone_R_Shin"));
            Bone_R_Foot.addChild((Node)nodes.get("Bone_R_Foot"));
            Bone_R_Toe.addChild((Node)nodes.get("Bone_R_Toe"));
           
            Bone_R_Shoulder.addChild((Node)nodes.get("Bone_R_Shoulder"));
            Bone_R_Bicep.addChild((Node)nodes.get("Bone_R_Bicep"));
            Bone_R_ForeArm.addChild((Node)nodes.get("Bone_R_ForeArm"));
            Bone_R_Hand.addChild((Node)nodes.get("Bone_R_Hand")); 
           
            System.out.println("loaded boxer");
        }
        catch(IOException e)
        {
            System.out.println("unable to load boxer");
            e.printStackTrace();
        }
    }
   
    public BranchGroup get_Head()
    {
        return Bone_Head;
    }
   
    public BranchGroup get_Neck()
    {
        return Bone_Neck;
    }
   
    public BranchGroup get_Upper_Back()
    {
        return Bone_Upper_Back;
    }
   
    public BranchGroup get_Lower_Back()
    {
        return Bone_Lower_Back;
    }   
    public BranchGroup get_L_Hip()
    {
        return Bone_L_Hip;
    }
    public BranchGroup get_L_Thigh()
    {
        return Bone_L_Thigh;
    }
    public BranchGroup get_L_Shin()
    {
        return Bone_L_Shin;
    }   
    public BranchGroup get_L_Foot()
    {
        return Bone_L_Foot;
    }
   
    public BranchGroup get_L_Toe()
    {
        return Bone_L_Toe;
    }
    public BranchGroup get_L_Shoulder()
    {
        return Bone_L_Shoulder;
    }
   
    public BranchGroup get_L_Bicep()
    {
        return Bone_L_Bicep;
    }
    public BranchGroup get_L_ForeArm()
    {
        return Bone_L_ForeArm;
    }
     public BranchGroup get_L_Hand()
    {
        return Bone_L_Hand;
    }     
    public BranchGroup get_R_Hip()
    {
        return Bone_R_Hip;
    }
    public BranchGroup get_R_Thigh()
    {
        return Bone_R_Thigh;
    }
    public BranchGroup get_R_Shin()
    {
        return Bone_R_Shin;
    }   
    public BranchGroup get_R_Foot()
    {
        return Bone_R_Foot;
    }
   
    public BranchGroup get_R_Toe()
    {
        return Bone_R_Toe;
    }
    public BranchGroup get_R_Shoulder()
    {
        return Bone_R_Shoulder;
    }
    public BranchGroup get_R_Bicep()
    {
        return Bone_R_Bicep;
    }
    public BranchGroup get_R_ForeArm()
    {
        return Bone_R_ForeArm;
    }
     public BranchGroup get_R_Hand()
    {
        return Bone_R_Hand;
    }       
}
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 29. December 2006, 06:39:55 am »

I see the mistake.

Remove all lines from the constructor except the first and last one Smiley.

All nodes inside the loaded model (including named objects) are already set-up in a tree. So each node already has a parent. These named nodes are TransformGroups, that simply need to be manipulated to animate the model.

BTW: Don't use BranchGroups inside the scenegraph, except as the very root node to be added to a Locale.

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 29. December 2006, 06:44:13 am »

Try something like this:

Code:
public class Boxer
{
    private String BoxersName;
    private TransformGroup Bone_Head;
    private TransformGroup Bone_Neck;
    private TransformGroup Bone_Upper_Back;
    ...
   
   
    /** Creates a new instance of Boxer */
    public Boxer(String name)
    {
        BoxersName = name;
        LoadObjectFile();
    }
   
    private void LoadObjectFile()
    {
        try
        {
            BoxerASEModel = new AseLoader().loadModel ("./model/boxer.ASE");
    Map nodes = BoxerASEModel.getNamedObjects();
           
            //BoxerOBJModel = new OBJLoader().loadModel( "./model/boxer.obj" );
            //Map nodes = BoxerOBJModel.getNamedObjects();
                     
            Bone_Head = (TransformGroup)nodes.get("Bone_Head");
            Bone_Neck = (TransformGroup)nodes.get("Bone_Neck");
            Bone_Upper_Back = (TransformGroup)nodes.get("Bone_Upper_Back");
            ...
           
            System.out.println("loaded boxer");
        }
        catch(IOException e)
        {
            System.out.println("unable to load boxer");
            e.printStackTrace();
        }
    }
   
    public TransformGroup get_Head()
    {
        return Bone_Head;
    }
   
    public TransformGroup get_Neck()
    {
        return Bone_Neck;
    }
   
    public TransformGroup get_Upper_Back()
    {
        return Bone_Upper_Back;
    }
   
    public TransformGroup get_Lower_Back()
    {
        return Bone_Lower_Back;
    }   
    public TransformGroup get_L_Hip()
    {
        return Bone_L_Hip;
    }
    public TransformGroup get_L_Thigh()
    {
        return Bone_L_Thigh;
    }
    public TransformGroup get_L_Shin()
    {
        return Bone_L_Shin;
    }   
    public TransformGroup get_L_Foot()
    {
        return Bone_L_Foot;
    }
   
    public TransformGroup get_L_Toe()
    {
        return Bone_L_Toe;
    }
    public TransformGroup get_L_Shoulder()
    {
        return Bone_L_Shoulder;
    }
   
    public TransformGroup get_L_Bicep()
    {
        return Bone_L_Bicep;
    }
    public TransformGroup get_L_ForeArm()
    {
        return Bone_L_ForeArm;
    }
     public TransformGroup get_L_Hand()
    {
        return Bone_L_Hand;
    }     
    public TransformGroup get_R_Hip()
    {
        return Bone_R_Hip;
    }
    public TransformGroup get_R_Thigh()
    {
        return Bone_R_Thigh;
    }
    public TransformGroup get_R_Shin()
    {
        return Bone_R_Shin;
    }   
    public TransformGroup get_R_Foot()
    {
        return Bone_R_Foot;
    }
   
    public TransformGroup get_R_Toe()
    {
        return Bone_R_Toe;
    }
    public TransformGroup get_R_Shoulder()
    {
        return Bone_R_Shoulder;
    }
    public TransformGroup get_R_Bicep()
    {
        return Bone_R_Bicep;
    }
    public TransformGroup get_R_ForeArm()
    {
        return Bone_R_ForeArm;
    }
     public TransformGroup get_R_Hand()
    {
        return Bone_R_Hand;
    }       
}
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #7 on: 29. December 2006, 02:32:36 pm »

thanks that was cool to know, except that now im not sure of how i understood the system to begin with.

Code:
public class DarosGym extends RenderLoop{
    private Canvas3DWrapper canvas;
    /** Creates a new instance of DarosGym */
    public DarosGym() {
        super( 128L );
       
        Tuple3f eyePosition = new Vector3f( 0.0f, 0.0f, 5.0f );
        Tuple3f viewFocus = new Vector3f( 0.0f, 0.0f, 0.0f );
        Tuple3f vecUp = new Vector3f( 0.0f, 1.0f, 0.0f );
       
        Xith3DEnvironment env = new Xith3DEnvironment( eyePosition, viewFocus, vecUp, this );
        canvas = Canvas3DWrapper.createStandalone( Resolution.RES_800X600,"THE GYM" );
        env.addCanvas(canvas );
        env.addBranchGraph( createScene() );
        this.registerKeyboardAndMouse( canvas );
        this.begin();
    }
   
    private BranchGroup createScene()
    {
        Boxer boxer = new Boxer("Daro");
       
        BranchGroup m = new BranchGroup();       
       
        m.addChild(boxer.get_Head());
       
    /*    m.addChild((Node)boxer.get_Neck());
        m.addChild((Node)boxer.get_Upper_Back());             
        m.addChild((Node)boxer.get_Lower_Back());
               
        m.addChild((Node)boxer.get_L_Shoulder());
        m.addChild((Node)boxer.get_L_Bicep());       
        m.addChild((Node)boxer.get_L_ForeArm());
        m.addChild((Node)boxer.get_L_Hand());
        m.addChild((Node)boxer.get_L_Hip());
        m.addChild((Node)boxer.get_L_Thigh());           
        m.addChild((Node)boxer.get_L_Shin());       
        m.addChild((Node)boxer.get_L_Foot());       
        m.addChild((Node)boxer.get_L_Toe());
     
        m.addChild((Node)boxer.get_R_Shoulder());       
        m.addChild((Node)boxer.get_R_Bicep());     
        m.addChild((Node)boxer.get_R_ForeArm());       
        m.addChild((Node)boxer.get_R_Hand());               
        m.addChild((Node)boxer.get_R_Hip());     
        m.addChild((Node)boxer.get_R_Thigh());       
        m.addChild((Node)boxer.get_R_Shin()); 
        m.addChild((Node)boxer.get_R_Foot());   
        m.addChild((Node)boxer.get_R_Toe());
        */
       
       
        return m;
       
    }

Exception in thread "main" java.lang.IllegalArgumentException: This Node already has a parent.
        at org.xith3d.scenegraph.GroupNode.addChild(GroupNode.java:142)
        at boxinggame.DarosGym.createScene(DarosGym.java:48)
        at boxinggame.DarosGym.<init>(DarosGym.java:37)
        at boxinggame.DarosGym.main(DarosGym.java:96)
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #8 on: 29. December 2006, 04:14:15 pm »

thanks that was cool to know, except that now im not sure of how i understood the system to begin with.

Code:
public class DarosGym extends RenderLoop{
    private Canvas3DWrapper canvas;
    /** Creates a new instance of DarosGym */
    public DarosGym() {
        super( 128L );
       
        Tuple3f eyePosition = new Vector3f( 0.0f, 0.0f, 5.0f );
        Tuple3f viewFocus = new Vector3f( 0.0f, 0.0f, 0.0f );
        Tuple3f vecUp = new Vector3f( 0.0f, 1.0f, 0.0f );
       
        Xith3DEnvironment env = new Xith3DEnvironment( eyePosition, viewFocus, vecUp, this );
        canvas = Canvas3DWrapper.createStandalone( Resolution.RES_800X600,"THE GYM" );
        env.addCanvas(canvas );
        env.addBranchGraph( createScene() );
        this.registerKeyboardAndMouse( canvas );
        this.begin();
    }

Are you talking about this code? It's absolutely correct.

Or are you talking about the model part to (first) put into the scene? Well that's easy. It's the whole model:

Code:
    private BranchGroup createScene()
    {
        BranchGroup m = new BranchGroup();       
       
        Boxer boxer = new Boxer("Daro");
        m.addChild(boxer);
       
        return m;
    }

This will do the trick.

Marvin
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #9 on: 29. December 2006, 06:04:57 pm »

none of the addChild methods will accept the boxer as a parameter, it doesnt compile; shouldnt i be doing some sort of cating? i tried to but that didnt work either.
Code:
m.addChild(boxer)
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #10 on: 29. December 2006, 06:45:35 pm »

none of the addChild methods will accept the boxer as a parameter, it doesnt compile; shouldnt i be doing some sort of cating? i tried to but that didnt work either.
Code:
m.addChild(boxer)

Oh, sorry. My fault. Try this:
Code:
public class Boxer extends Group
{
    private Model model;
   
    private void LoadObjectFile()
    {
        this.model = new AseLoader().loadModel ("./model/boxer.ASE" );
        this.addChild( this.model );
       
        ...
    }
   
    ...
}

// somewhere else:
myGroup.addChild( new Boxer() );

Hope, this is correct now (but I believe, it is Wink).

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #11 on: 29. December 2006, 06:50:40 pm »

Alternatively to extending Group you can add a new method to the Boxer class like this:
Code:
public class Boxer
{
    private Model model;
   
    public void addToSceneGraph(NodeGroup group)
    {
        group.addChild( model );
    }
   
    private void LoadObjectFile()
    {
        this.model = new AseLoader().loadModel ("./model/boxer.ASE" );
       
        ...
    }
   
    ...
}

// somewhere else:
Boxer boxer = new Boxer();
boxer.addToSceneGraph( myGroup );

Marvin
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #12 on: 29. December 2006, 08:18:09 pm »

thanks alot, i think its almost there now. just have to play around with the camera so i can zoom in and around to see if it loaded properly.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #13 on: 29. December 2006, 08:25:42 pm »

thanks alot, i think its almost there now. just have to play around with the camera so i can zoom in and around to see if it loaded properly.

Good to know Smiley.

Have a look at org.xith3d.utility.input.EgoInputAdapter. It is used in org.xith3d.test.loaders.BSPLoaderTest. This enables you to use the mouse to rotate the camera.

Marvin
Logged
daro eghagha
Enjoying the stay
*
Offline Offline

Posts: 27


View Profile Email
« Reply #14 on: 29. December 2006, 09:21:30 pm »

i was going to ask where are these test codes? in src download or something?
Logged
Pages: [1] 2 3
Print
Jump to:  

Theme orange-lt created by panic