Java Code Examples for com.jme3.asset.AssetInfo#getKey()

The following examples show how to use com.jme3.asset.AssetInfo#getKey() . 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: PFMLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    InputStream in = null;
    try {
        in = info.openStream();
        return load(in, ((TextureKey)info.getKey()).isFlipY());
    } finally {
        if (in != null){
            in.close();
        }
    }
    
}
 
Example 2
Source File: DDSLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    InputStream stream = null;
    try {
        stream = info.openStream();
        in = new LittleEndien(stream);
        loadHeader();
        if (texture3D) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Type.ThreeDimensional);
        } else if (depth > 1) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
        }
        ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
        return new Image(pixelFormat, width, height, depth, data, sizes);
    } finally {
        if (stream != null){
            stream.close();
        }
    }
}
 
Example 3
Source File: J3MLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    this.owner = info.getManager();

    InputStream in = info.openStream();
    try {
        key = info.getKey();
        loadFromRoot(BlockLanguageParser.parse(in));
    } finally {
        if (in != null){
            in.close();
        }
    }
    
    if (material != null){
        if (!(info.getKey() instanceof MaterialKey)){
            throw new IOException("Material instances must be loaded via MaterialKey");
        }
        // material implementation
        return material;
    }else{
        // material definition
        return materialDef;
    }
}
 
Example 4
Source File: AndroidTGALoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException{
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey)info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 5
Source File: OGGLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof AudioKey)){
        throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
    }
    
    AudioKey key = (AudioKey) info.getKey();
    boolean readStream = key.isStream();
    boolean streamCache = key.useStreamCache();
    
    InputStream in = null;
    try {
        in = info.openStream();
        AudioData data = load(in, readStream, streamCache);
        if (data instanceof AudioStream){
            // audio streams must remain open
            in = null;
        }
        return data;
    } finally {
        if (in != null){
            in.close();
        }
    }
    
}
 
Example 6
Source File: GdxTGALoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException{
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey)info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 7
Source File: KTXLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in);
        return img;
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
 
Example 8
Source File: HDRLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 9
Source File: TGALoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
 
Example 10
Source File: AWTLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){
        boolean flip = ((TextureKey) info.getKey()).isFlipY();
        InputStream in = null;
        try {
            in = info.openStream();
            Image img = load(in, flip);
            if (img == null){
                throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
            }
            return img;
        } finally {
            if (in != null){
                in.close();
            }
        }
    }else{
        throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported");
    }
}
 
Example 11
Source File: DDSLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }

    InputStream stream = null;
    try {
        stream = info.openStream();
        in = new LittleEndien(stream);
        loadHeader();
        if (texture3D) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional);
        } else if (depth > 1) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap);
        }
        ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
        return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);
    } finally {
        if (stream != null){
            stream.close();
        }
    }
}
 
Example 12
Source File: TGALoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object load(AssetInfo info) throws IOException{
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    boolean flip = ((TextureKey)info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 13
Source File: OGGLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof AudioKey)){
        throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
    }
    
    AudioKey key = (AudioKey) info.getKey();
    boolean readStream = key.isStream();
    boolean streamCache = key.useStreamCache();
    
    InputStream in = null;
    try {
        in = info.openStream();
        AudioData data = load(in, readStream, streamCache);
        if (readStream && !streamCache) {
            // we still need the stream in this case ..
            in = null;
        }
        return data;
    } finally {
        if (in != null){
            in.close();
        }
    }
    
}
 
Example 14
Source File: ShaderNodeDefinitionLoader.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 {
    AssetKey k = assetInfo.getKey();
    if (!(k instanceof ShaderNodeDefinitionKey)) {
        throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey");
    }
    ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k;
    loaderDelegate = new ShaderNodeLoaderDelegate();

    InputStream in = assetInfo.openStream();
    List<Statement> roots = BlockLanguageParser.parse(in);

    if (roots.size() == 2) {
        Statement exception = roots.get(0);
        String line = exception.getLine();
        if (line.startsWith("Exception")) {
            throw new AssetLoadException(line.substring("Exception ".length()));
        } else {
            throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception);
        }
    } else if (roots.size() != 1) {
        throw new MatParseException("Too many roots in J3SN file", roots.get(0));
    }

    return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key);

}
 
Example 15
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 16
Source File: SceneWithAnimationLoader.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 {
	AssetKey<?> key = assetInfo.getKey();
	if(!(key instanceof ModelKey))
		throw new AssetLoadException("Invalid asset key");
	InputStream stream = assetInfo.openStream();
	Scanner scanner = new Scanner(stream);
	AnimationList animList = new AnimationList();
	String modelName = null;
	try {
		while(scanner.hasNextLine()) {
			String line = scanner.nextLine();
			if(line.startsWith("#"))
				continue;
			if(modelName == null) {
				modelName = line;
				continue;
			}
			String[] split = split(line);
			if(split.length < 3)
				throw new IOException("Unparseable string \"" + line + "\"");
			int start;
			int end;
			try {
				start = Integer.parseInt(split[0]);
				end = Integer.parseInt(split[1]);
			} catch(NumberFormatException e) {
				throw new IOException("Unparseable string \"" + line + "\"", e);
			}
			animList.add(split[2], split.length > 3 ? split[3] : null, start, end);
		}
	} finally {
		scanner.close();
		stream.close();
	}
	return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList));
}
 
Example 17
Source File: PFMLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");

    InputStream in = null;
    try {
        in = info.openStream();
        return load(in, ((TextureKey)info.getKey()).isFlipY());
    } finally {
        if (in != null){
            in.close();
        }
    }
    
}
 
Example 18
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();
        }
    }
}
 
Example 19
Source File: GltfUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static GltfModelKey getKey(AssetInfo info) {
    if (info.getKey() instanceof GltfModelKey) {
        return (GltfModelKey) info.getKey();
    }
    return null;
}
 
Example 20
Source File: BlenderLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This method sets up the loader.
 * @param assetInfo
 *            the asset info
 * @throws BlenderFileException
 *             an exception is throw when something wrong happens with blender file
 */
protected void setup(AssetInfo assetInfo) throws BlenderFileException {
    // registering loaders
    ModelKey modelKey = (ModelKey) assetInfo.getKey();
    BlenderKey blenderKey;
    if (modelKey instanceof BlenderKey) {
        blenderKey = (BlenderKey) modelKey;
    } else {
        blenderKey = new BlenderKey(modelKey.getName());
        blenderKey.setAssetRootPath(modelKey.getFolder());
    }

    // opening stream
    BlenderInputStream inputStream = new BlenderInputStream(assetInfo.openStream());

    // reading blocks
    blocks = new ArrayList<FileBlockHeader>();
    FileBlockHeader fileBlock;
    blenderContext = new BlenderContext();
    blenderContext.setBlenderVersion(inputStream.getVersionNumber());
    blenderContext.setAssetManager(assetInfo.getManager());
    blenderContext.setInputStream(inputStream);
    blenderContext.setBlenderKey(blenderKey);

    // creating helpers
    blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber(), blenderContext));
    blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderContext));

    // reading the blocks (dna block is automatically saved in the blender context when found)
    FileBlockHeader sceneFileBlock = null;
    do {
        fileBlock = new FileBlockHeader(inputStream, blenderContext);
        if (!fileBlock.isDnaBlock()) {
            blocks.add(fileBlock);
            // save the scene's file block
            if (fileBlock.getCode() == FileBlockHeader.BLOCK_SC00) {
                sceneFileBlock = fileBlock;
            }
        }
    } while (!fileBlock.isLastBlock());
    if (sceneFileBlock != null) {
        blenderContext.setSceneStructure(sceneFileBlock.getStructure(blenderContext));
    }
}