Browse Source

Merge pull request #5074 from bghgary/gltf-compat-fix

glTF loader compatibility fix
David Catuhe 7 years ago
parent
commit
39660219cd
2 changed files with 11 additions and 4 deletions
  1. 9 2
      loaders/src/glTF/2.0/babylon.glTFLoader.ts
  2. 2 2
      sandbox/index.js

+ 9 - 2
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -1357,11 +1357,18 @@ module BABYLON.GLTF2 {
                     return new VertexBuffer(this.babylonScene.getEngine(), data, kind, false);
                 });
             }
+            // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
+            else if (accessor.byteOffset && accessor.byteOffset % VertexBuffer.GetTypeByteLength(accessor.componentType) !== 0) {
+                Tools.Warn("Accessor byte offset is not a multiple of component type byte length");
+                accessor._babylonVertexBuffer = this._loadFloatAccessorAsync(`#/accessors/${accessor.index}`, accessor).then(data => {
+                    return new VertexBuffer(this.babylonScene.getEngine(), data, kind, false);
+                });
+            }
             else {
                 const bufferView = ArrayItem.Get(`${context}/bufferView`, this.gltf.bufferViews, accessor.bufferView);
-                accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView, kind).then(buffer => {
+                accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView, kind).then(babylonBuffer => {
                     const size = GLTFLoader._GetNumComponents(context, accessor.type);
-                    return new VertexBuffer(this.babylonScene.getEngine(), buffer, kind, false, false, bufferView.byteStride,
+                    return new VertexBuffer(this.babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView.byteStride,
                         false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
                 });
             }

+ 2 - 2
sandbox/index.js

@@ -313,9 +313,9 @@ if (BABYLON.Engine.isSupported()) {
             else {
                 footer.style.display = "none";
                 errorZone.style.display = "none";
-                if (enableDebugLayer) {
+                if (debugLayerEnabled) {
                     currentScene.debugLayer.hide();
-                    enableDebugLayer = false;
+                    debugLayerEnabled = false;
                 }
             }
         }