com.jme3.asset.TextureKey Java Examples

The following examples show how to use com.jme3.asset.TextureKey. 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: TestBatchNodeTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #2
Source File: TestBatchedTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #3
Source File: HelloPhysics.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Initialize the materials used in this scene. */
public void initMaterials() {
  wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
  key.setGenerateMips(true);
  Texture tex = assetManager.loadTexture(key);
  wall_mat.setTexture("ColorMap", tex);

  stone_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
  key2.setGenerateMips(true);
  Texture tex2 = assetManager.loadTexture(key2);
  stone_mat.setTexture("ColorMap", tex2);

  floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
  key3.setGenerateMips(true);
  Texture tex3 = assetManager.loadTexture(key3);
  tex3.setWrap(WrapMode.Repeat);
  floor_mat.setTexture("ColorMap", tex3);
}
 
Example #4
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 #5
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 #6
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Texture loadTexture( String path, boolean repeat, boolean generateMips ) {
    TextureKey key = new TextureKey(path);
    key.setGenerateMips(generateMips);

    Texture t = assets.loadTexture(key);
    if( t == null ) {
        throw new RuntimeException("Error loading texture:" + path);
    }

    if( repeat ) {
        t.setWrap(Texture.WrapMode.Repeat);
    } else {
        // JME has deprecated Clamp and defaults to EdgeClamp.
        // I think the WrapMode.EdgeClamp javadoc is totally bonkers, though.
        t.setWrap(Texture.WrapMode.EdgeClamp);
    }

    return t;
}
 
Example #7
Source File: MaterialUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Refresh textures in a material.
 *
 * @param material   the material.
 * @param textureKey the texture key.
 */
@JmeThread
private static void refreshTextures(@NotNull Material material, @NotNull String textureKey) {

    var assetManager = EditorUtil.getAssetManager();

    material.getParams().forEach(matParam -> {

        var varType = matParam.getVarType();
        var value = matParam.getValue();

        if (varType != VarType.Texture2D || value == null) {
            return;
        }

        var texture = (Texture) value;
        var key = (TextureKey) texture.getKey();

        if (key != null && StringUtils.equals(key.getName(), textureKey)) {
            var newTexture = assetManager.loadAsset(key);
            matParam.setValue(newTexture);
        }
    });

}
 
Example #8
Source File: MaterialUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Check a material on containing a texture.
 *
 * @param material  the material.
 * @param assetPath the path of the texture.
 * @return true if the material definition contains the texture.
 */
@FromAnyThread
private static boolean containsTexture(@NotNull Material material, @NotNull String assetPath) {

    var materialParams = material.getParams();

    for (var materialParam : materialParams) {

        if (materialParam.getVarType() != VarType.Texture2D) {
            continue;
        }

        var value = (Texture) materialParam.getValue();
        var textureKey = value == null ? null : (TextureKey) value.getKey();
        if (textureKey != null && StringUtils.equals(textureKey.getName(), assetPath)) {
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: Texture2dPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Change a texture to the file.
 *
 * @param file the file of a new texture.
 */
@FxThread
protected void changeTexture(@Nullable Path file) {

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

        var config = EditorConfig.getInstance();
        var assetFile = notNull(getAssetFile(file));
        var textureKey = new TextureKey(toAssetPath(assetFile));
        textureKey.setFlipY(config.getBoolean(PREF_FLIPPED_TEXTURES, PREF_DEFAULT_FLIPPED_TEXTURES));

        var texture = (Texture2D) EditorUtil.getAssetManager()
                .loadTexture(textureKey);
        texture.setWrap(Texture.WrapMode.Repeat);

        changed(texture, getPropertyValue());
    }
}
 
Example #10
Source File: Texture2dPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Open a dialog with texture's settings.
 */
@FxThread
protected void openSettings() {

    var texture = notNull(getPropertyValue());
    var key = (TextureKey) texture.getKey();
    var flipY = key.isFlipY();
    var wrapS = texture.getWrap(Texture.WrapAxis.S);
    var wrapT = texture.getWrap(Texture.WrapAxis.T);
    var magFilter = texture.getMagFilter();
    var minFilter = texture.getMinFilter();

    var properties = ArrayFactory.<PropertyDefinition>newArray(PropertyDefinition.class);
    properties.add(new PropertyDefinition(BOOLEAN, Messages.MATERIAL_MODEL_PROPERTY_CONTROL_FLIP_Y, PROP_FLIP, flipY));
    properties.add(new PropertyDefinition(ENUM, Messages.MATERIAL_MODEL_PROPERTY_CONTROL_WRAP_MODE_S, PROP_WRAP_MODE_S, wrapS));
    properties.add(new PropertyDefinition(ENUM, Messages.MATERIAL_MODEL_PROPERTY_CONTROL_WRAP_MODE_T, PROP_WRAP_MODE_T, wrapT));
    properties.add(new PropertyDefinition(ENUM, Messages.MATERIAL_MODEL_PROPERTY_CONTROL_MAG_FILTER, PROP_MAG_FILTER, magFilter));
    properties.add(new PropertyDefinition(ENUM, Messages.MATERIAL_MODEL_PROPERTY_CONTROL_MIN_FILTER, PROP_MIN_FILTER, minFilter));

    var dialog = new GenericFactoryDialog(properties, this::applyChanges);
    dialog.setTitle(Messages.MATERIAL_MODEL_PROPERTY_CONTROL_TEXTURE_SETTINGS);
    dialog.setButtonOkText(Messages.SIMPLE_DIALOG_BUTTON_APPLY);
    dialog.setButtonCloseText(Messages.SIMPLE_DIALOG_BUTTON_CANCEL);
    dialog.configureSize(DIALOG_SIZE);
    dialog.show();
}
 
Example #11
Source File: TestBatchNodeTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #12
Source File: TestAttachDriver.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupFloor() {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    Box floor = new Box(100, 1f, 100);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));

    floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
    rootNode.attachChild(floorGeom);
    getPhysicsSpace().add(floorGeom);
}
 
Example #13
Source File: TestBrickTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #14
Source File: TestUrlLoading.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    // create a simple plane/quad
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1, true);

    Geometry quad = new Geometry("Textured Quad", quadMesh);

    assetManager.registerLocator("http://www.jmonkeyengine.com/wp-content/uploads/2010/09/",
                            UrlLocator.class);
    TextureKey key = new TextureKey("planet-2.jpg", false);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    quad.setMaterial(mat);

    float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
    quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
    quad.center();

    rootNode.attachChild(quad);
}
 
Example #15
Source File: TestUrlLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    // create a simple plane/quad
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1, true);

    Geometry quad = new Geometry("Textured Quad", quadMesh);

    assetManager.registerLocator("https://raw.githubusercontent.com/jMonkeyEngine/BookSamples/master/assets/Textures/",
                            UrlLocator.class);
    TextureKey key = new TextureKey("mucha-window.png", false);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    quad.setMaterial(mat);

    float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
    quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
    quad.center();

    rootNode.attachChild(quad);
}
 
Example #16
Source File: TestOnlineJar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    // create a simple plane/quad
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1, true);

    Geometry quad = new Geometry("Textured Quad", quadMesh);
    assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/town.zip",
                       HttpZipLocator.class);

    TextureKey key = new TextureKey("grass.jpg", false);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    quad.setMaterial(mat);

    float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
    quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
    quad.center();

    rootNode.attachChild(quad);
}
 
Example #17
Source File: TestBrickTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #18
Source File: TestAttachDriver.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setupFloor() {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    Box floor = new Box(Vector3f.ZERO, 100, 1f, 100);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));

    floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
    rootNode.attachChild(floorGeom);
    getPhysicsSpace().add(floorGeom);
}
 
Example #19
Source File: TestBrickWall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example #20
Source File: TestCylinder.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Cylinder t = new Cylinder(20, 50, 1, 2, true);
    Geometry geom = new Geometry("Cylinder", t);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    geom.setMaterial(mat);
    
    rootNode.attachChild(geom);
}
 
Example #21
Source File: HelloPhysics.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Initialize the materials used in this scene. */
public void initMaterials() {
  wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
  key.setGenerateMips(true);
  Texture tex = assetManager.loadTexture(key);
  wall_mat.setTexture("ColorMap", tex);

  stone_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
  key2.setGenerateMips(true);
  Texture tex2 = assetManager.loadTexture(key2);
  stone_mat.setTexture("ColorMap", tex2);

  floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
  key3.setGenerateMips(true);
  Texture tex3 = assetManager.loadTexture(key3);
  tex3.setWrap(WrapMode.Repeat);
  floor_mat.setTexture("ColorMap", tex3);
}
 
Example #22
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 #23
Source File: J3MLoaderTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void oldStyleTextureParameters_shouldBeSupported() throws Exception {
    when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-oldstyle.j3m"));

    final Texture textureOldStyle = Mockito.mock(Texture.class);
    final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class);

    final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes);
    final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle);

    j3MLoader.load(assetInfo);

    verify(assetManager).loadTexture(textureKeyUsingQuotes);
    verify(assetManager).loadTexture(textureKeyOldStyle);
    verify(textureOldStyle).setWrap(Texture.WrapMode.Repeat);
    verify(textureOldStyleUsingQuotes).setWrap(Texture.WrapMode.Repeat);
}
 
Example #24
Source File: ImageBasedHeightMapGrid.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    
    try {
        String name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        
        // CREATE HEIGHTMAP
        heightmap = new ImageBasedHeightMap(texture.getImage());
        
        heightmap.setHeightScale(1);
        heightmap.load();
    
    } catch (AssetNotFoundException e) {
        logger.log(Level.SEVERE, "Asset Not found! ", e);
    }
    return heightmap;
}
 
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
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();
        }
    }
}