ASE group support completed - *beta available*

Full geom and group node pivot support has been added to the Ase loader as proposed.

What does this mean? Well if you choose to, you can access individual groups or objects in your model and translate or rotate them around their individual pivot points (which can be specified in MAX). Previous support only allowed transformations around the origin.

The output of the pre-existing methods has NOT been changed - getModel should work exactally how it used to (although I encourage your to test to make sure my claim is valid).

How can you use this new feature? Well the most useful way is by the
TransformGroup getTransformGroupTree (HashMap namedNodes) method of AseFile.

That returns the root TransformGroup, plus it maps the node names to their TransformGroups in the passed HashMap.

For example, if you have a model of a human with the body parts “Body” (group of the body geom, arm geom and hand), “Arm” (group of the arm geom and hand geom) and “Hand” (the hand geom), you would add the returned TransformGroup to the root BranchGroup in your scene. Then you can easily get the Hand or Arm groups from the HashMap and rotate them around their pivot points (the bone joints).

An example of the code in action is given in the demo com.xith3d.test.Xith3DAseGroupTest.

There are two cubes in a group. Each cube spins in place around their respective pivot points. The group also spins around it’s pivot point (between the two groups), and the group spins around the origin. This demonstrates the new rotate abilities using three different pivots. Press the keys “1”, “2” and “3” to toggle the rotations of the respective TransformGroups.

The model data is in the files “rotatingcubetext.ASE” and “rotatingcubetest.max”.

I have uploaded an “experimental” build for beta testing here:
http://xith.org/download/builds/2003-12-07_experimental-aseloader/

Please run that test to see the new functionality. Anyone who currently uses the getModel() method in their code, please test my changes with your project and inform me of any problems.

I would like to commit those changes within a few days so long as no issues arise.

Will.

The demo works fine. I think these improvements will be very important for a lot of us. Keep up the good work. :slight_smile:

Thanks Jens :slight_smile:

NEW BETA RELEASED

This is hopefully the final version before I commit the changes in.

Just repeating, my changes should NOT change existing behaviour but I would like help testing that (so people who use the Ase loader - please download it and make sure nothing crazy happens).

I have also created a tutorial for the GSG about the new methods and functionality. It’s not in there officially yet and my Java example is still being created but I have uploaded it.

The build (and source) can be downloaded from here:
http://xith.org/download/builds/2003-12-08_experimental-aseloader

The GSG PDF is also there if you want some more info on the changes and how they work. Code is fully commented and javadocumented.

Run the Xith3DAseGroupTest demo from within the demo/ directory to see the new features in action.


java -cp ../libs/xith3d.jar -DXITH3D_USE_VERTEX_BUFFER_CACHING=FALSE com.xith3d.test.Xith3DAseGroupTest

Cheers,

Will.

nice one dude

code has been committed

JWS demos:

From the Getting Started Guide
http://www.xith.org/jws/jws-org.xith3d.gsg.AseTransformGroup.jnlp

Xith3D test case
http://www.xith.org/jws/jws-com.xith3d.test.Xith3DAseTransformGroupTreeTest.jnlp

I am going to upload the tutorial in the near future (it’s already in xith-tk CVS for those who can’t wait).

Cheers,

Will.

Was normal indices parsing aded to new version? I’v realised it earlier forself but waited for ASE group finishig.

[quote]Was normal indices parsing aded to new version? I’v realised it earlier forself but waited for ASE group finishig.
[/quote]
Normal’s have always been parsed - since alpha1 that is.

Look at the code:
src/com/xith3d/loaders/ase/AseMesh.java

in particular the ‘getTriangleArray’ method.


 // convert the normals coordinates.  For each face we have
            // three normal vertices, each of which has 3 floats
            if (normals != null) {
                n = 0;

                float[] norms = new float[nFaces * 3 * 3];

                for (int f = 0; f < numFaces; f++)
                    if ((faceMat[f] == matID) || (matID < 0)) {
                        for (int v = 0; v < 3; v++) {
                            if (convertMeshCoordinates) {
                                norms[(((n * 3) + v) * 3) + 0] = -normals[(((f * 3) +
                                    v) * 3) + 2]; // x
                                norms[(((n * 3) + v) * 3) + 1] = normals[(((f * 3) +
                                    v) * 3) + 1]; // y
                                norms[(((n * 3) + v) * 3) + 2] = normals[(((f * 3) +
                                    v) * 3) + 0]; // z
                            } else {
                                norms[(((n * 3) + v) * 3) + 0] = normals[(((f * 3) +
                                    v) * 3) + 0]; // x
                                norms[(((n * 3) + v) * 3) + 1] = normals[(((f * 3) +
                                    v) * 3) + 1]; // y
                                norms[(((n * 3) + v) * 3) + 2] = normals[(((f * 3) +
                                    v) * 3) + 2]; // z
                            }
                        }

                        n++;
                    }

                a.setNormals(0, norms);

Of course, one must instruct MAX to export normals.

If normals arn’t working for your then it would be a bug (somewhere) - not a missing feature :slight_smile:

Maybe I’ll whip up a demo in the next day or two.

Hope that helps,

Will.

Normals are definitally in there :slight_smile:

The below diff file contains the changes I made to get the Xith3DAseGroupTest test case to add lighting.

The changes are in three parts:

  • Adding lights to the scene
  • Creating a material and recursivly adding it to all Shape3D’s
  • a method to do said recursion.

Note that I am not generating normals - they are loaded in from the ase file!

[edit] The JWS link is here: http://xith.org/jws/jws-com.xith3d.test.Xith3DAseGroupTest.jnlp[/edit]

Will.


Index: Xith3DAseGroupTest.java
===================================================================
RCS file: /cvs/xith3d/src/com/xith3d/test/Xith3DAseGroupTest.java,v
retrieving revision 1.2
diff -u -r1.2 Xith3DAseGroupTest.java
--- Xith3DAseGroupTest.java     9 Dec 2003 12:33:32 -0000       1.2
+++ Xith3DAseGroupTest.java     11 Dec 2003 03:09:34 -0000
@@ -85,7 +85,11 @@
                // Sets the texture path.
                TextureLoader.tf.registerPath("./");
  
-
+               // Adds lights to the scene
+               AmbientLight light = new AmbientLight(true,new Color3f(0.4f,0.4f,0.4f));
+               DirectionalLight dlight = new DirectionalLight(true,new Color3f(0.75f,0.75f,0.75f),new Vector3f(-1,-1,-1));
+               objRoot.addChild(light);
+               objRoot.addChild(dlight);
  
                /*
                 * Loads the ASE file
@@ -132,7 +136,16 @@
                // Adds the entire geometry using the old getModel() method
                objRoot.addChild(af.getModel());
  
-
+               // Creates a material able to accept lighting
+               Material mat2 = new Material();
+               mat2.setEmissiveColor(0f,0f,0f);
+               mat2.setSpecularColor(0.5f,0.5f,0.5f);
+               mat2.setAmbientColor(0.75f,0.0f,0.0f);
+               mat2.setDiffuseColor(0.75f,0.0f,0.0f);
+               mat2.setLightingEnable(true);
+
+               // Recursivly applies material to root BG
+               addMaterial(objRoot, mat2);
  
                return objRoot;
        }
@@ -235,6 +248,27 @@
                }
        }
  
+       /**
+        * Recursivly adds the given material to all Shape3D objects
+        * in the passed group and all of its subgroups.
+        */
+       public static void addMaterial(Group group, Material mat) {
+
+               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;
+                               sh.getAppearance().setMaterial(mat);
+
+                       } else if (obj instanceof Group) {
+                               addMaterial( (Group) obj, mat);
+                       }
+               }
+       }
+
        public static void main(String[] args)
        {
                System.out.println("Hit ESC to exit\nPress 3 to stop/start rotation");