Skip to content
Draft
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 jme3-core/src/main/java/com/jme3/scene/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public void generateBindPose() {
pos.getNumComponents(),
pos.getFormat(),
BufferUtils.clone(pos.getData()));
clearBuffer(bindPos.getBufferType());
setBuffer(bindPos);

// XXX: note that this method also sets stream mode
Expand All @@ -379,6 +380,7 @@ public void generateBindPose() {
norm.getNumComponents(),
norm.getFormat(),
BufferUtils.clone(norm.getData()));
clearBuffer(bindNorm.getBufferType());
setBuffer(bindNorm);
norm.setUsage(Usage.Stream);
}
Expand All @@ -390,6 +392,7 @@ public void generateBindPose() {
tangents.getNumComponents(),
tangents.getFormat(),
BufferUtils.clone(tangents.getData()));
clearBuffer(bindTangents.getBufferType());
setBuffer(bindTangents);
tangents.setUsage(Usage.Stream);
}// else hardware setup does nothing, mesh already in bind pose
Expand Down
273 changes: 134 additions & 139 deletions jme3-examples/src/main/java/jme3test/model/TestGltfLoading.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jme3-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sourceSets {

dependencies {
api project(':jme3-core')

implementation "com.openize:drako:1.4.4"
implementation project(':jme3-plugins-json')
implementation project(':jme3-plugins-json-gson')
testRuntimeOnly project(':jme3-desktop')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* Copyright (c) 2009-2026 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 java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import com.jme3.util.BufferUtils;

/**
* A package-private class to perform dequantization of buffers.
*
* This handled buffers that contain (unsigned) byte or short values and that are "normalized", i.e. supposed
* to be interpreted as float values.
*
* (NOTE: Some of these methods are taken from a non-published state of JglTF, but published by the original
* author, as part of JMonkeyEngine)
*/
class BufferQuantization {

/**
* Dequantize the given buffer into a float buffer, treating each element of the input as a signed byte.
*
* @param byteBuffer
* The input buffer
* @return The result
*/
static FloatBuffer dequantizeByteBuffer(ByteBuffer byteBuffer) {
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(byteBuffer.capacity());
for (int i = 0; i < byteBuffer.capacity(); i++) {
byte c = byteBuffer.get(i);
float f = dequantizeByte(c);
floatBuffer.put(i, f);
}
return floatBuffer;
}

/**
* Dequantize the given buffer into a float buffer, treating each element of the input as an unsigned
* byte.
*
* @param byteBuffer
* The input buffer
* @return The result
*/
static FloatBuffer dequantizeUnsignedByteBuffer(ByteBuffer byteBuffer) {
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(byteBuffer.capacity());
for (int i = 0; i < byteBuffer.capacity(); i++) {
byte c = byteBuffer.get(i);
float f = dequantizeUnsignedByte(c);
floatBuffer.put(i, f);
}
return floatBuffer;
}

/**
* Dequantize the given buffer into a float buffer, treating each element of the input as a signed short.
*
* @param shortBuffer
* The input buffer
* @return The result
*/
static FloatBuffer dequantizeShortBuffer(ShortBuffer shortBuffer) {
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(shortBuffer.capacity());
for (int i = 0; i < shortBuffer.capacity(); i++) {
short c = shortBuffer.get(i);
float f = dequantizeShort(c);
floatBuffer.put(i, f);
}
return floatBuffer;
}

/**
* Dequantize the given buffer into a float buffer, treating each element of the input as an unsigned
* short.
*
* @param shortBuffer
* The input buffer
* @return The result
*/
static FloatBuffer dequantizeUnsignedShortBuffer(ShortBuffer shortBuffer) {
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(shortBuffer.capacity());
for (int i = 0; i < shortBuffer.capacity(); i++) {
short c = shortBuffer.get(i);
float f = dequantizeUnsignedShort(c);
floatBuffer.put(i, f);
}
return floatBuffer;
}

/**
* Dequantize the given signed byte into a floating point value
*
* @param c
* The input
* @return The result
*/
private static float dequantizeByte(byte c) {
float f = Math.max(c / 127.0f, -1.0f);
return f;
}

/**
* Dequantize the given unsigned byte into a floating point value
*
* @param c
* The input
* @return The result
*/
private static float dequantizeUnsignedByte(byte c) {
int i = Byte.toUnsignedInt(c);
float f = i / 255.0f;
return f;
}

/**
* Dequantize the given signed short into a floating point value
*
* @param c
* The input
* @return The result
*/
private static float dequantizeShort(short c) {
float f = Math.max(c / 32767.0f, -1.0f);
return f;
}

/**
*
* Dequantize the given unsigned byte into a floating point value
*
* @param c
* The input
* @return The result
*/
private static float dequantizeUnsignedShort(short c) {
int i = Short.toUnsignedInt(c);
float f = i / 65535.0f;
return f;
}

/**
* Private constructor to prevent instantiation
*/
private BufferQuantization() {
// Private constructor to prevent instantiation
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class CustomContentManager {
defaultExtensionLoaders.put("KHR_materials_unlit", UnlitExtensionLoader.class);
defaultExtensionLoaders.put("KHR_texture_transform", TextureTransformExtensionLoader.class);
defaultExtensionLoaders.put("KHR_materials_emissive_strength", PBREmissiveStrengthExtensionLoader.class);
defaultExtensionLoaders.put("KHR_draco_mesh_compression", DracoMeshCompressionExtensionLoader.class);

}

Expand Down
Loading
Loading