/** * Use in the case of multiple animation layers in FBX asset * @param name - animation name to assess via {@link AnimControl} * @param layerName - source layer */ public void add(String name, int firstFrame, int lastFrame) { add(name, null, firstFrame, lastFrame); }
public Quaternion rotate(Vector3f vec) { return fromEuler(vec.x * FastMath.DEG_TO_RAD, vec.y * FastMath.DEG_TO_RAD, vec.z * FastMath.DEG_TO_RAD, this); }
private static Quaternion fromEuler(float x, float y, float z, RotationOrder order) { switch(order) { case EULER_XYZ: return toQuat(x, Vector3f.UNIT_X, y, Vector3f.UNIT_Y, z, Vector3f.UNIT_Z); case EULER_YXZ: return toQuat(y, Vector3f.UNIT_Y, x, Vector3f.UNIT_X, z, Vector3f.UNIT_Z); case EULER_ZXY: return toQuat(z, Vector3f.UNIT_Z, x, Vector3f.UNIT_X, y, Vector3f.UNIT_Y); case EULER_ZYX: return toQuat(z, Vector3f.UNIT_Z, y, Vector3f.UNIT_Y, x, Vector3f.UNIT_X); case EULER_YZX: return toQuat(y, Vector3f.UNIT_Y, z, Vector3f.UNIT_Z, x, Vector3f.UNIT_X); case EULER_XZY: return toQuat(x, Vector3f.UNIT_X, z, Vector3f.UNIT_Z, y, Vector3f.UNIT_Y); case SPHERIC_XYZ: default: throw new IllegalArgumentException("Spheric rotation is unsupported in this importer"); } }
switch(e.id) { case "Geometry": FbxMesh mesh = new FbxMesh(this, e); obj = mesh; if(mesh.geometries != null) 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":
return; if(animList == null || animList.list.size() == 0) { animList = new AnimationList(); for(long layerId : alayerMap.keySet()) { FbxObject layer = alayerMap.get(layerId); animList.add(layer.name, layer.name, 0, -1); FbxAnimNode animTranslation = limb.animTranslation(sourceLayerId); FbxAnimNode animRotation = limb.animRotation(sourceLayerId); FbxAnimNode animScale = limb.animScale(sourceLayerId); boolean haveTranslation = haveAnyChannel(animTranslation); boolean haveRotation = haveAnyChannel(animRotation); boolean haveScale = haveAnyChannel(animScale); animTranslation.exportTimes(stamps); if(haveRotation) animRotation.exportTimes(stamps); if(haveScale) animScale.exportTimes(stamps); if(stamps.isEmpty()) continue; int keyIndex = firstKeyIndex + i; FbxAnimNode n = animTranslation; Vector3f tvec = n.getValue(keyTimes[keyIndex], n.value).subtractLocal(n.value); // Why do it here but not in other places? FBX magic? translations[i] = tvec.divideLocal(unitSize); int keyIndex = firstKeyIndex + i; FbxAnimNode n = animRotation;
reset(); loadData(stream); applyBindPoses(); updateWorldTransforms(); constructSkeletons(); Spatial scene = constructSceneGraph(); constructAnimations(); releaseObjects(); if (stream != null) { stream.close();
@Override public Object load(AssetInfo assetInfo) throws IOException { this.currentAssetInfo = assetInfo; this.assetManager = assetInfo.getManager(); AssetKey<?> assetKey = assetInfo.getKey(); if(assetKey instanceof SceneKey) animList = ((SceneKey) assetKey).getAnimations(); InputStream stream = assetInfo.openStream(); final Node sceneNode = this.sceneNode = new Node(sceneName + "-scene"); try { sceneFilename = assetKey.getName(); sceneFolderName = assetKey.getFolder(); String ext = assetKey.getExtension(); sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1); if(sceneFolderName != null && sceneFolderName.length() > 0) sceneName = sceneName.substring(sceneFolderName.length()); loadScene(stream); linkScene(); if(warnings.size() > 0) logger.log(Level.WARNING, "Model load finished with warnings:\n" + join(warnings, "\n")); } finally { releaseObjects(); if(stream != null) stream.close(); } return sceneNode; }
private void loadData(InputStream stream) throws IOException { FbxFile scene = FbxReader.readFBX(stream); FbxDump.dumpFile(scene); // TODO: Load FBX object templates 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); } } }
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); }
InputStream stream = assetInfo.openStream(); Scanner scanner = new Scanner(stream); AnimationList animList = new AnimationList(); String modelName = null; try { continue; String[] split = split(line); if(split.length < 3) throw new IOException("Unparseable string \"" + line + "\""); throw new IOException("Unparseable string \"" + line + "\"", e); animList.add(split[2], split.length > 3 ? split[3] : null, start, end); stream.close(); return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList));
Vector3f scalePivotRaw = new Vector3f(); Vector3f scaleLocalRaw = new Vector3f(1, 1, 1); for(FbxElement prop : element.getFbxProperties()) { double x, y, z; String propName = (String) prop.properties.get(0); break; case "Lcl Translation": readVectorFromProp(translationLocalRaw, prop); break; case "Lcl Rotation": readVectorFromProp(rotationLocalRaw, prop); break; case "Lcl Scaling": readVectorFromProp(scaleLocalRaw, prop); break; case "PreRotation": readVectorFromProp(rotationPreRaw, prop); break; case "RotationActive": break; case "RotationPivot": readVectorFromProp(rotationPivotRaw, prop); break; case "PostRotation": readVectorFromProp(rotationPostRaw, prop); break; case "ScaleOffset":
@SuppressWarnings("rawtypes") @Override public AssetInfo locate(AssetManager manager, AssetKey key) { if(key instanceof ContentTextureKey) { String name = key.getName(); byte[] content = ((ContentTextureKey) key).getContent(); if(content != null) { return new ContentAssetInfo(manager, key, content); } else { logger.log(Level.WARNING, "No content for " + name); return null; } } else { logger.log(Level.SEVERE, "AssetKey should be TextureContentKey instance"); return null; } }
private void linkScene() { logger.log(Level.FINE, "Linking scene objects"); long startTime = System.currentTimeMillis(); applySkinning(); buildAnimations(); for(FbxMesh mesh : geomMap.values()) mesh.clearMaterials(); // Remove bones from node structures : JME creates attach node by itself for(FbxNode limb : limbMap.values()) limb.node.removeFromParent(); long estimatedTime = System.currentTimeMillis() - startTime; logger.log(Level.FINE, "Linking done in {0} ms", estimatedTime); }
/** * Use in the case of multiple animation layers in FBX asset * @param name - animation name to assess via {@link AnimControl} * @param layerName - source layer */ public void add(String name, String layerName, int firstFrame, int lastFrame) { AnimInverval cue = new AnimInverval(); cue.name = name; cue.layerName = layerName; cue.firstFrame = firstFrame; cue.lastFrame = lastFrame; list.add(cue); }
try { assetManager.registerLocator(locatorPath, ContentTextureLocator.class); tex = assetManager.loadTexture(new ContentTextureKey(filename, content)); } catch(Exception e) {} finally { assetManager.unregisterLocator(locatorPath, ContentTextureLocator.class); Texture tex = null; try { tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content)); } catch(Exception e) {} if(tex != null)
scene.warning("Skinning support max 4 bone per vertex. Exceeding data of " + bonesLimitExceeded + " weights in mesh bones will be discarded");
/** * Use in the case of multiple animation layers in FBX asset * @param name - animation name to assess via {@link AnimControl} * @param layerName - source layer */ public void add(String name, int firstFrame, int lastFrame) { add(name, null, firstFrame, lastFrame); }
public Quaternion rotate(float x, float y, float z) { return fromEuler(x * FastMath.DEG_TO_RAD, y * FastMath.DEG_TO_RAD, z * FastMath.DEG_TO_RAD, this); }
/** * Use in the case of multiple animation layers in FBX asset * @param name - animation name to assess via {@link AnimControl} * @param layerName - source layer */ public void add(String name, int firstFrame, int lastFrame) { add(name, null, firstFrame, lastFrame); }
public Quaternion rotate(float x, float y, float z) { return fromEuler(x * FastMath.DEG_TO_RAD, y * FastMath.DEG_TO_RAD, z * FastMath.DEG_TO_RAD, this); }