コード例 #1
0
  // 處理讀取Asset資料夾內的模型
  private Object3D loadModel(String filename, float scale) {
    Resources res = this.resource;
    AssetManager asManager = res.getAssets();
    Object3D obj3D = new Object3D(0);
    Object3D objTemp = null;

    try {
      Object3D[] model =
          Loader.load3DS(asManager.open(filename, AssetManager.ACCESS_UNKNOWN), scale);

      for (int i = 0; i < model.length; i++) {
        objTemp = model[i];
        objTemp.setCenter(SimpleVector.ORIGIN);
        objTemp.rotateX((float) (-0.5f * Math.PI));
        objTemp.rotateMesh();
        objTemp.setRotationMatrix(new Matrix());
        obj3D = Object3D.mergeObjects(obj3D, objTemp);
        obj3D.compile();
      }
      return obj3D;

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
コード例 #2
0
ファイル: EnemyView.java プロジェクト: dtrsan/robombs
  static {
    // static initializer that creates a mesh blueprint and loads the
    // textures.
    try {
      SimpleStream ss = new SimpleStream("data/weapon.jpg");
      TextureManager.getInstance().addTexture("weapon", new Texture(ss.getStream()));
      ss.close();

      ss = new SimpleStream("data/snork.md2");
      bluePrint = new ClientObject(Loader.loadMD2(ss.getStream(), 0.22f)); // 0.32f
      bluePrint.translate(0, 4.5f, 0);
      bluePrint.translateMesh();
      bluePrint.getTranslationMatrix().setIdentity();
      bluePrint.translate(100000, 100000, 100000);

      sphereBluePrint = Primitives.getSphere(9, 6);
      sphereBluePrint.build();
      sphereBluePrint.setTexture("shield");

      sphereBluePrint.calcTextureWrapSpherical();

      ss.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: CrateView.java プロジェクト: dtrsan/robombs
  static {
    try {
      SimpleStream ss = new SimpleStream("data/crate.3ds");
      bluePrint = new ClientObject(Loader.load3DS(ss.getStream(), 0.09f)[0]);
      ss.close();
      bluePrint.translate(0, -4.3f, -5);
      bluePrint.translateMesh();
      bluePrint.getTranslationMatrix().setIdentity();
      TextureInfo ti = null;
      if (!Globals.normalMapping) {
        bluePrint.setTexture("crate");
      } else {
        ti = new TextureInfo(TextureManager.getInstance().getTextureID("crate"));
        ti.add(
            TextureManager.getInstance().getTextureID("cratenormals"), TextureInfo.MODE_MODULATE);
        bluePrint.setTexture(ti);
      }

      bluePrint.getMesh().compress();
      bluePrint.build();

      Object3D child = null;
      Animation anim = new Animation(6);
      anim.setClampingMode(Animation.USE_CLAMPING);
      anim.createSubSequence("explosion");

      Loader.setVertexOptimization(false);

      for (int i = 1; i < 6; i++) {
        String name = "data/crate" + i + ".3ds";
        ss = new SimpleStream(name);
        Object3D obj = Loader.load3DS(ss.getStream(), 4.4050189f)[0];
        ss.close();
        obj.translate(0, -5f, -0.6f);
        obj.translateMesh();
        obj.getTranslationMatrix().setIdentity();
        if (!Globals.normalMapping) {
          obj.setTexture("crate");
        } else {
          obj.setTexture(ti);
        }
        obj.build();

        if (i == 1) {
          child = obj;
          child.setMesh(child.getMesh().cloneMesh(true));
        }
        obj.getMesh().compress();
        anim.addKeyFrame(obj.getMesh());
      }
      child.setAnimationSequence(anim);

      Loader.setVertexOptimization(true);

      childBluePrint = child;

      /*
       * for (int i=0; i<child.getMesh().getBoundingBox().length; i++) {
       * System.out.print(child.getMesh().getBoundingBox()[i]);
       * System.out.println("="+bluePrint.getMesh().getBoundingBox()[i]);
       * }
       */
    } catch (Exception e) {
      e.printStackTrace();
    }
  }