Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #2277 - GltfLoader #2309

Merged
merged 5 commits into from
Sep 4, 2024
Merged
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
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'
Copy link
Contributor

@pspeed42 pspeed42 Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why all of these import and library changes were necessary.

Edit: or rather, I don't understand how Ric's changes were working at all before without this.... and if it was working, I don't know why suddenly it needs to change just to fix how .equals()/.hashCode() is working. I'm very confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pspeed42 I disabled most of Riccardo's changes to work around the bug.

Copy link
Contributor Author

@JNightRider JNightRider Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or rather, I don't understand how Ric's changes were working at all before without this.... and if it was working

These changes were removed as a temporary fix; Currently modules jme3-plugins-json and jme3-plugins-json-gson are not used.

I don't know why suddenly it needs to change just to fix how .equals()/.hashCode() is working.

@riccardobl's changes are no longer present in the loader (for the moment), it wouldn't make sense to fix something that isn't being used, which is why library imports (reconnect) are important.


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
Loading