use of com.jme3.asset.AssetKey in project jmonkeyengine by jMonkeyEngine.
the class FbxLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
this.assetManager = assetInfo.getManager();
AssetKey<?> assetKey = assetInfo.getKey();
if (!(assetKey instanceof ModelKey)) {
throw new AssetLoadException("Invalid asset key");
}
InputStream stream = assetInfo.openStream();
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());
}
reset();
// Load the data from the stream.
loadData(stream);
// Bind poses are needed to compute world transforms.
applyBindPoses();
// Need world transforms for skeleton creation.
updateWorldTransforms();
// Need skeletons for meshs to be created in scene graph construction.
// Mesh bone indices require skeletons to determine bone index.
constructSkeletons();
// Create the jME3 scene graph from the FBX scene graph.
// Also creates SkeletonControls based on the constructed skeletons.
Spatial scene = constructSceneGraph();
// Load animations into AnimControls
constructAnimations();
return scene;
} finally {
releaseObjects();
if (stream != null) {
stream.close();
}
}
}
use of com.jme3.asset.AssetKey in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method load.
@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;
}
use of com.jme3.asset.AssetKey in project jmonkeyengine by jMonkeyEngine.
the class MaterialLoader method load.
private MaterialList load(AssetManager assetManager, AssetKey key, InputStream in) throws IOException {
folderName = key.getFolder();
this.assetManager = assetManager;
MaterialList list = null;
List<Statement> statements = BlockLanguageParser.parse(in);
for (Statement statement : statements) {
if (statement.getLine().startsWith("import")) {
MaterialExtensionSet matExts = null;
if (key instanceof OgreMaterialKey) {
matExts = ((OgreMaterialKey) key).getMaterialExtensionSet();
}
if (matExts == null) {
throw new IOException("Must specify MaterialExtensionSet when loading\n" + "Ogre3D materials with extended materials");
}
list = new MaterialExtensionLoader().load(assetManager, key, matExts, statements);
break;
} else if (statement.getLine().startsWith("material")) {
if (list == null) {
list = new MaterialList();
}
String[] split = statement.getLine().split(" ", 2);
matName = split[1].trim();
if (matName.startsWith("\"") && matName.endsWith("\"")) {
matName = matName.substring(1, matName.length() - 1);
}
readMaterial(statement);
Material mat = compileMaterial();
list.put(mat.getName(), mat);
}
}
return list;
}
use of com.jme3.asset.AssetKey in project jmonkeyengine by jMonkeyEngine.
the class TestMaterialDefWrite method testWriteMat.
@Test
public void testWriteMat() throws Exception {
Material mat = new Material(assetManager, "example.j3md");
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
J3mdExporter exporter = new J3mdExporter();
try {
exporter.save(mat.getMaterialDef(), stream);
} catch (IOException e) {
e.printStackTrace();
}
// System.err.println(stream.toString());
J3MLoader loader = new J3MLoader();
AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {
@Override
public InputStream openStream() {
return new ByteArrayInputStream(stream.toByteArray());
}
};
MaterialDef matDef = (MaterialDef) loader.load(info);
MaterialDef ref = mat.getMaterialDef();
for (MatParam refParam : ref.getMaterialParams()) {
MatParam matParam = matDef.getMaterialParam(refParam.getName());
assertTrue(refParam != null);
assertEquals(refParam, matParam);
}
for (String key : ref.getTechniqueDefsNames()) {
List<TechniqueDef> refDefs = ref.getTechniqueDefs(key);
List<TechniqueDef> defs = matDef.getTechniqueDefs(key);
assertNotNull(defs);
assertTrue(refDefs.size() == defs.size());
for (int i = 0; i < refDefs.size(); i++) {
assertEqualTechniqueDefs(refDefs.get(i), defs.get(i));
}
}
}
Aggregations