Search in sources :

Example 6 with FbxElement

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

the class FbxLayerElement method fromElement.

public static FbxLayerElement fromElement(FbxElement element) {
    FbxLayerElement layerElement = new FbxLayerElement();
    if (!element.id.startsWith("LayerElement")) {
        throw new IllegalArgumentException("Not a layer element");
    }
    layerElement.index = (Integer) element.properties.get(0);
    String elementType = element.id.substring("LayerElement".length());
    try {
        layerElement.type = Type.valueOf(elementType);
    } catch (IllegalArgumentException ex) {
        logger.log(Level.WARNING, "Unsupported layer element: {0}. Ignoring.", elementType);
    }
    for (FbxElement child : element.children) {
        if (child.id.equals("MappingInformationType")) {
            String mapInfoTypeVal = (String) child.properties.get(0);
            if (mapInfoTypeVal.equals("ByVertice")) {
                mapInfoTypeVal = "ByVertex";
            }
            layerElement.mapInfoType = MappingInformationType.valueOf(mapInfoTypeVal);
        } else if (child.id.equals("ReferenceInformationType")) {
            String refInfoTypeVal = (String) child.properties.get(0);
            if (refInfoTypeVal.equals("Index")) {
                refInfoTypeVal = "IndexToDirect";
            }
            layerElement.refInfoType = ReferenceInformationType.valueOf(refInfoTypeVal);
        } else if (child.id.equals("Normals") || child.id.equals("Tangents") || child.id.equals("Binormals")) {
            layerElement.data = toVector3(FbxMeshUtil.getDoubleArray(child));
        } else if (child.id.equals("Colors")) {
            layerElement.data = toColorRGBA(FbxMeshUtil.getDoubleArray(child));
        } else if (child.id.equals("UV")) {
            layerElement.data = toVector2(FbxMeshUtil.getDoubleArray(child));
        } else if (indexTypes.contains(child.id)) {
            layerElement.dataIndices = FbxMeshUtil.getIntArray(child);
        } else if (child.id.equals("Name")) {
            layerElement.name = (String) child.properties.get(0);
        }
    }
    if (layerElement.data == null) {
        // For Smoothing / Materials, data = dataIndices
        layerElement.refInfoType = ReferenceInformationType.Direct;
        layerElement.data = new Integer[layerElement.dataIndices.length];
        for (int i = 0; i < layerElement.data.length; i++) {
            layerElement.data[i] = layerElement.dataIndices[i];
        }
        layerElement.dataIndices = null;
    }
    return layerElement;
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement)

Example 7 with FbxElement

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

the class FbxMesh method fromElement.

@Override
public void fromElement(FbxElement element) {
    super.fromElement(element);
    List<FbxLayerElement> layerElementsList = new ArrayList<FbxLayerElement>();
    List<FbxLayer> layersList = new ArrayList<FbxLayer>();
    for (FbxElement e : element.children) {
        if (e.id.equals("Vertices")) {
            setPositions(FbxMeshUtil.getDoubleArray(e));
        } else if (e.id.equals("PolygonVertexIndex")) {
            setPolygonVertexIndices(FbxMeshUtil.getIntArray(e));
        } else if (e.id.equals("Edges")) {
            setEdges(FbxMeshUtil.getIntArray(e));
        } else if (e.id.startsWith("LayerElement")) {
            layerElementsList.add(FbxLayerElement.fromElement(e));
        } else if (e.id.equals("Layer")) {
            layersList.add(FbxLayer.fromElement(e));
        }
    }
    for (FbxLayer layer : layersList) {
        layer.setLayerElements(layerElementsList);
    }
    layerElements = new FbxLayerElement[layerElementsList.size()];
    layerElementsList.toArray(layerElements);
    layers = new FbxLayer[layersList.size()];
    layersList.toArray(layers);
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) ArrayList(java.util.ArrayList)

Example 8 with FbxElement

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

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

the class FbxLoader method loadGlobalSettings.

private void loadGlobalSettings(FbxElement element) {
    globalSettings = new FbxGlobalSettings();
    globalSettings.fromElement(element);
}
Also used : FbxGlobalSettings(com.jme3.scene.plugins.fbx.misc.FbxGlobalSettings)

Example 10 with FbxElement

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

the class FbxLoader method loadData.

private void loadData(InputStream stream) throws IOException {
    FbxFile scene = FbxReader.readFBX(stream);
    FbxDump.dumpFile(scene);
    for (FbxElement e : scene.rootElements) {
        if (e.id.equals("FBXHeaderExtension")) {
            loadHeader(e);
        } else if (e.id.equals("GlobalSettings")) {
            loadGlobalSettings(e);
        } else if (e.id.equals("Objects")) {
            loadObjects(e);
        } else if (e.id.equals("Connections")) {
            connectObjects(e);
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) FbxFile(com.jme3.scene.plugins.fbx.file.FbxFile)

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