Skip to content

Commit

Permalink
Fix bug #2277 - GltfLoader (#2309)
Browse files Browse the repository at this point in the history
* fix bug #2277

* update

* script error

* module implementation

* corrections...

---------

Co-authored-by: wil <wil@debian>
  • Loading branch information
2 people authored and scenemax3d committed Oct 21, 2024
1 parent 5cadb88 commit bc6cdf5
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 32 deletions.
4 changes: 2 additions & 2 deletions jme3-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependencies {
implementation project(':jme3-networking')
implementation project(':jme3-niftygui')
implementation project(':jme3-plugins')
// implementation project(':jme3-plugins-json')
// implementation project(':jme3-plugins-json-gson')
implementation project(':jme3-plugins-json')
implementation project(':jme3-plugins-json-gson')
implementation project(':jme3-terrain')
implementation project(':jme3-awt-dialogs')
runtimeOnly project(':jme3-testdata')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.jme3.plugins.json.JsonObject;
import com.jme3.plugins.json.JsonPrimitive;

import java.util.Objects;

/**
* GSON implementation of {@link JsonElement}
*/
Expand All @@ -46,6 +48,23 @@ class GsonElement implements JsonElement {
this.element = element;
}

@Override
public int hashCode() {
return Objects.hashCode(this.element);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final GsonElement other = (GsonElement) obj;
return Objects.equals(this.element, other.element);
}

protected boolean isNull(com.google.gson.JsonElement element) {
if (element == null) return true;
if (element.isJsonNull()) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ public interface JsonElement {
* @return the casted JsonElement
*/
public <T extends JsonElement> T autoCast();

}
4 changes: 3 additions & 1 deletion jme3-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ sourceSets {

dependencies {
api project(':jme3-core')
api 'com.google.code.gson:gson:2.9.1'

implementation project(':jme3-plugins-json')
implementation project(':jme3-plugins-json-gson')
testRuntimeOnly project(':jme3-desktop')
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonElement;
import com.jme3.asset.AssetLoadException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonElement;
import java.io.IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonElement;

/**
* Interface to handle a glTF extra.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonObject;
import com.jme3.plugins.json.JsonPrimitive;
import com.jme3.plugins.json.JsonElement;
import com.jme3.anim.*;
import com.jme3.asset.*;
import com.jme3.material.Material;
Expand Down Expand Up @@ -123,7 +121,7 @@ protected Object loadFromStream(AssetInfo assetInfo, InputStream stream) throws
defaultMat.setFloat("Roughness", 1f);
}

docRoot = JsonParser.parseReader(new JsonReader(new InputStreamReader(stream))).getAsJsonObject();
docRoot = parse(stream);

JsonObject asset = docRoot.getAsJsonObject().get("asset").getAsJsonObject();
getAsString(asset, "generator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonElement;
import com.jme3.plugins.json.JsonObject;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoadException;
import com.jme3.math.*;
import com.jme3.plugins.json.Json;
import com.jme3.plugins.json.JsonParser;
import com.jme3.scene.*;
import com.jme3.texture.Texture;
import com.jme3.util.*;
Expand All @@ -58,8 +60,18 @@ public class GltfUtils {
*/
private GltfUtils() {
}

/**
* Parse a json input stream and returns a {@link JsonObject}
* @param stream the stream to parse
* @return the JsonObject
*/
public static JsonObject parse(InputStream stream) {
JsonParser parser = Json.create();
return parser.parse(stream);
}

public static Mesh.Mode getMeshMode(Integer mode) {
public static Mesh.Mode getMeshMode(Integer mode) {
if (mode == null) {
return Mesh.Mode.Triangles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonElement;
import com.jme3.plugins.json.JsonObject;
import com.jme3.asset.AssetLoadException;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
package com.jme3.scene.plugins.gltf;

import com.jme3.asset.AssetKey;
import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonElement;
import java.io.IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.jme3.asset.AssetKey;

import java.io.IOException;
import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonElement;
import static com.jme3.scene.plugins.gltf.GltfUtils.getAsColor;
import static com.jme3.scene.plugins.gltf.GltfUtils.getAsFloat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonElement;
import com.jme3.plugins.json.JsonObject;
import com.jme3.asset.AssetLoadException;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonElement;
import com.jme3.plugins.json.JsonElement;
import com.jme3.asset.AssetKey;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

package com.jme3.scene.plugins.gltf;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.jme3.plugins.json.JsonArray;
import com.jme3.plugins.json.JsonElement;
import com.jme3.plugins.json.JsonObject;
import com.jme3.plugins.json.JsonPrimitive;
import com.jme3.scene.Spatial;

import java.lang.reflect.Array;
Expand Down

0 comments on commit bc6cdf5

Please sign in to comment.