コード例 #1
0
 /**
  * Sets the Z-buffer state on the given node.
  *
  * <p>NOTE: This method assumes it is being called in a MT-Safe manner.
  */
 private void setZBufferState(Node node) {
   RenderManager rm = ClientContextJME.getWorldManager().getRenderManager();
   ZBufferState zbuf = (ZBufferState) rm.createRendererState(RenderState.StateType.ZBuffer);
   zbuf.setEnabled(true);
   zbuf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
   node.setRenderState(zbuf);
 }
コード例 #2
0
  /**
   * builds the trimesh.
   *
   * @see com.jme.app.SimpleGame#initGame()
   */
  protected void simpleInitGame() {
    display.setTitle("Imposter Test");
    cam.setLocation(new Vector3f(0.0f, 0.0f, 25.0f));
    cam.update();

    // setup the scene to be 'impostered'

    Md2ToJme converter = new Md2ToJme();
    ByteArrayOutputStream BO = new ByteArrayOutputStream();

    URL freak = TestMd2JmeWrite.class.getClassLoader().getResource(FILE_NAME);
    freakmd2 = null;

    try {
      long time = System.currentTimeMillis();
      converter.convert(freak.openStream(), BO);
      logger.info("Time to convert from md2 to .jme:" + (System.currentTimeMillis() - time));
    } catch (IOException e) {
      logger.info("damn exceptions:" + e.getMessage());
    }
    try {
      long time = System.currentTimeMillis();
      freakmd2 =
          (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
      logger.info("Time to convert from .jme to SceneGraph:" + (System.currentTimeMillis() - time));
    } catch (IOException e) {
      logger.info("damn exceptions:" + e.getMessage());
    }

    ((KeyframeController) freakmd2.getChild(0).getController(0)).setSpeed(10);
    ((KeyframeController) freakmd2.getChild(0).getController(0)).setRepeatType(Controller.RT_WRAP);
    fakeScene = new Node("Fake node");
    fakeScene.attachChild(freakmd2);

    // apply the appropriate texture to the imposter scene
    TextureState ts2 = display.getRenderer().createTextureState();
    ts2.setEnabled(true);
    ts2.setTexture(
        TextureManager.loadTexture(
            TestImposterNode.class.getClassLoader().getResource(TEXTURE_NAME),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear));
    fakeScene.setRenderState(ts2);

    ZBufferState buf = display.getRenderer().createZBufferState();
    buf.setEnabled(true);
    buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
    fakeScene.setRenderState(buf);
    fakeScene.updateRenderState();

    // setup the imposter node...
    iNode = new ImposterNode("model imposter", 10, display.getWidth(), display.getHeight());
    iNode.attachChild(fakeScene);
    iNode.setCameraDistance(100);
    iNode.setRedrawRate(.05f); // .05 = update texture 20 times a second on average
    //    iNode.setCameraThreshold(15*FastMath.DEG_TO_RAD);

    // Now add the imposter to a Screen Aligned billboard so the deception is complete.
    BillboardNode bnode = new BillboardNode("imposter bbnode");
    bnode.setAlignment(BillboardNode.SCREEN_ALIGNED);
    bnode.attachChild(iNode);
    rootNode.attachChild(bnode);
  }