Java 我不明白如何使用TextureLoader,它会删除IO异常
大家好,我刚刚用java3d(SimpleUniverse)编写了代码,我不明白它遇到的异常以及为什么它不能读取文件。。。我试图通过TextureLoader将图像作为我的背景图像,谢谢大家的帮助。 这是一个例外: com.sun.j3d.utils.image.ImageException:javax.imageio.IIOException: 无法读取输入文件!在 com.sun.j3d.utils.image.TextureLoader$1.run(TextureLoader.java:344)位于 java.security.AccessController.doPrivileged(本机方法)位于 com.sun.j3d.utils.image.TextureLoader。(TextureLoader.java:337) 在 com.sun.j3d.utils.image.TextureLoader.(TextureLoader.java:291) 在application.backGround.createSceneGraph(backGround.java:60)中 backGround.(backGround.java:39)位于 sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 位于sun.reflect.NativeConstructorAccessorImpl.newInstance(未知 来源)在 sun.reflect.delegatingConstructor AccessorImpl.newInstance(未知 源代码)位于java.lang.reflect.Constructor.newInstance(未知源代码) 位于java.lang.Class.newInstance(未知源) 位于的sun.applet.AppletPanel.createApplet(未知源) 位于的sun.applet.AppletPanel.runLoader(未知源) sun.applet.AppletPanel.run(未知源)位于 java.lang.Thread.run(未知源)由以下原因引起: javax.imageio.IIOException:无法读取输入文件!在 javax.imageio.imageio.read(未知源代码)位于 com.sun.j3d.utils.image.TextureLoader$1.run(TextureLoader.java:342) ... 14多 代码如下: /====================================================================/ /*===================运行上述代码所需的平面类===========*/Java 我不明白如何使用TextureLoader,它会删除IO异常,java,image,exception,Java,Image,Exception,大家好,我刚刚用java3d(SimpleUniverse)编写了代码,我不明白它遇到的异常以及为什么它不能读取文件。。。我试图通过TextureLoader将图像作为我的背景图像,谢谢大家的帮助。 这是一个例外: com.sun.j3d.utils.image.ImageException:javax.imageio.IIOException: 无法读取输入文件!在 com.sun.j3d.utils.image.TextureLoader$1.run(TextureLoader.java:3
package Aplication;
import javax.media.j3d.Appearance;
import javax.media.j3d.Geometry;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.Material;
import javax.media.j3d.QuadArray;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
public class createPlane extends Shape3D {
Shape3D plane;
public class LitQuad extends Shape3D {
LitQuad(Point3f A, Point3f B, Point3f C, Point3f D) {
this.setGeometry(createGeometry(A, B, C, D));
this.setAppearance(createAppearance());
}
Geometry createGeometry(Point3f A, Point3f B, Point3f C, Point3f D) {
QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
| GeometryArray.NORMALS);
plane.setCoordinate(0, A);
plane.setCoordinate(1, B);
plane.setCoordinate(2, C);
plane.setCoordinate(3, D);
Vector3f a = new Vector3f(A.x - B.x, A.y - B.y, A.z - B.z);
Vector3f b = new Vector3f(C.x - B.x, C.y - B.y, C.z - B.z);
Vector3f n = new Vector3f();
n.cross(b, a);
n.normalize();
plane.setNormal(0, n);
plane.setNormal(1, n);
plane.setNormal(2, n);
plane.setNormal(3, n);
return plane;
}
Appearance createAppearance() {
Appearance appear = new Appearance();
Color3f color = new Color3f(0.0f,1.5f,0.0f);
Material material = new Material();
material.setDiffuseColor(color);
appear.setMaterial(material);
return appear;
}
}
public createPlane(){
plane = new LitQuad(new Point3f(-1.5f, -0.5f, -5.0f),
new Point3f(-1.5f, -0.5f, 1.0f),
new Point3f(1.5f, -0.5f, 1.0f), new Point3f(1.5f, -0.5f, -5.0f));
}
public Shape3D getGeo(){
return plane;
}
}
“如果你想让我把代码放在这里”只是用需要包含2个类的代码更新了问题@谢谢你的帮助helping@lxg这是你的电话号码changes@Unheilig这是changes@lan这里是变化
package Aplication;
import javax.media.j3d.Appearance;
import javax.media.j3d.Geometry;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.Material;
import javax.media.j3d.QuadArray;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
public class createPlane extends Shape3D {
Shape3D plane;
public class LitQuad extends Shape3D {
LitQuad(Point3f A, Point3f B, Point3f C, Point3f D) {
this.setGeometry(createGeometry(A, B, C, D));
this.setAppearance(createAppearance());
}
Geometry createGeometry(Point3f A, Point3f B, Point3f C, Point3f D) {
QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
| GeometryArray.NORMALS);
plane.setCoordinate(0, A);
plane.setCoordinate(1, B);
plane.setCoordinate(2, C);
plane.setCoordinate(3, D);
Vector3f a = new Vector3f(A.x - B.x, A.y - B.y, A.z - B.z);
Vector3f b = new Vector3f(C.x - B.x, C.y - B.y, C.z - B.z);
Vector3f n = new Vector3f();
n.cross(b, a);
n.normalize();
plane.setNormal(0, n);
plane.setNormal(1, n);
plane.setNormal(2, n);
plane.setNormal(3, n);
return plane;
}
Appearance createAppearance() {
Appearance appear = new Appearance();
Color3f color = new Color3f(0.0f,1.5f,0.0f);
Material material = new Material();
material.setDiffuseColor(color);
appear.setMaterial(material);
return appear;
}
}
public createPlane(){
plane = new LitQuad(new Point3f(-1.5f, -0.5f, -5.0f),
new Point3f(-1.5f, -0.5f, 1.0f),
new Point3f(1.5f, -0.5f, 1.0f), new Point3f(1.5f, -0.5f, -5.0f));
}
public Shape3D getGeo(){
return plane;
}
}