当前位置: 首页>>代码示例>>Java>>正文


Java ObjectFile类代码示例

本文整理汇总了Java中com.sun.j3d.loaders.objectfile.ObjectFile的典型用法代码示例。如果您正苦于以下问题:Java ObjectFile类的具体用法?Java ObjectFile怎么用?Java ObjectFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ObjectFile类属于com.sun.j3d.loaders.objectfile包,在下文中一共展示了ObjectFile类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadObject

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
BranchGroup loadObject(String path) {
    try {
        return new ObjectFile(ObjectFile.RESIZE).load(getClass().getResource(path)).getSceneGroup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:tekrei,项目名称:JavaExamples,代码行数:9,代码来源:Java3DPanel.java

示例2: SparkySpacecraftMat

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
/**
 * Initialize with input scale factor.
 * 
 * @param    scale    Scale factor for the model.  A scale of
 *                    1.0 means the distance from the model origin, to the
 *                    furthest point on the model, will be one unit long.
 */
public SparkySpacecraftMat(double scale) {
    // allow the state of the model to be changed after compilation
  setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // add the visual representation to the TransformGroup
  try {
      // first try the sparkymatmesh.obj model
    Scene modelScene = null;
    ObjectFile of = new ObjectFile();
    of.setFlags(ObjectFile.RESIZE     |
               ObjectFile.TRIANGULATE |
               ObjectFile.STRIPIFY);   
      // load the mesh defined below
    URL sparkyURL = SparkySpacecraftMat.class.getResource("sparkymatmesh.obj");
    if (sparkyURL == null) {
      throw new java.io.FileNotFoundException("Can't find sparkymesh.obj" +
                                                                       this);
    }
    modelScene = of.load(sparkyURL);
      // rotate model axis to align with simulation axis.  Also, offset
      // it along the x-axis so the cg and origin coincide.
    Vector3d trans = new Vector3d();  // offset along x-axis
    trans.x = XOFF*scale;
    Matrix3d m1 = new Matrix3d();
    m1.rotX(Math.PI/2.0);          // nose down into plane
    Matrix3d m2 = new Matrix3d();
    m2.rotZ(Math.PI/2.0);          // nose yaw into X
    m2.mul(m1);                    // combine
    Transform3D t3d = new Transform3D(m2, trans, scale);
    TransformGroup tg = new TransformGroup(t3d);
    BranchGroup modelBG = modelScene.getSceneGroup();
      //
    tg.addChild(modelBG);
    addChild(tg);
  } catch(java.io.FileNotFoundException ex) {
      // if the above didn't work, load a sphere
    addChild(new Sphere(1.0f));
  }
}
 
开发者ID:motoq,项目名称:vse,代码行数:47,代码来源:SparkySpacecraftMat.java

示例3: drawOBJ

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
private static Shape drawOBJ (String filename, boolean colored) {

        int params = ObjectFile.RESIZE | Loader.LOAD_ALL;
        ObjectFile loader = new ObjectFile(params);
        try {
            BranchGroup bg = loader.load(filename).getSceneGroup();
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
            bg.setCapability(BranchGroup.ALLOW_DETACH);

            //System.out.println("Children: " + bg.numChildren());

            for (int i = 0; i < bg.numChildren(); i++) {
                Node child = bg.getChild(i);
                if (child instanceof Shape3D) {
                    Shape3D shape = (Shape3D) child;
                    //System.out.println("shape3d");
                    //                     Appearance ap = shape.getAppearance();
                    //                     PolygonAttributes pa = ap.getPolygonAttributes();
                    //                     if (pa == null) pa = new PolygonAttributes();
                    //                     pa.setCullFace(PolygonAttributes.CULL_NONE);
                    //                     ap.setPolygonAttributes(pa);
                    //                     Material m = ap.getMaterial();
                    //                     m.setSpecularColor(new Color3f(GRAY));
                    //                     m.setShininess(64);
                    if (colored)
                        shape.setAppearance(createAppearance(null, true));
                    else {
                        Appearance ap = shape.getAppearance();
                        PolygonAttributes pa = ap.getPolygonAttributes();
                        if (pa == null) pa = new PolygonAttributes();
                        pa.setCullFace(PolygonAttributes.CULL_NONE);
                        ap.setPolygonAttributes(pa);
                    }
                    //for (int j = 0; j < shape.numGeometries(); j++) {
                    //    Geometry g = shape.getGeometry(j);
                    //    if (g instanceof GeometryArray) {
                    //        GeometryArray ga = (GeometryArray) g;
                    //System.out.println("GeometryArray");
                    //System.out.println("format: " + ga.getVertexFormat());
                    //float[] colors = ga.getInterleavedVertices();
                    //for (int k = 0; k < colors.length; k++)
                    //    System.out.println(colors[k]);
                    //    }
                    //}
                }
            }

            TransformGroup transGroup = new TransformGroup();
            transGroup.addChild(bg);
            BranchGroup bg2 = createBranchGroup();
            bg2.addChild(transGroup);
            offscreenGroup.addChild(bg2);
            return new Shape(bg2, transGroup);
        } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); }
        return null;
    }
 
开发者ID:wz12406,项目名称:accumulate,代码行数:59,代码来源:StdDraw3D.java

示例4: loadWavefrontObject

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
/**
 * Chargement de l'objet Wavefront (masque.obj) ainsi que les materiaux qui
 * lui sont associes
 * 
 * @param filename nom du fichier de l'objet a charger
 * @return BranchGroup branch group contenant l'objet Wavefront
 */
private static BranchGroup loadWavefrontObject(String filename) {
  ObjectFile waveFrontObject = new ObjectFile();

  Scene scene = null;

  try {

    scene = waveFrontObject.load(filename);

    BranchGroup bg = scene.getSceneGroup();

    return bg;

  } catch (Exception e) {

    e.printStackTrace();
  }

  return null;

}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:29,代码来源:ManagerObj.java

示例5: drawOBJ

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
private static Shape drawOBJ (String filename, boolean colored, boolean resize) {

        int params = 0;
        if (resize) params = ObjectFile.RESIZE | Loader.LOAD_ALL;
        
        ObjectFile loader = new ObjectFile(params);
        try {
            BranchGroup bg = loader.load(filename).getSceneGroup();
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
            bg.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
            bg.setCapability(BranchGroup.ALLOW_DETACH);

            //System.out.println("Children: " + bg.numChildren());

            for (int i = 0; i < bg.numChildren(); i++) {
                Node child = bg.getChild(i);
                if (child instanceof Shape3D) {
                    Shape3D shape = (Shape3D) child;
                    //System.out.println("shape3d");
                    //                     Appearance ap = shape.getAppearance();
                    //                     PolygonAttributes pa = ap.getPolygonAttributes();
                    //                     if (pa == null) pa = new PolygonAttributes();
                    //                     pa.setCullFace(PolygonAttributes.CULL_NONE);
                    //                     ap.setPolygonAttributes(pa);
                    //                     Material m = ap.getMaterial();
                    //                     m.setSpecularColor(new Color3f(GRAY));
                    //                     m.setShininess(64);
                    if (colored)
                        shape.setAppearance(createAppearance(null, true));
                    else {
                        Appearance ap = shape.getAppearance();
                        PolygonAttributes pa = ap.getPolygonAttributes();
                        if (pa == null) pa = new PolygonAttributes();
                        pa.setCullFace(PolygonAttributes.CULL_NONE);
                        ap.setPolygonAttributes(pa);
                    }
                    //for (int j = 0; j < shape.numGeometries(); j++) {
                    //    Geometry g = shape.getGeometry(j);
                    //    if (g instanceof GeometryArray) {
                    //        GeometryArray ga = (GeometryArray) g;
                    //System.out.println("GeometryArray");
                    //System.out.println("format: " + ga.getVertexFormat());
                    //float[] colors = ga.getInterleavedVertices();
                    //for (int k = 0; k < colors.length; k++)
                    //    System.out.println(colors[k]);
                    //    }
                    //}
                }
            }

            TransformGroup transGroup = new TransformGroup();
            transGroup.addChild(bg);
            BranchGroup bg2 = createBranchGroup();
            bg2.addChild(transGroup);
            offscreenGroup.addChild(bg2);
            return new Shape(bg2, transGroup);
        } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); }
        return null;
    }
 
开发者ID:fracpete,项目名称:princeton-java-introduction,代码行数:61,代码来源:StdDraw3D.java

示例6: TestSpacecraft

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
/**
 * Initialize with input scale factor.  The model BranchGroup is retained
 * allowing for the getMassDyadic function to retrieve vertex info.
 * 
 * @param    scale    Scale factor for the model.  A scale of
 */
public TestSpacecraft(double scale) {
  sf = (float) scale;
    // allow the state of the model to be changed after compilation
  setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // add the visual representation to the TransformGroup
  try {
      // first try the sparkymatmesh.obj model
    Scene modelScene = null;
    ObjectFile of = new ObjectFile();
    of.setFlags(ObjectFile.RESIZE     |
               ObjectFile.TRIANGULATE |
               ObjectFile.STRIPIFY);   
      // load the mesh defined below
    URL sparkyURL = TestSpacecraft.class.getResource("sparkymatmesh.obj");
    if (sparkyURL == null) {
      System.out.println("Can't find sphere.obj");
      throw new java.io.FileNotFoundException("Can't find sparkymesh.obj" +
                                                                       this);
    }
    
    modelScene = of.load(sparkyURL);
    
      // rotate model axis to align with simulation axis.  Also, offset
      // it along the x-axis so the cg and origin coincide.
    Vector3d trans = new Vector3d();  // offset along x-axis
    trans.x = XOFF*scale;
    Matrix3d m1 = new Matrix3d();
    m1.rotX(Math.PI/2.0);          // nose down into plane
    Matrix3d m2 = new Matrix3d();
    m2.rotZ(Math.PI/2.0);          // nose yaw into X
    m2.mul(m1);                    // combine
    Transform3D t3d = new Transform3D(m2, trans, scale);
    TransformGroup tg = new TransformGroup(t3d);
    modelBG = modelScene.getSceneGroup();
    
    tg.addChild(modelBG);
    addChild(tg);
  } catch(java.io.FileNotFoundException ex) {
      // if the above didn't work, load a sphere
    addChild(new Sphere(1.0f));
  }
}
 
开发者ID:motoq,项目名称:vse,代码行数:50,代码来源:TestSpacecraft.java

示例7: SparkySpacecraft

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
public SparkySpacecraft(double scale) {
    // zero emissive (doesn't glow) - use black
  Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    // ambient and diffuse blue (normal object)
  Color3f blue = new Color3f(0.3f, 0.3f, 0.8f);
    // specular near white (normal object)
  Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);

    // Material(ambient, emissive, diffuse, specular, shininess)
  Material blueMat= new Material(blue, black, blue, specular, 25.0f);
  blueMat.setLightingEnable(true);

  Appearance blueApp = new Appearance();
  blueApp.setMaterial(blueMat);

    // allow the state of the model to be changed after compilation
  setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // add the visual representation to the TransformGroup
  try {
      // first try the sparkymesh.obj model
    Scene modelScene = null;
    ObjectFile of = new ObjectFile();
    of.setFlags(ObjectFile.RESIZE     |
               ObjectFile.TRIANGULATE |
               ObjectFile.STRIPIFY);   
      // load the mesh defined below
    URL sparkyURL = SparkySpacecraft.class.getResource("sparkymesh.obj");
    if (sparkyURL == null) {
      throw new java.io.FileNotFoundException("Can't find sparkymesh.obj" +
                                                                       this);
    }
    modelScene = of.load(sparkyURL);
      // rotate model axis to align with simulation axis.  Also, offset
      // it along the x-axis so the cg and origin coincide.
    Vector3d trans = new Vector3d();  // offset along x-axis
    trans.x = XOFF*scale;
    Matrix3d m1 = new Matrix3d();
    m1.rotX(Math.PI/2.0);          // nose down into plane
    Matrix3d m2 = new Matrix3d();
    m2.rotZ(Math.PI/2.0);          // nose yaw into X
    m2.mul(m1);                    // combine
    Transform3D t3d = new Transform3D(m2, trans, scale);
    TransformGroup tg = new TransformGroup(t3d);
    BranchGroup modelBG = modelScene.getSceneGroup();
      // modify appearance here
    Enumeration modelE = modelBG.getAllChildren();
    while(modelE.hasMoreElements()) {
      Object modelO = modelE.nextElement();
      if (modelO instanceof Shape3D) {
       Shape3D modelS3D = (Shape3D) modelO;
       modelS3D.setAppearance(blueApp);
      }
    }
    tg.addChild(modelBG);
    addChild(tg);
  } catch(java.io.FileNotFoundException ex) {
      // if the above didn't work, load a sphere
    addChild(new Sphere(1.0f, blueApp));
  }
}
 
开发者ID:motoq,项目名称:vse,代码行数:62,代码来源:SparkySpacecraft.java

示例8: SparkySpacecraftJ3DMat

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
public SparkySpacecraftJ3DMat(double scale) {
    // zero emissive (doesn't glow) - use black
  Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    // ambient and diffuse blue (normal object)
  Color3f blue = new Color3f(0.3f, 0.3f, 0.8f);
  Color3f red  = new Color3f(0.8f, 0.3f, 0.3f);
    // specular near white (normal object)
  Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);

    // Material(ambient, emissive, diffuse, specular, shininess)
  Material blueMat= new Material(blue, black, blue, specular, 25.0f);
  blueMat.setLightingEnable(true);
  Material redMat= new Material(red, black, red, specular, 25.0f);
  redMat.setLightingEnable(true);

  Appearance blueApp = new Appearance();
  blueApp.setMaterial(blueMat);
  Appearance redApp = new Appearance();
  redApp.setMaterial(redMat);

    // allow the state of the model to be changed after compilation
  setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // add the visual representation to the TransformGroup
  try {
      // first try the sparkymesh.obj model
    Scene modelScene = null;
    ObjectFile of = new ObjectFile();
    of.setFlags(ObjectFile.RESIZE     |
               ObjectFile.TRIANGULATE |
               ObjectFile.STRIPIFY);   
      // load the mesh defined below
    URL sparkyURL =
        SparkySpacecraftJ3DMat.class.getResource("sparkymesh_noball.obj");
    if (sparkyURL == null) {
      throw new java.io.FileNotFoundException("Can't find sparkymesh.obj" +
                                                                       this);
    }
    modelScene = of.load(sparkyURL);
      // rotate model axis to align with simulation axis.  Also, offset
      // it along the x-axis so the cg and origin coincide.
    Vector3d trans = new Vector3d();  // offset along x-axis
    trans.x = XOFF*scale;
    Matrix3d m1 = new Matrix3d();
    m1.rotX(Math.PI/2.0);          // nose down into plane
    Matrix3d m2 = new Matrix3d();
    m2.rotZ(Math.PI/2.0);          // nose yaw into X
    m2.mul(m1);                    // combine
    Transform3D t3d = new Transform3D(m2, trans, scale);
    TransformGroup tg = new TransformGroup(t3d);
    BranchGroup modelBG = modelScene.getSceneGroup();
      // modify appearance here
    Enumeration modelE = modelBG.getAllChildren();
    while(modelE.hasMoreElements()) {
      Object modelO = modelE.nextElement();
      if (modelO instanceof Shape3D) {
       Shape3D modelS3D = (Shape3D) modelO;
       modelS3D.setAppearance(blueApp);
      }
    }
    tg.addChild(modelBG);
    addChild(tg);
    addChild(new Sphere(0.25f*((float) scale), redApp));
  } catch(java.io.FileNotFoundException ex) {
      // if the above didn't work, load a sphere
    addChild(new Sphere(1.0f, blueApp));
  }
}
 
开发者ID:motoq,项目名称:vse,代码行数:69,代码来源:SparkySpacecraftJ3DMat.java

示例9: ObjectLoader

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
public ObjectLoader() {

		setLayout(new BorderLayout());
		GraphicsConfiguration graphicsConfig = SimpleUniverse
				.getPreferredConfiguration();

		Canvas3D canvas3D = new Canvas3D(graphicsConfig);
		add(canvas3D);
		canvas3D.setSize(1200, 800);
		canvas3D.setVisible(true);

		BranchGroup scene = new BranchGroup();

		ObjectFile loader = new ObjectFile(ObjectFile.LOAD_ALL);
		loader.setFlags(ObjectFile.RESIZE);

		Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);

		BoundingSphere bounds =

		new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

		Vector3f light1Direction = new Vector3f(2.0f, 12.0f, -12.0f);

		DirectionalLight light1

		= new DirectionalLight(light1Color, light1Direction);

		light1.setInfluencingBounds(bounds);

		scene.addChild(light1);

		Scene modelScene = null;

		try {
			modelScene = loader.load("Images/gargoyle.obj");

		} catch (Exception e) {

		}

		scene.addChild(modelScene.getSceneGroup());

		SimpleUniverse universe = new SimpleUniverse(canvas3D);
		universe.getViewingPlatform().setNominalViewingTransform();

		universe.addBranchGraph(scene);
		
		ViewingPlatform viewPlatform = universe.getViewingPlatform();
	    TransformGroup viewTransform = viewPlatform.getViewPlatformTransform();
	    Transform3D t3d = new Transform3D();
	    viewTransform.getTransform(t3d);
	    t3d.lookAt(new Point3d(0, 0, 4), new Point3d(0, 0, 0), new Vector3d(0, 1, 0));
	    t3d.invert();
	    viewTransform.setTransform(t3d);

	}
 
开发者ID:GettingNifty,项目名称:Heavy-Evil,代码行数:58,代码来源:ObjectLoader.java

示例10: modelFromFile

import com.sun.j3d.loaders.objectfile.ObjectFile; //导入依赖的package包/类
/**
 * Helper method to create model from .obj file.
 *
 * @param modelFile file name
 * @throws java.io.FileNotFoundException
 */
protected void modelFromFile(String modelFile) throws FileNotFoundException {
    ObjectFile objectFile = new ObjectFile();
    Scene scene = objectFile.load(modelFile);
    transformGroup.addChild(scene.getSceneGroup());
}
 
开发者ID:DrTon,项目名称:jMAVSim,代码行数:12,代码来源:KinematicObject.java


注:本文中的com.sun.j3d.loaders.objectfile.ObjectFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。