JAVA3D导入VRML的时候
需要VRML97.JAR文件
可是我没有配置明白路径
完好的文件总是执行错误import com.sun.j3d.loaders.vrml97.*;
import com.sun.j3d.loaders.*;
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.media.j3d.*;
import javax.vecmath.*;
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.*;
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), 100.0);
// Set up the background Color
Color3f bgColor = new Color3f(1.0f, 1.0f, 1.0f);
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); // Create the scene's transform group node (starts as
// identity). Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Note, we DO
// NOT set the TRANSFORM_READ capability because we only do
// writes. Add it to the root of the branch graph
TransformGroup sceneTG = new TransformGroup();
sceneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sceneRoot.addChild(sceneTG); // Create an Alpha object that goes from 0 to 1 in 8 seconds,
// repeatedly.
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
0, 0,
4000, 0, 0,
0, 0, 0); // Create a new Behavior object that will rotate the scene
// add it into the scene graph.
Transform3D yAxis = new Transform3D();
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, sceneTG, yAxis,
0.0f, (float) Math.PI*2.0f);
rotator.setSchedulingBounds(bounds);
// sceneTG.addChild(rotator); // Load the object
TransformGroup objTG = new TransformGroup();
Transform3D objTrans = new Transform3D();
objTG.getTransform(objTrans);
objTrans.setScale( 0.6 );
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="r.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), 500, 400);
}
}错误为:
Exception in thread "main" java.lang.NoSuchMethodError: vrml.node.Node.<init>(Lcom/sun/j3d/loaders/vrml97/impl/Node;)V
at com.sun.j3d.loaders.vrml97.impl.Node.wrap(Node.java:114)
at com.sun.j3d.loaders.vrml97.VrmlScene.<init>(VrmlScene.java:69)
at com.sun.j3d.loaders.vrml97.VrmlLoader.doLoad(VrmlLoader.java:119)
at com.sun.j3d.loaders.vrml97.VrmlLoader.load(VrmlLoader.java:99)
at vrmlLoader.createSceneGraph(vrmlLoader.java:103)
at vrmlLoader.<init>(vrmlLoader.java:144)
at vrmlLoader.main(vrmlLoader.java:157)到底怎么回事啊
?
是不是我的路径有问题?
我再另外一台电脑上好像弄好使过、
着急中
高手解答啊
需要VRML97.JAR文件
可是我没有配置明白路径
完好的文件总是执行错误import com.sun.j3d.loaders.vrml97.*;
import com.sun.j3d.loaders.*;
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.media.j3d.*;
import javax.vecmath.*;
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.*;
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), 100.0);
// Set up the background Color
Color3f bgColor = new Color3f(1.0f, 1.0f, 1.0f);
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); // Create the scene's transform group node (starts as
// identity). Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Note, we DO
// NOT set the TRANSFORM_READ capability because we only do
// writes. Add it to the root of the branch graph
TransformGroup sceneTG = new TransformGroup();
sceneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sceneRoot.addChild(sceneTG); // Create an Alpha object that goes from 0 to 1 in 8 seconds,
// repeatedly.
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
0, 0,
4000, 0, 0,
0, 0, 0); // Create a new Behavior object that will rotate the scene
// add it into the scene graph.
Transform3D yAxis = new Transform3D();
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, sceneTG, yAxis,
0.0f, (float) Math.PI*2.0f);
rotator.setSchedulingBounds(bounds);
// sceneTG.addChild(rotator); // Load the object
TransformGroup objTG = new TransformGroup();
Transform3D objTrans = new Transform3D();
objTG.getTransform(objTrans);
objTrans.setScale( 0.6 );
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="r.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), 500, 400);
}
}错误为:
Exception in thread "main" java.lang.NoSuchMethodError: vrml.node.Node.<init>(Lcom/sun/j3d/loaders/vrml97/impl/Node;)V
at com.sun.j3d.loaders.vrml97.impl.Node.wrap(Node.java:114)
at com.sun.j3d.loaders.vrml97.VrmlScene.<init>(VrmlScene.java:69)
at com.sun.j3d.loaders.vrml97.VrmlLoader.doLoad(VrmlLoader.java:119)
at com.sun.j3d.loaders.vrml97.VrmlLoader.load(VrmlLoader.java:99)
at vrmlLoader.createSceneGraph(vrmlLoader.java:103)
at vrmlLoader.<init>(vrmlLoader.java:144)
at vrmlLoader.main(vrmlLoader.java:157)到底怎么回事啊
?
是不是我的路径有问题?
我再另外一台电脑上好像弄好使过、
着急中
高手解答啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货