com.jme3.asset.AssetManager Java Examples

The following examples show how to use com.jme3.asset.AssetManager. 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: AbstractCreateGeometryAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final ModelChangeConsumer consumer = notNull(nodeTree.getChangeConsumer());
    final SceneLayer defaultLayer = getDefaultLayer(consumer);

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final Geometry geometry = createGeometry();
    geometry.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));

    final TreeNode<?> treeNode = getNode();
    final Node parent = (Node) treeNode.getElement();

    if (defaultLayer != null) {
        SceneLayer.setLayer(defaultLayer, geometry);
    }

    consumer.execute(new AddChildOperation(geometry, parent));
}
 
Example #2
Source File: UrlLocator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public AssetInfo locate(AssetManager manager, AssetKey key) {
        String name = key.getName();
        try{
            //TODO: remove workaround for SDK
//            URL url = new URL(root, name);
            if(name.startsWith("/")){
                name = name.substring(1);
            }
            URL url = new URL(root.toExternalForm() + name);
            return UrlAssetInfo.create(manager, key, url);
        }catch (FileNotFoundException e){
            return null;
        }catch (IOException ex){
            logger.log(Level.WARNING, "Error while locating " + name, ex);
            return null;
        }
    }
 
Example #3
Source File: SceneMatParamOverrideTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testOverrides_SaveAndLoad_KeepsMPOs() {
    MatParamOverride override = mpoInt("val", 5);
    Node scene = createDummyScene();
    scene.getChild("A").addMatParamOverride(override);

    AssetManager assetManager = TestUtil.createAssetManager();
    Node loadedScene = BinaryExporter.saveAndLoad(assetManager, scene);

    Node root = new Node("Root Node");
    root.attachChild(loadedScene);
    validateScene(root);
    validateScene(scene);

    assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
    assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
}
 
Example #4
Source File: MaterialExtensionLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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: 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 #6
Source File: BombControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void prepareEffect(AssetManager assetManager) {
    int COUNT_FACTOR = 1;
    float COUNT_FACTOR_F = 1f;
    effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
    effect.setSelectRandomImage(true);
    effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    effect.setStartSize(1.3f);
    effect.setEndSize(2f);
    effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    effect.setParticlesPerSec(0);
    effect.setGravity(0, -5f, 0);
    effect.setLowLife(.4f);
    effect.setHighLife(.5f);
    effect.setInitialVelocity(new Vector3f(0, 7, 0));
    effect.setVelocityVariation(1f);
    effect.setImagesX(2);
    effect.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    effect.setMaterial(mat);
}
 
Example #7
Source File: PosterizationFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
 
Example #8
Source File: CartoonSSAO.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.renderManager = renderManager;
    this.viewPort = vp;

    int screenWidth = Math.round(w / downsample);
    int screenHeight = Math.round(h / downsample);

    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth);

    frustumNearFar = new Vector2f();

    float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
    float farX = farY * (screenWidth / (float) screenHeight);
    frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
    frustumNearFar.x = vp.getCamera().getFrustumNear();
    frustumNearFar.y = vp.getCamera().getFrustumFar();

    //ssao Pass
    material = new Material(manager, "Common/MatDefs/VR/CartoonSSAO.j3md");
    material.setTexture("Normals", normalPass.getRenderedTexture());        

    material.setVector3("FrustumCorner", frustumCorner);
    material.setVector2("FrustumNearFar", frustumNearFar);
    material.setFloat("Distance", applyDistance);
    if( useOutline == false ) material.setBoolean("disableOutline", true);
    if( instancedRendering ) material.setBoolean("useInstancing", true);
}
 
Example #9
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Spatial doCreateSky(Node parent,
                            Texture west,
                            Texture east,
                            Texture north,
                            Texture south,
                            Texture top,
                            Texture bottom,
                            Vector3f normalScale)
{
    AssetManager manager = SceneApplication.getApplication().getAssetManager();
    Spatial sky = SkyFactory.createSky(manager, west, east, north, south, top, bottom, normalScale);
    parent.attachChild(sky);
    return sky;
}
 
Example #10
Source File: ClasspathManager.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Update libraries loader.
 */
@FromAnyThread
private void updateLibraries() {

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final URLClassLoader currentClassLoader = getLibrariesLoader();

    if (currentClassLoader != null) {
        assetManager.removeClassLoader(currentClassLoader);
        setLibrariesLoader(null);
    }

    final Path path = EDITOR_CONFIG.getFile(PREF_USER_LIBRARY_FOLDER);
    if (path == null) {
        return;
    }

    final Array<Path> jars = FileUtils.getFiles(path, false, JAR_EXTENSIONS);
    final URL[] urls = jars.stream()
            .map(FileUtils::toUrl)
            .toArray(URL[]::new);

    final URLClassLoader classLoader = new URLClassLoader(urls, getClass().getClassLoader());

    assetManager.addClassLoader(classLoader);
    setLibrariesLoader(classLoader);
}
 
Example #11
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];

    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);

    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);

    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);

        shadowFB[i].setDepthTexture(shadowMaps[i]);

        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i; 
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;

        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);

        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }

    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
    setRenderBackFacesShadows(isRenderBackFacesShadows());
}
 
Example #12
Source File: StaticPassLightingLogic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
        EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {

    // TODO: if it ever changes that render isn't called
    // right away with the same geometry after makeCurrent, it would be
    // a problem.
    // Do a radix sort.
    tempDirLights.clear();
    tempPointLights.clear();
    tempSpotLights.clear();
    for (Light light : lights) {
        switch (light.getType()) {
            case Directional:
                tempDirLights.add((DirectionalLight) light);
                break;
            case Point:
                tempPointLights.add((PointLight) light);
                break;
            case Spot:
                tempSpotLights.add((SpotLight) light);
                break;
        }
    }

    defines.set(numDirLightsDefineId, tempDirLights.size());
    defines.set(numPointLightsDefineId, tempPointLights.size());
    defines.set(numSpotLightsDefineId, tempSpotLights.size());

    return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
 
Example #13
Source File: BaseAWTTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private AssetManager createAssetManager() {
    /* Desktop.cfg supports the following additional file formats at the time of writing:
        LOADER com.jme3.texture.plugins.AWTLoader : jpg, bmp, gif, png, jpeg
        LOADER com.jme3.audio.plugins.OGGLoader : ogg
     */
    return JmeSystem.newAssetManager(BaseTest.class.getResource("/com/jme3/asset/Desktop.cfg"));
}
 
Example #14
Source File: ResourceManager.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a file event in an asset folder.
 */
@FromAnyThread
private synchronized void handleFile(@NotNull final Path file) {

    if (Files.isDirectory(file)) {
        return;
    }

    final String extension = FileUtils.getExtension(file);

    final ObjectDictionary<String, Array<String>> interestedResources = getInterestedResources();
    final Array<String> toStore = interestedResources.get(extension);

    if (toStore != null) {
        final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file);
        toStore.add(toAssetPath(assetFile));
    }

    if (extension.endsWith(FileExtensions.JAVA_LIBRARY)) {

        final AssetManager assetManager = EditorUtil.getAssetManager();
        final URL url = get(file, FileUtils::toUrl);

        final Array<URLClassLoader> classLoaders = getClassLoaders();
        final URLClassLoader oldLoader = classLoaders.search(url, (loader, toCheck) -> contains(loader.getURLs(), toCheck));
        if (oldLoader != null) return;

        final URLClassLoader newLoader = new URLClassLoader(toArray(url), getClass().getClassLoader());
        classLoaders.add(newLoader);
        assetManager.addClassLoader(newLoader);
    }
}
 
Example #15
Source File: TestAnisotropicFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Material createCheckerBoardMaterial(AssetManager assetManager) {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex = createCheckerBoardTexture(); // assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.dds");
    tex.setMagFilter(Texture.MagFilter.Bilinear);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    tex.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("ColorMap", tex);
    return mat;
}
 
Example #16
Source File: SimpleWaterProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a SimpleWaterProcessor
 * @param manager the asset manager
 */
public SimpleWaterProcessor(AssetManager manager) {
    this.manager = manager;
    material = new Material(manager, "Common/MatDefs/Water/SimpleWater.j3md");
    material.setFloat("waterDepth", waterDepth);
    material.setFloat("waterTransparency", waterTransparency / 10);
    material.setColor("waterColor", ColorRGBA.White);
    material.setVector3("lightPos", new Vector3f(1, -1, 1));
    
    material.setFloat("distortionScale", distortionScale);
    material.setFloat("distortionMix", distortionMix);
    material.setFloat("texScale", texScale);
    updateClipPlanes();

}
 
Example #17
Source File: PhysicsTestHelper.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Geometry createTestFloor(AssetManager assetManager, float floorDimensions, Vector3f position, ColorRGBA color) {
    Geometry floor = new Geometry("floor", createFloorMesh(20, floorDimensions));
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.getAdditionalRenderState().setWireframe(true);
    material.setColor("Color", color);
    floor.setMaterial(material);
    floor.setLocalTranslation(position);
    return floor;
}
 
Example #18
Source File: CreateSkyDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * The process of creating a new sky.
 */
@FxThread
private void createSkyInBackground() {

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final NodeTree<?> nodeTree = getNodeTree();
    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());

    final FloatTextField normalScaleXSpinner = getNormalScaleXField();
    final FloatTextField normalScaleYSpinner = getNormalScaleYField();
    final FloatTextField normalScaleZSpinner = getNormalScaleZField();

    final Vector3f scale = new Vector3f();
    scale.setX(normalScaleXSpinner.getValue());
    scale.setY(normalScaleYSpinner.getValue());
    scale.setZ(normalScaleZSpinner.getValue());

    final ComboBox<SkyType> skyTypeComboBox = getSkyTypeComboBox();
    final SingleSelectionModel<SkyType> selectionModel = skyTypeComboBox.getSelectionModel();
    final SkyType selectedItem = selectionModel.getSelectedItem();

    if (selectedItem == SkyType.SINGLE_TEXTURE) {
        createSingleTexture(assetManager, changeConsumer, scale);
    } else if (selectedItem == SkyType.MULTIPLE_TEXTURE) {
        createMultipleTexture(assetManager, changeConsumer, scale);
    }
}
 
Example #19
Source File: HDRRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public HDRRenderer(AssetManager manager, Renderer renderer){
    this.manager = manager;
    this.renderer = renderer;
    
    Collection<Caps> caps = renderer.getCaps();
    if (caps.contains(Caps.PackedFloatColorBuffer))
        bufFormat = Format.RGB111110F;
    else if (caps.contains(Caps.FloatColorBuffer))
        bufFormat = Format.RGB16F;
    else{
        enabled = false;
        return;
    }
}
 
Example #20
Source File: GammaCorrectionFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager,
		RenderManager renderManager, ViewPort vp, int w, int h)
{
	material = new Material(manager,
			"Common/MatDefs/Post/GammaCorrection.j3md");
	material.setFloat("gamma", gamma);
	material.setBoolean("computeLuma", computeLuma);
}
 
Example #21
Source File: ClearAssetCacheAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Clear asset cache.
 */
private void process() {
    ExecutorManager.getInstance().addJmeTask(() -> {
        final AssetManager assetManager = EditorUtil.getAssetManager();
        assetManager.clearCache();
    });
}
 
Example #22
Source File: BaseAWTTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AssetManager getAssetManager() {
    if (assetManager == null) {
        assetManager = createAssetManager();
    }

    return assetManager;
}
 
Example #23
Source File: TextureLayer.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set the new normal texture.
 *
 * @param normalFile the file to normal texture or null.
 */
@FromAnyThread
public void setNormalFile(@Nullable final Path normalFile) {
    final AssetManager assetManager = EditorUtil.getAssetManager();
    final Path assetFile = normalFile == null ? null : getAssetFile(normalFile);
    final String assetPath = assetFile == null ? null : toAssetPath(assetFile);
    final Texture texture = assetPath == null ? null : assetManager.loadTexture(assetPath);
    settings.setNormal(texture, getLayer());
}
 
Example #24
Source File: AudioViewerEditor.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void openFile(@NotNull final Path file) {
    super.openFile(file);

    final Path assetFile = notNull(EditorUtil.getAssetFile(file));
    final String assetPath = EditorUtil.toAssetPath(assetFile);

    final AudioKey audioKey = new AudioKey(assetPath);
    final AssetManager assetManager = EditorUtil.getAssetManager();
    final AudioData audioData = assetManager.loadAudio(audioKey);

    final float duration = audioData.getDuration();
    final int bitsPerSample = audioData.getBitsPerSample();
    final int channels = audioData.getChannels();
    final AudioData.DataType dataType = audioData.getDataType();
    final int sampleRate = audioData.getSampleRate();

    final AudioViewer3DPart editorAppState = getEditorAppState();
    editorAppState.load(audioData, audioKey);

    getChannelsField().setText(String.valueOf(channels));
    getDurationField().setText(String.valueOf(duration));
    getDataTypeField().setText(String.valueOf(dataType));
    getSampleRateField().setText(String.valueOf(sampleRate));
    getBitsPerSampleField().setText(String.valueOf(bitsPerSample));
}
 
Example #25
Source File: ZipLocator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AssetInfo locate(AssetManager manager, AssetKey key) {
    String name = key.getName();
    ZipEntry entry = zipfile.getEntry(name);
    if (entry == null)
        return null;
    
    return new JarAssetInfo(manager, key, entry);
}
 
Example #26
Source File: LegacyApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Deprecated
public void setAssetManager(AssetManager assetManager){
    if (this.assetManager != null)
        throw new IllegalStateException("Can only set asset manager"
                                      + " before initialization.");

    this.assetManager = assetManager;
}
 
Example #27
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public NiftyJmeDisplay(AssetManager assetManager, 
                       InputSystem inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    this.assetManager = assetManager;
    //TODO: move
    ((DesktopAssetManager)assetManager).clearCache();
    w = vp.getCamera().getWidth();
    h = vp.getCamera().getHeight();

    soundDev = new SoundDeviceJme(assetManager, audioRenderer);
    renderDev = new RenderDeviceJme(this);
    nifty = new Nifty(renderDev, soundDev, inputManager, new TimeProvider());
}
 
Example #28
Source File: DeleteMaterialsModelFileDeleteHandler.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
public void preDelete(@NotNull final Path file) {
    super.preDelete(file);

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final Path assetFile = notNull(getAssetFile(file));
    final String assetPath = toAssetPath(assetFile);

    final Spatial model;

    try {
        model = assetManager.loadModel(assetPath);
    } catch (final Exception e) {
        LOGGER.warning(this, e);
        return;
    }

    NodeUtils.visitGeometry(model, geometry -> {

        final Material material = geometry.getMaterial();
        final String assetName = material.getAssetName();

        if (!StringUtils.isEmpty(assetName)) {
            assetKeys.add(assetName);
        }
    });
}
 
Example #29
Source File: Technique.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * Prepares the technique for use by loading the shader and setting
     * the proper defines based on material parameters.
     * 
     * @param assetManager The asset manager to use for loading shaders.
     */
    public void makeCurrent(AssetManager assetManager, ListMap<String, MatParam> paramValues) {
        this.paramValues = paramValues;
        defineNameArray = new String[paramValues.size()];
        for(int i=paramValues.size()-1;i>=0;i--) {
            defineNameArray[i] = def.getShaderParamDefine(paramValues.getValue(i).getName());
        }
        // check if reload is needed..
        if (def.isUsingShaders()) {
//            DefineList newDefines = new DefineList();
//            Collection<MatParam> params = owner.getParams();
//            for (MatParam param : params) {
//                String defineName = def.getShaderParamDefine(param.getName());
//                if (defineName != null) {
//                    newDefines.set(defineName, param.getVarType(), param.getValue());
//                }
//            }

            if (!needReload /*&& defines.getCompiled().equals(newDefines.getCompiled())*/) {
//                newDefines = null;
                // defines have not been changed..
            } else {
//                defines.clear();
//                defines.addFrom(newDefines);
                // defines changed, recompile needed
                loadShader(assetManager);
                if (shader != null) {
                    uniformArray = new Uniform[paramValues.size()];
//                    for(int i=paramValues.size()-1;i>=0;i--) {
//                        uniformArray[i] = shader.getUniform(paramValues.getValue(i).getPrefixedName());
//                    }
                    defineNameArray = new String[paramValues.size()];
                    for(int i=paramValues.size()-1;i>=0;i--) {
                        defineNameArray[i] = def.getShaderParamDefine(paramValues.getValue(i).getName());
                    }
                }
            }
        }
    }
 
Example #30
Source File: FileSystemAssetLocator.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@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);
}