Title: Geleira
hello Martin,

excuse for the long time for answering, i think your code will be very useful for us. But I need to understand some basics about Java3D before.. Anyway, after some time researching and participating this list, I am sure Java3D can be used for implement our project, and the ability to load and use objects (not just load a world, it is important for us load objects from diferent files) is very important for our project.

thank you,
andrei

Martin Frey wrote:
Hi andrei
in my programs i do the same. i make a class that hold the shape3D and every
other information i need.
An other way is to attach a UserData-Object to every shape3D which's holding
these informations. i don't know which way is better, but i prefer the
first, that's why i can create behaviors and so on in the class which holds
the shape too.

Here's a loaderclass for obj-files which is holding a vector of loaded
shapes or loads the obj-file with the given name:

To all other people out there: look at the code too please and tell me if
this is a good way to handle objects in a scene.
Regards Martin

/***************************************************************************
************
* Loader.java
*
* Created on 23. April 2003, 17:49
*/
package MyProg.util;

import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import java.util.*;
/**
*
* @author Administrator
*/
public class Loader {
    public Loader(){
        shapes = new Vector();
    }

    public Shape3D getShape(String name){
        Enumeration e = shapes.elements();
        while (e.hasMoreElements()){
            Shape3D shape = (Shape3D) e.nextElement();
            if (name.equals(shape.getUserData())){
                return (Shape3D) shape.cloneTree();
            }
        }
        loadShape(name);
        return getShape(name);
    }

    private void loadShape(String name){
        ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
        try{
            com.sun.j3d.loaders.Scene s =
file.load(getClass().getResource("/MyProg/resources/" + name + ".obj"));
            Shape3D shape = (Shape3D) s.getSceneGroup().getChild(0);
            shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
            shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

shape.getAppearance().setCapability(Appearance.ALLOW_MATERIAL_READ);

shape.getAppearance().setCapability(Appearance.ALLOW_MATERIAL_WRITE);
            shape.setUserData(name);
            shapes.add(shape);
        } catch (Exception e) { System.out.println(e); }
    }

    private Vector shapes;
}

****************************************************************************
*********/

All you have to do is create your class and pass the Loader to it to get the
shapes. Here's my GameObject-Class:

/***************************************************************************
*********
* GameObject.java
*
* Created on 21. April 2003, 17:02
*/
package MyProg.gameobjects;
import MyProg.util.Loader;

import javax.media.j3d.*;
import javax.vecmath.*;
/**
*
* @author Administrator
*/
public abstract class GameObject {
    /** Creates a new instance of Enemy */
    public GameObject(Loader loader, String name){
        tg = new TransformGroup();
        tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        shape = loader.getShape(name);
        tg.addChild(shape);
    }

    public Shape3D getShape(){
        return shape;
    }

    public TransformGroup getTransformGroup(){
        return tg;
    }

    private Shape3D shape;
    private TransformGroup tg;
}

***********************************************************************/

I hope this helps you a little.

Greetz Martin



----- Original Message -----
From: "andrei" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 29, 2003 2:30 PM
Subject: Re: [JAVA3D] 3D Studio MAX


  
Martin Frey wrote:

    
download the obj-file exporter and load these objfiles. it works great
      
and
  
they works with textures and so on.

greetz Martin

      
hello list,

what loaders for 3DS and DXF files do you like more?

I need to build several classes for objects that are external files. So,
when an object is created, the constructor loads the file and this is
the 3d object. I tried some loaders yesterday, but something is not
working...

thank you,
andrei

--
"First of all you can't be subversive without being subversive to
    
yourself, that's very important. You miss something crucial if you think
subversion means to have clearly defined enemies and act against them. The
enemy always is always you, too and in the first place."
  
http://www.koreawebart.org/0100101110101101org.html


    
===========================================================================
  
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
    
body
  
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
    

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

.

  


--
"First of all you can't be subversive without being subversive to yourself, that's very important. You miss something crucial if you think subversion means to have clearly defined enemies and act against them. The enemy always is always you, too and in the first place."
http://www.koreawebart.org/2001/0100101110101101org.html

[EMAIL PROTECTED]
fone: 92067436
url: http://www.lelic.ufrgs.br/andrei/
url: http://www.atravesdoespelho.hpg.com.br/



Reply via email to