Hi, Thanks fors haring this code. I am also studying loaders right now, just started. Where can I download the loader U use ? Do I install it in the rootfolder of java ?
Tnx a lot ! -----Oorspronkelijk bericht----- Van: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED] Namens Fredrik Andersson Verzonden: maandag 15 december 2003 9:07 Aan: [EMAIL PROTECTED] Onderwerp: [JAVA3D] SV: [JAVA3D] SV: [JAVA3D] Problems with 3DS objects (test code valid) Hola Amgios! At last I solved it, with your helps of course. This was my misstakes: 1) The object was to big to fit. I was looking inside and out. 2) My 3D-object was not at the orgin. So now I have ended up with a loader manager that loads object either by StarFire excelent loader or by Ncsa excelent loader. It is supposed to scale as well but I doesn't think that work. I attach my 3D-object If any one would like to test it with that. Thanks for all help! Best regards Fredrik Here is the code: import java.io.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.loaders.*; import ncsa.j3d.loaders.*; import com.mnstarfire.loaders3d.*; public class ObjectloaderManager { public TransformGroup loadAndScale(String filePath, double scaleFactor) { TransformGroup transformGroup = null; try { ModelLoader loader = new ModelLoader(); Scene scene = loader.load( filePath ); if( scene != null ) { BranchGroup model = scene.getSceneGroup(); Transform3D scaleTransform = new Transform3D(); scaleTransform.setScale( scaleFactor ); transformGroup = new TransformGroup( ); transformGroup.setTransform( scaleTransform ); transformGroup.addChild( model ); } } catch( IOException ioe ) { System.err.println("Could not find object file: "); } return transformGroup; } public TransformGroup loadAndScaleStarfire(String filePath, double scaleFactor) { TransformGroup transformGroup = null; try { Loader3DS loader = new Loader3DS(); Scene scene = loader.load( filePath ); if( scene != null ) { BranchGroup model = scene.getSceneGroup(); Transform3D scaleTransform = new Transform3D(); scaleTransform.setScale( scaleFactor ); transformGroup = new TransformGroup( ); transformGroup.setTransform( scaleTransform ); transformGroup.addChild( model ); } } catch(Exception exception) { System.err.println("Could not find object file: "); } return transformGroup; } } And a test class import java.applet.*; import java.awt.*; import java.awt.Frame; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.keyboard.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; import com.sun.j3d.loaders.*; import java.io.*; import java.util.*; public class TestLoad extends Applet { BranchGroup branchGroup; Canvas3D canvas3D; SimpleUniverse simpleUniverse; public void init() { long start = System.currentTimeMillis(); setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas3D = new Canvas3D(config); add("Center", canvas3D); simpleUniverse = new SimpleUniverse(canvas3D); simpleUniverse.addBranchGraph( add3DObjects() ); simpleUniverse.addBranchGraph( addLight() ); long end = System.currentTimeMillis(); System.out.println((end-start)/1000); } private BranchGroup addLight() { BranchGroup branchGroup = new BranchGroup(); LightManager lightManager = new LightManager(branchGroup); lightManager.addAmbientLight(new Color3f(1f, 1f, 1f)); lightManager.addDirectionalLight(new Vector3f( -1.0f, 0.0f, -8.0f ), new Color3f(0.5f, 0.5f, 0.5f)); branchGroup.compile(); return branchGroup; } private BranchGroup add3DObjects() { BranchGroup branchGroup = new BranchGroup(); ObjectloaderManager objectloaderManager = new ObjectloaderManager(); TransformGroup transformGroup = objectloaderManager.loadAndScale("java3d/3dobjects/robot.3ds", 1.0005); Transform3D transform3D = new Transform3D(); transform3D.setTranslation( new Vector3d( 0.0, 0.0, -8.0 ) ); transformGroup.setTransform(transform3D); branchGroup.addChild(transformGroup); transformGroup = objectloaderManager.loadAndScaleStarfire("java3d/3dobjects/robot.3ds", 1.0005); transform3D = new Transform3D(); transform3D.rotX(Math.PI/2);//Depending of the cordinate system transform3D.setTranslation( new Vector3d( -1.0, 0.0, -8.0 ) ); transformGroup.setTransform(transform3D); branchGroup.addChild(transformGroup); branchGroup.compile(); return branchGroup; } public static void main(String[] args) { Frame frame = new MainFrame(new TestLoad(), 600, 400); } } -----Ursprungligt meddelande----- Från: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED] Jeremy Pitten Skickat: den 11 december 2003 14:53 Till: [EMAIL PROTECTED] Ämne: Re: [JAVA3D] SV: [JAVA3D] Problems with 3DS objects (test code valid) Are you sure loadScene isn't throwing an exception? Are you sure you are passing the correct path to the object file? Assuming the loader uses Class.getResource(String path) to get the file url then depending on whether you start the path with a slash or not will change where the loader looks for the file. As it is coded it probably looks in a directory ./java3d/java3d/3dobjects/... where as you pobably have the files stored in ./java3d/3dobjects/... so try it with a slash in front of the pathname. ----- Original Message ----- From: "Fredrik Andersson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, December 11, 2003 1:27 PM Subject: [JAVA3D] SV: [JAVA3D] Problems with 3DS objects (test code valid) > Hello! > > I changed my code to this but still nothing to see. > I guess that it is smarter to just extract the model instead of the scene (I > guess that is what this now is doing). > > package java3d; > > import java.applet.*; > import java.awt.*; > import java.awt.Frame; > import java.awt.event.*; > import com.sun.j3d.utils.applet.MainFrame; > import com.sun.j3d.utils.universe.*; > import com.sun.j3d.utils.geometry.*; > import com.sun.j3d.utils.behaviors.keyboard.*; > import javax.media.j3d.*; > import javax.vecmath.*; > import javax.swing.*; > import com.sun.j3d.loaders.*; > > import java.util.*; > > import com.mnstarfire.loaders3d.*; > > public class TestLoad extends Applet > { > BranchGroup branchGroup; > > > public void init() > { > setLayout(new BorderLayout()); > GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); > Canvas3D canvas3D = new Canvas3D(config); > add("Center", canvas3D); > SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D); > branchGroup = new BranchGroup(); > > //Scene scene = loadScene(); > //branchGroup = scene.getSceneGroup(); > > Inspector3DS loader = new Inspector3DS("java3d/3dobjects/girl.3DS"); > loader.parseIt(); > loader.setDetail(9); > loader.setTextureLightingOn(); > TransformGroup theModel = loader.getModel(); > Transform3D transform3D1 = new Transform3D(); > transform3D1.set(new Vector3f(0.0f, 0.0f, -5.0f)); > theModel.setTransform(transform3D1); > theModel.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); > branchGroup.addChild(theModel); > > addDirectionalLight(new Vector3f(0.0f, 0.0f, -5.0f), new Color3f(0.9f, > 0.9f, 0.9f)); > addDirectionalLight(new Vector3f(0.0f, 0.0f, -5.0f), new Color3f(0.9f, > 0.9f, 0.9f)); > addAmbientLight( new Color3f(0.9f, 0.9f, 0.9f) ); > > branchGroup.compile(); > simpleUniverse.addBranchGraph(branchGroup); > } > > public void addDirectionalLight(Vector3f direction, Color3f color) > { > BoundingSphere bounds = new BoundingSphere(); > bounds.setRadius(1000d); > > DirectionalLight lightD = new DirectionalLight(color, direction); > lightD.setInfluencingBounds(bounds); > > branchGroup.addChild(lightD); > } > > public void addAmbientLight(Color3f color) > { > BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), > 100.0); > AmbientLight ambientLightNode = new AmbientLight(color); > ambientLightNode.setInfluencingBounds(bounds); > > branchGroup.addChild(ambientLightNode); > } > > public Scene loadScene() > { > Scene scene = null; > > Loader3DS loader = new Loader3DS(); > try > { > scene = loader.load("java3d/3dobjects/girl.3DS"); > } > catch(Exception exception) > { > } > return scene; > } > > public static void main(String[] args) > { > Frame frame = new MainFrame(new TestLoad(), 600, 400); > } > } > > =========================================================================== > 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". =========================================================================== 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".