com.jme3.asset.AssetNotFoundException Java Examples

The following examples show how to use com.jme3.asset.AssetNotFoundException. 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: BaseMaterialEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update the {@link Material} in the {@link EditorThread}.
 *
 * @param material the new material.
 */
@JmeThread
protected void updateMaterialImpl(@NotNull final Material material) {

    final Geometry testBox = getTestBox();
    testBox.setMaterial(material);

    final Geometry testQuad = getTestQuad();
    testQuad.setMaterial(material);

    final Geometry testSphere = getTestSphere();
    testSphere.setMaterial(material);

    final RenderManager renderManager = EditorUtil.getRenderManager();
    try {
        renderManager.preloadScene(testBox);
    } catch (final RendererException | AssetNotFoundException | UnsupportedOperationException e) {
        handleMaterialException(e);
        testBox.setMaterial(EditorUtil.getDefaultMaterial());
        testQuad.setMaterial(EditorUtil.getDefaultMaterial());
        testSphere.setMaterial(EditorUtil.getDefaultMaterial());
    }
}
 
Example #2
Source File: FileLocator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public AssetInfo locate(AssetManager manager, AssetKey key) {
    String name = key.getName();
    File file = new File(root, name);
    if (file.exists() && file.isFile()){
        try {
            // Now, check asset name requirements
            String canonical = file.getCanonicalPath();
            String absolute = file.getAbsolutePath();
            if (!canonical.endsWith(absolute)){
                throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+
                                                 "\"" + canonical + "\" doesn't match \"" + absolute + "\"");
            }
        } catch (IOException ex) {
            throw new AssetLoadException("Failed to get file canonical path " + file, ex);
        }
        
        return new AssetInfoFile(manager, key, file);
    }else{
        return null;
    }
}
 
Example #3
Source File: ImageBasedHeightMapGrid.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    
    try {
        String name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        
        // CREATE HEIGHTMAP
        heightmap = new ImageBasedHeightMap(texture.getImage());
        
        heightmap.setHeightScale(1);
        heightmap.load();
    
    } catch (AssetNotFoundException e) {
        logger.log(Level.SEVERE, "Asset Not found! ", e);
    }
    return heightmap;
}
 
Example #4
Source File: Context.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: Context.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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');
        }
    }
}
 
Example #6
Source File: JmeFilePreviewManager.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Try to load and show the model.
 *
 * @param model the model.
 */
@JmeThread
private void tryToLoad(@NotNull Spatial model) {
    try {

        var renderManager = EditorUtil.getRenderManager();
        renderManager.preloadScene(model);

        modelNode.attachChild(model);

    } catch (RendererException | AssetNotFoundException | UnsupportedOperationException e) {
        EditorUtil.handleException(LOGGER, this, e);
    }
}
 
Example #7
Source File: SceneMaterialLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #8
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #9
Source File: Texture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter e) throws IOException {
    InputCapsule capsule = e.getCapsule(this);
    name = capsule.readString("name", null);
    key = (TextureKey) capsule.readSavable("key", null);
    
    // load texture from key, if available
    if (key != null) {
        // key is available, so try the texture from there.
        try {
            Texture loadedTex = e.getAssetManager().loadTexture(key);
            image = loadedTex.getImage();
        } catch (AssetNotFoundException ex){
            Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Cannot locate texture {0}", key);
            image = PlaceholderAssets.getPlaceholderImage(e.getAssetManager());
        }
    }else{
        // no key is set on the texture. Attempt to load an embedded image
        image = (Image) capsule.readSavable("image", null);
        if (image == null){
            // TODO: what to print out here? the texture has no key or data, there's no useful information .. 
            // assume texture.name is set even though the key is null
            Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Cannot load embedded image {0}", toString() );
        }
    }

    anisotropicFilter = capsule.readInt("anisotropicFilter", 1);
    minificationFilter = capsule.readEnum("minificationFilter",
            MinFilter.class,
            MinFilter.BilinearNoMipMaps);
    magnificationFilter = capsule.readEnum("magnificationFilter",
            MagFilter.class, MagFilter.Bilinear);
}
 
Example #10
Source File: SceneMaterialLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 = assetManager.loadAsset(new OgreMaterialKey(matFile));
                materialList.putAll(loadedMaterialList);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate material file: {0}", matFile);
            }
        }
    }
    elementStack.push(qName);
}
 
Example #11
Source File: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #12
Source File: SpawnPaintingComponent.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
protected void readState(@NotNull SpawnPaintingStateWithEditorTool state, @NotNull VarTable vars) {
    super.readState(state, vars);

    var method = state.getMethod();
    var selectedModels = state.getSelectedModels();

    vars.set(PROPERTY_METHOD, SPAWN_METHODS[method]);
    vars.set(PROPERTY_MIN_SCALE, state.getMinScale());
    vars.set(PROPERTY_MAX_SCALE, state.getMaxScale());
    vars.set(PROPERTY_PADDING, state.getPadding());

    var assetManager = EditorUtil.getAssetManager();

    for (int i = 1; i <= AVAILABLE_MODELS; i++) {

        var selectedModel = selectedModels[i - 1];
        if (selectedModel == null) {
            continue;
        }

        try {
            vars.set(PROPERTY_MODEL + "_" + i, assetManager.loadModel(selectedModel));
        } catch (AssetNotFoundException e) {
            LOGGER.warning(this, e);
        }
    }
}
 
Example #13
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * The process of showing the model in the scene.
 */
@JmeThread
private void openModelImpl(@NotNull final M model) {

    final Node modelNode = getModelNode();
    final M currentModel = getCurrentModel();

    if (currentModel != null) {
        detachPrevModel(modelNode, currentModel);
    }

    NodeUtils.visitGeometry(model, geometry -> {

        final RenderManager renderManager = EditorUtil.getRenderManager();
        try {
            renderManager.preloadScene(geometry);
        } catch (final RendererException | AssetNotFoundException | UnsupportedOperationException e) {
            EditorUtil.handleException(LOGGER, this,
                    new RuntimeException("Found invalid material in the geometry: [" + geometry.getName() + "]. " +
                            "The material will be removed from the geometry.", e));
            geometry.setMaterial(EditorUtil.getDefaultMaterial());
        }
    });

    PRE_TRANSFORM_HANDLERS.forEach(model, Consumer::accept);
    attachModel(model, modelNode);
    POST_TRANSFORM_HANDLERS.forEach(model, Consumer::accept);
    setCurrentModel(model);
}
 
Example #14
Source File: JmeApplication.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void update() {

    var stamp = syncLock();
    try {

        var executor = JmeThreadExecutor.getInstance();
        executor.execute();

        //System.out.println(cam.getRotation());
        //System.out.println(cam.getLocation());

        if (Config.ENABLE_3D) {
            super.update();
        }

    } catch (AssetNotFoundException | NoSuchMethodError | RendererException | AssertionError |
            ArrayIndexOutOfBoundsException | NullPointerException | StackOverflowError |
            IllegalStateException | UnsupportedOperationException e) {
        LOGGER.warning(e);
        finishWorkOnError(e);
    } finally {
        syncUnlock(stamp);
    }

    listener.setLocation(cam.getLocation());
    listener.setRotation(cam.getRotation());
}
 
Example #15
Source File: JmeDesktopSystem.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
    if (SwingUtilities.isEventDispatchThread()) {
        throw new IllegalStateException("Cannot run from EDT");
    }
    if (GraphicsEnvironment.isHeadless()) {
        throw new IllegalStateException("Cannot show dialog in headless environment");
    }

    final AppSettings settings = new AppSettings(false);
    settings.copyFrom(sourceSettings);
    String iconPath = sourceSettings.getSettingsDialogImage();
    if(iconPath == null){
        iconPath = "";
    }
    final URL iconUrl = JmeSystem.class.getResource(iconPath.startsWith("/") ? iconPath : "/" + iconPath);
    if (iconUrl == null) {
        throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
    }

    final AtomicBoolean done = new AtomicBoolean();
    final AtomicInteger result = new AtomicInteger();
    final Object lock = new Object();

    final SelectionListener selectionListener = new SelectionListener() {

        @Override
        public void onSelection(int selection) {
            synchronized (lock) {
                done.set(true);
                result.set(selection);
                lock.notifyAll();
            }
        }
    };
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            synchronized (lock) {
                SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry);
                dialog.setSelectionListener(selectionListener);
                dialog.showDialog();
            }
        }
    });

    synchronized (lock) {
        while (!done.get()) {
            try {
                lock.wait();
            } catch (InterruptedException ex) {
            }
        }
    }

    sourceSettings.copyFrom(settings);

    return result.get() == SettingsDialog.APPROVE_SELECTION;
}
 
Example #16
Source File: ImageTileLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * The ImageHeightmap that will parse the image type that you 
 * specify with setImageType().
 * @param customImageHeightmap must extend AbstractHeightmap
 */
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
    if (!(customImageHeightmap instanceof AbstractHeightMap)) {
        throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
    }
    this.customImageHeightmap = customImageHeightmap;
}*/

private HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    
    String name = null;
    try {
        name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        heightmap = new ImageBasedHeightMap(texture.getImage());
        /*if (assetInfo != null){
            InputStream in = assetInfo.openStream();
            im = ImageIO.read(in);
        } else {
            im = new BufferedImage(patchSize, patchSize, imageType);
            logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
        }*/
        // CREATE HEIGHTMAP
        /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
            heightmap = new Grayscale16BitHeightMap(im);
        } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
            heightmap = new ImageBasedHeightMap(im);
        } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
            // If it gets here, it means you have specified a different image type, and you must
            // then also supply a custom image heightmap class that can parse that image into
            // a heightmap.
            customImageHeightmap.setImage(im);
            heightmap = (AbstractHeightMap) customImageHeightmap;
        } else {
            // error, no supported image format and no custom image heightmap specified
            if (customImageHeightmap == null)
                logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
            if (!(customImageHeightmap instanceof AbstractHeightMap))
                logger.severe("customImageHeightmap must be an AbstractHeightMap!");
            return null;
        }*/
        heightmap.setHeightScale(1);
        heightmap.load();
    //} catch (IOException e) {
    //    e.printStackTrace();
    } catch (AssetNotFoundException e) {
        logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
    }
    return heightmap;
}
 
Example #17
Source File: AudioNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);

    // NOTE: In previous versions of jME3, audioKey was actually
    // written with the name "key". This has been changed
    // 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();
        }
    }
}
 
Example #18
Source File: ShaderNodeLoaderDelegate.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Find the definition from this statement (loads it if necessary)
 *
 * @param statement the statement being read
 * @return the definition
 * @throws IOException
 */
public ShaderNodeDefinition findDefinition(Statement statement) throws IOException {

    final String defLine[] = statement.getLine().split(":");

    if (defLine.length != 3) {
        throw new MatParseException("Can't find shader node definition for: ", statement);
    }

    final Map<String, ShaderNodeDefinition> nodeDefinitions = getNodeDefinitions();
    final String definitionName = defLine[1].trim();
    final String definitionPath = defLine[2].trim();
    final String fullName = definitionName + ":" + definitionPath;

    ShaderNodeDefinition def = nodeDefinitions.get(fullName);
    if (def != null) {
        return def;
    }

    List<ShaderNodeDefinition> defs;
    try {
        defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(definitionPath));
    } catch (final AssetNotFoundException e) {
        throw new MatParseException("Couldn't find " + definitionPath, statement, e);
    }

    for (final ShaderNodeDefinition definition : defs) {
        if (definitionName.equals(definition.getName())) {
            def = definition;
        }
        final String key = definition.getName() + ":" + definitionPath;
        if (!(nodeDefinitions.containsKey(key))) {
            nodeDefinitions.put(key, definition);
        }
    }

    if (def == null) {
        throw new MatParseException(definitionName + " is not a declared as Shader Node Definition", statement);
    }

    return def;
}
 
Example #19
Source File: ImageTileLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * The ImageHeightmap that will parse the image type that you 
 * specify with setImageType().
 * @param customImageHeightmap must extend AbstractHeightmap
 */
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
    if (!(customImageHeightmap instanceof AbstractHeightMap)) {
        throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
    }
    this.customImageHeightmap = customImageHeightmap;
}*/

private HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    
    String name = null;
    try {
        name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        heightmap = new ImageBasedHeightMap(texture.getImage());
        /*if (assetInfo != null){
            InputStream in = assetInfo.openStream();
            im = ImageIO.read(in);
        } else {
            im = new BufferedImage(patchSize, patchSize, imageType);
            logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
        }*/
        // CREATE HEIGHTMAP
        /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
            heightmap = new Grayscale16BitHeightMap(im);
        } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
            heightmap = new ImageBasedHeightMap(im);
        } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
            // If it gets here, it means you have specified a different image type, and you must
            // then also supply a custom image heightmap class that can parse that image into
            // a heightmap.
            customImageHeightmap.setImage(im);
            heightmap = (AbstractHeightMap) customImageHeightmap;
        } else {
            // error, no supported image format and no custom image heightmap specified
            if (customImageHeightmap == null)
                logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
            if (!(customImageHeightmap instanceof AbstractHeightMap))
                logger.severe("customImageHeightmap must be an AbstractHeightMap!");
            return null;
        }*/
        heightmap.setHeightScale(1);
        heightmap.load();
    //} catch (IOException e) {
    //    e.printStackTrace();
    } catch (AssetNotFoundException e) {
        logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
    }
    return heightmap;
}
 
Example #20
Source File: JmeSystemDelegateImpl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
    if (SwingUtilities.isEventDispatchThread()) {
        throw new IllegalStateException("Cannot run from EDT");
    }


    final AppSettings settings = new AppSettings(false);
    settings.copyFrom(sourceSettings);
    String iconPath = sourceSettings.getSettingsDialogImage();
    final URL iconUrl = JmeSystem.class.getResource(iconPath.startsWith("/") ? iconPath : "/" + iconPath);
    if (iconUrl == null) {
        throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
    }

    final AtomicBoolean done = new AtomicBoolean();
    final AtomicInteger result = new AtomicInteger();
    final Object lock = new Object();

    final SelectionListener selectionListener = new SelectionListener() {

        public void onSelection(int selection) {
            synchronized (lock) {
                done.set(true);
                result.set(selection);
                lock.notifyAll();
            }
        }
    };
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            synchronized (lock) {
                SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry);
                dialog.setSelectionListener(selectionListener);
                dialog.showDialog();
            }
        }
    });

    synchronized (lock) {
        while (!done.get()) {
            try {
                lock.wait();
            } catch (InterruptedException ex) {
            }
        }
    }

    sourceSettings.copyFrom(settings);

    return result.get() == SettingsDialog.APPROVE_SELECTION;
}
 
Example #21
Source File: Context.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * 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());
}