Search in sources :

Example 56 with Texture

use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.

the class TestSoftwareMouse method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);
    //        inputManager.setCursorVisible(false);
    Texture tex = assetManager.loadTexture("Interface/Logo/Cursor.png");
    cursor = new Picture("cursor");
    cursor.setTexture(assetManager, (Texture2D) tex, true);
    cursor.setWidth(64);
    cursor.setHeight(64);
    guiNode.attachChild(cursor);
    inputManager.addRawInputListener(inputListener);
//        Image img = tex.getImage();
//        ByteBuffer data = img.getData(0);
//        IntBuffer image = BufferUtils.createIntBuffer(64 * 64);
//        for (int y = 0; y < 64; y++){
//            for (int x = 0; x < 64; x++){
//                int rgba = data.getInt();
//                image.put(rgba);
//            }
//        }
//        image.clear();
//
//        try {
//            Cursor cur = new Cursor(64, 64, 2, 62, 1, image, null);
//            Mouse.setNativeCursor(cur);
//        } catch (LWJGLException ex) {
//            Logger.getLogger(TestSoftwareMouse.class.getName()).log(Level.SEVERE, null, ex);
//        }
}
Also used : Picture(com.jme3.ui.Picture) Texture(com.jme3.texture.Texture)

Example 57 with Texture

use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar method createTerrain.

private void createTerrain() {
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    matRock.setBoolean("WardIso", true);
    matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap", grass);
    matRock.setFloat("DiffuseMap_0_scale", 64);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_1", dirt);
    matRock.setFloat("DiffuseMap_1_scale", 16);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_2", rock);
    matRock.setFloat("DiffuseMap_2_scale", 128);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matRock.setTexture("NormalMap", normalMap0);
    matRock.setTexture("NormalMap_1", normalMap2);
    matRock.setTexture("NormalMap_2", normalMap2);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(getCamera());
    TerrainLodControl control = new TerrainLodControl(terrain, cameras);
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);
    terrain.addControl(terrainPhysicsNode);
    rootNode.attachChild(terrain);
    getPhysicsSpace().add(terrainPhysicsNode);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) ChaseCamera(com.jme3.input.ChaseCamera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 58 with Texture

use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method createImage.

private Image createImage() {
    AssetManager assetManager = scene.assetManager;
    Image image = null;
    if (filename != null) {
        // Try load by absolute path
        File file = new File(filename);
        if (file.exists() && file.isFile()) {
            File dir = new File(file.getParent());
            String locatorPath = dir.getAbsolutePath();
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
                tex = assetManager.loadTexture(file.getName());
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null && relativeFilename != null) {
        // Try load by relative path
        File dir = new File(scene.sceneFolderName);
        String locatorPath = dir.getAbsolutePath();
        Texture tex = null;
        try {
            assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            tex = assetManager.loadTexture(relativeFilename);
        } catch (Exception e) {
        } finally {
            assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
        }
        if (tex != null)
            image = tex.getImage();
    }
    if (image == null && content != null) {
        // Try load from content
        String filename = null;
        if (this.filename != null)
            filename = new File(this.filename).getName();
        if (filename != null && this.relativeFilename != null)
            filename = this.relativeFilename;
        // Filename is required to aquire asset loader by extension
        if (filename != null) {
            String locatorPath = scene.sceneFilename;
            // Unique path
            filename = scene.sceneFilename + File.separatorChar + filename;
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, ContentTextureLocator.class);
                tex = assetManager.loadTexture(new ContentTextureKey(filename, content));
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, ContentTextureLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null) {
        // Try to load from files near
        if (relativeFilename != null) {
            String[] split = relativeFilename.split("[\\\\/]");
            String filename = split[split.length - 1];
            Texture tex = null;
            try {
                tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content));
            } catch (Exception e) {
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null)
        return new Image(Image.Format.RGB8, 1, 1, BufferUtils.createByteBuffer((int) ((long) 1 * (long) 1 * (long) Image.Format.RGB8.getBitsPerPixel() / 8L)), ColorSpace.Linear);
    return image;
}
Also used : AssetManager(com.jme3.asset.AssetManager) ContentTextureKey(com.jme3.scene.plugins.fbx.ContentTextureKey) Image(com.jme3.texture.Image) File(java.io.File) Texture(com.jme3.texture.Texture)

Example 59 with Texture

use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.

the class J3MOutputCapsule method formatMatParamTexture.

protected static String formatMatParamTexture(MatParamTexture param) {
    StringBuilder ret = new StringBuilder();
    Texture tex = (Texture) param.getValue();
    TextureKey key;
    if (tex != null) {
        key = (TextureKey) tex.getKey();
        if (key != null && key.isFlipY()) {
            ret.append("Flip ");
        }
        ret.append(formatWrapMode(tex, Texture.WrapAxis.S));
        ret.append(formatWrapMode(tex, Texture.WrapAxis.T));
        ret.append(formatWrapMode(tex, Texture.WrapAxis.R));
        //Min and Mag filter
        Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
        if (tex.getImage().hasMipmaps() || (key != null && key.isGenerateMips())) {
            def = Texture.MinFilter.Trilinear;
        }
        if (tex.getMinFilter() != def) {
            ret.append("Min").append(tex.getMinFilter().name()).append(" ");
        }
        if (tex.getMagFilter() != Texture.MagFilter.Bilinear) {
            ret.append("Mag").append(tex.getMagFilter().name()).append(" ");
        }
        ret.append("\"").append(key.getName()).append("\"");
    }
    return ret.toString();
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture)

Example 60 with Texture

use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method toJmeObject.

@Override
protected Object toJmeObject() {
    Image image = null;
    String fileName = null;
    String relativeFilePathJme;
    if (filePath != null) {
        fileName = getFileName(filePath);
    } else if (relativeFilePath != null) {
        fileName = getFileName(relativeFilePath);
    }
    if (fileName != null) {
        try {
            // Try to load filename relative to FBX folder
            key = new TextureKey(sceneFolderName + fileName);
            key.setGenerateMips(true);
            image = loadImageSafe(assetManager, key);
            // Try to load relative filepath relative to FBX folder
            if (image == null && relativeFilePath != null) {
                // Convert Windows paths to jME3 paths
                relativeFilePathJme = relativeFilePath.replace('\\', '/');
                key = new TextureKey(sceneFolderName + relativeFilePathJme);
                key.setGenerateMips(true);
                image = loadImageSafe(assetManager, key);
            }
            // Try to load embedded image
            if (image == null && content != null && content.length > 0) {
                key = new TextureKey(fileName);
                key.setGenerateMips(true);
                InputStream is = new ByteArrayInputStream(content);
                image = assetManager.loadAssetFromStream(key, is).getImage();
                // NOTE: embedded texture doesn't exist in the asset manager,
                //       so the texture key must not be saved.
                key = null;
            }
        } catch (AssetLoadException ex) {
            logger.log(Level.WARNING, "Error while attempting to load texture {0}:\n{1}", new Object[] { name, ex.toString() });
        }
    }
    if (image == null) {
        logger.log(Level.WARNING, "Cannot locate {0} for texture {1}", new Object[] { fileName, name });
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    return image;
}
Also used : TextureKey(com.jme3.asset.TextureKey) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) Image(com.jme3.texture.Image) AssetLoadException(com.jme3.asset.AssetLoadException)

Aggregations

Material (com.jme3.material.Material)97 Texture (com.jme3.texture.Texture)94 Vector3f (com.jme3.math.Vector3f)66 Geometry (com.jme3.scene.Geometry)40 Image (com.jme3.texture.Image)39 TextureKey (com.jme3.asset.TextureKey)31 ArrayList (java.util.ArrayList)27 Texture2D (com.jme3.texture.Texture2D)25 ColorRGBA (com.jme3.math.ColorRGBA)23 Box (com.jme3.scene.shape.Box)19 Spatial (com.jme3.scene.Spatial)18 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 ParticleEmitter (com.jme3.effect.ParticleEmitter)17 DirectionalLight (com.jme3.light.DirectionalLight)17 Vector2f (com.jme3.math.Vector2f)17 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)16 ByteBuffer (java.nio.ByteBuffer)16 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)15 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 Camera (com.jme3.renderer.Camera)14