Search in sources :

Example 1 with FbxId

use of com.jme3.scene.plugins.fbx.file.FbxId in project jmonkeyengine by jMonkeyEngine.

the class FbxBindPose method fromElement.

@Override
public void fromElement(FbxElement element) {
    super.fromElement(element);
    for (FbxElement child : element.children) {
        if (!child.id.equals("PoseNode")) {
            continue;
        }
        FbxId node = null;
        float[] matData = null;
        for (FbxElement e : child.children) {
            if (e.id.equals("Node")) {
                node = FbxId.create(e.properties.get(0));
            } else if (e.id.equals("Matrix")) {
                double[] matDataDoubles = (double[]) e.properties.get(0);
                if (matDataDoubles.length != 16) {
                    // corrupt
                    throw new UnsupportedOperationException("Bind pose matrix " + "must have 16 doubles, but it has " + matDataDoubles.length + ". Data is corrupt");
                }
                matData = new float[16];
                for (int i = 0; i < matDataDoubles.length; i++) {
                    matData[i] = (float) matDataDoubles[i];
                }
            }
        }
        if (node != null && matData != null) {
            Matrix4f matrix = new Matrix4f(matData);
            bindPose.put(node, matrix);
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) Matrix4f(com.jme3.math.Matrix4f) FbxId(com.jme3.scene.plugins.fbx.file.FbxId)

Example 2 with FbxId

use of com.jme3.scene.plugins.fbx.file.FbxId in project jmonkeyengine by jMonkeyEngine.

the class FbxLoader method applyBindPoses.

/**
     * Copies the bind poses from FBX BindPose objects to FBX nodes.
     * Must be called prior to {@link #updateWorldTransforms()}.
     */
private void applyBindPoses() {
    for (FbxBindPose bindPose : bindPoses) {
        Map<FbxId, Matrix4f> bindPoseData = bindPose.getJmeObject();
        logger.log(Level.INFO, "Applying {0} bind poses", bindPoseData.size());
        for (Map.Entry<FbxId, Matrix4f> entry : bindPoseData.entrySet()) {
            FbxObject obj = objectMap.get(entry.getKey());
            if (obj instanceof FbxNode) {
                FbxNode node = (FbxNode) obj;
                node.setWorldBindPose(entry.getValue());
            } else {
                logger.log(Level.WARNING, "Bind pose can only be applied to FBX nodes. Ignoring.");
            }
        }
    }
}
Also used : FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) FbxNode(com.jme3.scene.plugins.fbx.node.FbxNode) Matrix4f(com.jme3.math.Matrix4f) FbxBindPose(com.jme3.scene.plugins.fbx.anim.FbxBindPose) HashMap(java.util.HashMap) Map(java.util.Map) FbxId(com.jme3.scene.plugins.fbx.file.FbxId)

Example 3 with FbxId

use of com.jme3.scene.plugins.fbx.file.FbxId in project jmonkeyengine by jMonkeyEngine.

the class FbxLoader method connectObjects.

private void connectObjects(FbxElement element) {
    if (objectMap.isEmpty()) {
        logger.log(Level.WARNING, "FBX file is missing object information");
        return;
    } else if (objectMap.size() == 1) {
        // Only root node (automatically added by jME3)
        logger.log(Level.WARNING, "FBX file has no objects");
        return;
    }
    for (FbxElement el : element.children) {
        if (!el.id.equals("C") && !el.id.equals("Connect")) {
            continue;
        }
        String type = (String) el.properties.get(0);
        FbxId childId;
        FbxId parentId;
        if (type.equals("OO")) {
            childId = FbxId.create(el.properties.get(1));
            parentId = FbxId.create(el.properties.get(2));
            FbxObject child = objectMap.get(childId);
            FbxObject parent;
            if (parentId.isNull()) {
                // TODO: maybe clean this up a bit..
                parent = objectMap.get(FbxId.ROOT);
            } else {
                parent = objectMap.get(parentId);
            }
            if (parent == null) {
                throw new UnsupportedOperationException("Cannot find parent object ID \"" + parentId + "\"");
            }
            parent.connectObject(child);
        } else if (type.equals("OP")) {
            childId = FbxId.create(el.properties.get(1));
            parentId = FbxId.create(el.properties.get(2));
            String propName = (String) el.properties.get(3);
            FbxObject child = objectMap.get(childId);
            FbxObject parent = objectMap.get(parentId);
            parent.connectObjectProperty(child, propName);
        } else {
            logger.log(Level.WARNING, "Unknown connection type: {0}. Ignoring.", type);
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) FbxId(com.jme3.scene.plugins.fbx.file.FbxId)

Aggregations

FbxId (com.jme3.scene.plugins.fbx.file.FbxId)3 Matrix4f (com.jme3.math.Matrix4f)2 FbxElement (com.jme3.scene.plugins.fbx.file.FbxElement)2 FbxObject (com.jme3.scene.plugins.fbx.obj.FbxObject)2 FbxBindPose (com.jme3.scene.plugins.fbx.anim.FbxBindPose)1 FbxNode (com.jme3.scene.plugins.fbx.node.FbxNode)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1