Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ nifty-style-black = { module = "com.github.nifty-gui:nifty-style-black",
spotbugs-gradle-plugin = "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.4.8"
vecmath = "javax.vecmath:vecmath:1.5.2"

stb-image = "org.ngengine:stb-image:2.30.4"
imagewebp = "org.ngengine:image-webp-decoder:1.3.0"

[bundles]

[plugins]
Expand Down
4 changes: 1 addition & 3 deletions jme3-android/src/main/resources/com/jme3/asset/Android.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ INCLUDE com/jme3/asset/General.cfg
# Android specific locators
LOCATOR / com.jme3.asset.plugins.AndroidLocator

# Android specific loaders
LOADER com.jme3.texture.plugins.AndroidNativeImageLoader : jpg, bmp, gif, png, jpeg
LOADER com.jme3.texture.plugins.AndroidBufferImageLoader : webp, heic, heif
LOADER com.jme3.texture.plugins.AndroidBufferImageLoader : heic, heif
22 changes: 15 additions & 7 deletions jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,21 @@ public ImageCodec(int bpp, int flags, int maxAlpha, int maxRed, int maxGreen, in

params.put(Format.RGB8, new ByteOffsetImageCodec(3, 0, -1, 0, 1, 2));

params.put(Format.RGB32F, new ByteAlignedImageCodec(12, FLAG_F32,
0, 4, 4, 4,
0, 0, 4, 8));

ByteAlignedImageCodec rgb16f = new ByteAlignedImageCodec(6, FLAG_F16,
0, 2, 2, 2,
0, 0, 2, 4);
params.put(Format.RGB32F, new ByteAlignedImageCodec(12, FLAG_F32,
0, 4, 4, 4,
0, 0, 4, 8));

params.put(Format.R16F, new ByteAlignedImageCodec(2, FLAG_F16,
0, 2, 0, 0,
0, 0, 0, 0));

params.put(Format.RG16F, new ByteAlignedImageCodec(4, FLAG_F16,
0, 2, 2, 0,
0, 0, 2, 0));

ByteAlignedImageCodec rgb16f = new ByteAlignedImageCodec(6, FLAG_F16,
0, 2, 2, 2,
0, 0, 2, 4);
params.put(Format.RGB16F, rgb16f);
params.put(Format.RGB16F_to_RGB111110F, rgb16f);
params.put(Format.RGB16F_to_RGB9E5, rgb16f);
Expand Down
1 change: 0 additions & 1 deletion jme3-core/src/main/resources/com/jme3/asset/Desktop.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
INCLUDE com/jme3/asset/General.cfg

# Desktop-specific loaders
LOADER com.jme3.texture.plugins.AWTLoader : jpg, bmp, gif, png, jpeg
LOADER com.jme3.cursors.plugins.CursorLoader : ani, cur, ico
4 changes: 2 additions & 2 deletions jme3-core/src/main/resources/com/jme3/asset/General.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ LOADER com.jme3.material.plugins.ShaderNodeDefinitionLoader : j3sn
LOADER com.jme3.font.plugins.BitmapFontLoader : fnt
LOADER com.jme3.texture.plugins.DDSLoader : dds
LOADER com.jme3.texture.plugins.PFMLoader : pfm
LOADER com.jme3.texture.plugins.HDRLoader : hdr
LOADER com.jme3.texture.plugins.TGALoader : tga
LOADER com.jme3.export.binary.BinaryLoader : j3o
LOADER com.jme3.export.binary.BinaryLoader : j3f
LOADER com.jme3.scene.plugins.OBJLoader : obj
Expand All @@ -23,4 +21,6 @@ LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, geom, tsctrl, tseval, gl
LOADER com.jme3.scene.plugins.gltf.GltfLoader : gltf
LOADER com.jme3.scene.plugins.gltf.BinLoader : bin
LOADER com.jme3.scene.plugins.gltf.GlbLoader : glb
LOADER com.jme3.texture.plugins.StbImageLoader : jpg, bmp, gif, png, jpeg, tga, psd, hdr
LOADER com.jme3.audio.plugins.OGGLoader : ogg
LOADER com.jme3.texture.plugins.WebpImageLoader : webp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @deprecated use {@link StbImageLoader} instead, which supports HDR images and more formats. This loader is
* kept for backward compatibility but may be removed in future versions.
*/
@Deprecated
public class HDRLoader implements AssetLoader {

private static final Logger logger = Logger.getLogger(HDRLoader.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@
import java.nio.ByteBuffer;

/**
* <code>TextureManager</code> provides static methods for building a
* <code>Texture</code> object. Typically, the information supplied is the
* filename and the texture properties.
* <code>TextureManager</code> provides static methods for building a <code>Texture</code> object. Typically,
* the information supplied is the filename and the texture properties.
*
* @author Mark Powell
* @author Joshua Slack - cleaned, commented, added ability to read 16bit true color and color-mapped TGAs.
* @author Kirill Vainer - ported to jME3
* @version $Id: TGALoader.java 4131 2009-03-19 20:15:28Z blaine.dev $
* @deprecated use {@link StbImageLoader} instead
*/
@Deprecated
public final class TGALoader implements AssetLoader {

// 0 - no image data in file
Expand Down
1 change: 1 addition & 0 deletions jme3-desktop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies {
api project(':jme3-core')
api project(':jme3-plugins')
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
import java.nio.ByteBuffer;
import javax.imageio.ImageIO;

/**
* @deprecated use {@link StbImageLoader} instead, which supports more formats and is more efficient and
* platform agnostic. This loader is kept for backward compatibility but may be removed in future
* versions.
*/
@Deprecated
public class AWTLoader implements AssetLoader {

public static final ColorModel AWT_RGBA4444 = new DirectColorModel(16,
Expand Down
11 changes: 8 additions & 3 deletions jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ public void simpleInitApp() {
// Test for normalized texture coordinates in draco
//loadModelFromPath("Models/gltf/unitSquare11x11_unsignedShortTexCoords-draco.glb");

// Uses EXT_texture_webp - not supported yet
//loadModelSample("SunglassesKhronos", "draco");
// Uses EXT_texture_webp
// loadModelSample("SunglassesKhronos", "draco");
// loadModelSample("CarConcept", "webp");

// Probably invalid model
// See https://github.com/KhronosGroup/glTF-Sample-Assets/issues/264
// loadModelSample("VirtualCity", "draco");

probeNode.attachChild(assets.get(0));

inputManager.addMapping("autorotate", new KeyTrigger(KeyInput.KEY_SPACE));
Expand Down Expand Up @@ -213,10 +213,15 @@ private void loadModelSample(String name, String type) {
path += "/glTF-Binary/";
ext = "glb";
break;
case "webp":
path += "/glTF-WEBP/";
ext = "gltf";
break;
default:
path += "/glTF/";
ext = "gltf";
break;

}
path += name + "." + ext;
loadModelFromPath(path);
Expand Down
3 changes: 3 additions & 0 deletions jme3-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ dependencies {
implementation "org.jmonkeyengine:drako:1.4.5-jme"
implementation project(':jme3-plugins-json')
implementation project(':jme3-plugins-json-gson')
implementation libs.stb.image
implementation libs.imagewebp

testRuntimeOnly project(':jme3-desktop')
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class CustomContentManager {
defaultExtensionLoaders.put("KHR_texture_transform", TextureTransformExtensionLoader.class);
defaultExtensionLoaders.put("KHR_materials_emissive_strength", PBREmissiveStrengthExtensionLoader.class);
defaultExtensionLoaders.put("KHR_draco_mesh_compression", DracoMeshCompressionExtensionLoader.class);
defaultExtensionLoaders.put("EXT_texture_webp", TextureWebpExtensionLoader.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,9 @@ public Texture2D readTexture(JsonObject texture, boolean flip) throws IOExceptio
}

JsonObject textureData = textures.get(textureIndex).getAsJsonObject();
Integer sourceIndex = getAsInteger(textureData, "source");
Integer sourceIndex = TextureWebpExtensionLoader.getTextureSourceIndex(textureData);
Integer samplerIndex = getAsInteger(textureData, "sampler");
assertNotNull(sourceIndex, "Texture has no source");

texture2d = readImage(sourceIndex, flip);

Expand Down Expand Up @@ -1708,4 +1709,4 @@ public static void registerDefaultExtrasLoader(Class<? extends ExtrasLoader> loa
public static void unregisterDefaultExtrasLoader() {
CustomContentManager.defaultExtraLoaderClass = UserDataLoader.class;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.scene.plugins.gltf;

import static com.jme3.scene.plugins.gltf.GltfUtils.assertNotNull;
import static com.jme3.scene.plugins.gltf.GltfUtils.getAsInteger;

import com.jme3.plugins.json.JsonElement;
import com.jme3.plugins.json.JsonObject;
import java.io.IOException;

/**
* Handles EXT_texture_webp texture source selection.
*/
public class TextureWebpExtensionLoader implements ExtensionLoader {

static final String EXTENSION_NAME = "EXT_texture_webp";

static Integer getTextureSourceIndex(JsonObject textureData) {
Integer sourceIndex = getAsInteger(textureData, "source");

JsonObject extensions = textureData.getAsJsonObject("extensions");
if (extensions == null) {
return sourceIndex;
}

JsonObject webpExtension = extensions.getAsJsonObject(EXTENSION_NAME);
if (webpExtension == null) {
return sourceIndex;
}

Integer webpSourceIndex = getAsInteger(webpExtension, "source");
assertNotNull(webpSourceIndex, EXTENSION_NAME + " extension has no source");
return webpSourceIndex;
}

@Override
public Object handleExtension(GltfLoader loader, String parentName, JsonElement parent, JsonElement extension,
Object input) throws IOException {
return input;
}
}
Loading