@babylonjs/core 7.13.3 → 7.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Buffers/buffer.js CHANGED
@@ -645,7 +645,7 @@ export class VertexBuffer {
645
645
  return new Float32Array(data, byteOffset, count);
646
646
  }
647
647
  else {
648
- let offset = data.byteOffset + byteOffset;
648
+ const offset = data.byteOffset + byteOffset;
649
649
  if (forceCopy) {
650
650
  const result = new Float32Array(count);
651
651
  const source = new Float32Array(data.buffer, offset, count);
@@ -655,7 +655,9 @@ export class VertexBuffer {
655
655
  // Protect against bad data
656
656
  const remainder = offset % 4;
657
657
  if (remainder) {
658
- offset = Math.max(0, offset - remainder);
658
+ Logger.Warn("GetFloatData: copied misaligned data.");
659
+ // If not aligned, copy the data to aligned buffer
660
+ return new Float32Array(data.buffer.slice(offset, offset + count * 4));
659
661
  }
660
662
  return new Float32Array(data.buffer, offset, count);
661
663
  }
@@ -1 +1 @@
1
- {"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../../../dev/core/src/Buffers/buffer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,MAAM;IAYf;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAOD;;;;;;;;;;;OAWG;IACH,YACI,MAAsB,EACtB,IAA4B,EAC5B,SAAkB,EAClB,MAAM,GAAG,CAAC,EACV,wBAAwB,GAAG,KAAK,EAChC,SAAS,GAAG,KAAK,EACjB,QAAQ,GAAG,KAAK,EAChB,OAAgB,EAChB,KAAc;QArCV,oBAAe,GAAG,KAAK,CAAC;QACxB,gBAAW,GAAG,KAAK,CAAC;QAsCxB,IAAI,MA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AACoB,8BAAiB,GAAG,SAAS,CAAC,iBAAiB,AAA9B,CAA+B;AACvE;;GAEG;AACoB,gCAAmB,GAAG,SAAS,CAAC,mBAAmB,AAAhC,CAAiC;AAC3E;;GAEG;AACoB,gCAAmB,GAAG,SAAS,CAAC,mBAAmB,AAAhC,CAAiC;AAC3E;;GAEG;AACoB,qCAAwB,GAAG,SAAS,CAAC,wBAAwB,AAArC,CAAsC;AACrF;;GAEG;AACoB,qCAAwB,GAAG,SAAS,CAAC,wBAAwB,AAArC,CAAsC","sourcesContent":["import type { Nullable, DataArray, FloatArray } from \"../types\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { DataBuffer } from \"./dataBuffer\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\n/**\r\n * Class used to store data that will be store in GPU memory\r\n */\r\nexport class Buffer {\r\n private _engine: AbstractEngine;\r\n private _buffer: Nullable<DataBuffer>;\r\n /** @internal */\r\n public _data: Nullable<DataArray>;\r\n private _updatable: boolean;\r\n private _instanced: boolean;\r\n private _divisor: number;\r\n private _isAlreadyOwned = false;\r\n private _isDisposed = false;\r\n private _label?: string;\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is disposed\r\n */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this buffer\r\n * @param updatable whether the data is updatable\r\n * @param stride the stride (optional)\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param useBytes set to true if the stride in in bytes (optional)\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n * @param label defines the label of the buffer (for debug purpose)\r\n */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | DataBuffer,\r\n updatable: boolean,\r\n stride = 0,\r\n postponeInternalCreation = false,\r\n instanced = false,\r\n useBytes = false,\r\n divisor?: number,\r\n label?: string\r\n ) {\r\n if (engine && (engine as unknown as Mesh).getScene) {\r\n // old versions of VertexBuffer accepted 'mesh' instead of 'engine'\r\n this._engine = (engine as unknown as Mesh).getScene().getEngine();\r\n } else {\r\n this._engine = engine;\r\n }\r\n\r\n this._updatable = updatable;\r\n this._instanced = instanced;\r\n this._divisor = divisor || 1;\r\n this._label = label;\r\n\r\n if (data instanceof DataBuffer) {\r\n this._data = null;\r\n this._buffer = data;\r\n } else {\r\n this._data = data;\r\n this._buffer = null;\r\n }\r\n\r\n this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;\r\n\r\n if (!postponeInternalCreation) {\r\n // by default\r\n this.create();\r\n }\r\n }\r\n\r\n /**\r\n * Create a new VertexBuffer based on the current buffer\r\n * @param kind defines the vertex buffer kind (position, normal, etc.)\r\n * @param offset defines offset in the buffer (0 by default)\r\n * @param size defines the size in floats of attributes (position is 3 for instance)\r\n * @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)\r\n * @param instanced defines if the vertex buffer contains indexed data\r\n * @param useBytes defines if the offset and stride are in bytes *\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n * @returns the new vertex buffer\r\n */\r\n public createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes = false, divisor?: number): VertexBuffer {\r\n const byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;\r\n const byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;\r\n\r\n // a lot of these parameters are ignored as they are overridden by the buffer\r\n return new VertexBuffer(\r\n this._engine,\r\n this,\r\n kind,\r\n this._updatable,\r\n true,\r\n byteStride,\r\n instanced === undefined ? this._instanced : instanced,\r\n byteOffset,\r\n size,\r\n undefined,\r\n undefined,\r\n true,\r\n this._divisor || divisor\r\n );\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._updatable;\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable<DataArray> {\r\n return this._data;\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable<DataBuffer> {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / Float32Array.BYTES_PER_ELEMENT;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. Creates the buffer if not used already.\r\n * If the buffer was already used, it will be updated only if it is updatable, otherwise it will do nothing.\r\n * @param data defines the data to store\r\n */\r\n public create(data: Nullable<DataArray> = null): void {\r\n if (!data && this._buffer) {\r\n return; // nothing to do\r\n }\r\n\r\n data = data || this._data;\r\n\r\n if (!data) {\r\n return;\r\n }\r\n\r\n if (!this._buffer) {\r\n // create buffer\r\n if (this._updatable) {\r\n this._buffer = this._engine.createDynamicVertexBuffer(data, this._label);\r\n this._data = data;\r\n } else {\r\n this._buffer = this._engine.createVertexBuffer(data, undefined, this._label);\r\n }\r\n } else if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(this._buffer, data);\r\n this._data = data;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (!this._data) {\r\n if (!this._buffer) {\r\n // Buffer was not yet created, nothing to do\r\n return;\r\n }\r\n if (this._buffer.capacity > 0) {\r\n // We can at least recreate the buffer with the right size, even if we don't have the data\r\n if (this._updatable) {\r\n this._buffer = this._engine.createDynamicVertexBuffer(this._buffer.capacity, this._label);\r\n } else {\r\n this._buffer = this._engine.createVertexBuffer(this._buffer.capacity, undefined, this._label);\r\n }\r\n return;\r\n }\r\n Logger.Warn(`Missing data for buffer \"${this._label}\" ${this._buffer ? \"(uniqueId: \" + this._buffer.uniqueId + \")\" : \"\"}. Buffer reconstruction failed.`);\r\n this._buffer = null;\r\n } else {\r\n this._buffer = null;\r\n this.create(this._data);\r\n }\r\n }\r\n\r\n /**\r\n * Update current buffer data\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this.create(data);\r\n }\r\n\r\n /**\r\n * Updates the data directly.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param vertexCount the vertex count (optional)\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes: boolean = false): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(\r\n this._buffer,\r\n data,\r\n useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT,\r\n vertexCount ? vertexCount * this.byteStride : undefined\r\n );\r\n if (offset === 0 && vertexCount === undefined) {\r\n // Keep the data if we easily can\r\n this._data = data;\r\n } else {\r\n this._data = null;\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _increaseReferences() {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (!this._isAlreadyOwned) {\r\n this._isAlreadyOwned = true;\r\n return;\r\n }\r\n\r\n this._buffer.references++;\r\n }\r\n\r\n /**\r\n * Release all resources\r\n */\r\n public dispose(): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n // The data buffer has an internal counter as this buffer can be used by several VertexBuffer objects\r\n // This means that we only flag it as disposed when all references are released (when _releaseBuffer will return true)\r\n if (this._engine._releaseBuffer(this._buffer)) {\r\n this._isDisposed = true;\r\n this._data = null;\r\n this._buffer = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to be used when creating a vertex buffer\r\n */\r\nexport interface IVertexBufferOptions {\r\n /**\r\n * whether the data is updatable (default: false)\r\n */\r\n updatable?: boolean;\r\n /**\r\n * whether to postpone creating the internal WebGL buffer (default: false)\r\n */\r\n postponeInternalCreation?: boolean;\r\n /**\r\n * the stride (will be automatically computed from the kind parameter if not specified)\r\n */\r\n stride?: number;\r\n /**\r\n * whether the buffer is instanced (default: false)\r\n */\r\n instanced?: boolean;\r\n /**\r\n * the offset of the data (default: 0)\r\n */\r\n offset?: number;\r\n /**\r\n * the number of components (will be automatically computed from the kind parameter if not specified)\r\n */\r\n size?: number;\r\n /**\r\n * the type of the component (will be deduce from the data parameter if not specified)\r\n */\r\n type?: number;\r\n /**\r\n * whether the data contains normalized data (default: false)\r\n */\r\n normalized?: boolean;\r\n /**\r\n * set to true if stride and offset are in bytes (default: false)\r\n */\r\n useBytes?: boolean;\r\n /**\r\n * defines the instance divisor to use (default: 1, only used if instanced is true)\r\n */\r\n divisor?: number;\r\n /**\r\n * defines if the buffer should be released when the vertex buffer is disposed (default: false)\r\n */\r\n takeBufferOwnership?: boolean;\r\n /**\r\n * label to use for this vertex buffer (debugging purpose)\r\n */\r\n label?: string;\r\n}\r\n\r\n/**\r\n * Specialized buffer used to store vertex data\r\n */\r\nexport class VertexBuffer {\r\n private static _Counter = 0;\r\n\r\n /** @internal */\r\n public _buffer: Buffer;\r\n /** @internal */\r\n public _validOffsetRange: boolean; // used internally by the engine\r\n private _kind: string;\r\n private _size: number;\r\n /** @internal */\r\n public _ownsBuffer: boolean;\r\n private _instanced: boolean;\r\n private _instanceDivisor: number;\r\n /** @internal */\r\n public _isDisposed = false;\r\n /** @internal */\r\n public _label?: string;\r\n\r\n /**\r\n * The byte type.\r\n */\r\n public static readonly BYTE = Constants.BYTE;\r\n\r\n /**\r\n * The unsigned byte type.\r\n */\r\n public static readonly UNSIGNED_BYTE = Constants.UNSIGNED_BYTE;\r\n\r\n /**\r\n * The short type.\r\n */\r\n public static readonly SHORT = Constants.SHORT;\r\n\r\n /**\r\n * The unsigned short type.\r\n */\r\n public static readonly UNSIGNED_SHORT = Constants.UNSIGNED_SHORT;\r\n\r\n /**\r\n * The integer type.\r\n */\r\n public static readonly INT = Constants.INT;\r\n\r\n /**\r\n * The unsigned integer type.\r\n */\r\n public static readonly UNSIGNED_INT = Constants.UNSIGNED_INT;\r\n\r\n /**\r\n * The float type.\r\n */\r\n public static readonly FLOAT = Constants.FLOAT;\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is disposed\r\n */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Gets or sets the instance divisor when in instanced mode\r\n */\r\n public get instanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n public set instanceDivisor(value: number) {\r\n const isInstanced = value != 0;\r\n this._instanceDivisor = value;\r\n\r\n if (isInstanced !== this._instanced) {\r\n this._instanced = isInstanced;\r\n this._computeHashCode();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Gets the byte offset.\r\n */\r\n public readonly byteOffset: number;\r\n\r\n /**\r\n * Gets whether integer data values should be normalized into a certain range when being casted to a float.\r\n */\r\n public readonly normalized: boolean;\r\n\r\n /**\r\n * Gets the data type of each component in the array.\r\n */\r\n public readonly type: number;\r\n\r\n /**\r\n * Gets the unique id of this vertex buffer\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * Gets a hash code representing the format (type, normalized, size, instanced, stride) of this buffer\r\n * All buffers with the same format will have the same hash code\r\n */\r\n public readonly hashCode: number;\r\n\r\n /**\r\n * Gets the engine associated with the buffer\r\n */\r\n public readonly engine: AbstractEngine;\r\n\r\n /**\r\n * Gets the max possible amount of vertices stored within the current vertex buffer.\r\n * We do not have the end offset or count so this will be too big for concatenated vertex buffers.\r\n * @internal\r\n */\r\n public get _maxVerticesCount() {\r\n const data = this.getData();\r\n if (!data) {\r\n return 0;\r\n }\r\n\r\n if (Array.isArray(data)) {\r\n // data is a regular number[] with float values\r\n return data.length / (this.byteStride / 4) - this.byteOffset / 4;\r\n }\r\n\r\n return (data.byteLength - this.byteOffset) / this.byteStride;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this vertex buffer\r\n * @param kind the vertex buffer kind\r\n * @param updatable whether the data is updatable\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param stride the stride (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param offset the offset of the data (optional)\r\n * @param size the number of components (optional)\r\n * @param type the type of the component (optional)\r\n * @param normalized whether the data contains normalized data (optional)\r\n * @param useBytes set to true if stride and offset are in bytes (optional)\r\n * @param divisor defines the instance divisor to use (1 by default)\r\n * @param takeBufferOwnership defines if the buffer should be released when the vertex buffer is disposed\r\n */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | Buffer | DataBuffer,\r\n kind: string,\r\n updatable: boolean,\r\n postponeInternalCreation?: boolean,\r\n stride?: number,\r\n instanced?: boolean,\r\n offset?: number,\r\n size?: number,\r\n type?: number,\r\n normalized?: boolean,\r\n useBytes?: boolean,\r\n divisor?: number,\r\n takeBufferOwnership?: boolean\r\n );\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this vertex buffer\r\n * @param kind the vertex buffer kind\r\n * @param options defines the rest of the options used to create the buffer\r\n */\r\n constructor(engine: AbstractEngine, data: DataArray | Buffer | DataBuffer, kind: string, options?: IVertexBufferOptions);\r\n\r\n /** @internal */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | Buffer | DataBuffer,\r\n kind: string,\r\n updatableOrOptions?: boolean | IVertexBufferOptions,\r\n postponeInternalCreation?: boolean,\r\n stride?: number,\r\n instanced?: boolean,\r\n offset?: number,\r\n size?: number,\r\n type?: number,\r\n normalized = false,\r\n useBytes = false,\r\n divisor = 1,\r\n takeBufferOwnership = false\r\n ) {\r\n let updatable = false;\r\n\r\n this.engine = engine;\r\n\r\n if (typeof updatableOrOptions === \"object\" && updatableOrOptions !== null) {\r\n updatable = updatableOrOptions.updatable ?? false;\r\n postponeInternalCreation = updatableOrOptions.postponeInternalCreation;\r\n stride = updatableOrOptions.stride;\r\n instanced = updatableOrOptions.instanced;\r\n offset = updatableOrOptions.offset;\r\n size = updatableOrOptions.size;\r\n type = updatableOrOptions.type;\r\n normalized = updatableOrOptions.normalized ?? false;\r\n useBytes = updatableOrOptions.useBytes ?? false;\r\n divisor = updatableOrOptions.divisor ?? 1;\r\n takeBufferOwnership = updatableOrOptions.takeBufferOwnership ?? false;\r\n this._label = updatableOrOptions.label;\r\n } else {\r\n updatable = !!updatableOrOptions;\r\n }\r\n\r\n if (data instanceof Buffer) {\r\n this._buffer = data;\r\n this._ownsBuffer = takeBufferOwnership;\r\n } else {\r\n this._buffer = new Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes, divisor, this._label);\r\n this._ownsBuffer = true;\r\n }\r\n\r\n this.uniqueId = VertexBuffer._Counter++;\r\n this._kind = kind;\r\n\r\n if (type === undefined) {\r\n const vertexData = this.getData();\r\n this.type = vertexData ? VertexBuffer.GetDataType(vertexData) : VertexBuffer.FLOAT;\r\n } else {\r\n this.type = type;\r\n }\r\n\r\n const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);\r\n\r\n if (useBytes) {\r\n this._size = size || (stride ? stride / typeByteLength : VertexBuffer.DeduceStride(kind));\r\n this.byteStride = stride || this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = offset || 0;\r\n } else {\r\n this._size = size || stride || VertexBuffer.DeduceStride(kind);\r\n this.byteStride = stride ? stride * typeByteLength : this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = (offset || 0) * typeByteLength;\r\n }\r\n\r\n this.normalized = normalized;\r\n\r\n this._instanced = instanced !== undefined ? instanced : false;\r\n this._instanceDivisor = instanced ? divisor : 0;\r\n\r\n this._alignBuffer();\r\n this._computeHashCode();\r\n }\r\n\r\n private _computeHashCode(): void {\r\n // note: cast to any because the property is declared readonly\r\n (this.hashCode as any) =\r\n ((this.type - 5120) << 0) +\r\n ((this.normalized ? 1 : 0) << 3) +\r\n (this._size << 4) +\r\n ((this._instanced ? 1 : 0) << 6) +\r\n /* keep 5 bits free */\r\n (this.byteStride << 12);\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n this._buffer?._rebuild();\r\n }\r\n\r\n /**\r\n * Returns the kind of the VertexBuffer (string)\r\n * @returns a string\r\n */\r\n public getKind(): string {\r\n return this._kind;\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the VertexBuffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._buffer.isUpdatable();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable<DataArray> {\r\n return this._buffer.getData();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data as a float array. Float data is constructed if the vertex buffer data cannot be returned directly.\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public getFloatData(totalVertices: number, forceCopy?: boolean): Nullable<FloatArray> {\r\n const data = this.getData();\r\n if (!data) {\r\n return null;\r\n }\r\n\r\n return VertexBuffer.GetFloatData(data, this._size, this.type, this.byteOffset, this.byteStride, this.normalized, totalVertices, forceCopy);\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable<DataBuffer> {\r\n return this._buffer.getBuffer();\r\n }\r\n\r\n /**\r\n * Gets the Buffer instance that wraps the native GPU buffer\r\n * @returns the wrapper buffer\r\n */\r\n public getWrapperBuffer(): Buffer {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the offset as a multiple of the type byte length.\r\n * @returns the offset in bytes\r\n * @deprecated Please use byteOffset instead.\r\n */\r\n public getOffset(): number {\r\n return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the number of components or the byte size per vertex attribute\r\n * @param sizeInBytes If true, returns the size in bytes or else the size in number of components of the vertex attribute (default: false)\r\n * @returns the number of components\r\n */\r\n public getSize(sizeInBytes = false): number {\r\n return sizeInBytes ? this._size * VertexBuffer.GetTypeByteLength(this.type) : this._size;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced\r\n * @returns true if this buffer is instanced\r\n */\r\n public getIsInstanced(): boolean {\r\n return this._instanced;\r\n }\r\n\r\n /**\r\n * Returns the instancing divisor, zero for non-instanced (integer).\r\n * @returns a number\r\n */\r\n public getInstanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property\r\n * @param data defines the data to store\r\n */\r\n public create(data?: DataArray): void {\r\n this._buffer.create(data);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Updates the underlying buffer according to the passed numeric array or Float32Array.\r\n * This function will create a new buffer if the current one is not updatable\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this._buffer.update(data);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.\r\n * Returns the directly updated WebGLBuffer.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {\r\n this._buffer.updateDirectly(data, offset, undefined, useBytes);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Disposes the VertexBuffer and the underlying WebGLBuffer.\r\n */\r\n public dispose(): void {\r\n if (this._ownsBuffer) {\r\n this._buffer.dispose();\r\n }\r\n\r\n this._isDisposed = true;\r\n }\r\n\r\n /**\r\n * Enumerates each value of this vertex buffer as numbers.\r\n * @param count the number of values to enumerate\r\n * @param callback the callback function called for each value\r\n */\r\n public forEach(count: number, callback: (value: number, index: number) => void): void {\r\n VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);\r\n }\r\n\r\n /** @internal */\r\n public _alignBuffer() {}\r\n\r\n // Enums\r\n /**\r\n * Positions\r\n */\r\n public static readonly PositionKind = Constants.PositionKind;\r\n /**\r\n * Normals\r\n */\r\n public static readonly NormalKind = Constants.NormalKind;\r\n /**\r\n * Tangents\r\n */\r\n public static readonly TangentKind = Constants.TangentKind;\r\n /**\r\n * Texture coordinates\r\n */\r\n public static readonly UVKind = Constants.UVKind;\r\n /**\r\n * Texture coordinates 2\r\n */\r\n public static readonly UV2Kind = Constants.UV2Kind;\r\n /**\r\n * Texture coordinates 3\r\n */\r\n public static readonly UV3Kind = Constants.UV3Kind;\r\n /**\r\n * Texture coordinates 4\r\n */\r\n public static readonly UV4Kind = Constants.UV4Kind;\r\n /**\r\n * Texture coordinates 5\r\n */\r\n public static readonly UV5Kind = Constants.UV5Kind;\r\n /**\r\n * Texture coordinates 6\r\n */\r\n public static readonly UV6Kind = Constants.UV6Kind;\r\n /**\r\n * Colors\r\n */\r\n public static readonly ColorKind = Constants.ColorKind;\r\n /**\r\n * Instance Colors\r\n */\r\n public static readonly ColorInstanceKind = Constants.ColorInstanceKind;\r\n /**\r\n * Matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesKind = Constants.MatricesIndicesKind;\r\n /**\r\n * Matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsKind = Constants.MatricesWeightsKind;\r\n /**\r\n * Additional matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesExtraKind = Constants.MatricesIndicesExtraKind;\r\n /**\r\n * Additional matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsExtraKind = Constants.MatricesWeightsExtraKind;\r\n\r\n /**\r\n * Deduces the stride given a kind.\r\n * @param kind The kind string to deduce\r\n * @returns The deduced stride\r\n */\r\n public static DeduceStride(kind: string): number {\r\n switch (kind) {\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind:\r\n case VertexBuffer.UV3Kind:\r\n case VertexBuffer.UV4Kind:\r\n case VertexBuffer.UV5Kind:\r\n case VertexBuffer.UV6Kind:\r\n return 2;\r\n case VertexBuffer.NormalKind:\r\n case VertexBuffer.PositionKind:\r\n return 3;\r\n case VertexBuffer.ColorKind:\r\n case VertexBuffer.ColorInstanceKind:\r\n case VertexBuffer.MatricesIndicesKind:\r\n case VertexBuffer.MatricesIndicesExtraKind:\r\n case VertexBuffer.MatricesWeightsKind:\r\n case VertexBuffer.MatricesWeightsExtraKind:\r\n case VertexBuffer.TangentKind:\r\n return 4;\r\n default:\r\n throw new Error(\"Invalid kind '\" + kind + \"'\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the vertex buffer type of the given data array.\r\n * @param data the data array\r\n * @returns the vertex buffer type\r\n */\r\n public static GetDataType(data: DataArray): number {\r\n if (data instanceof Int8Array) {\r\n return VertexBuffer.BYTE;\r\n } else if (data instanceof Uint8Array) {\r\n return VertexBuffer.UNSIGNED_BYTE;\r\n } else if (data instanceof Int16Array) {\r\n return VertexBuffer.SHORT;\r\n } else if (data instanceof Uint16Array) {\r\n return VertexBuffer.UNSIGNED_SHORT;\r\n } else if (data instanceof Int32Array) {\r\n return VertexBuffer.INT;\r\n } else if (data instanceof Uint32Array) {\r\n return VertexBuffer.UNSIGNED_INT;\r\n } else {\r\n return VertexBuffer.FLOAT;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte length of the given type.\r\n * @param type the type\r\n * @returns the number of bytes\r\n */\r\n public static GetTypeByteLength(type: number): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE:\r\n case VertexBuffer.UNSIGNED_BYTE:\r\n return 1;\r\n case VertexBuffer.SHORT:\r\n case VertexBuffer.UNSIGNED_SHORT:\r\n return 2;\r\n case VertexBuffer.INT:\r\n case VertexBuffer.UNSIGNED_INT:\r\n case VertexBuffer.FLOAT:\r\n return 4;\r\n default:\r\n throw new Error(`Invalid type '${type}'`);\r\n }\r\n }\r\n\r\n /**\r\n * Enumerates each value of the given parameters as numbers.\r\n * @param data the data to enumerate\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param componentCount the number of components per element\r\n * @param componentType the type of the component\r\n * @param count the number of values to enumerate\r\n * @param normalized whether the data is normalized\r\n * @param callback the callback function called for each value\r\n */\r\n public static ForEach(\r\n data: DataArray,\r\n byteOffset: number,\r\n byteStride: number,\r\n componentCount: number,\r\n componentType: number,\r\n count: number,\r\n normalized: boolean,\r\n callback: (value: number, index: number) => void\r\n ): void {\r\n if (data instanceof Array) {\r\n let offset = byteOffset / 4;\r\n const stride = byteStride / 4;\r\n for (let index = 0; index < count; index += componentCount) {\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n callback(data[offset + componentIndex], index + componentIndex);\r\n }\r\n offset += stride;\r\n }\r\n } else {\r\n const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);\r\n const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);\r\n for (let index = 0; index < count; index += componentCount) {\r\n let componentByteOffset = byteOffset;\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);\r\n callback(value, index + componentIndex);\r\n componentByteOffset += componentByteLength;\r\n }\r\n byteOffset += byteStride;\r\n }\r\n }\r\n }\r\n\r\n private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE: {\r\n let value = dataView.getInt8(byteOffset);\r\n if (normalized) {\r\n value = Math.max(value / 127, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_BYTE: {\r\n let value = dataView.getUint8(byteOffset);\r\n if (normalized) {\r\n value = value / 255;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.SHORT: {\r\n let value = dataView.getInt16(byteOffset, true);\r\n if (normalized) {\r\n value = Math.max(value / 32767, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_SHORT: {\r\n let value = dataView.getUint16(byteOffset, true);\r\n if (normalized) {\r\n value = value / 65535;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.INT: {\r\n return dataView.getInt32(byteOffset, true);\r\n }\r\n case VertexBuffer.UNSIGNED_INT: {\r\n return dataView.getUint32(byteOffset, true);\r\n }\r\n case VertexBuffer.FLOAT: {\r\n return dataView.getFloat32(byteOffset, true);\r\n }\r\n default: {\r\n throw new Error(`Invalid component type ${type}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the given data array as a float array. Float data is constructed if the data array cannot be returned directly.\r\n * @param data the input data array\r\n * @param size the number of components\r\n * @param type the component type\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param normalized whether the data is normalized\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public static GetFloatData(\r\n data: DataArray,\r\n size: number,\r\n type: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n normalized: boolean,\r\n totalVertices: number,\r\n forceCopy?: boolean\r\n ): FloatArray {\r\n const tightlyPackedByteStride = size * VertexBuffer.GetTypeByteLength(type);\r\n const count = totalVertices * size;\r\n\r\n if (type !== VertexBuffer.FLOAT || byteStride !== tightlyPackedByteStride) {\r\n const copy = new Float32Array(count);\r\n VertexBuffer.ForEach(data, byteOffset, byteStride, size, type, count, normalized, (value, index) => (copy[index] = value));\r\n return copy;\r\n }\r\n\r\n if (!(data instanceof Array || data instanceof Float32Array) || byteOffset !== 0 || data.length !== count) {\r\n if (data instanceof Array) {\r\n const offset = byteOffset / 4;\r\n return data.slice(offset, offset + count);\r\n } else if (data instanceof ArrayBuffer) {\r\n return new Float32Array(data, byteOffset, count);\r\n } else {\r\n let offset = data.byteOffset + byteOffset;\r\n if (forceCopy) {\r\n const result = new Float32Array(count);\r\n const source = new Float32Array(data.buffer, offset, count);\r\n\r\n result.set(source);\r\n\r\n return result;\r\n }\r\n\r\n // Protect against bad data\r\n const remainder = offset % 4;\r\n\r\n if (remainder) {\r\n offset = Math.max(0, offset - remainder);\r\n }\r\n\r\n return new Float32Array(data.buffer, offset, count);\r\n }\r\n }\r\n\r\n if (forceCopy) {\r\n return data.slice();\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../../../dev/core/src/Buffers/buffer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,MAAM;IAYf;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAOD;;;;;;;;;;;OAWG;IACH,YACI,MAAsB,EACtB,IAA4B,EAC5B,SAAkB,EAClB,MAAM,GAAG,CAAC,EACV,wBAAwB,GAAG,KAAK,EAChC,SAAS,GAAG,KAAK,EACjB,QAAQ,GAAG,KAAK,EAChB,OAAgB,EAChB,KAAc;QArCV,oBAAe,GAAG,KAAK,CAAC;QAC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AAApB,CAAqB;AACnD;;GAEG;AACoB,oBAAO,GAAG,SAAS,CAAC,OAAO,AAApB,CAAqB;AACnD;;GAEG;AACoB,sBAAS,GAAG,SAAS,CAAC,SAAS,AAAtB,CAAuB;AACvD;;GAEG;AACoB,8BAAiB,GAAG,SAAS,CAAC,iBAAiB,AAA9B,CAA+B;AACvE;;GAEG;AACoB,gCAAmB,GAAG,SAAS,CAAC,mBAAmB,AAAhC,CAAiC;AAC3E;;GAEG;AACoB,gCAAmB,GAAG,SAAS,CAAC,mBAAmB,AAAhC,CAAiC;AAC3E;;GAEG;AACoB,qCAAwB,GAAG,SAAS,CAAC,wBAAwB,AAArC,CAAsC;AACrF;;GAEG;AACoB,qCAAwB,GAAG,SAAS,CAAC,wBAAwB,AAArC,CAAsC","sourcesContent":["import type { Nullable, DataArray, FloatArray } from \"../types\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { DataBuffer } from \"./dataBuffer\";\r\nimport type { Mesh } from \"../Meshes/mesh\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Constants } from \"../Engines/constants\";\r\n\r\n/**\r\n * Class used to store data that will be store in GPU memory\r\n */\r\nexport class Buffer {\r\n private _engine: AbstractEngine;\r\n private _buffer: Nullable<DataBuffer>;\r\n /** @internal */\r\n public _data: Nullable<DataArray>;\r\n private _updatable: boolean;\r\n private _instanced: boolean;\r\n private _divisor: number;\r\n private _isAlreadyOwned = false;\r\n private _isDisposed = false;\r\n private _label?: string;\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is disposed\r\n */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this buffer\r\n * @param updatable whether the data is updatable\r\n * @param stride the stride (optional)\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param useBytes set to true if the stride in in bytes (optional)\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n * @param label defines the label of the buffer (for debug purpose)\r\n */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | DataBuffer,\r\n updatable: boolean,\r\n stride = 0,\r\n postponeInternalCreation = false,\r\n instanced = false,\r\n useBytes = false,\r\n divisor?: number,\r\n label?: string\r\n ) {\r\n if (engine && (engine as unknown as Mesh).getScene) {\r\n // old versions of VertexBuffer accepted 'mesh' instead of 'engine'\r\n this._engine = (engine as unknown as Mesh).getScene().getEngine();\r\n } else {\r\n this._engine = engine;\r\n }\r\n\r\n this._updatable = updatable;\r\n this._instanced = instanced;\r\n this._divisor = divisor || 1;\r\n this._label = label;\r\n\r\n if (data instanceof DataBuffer) {\r\n this._data = null;\r\n this._buffer = data;\r\n } else {\r\n this._data = data;\r\n this._buffer = null;\r\n }\r\n\r\n this.byteStride = useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT;\r\n\r\n if (!postponeInternalCreation) {\r\n // by default\r\n this.create();\r\n }\r\n }\r\n\r\n /**\r\n * Create a new VertexBuffer based on the current buffer\r\n * @param kind defines the vertex buffer kind (position, normal, etc.)\r\n * @param offset defines offset in the buffer (0 by default)\r\n * @param size defines the size in floats of attributes (position is 3 for instance)\r\n * @param stride defines the stride size in floats in the buffer (the offset to apply to reach next value when data is interleaved)\r\n * @param instanced defines if the vertex buffer contains indexed data\r\n * @param useBytes defines if the offset and stride are in bytes *\r\n * @param divisor sets an optional divisor for instances (1 by default)\r\n * @returns the new vertex buffer\r\n */\r\n public createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes = false, divisor?: number): VertexBuffer {\r\n const byteOffset = useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT;\r\n const byteStride = stride ? (useBytes ? stride : stride * Float32Array.BYTES_PER_ELEMENT) : this.byteStride;\r\n\r\n // a lot of these parameters are ignored as they are overridden by the buffer\r\n return new VertexBuffer(\r\n this._engine,\r\n this,\r\n kind,\r\n this._updatable,\r\n true,\r\n byteStride,\r\n instanced === undefined ? this._instanced : instanced,\r\n byteOffset,\r\n size,\r\n undefined,\r\n undefined,\r\n true,\r\n this._divisor || divisor\r\n );\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._updatable;\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable<DataArray> {\r\n return this._data;\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable<DataBuffer> {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / Float32Array.BYTES_PER_ELEMENT;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. Creates the buffer if not used already.\r\n * If the buffer was already used, it will be updated only if it is updatable, otherwise it will do nothing.\r\n * @param data defines the data to store\r\n */\r\n public create(data: Nullable<DataArray> = null): void {\r\n if (!data && this._buffer) {\r\n return; // nothing to do\r\n }\r\n\r\n data = data || this._data;\r\n\r\n if (!data) {\r\n return;\r\n }\r\n\r\n if (!this._buffer) {\r\n // create buffer\r\n if (this._updatable) {\r\n this._buffer = this._engine.createDynamicVertexBuffer(data, this._label);\r\n this._data = data;\r\n } else {\r\n this._buffer = this._engine.createVertexBuffer(data, undefined, this._label);\r\n }\r\n } else if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(this._buffer, data);\r\n this._data = data;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n if (!this._data) {\r\n if (!this._buffer) {\r\n // Buffer was not yet created, nothing to do\r\n return;\r\n }\r\n if (this._buffer.capacity > 0) {\r\n // We can at least recreate the buffer with the right size, even if we don't have the data\r\n if (this._updatable) {\r\n this._buffer = this._engine.createDynamicVertexBuffer(this._buffer.capacity, this._label);\r\n } else {\r\n this._buffer = this._engine.createVertexBuffer(this._buffer.capacity, undefined, this._label);\r\n }\r\n return;\r\n }\r\n Logger.Warn(`Missing data for buffer \"${this._label}\" ${this._buffer ? \"(uniqueId: \" + this._buffer.uniqueId + \")\" : \"\"}. Buffer reconstruction failed.`);\r\n this._buffer = null;\r\n } else {\r\n this._buffer = null;\r\n this.create(this._data);\r\n }\r\n }\r\n\r\n /**\r\n * Update current buffer data\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this.create(data);\r\n }\r\n\r\n /**\r\n * Updates the data directly.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param vertexCount the vertex count (optional)\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes: boolean = false): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (this._updatable) {\r\n // update buffer\r\n this._engine.updateDynamicVertexBuffer(\r\n this._buffer,\r\n data,\r\n useBytes ? offset : offset * Float32Array.BYTES_PER_ELEMENT,\r\n vertexCount ? vertexCount * this.byteStride : undefined\r\n );\r\n if (offset === 0 && vertexCount === undefined) {\r\n // Keep the data if we easily can\r\n this._data = data;\r\n } else {\r\n this._data = null;\r\n }\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _increaseReferences() {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n if (!this._isAlreadyOwned) {\r\n this._isAlreadyOwned = true;\r\n return;\r\n }\r\n\r\n this._buffer.references++;\r\n }\r\n\r\n /**\r\n * Release all resources\r\n */\r\n public dispose(): void {\r\n if (!this._buffer) {\r\n return;\r\n }\r\n\r\n // The data buffer has an internal counter as this buffer can be used by several VertexBuffer objects\r\n // This means that we only flag it as disposed when all references are released (when _releaseBuffer will return true)\r\n if (this._engine._releaseBuffer(this._buffer)) {\r\n this._isDisposed = true;\r\n this._data = null;\r\n this._buffer = null;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Options to be used when creating a vertex buffer\r\n */\r\nexport interface IVertexBufferOptions {\r\n /**\r\n * whether the data is updatable (default: false)\r\n */\r\n updatable?: boolean;\r\n /**\r\n * whether to postpone creating the internal WebGL buffer (default: false)\r\n */\r\n postponeInternalCreation?: boolean;\r\n /**\r\n * the stride (will be automatically computed from the kind parameter if not specified)\r\n */\r\n stride?: number;\r\n /**\r\n * whether the buffer is instanced (default: false)\r\n */\r\n instanced?: boolean;\r\n /**\r\n * the offset of the data (default: 0)\r\n */\r\n offset?: number;\r\n /**\r\n * the number of components (will be automatically computed from the kind parameter if not specified)\r\n */\r\n size?: number;\r\n /**\r\n * the type of the component (will be deduce from the data parameter if not specified)\r\n */\r\n type?: number;\r\n /**\r\n * whether the data contains normalized data (default: false)\r\n */\r\n normalized?: boolean;\r\n /**\r\n * set to true if stride and offset are in bytes (default: false)\r\n */\r\n useBytes?: boolean;\r\n /**\r\n * defines the instance divisor to use (default: 1, only used if instanced is true)\r\n */\r\n divisor?: number;\r\n /**\r\n * defines if the buffer should be released when the vertex buffer is disposed (default: false)\r\n */\r\n takeBufferOwnership?: boolean;\r\n /**\r\n * label to use for this vertex buffer (debugging purpose)\r\n */\r\n label?: string;\r\n}\r\n\r\n/**\r\n * Specialized buffer used to store vertex data\r\n */\r\nexport class VertexBuffer {\r\n private static _Counter = 0;\r\n\r\n /** @internal */\r\n public _buffer: Buffer;\r\n /** @internal */\r\n public _validOffsetRange: boolean; // used internally by the engine\r\n private _kind: string;\r\n private _size: number;\r\n /** @internal */\r\n public _ownsBuffer: boolean;\r\n private _instanced: boolean;\r\n private _instanceDivisor: number;\r\n /** @internal */\r\n public _isDisposed = false;\r\n /** @internal */\r\n public _label?: string;\r\n\r\n /**\r\n * The byte type.\r\n */\r\n public static readonly BYTE = Constants.BYTE;\r\n\r\n /**\r\n * The unsigned byte type.\r\n */\r\n public static readonly UNSIGNED_BYTE = Constants.UNSIGNED_BYTE;\r\n\r\n /**\r\n * The short type.\r\n */\r\n public static readonly SHORT = Constants.SHORT;\r\n\r\n /**\r\n * The unsigned short type.\r\n */\r\n public static readonly UNSIGNED_SHORT = Constants.UNSIGNED_SHORT;\r\n\r\n /**\r\n * The integer type.\r\n */\r\n public static readonly INT = Constants.INT;\r\n\r\n /**\r\n * The unsigned integer type.\r\n */\r\n public static readonly UNSIGNED_INT = Constants.UNSIGNED_INT;\r\n\r\n /**\r\n * The float type.\r\n */\r\n public static readonly FLOAT = Constants.FLOAT;\r\n\r\n /**\r\n * Gets a boolean indicating if the Buffer is disposed\r\n */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Gets or sets the instance divisor when in instanced mode\r\n */\r\n public get instanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n public set instanceDivisor(value: number) {\r\n const isInstanced = value != 0;\r\n this._instanceDivisor = value;\r\n\r\n if (isInstanced !== this._instanced) {\r\n this._instanced = isInstanced;\r\n this._computeHashCode();\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte stride.\r\n */\r\n public readonly byteStride: number;\r\n\r\n /**\r\n * Gets the byte offset.\r\n */\r\n public readonly byteOffset: number;\r\n\r\n /**\r\n * Gets whether integer data values should be normalized into a certain range when being casted to a float.\r\n */\r\n public readonly normalized: boolean;\r\n\r\n /**\r\n * Gets the data type of each component in the array.\r\n */\r\n public readonly type: number;\r\n\r\n /**\r\n * Gets the unique id of this vertex buffer\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * Gets a hash code representing the format (type, normalized, size, instanced, stride) of this buffer\r\n * All buffers with the same format will have the same hash code\r\n */\r\n public readonly hashCode: number;\r\n\r\n /**\r\n * Gets the engine associated with the buffer\r\n */\r\n public readonly engine: AbstractEngine;\r\n\r\n /**\r\n * Gets the max possible amount of vertices stored within the current vertex buffer.\r\n * We do not have the end offset or count so this will be too big for concatenated vertex buffers.\r\n * @internal\r\n */\r\n public get _maxVerticesCount() {\r\n const data = this.getData();\r\n if (!data) {\r\n return 0;\r\n }\r\n\r\n if (Array.isArray(data)) {\r\n // data is a regular number[] with float values\r\n return data.length / (this.byteStride / 4) - this.byteOffset / 4;\r\n }\r\n\r\n return (data.byteLength - this.byteOffset) / this.byteStride;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this vertex buffer\r\n * @param kind the vertex buffer kind\r\n * @param updatable whether the data is updatable\r\n * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)\r\n * @param stride the stride (optional)\r\n * @param instanced whether the buffer is instanced (optional)\r\n * @param offset the offset of the data (optional)\r\n * @param size the number of components (optional)\r\n * @param type the type of the component (optional)\r\n * @param normalized whether the data contains normalized data (optional)\r\n * @param useBytes set to true if stride and offset are in bytes (optional)\r\n * @param divisor defines the instance divisor to use (1 by default)\r\n * @param takeBufferOwnership defines if the buffer should be released when the vertex buffer is disposed\r\n */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | Buffer | DataBuffer,\r\n kind: string,\r\n updatable: boolean,\r\n postponeInternalCreation?: boolean,\r\n stride?: number,\r\n instanced?: boolean,\r\n offset?: number,\r\n size?: number,\r\n type?: number,\r\n normalized?: boolean,\r\n useBytes?: boolean,\r\n divisor?: number,\r\n takeBufferOwnership?: boolean\r\n );\r\n\r\n /**\r\n * Constructor\r\n * @param engine the engine\r\n * @param data the data to use for this vertex buffer\r\n * @param kind the vertex buffer kind\r\n * @param options defines the rest of the options used to create the buffer\r\n */\r\n constructor(engine: AbstractEngine, data: DataArray | Buffer | DataBuffer, kind: string, options?: IVertexBufferOptions);\r\n\r\n /** @internal */\r\n constructor(\r\n engine: AbstractEngine,\r\n data: DataArray | Buffer | DataBuffer,\r\n kind: string,\r\n updatableOrOptions?: boolean | IVertexBufferOptions,\r\n postponeInternalCreation?: boolean,\r\n stride?: number,\r\n instanced?: boolean,\r\n offset?: number,\r\n size?: number,\r\n type?: number,\r\n normalized = false,\r\n useBytes = false,\r\n divisor = 1,\r\n takeBufferOwnership = false\r\n ) {\r\n let updatable = false;\r\n\r\n this.engine = engine;\r\n\r\n if (typeof updatableOrOptions === \"object\" && updatableOrOptions !== null) {\r\n updatable = updatableOrOptions.updatable ?? false;\r\n postponeInternalCreation = updatableOrOptions.postponeInternalCreation;\r\n stride = updatableOrOptions.stride;\r\n instanced = updatableOrOptions.instanced;\r\n offset = updatableOrOptions.offset;\r\n size = updatableOrOptions.size;\r\n type = updatableOrOptions.type;\r\n normalized = updatableOrOptions.normalized ?? false;\r\n useBytes = updatableOrOptions.useBytes ?? false;\r\n divisor = updatableOrOptions.divisor ?? 1;\r\n takeBufferOwnership = updatableOrOptions.takeBufferOwnership ?? false;\r\n this._label = updatableOrOptions.label;\r\n } else {\r\n updatable = !!updatableOrOptions;\r\n }\r\n\r\n if (data instanceof Buffer) {\r\n this._buffer = data;\r\n this._ownsBuffer = takeBufferOwnership;\r\n } else {\r\n this._buffer = new Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes, divisor, this._label);\r\n this._ownsBuffer = true;\r\n }\r\n\r\n this.uniqueId = VertexBuffer._Counter++;\r\n this._kind = kind;\r\n\r\n if (type === undefined) {\r\n const vertexData = this.getData();\r\n this.type = vertexData ? VertexBuffer.GetDataType(vertexData) : VertexBuffer.FLOAT;\r\n } else {\r\n this.type = type;\r\n }\r\n\r\n const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);\r\n\r\n if (useBytes) {\r\n this._size = size || (stride ? stride / typeByteLength : VertexBuffer.DeduceStride(kind));\r\n this.byteStride = stride || this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = offset || 0;\r\n } else {\r\n this._size = size || stride || VertexBuffer.DeduceStride(kind);\r\n this.byteStride = stride ? stride * typeByteLength : this._buffer.byteStride || this._size * typeByteLength;\r\n this.byteOffset = (offset || 0) * typeByteLength;\r\n }\r\n\r\n this.normalized = normalized;\r\n\r\n this._instanced = instanced !== undefined ? instanced : false;\r\n this._instanceDivisor = instanced ? divisor : 0;\r\n\r\n this._alignBuffer();\r\n this._computeHashCode();\r\n }\r\n\r\n private _computeHashCode(): void {\r\n // note: cast to any because the property is declared readonly\r\n (this.hashCode as any) =\r\n ((this.type - 5120) << 0) +\r\n ((this.normalized ? 1 : 0) << 3) +\r\n (this._size << 4) +\r\n ((this._instanced ? 1 : 0) << 6) +\r\n /* keep 5 bits free */\r\n (this.byteStride << 12);\r\n }\r\n\r\n /** @internal */\r\n public _rebuild(): void {\r\n this._buffer?._rebuild();\r\n }\r\n\r\n /**\r\n * Returns the kind of the VertexBuffer (string)\r\n * @returns a string\r\n */\r\n public getKind(): string {\r\n return this._kind;\r\n }\r\n\r\n // Properties\r\n\r\n /**\r\n * Gets a boolean indicating if the VertexBuffer is updatable?\r\n * @returns true if the buffer is updatable\r\n */\r\n public isUpdatable(): boolean {\r\n return this._buffer.isUpdatable();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data\r\n * @returns a DataArray or null\r\n */\r\n public getData(): Nullable<DataArray> {\r\n return this._buffer.getData();\r\n }\r\n\r\n /**\r\n * Gets current buffer's data as a float array. Float data is constructed if the vertex buffer data cannot be returned directly.\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public getFloatData(totalVertices: number, forceCopy?: boolean): Nullable<FloatArray> {\r\n const data = this.getData();\r\n if (!data) {\r\n return null;\r\n }\r\n\r\n return VertexBuffer.GetFloatData(data, this._size, this.type, this.byteOffset, this.byteStride, this.normalized, totalVertices, forceCopy);\r\n }\r\n\r\n /**\r\n * Gets underlying native buffer\r\n * @returns underlying native buffer\r\n */\r\n public getBuffer(): Nullable<DataBuffer> {\r\n return this._buffer.getBuffer();\r\n }\r\n\r\n /**\r\n * Gets the Buffer instance that wraps the native GPU buffer\r\n * @returns the wrapper buffer\r\n */\r\n public getWrapperBuffer(): Buffer {\r\n return this._buffer;\r\n }\r\n\r\n /**\r\n * Gets the stride in float32 units (i.e. byte stride / 4).\r\n * May not be an integer if the byte stride is not divisible by 4.\r\n * @returns the stride in float32 units\r\n * @deprecated Please use byteStride instead.\r\n */\r\n public getStrideSize(): number {\r\n return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the offset as a multiple of the type byte length.\r\n * @returns the offset in bytes\r\n * @deprecated Please use byteOffset instead.\r\n */\r\n public getOffset(): number {\r\n return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);\r\n }\r\n\r\n /**\r\n * Returns the number of components or the byte size per vertex attribute\r\n * @param sizeInBytes If true, returns the size in bytes or else the size in number of components of the vertex attribute (default: false)\r\n * @returns the number of components\r\n */\r\n public getSize(sizeInBytes = false): number {\r\n return sizeInBytes ? this._size * VertexBuffer.GetTypeByteLength(this.type) : this._size;\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced\r\n * @returns true if this buffer is instanced\r\n */\r\n public getIsInstanced(): boolean {\r\n return this._instanced;\r\n }\r\n\r\n /**\r\n * Returns the instancing divisor, zero for non-instanced (integer).\r\n * @returns a number\r\n */\r\n public getInstanceDivisor(): number {\r\n return this._instanceDivisor;\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property\r\n * @param data defines the data to store\r\n */\r\n public create(data?: DataArray): void {\r\n this._buffer.create(data);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Updates the underlying buffer according to the passed numeric array or Float32Array.\r\n * This function will create a new buffer if the current one is not updatable\r\n * @param data defines the data to store\r\n */\r\n public update(data: DataArray): void {\r\n this._buffer.update(data);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.\r\n * Returns the directly updated WebGLBuffer.\r\n * @param data the new data\r\n * @param offset the new offset\r\n * @param useBytes set to true if the offset is in bytes\r\n */\r\n public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {\r\n this._buffer.updateDirectly(data, offset, undefined, useBytes);\r\n this._alignBuffer();\r\n }\r\n\r\n /**\r\n * Disposes the VertexBuffer and the underlying WebGLBuffer.\r\n */\r\n public dispose(): void {\r\n if (this._ownsBuffer) {\r\n this._buffer.dispose();\r\n }\r\n\r\n this._isDisposed = true;\r\n }\r\n\r\n /**\r\n * Enumerates each value of this vertex buffer as numbers.\r\n * @param count the number of values to enumerate\r\n * @param callback the callback function called for each value\r\n */\r\n public forEach(count: number, callback: (value: number, index: number) => void): void {\r\n VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);\r\n }\r\n\r\n /** @internal */\r\n public _alignBuffer() {}\r\n\r\n // Enums\r\n /**\r\n * Positions\r\n */\r\n public static readonly PositionKind = Constants.PositionKind;\r\n /**\r\n * Normals\r\n */\r\n public static readonly NormalKind = Constants.NormalKind;\r\n /**\r\n * Tangents\r\n */\r\n public static readonly TangentKind = Constants.TangentKind;\r\n /**\r\n * Texture coordinates\r\n */\r\n public static readonly UVKind = Constants.UVKind;\r\n /**\r\n * Texture coordinates 2\r\n */\r\n public static readonly UV2Kind = Constants.UV2Kind;\r\n /**\r\n * Texture coordinates 3\r\n */\r\n public static readonly UV3Kind = Constants.UV3Kind;\r\n /**\r\n * Texture coordinates 4\r\n */\r\n public static readonly UV4Kind = Constants.UV4Kind;\r\n /**\r\n * Texture coordinates 5\r\n */\r\n public static readonly UV5Kind = Constants.UV5Kind;\r\n /**\r\n * Texture coordinates 6\r\n */\r\n public static readonly UV6Kind = Constants.UV6Kind;\r\n /**\r\n * Colors\r\n */\r\n public static readonly ColorKind = Constants.ColorKind;\r\n /**\r\n * Instance Colors\r\n */\r\n public static readonly ColorInstanceKind = Constants.ColorInstanceKind;\r\n /**\r\n * Matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesKind = Constants.MatricesIndicesKind;\r\n /**\r\n * Matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsKind = Constants.MatricesWeightsKind;\r\n /**\r\n * Additional matrix indices (for bones)\r\n */\r\n public static readonly MatricesIndicesExtraKind = Constants.MatricesIndicesExtraKind;\r\n /**\r\n * Additional matrix weights (for bones)\r\n */\r\n public static readonly MatricesWeightsExtraKind = Constants.MatricesWeightsExtraKind;\r\n\r\n /**\r\n * Deduces the stride given a kind.\r\n * @param kind The kind string to deduce\r\n * @returns The deduced stride\r\n */\r\n public static DeduceStride(kind: string): number {\r\n switch (kind) {\r\n case VertexBuffer.UVKind:\r\n case VertexBuffer.UV2Kind:\r\n case VertexBuffer.UV3Kind:\r\n case VertexBuffer.UV4Kind:\r\n case VertexBuffer.UV5Kind:\r\n case VertexBuffer.UV6Kind:\r\n return 2;\r\n case VertexBuffer.NormalKind:\r\n case VertexBuffer.PositionKind:\r\n return 3;\r\n case VertexBuffer.ColorKind:\r\n case VertexBuffer.ColorInstanceKind:\r\n case VertexBuffer.MatricesIndicesKind:\r\n case VertexBuffer.MatricesIndicesExtraKind:\r\n case VertexBuffer.MatricesWeightsKind:\r\n case VertexBuffer.MatricesWeightsExtraKind:\r\n case VertexBuffer.TangentKind:\r\n return 4;\r\n default:\r\n throw new Error(\"Invalid kind '\" + kind + \"'\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the vertex buffer type of the given data array.\r\n * @param data the data array\r\n * @returns the vertex buffer type\r\n */\r\n public static GetDataType(data: DataArray): number {\r\n if (data instanceof Int8Array) {\r\n return VertexBuffer.BYTE;\r\n } else if (data instanceof Uint8Array) {\r\n return VertexBuffer.UNSIGNED_BYTE;\r\n } else if (data instanceof Int16Array) {\r\n return VertexBuffer.SHORT;\r\n } else if (data instanceof Uint16Array) {\r\n return VertexBuffer.UNSIGNED_SHORT;\r\n } else if (data instanceof Int32Array) {\r\n return VertexBuffer.INT;\r\n } else if (data instanceof Uint32Array) {\r\n return VertexBuffer.UNSIGNED_INT;\r\n } else {\r\n return VertexBuffer.FLOAT;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the byte length of the given type.\r\n * @param type the type\r\n * @returns the number of bytes\r\n */\r\n public static GetTypeByteLength(type: number): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE:\r\n case VertexBuffer.UNSIGNED_BYTE:\r\n return 1;\r\n case VertexBuffer.SHORT:\r\n case VertexBuffer.UNSIGNED_SHORT:\r\n return 2;\r\n case VertexBuffer.INT:\r\n case VertexBuffer.UNSIGNED_INT:\r\n case VertexBuffer.FLOAT:\r\n return 4;\r\n default:\r\n throw new Error(`Invalid type '${type}'`);\r\n }\r\n }\r\n\r\n /**\r\n * Enumerates each value of the given parameters as numbers.\r\n * @param data the data to enumerate\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param componentCount the number of components per element\r\n * @param componentType the type of the component\r\n * @param count the number of values to enumerate\r\n * @param normalized whether the data is normalized\r\n * @param callback the callback function called for each value\r\n */\r\n public static ForEach(\r\n data: DataArray,\r\n byteOffset: number,\r\n byteStride: number,\r\n componentCount: number,\r\n componentType: number,\r\n count: number,\r\n normalized: boolean,\r\n callback: (value: number, index: number) => void\r\n ): void {\r\n if (data instanceof Array) {\r\n let offset = byteOffset / 4;\r\n const stride = byteStride / 4;\r\n for (let index = 0; index < count; index += componentCount) {\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n callback(data[offset + componentIndex], index + componentIndex);\r\n }\r\n offset += stride;\r\n }\r\n } else {\r\n const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);\r\n const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);\r\n for (let index = 0; index < count; index += componentCount) {\r\n let componentByteOffset = byteOffset;\r\n for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {\r\n const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);\r\n callback(value, index + componentIndex);\r\n componentByteOffset += componentByteLength;\r\n }\r\n byteOffset += byteStride;\r\n }\r\n }\r\n }\r\n\r\n private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {\r\n switch (type) {\r\n case VertexBuffer.BYTE: {\r\n let value = dataView.getInt8(byteOffset);\r\n if (normalized) {\r\n value = Math.max(value / 127, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_BYTE: {\r\n let value = dataView.getUint8(byteOffset);\r\n if (normalized) {\r\n value = value / 255;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.SHORT: {\r\n let value = dataView.getInt16(byteOffset, true);\r\n if (normalized) {\r\n value = Math.max(value / 32767, -1);\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.UNSIGNED_SHORT: {\r\n let value = dataView.getUint16(byteOffset, true);\r\n if (normalized) {\r\n value = value / 65535;\r\n }\r\n return value;\r\n }\r\n case VertexBuffer.INT: {\r\n return dataView.getInt32(byteOffset, true);\r\n }\r\n case VertexBuffer.UNSIGNED_INT: {\r\n return dataView.getUint32(byteOffset, true);\r\n }\r\n case VertexBuffer.FLOAT: {\r\n return dataView.getFloat32(byteOffset, true);\r\n }\r\n default: {\r\n throw new Error(`Invalid component type ${type}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the given data array as a float array. Float data is constructed if the data array cannot be returned directly.\r\n * @param data the input data array\r\n * @param size the number of components\r\n * @param type the component type\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param normalized whether the data is normalized\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it\r\n * @returns a float array containing vertex data\r\n */\r\n public static GetFloatData(\r\n data: DataArray,\r\n size: number,\r\n type: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n normalized: boolean,\r\n totalVertices: number,\r\n forceCopy?: boolean\r\n ): FloatArray {\r\n const tightlyPackedByteStride = size * VertexBuffer.GetTypeByteLength(type);\r\n const count = totalVertices * size;\r\n\r\n if (type !== VertexBuffer.FLOAT || byteStride !== tightlyPackedByteStride) {\r\n const copy = new Float32Array(count);\r\n VertexBuffer.ForEach(data, byteOffset, byteStride, size, type, count, normalized, (value, index) => (copy[index] = value));\r\n return copy;\r\n }\r\n\r\n if (!(data instanceof Array || data instanceof Float32Array) || byteOffset !== 0 || data.length !== count) {\r\n if (data instanceof Array) {\r\n const offset = byteOffset / 4;\r\n return data.slice(offset, offset + count);\r\n } else if (data instanceof ArrayBuffer) {\r\n return new Float32Array(data, byteOffset, count);\r\n } else {\r\n const offset = data.byteOffset + byteOffset;\r\n if (forceCopy) {\r\n const result = new Float32Array(count);\r\n const source = new Float32Array(data.buffer, offset, count);\r\n\r\n result.set(source);\r\n\r\n return result;\r\n }\r\n\r\n // Protect against bad data\r\n const remainder = offset % 4;\r\n\r\n if (remainder) {\r\n Logger.Warn(\"GetFloatData: copied misaligned data.\");\r\n // If not aligned, copy the data to aligned buffer\r\n return new Float32Array(data.buffer.slice(offset, offset + count * 4));\r\n }\r\n\r\n return new Float32Array(data.buffer, offset, count);\r\n }\r\n }\r\n\r\n if (forceCopy) {\r\n return data.slice();\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n"]}
@@ -1,4 +1,5 @@
1
1
  import { VertexBuffer } from "./buffer.js";
2
+ import { Logger } from "../Misc/logger.js";
2
3
  /**
3
4
  * Copies the given data array to the given float array.
4
5
  * @param input the input data array
@@ -29,11 +30,14 @@ export function CopyFloatData(input, size, type, byteOffset, byteStride, normali
29
30
  output.set(floatData);
30
31
  }
31
32
  else {
32
- let offset = input.byteOffset + byteOffset;
33
+ const offset = input.byteOffset + byteOffset;
33
34
  // Protect against bad data
34
35
  const remainder = offset % 4;
35
36
  if (remainder) {
36
- offset = Math.max(0, offset - remainder);
37
+ Logger.Warn("CopyFloatData: copied misaligned data.");
38
+ // If not aligned, copy the data to aligned buffer
39
+ output.set(new Float32Array(input.buffer.slice(offset, offset + count * 4)));
40
+ return;
37
41
  }
38
42
  const floatData = new Float32Array(input.buffer, offset, count);
39
43
  output.set(floatData);
@@ -1 +1 @@
1
- {"version":3,"file":"bufferUtils.js","sourceRoot":"","sources":["../../../../dev/core/src/Buffers/bufferUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CACzB,KAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,UAAkB,EAClB,UAAkB,EAClB,UAAmB,EACnB,aAAqB,EACrB,MAAoB;IAEpB,MAAM,uBAAuB,GAAG,IAAI,GAAG,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,aAAa,GAAG,IAAI,CAAC;IAEnC,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KACjD;IAED,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,IAAI,UAAU,KAAK,uBAAuB,EAAE;QACvE,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QAC9H,OAAO;KACV;IAED,IAAI,KAAK,YAAY,KAAK,EAAE;QACxB,MAAM,MAAM,GAAG,UAAU,GAAG,CAAC,CAAC;QAC9B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAC7B;SAAM,IAAI,KAAK,YAAY,WAAW,EAAE;QACrC,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACzB;SAAM;QACH,IAAI,MAAM,GAAG,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;QAE3C,2BAA2B;QAC3B,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC;QAC7B,IAAI,SAAS,EAAE;YACX,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;SAC5C;QAED,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAChE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACzB;AACL,CAAC","sourcesContent":["import type { DataArray } from \"../types\";\r\nimport { VertexBuffer } from \"./buffer\";\r\n\r\n/**\r\n * Copies the given data array to the given float array.\r\n * @param input the input data array\r\n * @param size the number of components\r\n * @param type the component type\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param normalized whether the data is normalized\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param output the output float array\r\n */\r\nexport function CopyFloatData(\r\n input: DataArray,\r\n size: number,\r\n type: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n normalized: boolean,\r\n totalVertices: number,\r\n output: Float32Array\r\n): void {\r\n const tightlyPackedByteStride = size * VertexBuffer.GetTypeByteLength(type);\r\n const count = totalVertices * size;\r\n\r\n if (output.length !== count) {\r\n throw new Error(\"Output length is not valid\");\r\n }\r\n\r\n if (type !== VertexBuffer.FLOAT || byteStride !== tightlyPackedByteStride) {\r\n VertexBuffer.ForEach(input, byteOffset, byteStride, size, type, count, normalized, (value, index) => (output[index] = value));\r\n return;\r\n }\r\n\r\n if (input instanceof Array) {\r\n const offset = byteOffset / 4;\r\n output.set(input, offset);\r\n } else if (input instanceof ArrayBuffer) {\r\n const floatData = new Float32Array(input, byteOffset, count);\r\n output.set(floatData);\r\n } else {\r\n let offset = input.byteOffset + byteOffset;\r\n\r\n // Protect against bad data\r\n const remainder = offset % 4;\r\n if (remainder) {\r\n offset = Math.max(0, offset - remainder);\r\n }\r\n\r\n const floatData = new Float32Array(input.buffer, offset, count);\r\n output.set(floatData);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"bufferUtils.js","sourceRoot":"","sources":["../../../../dev/core/src/Buffers/bufferUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CACzB,KAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,UAAkB,EAClB,UAAkB,EAClB,UAAmB,EACnB,aAAqB,EACrB,MAAoB;IAEpB,MAAM,uBAAuB,GAAG,IAAI,GAAG,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,aAAa,GAAG,IAAI,CAAC;IAEnC,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KACjD;IAED,IAAI,IAAI,KAAK,YAAY,CAAC,KAAK,IAAI,UAAU,KAAK,uBAAuB,EAAE;QACvE,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QAC9H,OAAO;KACV;IAED,IAAI,KAAK,YAAY,KAAK,EAAE;QACxB,MAAM,MAAM,GAAG,UAAU,GAAG,CAAC,CAAC;QAC9B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAC7B;SAAM,IAAI,KAAK,YAAY,WAAW,EAAE;QACrC,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACzB;SAAM;QACH,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7C,2BAA2B;QAC3B,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC;QAC7B,IAAI,SAAS,EAAE;YACX,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;YACtD,kDAAkD;YAClD,MAAM,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7E,OAAO;SACV;QAED,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAChE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KACzB;AACL,CAAC","sourcesContent":["import type { DataArray } from \"../types\";\r\nimport { VertexBuffer } from \"./buffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\n\r\n/**\r\n * Copies the given data array to the given float array.\r\n * @param input the input data array\r\n * @param size the number of components\r\n * @param type the component type\r\n * @param byteOffset the byte offset of the data\r\n * @param byteStride the byte stride of the data\r\n * @param normalized whether the data is normalized\r\n * @param totalVertices number of vertices in the buffer to take into account\r\n * @param output the output float array\r\n */\r\nexport function CopyFloatData(\r\n input: DataArray,\r\n size: number,\r\n type: number,\r\n byteOffset: number,\r\n byteStride: number,\r\n normalized: boolean,\r\n totalVertices: number,\r\n output: Float32Array\r\n): void {\r\n const tightlyPackedByteStride = size * VertexBuffer.GetTypeByteLength(type);\r\n const count = totalVertices * size;\r\n\r\n if (output.length !== count) {\r\n throw new Error(\"Output length is not valid\");\r\n }\r\n\r\n if (type !== VertexBuffer.FLOAT || byteStride !== tightlyPackedByteStride) {\r\n VertexBuffer.ForEach(input, byteOffset, byteStride, size, type, count, normalized, (value, index) => (output[index] = value));\r\n return;\r\n }\r\n\r\n if (input instanceof Array) {\r\n const offset = byteOffset / 4;\r\n output.set(input, offset);\r\n } else if (input instanceof ArrayBuffer) {\r\n const floatData = new Float32Array(input, byteOffset, count);\r\n output.set(floatData);\r\n } else {\r\n const offset = input.byteOffset + byteOffset;\r\n\r\n // Protect against bad data\r\n const remainder = offset % 4;\r\n if (remainder) {\r\n Logger.Warn(\"CopyFloatData: copied misaligned data.\");\r\n // If not aligned, copy the data to aligned buffer\r\n output.set(new Float32Array(input.buffer.slice(offset, offset + count * 4)));\r\n return;\r\n }\r\n\r\n const floatData = new Float32Array(input.buffer, offset, count);\r\n output.set(floatData);\r\n }\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "../tslib.es6.js";
2
2
  import { serialize, serializeAsVector3, serializeAsMeshReference, serializeAsVector2 } from "../Misc/decorators.js";
3
3
  import { Observable } from "../Misc/observable.js";
4
- import { Matrix, Vector3, Vector2, TmpVectors } from "../Maths/math.vector.js";
4
+ import { Matrix, Vector3, Vector2, TmpVectors, Quaternion } from "../Maths/math.vector.js";
5
5
  import { Node } from "../node.js";
6
6
  import { Mesh } from "../Meshes/mesh.js";
7
7
  import { AutoRotationBehavior } from "../Behaviors/Cameras/autoRotationBehavior.js";
@@ -714,19 +714,21 @@ export class ArcRotateCamera extends TargetCamera {
714
714
  if (this._progressiveRestore) {
715
715
  const dt = this._scene.getEngine().getDeltaTime() / 1000;
716
716
  const t = 1 - Math.pow(2, -dt / this.restoreStateInterpolationFactor);
717
- const mod = 2 * Math.PI;
718
717
  // can't use tmp vector here because of assignment
719
718
  this.setTarget(Vector3.Lerp(this.getTarget(), this._storedTarget, t));
720
- this.alpha %= mod;
721
- this.beta %= mod;
722
- this.alpha += ((this._storedAlpha % mod) - this.alpha) * t;
723
- this.beta += ((this._storedBeta % mod) - this.beta) * t;
719
+ // Using quaternion for smoother interpolation (and no Euler angles modulo)
720
+ Quaternion.RotationAlphaBetaGammaToRef(this._storedAlpha, this._storedBeta, 0, TmpVectors.Quaternion[0]);
721
+ Quaternion.RotationAlphaBetaGammaToRef(this.alpha, this.beta, 0, TmpVectors.Quaternion[1]);
722
+ Quaternion.SlerpToRef(TmpVectors.Quaternion[1], TmpVectors.Quaternion[0], t, TmpVectors.Quaternion[2]);
723
+ TmpVectors.Quaternion[2].normalize();
724
+ TmpVectors.Quaternion[2].toAlphaBetaGammaToRef(TmpVectors.Vector3[0]);
725
+ this.alpha = TmpVectors.Vector3[0].x;
726
+ this.beta = TmpVectors.Vector3[0].y;
724
727
  this.radius += (this._storedRadius - this.radius) * t;
725
728
  Vector2.LerpToRef(this.targetScreenOffset, this._storedTargetScreenOffset, t, this.targetScreenOffset);
726
729
  // stop restoring when wihtin close range or when user starts interacting
727
730
  if ((Vector3.DistanceSquared(this.getTarget(), this._storedTarget) < Epsilon &&
728
- Math.pow((this._storedAlpha % mod) - (this.alpha % mod), 2) < Epsilon &&
729
- Math.pow((this._storedBeta % mod) - (this.beta % mod), 2) < Epsilon &&
731
+ TmpVectors.Quaternion[2].equalsWithEpsilon(TmpVectors.Quaternion[0]) &&
730
732
  Math.pow(this._storedRadius - this.radius, 2) < Epsilon &&
731
733
  Vector2.Distance(this.targetScreenOffset, this._storedTargetScreenOffset) < Epsilon) ||
732
734
  this.inertialAlphaOffset !== 0 ||