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