Bläddra i källkod

Merge pull request #4074 from a-carvallo/pass-useBytes-from-updateDirectly

Pass useBytes in updateVerticesDataDirectly in Geometry & VertexBuffer
David Catuhe 7 år sedan
förälder
incheckning
978800c067
3 ändrade filer med 15 tillägg och 11 borttagningar
  1. 6 6
      src/Mesh/babylon.buffer.ts
  2. 3 2
      src/Mesh/babylon.geometry.ts
  3. 6 3
      src/Mesh/babylon.vertexBuffer.ts

+ 6 - 6
src/Mesh/babylon.buffer.ts

@@ -34,7 +34,7 @@
 
 
             this._data = data;
             this._data = data;
 
 
-            this.byteStride = useBytes ? stride : stride * 4;
+            this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;
 
 
             if (!postponeInternalCreation) { // by default
             if (!postponeInternalCreation) { // by default
                 this.create();
                 this.create();
@@ -52,8 +52,8 @@
          * @returns the new vertex buffer
          * @returns the new vertex buffer
          */
          */
         public createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes = false): VertexBuffer {
         public createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes = false): VertexBuffer {
-            const byteOffset = useBytes ? offset : offset * 4;
-            const byteStride = stride ? (useBytes ? stride : stride * 4) : this.byteStride;
+            const byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;
+            const byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;
 
 
             // a lot of these parameters are ignored as they are overriden by the buffer
             // a lot of these parameters are ignored as they are overriden by the buffer
             return new VertexBuffer(this._engine, this, kind, this._updatable, true, byteStride, instanced === undefined ? this._instanced : instanced, byteOffset, size, undefined, undefined, true);
             return new VertexBuffer(this._engine, this, kind, this._updatable, true, byteStride, instanced === undefined ? this._instanced : instanced, byteOffset, size, undefined, undefined, true);
@@ -79,7 +79,7 @@
          * @returns the stride in float32 units
          * @returns the stride in float32 units
          */
          */
         public getStrideSize(): number {
         public getStrideSize(): number {
-            return this.byteStride / 4;
+            return this.byteStride / Float32Array.BYTES_PER_ELEMENT;
         }
         }
 
 
         // Methods
         // Methods
@@ -123,13 +123,13 @@
          * @param vertexCount the vertex count (optional)
          * @param vertexCount the vertex count (optional)
          * @param useBytes set to true if the offset is in bytes
          * @param useBytes set to true if the offset is in bytes
          */
          */
-        public updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes = false): void {
+        public updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes: boolean = false): void {
             if (!this._buffer) {
             if (!this._buffer) {
                 return;
                 return;
             }
             }
 
 
             if (this._updatable) { // update buffer
             if (this._updatable) { // update buffer
-                this._engine.updateDynamicVertexBuffer(this._buffer, data, useBytes ? offset : offset * 4, (vertexCount ? vertexCount * this.byteStride : undefined));
+                this._engine.updateDynamicVertexBuffer(this._buffer, data, useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT, (vertexCount ? vertexCount * this.byteStride : undefined));
                 this._data = null;
                 this._data = null;
             }
             }
         }
         }

+ 3 - 2
src/Mesh/babylon.geometry.ts

@@ -271,15 +271,16 @@
          * @param kind defines the data kind (Position, normal, etc...)
          * @param kind defines the data kind (Position, normal, etc...)
          * @param data defines the data to use 
          * @param data defines the data to use 
          * @param offset defines the offset in the target buffer where to store the data
          * @param offset defines the offset in the target buffer where to store the data
+         * @param useBytes set to true if the offset is in bytes
          */
          */
-        public updateVerticesDataDirectly(kind: string, data: Float32Array, offset: number): void {
+        public updateVerticesDataDirectly(kind: string, data: DataArray, offset: number, useBytes: boolean = false): void {
             var vertexBuffer = this.getVertexBuffer(kind);
             var vertexBuffer = this.getVertexBuffer(kind);
 
 
             if (!vertexBuffer) {
             if (!vertexBuffer) {
                 return;
                 return;
             }
             }
 
 
-            vertexBuffer.updateDirectly(data, offset);
+            vertexBuffer.updateDirectly(data, offset, useBytes);
             this.notifyUpdate(kind);
             this.notifyUpdate(kind);
         }
         }
 
 

+ 6 - 3
src/Mesh/babylon.vertexBuffer.ts

@@ -232,10 +232,13 @@
 
 
         /**
         /**
          * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.  
          * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.  
-         * Returns the directly updated WebGLBuffer. 
+         * Returns the directly updated WebGLBuffer.
+         * @param data the new data
+         * @param offset the new offset
+         * @param useBytes set to true if the offset is in bytes
          */
          */
-        public updateDirectly(data: DataArray, offset: number): void {
-            return this._buffer.updateDirectly(data, offset);
+        public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {
+            this._buffer.updateDirectly(data, offset, undefined, useBytes);
         }
         }
 
 
         /** 
         /**