Browse Source

Squashed commit of the following:

commit 88634c8ac280fb8f75031c7f3ede531e6bcd1db5
Author: codex <[email protected]>
Date:   Thu Oct 12 11:15:33 2023 -0400

    removed dedicated test, using TestGltfLoading instead

commit 4cce0d08ada6ccf2795383df5b1fc2f683344fa8
Author: codex <[email protected]>
Date:   Mon Oct 9 12:32:11 2023 -0400

    copyright date change

commit 0db0c1e4148cd134b65460ae780a88eead3c4f6c
Author: codex <[email protected]>
Date:   Mon Oct 9 07:50:37 2023 -0400

    fixed javadoc and license

commit fe087ff2eed9243e90df4e9692ff6f4ad0c9ac47
Author: codex <[email protected]>
Date:   Sun Oct 8 19:51:49 2023 -0400

    added docs on test

commit 16be9e59e0cd220736a2183efd031b38f0c55964
Author: codex <[email protected]>
Date:   Sun Oct 8 19:48:07 2023 -0400

    test-model appears as expected
Author: codex 1 year ago
parent
commit
e440f318bf

+ 10 - 0
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@@ -385,6 +385,8 @@ public class GltfLoader implements AssetLoader {
                 JsonObject attributes = meshObject.getAsJsonObject("attributes");
                 assertNotNull(attributes, "No attributes defined for mesh " + mesh);
 
+                boolean useVertexColors = false;
+
                 skinBuffers.clear();
 
                 for (Map.Entry<String, JsonElement> entry : attributes.entrySet()) {
@@ -408,6 +410,10 @@ public class GltfLoader implements AssetLoader {
                             mesh.setBuffer(vb);
                         }
                     }
+                    // if the color buffer is used, we will need to enable vertex colors on the material
+                    if (bufferType.startsWith("COLOR")) {
+                        useVertexColors = true;
+                    }
                 }
                 handleSkinningBuffers(mesh, skinBuffers);
 
@@ -476,6 +482,10 @@ public class GltfLoader implements AssetLoader {
                     }
                 }
 
+                if (useVertexColors) {
+                    geom.getMaterial().setBoolean("UseVertexColor", useVertexColors);
+                }
+
                 geom.setName(name + "_" + index);
                 
                 geom.updateModelBound();

+ 75 - 0
jme3-testdata/src/main/resources/Models/gltf/vertClrBox/BoxVertexColors.gltf

@@ -0,0 +1,75 @@
+{
+    "accessors" : [ {
+      "bufferView" : 0,
+      "byteOffset" : 0,
+      "componentType" : 5123,
+      "count" : 36,
+      "type" : "SCALAR",
+      "max" : [ 23 ],
+      "min" : [ 0 ]
+    }, {
+      "bufferView" : 1,
+      "byteOffset" : 0,
+      "componentType" : 5126,
+      "count" : 24,
+      "type" : "VEC3",
+      "max" : [ 1.0, 1.0, 1.0 ],
+      "min" : [ 0.0, 0.0, 0.0 ]
+    }, {
+      "bufferView" : 1,
+      "byteOffset" : 288,
+      "componentType" : 5126,
+      "count" : 24,
+      "type" : "VEC3",
+      "max" : [ 1.0, 1.0, 1.0 ],
+      "min" : [ -1.0, -1.0, -1.0 ]
+    }, {
+      "bufferView" : 1,
+      "byteOffset" : 576,
+      "componentType" : 5126,
+      "count" : 24,
+      "type" : "VEC3",
+      "max" : [ 1.0, 1.0, 1.0 ],
+      "min" : [ 0.0, 0.0, 0.0 ]
+    } ],
+    "asset" : {
+      "generator" : "JglTF from https://github.com/javagl/JglTF",
+      "version" : "2.0"
+    },
+    "buffers" : [ {
+      "uri" : "buffer.bin",
+      "byteLength" : 936
+    } ],
+    "bufferViews" : [ {
+      "name" : "indices bufferView",
+      "buffer" : 0,
+      "byteOffset" : 0,
+      "byteLength" : 72,
+      "target" : 34963
+    }, {
+      "name" : "attributes bufferView",
+      "buffer" : 0,
+      "byteOffset" : 72,
+      "byteLength" : 864,
+      "byteStride" : 12,
+      "target" : 34962
+    } ],
+    "meshes" : [ {
+      "primitives" : [ {
+        "attributes" : {
+          "POSITION" : 1,
+          "NORMAL" : 2,
+          "COLOR_0" : 3
+        },
+        "indices" : 0,
+        "mode" : 4
+      } ]
+    } ],
+    "nodes" : [ {
+      "mesh" : 0
+    } ],
+    "scene" : 0,
+    "scenes" : [ {
+      "nodes" : [ 0 ]
+    } ]
+  }

BIN
jme3-testdata/src/main/resources/Models/gltf/vertClrBox/buffer.bin