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

The following examples show how to use com.jme3.asset.AssetInfo#openStream() . 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: 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 2
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 3
Source File: WAVLoader.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 {
    AudioData data;
    InputStream inputStream = null;
    try {
        inputStream = info.openStream();
        data = load(info, inputStream, ((AudioKey)info.getKey()).isStream());
        if (data instanceof AudioStream){
            inputStream = null;
        }
        return data;
    } finally {
        if (inputStream != null){
            inputStream.close();
        }
    }
}
 
Example 4
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 5
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 6
Source File: GLSLLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 *
 * @param owner
 * @param in
 * @param extension
 * @param key
 * @return
 * @throws java.io.IOException
 */
public Object load(AssetInfo info) throws IOException {
    // The input stream provided is for the vertex shader, 
    // to retrieve the fragment shader, use the content manager
    this.owner = info.getManager();
    if (info.getKey().getExtension().equals("glsllib")){
        // NOTE: Loopback, GLSLLIB is loaded by this loader
        // and needs data as InputStream
        return info.openStream();
    }else{
        // GLSLLoader wants result as String for
        // fragment shader
        DependencyNode rootNode = loadNode(info.openStream(), "[main]");
        String code = resolveDependencies(rootNode);
        dependCache.clear();
        return code;
    }
}
 
Example 7
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 8
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 9
Source File: BitmapFontLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    InputStream in = null;
    try {
        in = info.openStream();
        BitmapFont font = load(info.getManager(), info.getKey().getFolder(), in);
        return font;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 10
Source File: MTLLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("empty-statement")
public Object load(AssetInfo info) throws IOException{
    reset();
    
    this.assetManager = info.getManager();
    folderName = info.getKey().getFolder();
    matList = new MaterialList();

    InputStream in = null;
    try {
        in = info.openStream();
        scan = new Scanner(in);
        scan.useLocale(Locale.US);
        
        while (readLine());
    } finally {
        if (in != null){
            in.close();
        }
    }
    
    if (matName != null){
        // still have a material in the vars
        createMaterial();
        resetMaterial();
    }
    
    MaterialList list = matList;

    

    return list;
}
 
Example 11
Source File: SkeletonLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
    assetManager = info.getManager();
    InputStream in = null;
    try {
        in = info.openStream();
        return load(in);
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 12
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 13
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 14
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 15
Source File: GdxAudioLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object load(AssetInfo assetInfo) throws IOException
{

    InputStream in = assetInfo.openStream();
    if (in != null)
    {
        in.close();
    }
    GdxAudioData result = new GdxAudioData();
    result.setAssetKey( assetInfo.getKey() );
    return result;
}
 
Example 16
Source File: AndroidAudioLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object load(AssetInfo assetInfo) throws IOException 
{

    InputStream in = assetInfo.openStream();
    if (in != null)
    {            
        in.close();
    }
    AndroidAudioData result = new AndroidAudioData();
    result.setAssetKey( assetInfo.getKey() );
    return result;
}
 
Example 17
Source File: AndroidNativeImageLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Image load(AssetInfo info) throws IOException {
    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        return load(in, flip, tmpArray);
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example 18
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 19
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 20
Source File: AndroidImageLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Object load(AssetInfo info) throws IOException {
        InputStream in = null;
        Bitmap bitmap = null;
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            in = info.openStream();
            BitmapFactory.decodeStream(in,null, options);
            float scaleW=(float)options.outWidth /256f;  
            float scaleH=(float)options.outHeight/256f;  
            float scale = 1; //Math.max(scaleW,scaleH);            
            in.close();
            in = null;
            options = new BitmapFactory.Options();
            options.inJustDecodeBounds=false;  
            options.inPurgeable = false;
            options.inSampleSize = (int)FastMath.ceil(scale);
            in = info.openStream();
            bitmap = BitmapFactory.decodeStream(in, null, options);
            if (bitmap == null) {
                throw new IOException("Failed to load image: " + info.getKey().getName());
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Format fmt;

        switch (bitmap.getConfig()) {
            case ALPHA_8:
                fmt = Format.Alpha8;
                break;
            case ARGB_4444:
                fmt = Format.ARGB4444;
                break;
            case ARGB_8888:
                fmt = Format.RGBA8;
                break;
            case RGB_565:
                fmt = Format.RGB565;
                break;
            default:
//                return null;
                throw new IOException("Failed to load image: " + info.getKey().getName());
        }

        if (((TextureKey) info.getKey()).isFlipY()) {
            Bitmap newBitmap = null;
            Matrix flipMat = new Matrix();
            flipMat.preScale(1.0f, -1.0f);
            newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), flipMat, false);
            bitmap.recycle();
            bitmap = newBitmap;

            if (bitmap == null) {
                throw new IOException("Failed to flip image: " + info.getKey().getName());
            }
        }

        Image image = new Image(fmt, width, height, null);
        image.setEfficentData(bitmap);
        return image;
    }