Java Code Examples for com.jme3.asset.AssetKey#getName()

The following examples show how to use com.jme3.asset.AssetKey#getName() . 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: EditorUtil.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Open the asset resource in an editor.
 *
 * @param assetKey the asset key.
 */
@FromAnyThread
public static void openInEditor(@Nullable AssetKey<?> assetKey) {

    if (assetKey == null) {
        return;
    }

    var assetPath = assetKey.getName();
    if (StringUtils.isEmpty(assetPath)) {
        return;
    }

    var assetFile = Paths.get(assetPath);
    var realFile = notNull(getRealFile(assetFile));
    if (!Files.exists(realFile)) {
        return;
    }

    FxEventManager.getInstance()
            .notify(new RequestedOpenFileEvent(realFile));
}
 
Example 2
Source File: FolderAssetLocator.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
public AssetInfo locate(@NotNull final AssetManager manager, @NotNull final AssetKey key) {
    if (IGNORE_LOCAL.get() == Boolean.TRUE) {
        return null;
    }

    final Path absoluteFile = Paths.get(key.getName());
    if (Files.exists(absoluteFile)) {
        return null;
    }

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final Path currentAsset = editorConfig.getCurrentAsset();
    if (currentAsset == null) {
        return null;
    }

    final String name = key.getName();
    final Path resolve = currentAsset.resolve(name);
    if (!Files.exists(resolve)) {
        return null;
    }

    return new PathAssetInfo(manager, key, resolve);
}
 
Example 3
Source File: ContentTextureLocator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public AssetInfo locate(AssetManager manager, AssetKey key) {
	if(key instanceof ContentTextureKey) {
		String name = key.getName();
		byte[] content = ((ContentTextureKey) key).getContent();
		if(content != null) {
			return new ContentAssetInfo(manager, key, content);
		} else {
			logger.log(Level.WARNING, "No content for " + name);
			return null;
		}
	} else {
		logger.log(Level.SEVERE, "AssetKey should be TextureContentKey instance");
		return null;
	}
}
 
Example 4
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 5
Source File: AndroidLocator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public AssetInfo locate(com.jme3.asset.AssetManager manager, AssetKey key) 
{
    InputStream in = null;
    String sAssetPath = rootPath + key.getName();
    // Fix path issues
    if (sAssetPath.startsWith("/"))
    {
        // Remove leading /
        sAssetPath = sAssetPath.substring(1);
    }
    sAssetPath = sAssetPath.replace("//", "/");
    try {      
        in = androidManager.open(sAssetPath);
        if (in == null)
            return null;

        return new AndroidAssetInfo(manager, key, sAssetPath);
    } 
    catch (IOException ex) 
    {
        //logger.log(Level.WARNING, "Failed to locate {0} ", sAssetPath);
    }
    return null;
}
 
Example 6
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 7
Source File: SceneLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object load(AssetInfo assetInfo) throws IOException {
	this.currentAssetInfo = assetInfo;
	this.assetManager = assetInfo.getManager();
	AssetKey<?> assetKey = assetInfo.getKey();
	if(assetKey instanceof SceneKey)
		animList = ((SceneKey) assetKey).getAnimations();
	InputStream stream = assetInfo.openStream();
	final Node sceneNode = this.sceneNode = new Node(sceneName + "-scene");
	try {
		sceneFilename = assetKey.getName();
		sceneFolderName = assetKey.getFolder();
		String ext = assetKey.getExtension();
		sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
		if(sceneFolderName != null && sceneFolderName.length() > 0)
			sceneName = sceneName.substring(sceneFolderName.length());
		loadScene(stream);
		linkScene();
		if(warnings.size() > 0)
			logger.log(Level.WARNING, "Model load finished with warnings:\n" + join(warnings, "\n"));
	} finally {
		releaseObjects();
		if(stream != null)
			stream.close();
	}
	return sceneNode;
}
 
Example 8
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 9
Source File: FbxLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Object load(AssetInfo assetInfo) throws IOException {
    this.assetManager = assetInfo.getManager();
    AssetKey<?> assetKey = assetInfo.getKey();
    if (!(assetKey instanceof ModelKey)) {
        throw new AssetLoadException("Invalid asset key");
    }
    
    InputStream stream = assetInfo.openStream();
    try {
        sceneFilename = assetKey.getName();
        sceneFolderName = assetKey.getFolder();
        String ext = assetKey.getExtension();
        
        sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
        if (sceneFolderName != null && sceneFolderName.length() > 0) {
            sceneName = sceneName.substring(sceneFolderName.length());
        }
        
        reset();
        
        // Load the data from the stream.
        loadData(stream);
        
        // Bind poses are needed to compute world transforms.
        applyBindPoses();
        
        // Need world transforms for skeleton creation.
        updateWorldTransforms();
        
        // Need skeletons for meshs to be created in scene graph construction.
        // Mesh bone indices require skeletons to determine bone index.
        constructSkeletons();
        
        // Create the jME3 scene graph from the FBX scene graph.
        // Also creates SkeletonControls based on the constructed skeletons.
        Spatial scene = constructSceneGraph();
        
        // Load animations into AnimControls
        constructAnimations();
       
        return scene;
    } finally {
        releaseObjects();
        if (stream != null) {
            stream.close();
        }
    }
}