public T call() throws Exception { return owner.loadAsset(assetKey); } }
private void startSkeleton(String name) { AssetKey assetKey = new AssetKey(folderName + name + ".xml"); try { animData = (AnimData) assetManager.loadAsset(assetKey); } catch (AssetNotFoundException ex) { logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{assetKey, key}); animData = null; } }
public Material(AssetManager contentMan, String defName) { this((MaterialDef) contentMan.loadAsset(new AssetKey(defName))); }
/** * 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 */ public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) { this.audioKey = new AudioKey(name, stream, streamCache); this.data = (AudioData) assetManager.loadAsset(audioKey); }
public void attachLinkedChild(AssetManager manager, ModelKey key) { addLinkedChild(key); Spatial child = manager.loadAsset(key); assetChildren.put(key, child); attachChild(child); }
protected void loadMtlLib(String name) throws IOException{ if (!name.toLowerCase().endsWith(".mtl")) throw new IOException("Expected .mtl file! Got: " + name); // NOTE: Cut off any relative/absolute paths name = new File(name).getName(); AssetKey mtlKey = new AssetKey(key.getFolder() + name); try { matList = (MaterialList) assetManager.loadAsset(mtlKey); } catch (AssetNotFoundException ex){ logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{name, key}); } if (matList != null){ // create face lists for every material for (String matName : matList.keySet()){ matFaces.put(matName, new ArrayList<Face>()); } } }
@Override public void simpleInitApp() { flyCam.setEnabled(false); // We need the cursor to be visible. If it is not visible the cursor // will still be "used" and loaded, you just won't see it on the screen. inputManager.setCursorVisible(true); /* * To make jME3 use a custom cursor it is as simple as putting the * .cur/.ico/.ani file in an asset directory. Here we use * "Textures/GUI/Cursors". * * For the purpose of this demonstration we load 3 different cursors and add them * into an array list and switch cursor every 8 seconds. * * The first ico has been made by Sirea and the set can be found here: * http://www.rw-designer.com/icon-set/nyan-cat * * The second cursor has been made by Virum64 and is Public Domain. * http://www.rw-designer.com/cursor-set/memes-faces-v64 * * The animated cursor has been made by Pointer Adic and can be found here: * http://www.rw-designer.com/cursor-set/monkey */ cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/meme.cur")); cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/nyancat.ico")); cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/monkey.ani")); sysTime = System.currentTimeMillis(); inputManager.setMouseCursor(cursors.get(count)); }
/** * 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); } }
public static void main(String[] args){ AssetManager assetManager = JmeSystem.newAssetManager(); assetManager.registerLocator("/", ClasspathLocator.class); assetManager.registerLoader(TextLoader.class, "fnt"); System.out.println(assetManager.loadAsset("Interface/Fonts/Console.fnt")); } }
@Override public void read(JmeImporter e) throws IOException { super.read(e); final InputCapsule capsule = e.getCapsule(this); final AssetManager assetManager = e.getAssetManager(); assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>()); 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}); } } }
private static void checkMatDef(String matdefName) { MaterialDef def = (MaterialDef) assetManager.loadAsset(matdefName); EnumSet<Caps> rendererCaps = EnumSet.noneOf(Caps.class); rendererCaps.add(Caps.GLSL100); for (TechniqueDef techDef : def.getTechniqueDefs(TechniqueDef.DEFAULT_TECHNIQUE_NAME)) { DefineList defines = techDef.createDefineList(); Shader shader = techDef.getShader(assetManager, rendererCaps, defines); for (Validator validator : validators) { StringBuilder sb = new StringBuilder(); validator.validate(shader, sb); System.out.println("==== Validator: " + validator.getName() + " " + validator.getInstalledVersion() + " ===="); System.out.println(sb.toString()); } } throw new UnsupportedOperationException(); }
@Override public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException { if (qName.equals("externals")) { checkTopNode("scene"); // Has an externals block, create material list. materialList = new MaterialList(); } else if (qName.equals("item")) { checkTopNode("externals"); if (!attribs.getValue("type").equals("material")) { // This is not a material external. Ignore it. ignoreItem = true; } } else if (qName.equals("file")) { checkTopNode("item"); if (!ignoreItem) { String materialPath = attribs.getValue("name"); String materialName = new File(materialPath).getName(); String matFile = folderName + materialName; try { MaterialList loadedMaterialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(matFile)); materialList.putAll(loadedMaterialList); } catch (AssetNotFoundException ex) { logger.log(Level.WARNING, "Cannot locate material file: {0}", matFile); } } } elementStack.push(qName); }
protected byte[] getBytes(int bufferIndex, String uri, Integer bufferLength) throws IOException { byte[] data; if (uri != null) { if (uri.startsWith("data:")) { //base 64 embed data data = DatatypeConverter.parseBase64Binary(uri.substring(uri.indexOf(",") + 1)); } else { //external file let's load it if (!uri.endsWith(".bin")) { throw new AssetLoadException("Cannot load " + uri + ", a .bin extension is required."); } BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri); InputStream input = (InputStream) info.getManager().loadAsset(key); data = new byte[bufferLength]; DataInputStream dataStream = new DataInputStream(input); dataStream.readFully(data); dataStream.close(); } } else { //no URI this should not happen in a gltf file, only in glb files. throw new AssetLoadException("Buffer " + bufferIndex + " has no uri"); } return data; }
stream.close(); return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList));
@Before public void setUp() throws Exception { when(assetKey.getExtension()).thenReturn(".j3m"); when(assetInfo.getManager()).thenReturn(assetManager); when(assetInfo.getKey()).thenReturn(assetKey); when(assetManager.loadAsset(any(AssetKey.class))).thenReturn(materialDef); j3MLoader = new J3MLoader(); }
int index = findShaderIndexFromVersion(shaderNode, type); String shaderPath = shaderNode.getDefinition().getShadersPath().get(index); Map<String, String> sources = (Map<String, String>) assetManager.loadAsset(new ShaderAssetKey(shaderPath, false)); String loadedSource = sources.get("[main]"); for (String name : sources.keySet()) {
continue; String shaderSourceCode = (String) assetManager.loadAsset(shaderSourceAssetName); shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language);
@Test public void testLoadShaderSource() { JmeSystem.setSystemDelegate(new MockJmeSystemDelegate()); AssetManager assetManager = new DesktopAssetManager(); assetManager.registerLocator(null, ClasspathLocator.class); assetManager.registerLoader(GLSLLoader.class, "frag"); assetManager.registerLoader(GLSLLoader.class, "glsllib"); String showNormals = (String) assetManager.loadAsset("Common/MatDefs/Misc/ShowNormals.frag"); System.out.println(showNormals); }
@Override public void simpleInitApp() { Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml")); signpost.setMaterial( (Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m")); TangentBinormalGenerator.generate(signpost); rootNode.attachChild(signpost); lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMdl.setMaterial( (Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m")); rootNode.attachChild(lightMdl); // flourescent main light pl = new PointLight(); pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f)); rootNode.addLight(pl); // sunset light DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f,-0.7f,1).normalizeLocal()); dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f)); rootNode.addLight(dl); // skylight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.6f,-1,-0.6f).normalizeLocal()); dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f)); rootNode.addLight(dl); // white ambient light dl = new DirectionalLight(); dl.setDirection(new Vector3f(1, -0.5f,-0.1f).normalizeLocal()); dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f)); rootNode.addLight(dl); }