protected void initScene() {
    mLight = new DirectionalLight(0, -0.2f, -1.0f); // set the direction
    mLight.setColor(1.0f, 1.0f, .8f);
    mLight.setPower(1);

    getCurrentScene().addLight(mLight);
    getCurrentCamera().setZ(dist);

    try {
      LoaderMD5Mesh meshParser = new LoaderMD5Mesh(this, R.raw.ingrid_mesh);
      meshParser.parse();

      LoaderMD5Anim animParser = new LoaderMD5Anim("idle", this, R.raw.ingrid_idle);
      animParser.parse();

      mSequenceIdle = (SkeletalAnimationSequence) animParser.getParsedAnimationSequence();

      animParser = new LoaderMD5Anim("walk", this, R.raw.ingrid_walk);
      animParser.parse();

      mSequenceWalk = (SkeletalAnimationSequence) animParser.getParsedAnimationSequence();

      animParser = new LoaderMD5Anim("armstretch", this, R.raw.ingrid_arm_stretch);
      animParser.parse();

      mSequenceArmStretch = (SkeletalAnimationSequence) animParser.getParsedAnimationSequence();

      animParser = new LoaderMD5Anim("bend", this, R.raw.ingrid_bend);
      animParser.parse();

      mSequenceBend = (SkeletalAnimationSequence) animParser.getParsedAnimationSequence();

      mObject = (SkeletalAnimationObject3D) meshParser.getParsedAnimationObject();
      mObject.setAnimationSequence(mSequenceWalk);
      mObject.setFps(24);
      mObject.setScale(.8f);
      mObject.play();

      addChild(mObject);
    } catch (ParsingException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  private ALight buildLight(Model l) {
    int m = l.properties.lightType != null ? l.properties.lightType : ALight.POINT_LIGHT;
    switch (m) {
      case ALight.POINT_LIGHT: // Point
        PointLight light = new PointLight();
        light.setPosition(l.properties.lclTranslation);
        light.setX(light.getX() * -1f);
        light.setRotation(l.properties.lclRotation);
        light.setPower(l.properties.intensity / 100f);
        light.setColor(l.properties.color);
        // TODO add to scene
        // mRootObject.addLight(light);
        return light;

      case ALight.DIRECTIONAL_LIGHT: // Area
        DirectionalLight lD =
            new DirectionalLight(0, -1, 0); // TODO calculate direction based on position and
        // rotation
        lD.setPosition(l.properties.lclTranslation);
        lD.setX(lD.getX() * -1f);
        lD.setRotation(l.properties.lclRotation);
        lD.setPower(l.properties.intensity / 100f);
        lD.setColor(l.properties.color);
        // TODO add to scene
        // mRootObject.addLight(lD);
        return lD;

      default:
      case ALight.SPOT_LIGHT: // Spot
        SpotLight lS = new SpotLight(); // TODO calculate direction based on position and rotation
        lS.setPosition(l.properties.lclTranslation);
        lS.setX(lS.getX() * -1f);
        lS.setRotation(l.properties.lclRotation);
        lS.setPower(l.properties.intensity / 100f);
        lS.setCutoffAngle(l.properties.coneangle);
        lS.setColor(l.properties.color);
        lS.setLookAt(0, 0, 0);
        // TODO add to scene
        // mRootObject.addLight(lS);
        return lS;
    }
  }
    protected void initScene() {
      DirectionalLight light = new DirectionalLight(0, -.6f, .4f);
      light.setPower(1);
      getCurrentScene().addLight(light);

      // -- create sky sphere
      mSphere = new Sphere(400, 8, 8);
      Material sphereMaterial = new Material();
      try {
        sphereMaterial.addTexture(new Texture("skySphere", R.drawable.skysphere));
      } catch (TextureException e1) {
        e1.printStackTrace();
      }
      mSphere.setMaterial(sphereMaterial);
      mSphere.setDoubleSided(true);
      addChild(mSphere);

      try {
        // -- load gzipped serialized object
        ObjectInputStream ois;
        GZIPInputStream zis =
            new GZIPInputStream(mContext.getResources().openRawResource(R.raw.raptor));
        ois = new ObjectInputStream(zis);
        mRaptor = new Object3D((SerializedObject3D) ois.readObject());
        Material raptorMaterial = new Material();
        raptorMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
        raptorMaterial.enableLighting(true);
        raptorMaterial.addTexture(new Texture("raptorTex", R.drawable.raptor_texture));
        mRaptor.setMaterial(raptorMaterial);
        mRaptor.setScale(.5f);
        addChild(mRaptor);
      } catch (Exception e) {
        e.printStackTrace();
      }

      // -- create a bunch of cubes that will serve as orientation helpers

      mCubes = new Object3D[30];

      mRootCube = new Cube(1);
      Material rootCubeMaterial = new Material();
      rootCubeMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
      rootCubeMaterial.enableLighting(true);
      try {
        rootCubeMaterial.addTexture(new Texture("camouflage", R.drawable.camouflage));
      } catch (TextureException e) {
        e.printStackTrace();
      }
      mRootCube.setMaterial(rootCubeMaterial);
      mRootCube.setY(-1f);
      // -- similar objects with the same material, optimize
      mRootCube.setRenderChildrenAsBatch(true);
      addChild(mRootCube);
      mCubes[0] = mRootCube;

      for (int i = 1; i < mCubes.length; ++i) {
        Object3D cube = mRootCube.clone(true);
        cube.setY(-1f);
        cube.setZ(i * 30);
        mRootCube.addChild(cube);
        mCubes[i] = cube;
      }

      // -- create a chase camera
      // the first parameter is the camera offset
      // the second parameter is the interpolation factor
      ChaseCamera chaseCamera = new ChaseCamera(new Vector3(0, 3, 16), .1f);
      // -- tell the camera which object to chase
      chaseCamera.setObjectToChase(mRaptor);
      // -- set the far plane to 1000 so that we actually see the sky sphere
      chaseCamera.setFarPlane(1000);
      replaceAndSwitchCamera(chaseCamera, 0);
    }