Jelajahi Sumber

Fixed glTF file loader to work withY is UP and homogeneous coordinates

Updated readme.md
luaacro 9 tahun lalu
induk
melakukan
2238006023
2 mengubah file dengan 16 tambahan dan 3 penghapusan
  1. 6 2
      loaders/glTF/README.md
  2. 10 1
      loaders/glTF/babylon.glTFFileLoader.ts

+ 6 - 2
loaders/glTF/README.md

@@ -26,8 +26,12 @@ BABYLON.SceneLoader.ImportMesh(["myMesh1", "myMesh2", "..."], "./", "duck.gltf",
 
 In order the fix the UP vector (Y with Babylon.js) if you want to play with physics, you can customize the loader:
 ```
-var plugin = BABYLON.SceneLoader.GetPluginForExtension(".gltf");
-plugin.MakeYUP = true; // Which is false by default
+BABYLON.GLTFFileLoader.MakeYUP = true; // false by default
+```
+
+In order to work with homogeneous coordinates (that can be available with some converters and exporters):
+```
+BABYLON.GLTFFileLoader.HomogeneousCoordinates = true; // false by default
 ```
 
 ## Supported features

+ 10 - 1
loaders/glTF/babylon.glTFFileLoader.ts

@@ -860,9 +860,17 @@
                     }
                     else if (semantic === "POSITION") {
                         tempVertexData.positions = [];
-                        for (var j = 0; j < buffer.length; j++) {
+
+                        var count = 3;
+                        if (GLTFFileLoader.HomogeneousCoordinates) {
+                            count = 4;
+                        }
+                        for (var j = 0; j < buffer.length; j += count) {
                             (<number[]>tempVertexData.positions).push(buffer[j]);
+                            (<number[]>tempVertexData.positions).push(buffer[j+1]);
+                            (<number[]>tempVertexData.positions).push(buffer[j+2]);
                         }
+
                         verticesCounts.push(tempVertexData.positions.length);
                     }
                     else if (semantic.indexOf("TEXCOORD_") !== -1) {
@@ -1658,6 +1666,7 @@
         * Static members
         */
         public static MakeYUP: boolean = false;
+        public static HomogeneousCoordinates: boolean = false;
 
         /**
         * Import meshes