當前位置: 首頁>>代碼示例>>Java>>正文


Java AssetManager類代碼示例

本文整理匯總了Java中com.jme3.asset.AssetManager的典型用法代碼示例。如果您正苦於以下問題:Java AssetManager類的具體用法?Java AssetManager怎麽用?Java AssetManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AssetManager類屬於com.jme3.asset包,在下文中一共展示了AssetManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toMaterial

import com.jme3.asset.AssetManager; //導入依賴的package包/類
@Override
public MaterialMap toMaterial(AssetManager am, Substance substance, String substance_assets_path) {
	Material mat=new Material(am,"Common/MatDefs/Light/PBRLighting.j3md");
	mat.setName(substance.get("name").toString());
	Map<Object,Object> textures=(Map<Object,Object>)substance.get("textures");
	if(textures!=null){
		for(Entry e:textures.entrySet()){
			String tx=e.getKey().toString();
			if(!e.getValue().toString().isEmpty()){
				tx=tx.substring(tx.lastIndexOf("_")+1);
				String p=substance_assets_path+e.getValue();
				LOGGER.log(Level.FINE,"Set "+tx+"="+p);
				mat.setTexture(tx,am.loadTexture(p));
			}
		}
	}
	MaterialMap map=new MaterialMap();
	map.material=mat;
	map.render_bucket=Bucket.Opaque;
	return map;
}
 
開發者ID:riccardobl,項目名稱:JMELink-SP,代碼行數:22,代碼來源:PBRSubstance.java

示例2: updateLibraries

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Update libraries loader.
 */
@FromAnyThread
private void updateLibraries() {

    final Editor editor = Editor.getInstance();
    final AssetManager assetManager = editor.getAssetManager();
    final URLClassLoader currentClassLoader = getLibrariesLoader();

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

    final Path path = EDITOR_CONFIG.getLibrariesPath();
    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);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:29,代碼來源:ClasspathManager.java

示例3: readJMETexture

import com.jme3.asset.AssetManager; //導入依賴的package包/類
@FXThread
private @NotNull Image readJMETexture(final int width, final int height, @NotNull final String externalForm,
                                      @NotNull final Path cacheFile) {

    final Editor editor = Editor.getInstance();
    final AssetManager assetManager = editor.getAssetManager();
    final Texture texture = assetManager.loadTexture(externalForm);

    final BufferedImage textureImage;
    try {
        textureImage = ImageToAwt.convert(texture.getImage(), false, true, 0);
    } catch (final UnsupportedOperationException e) {
        EditorUtil.handleException(LOGGER, this, e);
        return Icons.IMAGE_512;
    }

    final int imageWidth = textureImage.getWidth();
    final int imageHeight = textureImage.getHeight();

    return scaleAndWrite(width, height, cacheFile, textureImage, imageWidth, imageHeight);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:22,代碼來源:JavaFXImageManager.java

示例4: onAfterCreateJMEContext

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Do some things after when JME context was created.
 */
@JMEThread
private void onAfterCreateJMEContext() {
    final Array<Plugin> plugins = pluginSystem.getPlugins();
    plugins.stream().filter(EditorPlugin.class::isInstance)
            .map(EditorPlugin.class::cast)
            .forEach(editorPlugin -> {
                editorPlugin.onAfterCreateJMEContext(pluginSystem);

                final PluginContainer container = editorPlugin.getContainer();
                final URLClassLoader classLoader = container.getClassLoader();

                final Editor editor = Editor.getInstance();
                final AssetManager assetManager = editor.getAssetManager();
                assetManager.addClassLoader(classLoader);
            });
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:20,代碼來源:PluginManager.java

示例5: showObject

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Show a j3o object.
 *
 * @param path     the path to object.
 * @param external true if the object is external object.
 */
@JMEThread
private void showObject(@NotNull final String path, final boolean external) {
    prepareProcessor();

    final Editor editor = Editor.getInstance();
    final AssetManager assetManager = editor.getAssetManager();
    final Spatial model;

    FolderAssetLocator.setIgnore(external);
    try {
        model = assetManager.loadModel(path);

        if (external && EDITOR_CONFIG.isAutoTangentGenerating()) {
            TangentGenerator.useMikktspaceGenerator(model);
        }

    } finally {
        FolderAssetLocator.setIgnore(false);
    }

    tryToLoad(model);

    final Node rootNode = editor.getPreviewNode();
    rootNode.detachChild(modelNode);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:32,代碼來源:JMEFilePreviewManager.java

示例6: createCollisionPlane

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Create collision plane.
 */
@FromAnyThread
private void createCollisionPlane() {

    final AssetManager assetManager = EDITOR.getAssetManager();

    final Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    final RenderState renderState = material.getAdditionalRenderState();
    renderState.setFaceCullMode(RenderState.FaceCullMode.Off);
    renderState.setWireframe(true);

    final float size = 20000;

    final Geometry geometry = new Geometry("plane", new Quad(size, size));
    geometry.setMaterial(material);
    geometry.setLocalTranslation(-size / 2, -size / 2, 0);

    collisionPlane = new Node();
    collisionPlane.attachChild(geometry);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:23,代碼來源:AbstractSceneEditor3DState.java

示例7: processOpen

import com.jme3.asset.AssetManager; //導入依賴的package包/類
@Override
@FXThread
protected void processOpen(@NotNull final ResourceElement element) {
    super.processOpen(element);

    final ComboBox<String> textureParamNameBox = getTextureParamNameComboBox();
    final SingleSelectionModel<String> selectionModel = textureParamNameBox.getSelectionModel();
    final String textureParamName = selectionModel.getSelectedItem();

    final CheckBox transformBox = getApplyLightingTransformCheckBox();

    final AssetManager assetManager = EDITOR.getAssetManager();

    final Path file = element.getFile();
    final Path assetFile = getAssetFile(file);

    if (assetFile == null) {
        throw new RuntimeException("AssetFile can't be null.");
    }

    final Material material = assetManager.loadAsset(new MaterialKey(toAssetPath(assetFile)));

    final Consumer<ParticlesMaterial> consumer = getConsumer();
    consumer.accept(new ParticlesMaterial(material, textureParamName, transformBox.isSelected()));
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:26,代碼來源:ParticlesAssetEditorDialog.java

示例8: setTexture

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Sets new texture to this property.
 *
 * @param file the file to new texture.
 */
@FXThread
protected void setTexture(@Nullable final Path file) {

    if (file == null) {
        changed(null, getPropertyValue());
    } else {

        final EditorConfig config = EditorConfig.getInstance();
        final Path assetFile = notNull(getAssetFile(file));
        final TextureKey textureKey = new TextureKey(toAssetPath(assetFile));
        textureKey.setFlipY(config.isDefaultUseFlippedTexture());

        final AssetManager assetManager = EDITOR.getAssetManager();
        final Texture2D texture = (Texture2D) assetManager.loadTexture(textureKey);
        texture.setWrap(Texture.WrapMode.Repeat);

        changed(texture, getPropertyValue());
    }
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:25,代碼來源:Texture2DPropertyControl.java

示例9: createMaterialFileIfNeed

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Create a material of the geometry as a file if need.
 *
 * @param geometry the sky geometry.
 */
@BackgroundThread
private @NotNull Material createMaterialFileIfNeed(@NotNull final Geometry geometry) {

    final TextField materialNameField = getMaterialNameField();
    final ChooseFolderControl materialFolderControl = getMaterialFolderControl();

    final Material material = geometry.getMaterial();
    final String content = MaterialSerializer.serializeToString(material);

    final Path folder = materialFolderControl.getFolder();
    final Path materialFile = folder.resolve(materialNameField.getText() + "." + FileExtensions.JME_MATERIAL);

    try {
        Files.write(materialFile, content.getBytes("UTF-8"), WRITE, TRUNCATE_EXISTING, CREATE);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

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

    return assetManager.loadMaterial(assetPath);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:30,代碼來源:CreateSkyDialog.java

示例10: processOpen

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * The process of opening file.
 *
 * @param file the file
 */
protected void processOpen(@NotNull final Path file) {

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final ModelChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());

    final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file);
    final String assetPath = toAssetPath(assetFile);

    final AssetManager assetManager = EDITOR.getAssetManager();
    final Spatial loadedModel = assetManager.loadModel(assetPath);
    final Geometry geometry = NodeUtils.findGeometry(loadedModel);

    if (geometry == null) {
        LOGGER.warning(this, "not found a geometry in the model " + assetPath);
        return;
    }

    final TreeNode<?> treeNode = getNode();
    final ParticleEmitterNode element = (ParticleEmitterNode) treeNode.getElement();

    changeConsumer.execute(new ChangeEmitterMeshOperation(geometry.getMesh(), element));
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:28,代碼來源:LoadModelShapeEmitterAction.java

示例11: process

import com.jme3.asset.AssetManager; //導入依賴的package包/類
@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 = EDITOR.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));
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:24,代碼來源:AbstractCreateGeometryAction.java

示例12: processSave

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * 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 = EDITOR.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);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:31,代碼來源:SaveAsMaterialAction.java

示例13: processOpen

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * The process of opening file.
 *
 * @param file the file
 */
@FXThread
protected void processOpen(@NotNull final Path file) {

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

    final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file);
    final String assetPath = toAssetPath(assetFile);

    final ModelKey modelKey = new ModelKey(assetPath);

    final AssetManager assetManager = EDITOR.getAssetManager();
    final Spatial loadedModel = assetManager.loadModel(modelKey);
    loadedModel.setUserData(LOADED_MODEL_KEY, true);

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

    final TreeNode<?> treeNode = getNode();
    final Node parent = (Node) treeNode.getElement();
    consumer.execute(new AddChildOperation(loadedModel, parent));
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:30,代碼來源:LoadModelAction.java

示例14: process

import com.jme3.asset.AssetManager; //導入依賴的package包/類
@Override
@FXThread
protected void process() {
    super.process();

    final AudioTreeNode audioModelNode = (AudioTreeNode) getNode();
    final AudioNode audioNode = audioModelNode.getElement();

    final AssetManager assetManager = EDITOR.getAssetManager();

    EXECUTOR_MANAGER.addJMETask(() -> {

        final AudioKey audioKey = AudioNodeUtils.getAudioKey(audioNode);
        final AudioData audioData = assetManager.loadAudio(audioKey);

        AudioNodeUtils.updateData(audioNode, audioData, audioKey);

        audioNode.play();
    });
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:21,代碼來源:PlayAudioNodeAction.java

示例15: dropExternalObject

import com.jme3.asset.AssetManager; //導入依賴的package包/類
/**
 * Add the external object to this node.
 *
 * @param node this node.
 * @param cons the change consumer.
 * @param path the path to the external object.
 */
protected void dropExternalObject(@NotNull final T node, @NotNull final ChangeConsumer cons,
                                  @NotNull final Path path) {

    final SceneLayer defaultLayer = getDefaultLayer(cons);
    final Path assetFile = notNull(getAssetFile(path), "Not found asset file for " + path);
    final String assetPath = toAssetPath(assetFile);
    final ModelKey modelKey = new ModelKey(assetPath);

    final AssetManager assetManager = EDITOR.getAssetManager();
    final Spatial loadedModel = assetManager.loadModel(assetPath);
    final AssetLinkNode assetLinkNode = new AssetLinkNode(modelKey);
    assetLinkNode.attachLinkedChild(loadedModel, modelKey);

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

    cons.execute(new AddChildOperation(assetLinkNode, node));
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:27,代碼來源:NodeTreeNode.java


注:本文中的com.jme3.asset.AssetManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。