Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Loaders: how to set capabilities of the scene  (Read 1076 times)
0 Members and 1 Guest are viewing this topic.
Offline Conzar

Junior Devvie




There is nothing common about common sense


« Posted 2002-12-05 16:48:14 »

So I am trying to do terrain following and later on collision avoidance.  Well, I use loaders to construct all of my objects.  The specific one is the VRML loader.  

Anyways, how do you set capabilities to the Shape3D objects that the loader creates.  The loader returns a scene, so how do you get down to the terminals of the scene to get to the Shape3D so that you can set capabilities like ALLOW_GEOMETRY_READ.

Thanks

Ubuntu
Offline Conzar

Junior Devvie




There is nothing common about common sense


« Reply #1 - Posted 2003-01-15 15:10:59 »

So I think I came up w/ a method to attack this problem (I haven't tested this out yet though).  You get the scene from the loader, get the BranchGroup and then get all the children of the BG.  Once you get the enum, then you can set the capabilities of each object.  The only thing is, all these objects must be Shap3D for this to work out.  I'm not sure if this is always the case.  Below is some code to go w/ it.  Any suggestions?

       Scene s = loader.load(fileName);

        //Here we go - lets get all objects out of sceen
        BranchGroup bg = s.getSceneGroup();

        Enumeration enum1 = bg.getAllChildren();

        while(enum1.hasMoreElements()){
           shape = (Shape3D)enum1.nextElement();
           shape.setCapability(<whatever capability you want);
         }
           

Ubuntu
Offline bmyers

Junior Devvie





« Reply #2 - Posted 2003-01-15 15:46:06 »

It's the right approach, but instead of assuming that each Node in the graph is a Shape3D, you should get it out of the Enumeration as a Node, and then check to see if it an instanceof Shape3D before forcing the cast.

At least that way you won't get a ClassCastException at runtime!!

You will want to also check for Group nodes, because then you will want to iterate through all of the children of the sub-group.  I believe most of the VRML Loaders support nested Groups.

Here's an example SceneGraph to illustrate:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
BranchGroup
+-- Shape3D
+-- Shape3D
+-- TransformGroup
      +-- Shape3D
      +-- Shape3D
      +-- TransformGroup
            +-- Shape3D
       +-- TransformGroup
            +-- Shape3D
+--  etc, etc, etc...


I am doing exactly the same thing in a ModelManager class, which supports loading several different types of Loaders (OBJ, VRML, and 3DS for now).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Conzar

Junior Devvie




There is nothing common about common sense


« Reply #3 - Posted 2003-01-15 23:56:24 »

Yep, what you said worked.  Here is the code I am using to get through all the nodes of the scene for those of you who are interested.

So you will want to call this function inside of the while loop in the above post.


  private void setCapabilities(Node node){
     if(node.getClass().getName().equals("javax.media.j3d.Shape3D")){
        Shape3D shape = (Shape3D)node;
        shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
        Geometry geom = shape.getGeometry();
        geom.setCapability(GeometryArray.ALLOW_COORDINATE_READ);          geom.setCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ);
        geom.setCapability(IndexedGeometryArray.ALLOW_FORMAT_READ);                          
        geom.setCapability(IndexedGeometryArray.ALLOW_COUNT_READ);
     }
     else if(node.getClass().getName().equals("javax.media.j3d.BranchGroup")){
        Enumeration enum2 = ((BranchGroup)node).getAllChildren();
        while(enum2.hasMoreElements()){
           setCapabilities((Node)enum2.nextElement());
        }
     }
     else if(node.getClass().getName().equals("javax.media.j3d.TransformGroup")){
        Enumeration enum2 = ((TransformGroup)node).getAllChildren();
        while(enum2.hasMoreElements()){
           setCapabilities((Node)enum2.nextElement());
        }
     }
     else if(node.getClass().getName().equals("javax.media.j3d.Group")){
        Enumeration enum2 = ((Group)node).getAllChildren();
        while(enum2.hasMoreElements()){
           setCapabilities((Node)enum2.nextElement());
        }
     }
  }

Ubuntu
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.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (79 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!