com.jme3.asset.ModelKey Java Examples
The following examples show how to use
com.jme3.asset.ModelKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeTreeNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Add the external object to this node. * * @param node this node. * @param cons the change consumer. * @param path the path to the external object. */ @FxThread protected void dropExternalObject(@NotNull final T node, @NotNull final ChangeConsumer cons, @NotNull final Path path) { final SceneLayer defaultLayer = getDefaultLayer(cons); final Path assetFile = notNull(getAssetFile(path), "Not found asset file for " + path); final String assetPath = toAssetPath(assetFile); final ModelKey modelKey = new ModelKey(assetPath); final AssetManager assetManager = EditorUtil.getAssetManager(); final Spatial loadedModel = assetManager.loadModel(assetPath); final AssetLinkNode assetLinkNode = new AssetLinkNode(modelKey); assetLinkNode.attachLinkedChild(loadedModel, modelKey); if (defaultLayer != null) { SceneLayer.setLayer(defaultLayer, loadedModel); } cons.execute(new AddChildOperation(assetLinkNode, node)); }
Example #2
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @SuppressWarnings("unchecked") public void read(JmeImporter e) throws IOException { super.read(e); final InputCapsule capsule = e.getCapsule(this); final AssetManager assetManager = e.getAssetManager(); assetLoaderKeys = capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<>()); for (final Iterator<ModelKey> iterator = assetLoaderKeys.iterator(); iterator.hasNext(); ) { final ModelKey modelKey = iterator.next(); final Spatial child = assetManager.loadAsset(modelKey); if (child != null) { child.parent = this; children.add(child); assetChildren.put(modelKey, child); } else { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", new Object[]{modelKey, key}); } } }
Example #3
Source File: LoadModelAction.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * The process of opening file. * * @param file the file */ @FxThread protected void processOpen(@NotNull final Path file) { final NodeTree<?> nodeTree = getNodeTree(); final ChangeConsumer consumer = notNull(nodeTree.getChangeConsumer()); final SceneLayer defaultLayer = getDefaultLayer(consumer); final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file); final String assetPath = toAssetPath(assetFile); final ModelKey modelKey = new ModelKey(assetPath); final AssetManager assetManager = EditorUtil.getAssetManager(); final Spatial loadedModel = assetManager.loadModel(modelKey); loadedModel.setUserData(KEY_LOADED_MODEL, true); if (defaultLayer != null) { SceneLayer.setLayer(defaultLayer, loadedModel); } final TreeNode<?> treeNode = getNode(); final Node parent = (Node) treeNode.getElement(); consumer.execute(new AddChildOperation(loadedModel, parent)); }
Example #4
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void read(JmeImporter e) throws IOException { super.read(e); InputCapsule capsule = e.getCapsule(this); BinaryImporter importer = BinaryImporter.getInstance(); AssetManager loaderManager = e.getAssetManager(); assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>()); for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) { ModelKey modelKey = it.next(); AssetInfo info = loaderManager.locateAsset(modelKey); Spatial child = null; if (info != null) { child = (Spatial) importer.load(info); } if (child != null) { child.parent = this; children.add(child); assetChildren.put(modelKey, child); } else { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Could not load linked child spatial: {0}", modelKey.getName()); } } }
Example #5
Source File: OBJLoaderTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testHappyPath() { Node scene = (Node) assetManager.loadModel(new ModelKey("OBJLoaderTest/TwoChairs.obj")); String sceneAsString = toDiffFriendlyString("", scene); System.out.println(sceneAsString); String expectedText = "" + // generated root name (as before named groups support) "TwoChairs-objnode\n" + // unnamed geometry with generated name (as before named groups support). // actually it's partially smoothed, but this fact is ignored. " TwoChairs-geom-0 (material: dot_purple)\n" + // named group as Geometry " Chair 2 (material: dot_purple)\n" + // named group as Geometry " Pillow 2 (material: dot_red)\n" + // named group as node with two dufferent Geometry instances, // because two materials are used (as before named groups support) " Podium\n" + " TwoChairs-geom-3 (material: dot_red)\n" + " TwoChairs-geom-4 (material: dot_blue)\n" + // named group as Geometry " Pillow 1 (material: dot_green)"; assertEquals(expectedText, sceneAsString.trim()); }
Example #6
Source File: TestObjGroupsLoading.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { // load scene with following structure: // Chair 1 (just mesh without name) and named groups: Chair 2, Pillow 2, Podium Spatial scene = assetManager.loadModel(new ModelKey("OBJLoaderTest/TwoChairs.obj")); // add light to make it visible scene.addLight(new AmbientLight(ColorRGBA.White)); // attach scene to the root rootNode.attachChild(scene); // configure camera for best scene viewing cam.setLocation(new Vector3f(-3, 4, 3)); cam.lookAtDirection(new Vector3f(0, -0.5f, -1), Vector3f.UNIT_Y); flyCam.setMoveSpeed(10); // create display to indicate pointed geometry name pointerDisplay = new BitmapText(guiFont); pointerDisplay.setBox(new Rectangle(0, settings.getHeight(), settings.getWidth(), settings.getHeight()/2)); pointerDisplay.setAlignment(BitmapFont.Align.Center); pointerDisplay.setVerticalAlignment(BitmapFont.VAlign.Center); guiNode.attachChild(pointerDisplay); initCrossHairs(); }
Example #7
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Loads the linked children AssetKeys from the AssetManager and attaches them to the Node<br> * If they are already attached, they will be reloaded. * @param manager */ public void attachLinkedChildren(AssetManager manager) { detachLinkedChildren(); for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) { ModelKey assetKey = it.next(); Spatial curChild = assetChildren.get(assetKey); if (curChild != null) { curChild.removeFromParent(); } Spatial child = manager.loadAsset(assetKey); attachChild(child); assetChildren.put(assetKey, child); } }
Example #8
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void detachLinkedChild(ModelKey key) { Spatial spatial = assetChildren.get(key); if (spatial != null) { detachChild(spatial); } removeLinkedChild(key); assetChildren.remove(key); }
Example #9
Source File: SpawnToolControl.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Create an asset link node for the spatial. * * @param spatial the spatial. * @return the asset link node. */ @JmeThread protected @NotNull AssetLinkNode linkSpatial(@NotNull Spatial spatial) { var linkNode = new AssetLinkNode(); linkNode.setLocalTranslation(spatial.getLocalTranslation()); linkNode.setName(spatial.getName()); linkNode.setLocalScale(getMinScale()); linkNode.attachLinkedChild(getAssetManager(), (ModelKey) spatial.getKey()); return linkNode; }
Example #10
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void detachLinkedChildren() { Set<Entry<ModelKey, Spatial>> set = assetChildren.entrySet(); for (Iterator<Entry<ModelKey, Spatial>> it = set.iterator(); it.hasNext();) { Entry<ModelKey, Spatial> entry = it.next(); entry.getValue().removeFromParent(); it.remove(); } }
Example #11
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Add a "linked" child. These are loaded from the assetManager when the * AssetLinkNode is loaded from a binary file. * @param key */ public void addLinkedChild(ModelKey key) { if (assetLoaderKeys.contains(key)) { return; } assetLoaderKeys.add(key); }
Example #12
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void detachLinkedChild(ModelKey key) { Spatial spatial = assetChildren.get(key); if (spatial != null) { detachChild(spatial); } removeLinkedChild(key); assetChildren.remove(key); }
Example #13
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Loads the linked children AssetKeys from the AssetManager and attaches them to the Node<br> * If they are already attached, they will be reloaded. * @param manager */ public void attachLinkedChildren(AssetManager manager) { detachLinkedChildren(); for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) { ModelKey assetKey = it.next(); Spatial curChild = assetChildren.get(assetKey); if (curChild != null) { curChild.removeFromParent(); } Spatial child = manager.loadAsset(assetKey); attachChild(child); assetChildren.put(assetKey, child); } }
Example #14
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void detachLinkedChildren() { Set<Entry<ModelKey, Spatial>> set = assetChildren.entrySet(); for (Iterator<Entry<ModelKey, Spatial>> it = set.iterator(); it.hasNext();) { Entry<ModelKey, Spatial> entry = it.next(); entry.getValue().removeFromParent(); it.remove(); } }
Example #15
Source File: OgreXMLDataObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ModelKey getAssetKey() { if(super.getAssetKey() instanceof OgreMeshKey){ return (OgreMeshKey)assetKey; } assetKey = new OgreMeshKey(super.getAssetKey().getName()); return (OgreMeshKey)assetKey; }
Example #16
Source File: SpatialAssetDataObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ModelKey getAssetKey() { AssetKey superKey = super.getAssetKey(); if (superKey instanceof ModelKey) { return (ModelKey)superKey; } else { ProjectAssetManager mgr = getLookup().lookup(ProjectAssetManager.class); if (mgr == null) { return null; } String assetKey = mgr.getRelativeAssetPath(getPrimaryFile().getPath()); return new ModelKey(assetKey); } }
Example #17
Source File: JmeAssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected Node[] createNodes(Object key) { if (key instanceof ModelKey) { ModelKey assetKey = (ModelKey) key; return new Node[]{new JmeAssetLinkChild(assetKey, (AssetLinkNode) spatial)}; } return null; }
Example #18
Source File: BlenderDataObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ModelKey getAssetKey() { if(super.getAssetKey() instanceof BlenderKey){ return (BlenderKey)assetKey; } assetKey = new BlenderKey(super.getAssetKey().getName()); return (BlenderKey)assetKey; }
Example #19
Source File: SpatialAssetResourcePropertyControl.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void chooseNew(@NotNull Path file) { var assetManager = EditorUtil.getAssetManager(); var assetFile = notNull(getAssetFile(file)); var modelKey = new ModelKey(toAssetPath(assetFile)); var spatial = findResource(assetManager, modelKey); setPropertyValue(unsafeCast(spatial)); super.chooseNew(file); }
Example #20
Source File: LinkModelAction.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * The process of opening file. * * @param file the file */ @FxThread protected void processOpen(@NotNull final Path file) { final NodeTree<?> nodeTree = getNodeTree(); final ChangeConsumer consumer = notNull(nodeTree.getChangeConsumer()); final SceneLayer defaultLayer = EditorUtil.getDefaultLayer(consumer); final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file); final String assetPath = toAssetPath(assetFile); final ModelKey modelKey = new ModelKey(assetPath); final AssetManager assetManager = EditorUtil.getAssetManager(); final Spatial loadedModel = assetManager.loadModel(modelKey); final AssetLinkNode assetLinkNode = new AssetLinkNode(modelKey); assetLinkNode.attachLinkedChild(loadedModel, modelKey); assetLinkNode.setUserData(KEY_LOADED_MODEL, true); if (defaultLayer != null) { SceneLayer.setLayer(defaultLayer, assetLinkNode); } final TreeNode<?> treeNode = getNode(); final Node parent = (Node) treeNode.getElement(); consumer.execute(new AddChildOperation(assetLinkNode, parent)); }
Example #21
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add a "linked" child. These are loaded from the assetManager when the * AssetLinkNode is loaded from a binary file. * @param key */ public void addLinkedChild(ModelKey key) { if (assetLoaderKeys.contains(key)) { return; } assetLoaderKeys.add(key); }
Example #22
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Called internally by com.jme3.util.clone.Cloner. Do not call directly. */ @Override public void cloneFields( Cloner cloner, Object original ) { super.cloneFields(cloner, original); // This is a change in behavior because the old version did not clone // this list... changes to one clone would be reflected in all. // I think that's probably undesirable. -pspeed this.assetLoaderKeys = cloner.clone(assetLoaderKeys); this.assetChildren = new HashMap<ModelKey, Spatial>(); }
Example #23
Source File: SceneFileEditor.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void doOpenFile(@NotNull final Path file) throws IOException { super.doOpenFile(file); final Path assetFile = notNull(getAssetFile(file), "Asset file for " + file + " can't be null."); final ModelKey modelKey = new ModelKey(toAssetPath(assetFile)); final AssetManager assetManager = EditorUtil.getAssetManager(); Spatial loadedScene = assetManager.loadAsset(modelKey); final SceneNode model = (SceneNode) loadedScene; model.depthFirstTraversal(this::updateVisibility); MaterialUtils.cleanUpMaterialParams(model); final SceneEditor3DPart editor3DState = getEditor3DPart(); editor3DState.openModel(model); handleAddedObject(model); setCurrentModel(model); setIgnoreListeners(true); try { refreshTree(); } finally { setIgnoreListeners(false); } }
Example #24
Source File: ModelFileEditor.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void doOpenFile(@NotNull Path file) throws IOException { super.doOpenFile(file); var assetFile = notNull(getAssetFile(file), "Asset file for " + file + " can't be null."); var modelKey = new ModelKey(toAssetPath(assetFile)); var assetManager = EditorUtil.getAssetManager(); var model = assetManager.loadAsset(modelKey); MaterialUtils.cleanUpMaterialParams(model); var editor3DPart = getEditor3DPart(); editor3DPart.openModel(model); handleAddedObject(model); setCurrentModel(model); setIgnoreListeners(true); try { getFastSkyComboBox().getSelectionModel() .select(FAST_SKY_LIST.first()); refreshTree(); } finally { setIgnoreListeners(false); } }
Example #25
Source File: SceneWithAnimationLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Object load(AssetInfo assetInfo) throws IOException { AssetKey<?> key = assetInfo.getKey(); if(!(key instanceof ModelKey)) throw new AssetLoadException("Invalid asset key"); InputStream stream = assetInfo.openStream(); Scanner scanner = new Scanner(stream); AnimationList animList = new AnimationList(); String modelName = null; try { while(scanner.hasNextLine()) { String line = scanner.nextLine(); if(line.startsWith("#")) continue; if(modelName == null) { modelName = line; continue; } String[] split = split(line); if(split.length < 3) throw new IOException("Unparseable string \"" + line + "\""); int start; int end; try { start = Integer.parseInt(split[0]); end = Integer.parseInt(split[1]); } catch(NumberFormatException e) { throw new IOException("Unparseable string \"" + line + "\"", e); } animList.add(split[2], split.length > 3 ? split[3] : null, start, end); } } finally { scanner.close(); stream.close(); } return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList)); }
Example #26
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void removeLinkedChild(ModelKey key) { assetLoaderKeys.remove(key); }
Example #27
Source File: GeometryAssetResourcePropertyControl.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
@Override @FxThread protected @Nullable Geometry findResource(@NotNull AssetManager assetManager, @NotNull ModelKey modelKey) { return NodeUtils.findGeometry(assetManager.loadModel(modelKey)); }
Example #28
Source File: JmeAssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public JmeAssetLinkChild(ModelKey key, AssetLinkNode linkNode) { super(Children.LEAF); this.key = key; this.linkNode = linkNode; this.setName(key.getName()); }
Example #29
Source File: AbstractModelFileConverter.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * Convert a file using settings from the dialog. */ @BackgroundThread private void convertImpl(@NotNull final Path source, @NotNull final VarTable vars) throws IOException { final String filename = vars.getString(PROP_RESULT_NAME); final Path destinationFolder = notNull(getRealFile(vars.get(PROP_DESTINATION, Path.class))); final Path destination = destinationFolder.resolve(filename + "." + FileExtensions.JME_OBJECT); final boolean isOverwrite = Files.exists(destination); final Path assetFile = notNull(getAssetFile(source), "Not found asset file for " + source); final ModelKey modelKey = new ModelKey(toAssetPath(assetFile)); final AssetManager assetManager = EditorUtil.getAssetManager(); final Spatial model = assetManager.loadAsset(modelKey); if (EDITOR_CONFIG.getBoolean(PREF_TANGENT_GENERATION, PREF_DEFAULT_TANGENT_GENERATION)) { TangentGenerator.useMikktspaceGenerator(model); } if (vars.getBoolean(PROP_EXPORT_MATERIALS)) { final Array<Geometry> geometries = ArrayFactory.newArray(Geometry.class); final ObjectDictionary<String, Geometry> mapping = DictionaryFactory.newObjectDictionary(); final Path materialsFolder = vars.get(PROP_MATERIALS_FOLDER); final boolean canOverwrite = vars.getBoolean(PROP_OVERWRITE_MATERIALS); NodeUtils.visitGeometry(model, geometry -> checkAndAdd(geometries, geometry)); geometries.forEach(geometry -> generateNames(mapping, geometry)); mapping.forEach((materialName, geometry) -> storeMaterials(materialsFolder, canOverwrite, materialName, geometry)); } final BinaryExporter exporter = BinaryExporter.getInstance(); try (final OutputStream out = Files.newOutputStream(destination, WRITE, TRUNCATE_EXISTING, CREATE)) { exporter.save(model, out); } if (isOverwrite) { notifyFileChanged(destination); } else { notifyFileCreated(destination); } }
Example #30
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void detachLinkedChild(Spatial child, ModelKey key) { removeLinkedChild(key); assetChildren.remove(key); detachChild(child); }