示例#1
0
  protected void simpleInitGame() {
    if (modelToLoad == null) {
      modelToLoad =
          TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/model/char.3ds");
    }
    try {
      MaxToJme C1 = new MaxToJme();
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
      Node r1 =
          (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
      // Node r = new Node("parent stuff");
      // r.attachChild(C1.get(new BufferedInputStream(modelToLoad.openStream()), BO));
      // r.setLocalScale(.1f);
      r1.setLocalScale(.1f);
      if (r1.getChild(0).getControllers().size() != 0) r1.getChild(0).getController(0).setSpeed(20);

      Quaternion temp = new Quaternion();
      temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
      rootNode.setLocalRotation(temp);
      r1.setLocalTranslation(new Vector3f(10, 0, 0));
      // rootNode.attachChild(r);
      rootNode.attachChild(r1);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Failed to load Max file", e);
    }
  }
示例#2
0
  public Enemy(String id, Renderer renderer) {
    super(id, null);

    URL model = getClass().getClassLoader().getResource("fokker.jme");
    Spatial ship = null;
    try {
      ship = (Spatial) BinaryImporter.getInstance().load(model.openStream());
    } catch (IOException e) {
      e.printStackTrace();
    }

    ship.setLocalScale(.2f);
    TextureState ts = renderer.createTextureState();
    ts.setEnabled(true);
    ts.setTexture(
        TextureManager.loadTexture(
            getClass().getClassLoader().getResource("fokker.jpg"),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear));
    ship.setRenderState(ts);
    ship.setNormalsMode(NormalsMode.AlwaysNormalize);
    ship.setModelBound(new BoundingBox());
    ship.updateModelBound();

    //        ship.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Z));
    setModel(ship);

    Vector3f[] points = new Vector3f[6];
    points[0] = new Vector3f(110, 0, 110);
    points[1] = new Vector3f(110, 0, 50);
    points[2] = new Vector3f(-20, 0, 10);
    points[3] = new Vector3f(20, 0, -20);
    points[4] = new Vector3f(-90, 0, -90);
    points[5] = new Vector3f(0, 0, 110);
    endPoint = points[5];

    CatmullRomCurve curve = new CatmullRomCurve("Curve", points);
    curve.setSteps(512);
    //        ship.setLocalTranslation(points[0]);
    //        curve.setCullHint(CullHint.Always);

    CurveController curveController = new CurveController(curve, ship);
    ship.addController(curveController);
    curveController.setRepeatType(Controller.RT_CLAMP);
    curveController.setSpeed(0.05f);
    curveController.setAutoRotation(true);
    curveController.setUpVector(new Vector3f(0, 0.5f, 0));

    attachChild(curve);

    ExplosionFactory.warmup();
  }
示例#3
0
  protected void simpleInitGame() {
    // Setup camera
    cam.setFrustumPerspective(
        55.0f, (float) display.getWidth() / (float) display.getHeight(), 1, 1000);

    // Setup lights
    PointLight light = new PointLight();
    light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
    light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
    light.setLocation(new Vector3f(0, 30, 0));
    light.setEnabled(true);
    lightState.attach(light);

    // Add dummy objects to rootNode
    rootNode.attachChild(createObjects());

    try {
      MaxToJme C1 = new MaxToJme();
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      URL maxFile =
          TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/model/Character.3DS");
      C1.convert(new BufferedInputStream(maxFile.openStream()), BO);
      Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
      r.setLocalScale(.1f);
      if (r.getChild(0).getControllers().size() != 0) r.getChild(0).getController(0).setSpeed(20);
      Quaternion temp = new Quaternion();
      temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
      r.setLocalRotation(temp);
      r.setLocalTranslation(new Vector3f(0, 3, 0));
      rootNode.attachChild(r);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Error loading max file", e);
    }

    // Setup renderpasses
    RenderPass rootPass = new RenderPass();
    rootPass.add(rootNode);
    pManager.add(rootPass);

    sketchRenderPass = new SketchRenderPass(cam, 2);
    if (!sketchRenderPass.isSupported()) {
      Text t = new Text("Text", "GLSL Not supported on this computer.");
      t.setRenderQueueMode(Renderer.QUEUE_ORTHO);
      t.setLightCombineMode(LightState.OFF);
      t.setLocalTranslation(new Vector3f(0, 20, 0));
      fpsNode.attachChild(t);
    } else {
      sketchRenderPass.add(rootNode);
      pManager.add(sketchRenderPass);
    }

    if (!sketchRenderPass.isSupported()) {
      Text t = new Text("Text", "GLSL Not supported on this computer.");
      t.setRenderQueueMode(Renderer.QUEUE_ORTHO);
      t.setLightCombineMode(LightState.OFF);
      t.setLocalTranslation(new Vector3f(0, 20, 0));
      fpsNode.attachChild(t);
    }

    RenderPass fpsPass = new RenderPass();
    fpsPass.add(fpsNode);
    pManager.add(fpsPass);

    // Initialize keybindings
    KeyBindingManager.getKeyBindingManager().set("1", KeyInput.KEY_1);
    KeyBindingManager.getKeyBindingManager().set("2", KeyInput.KEY_2);
    KeyBindingManager.getKeyBindingManager().set("3", KeyInput.KEY_3);
    KeyBindingManager.getKeyBindingManager().set("4", KeyInput.KEY_4);
    KeyBindingManager.getKeyBindingManager().set("5", KeyInput.KEY_5);
    KeyBindingManager.getKeyBindingManager().set("6", KeyInput.KEY_6);
    KeyBindingManager.getKeyBindingManager().set("7", KeyInput.KEY_7);
    KeyBindingManager.getKeyBindingManager().set("8", KeyInput.KEY_8);
    KeyBindingManager.getKeyBindingManager().set("9", KeyInput.KEY_9);
    KeyBindingManager.getKeyBindingManager().set("0", KeyInput.KEY_0);

    KeyBindingManager.getKeyBindingManager().set("y", KeyInput.KEY_Y);
    KeyBindingManager.getKeyBindingManager().set("h", KeyInput.KEY_H);

    KeyBindingManager.getKeyBindingManager().set("shot", KeyInput.KEY_F4);
  }
  /**
   * 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);
  }
示例#5
0
  /**
   * set up the scene
   *
   * @see com.jme.app.AbstractGame#initGame()
   */
  protected void simpleInitGame() {
    display.setTitle("Joint Animation");
    display.setVSyncEnabled(true);
    cam.setLocation(new Vector3f(0.0f, 0.0f, 200.0f));
    cam.update();
    ((FirstPersonHandler) input).getKeyboardLookHandler().setActionSpeed(100);

    lightState.setEnabled(false);

    try {
      ResourceLocatorTool.addResourceLocator(
          ResourceLocatorTool.TYPE_TEXTURE,
          new SimpleResourceLocator(
              TestFireMilk.class.getClassLoader().getResource("jmetest/data/model/msascii/")));
      ResourceLocatorTool.addResourceLocator(
          ResourceLocatorTool.TYPE_TEXTURE,
          new SimpleResourceLocator(
              TestFireMilk.class.getClassLoader().getResource("jmetest/data/texture/")));
    } catch (URISyntaxException e1) {
      logger.log(Level.WARNING, "unable to setup texture directories.", e1);
    }

    MilkToJme converter = new MilkToJme();
    URL MSFile =
        TestFireMilk.class.getClassLoader().getResource("jmetest/data/model/msascii/run.ms3d");
    ByteArrayOutputStream BO = new ByteArrayOutputStream();

    try {
      converter.convert(MSFile.openStream(), BO);
    } catch (IOException e) {
      logger.info("IO problem writting the file!!!");
      logger.info(e.getMessage());
      System.exit(0);
    }

    i = null;
    try {
      i = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
    } catch (IOException e) {
      logger.info("darn exceptions:" + e.getMessage());
    }
    ((JointController) i.getController(0)).setSpeed(1.0f);
    ((JointController) i.getController(0)).setRepeatType(Controller.RT_CYCLE);
    i.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
    rootNode.attachChild(i);

    AlphaState as1 = display.getRenderer().createAlphaState();
    as1.setBlendEnabled(true);
    as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
    as1.setDstFunction(AlphaState.DB_ONE);
    as1.setTestEnabled(true);
    as1.setTestFunction(AlphaState.TF_GREATER);
    as1.setEnabled(true);

    TextureState ts = display.getRenderer().createTextureState();
    ts.setTexture(
        TextureManager.loadTexture("flaresmall.jpg", Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR));
    ts.setEnabled(true);

    ParticleMesh manager = ParticleFactory.buildParticles("particles", 200);
    manager.setEmissionDirection(new Vector3f(0.0f, 1.0f, 0.0f));
    manager.setMaximumAngle(0.20943952f);
    manager.getParticleController().setSpeed(1.0f);
    manager.setMinimumLifeTime(150.0f);
    manager.setMaximumLifeTime(225.0f);
    manager.setStartSize(8.0f);
    manager.setEndSize(4.0f);
    manager.setStartColor(new ColorRGBA(1.0f, 0.312f, 0.121f, 1.0f));
    manager.setEndColor(new ColorRGBA(1.0f, 0.312f, 0.121f, 0.0f));
    manager.getParticleController().setControlFlow(false);
    manager.setInitialVelocity(0.12f);
    manager.setGeometry((Geometry) (i.getChild(0)));

    manager.warmUp(60);
    manager.setRenderState(ts);
    manager.setRenderState(as1);
    manager.setLightCombineMode(LightState.OFF);
    manager.setTextureCombineMode(TextureState.REPLACE);
    ZBufferState zstate = display.getRenderer().createZBufferState();
    zstate.setEnabled(false);
    manager.setRenderState(zstate);
    rootNode.attachChild(manager);
  }