Search in sources :

Example 1 with Connect

use of org.rajawali3d.loader.fbx.FBXValues.Connections.Connect in project Rajawali by Rajawali.

the class LoaderFBX method setMeshTextures.

private void setMeshTextures(Object3D o, String name) throws TextureException, ParsingException {
    Stack<FBXValues.Objects.Texture> textures = mFbx.objects.textures;
    Stack<Connect> connections = mFbx.connections.connections;
    int numTex = textures.size();
    int numCon = connections.size();
    for (int i = 0; i < numTex; ++i) {
        FBXValues.Objects.Texture tex = textures.get(i);
        for (int j = 0; j < numCon; ++j) {
            Connect conn = connections.get(j);
            if (conn.object2.equals(name) && conn.object1.equals(tex.textureName)) {
                // -- one texture for now
                String textureName = tex.fileName;
                Bitmap bitmap = null;
                if (mFile == null) {
                    int identifier = mResources.getIdentifier(getFileNameWithoutExtension(textureName).toLowerCase(Locale.US), "drawable", mResources.getResourcePackageName(mResourceId));
                    bitmap = BitmapFactory.decodeResource(mResources, identifier);
                } else {
                    try {
                        String filePath = mFile.getParent() + File.separatorChar + getOnlyFileName(textureName);
                        bitmap = BitmapFactory.decodeFile(filePath);
                    } catch (Exception e) {
                        throw new ParsingException("[" + getClass().getCanonicalName() + "] Could not find file " + getOnlyFileName(textureName));
                    }
                }
                o.getMaterial().setColorInfluence(0);
                o.getMaterial().addTexture(new Texture(textureName.replaceAll("[\\W]|_", ""), bitmap));
                return;
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Connect(org.rajawali3d.loader.fbx.FBXValues.Connections.Connect) ParsingException(org.rajawali3d.loader.ParsingException) Texture(org.rajawali3d.materials.textures.Texture) TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ParsingException(org.rajawali3d.loader.ParsingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Connect

use of org.rajawali3d.loader.fbx.FBXValues.Connections.Connect in project Rajawali by Rajawali.

the class LoaderFBX method getMaterialForMesh.

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;
}
Also used : Connect(org.rajawali3d.loader.fbx.FBXValues.Connections.Connect) FBXMaterial(org.rajawali3d.loader.fbx.FBXValues.Objects.FBXMaterial) Material(org.rajawali3d.materials.Material) FBXMaterial(org.rajawali3d.loader.fbx.FBXValues.Objects.FBXMaterial) Vector3(org.rajawali3d.math.vector.Vector3) SpecularMethod(org.rajawali3d.materials.methods.SpecularMethod) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod)

Aggregations

Connect (org.rajawali3d.loader.fbx.FBXValues.Connections.Connect)2 Bitmap (android.graphics.Bitmap)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParsingException (org.rajawali3d.loader.ParsingException)1 FBXMaterial (org.rajawali3d.loader.fbx.FBXValues.Objects.FBXMaterial)1 Material (org.rajawali3d.materials.Material)1 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)1 SpecularMethod (org.rajawali3d.materials.methods.SpecularMethod)1 TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)1 Texture (org.rajawali3d.materials.textures.Texture)1 Vector3 (org.rajawali3d.math.vector.Vector3)1