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;
}
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);
}
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);
}
}
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);
}
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);
}
}
}
Aggregations