|
@@ -12,6 +12,7 @@ export class Buffer {
|
|
|
public _data: Nullable<DataArray>;
|
|
|
private _updatable: boolean;
|
|
|
private _instanced: boolean;
|
|
|
+ private _divisor: number;
|
|
|
|
|
|
/**
|
|
|
* Gets the byte stride.
|
|
@@ -27,8 +28,9 @@ export class Buffer {
|
|
|
* @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
|
|
|
* @param instanced whether the buffer is instanced (optional)
|
|
|
* @param useBytes set to true if the stride in in bytes (optional)
|
|
|
+ * @param divisor sets an optional divisor for instances (1 by default)
|
|
|
*/
|
|
|
- constructor(engine: any, data: DataArray, updatable: boolean, stride = 0, postponeInternalCreation = false, instanced = false, useBytes = false) {
|
|
|
+ constructor(engine: any, data: DataArray, updatable: boolean, stride = 0, postponeInternalCreation = false, instanced = false, useBytes = false, divisor?: number) {
|
|
|
if (engine.getScene) { // old versions of VertexBuffer accepted 'mesh' instead of 'engine'
|
|
|
this._engine = engine.getScene().getEngine();
|
|
|
}
|
|
@@ -38,6 +40,7 @@ export class Buffer {
|
|
|
|
|
|
this._updatable = updatable;
|
|
|
this._instanced = instanced;
|
|
|
+ this._divisor = divisor || 1;
|
|
|
|
|
|
this._data = data;
|
|
|
|
|
@@ -55,15 +58,16 @@ export class Buffer {
|
|
|
* @param size defines the size in floats of attributes (position is 3 for instance)
|
|
|
* @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)
|
|
|
* @param instanced defines if the vertex buffer contains indexed data
|
|
|
- * @param useBytes defines if the offset and stride are in bytes
|
|
|
+ * @param useBytes defines if the offset and stride are in bytes *
|
|
|
+ * @param divisor sets an optional divisor for instances (1 by default)
|
|
|
* @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, divisor?: number): VertexBuffer {
|
|
|
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
|
|
|
- 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, this._divisor || divisor);
|
|
|
}
|
|
|
|
|
|
// Properties
|
|
@@ -274,8 +278,10 @@ export class VertexBuffer {
|
|
|
* @param type the type of the component (optional)
|
|
|
* @param normalized whether the data contains normalized data (optional)
|
|
|
* @param useBytes set to true if stride and offset are in bytes (optional)
|
|
|
+ * @param divisor defines the instance divisor to use (1 by default)
|
|
|
*/
|
|
|
- constructor(engine: any, data: DataArray | Buffer, kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number, instanced?: boolean, offset?: number, size?: number, type?: number, normalized = false, useBytes = false) {
|
|
|
+ constructor(engine: any, data: DataArray | Buffer, kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number,
|
|
|
+ instanced?: boolean, offset?: number, size?: number, type?: number, normalized = false, useBytes = false, divisor = 1) {
|
|
|
if (data instanceof Buffer) {
|
|
|
this._buffer = data;
|
|
|
this._ownsBuffer = false;
|
|
@@ -316,7 +322,7 @@ export class VertexBuffer {
|
|
|
this.normalized = normalized;
|
|
|
|
|
|
this._instanced = instanced !== undefined ? instanced : false;
|
|
|
- this._instanceDivisor = instanced ? 1 : 0;
|
|
|
+ this._instanceDivisor = instanced ? divisor : 0;
|
|
|
}
|
|
|
|
|
|
/** @hidden */
|