com.jme3.asset.AssetKey Java Examples
The following examples show how to use
com.jme3.asset.AssetKey.
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: PBRSpecGlossExtensionLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object handleExtension(GltfLoader loader, String parentName, JsonElement parent, JsonElement extension, Object input) throws IOException { MaterialAdapter adapter = materialAdapter; AssetKey key = loader.getInfo().getKey(); //check for a custom adapter for spec/gloss pipeline if (key instanceof GltfModelKey) { GltfModelKey gltfKey = (GltfModelKey) key; MaterialAdapter ma = gltfKey.getAdapterForMaterial("pbrSpecularGlossiness"); if (ma != null) { adapter = ma; } } adapter.init(loader.getInfo().getManager()); adapter.setParam("diffuseFactor", getAsColor(extension.getAsJsonObject(), "diffuseFactor")); adapter.setParam("specularFactor", getAsColor(extension.getAsJsonObject(), "specularFactor")); adapter.setParam("glossinessFactor", getAsFloat(extension.getAsJsonObject(), "glossinessFactor")); adapter.setParam("diffuseTexture", loader.readTexture(extension.getAsJsonObject().getAsJsonObject("diffuseTexture"))); adapter.setParam("specularGlossinessTexture", loader.readTexture(extension.getAsJsonObject().getAsJsonObject("specularGlossinessTexture"))); return adapter; }
Example #2
Source File: ContentTextureLocator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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; } }
Example #3
Source File: SaveAsMaterialAction.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * The process of saving the file. * * @param file the file to save */ @FxThread private void processSave(@NotNull final Path file) { final TreeNode<?> node = getNode(); final Material material = (Material) node.getElement(); final String materialContent = MaterialSerializer.serializeToString(material); try (final PrintWriter out = new PrintWriter(Files.newOutputStream(file, WRITE, TRUNCATE_EXISTING, CREATE))) { out.print(materialContent); } catch (final IOException e) { EditorUtil.handleException(LOGGER, this, e); return; } final Path assetFile = notNull(getAssetFile(file)); final AssetManager assetManager = EditorUtil.getAssetManager(); final Material savedMaterial = assetManager.loadMaterial(notNull(toAssetPath(assetFile))); final PropertyOperation<ChangeConsumer, Material, AssetKey> operation = new PropertyOperation<>(material, "AssetKey", savedMaterial.getKey(), null); operation.setApplyHandler(Material::setKey); final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(operation); }
Example #4
Source File: MaterialExtensionLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public MaterialList load(AssetManager assetManager, AssetKey key, MaterialExtensionSet matExts, List<Statement> statements) throws IOException{ this.assetManager = assetManager; this.matExts = matExts; this.key = key; list = new MaterialList(); for (Statement statement : statements){ if (statement.getLine().startsWith("import")){ // ignore continue; }else if (statement.getLine().startsWith("material")){ Material material = readExtendingMaterial(statement); list.put(matName, material); List<String> matAliases = matExts.getNameMappings(matName); if(matAliases != null){ for (String string : matAliases) { list.put(string, material); } } } } return list; }
Example #5
Source File: HttpZipLocator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public AssetInfo locate(AssetManager manager, AssetKey key){ final ZipEntry2 entry = entries.get(key.getName()); if (entry == null) return null; return new AssetInfo(manager, key){ @Override public InputStream openStream() { try { return HttpZipLocator.this.openStream(entry); } catch (IOException ex) { logger.log(Level.WARNING, "Error retrieving "+entry.name, ex); return null; } } }; }
Example #6
Source File: HttpZipLocator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public AssetInfo locate(AssetManager manager, AssetKey key){ final ZipEntry2 entry = entries.get(key.getName()); if (entry == null) return null; return new AssetInfo(manager, key){ @Override public InputStream openStream() { try { return HttpZipLocator.this.openStream(entry); } catch (IOException ex) { logger.log(Level.WARNING, "Error retrieving "+entry.name, ex); return null; } } }; }
Example #7
Source File: MaterialExtensionLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public MaterialList load(AssetManager assetManager, AssetKey key, MaterialExtensionSet matExts, List<Statement> statements) throws IOException{ this.assetManager = assetManager; this.matExts = matExts; this.key = key; list = new MaterialList(); for (Statement statement : statements){ if (statement.getLine().startsWith("import")){ // ignore continue; }else if (statement.getLine().startsWith("material")){ Material material = readExtendingMaterial(statement); list.put(matName, material); List<String> matAliases = matExts.getNameMappings(matName); if(matAliases != null){ for (String string : matAliases) { list.put(string, material); } } } } return list; }
Example #8
Source File: WeakRefCloneAssetCache.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public <T> void addToCache(AssetKey<T> originalKey, T obj) { // Make room for new asset removeCollectedAssets(); CloneableSmartAsset asset = (CloneableSmartAsset) obj; // No circular references, since the original asset is // strongly referenced, we don't want the key strongly referenced. asset.setKey(null); // Start tracking the collection of originalKey // (this adds the KeyRef to the ReferenceQueue) KeyRef ref = new KeyRef(originalKey, refQueue); // Place the asset in the cache, but use a clone of // the original key. smartCache.put(ref.clonedKey, new AssetRef(asset, originalKey)); // Push the original key used to load the asset // so that it can be set on the clone later ArrayList<AssetKey> loadStack = assetLoadStack.get(); loadStack.add(originalKey); }
Example #9
Source File: AndroidLocator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("rawtypes") @Override public AssetInfo locate(com.jme3.asset.AssetManager manager, AssetKey key) { InputStream in = null; String sAssetPath = rootPath + key.getName(); // Fix path issues if (sAssetPath.startsWith("/")) { // Remove leading / sAssetPath = sAssetPath.substring(1); } sAssetPath = sAssetPath.replace("//", "/"); try { in = androidManager.open(sAssetPath); if (in == null) return null; return new AndroidAssetInfo(manager, key, sAssetPath); } catch (IOException ex) { //logger.log(Level.WARNING, "Failed to locate {0} ", sAssetPath); } return null; }
Example #10
Source File: ModelImporterVisualPanel1.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed if (currentModelPath != null) { if (loading.get()) { return; } loading.set(true); final String modelPath = currentModelPath; final AssetKey key = mainKey; new Thread(new Runnable() { public void run() { ProgressHandle handle = ProgressHandleFactory.createHandle("Opening Model.."); handle.start(); loadModel(new File(modelPath), key); handle.finish(); loading.set(false); } }).start(); } }
Example #11
Source File: WeakRefCloneAssetCache.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> T getFromCache(AssetKey<T> key) { AssetRef smartInfo = smartCache.get(key); if (smartInfo == null) { return null; } else { // NOTE: Optimization so that registerAssetClone() // can check this and determine that the asset clone // belongs to the asset retrieved here. AssetKey keyForTheClone = smartInfo.get(); if (keyForTheClone == null){ // The asset was JUST collected by GC // (between here and smartCache.get) return null; } // Prevent original key from getting collected // while an asset is loaded for it. ArrayList<AssetKey> loadStack = assetLoadStack.get(); loadStack.add(keyForTheClone); return (T) smartInfo.asset; } }
Example #12
Source File: ResourceManager.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FromAnyThread public synchronized void assetRequested(@NotNull final AssetKey key) { if (key.getCacheType() == null) { return; } final String extension = key.getExtension(); if (StringUtils.isEmpty(extension)){ return; } final ObjectDictionary<String, Reference> table = getAssetCacheTable(); final Reference reference = table.get(key.getName()); if (reference == null) { return; } final Path realFile = getRealFile(Paths.get(key.getName())); if (realFile == null || !Files.exists(realFile)) { return; } try { final long timestamp = reference.getLong(); final FileTime lastModifiedTime = Files.getLastModifiedTime(realFile); if (lastModifiedTime.to(TimeUnit.MILLISECONDS) <= timestamp) { return; } final AssetManager assetManager = EditorUtil.getAssetManager(); assetManager.deleteFromCache(key); } catch (final IOException e) { LOGGER.warning(e); } }
Example #13
Source File: WeakRefAssetCache.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T getFromCache(AssetKey<T> key) { AssetRef ref = assetCache.get(key); if (ref != null){ return (T) ref.get(); }else{ return null; } }
Example #14
Source File: WeakRefCloneAssetCache.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void clearCache() { ArrayList<AssetKey> loadStack = assetLoadStack.get(); if (!loadStack.isEmpty()){ throw new UnsupportedOperationException("Cache cannot be modified" + "while assets are being loaded"); } smartCache.clear(); }
Example #15
Source File: NiftyJmeDisplay.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public InputStream getResourceAsStream(String path) { AssetKey<Object> key = new AssetKey<>(path); AssetInfo info = assetManager.locateAsset(key); if (info != null) { return info.openStream(); } else { throw new AssetNotFoundException(path); } }
Example #16
Source File: AbstractModelFileConverter.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
private void checkAndAdd(@NotNull final Array<Geometry> geometries, @NotNull final Geometry geometry) { final Material material = geometry.getMaterial(); final AssetKey key = material.getKey(); if (key == null) { geometries.add(geometry); } }
Example #17
Source File: ModelImporterVisualPanel1.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void assetRequested(AssetKey ak) { if (!"j3md".equalsIgnoreCase(ak.getExtension()) && !"glsllib".equalsIgnoreCase(ak.getExtension()) && !"frag".equalsIgnoreCase(ak.getExtension()) && !"vert".equalsIgnoreCase(ak.getExtension())) { if (!requestedAssets.contains(ak)) { requestedAssets.add(ak); } } }
Example #18
Source File: FileSystemAssetLocator.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override public AssetInfo locate(@NotNull final AssetManager manager, @NotNull final AssetKey key) { final Path absoluteFile = Paths.get(key.getName()); if (!Files.exists(absoluteFile)) { return null; } ArrayUtils.runInWriteLock(LOCATED_KEYS, key, Collection::add); return new FolderAssetLocator.PathAssetInfo(manager, key, absoluteFile); }
Example #19
Source File: ModelImportDialog.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Copy textures from the external model. * * @param texturesFolder the textures folder. * @param overwriteTextures true if need to overwrite existing textures. * @param textures the found textures. */ @BackgroundThread private void copyTextures(@NotNull final Path texturesFolder, final boolean overwriteTextures, @NotNull final Array<Texture> textures) { if (textures.isEmpty()) { return; } final ObjectDictionary<String, String> oldKeyToNew = DictionaryFactory.newObjectDictionary(); final Array<AssetKey<?>> newTextureKeys = ArrayFactory.newArray(AssetKey.class); for (final Texture texture : textures) { final TextureKey textureKey = (TextureKey) texture.getKey(); if (newTextureKeys.contains(textureKey)) continue; final String newKey = oldKeyToNew.get(textureKey.getName(), makeCopyTextureFunction(texturesFolder, overwriteTextures)); final TextureKey newTextureKey = new TextureKey(newKey, textureKey.isFlipY()); newTextureKey.setGenerateMips(textureKey.isGenerateMips()); newTextureKey.setTextureTypeHint(textureKey.getTextureTypeHint()); texture.setKey(newTextureKey); newTextureKeys.add(newTextureKey); } }
Example #20
Source File: SceneLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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; }
Example #21
Source File: WeakRefCloneAssetCache.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void clearCache() { ArrayList<AssetKey> loadStack = assetLoadStack.get(); if (!loadStack.isEmpty()){ throw new UnsupportedOperationException("Cache cannot be modified" + "while assets are being loaded"); } smartCache.clear(); }
Example #22
Source File: TextureAtlas.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private String textureName(Texture texture) { if (texture == null) { return null; } AssetKey key = texture.getKey(); if (key != null) { return key.toString(); } else { return null; } }
Example #23
Source File: ModelImporterVisualPanel1.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void updateProperties(final AssetKey key) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { if (key == null) { ps.setNodes(new Node[]{}); } else { ps.setNodes(new Node[]{new ImportKeyNode(key)}); } } }); }
Example #24
Source File: ShaderNodeDefinitionLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Object load(AssetInfo assetInfo) throws IOException { AssetKey k = assetInfo.getKey(); if (!(k instanceof ShaderNodeDefinitionKey)) { throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey"); } ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k; loaderDelegate = new ShaderNodeLoaderDelegate(); InputStream in = assetInfo.openStream(); List<Statement> roots = BlockLanguageParser.parse(in); if (roots.size() == 2) { Statement exception = roots.get(0); String line = exception.getLine(); if (line.startsWith("Exception")) { throw new AssetLoadException(line.substring("Exception ".length())); } else { throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception); } } else if (roots.size() != 1) { throw new MatParseException("Too many roots in J3SN file", roots.get(0)); } return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key); }
Example #25
Source File: WeakRefCloneAssetCache.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T getFromCache(AssetKey<T> key) { AssetRef smartInfo; synchronized (smartCache){ smartInfo = smartCache.get(key); } if (smartInfo == null) { return null; } else { // NOTE: Optimization so that registerAssetClone() // can check this and determine that the asset clone // belongs to the asset retrieved here. AssetKey keyForTheClone = smartInfo.get(); if (keyForTheClone == null){ // The asset was JUST collected by GC // (between here and smartCache.get) return null; } // Prevent original key from getting collected // while an asset is loaded for it. ArrayList<AssetKey> loadStack = assetLoadStack.get(); loadStack.add(keyForTheClone); return (T) smartInfo.asset; } }
Example #26
Source File: NiftyJmeDisplay.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public InputStream getResourceAsStream(String path) { AssetKey<Object> key = new AssetKey<Object>(path); AssetInfo info = assetManager.locateAsset(key); if (info != null){ return info.openStream(); }else{ throw new AssetNotFoundException(path); } }
Example #27
Source File: AssetDataNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected Sheet createSheet() { Sheet sheet = super.createSheet(); AssetData data = getLookup().lookup(AssetData.class); if (data == null) { return sheet; } AssetKey<?> key = data.getAssetKey(); if (key == null) { return sheet; } Sheet.Set set = sheet.createPropertiesSet(); set.setName("AssetKey"); set.setDisplayName("Conversion Settings"); for (Field field : key.getClass().getDeclaredFields()) { PropertyDescriptor prop = PropertyUtils.getPropertyDescriptor(key.getClass(), field); if (prop != null) { try { Property sup = new PropertySupport.Reflection(key, prop.getPropertyType(), prop.getReadMethod(), prop.getWriteMethod()); sup.setName(prop.getName()); sup.setDisplayName(prop.getDisplayName()); set.put(sup); } catch (Exception e) { Exceptions.printStackTrace(e); } } } sheet.put(set); return sheet; }
Example #28
Source File: AssetData.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setAssetKey(AssetKey key){ file.setAssetKeyData(key); }
Example #29
Source File: J3MLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
private void loadFromRoot(List<Statement> roots) throws IOException{ if (roots.size() == 2){ Statement exception = roots.get(0); String line = exception.getLine(); if (line.startsWith("Exception")){ throw new AssetLoadException(line.substring("Exception ".length())); }else{ throw new IOException("In multiroot material, expected first statement to be 'Exception'"); } }else if (roots.size() != 1){ throw new IOException("Too many roots in J3M/J3MD file"); } boolean extending = false; Statement materialStat = roots.get(0); String materialName = materialStat.getLine(); if (materialName.startsWith("MaterialDef")){ materialName = materialName.substring("MaterialDef ".length()).trim(); extending = false; }else if (materialName.startsWith("Material")){ materialName = materialName.substring("Material ".length()).trim(); extending = true; }else{ throw new IOException("Specified file is not a Material file"); } String[] split = materialName.split(":", 2); if (materialName.equals("")){ throw new IOException("Material name cannot be empty"); } if (split.length == 2){ if (!extending){ throw new IOException("Must use 'Material' when extending."); } String extendedMat = split[1].trim(); MaterialDef def = (MaterialDef) owner.loadAsset(new AssetKey(extendedMat)); if (def == null) throw new IOException("Extended material "+extendedMat+" cannot be found."); material = new Material(def); material.setKey(key); // material.setAssetName(fileName); }else if (split.length == 1){ if (extending){ throw new IOException("Expected ':', got '{'"); } materialDef = new MaterialDef(owner, materialName); // NOTE: pass file name for defs so they can be loaded later materialDef.setAssetName(key.getName()); }else{ throw new IOException("Cannot use colon in material name/path"); } for (Statement statement : materialStat.getContents()){ split = statement.getLine().split("[ \\{]"); String statType = split[0]; if (extending){ if (statType.equals("MaterialParameters")){ readExtendingMaterialParams(statement.getContents()); }else if (statType.equals("AdditionalRenderState")){ readAdditionalRenderState(statement.getContents()); }else if (statType.equals("Transparent")){ readTransparentStatement(statement.getLine()); } }else{ if (statType.equals("Technique")){ readTechnique(statement); }else if (statType.equals("MaterialParameters")){ readMaterialParams(statement.getContents()); }else{ throw new IOException("Expected material statement, got '"+statType+"'"); } } } }
Example #30
Source File: Texture.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public AssetKey getKey(){ return this.key; }