⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vrmlloader.java

📁 vrml和java3d的完美结合 大家可以尝试把wrl文件导入Java三维环境。 尽情的去作自己的毕业设计吧!
💻 JAVA
字号:
import com.sun.j3d.loaders.*;import java.awt.GraphicsConfiguration;import java.applet.Applet;import java.awt.BorderLayout;import java.awt.event.*;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.universe.*;import java.io.*;import javax.imageio.*;import javax.media.j3d.*;import javax.vecmath.*;import com.sun.j3d.loaders.vrml97.VrmlLoader;import com.sun.j3d.loaders.vrml97.*;public class vrmlLoader extends Applet {  public BranchGroup createSceneGraph(String filename) {    // Create the root of the branch graph    BranchGroup sceneRoot = new BranchGroup();    // Create a bounds for the background and lights    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 500.0);    // Set up the background Color    Color3f bgColor = new Color3f(0.1f, 0.2f, 0.3f);    Background bg = new Background(bgColor);    bg.setApplicationBounds(bounds);    sceneRoot.addChild(bg);    // Set up the global lights First, define the color of the lights    Color3f light1Color = new Color3f(0.0f, 1.0f,1.0f);    Vector3f light1Direction  = new Vector3f(4.0f, -7.0f, -12.0f);    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);    Vector3f light2Direction  = new Vector3f(-6.0f, -2.0f, -1.0f);    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);    // Second, define the ambient light, and insert it in the branch    AmbientLight ambientLight = new AmbientLight(ambientColor);    ambientLight.setInfluencingBounds(bounds);    sceneRoot.addChild(ambientLight);    // Lastly, define the directional lights and insert it    DirectionalLight light1= new DirectionalLight(light1Color, light1Direction);    light1.setInfluencingBounds(bounds);    sceneRoot.addChild(light1);    DirectionalLight light2= new DirectionalLight(light2Color, light2Direction);    light2.setInfluencingBounds(bounds);    sceneRoot.addChild(light2);    TransformGroup sceneTG = new TransformGroup();    sceneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);    sceneRoot.addChild(sceneTG);       TransformGroup objTG = new TransformGroup();    Transform3D objTrans = new Transform3D();    objTG.getTransform(objTrans);    objTrans.setScale( 0.2 );    objTG.setTransform(objTrans);    sceneTG.addChild(objTG);        VrmlLoader l=new  VrmlLoader();    Scene s = null;    try {      s = l.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);    }    //sceneTG.addChild(f);    objTG.addChild(s.getSceneGroup());    return sceneRoot;  }  public vrmlLoader(String filename) {    filename="b.wrl";    setLayout(new BorderLayout());    GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();    Canvas3D c=new Canvas3D(config);    add("Center",c);      Viewer viewer=new Viewer(c);   Vector3d viewpoint=new Vector3d(.0,.0,3.0);   Transform3D t=new Transform3D();   t.set(viewpoint);   ViewingPlatform v=new ViewingPlatform();   v.getViewPlatformTransform().setTransform(t);      // Create a simple scene and attach it to the virtual universe    BranchGroup scene = createSceneGraph(filename);    SimpleUniverse u = new SimpleUniverse(c);    u.getViewingPlatform().setNominalViewingTransform();    u.addBranchGraph(scene);  }  public static void main(String[] args) {      new MainFrame(new vrmlLoader(null), 800,600);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -