在J3D中可以直接倒入OBJ和VRML格式的3D模型,先把人物模型导出为OBJ格式就可以了。如果要倒入VRML格式的,需要下载vrml97.jar,J3D不自带的,如果你要的话,我可以给你。下面是我写的一个装载OBJ格式的类 ObjectLoader.java ////////////////////////////////////////////////////////// import java.io.FileNotFoundException; import java.net.URL;import javax.media.j3d.BranchGroup;import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile;// This is a help class, and can not be instantiated public class ObjectLoader extends BranchGroup { private static double creaseAngle = 60.0; private static ObjectFile objFile = new ObjectFile(ObjectFile.RESIZE, (float) (creaseAngle * Math.PI / 180.0));
ObjectLoader.java
//////////////////////////////////////////////////////////
import java.io.FileNotFoundException;
import java.net.URL;import javax.media.j3d.BranchGroup;import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;// This is a help class, and can not be instantiated
public class ObjectLoader extends BranchGroup { private static double creaseAngle = 60.0; private static ObjectFile objFile = new ObjectFile(ObjectFile.RESIZE, (float) (creaseAngle * Math.PI / 180.0));
private static Scene scene;
private ObjectLoader() {
} public static BranchGroup load(URL url) {
scene = null;
try {
scene = objFile.load(url);
} catch (FileNotFoundException e) {
System.err.println(e);
return null;
} catch (ParsingErrorException e) {
System.err.println(e);
return null;
} catch (IncorrectFormatException e) {
System.err.println(e);
return null;
} catch(Exception e) {
System.err.println(e);
return null;
}
if (scene != null) {
return scene.getSceneGroup();
}
return null;
}
public static BranchGroup load(String filename) {
scene = null;
try {
scene = objFile.load(filename);
} catch (FileNotFoundException e) {
System.err.println(e);
return null;
} catch (ParsingErrorException e) {
System.err.println(e);
return null;
} catch (IncorrectFormatException e) {
System.err.println(e);
return null;
} catch(Exception e) {
System.err.println(e);
return null;
}
if (scene != null) {
return scene.getSceneGroup();
}
return null;
}
}
只是现在想到。不知道能否用JAVA3D直接写个3D模型出来.想动物.或者其他什么的东西.可以不?
这样的算法还是很难
知道怎么把vrml格式的模型调入吗?