Search in sources :

Example 1 with FbxMesh

use of com.jme3.scene.plugins.fbx.objects.FbxMesh in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method link.

@Override
public void link(FbxObject otherObject) {
    if (otherObject instanceof FbxMaterial) {
        FbxMaterial m = (FbxMaterial) otherObject;
        Material mat = m.material;
        if (cullMode != FaceCullMode.Back)
            mat.getAdditionalRenderState().setFaceCullMode(cullMode);
        for (Geometry g : mesh.geometries) {
            if (g.getUserData("FBXMaterial") != null) {
                if ((Integer) g.getUserData("FBXMaterial") == mesh.lastMaterialId)
                    g.setMaterial(mat);
            } else {
                g.setMaterial(mat);
            }
        }
        mesh.lastMaterialId++;
    } else if (otherObject instanceof FbxNode) {
        FbxNode n = (FbxNode) otherObject;
        node.attachChild(n.node);
        n.parentFbxNode = this;
        if (isLimb() && n.isLimb()) {
            if (bone == null)
                bone = new Bone(name);
            if (n.bone == null)
                n.bone = new Bone(n.name);
            bone.addChild(n.bone);
        }
    } else if (otherObject instanceof FbxMesh) {
        FbxMesh m = (FbxMesh) otherObject;
        m.setParent(node);
        m.parent = this;
        mesh = m;
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material) Bone(com.jme3.animation.Bone)

Example 2 with FbxMesh

use of com.jme3.scene.plugins.fbx.objects.FbxMesh in project jmonkeyengine by jMonkeyEngine.

the class FbxSkin method generateSkinning.

public void generateSkinning() {
    for (FbxMesh fbxMesh : toSkin) {
        if (fbxMesh.geometries == null)
            continue;
        Mesh firstMesh = fbxMesh.geometries.get(0).getMesh();
        int maxWeightsPerVert = generateBoneData(firstMesh, fbxMesh);
        for (int i = 0; i < fbxMesh.geometries.size(); ++i) {
            Mesh mesh = fbxMesh.geometries.get(i).getMesh();
            if (mesh != firstMesh) {
                mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.BoneWeight));
                mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.BoneIndex));
                mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.HWBoneWeight));
                mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.HWBoneIndex));
            }
            mesh.setMaxNumWeights(maxWeightsPerVert);
            mesh.generateBindPose(true);
        }
    }
}
Also used : Mesh(com.jme3.scene.Mesh)

Example 3 with FbxMesh

use of com.jme3.scene.plugins.fbx.objects.FbxMesh in project jmonkeyengine by jMonkeyEngine.

the class FbxMesh method toIRMesh.

/**
     * Convert FBXMesh to IRMesh.
     */
public IrMesh toIRMesh() {
    IrMesh newMesh = new IrMesh();
    newMesh.polygons = new IrPolygon[polygons.length];
    int polygonVertexIndex = 0;
    int positionIndex = 0;
    FbxLayer layer0 = layers[0];
    FbxLayer layer1 = layers.length > 1 ? layers[1] : null;
    for (int i = 0; i < polygons.length; i++) {
        FbxPolygon polygon = polygons[i];
        IrPolygon irPolygon = new IrPolygon();
        irPolygon.vertices = new IrVertex[polygon.indices.length];
        for (int j = 0; j < polygon.indices.length; j++) {
            positionIndex = polygon.indices[j];
            IrVertex irVertex = new IrVertex();
            irVertex.pos = positions[positionIndex];
            if (layer0 != null) {
                irVertex.norm = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Normal, i, polygonVertexIndex, positionIndex, 0);
                irVertex.tang = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Tangent, i, polygonVertexIndex, positionIndex, 0);
                irVertex.bitang = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Binormal, i, polygonVertexIndex, positionIndex, 0);
                irVertex.uv0 = (Vector2f) layer0.getVertexData(FbxLayerElement.Type.UV, i, polygonVertexIndex, positionIndex, 0);
                irVertex.color = (ColorRGBA) layer0.getVertexData(FbxLayerElement.Type.Color, i, polygonVertexIndex, positionIndex, 0);
                irVertex.material = (Integer) layer0.getVertexData(FbxLayerElement.Type.Material, i, polygonVertexIndex, positionIndex, 0);
                irVertex.smoothing = (Integer) layer0.getVertexData(FbxLayerElement.Type.Smoothing, i, polygonVertexIndex, positionIndex, 0);
            }
            if (layer1 != null) {
                irVertex.uv1 = (Vector2f) layer1.getVertexData(FbxLayerElement.Type.UV, i, polygonVertexIndex, positionIndex, 0);
            }
            if (boneIndices != null) {
                ArrayList<Integer> boneIndicesForVertex = boneIndices[positionIndex];
                ArrayList<Float> boneWeightsForVertex = boneWeights[positionIndex];
                if (boneIndicesForVertex != null) {
                    irVertex.boneWeightsIndices = toBoneWeightIndices(boneIndicesForVertex, boneWeightsForVertex);
                }
            }
            irPolygon.vertices[j] = irVertex;
            polygonVertexIndex++;
        }
        newMesh.polygons[i] = irPolygon;
    }
    // Ensure "inspection vertex" specifies that mesh has bone indices / weights
    if (boneIndices != null && newMesh.polygons[0].vertices[0] == null) {
        newMesh.polygons[0].vertices[0].boneWeightsIndices = new IrBoneWeightIndex[0];
    }
    return newMesh;
}
Also used : IrPolygon(com.jme3.scene.plugins.IrPolygon) IrMesh(com.jme3.scene.plugins.IrMesh) IrVertex(com.jme3.scene.plugins.IrVertex)

Example 4 with FbxMesh

use of com.jme3.scene.plugins.fbx.objects.FbxMesh in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method fromElement.

@Override
public void fromElement(FbxElement element) {
    super.fromElement(element);
    Vector3f localTranslation = new Vector3f();
    Quaternion localRotation = new Quaternion();
    Vector3f localScale = new Vector3f(Vector3f.UNIT_XYZ);
    Quaternion preRotation = new Quaternion();
    for (FbxElement e2 : element.getFbxProperties()) {
        String propName = (String) e2.properties.get(0);
        String type = (String) e2.properties.get(3);
        if (propName.equals("Lcl Translation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            //.divideLocal(unitSize);
            localTranslation.set((float) x, (float) y, (float) z);
        } else if (propName.equals("Lcl Rotation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            localRotation.fromAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD);
        } else if (propName.equals("Lcl Scaling")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            //.multLocal(unitSize);
            localScale.set((float) x, (float) y, (float) z);
        } else if (propName.equals("PreRotation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            preRotation.set(FbxNodeUtil.quatFromBoneAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD));
        } else if (propName.equals("InheritType")) {
            int inheritType = (Integer) e2.properties.get(4);
            inheritMode = InheritMode.values()[inheritType];
        } else if (propName.equals("Visibility")) {
            visibility = (Double) e2.properties.get(4);
        } else if (type.contains("U")) {
            String userDataKey = (String) e2.properties.get(0);
            String userDataType = (String) e2.properties.get(1);
            Object userDataValue;
            if (userDataType.equals("KString")) {
                userDataValue = (String) e2.properties.get(4);
            } else if (userDataType.equals("int")) {
                userDataValue = (Integer) e2.properties.get(4);
            } else if (userDataType.equals("double")) {
                // NOTE: jME3 does not support doubles in UserData.
                //       Need to convert to float.
                userDataValue = ((Double) e2.properties.get(4)).floatValue();
            } else if (userDataType.equals("Vector")) {
                float x = ((Double) e2.properties.get(4)).floatValue();
                float y = ((Double) e2.properties.get(5)).floatValue();
                float z = ((Double) e2.properties.get(6)).floatValue();
                userDataValue = new Vector3f(x, y, z);
            } else {
                logger.log(Level.WARNING, "Unsupported user data type: {0}. Ignoring.", userDataType);
                continue;
            }
            userData.put(userDataKey, userDataValue);
        }
    }
    // Create local transform
    // TODO: take into account Maya-style transforms (pre / post rotation ..)
    jmeLocalNodeTransform.setTranslation(localTranslation);
    jmeLocalNodeTransform.setRotation(localRotation);
    jmeLocalNodeTransform.setScale(localScale);
    if (element.getChildById("Vertices") != null) {
        // This is an old-style FBX 6.1
        // Meshes could be embedded inside the node..
        // Inject the mesh into ourselves..
        FbxMesh mesh = new FbxMesh(assetManager, sceneFolderName);
        mesh.fromElement(element);
        connectObject(mesh);
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) FbxMesh(com.jme3.scene.plugins.fbx.mesh.FbxMesh) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) CullHint(com.jme3.scene.Spatial.CullHint)

Example 5 with FbxMesh

use of com.jme3.scene.plugins.fbx.objects.FbxMesh in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method loadObjects.

private void loadObjects(FbxElement element) throws IOException {
    FbxObject obj = null;
    for (FbxElement e : element.children) {
        switch(e.id) {
            case "Geometry":
                FbxMesh mesh = new FbxMesh(this, e);
                obj = mesh;
                if (mesh.geometries != null)
                    geomMap.put(mesh.id, mesh);
                break;
            case "Material":
                obj = new FbxMaterial(this, e);
                break;
            case "Model":
                FbxNode node = new FbxNode(this, e);
                obj = node;
                modelMap.put(node.id, node);
                if (node.isLimb())
                    limbMap.put(node.id, node);
                break;
            case "Pose":
                FbxBindPose pose = new FbxBindPose(this, e);
                obj = pose;
                bindMap.put(pose.id, pose);
                break;
            case "Texture":
                obj = new FbxTexture(this, e);
                break;
            case "Video":
                obj = new FbxImage(this, e);
                break;
            case "Deformer":
                obj = loadDeformer(e);
                break;
            case "AnimationLayer":
                FbxObject layer = new FbxObject(this, e);
                obj = layer;
                alayerMap.put(layer.id, layer);
                break;
            case "AnimationCurve":
                obj = new FbxAnimCurve(this, e);
                break;
            case "AnimationCurveNode":
                obj = new FbxAnimNode(this, e);
                break;
            default:
                obj = null;
        }
        if (obj != null)
            allObjects.put(obj.id, obj);
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxObject(com.jme3.scene.plugins.fbx.objects.FbxObject) FbxNode(com.jme3.scene.plugins.fbx.objects.FbxNode) FbxAnimCurve(com.jme3.scene.plugins.fbx.objects.FbxAnimCurve) FbxTexture(com.jme3.scene.plugins.fbx.objects.FbxTexture) FbxMesh(com.jme3.scene.plugins.fbx.objects.FbxMesh) FbxBindPose(com.jme3.scene.plugins.fbx.objects.FbxBindPose) FbxAnimNode(com.jme3.scene.plugins.fbx.objects.FbxAnimNode) FbxMaterial(com.jme3.scene.plugins.fbx.objects.FbxMaterial) FbxImage(com.jme3.scene.plugins.fbx.objects.FbxImage)

Aggregations

FbxMesh (com.jme3.scene.plugins.fbx.mesh.FbxMesh)3 Vector3f (com.jme3.math.Vector3f)2 Mesh (com.jme3.scene.Mesh)2 FbxLimbNode (com.jme3.scene.plugins.fbx.anim.FbxLimbNode)2 FbxElement (com.jme3.scene.plugins.fbx.file.FbxElement)2 FbxObject (com.jme3.scene.plugins.fbx.obj.FbxObject)2 FbxMesh (com.jme3.scene.plugins.fbx.objects.FbxMesh)2 FbxNode (com.jme3.scene.plugins.fbx.objects.FbxNode)2 Bone (com.jme3.animation.Bone)1 AssetLoadException (com.jme3.asset.AssetLoadException)1 Material (com.jme3.material.Material)1 Quaternion (com.jme3.math.Quaternion)1 Geometry (com.jme3.scene.Geometry)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 CullHint (com.jme3.scene.Spatial.CullHint)1 VertexBuffer (com.jme3.scene.VertexBuffer)1 IrMesh (com.jme3.scene.plugins.IrMesh)1 IrPolygon (com.jme3.scene.plugins.IrPolygon)1 IrVertex (com.jme3.scene.plugins.IrVertex)1