Ejemplo n.º 1
0
  private Material getMaterialForMesh(Object3D o, String name) {
    Material mat = new Material();
    FBXMaterial material = null;
    Stack<Connect> conns = mFbx.connections.connections;
    int num = conns.size();
    String materialName = null;

    for (int i = 0; i < num; ++i) {
      if (conns.get(i).object2.equals(name)) {
        materialName = conns.get(i).object1;
        break;
      }
    }

    if (materialName != null) {
      Stack<FBXMaterial> materials = mFbx.objects.materials;
      num = materials.size();
      for (int i = 0; i < num; ++i) {
        if (materials.get(i).name.equals(materialName)) {
          material = materials.get(i);
          break;
        }
      }
    }

    if (material != null) {
      mat.setDiffuseMethod(new DiffuseMethod.Lambert());
      mat.enableLighting(true);
      Vector3 color = material.properties.diffuseColor;
      mat.setColor(
          Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
      color = material.properties.ambientColor;
      mat.setAmbientColor(
          Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
      float intensity = material.properties.ambientFactor.floatValue();
      mat.setAmbientIntensity(intensity, intensity, intensity);

      if (material.shadingModel.equals("phong")) {
        SpecularMethod.Phong method = new SpecularMethod.Phong();
        if (material.properties.specularColor != null) {
          color = material.properties.specularColor;
          method.setSpecularColor(
              Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f)));
        }
        if (material.properties.shininess != null)
          method.setShininess(material.properties.shininess);
      }
    }

    return mat;
  }
Ejemplo n.º 2
0
 /**
  * This material's ambient intensity for the r, g, b channels.
  *
  * @param r The value [0..1] for the red channel
  * @param g The value [0..1] for the green channel
  * @param b The value [0..1] for the blue channel
  */
 public void setAmbientIntensity(double r, double g, double b) {
   setAmbientIntensity((float) r, (float) g, (float) b);
 }