Pārlūkot izejas kodu

Allow configuration of Instance Divisor

Ben Adams 8 gadi atpakaļ
vecāks
revīzija
d5c1527be6

+ 15 - 0
src/Mesh/babylon.buffer.ts

@@ -6,6 +6,7 @@
         private _updatable: boolean;
         private _strideSize: number;
         private _instanced: boolean;
+        private _instanceDivisor: number;
 
         constructor(engine: any, data: number[] | Float32Array, updatable: boolean, stride: number, postponeInternalCreation?: boolean, instanced?: boolean) {
             if (engine instanceof Mesh) { // old versions of BABYLON.VertexBuffer accepted 'mesh' instead of 'engine'
@@ -26,6 +27,7 @@
             }
 
             this._instanced = instanced;
+            this._instanceDivisor = instanced ? 1 : 0;
         }
 
         public createVertexBuffer(kind: string, offset: number, size: number, stride?: number): VertexBuffer {
@@ -54,6 +56,19 @@
             return this._instanced;
         }
 
+        public get instanceDivisor(): number {
+            return this._instanceDivisor;
+        }
+
+        public set instanceDivisor(value: number) {
+            this._instanceDivisor = value;
+            if (value == 0) {
+                this._instanced = false;
+            } else {
+                this._instanced = true;
+            }
+        }
+
         // Methods
         public create(data?: number[] | Float32Array): void {
             if (!data && this._buffer) {

+ 7 - 0
src/Mesh/babylon.vertexBuffer.ts

@@ -117,6 +117,13 @@
             return this._buffer.getIsInstanced();
         }
 
+        /**
+         * Returns the instancing divisor, zero for non-instanced (integer).  
+         */
+        public getInstanceDivisor(): number {
+            return this._buffer.instanceDivisor;
+        }
+
         // Methods
 
         /**

+ 1 - 1
src/babylon.engine.ts

@@ -1699,7 +1699,7 @@
                     this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
 
                     if (vertexBuffer.getIsInstanced()) {
-                        this._gl.vertexAttribDivisor(order, 1);
+                        this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());
                         if (!this._vaoRecordInProgress) {
                             this._currentInstanceLocations.push(order);
                             this._currentInstanceBuffers.push(buffer);