Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Ase Loader Tutorial - Troubleshoot....  (Read 1823 times)
0 Members and 1 Guest are viewing this topic.
Offline Toba

Junior Newbie




procrastinating 101.beta


« Posted 2004-07-13 14:29:19 »

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.<init>(CrudeTank.java:64)
       at MeshWorks.<init>(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 :)

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

Cheers,
Ian
Offline Cristianbs

Senior Newbie




Java games rock!


« Reply #1 - Posted 2004-07-13 14:46:07 »

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.  Smiley
Offline VeeJay

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-07-13 16:22:49 »

Hi,

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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();
      }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #3 - Posted 2004-07-14 11:06:49 »

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.

Offline Cristianbs

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-07-14 13:54:28 »

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
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #5 - Posted 2004-07-14 22:18:10 »

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 Smiley

1  
2  
3  
4  
5  
+    public void removeFromParentGroup() {
+      if (this.parent instanceof Group) {
+            ((Group) this.parent).removeChild(this);
+      }
+    }


Cheers,

Will.

Offline Toba

Junior Newbie




procrastinating 101.beta


« Reply #6 - Posted 2004-07-15 00:17:52 »


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

Smiley
Offline m_ali_alex

Senior Newbie





« Reply #7 - Posted 2006-01-25 23:51:49 »

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.<init>(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.<init>(CrudeTank.java:113)
        at CrudeTank.main(CrudeTank.java:151)
Press any key to continue . . .
Offline jaakko777

Senior Newbie





« Reply #8 - Posted 2006-01-26 05:12:45 »

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:
      try
      {
         af = new AseFile();
         BufferedReader br = null;

         try
         {
            br = new BufferedReader(new FileReader("tri_leged.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);

         tri_legBG = af.getModel("tri_legged.ase");
      }

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

Senior Member




money is the worst drug- we should not let it rule


« Reply #9 - Posted 2006-01-26 15:47:15 »

Why don't you simply use

BranchGroup bg = AseFile.getModel("pathToYourModel");

And don't forget to add it to your scenegraph

:: JOODE :: Xith3d :: OdeJava ::
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline m_ali_alex

Senior Newbie





« Reply #10 - Posted 2006-01-27 20:58:49 »

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(r);

         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 (;Wink {
         v.renderOnce();
      }


   }

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


}

Offline m_ali_alex

Senior Newbie





« Reply #11 - Posted 2006-01-27 21:26:26 »

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(r);

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


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (51 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!