use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class AudioNode method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
// to "audio_key" in case Spatial's key will be written as "key".
if (ic.getSavableVersion(AudioNode.class) == 0) {
audioKey = (AudioKey) ic.readSavable("key", null);
} else {
audioKey = (AudioKey) ic.readSavable("audio_key", null);
}
loop = ic.readBoolean("looping", false);
volume = ic.readFloat("volume", 1);
pitch = ic.readFloat("pitch", 1);
timeOffset = ic.readFloat("time_offset", 0);
dryFilter = (Filter) ic.readSavable("dry_filter", null);
velocity = (Vector3f) ic.readSavable("velocity", null);
reverbEnabled = ic.readBoolean("reverb_enabled", false);
reverbFilter = (Filter) ic.readSavable("reverb_filter", null);
maxDistance = ic.readFloat("max_distance", 20);
refDistance = ic.readFloat("ref_distance", 10);
directional = ic.readBoolean("directional", false);
direction = (Vector3f) ic.readSavable("direction", null);
innerAngle = ic.readFloat("inner_angle", 360);
outerAngle = ic.readFloat("outer_angle", 360);
positional = ic.readBoolean("positional", false);
velocityFromTranslation = ic.readBoolean("velocity_from_translation", false);
if (audioKey != null) {
try {
data = im.getAssetManager().loadAsset(audioKey);
} catch (AssetNotFoundException ex) {
Logger.getLogger(AudioNode.class.getName()).log(Level.FINE, "Cannot locate {0} for audio node {1}", new Object[] { audioKey, key });
data = PlaceholderAssets.getPlaceholderAudio();
}
}
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class Context method createProgramFromSourceFilesWithInclude.
/**
* Creates a program object from the provided source code and files.
* The source code is made up from the specified include string first,
* then all files specified by the resource array (array of asset paths)
* are loaded by the provided asset manager and appended to the source code.
* <p>
* The typical use case is:
* <ul>
* <li>The include string contains some compiler constants like the grid size </li>
* <li>Some common OpenCL files used as libraries (Convention: file names end with {@code .clh}</li>
* <li>One main OpenCL file containing the actual kernels (Convention: file name ends with {@code .cl})</li>
* </ul>
*
* After the files were combined, additional include statements are resolved
* by {@link #createProgramFromSourceCodeWithDependencies(java.lang.String, com.jme3.asset.AssetManager) }.
*
* @param assetManager the asset manager used to load the files
* @param include an additional include string
* @param resources an array of asset paths pointing to OpenCL source files
* @return the new program objects
* @throws AssetNotFoundException if a file could not be loaded
*/
public Program createProgramFromSourceFilesWithInclude(AssetManager assetManager, String include, List<String> resources) {
StringBuilder str = new StringBuilder();
str.append(include);
for (String res : resources) {
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res));
if (info == null) {
throw new AssetNotFoundException("Unable to load source file \"" + res + "\"");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()))) {
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
str.append(line).append('\n');
}
} catch (IOException ex) {
LOG.log(Level.WARNING, "unable to load source file '" + res + "'", ex);
}
}
return createProgramFromSourceCodeWithDependencies(str.toString(), assetManager);
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class Geometry method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
mesh = (Mesh) ic.readSavable("mesh", null);
material = null;
String matName = ic.readString("materialName", null);
if (matName != null) {
// Attempt to load material via J3M
try {
material = im.getAssetManager().loadMaterial(matName);
} catch (AssetNotFoundException ex) {
// Cannot find J3M file.
logger.log(Level.FINE, "Cannot locate {0} for geometry {1}", new Object[] { matName, key });
}
}
// If material is NULL, try to load it from the geometry
if (material == null) {
material = (Material) ic.readSavable("material", null);
}
ignoreTransform = ic.readBoolean("ignoreTransform", false);
if (ic.getSavableVersion(Geometry.class) == 0) {
// Fix shared mesh (if set)
Mesh sharedMesh = getUserData(UserData.JME_SHAREDMESH);
if (sharedMesh != null) {
getMesh().extractVertexData(sharedMesh);
setUserData(UserData.JME_SHAREDMESH, null);
}
}
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class Context method buildSourcesRec.
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
String ln;
while ((ln = reader.readLine()) != null) {
if (ln.trim().startsWith("#import ")) {
ln = ln.trim().substring(8).trim();
if (ln.startsWith("\"")) {
ln = ln.substring(1);
}
if (ln.endsWith("\"")) {
ln = ln.substring(0, ln.length() - 1);
}
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln));
if (info == null) {
throw new AssetNotFoundException("Unable to load source file \"" + ln + "\"");
}
try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) {
builder.append("//-- begin import ").append(ln).append(" --\n");
buildSourcesRec(r, builder, assetManager);
builder.append("//-- end import ").append(ln).append(" --\n");
}
} else {
builder.append(ln).append('\n');
}
}
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class Context method createProgramFromSourceCodeWithDependencies.
/**
* Resolves dependencies (using {@code #include } in the source code)
* and delegates the combined source code to
* {@link #createProgramFromSourceCode(java.lang.String) }.
* Important: only absolute paths are allowed.
* @param sourceCode the original source code
* @param assetManager the asset manager to load the files
* @return the created program object
* @throws AssetNotFoundException if a dependency could not be loaded
*/
public Program createProgramFromSourceCodeWithDependencies(String sourceCode, AssetManager assetManager) {
StringBuilder builder = new StringBuilder(sourceCode.length());
BufferedReader reader = new BufferedReader(new StringReader(sourceCode));
try {
buildSourcesRec(reader, builder, assetManager);
} catch (IOException ex) {
throw new AssetNotFoundException("Unable to read a dependency file", ex);
}
return createProgramFromSourceCode(builder.toString());
}
Aggregations