import javax.media.j3d.*; import com.sun.j3d.loaders.Scene; //import com.jme.math.*; //import com.jme.scene.state.MaterialState; //import com.jme.scene.state.TextureState; //import com.jme.renderer.ColorRGBA; import javax.vecmath.*; //import java.awt.Color; //import java.awt.color.ColorSpace; class cJ3D { static boolean gennormals = false; // can be done through UI static boolean trim = true; static boolean stripify = true; static boolean genUV = false; Matrix4d tempmat = new Matrix4d(); Matrix4d tempmatR = new Matrix4d(); Matrix4d tempmatS = new Matrix4d(); Matrix4d tempmatT = new Matrix4d(); Quat4d quat = new Quat4d(); javax.vecmath.Vector3d trans = new javax.vecmath.Vector3d(); void ResetTransform(Object3D obj, Node s) { if (s instanceof TransformGroup) { ResetTransform(obj, (TransformGroup)s); return; } if (s instanceof Group) { Group g = (Group) s; assert(obj.size() == g.numChildren()); for (int i=0; i e = names.keys(); e.hasMoreElements();) { String name = e.nextElement(); if (names.get(name) == sgo) { thename = name; break; } } return thename; } Object3D Read(Shape3D s) { Object3D obj = new Object3D(GetName(s)); obj.bRep = Read(s.getGeometry()); if (s.getAppearance() != null) { if (s.getAppearance().getUserData() != null) obj.SetBumpTexture(/*"/" +*/ filename + "/" + s.getAppearance().getUserData().toString()); if (s.getAppearance().getMaterial() != null) { obj.CreateMaterial(); if (s.getAppearance().getMaterial().getUserData() != null) obj.SetPigmentTexture(/*"/" +*/ filename + "/" + s.getAppearance().getMaterial().getUserData().toString()); ReadMaterial(obj, s); } } return obj; } Object3D Read(Group g) { Composite c = new Composite(GetName(g)); // g.getClass().getName()); // ReadNode(c, g); for (int i=0; i enumnames; float[] buffer = new float[4]; /* cMaterial Read(MaterialState mat) { if (mat == null) return null; cMaterial cmat = new cMaterial(); ColorRGBA col = mat.getDiffuse(); buffer[0] = col.r; buffer[1] = col.g; buffer[2] = col.b; buffer[3] = col.a; //Color col = new Color(buffer[0], buffer[1], buffer[2]); //col.getColorComponents(ColorSpace.getInstance(ColorSpace.TYPE_HSV), buffer); cColor.RGBtoHSB(buffer[0], buffer[1], buffer[2], buffer); cmat.color = buffer[0]+0.001f; cmat.modulation = buffer[1]+0.001f; cmat.diffuse = buffer[2]+0.001f; col = mat.getSpecular(); buffer[0] = col.r; buffer[1] = col.g; buffer[2] = col.b; buffer[3] = col.a; cmat.specular = buffer[0]+0.001f; // No way to get the metalness col = mat.getAmbient(); buffer[0] = col.r; buffer[1] = col.g; buffer[2] = col.b; buffer[3] = col.a; cmat.ambient = buffer[0]+0.001f; cmat.shininess = (Math.max(mat.getShininess(),0)+0.001f); // 1/x return cmat; } cTexture Read(TextureState tex) { if (tex == null) return null; if( tex.getTexture() != null) { System.out.println(tex.getTexture().getImageLocation()); System.out.println(tex.getTexture().getImage()); System.out.println(tex.getTexture().getTextureKey()); } else System.out.println("NO TEXTURE"); cTexture ctex = null; // new cTexture(); return ctex; } */ //Vertex v = new Vertex(true); static Vector3f v3f = new Vector3f(); static Point3f p3f = new Point3f(); static TexCoord2f t2f = new TexCoord2f(); BoundaryRep Read(javax.media.j3d.Geometry g) { BoundaryRep brep = null; if (g instanceof javax.media.j3d.TriangleArray) { javax.media.j3d.TriangleArray ta = (javax.media.j3d.TriangleArray) g; int nbvertices = ta.getVertexCount(); assert (nbvertices % 3 == 0); brep = new BoundaryRep(); brep.redimension(nbvertices, nbvertices/3); for (int i=0; i= 3; bRep.AddFace(indexV, indexV+1, indexV+2); indexF++; //bRep.faces.addElement(null); //bRep.setFace(indexF++, indexV, indexV+1, indexV+2); indexV += 3; for (int j=3; j= 3; bRep.AddFace(indexV, indexV+1, indexV+2); indexF++; //bRep.faces.addElement(null); //bRep.setFace(indexF++, indexV, indexV+1, indexV+2); indexV += 3; for (int j=3; j