Search in sources :

Example 1 with FbxObject

use of com.jme3.scene.plugins.fbx.objects.FbxObject 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)

Example 2 with FbxObject

use of com.jme3.scene.plugins.fbx.objects.FbxObject 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 3 with FbxObject

use of com.jme3.scene.plugins.fbx.objects.FbxObject 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 4 with FbxObject

use of com.jme3.scene.plugins.fbx.objects.FbxObject 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)

Example 5 with FbxObject

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

the class FbxLoader method removeUnconnectedObjects.

private void removeUnconnectedObjects() {
    for (FbxObject object : new ArrayList<FbxObject>(objectMap.values())) {
        if (!object.isJmeObjectCreated()) {
            logger.log(Level.WARNING, "Purging orphan FBX object: {0}", object);
            objectMap.remove(object.getId());
        }
    }
}
Also used : FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) ArrayList(java.util.ArrayList)

Aggregations

FbxElement (com.jme3.scene.plugins.fbx.file.FbxElement)3 FbxObject (com.jme3.scene.plugins.fbx.obj.FbxObject)3 FbxObject (com.jme3.scene.plugins.fbx.objects.FbxObject)3 FbxId (com.jme3.scene.plugins.fbx.file.FbxId)2 FbxAnimNode (com.jme3.scene.plugins.fbx.objects.FbxAnimNode)2 FbxNode (com.jme3.scene.plugins.fbx.objects.FbxNode)2 HashMap (java.util.HashMap)2 Animation (com.jme3.animation.Animation)1 Bone (com.jme3.animation.Bone)1 BoneTrack (com.jme3.animation.BoneTrack)1 Track (com.jme3.animation.Track)1 Material (com.jme3.material.Material)1 Matrix4f (com.jme3.math.Matrix4f)1 Quaternion (com.jme3.math.Quaternion)1 Vector3f (com.jme3.math.Vector3f)1 Geometry (com.jme3.scene.Geometry)1 AnimInverval (com.jme3.scene.plugins.fbx.AnimationList.AnimInverval)1 FbxAnimCurveNode (com.jme3.scene.plugins.fbx.anim.FbxAnimCurveNode)1 FbxBindPose (com.jme3.scene.plugins.fbx.anim.FbxBindPose)1 FbxNode (com.jme3.scene.plugins.fbx.node.FbxNode)1