Skip to main content

Manipulate object from VRML file !

2 replies [Last post]
ddm
Offline
Joined: 2006-05-05

Hi all,

I need great help !

This is my problem : I try to move by mouse an object loaded from VRML file, this object is composed by some shape3Ds.
If the part of object clicked is the greatest then the object move correctly but if by any chance I click on another less part it moves separetly the group and the rest follow at distance.

Your idea is welcome

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aces
Offline
Joined: 2003-07-17

Just my 2 cents:
Try to create a "skeleton" scene graph with the body parts, using TransformGroup for each part.

Maybe this old study gives you some inspiration:
http://planeta.terra.com.br/educacao/alessandroborges/ana/ana.html

There is a applet where you can pick and rotate. The secret here is the transform around the pivot point.

Alessandro

ddm
Offline
Joined: 2006-05-05

Hi,
Certainly your suggest give me some ideas but my application consist of more simple. The object vrml is composed by 4 boxes ; there is the code to create a java object relating on the scene VRML
-------------
class PosteTravail{

public TransformGroup TG = new TransformGroup() ;
public MouseTranslate mTranslate = new MouseTranslate();

public PosteTravail (float cX, float cY, float cZ) {

// Loiding the vrml object
VRML97Loader loader = new VRML97Loader(255);
String filename = "D:\\DODO\\Projet3D\\poste\\poste.wrl";
Scene s = null;

try {
s = loader.load(filename);
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
}
catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

Transform3D translate = new Transform3D () ;
translate.setTranslation (new Vector3f(cX, cY, cZ)) ;

TransformGroup transform = new TransformGroup () ;
transform.setTransform(translate);

transform.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);
transform.setCapability (TransformGroup.ALLOW_TRANSFORM_READ);
transform.setCapability (TransformGroup.ENABLE_PICK_REPORTING);
transform.setCapability (TransformGroup.ENABLE_COLLISION_REPORTING);
transform.setCapability (TransformGroup.ALLOW_BOUNDS_READ) ;
transform.setCapability (TransformGroup.ALLOW_BOUNDS_WRITE) ;

System.out.println("debut");
//setCapabilityBitToGeometries(s.getSceneGroup()) ;
setCapabilities(s);
System.out.println("fin");

transform.addChild (s.getSceneGroup()) ;
TG = transform ;
}

/*
*****************************************************************************
Method to set the capabilites required on the Vrml shape

@Param scene = the loaded scene from the loadVrml method
*****************************************************************************
*/
public void setCapabilities(Scene scene){

Hashtable VRMLObjects = new Hashtable();
VRMLObjects = scene.getNamedObjects();
int numOfObjects = VRMLObjects.size();
Enumeration eNumKey = VRMLObjects.keys() ;
Enumeration eNumValue = VRMLObjects.elements();

if (eNumValue != null){

while(eNumValue.hasMoreElements()!= false){

Object value = eNumValue.nextElement();
Object key = eNumKey.nextElement();
//System.out.println(value.getClass().getName());

if (value instanceof SharedGroup) {
SharedGroup sg = (SharedGroup) value;
Object item = sg.getAllChildren().nextElement();

if (item instanceof TransformGroup) {
System.out.println(key);
((Node)item).setCapability(Node.ENABLE_PICK_REPORTING);
}

}

if (value instanceof Node)
setCap((Node)value);
}// End while(eNumValue.hasMoreElements()!= false)

}// End if (eNumValue != null)

}// End of method
/*
*****************************************************************************
Recursive Method to set the capabilites required on the Vrml shape

@Param = node the individual mode to set capabilities on.
*****************************************************************************
*/
public void setCap(Node node)
{
System.out.println(node.getClass().getName());
node.setPickable(true);

if (node instanceof Group){
Enumeration en = ((Group)node).getAllChildren();
while (en.hasMoreElements()){
setCap((Node)en.nextElement());
}// End of while (en.hasMoreElements())
}// End of if (node instanceof Group)
else if (node instanceof Link){
setCap(((Link)node).getSharedGroup());
}// End of if (node instanceof Link)
else if (node instanceof Shape3D)
{
node.setUserData(TG);
//System.out.println("User Data added to imported Vrml shape = " +node.getUserData());
System.out.println("Shape : "+node.getClass().getName());
node.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
node.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
node.setCapability(Shape3D.ALLOW_PICKABLE_WRITE);
node.setCapability(Shape3D.ALLOW_PICKABLE_READ);
node.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
node.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
Shape3D shape = (Shape3D)node;
Enumeration en = shape.getAllGeometries();
while (en.hasMoreElements())
{
Geometry geometry = (Geometry)en.nextElement();
if (geometry instanceof TriangleArray)
{
TriangleArray TA = (TriangleArray)geometry;
TA.setCapability(GeometryArray.ALLOW_FORMAT_READ);
TA.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
TA.setCapability(GeometryArray.ALLOW_COUNT_READ);
TA.setCapability(GeometryArray.ALLOW_INTERSECT);
TA.setCapability(GeometryArray.ALLOW_FORMAT_READ);
TA.setCapability(GeometryArray.ALLOW_NORMAL_READ);
}// End if (geometry instanceof TriangleArray)
else //doSomethingWithGeometry(geometry);
{
if (geometry instanceof TriangleStripArray)
{
TriangleStripArray TA = (TriangleStripArray)geometry;
TA.setCapability(GeometryArray.ALLOW_FORMAT_READ);
TA.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
TA.setCapability(GeometryArray.ALLOW_COUNT_READ);
TA.setCapability(GeometryArray.ALLOW_INTERSECT);
TA.setCapability(GeometryArray.ALLOW_FORMAT_READ);
TA.setCapability(GeometryArray.ALLOW_NORMAL_READ);
}// End if (geometry instanceof TriangleStripArray)
else
if(geometry instanceof QuadArray)
{
QuadArray TA = (QuadArray)geometry;
TA.setCapability(QuadArray.ALLOW_FORMAT_READ);
TA.setCapability(QuadArray.ALLOW_COORDINATE_READ);
TA.setCapability(QuadArray.ALLOW_COUNT_READ);
TA.setCapability(QuadArray.ALLOW_INTERSECT);
TA.setCapability(QuadArray.ALLOW_FORMAT_READ);
TA.setCapability(QuadArray.ALLOW_NORMAL_READ);
}// End if(geometry instanceof QuadArray)
}// End else
}// End of while (en.hasMoreElements())
}// End if (node instanceof Shape3D)
else
{
// ignore the rest because you don't
//know what it can be,behaviours, lights, or else...
} //end else
}//end of method// End of setCapabilities()

}

-------------

In the main class I use the PickTranslateBehavior like this :

PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas3D, bounds);
behavior3.setMode(PickTool.GEOMETRY);
objRoot.addChild(behavior3);
-----------------------

Can you tell me what must add or modify in my code ?

Thanks advance !