Java Code Examples for com.jme3.asset.AssetManager#loadAsset()
The following examples show how to use
com.jme3.asset.AssetManager#loadAsset() .
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: MaterialFileEditor.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected void handleExternalChanges() { super.handleExternalChanges(); final Path assetFile = notNull(getAssetFile(getEditFile())); final MaterialKey materialKey = new MaterialKey(toAssetPath(assetFile)); final AssetManager assetManager = EditorUtil.getAssetManager(); final Material material = assetManager.loadAsset(materialKey); reload(material); final EditorOperationControl operationControl = getOperationControl(); operationControl.clear(); }
Example 2
Source File: MaterialFileEditor.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected void doOpenFile(@NotNull final Path file) throws IOException { super.doOpenFile(file); final Path assetFile = notNull(getAssetFile(file)); final MaterialKey materialKey = new MaterialKey(toAssetPath(assetFile)); final AssetManager assetManager = EditorUtil.getAssetManager(); final Material material = assetManager.loadAsset(materialKey); final MaterialEditor3DPart editor3DState = getEditor3DPart(); editor3DState.changeMode(ModelType.BOX); reload(material); }
Example 3
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 4
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 5
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 6
Source File: TechniqueDef.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Shader loadShader(AssetManager assetManager, EnumSet<Caps> rendererCaps, DefineList defines) { StringBuilder sb = new StringBuilder(); sb.append(shaderPrologue); defines.generateSource(sb, defineNames, defineTypes); String definesSourceCode = sb.toString(); Shader shader; if (isUsingShaderNodes()) { ShaderGenerator shaderGenerator = assetManager.getShaderGenerator(rendererCaps); if (shaderGenerator == null) { throw new UnsupportedOperationException("ShaderGenerator was not initialized, " + "make sure assetManager.getGenerator(caps) has been called"); } shaderGenerator.initialize(this); shader = shaderGenerator.generateShader(definesSourceCode); } else { shader = new Shader(); for (ShaderType type : ShaderType.values()) { String language = shaderLanguages.get(type); String shaderSourceAssetName = shaderNames.get(type); if (language == null || shaderSourceAssetName == null) { continue; } String shaderSourceCode = (String) assetManager.loadAsset(shaderSourceAssetName); shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language); } } for (final UniformBinding binding : getWorldBindings()) { shader.addUniformBinding(binding); } return shader; }
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: 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 9
Source File: AssetLinkNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void attachLinkedChild(AssetManager manager, ModelKey key) { addLinkedChild(key); Spatial child = manager.loadAsset(key); assetChildren.put(key, child); attachChild(child); }
Example 10
Source File: Material.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Material(AssetManager contentMan, String defName) { this(contentMan.loadAsset(new AssetKey<MaterialDef>(defName))); }
Example 11
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void attachLinkedChild(AssetManager manager, ModelKey key) { addLinkedChild(key); Spatial child = manager.loadAsset(key); assetChildren.put(key, child); attachChild(child); }
Example 12
Source File: Material.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public Material(AssetManager contentMan, String defName) { this((MaterialDef) contentMan.loadAsset(new AssetKey(defName))); }
Example 13
Source File: AudioNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a new <code>AudioNode</code> with the given audio file. * * @param assetManager The asset manager to use to load the audio file * @param name The filename of the audio file * @param stream If true, the audio will be streamed gradually from disk, * otherwise, it will be buffered. * @param streamCache If stream is also true, then this specifies if * the stream cache is used. When enabled, the audio stream will * be read entirely but not decoded, allowing features such as * seeking, looping and determining duration. * * @deprecated Use {@link AudioNode#AudioNode(com.jme3.asset.AssetManager, java.lang.String, com.jme3.audio.AudioData.DataType)} instead */ @Deprecated public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) { this.audioKey = new AudioKey(name, stream, streamCache); this.data = assetManager.loadAsset(audioKey); }
Example 14
Source File: AudioNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * Creates a new <code>AudioNode</code> with the given audio file. * * @param audioRenderer The audio renderer to use for playing. Cannot be null. * @param assetManager The asset manager to use to load the audio file * @param name The filename of the audio file * @param stream If true, the audio will be streamed gradually from disk, * otherwise, it will be buffered. * @param streamCache If stream is also true, then this specifies if * the stream cache is used. When enabled, the audio stream will * be read entirely but not decoded, allowing features such as * seeking, looping and determining duration. * * @deprecated AudioRenderer parameter is ignored. */ public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name, boolean stream, boolean streamCache) { this.audioKey = new AudioKey(name, stream, streamCache); this.data = (AudioData) assetManager.loadAsset(audioKey); }
Example 15
Source File: AudioNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * Creates a new <code>AudioNode</code> with the given audio file. * * @param assetManager The asset manager to use to load the audio file * @param name The filename of the audio file * @param stream If true, the audio will be streamed gradually from disk, * otherwise, it will be buffered. * @param streamCache If stream is also true, then this specifies if * the stream cache is used. When enabled, the audio stream will * be read entirely but not decoded, allowing features such as * seeking, looping and determining duration. */ public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) { this.audioKey = new AudioKey(name, stream, streamCache); this.data = (AudioData) assetManager.loadAsset(audioKey); }