First of all sorry if i'm asking a newbie question, but i'm a java3d beginner.
I need to load a vrml file (eg: a cube), then to translate and rescale it. I need to do a non-unform rescaling, so i've tried this:
import java.applet.Applet; import java.net.URL; import java.net.MalformedURLException; import java.awt.BorderLayout; import java.awt.Frame; import java.awt.event.*; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.loaders.vrml97.VrmlLoader; import com.sun.j3d.loaders.Scene; import java.util.Hashtable;
[...]
private BranchGroup loadVrmlFile( String location ) { BranchGroup sceneGroup = null; Scene scene = null;
VrmlLoader loader = new VrmlLoader( );
try { URL loadUrl = new URL( location );
try { // load the scene scene = loader.load( new URL( location ) ); } catch ( Exception e ) { System.out.println( "Exception loading URL:" + e ); e.printStackTrace( ); } } catch ( MalformedURLException badUrl ) { // location may be a path name try { // load the scene scene = loader.load( location ); } catch ( Exception e ) { System.out.println( "Exception loading file from path:" + e ); e.printStackTrace( ); } }
if (scene != null) { // get the scene group sceneGroup = scene.getSceneGroup( );
}
return sceneGroup; }
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup();
Transform3D rotate2 = new Transform3D();
Vector3d v= new Vector3d();
v.x = .5d; v.y = .5d; v.z = .3d;
rotate2.rotZ(Math.PI/4.0d); rotate2.setScale(v);
TransformGroup objRotate2 = new TransformGroup(rotate2);
objRoot.addChild(objRotate2);
BranchGroup sceneRoot = loadVrmlFile( "vrml.wrl" );
objRotate2.addChild(sceneRoot);
return objRoot; }
public DueCubi() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config); add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene); }
now, when i launch DueCubi(), i obtain this exception:
javax.media.j3d.BadTransformException: non-congruent transform above ViewPlatform at javax.media.j3d.TransformGroupRetained.setLive(TransformGroupRetained.java:608) at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2125) at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:2180) at javax.media.j3d.BranchGroupRetained.setLive(BranchGroupRetained.java:160) at javax.media.j3d.Locale.doAddBranchGraph(Locale.java:204) at javax.media.j3d.Locale.addBranchGraph(Locale.java:163) at com.sun.j3d.utils.universe.SimpleUniverse.addBranchGraph(SimpleUniverse.java:356) at DueCubi.<init>(DueCubi.java:141) at DueCubi.main(DueCubi.java:209)
and the only way to fix it is to use a uniform scale factor (like 0.5, 0.5, 0.5). I've tried using affine transformation and other tricks but i always obtain this error. I've also tried to resize a ColorCube object and all goes fine, so it seems that isn't possible to do an anamorphic resize of a vrml mesh, and i need it!
Do you have any suggestion? Thanks a lot!
=========================================================================== 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".