Search in sources :

Example 11 with FbxElement

use of com.jme3.scene.plugins.fbx.file.FbxElement 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 12 with FbxElement

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

the class SceneLoader method loadDeformer.

private FbxObject loadDeformer(FbxElement element) {
    String type = (String) element.properties.get(2);
    switch(type) {
        case "Skin":
            FbxSkin skinData = new FbxSkin(this, element);
            skinMap.put(skinData.id, skinData);
            return skinData;
        case "Cluster":
            FbxCluster clusterData = new FbxCluster(this, element);
            return clusterData;
    }
    return null;
}
Also used : FbxCluster(com.jme3.scene.plugins.fbx.objects.FbxCluster) FbxSkin(com.jme3.scene.plugins.fbx.objects.FbxSkin)

Example 13 with FbxElement

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

the class SceneLoader method loadScene.

private void loadScene(InputStream stream) throws IOException {
    logger.log(Level.FINE, "Loading scene {0}", sceneFilename);
    long startTime = System.currentTimeMillis();
    FbxFile scene = FbxReader.readFBX(stream);
    for (FbxElement e : scene.rootElements) {
        // Is it possible for elements to be in wrong order?
        switch(e.id) {
            case "GlobalSettings":
                loadGlobalSettings(e);
                break;
            case "Objects":
                loadObjects(e);
                break;
            case "Connections":
                loadConnections(e);
                break;
        }
    }
    long estimatedTime = System.currentTimeMillis() - startTime;
    logger.log(Level.FINE, "Loading done in {0} ms", estimatedTime);
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxFile(com.jme3.scene.plugins.fbx.file.FbxFile)

Example 14 with FbxElement

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

the class SceneLoader method loadConnections.

private void loadConnections(FbxElement element) {
    for (FbxElement e : element.children) {
        if (e.id.equals("C")) {
            String type = (String) e.properties.get(0);
            long objId, refId;
            FbxObject obj, ref;
            switch(type) {
                case "OO":
                    objId = (Long) e.properties.get(1);
                    refId = (Long) e.properties.get(2);
                    obj = allObjects.get(objId);
                    ref = allObjects.get(refId);
                    if (ref != null) {
                        ref.link(obj);
                    } else if (refId == 0) {
                        obj.linkToZero();
                    }
                    break;
                case "OP":
                    objId = (Long) e.properties.get(1);
                    refId = (Long) e.properties.get(2);
                    String propName = (String) e.properties.get(3);
                    obj = allObjects.get(objId);
                    ref = allObjects.get(refId);
                    if (ref != null)
                        ref.link(obj, propName);
                    break;
            }
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxObject(com.jme3.scene.plugins.fbx.objects.FbxObject)

Example 15 with FbxElement

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

the class FbxGlobalSettings method fromElement.

public void fromElement(FbxElement element) {
    // jME3 uses a +Y up, -Z forward coordinate system (same as OpenGL)
    // Luckily enough, this is also the default for FBX models.
    int timeMode = -1;
    float customFrameRate = 30.0f;
    for (FbxElement e2 : element.getFbxProperties()) {
        String propName = (String) e2.properties.get(0);
        if (propName.equals("UnitScaleFactor")) {
            unitScaleFactor = ((Double) e2.properties.get(4)).floatValue();
            if (unitScaleFactor != 100.0f) {
                logger.log(Level.WARNING, "FBX model isn't using meters for world units. Scale could be incorrect.");
            }
        } else if (propName.equals("TimeMode")) {
            timeMode = (Integer) e2.properties.get(4);
        } else if (propName.equals("CustomFrameRate")) {
            float framerate = ((Double) e2.properties.get(4)).floatValue();
            if (framerate != -1) {
                customFrameRate = framerate;
            }
        } else if (propName.equals("UpAxis")) {
            Integer upAxis = (Integer) e2.properties.get(4);
            if (upAxis != 1) {
                logger.log(Level.WARNING, "FBX model isn't using Y as up axis. Orientation could be incorrect");
            }
        } else if (propName.equals("UpAxisSign")) {
            Integer upAxisSign = (Integer) e2.properties.get(4);
            if (upAxisSign != 1) {
                logger.log(Level.WARNING, "FBX model isn't using correct up axis sign. Orientation could be incorrect");
            }
        } else if (propName.equals("FrontAxis")) {
            Integer frontAxis = (Integer) e2.properties.get(4);
            if (frontAxis != 2) {
                logger.log(Level.WARNING, "FBX model isn't using Z as forward axis. Orientation could be incorrect");
            }
        } else if (propName.equals("FrontAxisSign")) {
            Integer frontAxisSign = (Integer) e2.properties.get(4);
            if (frontAxisSign != -1) {
                logger.log(Level.WARNING, "FBX model isn't using correct forward axis sign. Orientation could be incorrect");
            }
        }
    }
    Float fps = timeModeToFps.get(timeMode);
    if (fps != null) {
        if (fps == -1f) {
            // Using custom framerate
            frameRate = customFrameRate;
        } else {
            // Use FPS from time mode.
            frameRate = fps;
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement)

Aggregations

FbxElement (com.jme3.scene.plugins.fbx.file.FbxElement)14 FbxFile (com.jme3.scene.plugins.fbx.file.FbxFile)2 FbxId (com.jme3.scene.plugins.fbx.file.FbxId)2 FbxObject (com.jme3.scene.plugins.fbx.obj.FbxObject)2 FbxObject (com.jme3.scene.plugins.fbx.objects.FbxObject)2 ColorRGBA (com.jme3.math.ColorRGBA)1 Matrix4f (com.jme3.math.Matrix4f)1 Quaternion (com.jme3.math.Quaternion)1 Vector3f (com.jme3.math.Vector3f)1 CullHint (com.jme3.scene.Spatial.CullHint)1 FbxMesh (com.jme3.scene.plugins.fbx.mesh.FbxMesh)1 FbxGlobalSettings (com.jme3.scene.plugins.fbx.misc.FbxGlobalSettings)1 FbxAnimCurve (com.jme3.scene.plugins.fbx.objects.FbxAnimCurve)1 FbxAnimNode (com.jme3.scene.plugins.fbx.objects.FbxAnimNode)1 FbxBindPose (com.jme3.scene.plugins.fbx.objects.FbxBindPose)1 FbxCluster (com.jme3.scene.plugins.fbx.objects.FbxCluster)1 FbxImage (com.jme3.scene.plugins.fbx.objects.FbxImage)1 FbxMaterial (com.jme3.scene.plugins.fbx.objects.FbxMaterial)1 FbxMesh (com.jme3.scene.plugins.fbx.objects.FbxMesh)1 FbxNode (com.jme3.scene.plugins.fbx.objects.FbxNode)1