|
@@ -7970,13 +7970,15 @@ var BABYLON;
|
|
|
/**
|
|
|
* Provides a slice function that will work even on IE
|
|
|
* @param data defines the array to slice
|
|
|
+ * @param start defines the start of the data (optional)
|
|
|
+ * @param end defines the end of the data (optional)
|
|
|
* @returns the new sliced array
|
|
|
*/
|
|
|
- Tools.Slice = function (data) {
|
|
|
+ Tools.Slice = function (data, start, end) {
|
|
|
if (data.slice) {
|
|
|
- return data.slice();
|
|
|
+ return data.slice(start, end);
|
|
|
}
|
|
|
- return Array.prototype.slice.call(data);
|
|
|
+ return Array.prototype.slice.call(data, start, end);
|
|
|
};
|
|
|
Tools.SetImmediate = function (action) {
|
|
|
if (window.setImmediate) {
|
|
@@ -12245,33 +12247,43 @@ var BABYLON;
|
|
|
this.bindArrayBuffer(null);
|
|
|
this._cachedVertexBuffers = null;
|
|
|
};
|
|
|
- Engine.prototype.createVertexBuffer = function (vertices) {
|
|
|
+ /**
|
|
|
+ * Creates a vertex buffer
|
|
|
+ * @param data the data for the vertex buffer
|
|
|
+ * @returns the new WebGL static buffer
|
|
|
+ */
|
|
|
+ Engine.prototype.createVertexBuffer = function (data) {
|
|
|
var vbo = this._gl.createBuffer();
|
|
|
if (!vbo) {
|
|
|
throw new Error("Unable to create vertex buffer");
|
|
|
}
|
|
|
this.bindArrayBuffer(vbo);
|
|
|
- if (vertices instanceof Float32Array) {
|
|
|
- this._gl.bufferData(this._gl.ARRAY_BUFFER, vertices, this._gl.STATIC_DRAW);
|
|
|
+ if (data instanceof Array) {
|
|
|
+ this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), this._gl.STATIC_DRAW);
|
|
|
}
|
|
|
else {
|
|
|
- this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(vertices), this._gl.STATIC_DRAW);
|
|
|
+ this._gl.bufferData(this._gl.ARRAY_BUFFER, data, this._gl.STATIC_DRAW);
|
|
|
}
|
|
|
this._resetVertexBufferBinding();
|
|
|
vbo.references = 1;
|
|
|
return vbo;
|
|
|
};
|
|
|
- Engine.prototype.createDynamicVertexBuffer = function (vertices) {
|
|
|
+ /**
|
|
|
+ * Creates a dynamic vertex buffer
|
|
|
+ * @param data the data for the dynamic vertex buffer
|
|
|
+ * @returns the new WebGL dynamic buffer
|
|
|
+ */
|
|
|
+ Engine.prototype.createDynamicVertexBuffer = function (data) {
|
|
|
var vbo = this._gl.createBuffer();
|
|
|
if (!vbo) {
|
|
|
throw new Error("Unable to create dynamic vertex buffer");
|
|
|
}
|
|
|
this.bindArrayBuffer(vbo);
|
|
|
- if (vertices instanceof Float32Array) {
|
|
|
- this._gl.bufferData(this._gl.ARRAY_BUFFER, vertices, this._gl.DYNAMIC_DRAW);
|
|
|
+ if (data instanceof Array) {
|
|
|
+ this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), this._gl.DYNAMIC_DRAW);
|
|
|
}
|
|
|
else {
|
|
|
- this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(vertices), this._gl.DYNAMIC_DRAW);
|
|
|
+ this._gl.bufferData(this._gl.ARRAY_BUFFER, data, this._gl.DYNAMIC_DRAW);
|
|
|
}
|
|
|
this._resetVertexBufferBinding();
|
|
|
vbo.references = 1;
|
|
@@ -12292,25 +12304,38 @@ var BABYLON;
|
|
|
this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.DYNAMIC_DRAW);
|
|
|
this._resetIndexBufferBinding();
|
|
|
};
|
|
|
- Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, offset, count) {
|
|
|
+ /**
|
|
|
+ * Updates a dynamic vertex buffer.
|
|
|
+ * @param vertexBuffer the vertex buffer to update
|
|
|
+ * @param data the data used to update the vertex buffer
|
|
|
+ * @param byteOffset the byte offset of the data (optional)
|
|
|
+ * @param byteLength the byte length of the data (optional)
|
|
|
+ */
|
|
|
+ Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, data, byteOffset, byteLength) {
|
|
|
this.bindArrayBuffer(vertexBuffer);
|
|
|
- if (offset === undefined) {
|
|
|
- offset = 0;
|
|
|
+ if (byteOffset === undefined) {
|
|
|
+ byteOffset = 0;
|
|
|
}
|
|
|
- if (count === undefined) {
|
|
|
- if (vertices instanceof Float32Array) {
|
|
|
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, vertices);
|
|
|
+ if (byteLength === undefined) {
|
|
|
+ if (data instanceof Array) {
|
|
|
+ this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, new Float32Array(data));
|
|
|
}
|
|
|
else {
|
|
|
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, new Float32Array(vertices));
|
|
|
+ this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, data);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- if (vertices instanceof Float32Array) {
|
|
|
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, vertices.subarray(offset, offset + count));
|
|
|
+ if (data instanceof Array) {
|
|
|
+ this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(data).subarray(byteOffset, byteOffset + byteLength));
|
|
|
}
|
|
|
else {
|
|
|
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(vertices).subarray(offset, offset + count));
|
|
|
+ if (data instanceof ArrayBuffer) {
|
|
|
+ data = new Uint8Array(data, byteOffset, byteLength);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ data = new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
|
|
|
+ }
|
|
|
+ this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
|
|
|
}
|
|
|
}
|
|
|
this._resetVertexBufferBinding();
|
|
@@ -12466,7 +12491,7 @@ var BABYLON;
|
|
|
}
|
|
|
var buffer = vertexBuffer.getBuffer();
|
|
|
if (buffer) {
|
|
|
- this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
|
|
|
+ this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), vertexBuffer.type, vertexBuffer.normalized, vertexBuffer.byteStride, vertexBuffer.byteOffset);
|
|
|
if (vertexBuffer.getIsInstanced()) {
|
|
|
this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());
|
|
|
if (!this._vaoRecordInProgress) {
|
|
@@ -27100,8 +27125,21 @@ var BABYLON;
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
var Buffer = /** @class */ (function () {
|
|
|
- function Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced) {
|
|
|
+ /**
|
|
|
+ * Constructor
|
|
|
+ * @param engine the engine
|
|
|
+ * @param data the data to use for this buffer
|
|
|
+ * @param updatable whether the data is updatable
|
|
|
+ * @param stride the stride (optional)
|
|
|
+ * @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)
|
|
|
+ */
|
|
|
+ function Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes) {
|
|
|
+ if (stride === void 0) { stride = 0; }
|
|
|
+ if (postponeInternalCreation === void 0) { postponeInternalCreation = false; }
|
|
|
if (instanced === void 0) { instanced = false; }
|
|
|
+ if (useBytes === void 0) { useBytes = false; }
|
|
|
if (engine instanceof BABYLON.Mesh) {
|
|
|
this._engine = engine.getScene().getEngine();
|
|
|
}
|
|
@@ -27111,7 +27149,7 @@ var BABYLON;
|
|
|
this._updatable = updatable;
|
|
|
this._instanced = instanced;
|
|
|
this._data = data;
|
|
|
- this._strideSize = stride;
|
|
|
+ this.byteStride = useBytes ? stride : stride * 4;
|
|
|
if (!postponeInternalCreation) {
|
|
|
this.create();
|
|
|
}
|
|
@@ -27123,11 +27161,15 @@ var BABYLON;
|
|
|
* @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
|
|
|
* @returns the new vertex buffer
|
|
|
*/
|
|
|
- Buffer.prototype.createVertexBuffer = function (kind, offset, size, stride, instanced) {
|
|
|
+ Buffer.prototype.createVertexBuffer = function (kind, offset, size, stride, instanced, useBytes) {
|
|
|
+ if (useBytes === void 0) { useBytes = false; }
|
|
|
+ var byteOffset = useBytes ? offset : offset * 4;
|
|
|
+ var byteStride = stride ? (useBytes ? stride : stride * 4) : this.byteStride;
|
|
|
// a lot of these parameters are ignored as they are overriden by the buffer
|
|
|
- return new BABYLON.VertexBuffer(this._engine, this, kind, this._updatable, true, stride ? stride : this._strideSize, instanced === undefined ? this._instanced : instanced, offset, size);
|
|
|
+ return new BABYLON.VertexBuffer(this._engine, this, kind, this._updatable, true, byteStride, instanced === undefined ? this._instanced : instanced, byteOffset, size, undefined, undefined, true);
|
|
|
};
|
|
|
// Properties
|
|
|
Buffer.prototype.isUpdatable = function () {
|
|
@@ -27139,23 +27181,15 @@ var BABYLON;
|
|
|
Buffer.prototype.getBuffer = function () {
|
|
|
return this._buffer;
|
|
|
};
|
|
|
+ /**
|
|
|
+ * Gets the stride in float32 units (i.e. byte stride / 4).
|
|
|
+ * May not be an integer if the byte stride is not divisible by 4.
|
|
|
+ * DEPRECATED. Use byteStride instead.
|
|
|
+ * @returns the stride in float32 units
|
|
|
+ */
|
|
|
Buffer.prototype.getStrideSize = function () {
|
|
|
- return this._strideSize;
|
|
|
+ return this.byteStride / 4;
|
|
|
};
|
|
|
- // public getIsInstanced(): boolean {
|
|
|
- // 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
|
|
|
Buffer.prototype.create = function (data) {
|
|
|
if (data === void 0) { data = null; }
|
|
@@ -27187,12 +27221,20 @@ var BABYLON;
|
|
|
Buffer.prototype.update = function (data) {
|
|
|
this.create(data);
|
|
|
};
|
|
|
- Buffer.prototype.updateDirectly = function (data, offset, vertexCount) {
|
|
|
+ /**
|
|
|
+ * Updates the data directly.
|
|
|
+ * @param data the new data
|
|
|
+ * @param offset the new offset
|
|
|
+ * @param vertexCount the vertex count (optional)
|
|
|
+ * @param useBytes set to true if the offset is in bytes
|
|
|
+ */
|
|
|
+ Buffer.prototype.updateDirectly = function (data, offset, vertexCount, useBytes) {
|
|
|
+ if (useBytes === void 0) { useBytes = false; }
|
|
|
if (!this._buffer) {
|
|
|
return;
|
|
|
}
|
|
|
if (this._updatable) {
|
|
|
- this._engine.updateDynamicVertexBuffer(this._buffer, data, offset, (vertexCount ? vertexCount * this.getStrideSize() : undefined));
|
|
|
+ this._engine.updateDynamicVertexBuffer(this._buffer, data, useBytes ? offset : offset * 4, (vertexCount ? vertexCount * this.byteStride : undefined));
|
|
|
this._data = null;
|
|
|
}
|
|
|
};
|
|
@@ -27215,27 +27257,66 @@ var BABYLON;
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
var VertexBuffer = /** @class */ (function () {
|
|
|
- function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation, stride, instanced, offset, size) {
|
|
|
+ /**
|
|
|
+ * Constructor
|
|
|
+ * @param engine the engine
|
|
|
+ * @param data the data to use for this vertex buffer
|
|
|
+ * @param kind the vertex buffer kind
|
|
|
+ * @param updatable whether the data is updatable
|
|
|
+ * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
|
|
|
+ * @param stride the stride (optional)
|
|
|
+ * @param instanced whether the buffer is instanced (optional)
|
|
|
+ * @param offset the offset of the data (optional)
|
|
|
+ * @param size the number of components (optional)
|
|
|
+ * @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)
|
|
|
+ */
|
|
|
+ function VertexBuffer(engine, data, kind, updatable, postponeInternalCreation, stride, instanced, offset, size, type, normalized, useBytes) {
|
|
|
+ if (normalized === void 0) { normalized = false; }
|
|
|
+ if (useBytes === void 0) { useBytes = false; }
|
|
|
if (data instanceof BABYLON.Buffer) {
|
|
|
- if (!stride) {
|
|
|
- stride = data.getStrideSize();
|
|
|
- }
|
|
|
this._buffer = data;
|
|
|
this._ownsBuffer = false;
|
|
|
}
|
|
|
else {
|
|
|
- if (!stride) {
|
|
|
- stride = VertexBuffer.DeduceStride(kind);
|
|
|
- }
|
|
|
- this._buffer = new BABYLON.Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced);
|
|
|
+ this._buffer = new BABYLON.Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);
|
|
|
this._ownsBuffer = true;
|
|
|
}
|
|
|
- this._stride = stride;
|
|
|
+ this._kind = kind;
|
|
|
+ if (type == undefined) {
|
|
|
+ var data_1 = this.getData();
|
|
|
+ this.type = VertexBuffer.FLOAT;
|
|
|
+ if (data_1 instanceof Int8Array)
|
|
|
+ this.type = VertexBuffer.BYTE;
|
|
|
+ else if (data_1 instanceof Uint8Array)
|
|
|
+ this.type = VertexBuffer.UNSIGNED_BYTE;
|
|
|
+ else if (data_1 instanceof Int16Array)
|
|
|
+ this.type = VertexBuffer.SHORT;
|
|
|
+ else if (data_1 instanceof Uint16Array)
|
|
|
+ this.type = VertexBuffer.UNSIGNED_SHORT;
|
|
|
+ else if (data_1 instanceof Int32Array)
|
|
|
+ this.type = VertexBuffer.INT;
|
|
|
+ else if (data_1 instanceof Uint32Array)
|
|
|
+ this.type = VertexBuffer.UNSIGNED_INT;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.type = type;
|
|
|
+ }
|
|
|
+ var typeByteLength = VertexBuffer.GetTypeByteLength(this.type);
|
|
|
+ if (useBytes) {
|
|
|
+ this._size = size || (stride ? (stride / typeByteLength) : VertexBuffer.DeduceStride(kind));
|
|
|
+ this.byteStride = stride || this._buffer.byteStride || (this._size * typeByteLength);
|
|
|
+ this.byteOffset = offset || 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._size = size || stride || VertexBuffer.DeduceStride(kind);
|
|
|
+ this.byteStride = stride ? (stride * typeByteLength) : (this._buffer.byteStride || (this._size * typeByteLength));
|
|
|
+ this.byteOffset = (offset || 0) * typeByteLength;
|
|
|
+ }
|
|
|
+ this.normalized = normalized;
|
|
|
this._instanced = instanced !== undefined ? instanced : false;
|
|
|
this._instanceDivisor = instanced ? 1 : 0;
|
|
|
- this._offset = offset ? offset : 0;
|
|
|
- this._size = size ? size : stride;
|
|
|
- this._kind = kind;
|
|
|
}
|
|
|
Object.defineProperty(VertexBuffer.prototype, "instanceDivisor", {
|
|
|
/**
|
|
@@ -27276,7 +27357,7 @@ var BABYLON;
|
|
|
return this._buffer.isUpdatable();
|
|
|
};
|
|
|
/**
|
|
|
- * Returns an array of numbers or a Float32Array containing the VertexBuffer data.
|
|
|
+ * Returns an array of numbers or a typed array containing the VertexBuffer data.
|
|
|
*/
|
|
|
VertexBuffer.prototype.getData = function () {
|
|
|
return this._buffer.getData();
|
|
@@ -27288,19 +27369,21 @@ var BABYLON;
|
|
|
return this._buffer.getBuffer();
|
|
|
};
|
|
|
/**
|
|
|
- * Returns the stride of the VertexBuffer (integer).
|
|
|
+ * Returns the stride as a multiple of the type byte length.
|
|
|
+ * DEPRECATED. Use byteStride instead.
|
|
|
*/
|
|
|
VertexBuffer.prototype.getStrideSize = function () {
|
|
|
- return this._stride;
|
|
|
+ return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);
|
|
|
};
|
|
|
/**
|
|
|
- * Returns the offset (integer).
|
|
|
+ * Returns the offset as a multiple of the type byte length.
|
|
|
+ * DEPRECATED. Use byteOffset instead.
|
|
|
*/
|
|
|
VertexBuffer.prototype.getOffset = function () {
|
|
|
- return this._offset;
|
|
|
+ return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);
|
|
|
};
|
|
|
/**
|
|
|
- * Returns the VertexBuffer total size (integer).
|
|
|
+ * Returns the number of components per vertex attribute (integer).
|
|
|
*/
|
|
|
VertexBuffer.prototype.getSize = function () {
|
|
|
return this._size;
|
|
@@ -27348,6 +27431,14 @@ var BABYLON;
|
|
|
this._buffer.dispose();
|
|
|
}
|
|
|
};
|
|
|
+ /**
|
|
|
+ * Enumerates each value of this vertex buffer as numbers.
|
|
|
+ * @param count the number of values to enumerate
|
|
|
+ * @param callback the callback function called for each value
|
|
|
+ */
|
|
|
+ VertexBuffer.prototype.forEach = function (count, callback) {
|
|
|
+ VertexBuffer.ForEach(this._buffer.getData(), this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);
|
|
|
+ };
|
|
|
Object.defineProperty(VertexBuffer, "PositionKind", {
|
|
|
get: function () {
|
|
|
return VertexBuffer._PositionKind;
|
|
@@ -27474,6 +27565,128 @@ var BABYLON;
|
|
|
throw new Error("Invalid kind '" + kind + "'");
|
|
|
}
|
|
|
};
|
|
|
+ /**
|
|
|
+ * Gets the byte length of the given type.
|
|
|
+ * @param type the type
|
|
|
+ * @returns the number of bytes
|
|
|
+ */
|
|
|
+ VertexBuffer.GetTypeByteLength = function (type) {
|
|
|
+ switch (type) {
|
|
|
+ case VertexBuffer.BYTE:
|
|
|
+ case VertexBuffer.UNSIGNED_BYTE:
|
|
|
+ return 1;
|
|
|
+ case VertexBuffer.SHORT:
|
|
|
+ case VertexBuffer.UNSIGNED_SHORT:
|
|
|
+ return 2;
|
|
|
+ case VertexBuffer.INT:
|
|
|
+ case VertexBuffer.FLOAT:
|
|
|
+ return 4;
|
|
|
+ default:
|
|
|
+ throw new Error("Invalid type '" + type + "'");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * Enumerates each value of the given parameters as numbers.
|
|
|
+ * @param data the data to enumerate
|
|
|
+ * @param byteOffset the byte offset of the data
|
|
|
+ * @param byteStride the byte stride of the data
|
|
|
+ * @param componentCount the number of components per element
|
|
|
+ * @param componentType the type of the component
|
|
|
+ * @param count the total number of components
|
|
|
+ * @param normalized whether the data is normalized
|
|
|
+ * @param callback the callback function called for each value
|
|
|
+ */
|
|
|
+ VertexBuffer.ForEach = function (data, byteOffset, byteStride, componentCount, componentType, count, normalized, callback) {
|
|
|
+ if (data instanceof Array) {
|
|
|
+ var offset = byteOffset / 4;
|
|
|
+ var stride = byteStride / 4;
|
|
|
+ for (var index = 0; index < count; index += componentCount) {
|
|
|
+ for (var componentIndex = 0; componentIndex < componentCount; componentIndex++) {
|
|
|
+ callback(data[offset + componentIndex], index + componentIndex);
|
|
|
+ }
|
|
|
+ offset += stride;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
|
+ var componentByteLength = VertexBuffer.GetTypeByteLength(componentType);
|
|
|
+ for (var index = 0; index < count; index += componentCount) {
|
|
|
+ var componentByteOffset = byteOffset;
|
|
|
+ for (var componentIndex = 0; componentIndex < componentCount; componentIndex++) {
|
|
|
+ var value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);
|
|
|
+ callback(value, index + componentIndex);
|
|
|
+ componentByteOffset += componentByteLength;
|
|
|
+ }
|
|
|
+ byteOffset += byteStride;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ VertexBuffer._GetFloatValue = function (dataView, type, byteOffset, normalized) {
|
|
|
+ switch (type) {
|
|
|
+ case VertexBuffer.BYTE: {
|
|
|
+ var value = dataView.getInt8(byteOffset);
|
|
|
+ if (normalized) {
|
|
|
+ value = (value + 0.5) / 127.5;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ case VertexBuffer.UNSIGNED_BYTE: {
|
|
|
+ var value = dataView.getUint8(byteOffset);
|
|
|
+ if (normalized) {
|
|
|
+ value = value / 255;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ case VertexBuffer.SHORT: {
|
|
|
+ var value = dataView.getInt16(byteOffset, true);
|
|
|
+ if (normalized) {
|
|
|
+ value = (value + 0.5) / 16383.5;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ case VertexBuffer.UNSIGNED_SHORT: {
|
|
|
+ var value = dataView.getUint16(byteOffset, true);
|
|
|
+ if (normalized) {
|
|
|
+ value = value / 65535;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ case VertexBuffer.FLOAT: {
|
|
|
+ return dataView.getFloat32(byteOffset, true);
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ throw new Error("Invalid component type " + type);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * The byte type.
|
|
|
+ */
|
|
|
+ VertexBuffer.BYTE = 5120;
|
|
|
+ /**
|
|
|
+ * The unsigned byte type.
|
|
|
+ */
|
|
|
+ VertexBuffer.UNSIGNED_BYTE = 5121;
|
|
|
+ /**
|
|
|
+ * The short type.
|
|
|
+ */
|
|
|
+ VertexBuffer.SHORT = 5122;
|
|
|
+ /**
|
|
|
+ * The unsigned short type.
|
|
|
+ */
|
|
|
+ VertexBuffer.UNSIGNED_SHORT = 5123;
|
|
|
+ /**
|
|
|
+ * The integer type.
|
|
|
+ */
|
|
|
+ VertexBuffer.INT = 5124;
|
|
|
+ /**
|
|
|
+ * The unsigned integer type.
|
|
|
+ */
|
|
|
+ VertexBuffer.UNSIGNED_INT = 5125;
|
|
|
+ /**
|
|
|
+ * The float type.
|
|
|
+ */
|
|
|
+ VertexBuffer.FLOAT = 5126;
|
|
|
// Enums
|
|
|
VertexBuffer._PositionKind = "position";
|
|
|
VertexBuffer._NormalKind = "normal";
|
|
@@ -29710,7 +29923,7 @@ var BABYLON;
|
|
|
};
|
|
|
Mesh.prototype._draw = function (subMesh, fillMode, instancesCount, alternate) {
|
|
|
if (alternate === void 0) { alternate = false; }
|
|
|
- if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
|
|
|
+ if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
|
|
|
return this;
|
|
|
}
|
|
|
this.onBeforeDrawObservable.notifyObservers(this);
|
|
@@ -29906,7 +30119,7 @@ var BABYLON;
|
|
|
return this;
|
|
|
}
|
|
|
// Checking geometry state
|
|
|
- if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
|
|
|
+ if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
|
|
|
return this;
|
|
|
}
|
|
|
this.onBeforeRenderObservable.notifyObservers(this);
|
|
@@ -36145,7 +36358,7 @@ var BABYLON;
|
|
|
if (mesh) {
|
|
|
if (mesh.getClassName() === "LinesMesh") {
|
|
|
this.boundingBias = new BABYLON.Vector2(0, mesh.intersectionThreshold);
|
|
|
- this.updateExtend();
|
|
|
+ this._updateExtend();
|
|
|
}
|
|
|
this.applyToMesh(mesh);
|
|
|
mesh.computeWorldMatrix(true);
|
|
@@ -36166,7 +36379,7 @@ var BABYLON;
|
|
|
return;
|
|
|
}
|
|
|
this._boundingBias = value.clone();
|
|
|
- this.updateBoundingInfo(true, null);
|
|
|
+ this._updateBoundingInfo(true, null);
|
|
|
},
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
@@ -36260,6 +36473,9 @@ var BABYLON;
|
|
|
*/
|
|
|
Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
|
|
|
if (updatable === void 0) { updatable = false; }
|
|
|
+ if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
+ this._totalVertices = data.length / (stride || 3);
|
|
|
+ }
|
|
|
var buffer = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
|
|
|
this.setVerticesBuffer(buffer);
|
|
|
};
|
|
@@ -36276,18 +36492,20 @@ var BABYLON;
|
|
|
/**
|
|
|
* Affect a vertex buffer to the geometry. the vertexBuffer.getKind() function is used to determine where to store the data
|
|
|
* @param buffer defines the vertex buffer to use
|
|
|
+ * @param totalVertices defines the total number of vertices for position kind (could be null)
|
|
|
*/
|
|
|
- Geometry.prototype.setVerticesBuffer = function (buffer) {
|
|
|
+ Geometry.prototype.setVerticesBuffer = function (buffer, totalVertices) {
|
|
|
+ if (totalVertices === void 0) { totalVertices = null; }
|
|
|
var kind = buffer.getKind();
|
|
|
if (this._vertexBuffers[kind]) {
|
|
|
this._vertexBuffers[kind].dispose();
|
|
|
}
|
|
|
this._vertexBuffers[kind] = buffer;
|
|
|
if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
- var data = buffer.getData();
|
|
|
- var stride = buffer.getStrideSize();
|
|
|
- this._totalVertices = data.length / stride;
|
|
|
- this.updateExtend(data, stride);
|
|
|
+ if (totalVertices != null) {
|
|
|
+ this._totalVertices = totalVertices;
|
|
|
+ }
|
|
|
+ this._updateExtend();
|
|
|
this._resetPointsArrayCache();
|
|
|
var meshes = this._meshes;
|
|
|
var numOfMeshes = meshes.length;
|
|
@@ -36335,15 +36553,13 @@ var BABYLON;
|
|
|
}
|
|
|
vertexBuffer.update(data);
|
|
|
if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
- var stride = vertexBuffer.getStrideSize();
|
|
|
- this._totalVertices = data.length / stride;
|
|
|
- this.updateBoundingInfo(updateExtends, data);
|
|
|
+ this._updateBoundingInfo(updateExtends, data);
|
|
|
}
|
|
|
this.notifyUpdate(kind);
|
|
|
};
|
|
|
- Geometry.prototype.updateBoundingInfo = function (updateExtends, data) {
|
|
|
+ Geometry.prototype._updateBoundingInfo = function (updateExtends, data) {
|
|
|
if (updateExtends) {
|
|
|
- this.updateExtend(data);
|
|
|
+ this._updateExtend(data);
|
|
|
}
|
|
|
var meshes = this._meshes;
|
|
|
var numOfMeshes = meshes.length;
|
|
@@ -36392,7 +36608,7 @@ var BABYLON;
|
|
|
return this._totalVertices;
|
|
|
};
|
|
|
/**
|
|
|
- * Gets a specific vertex data attached to this geometry
|
|
|
+ * Gets a specific vertex data attached to this geometry. Float data is constructed if the vertex buffer data cannot be returned directly.
|
|
|
* @param kind defines the data kind (Position, normal, etc...)
|
|
|
* @param copyWhenShared defines if the returned array must be cloned upon returning it if the current geometry is shared between multiple meshes
|
|
|
* @param forceCopy defines a boolean indicating that the returned array must be cloned upon returning it
|
|
@@ -36403,18 +36619,36 @@ var BABYLON;
|
|
|
if (!vertexBuffer) {
|
|
|
return null;
|
|
|
}
|
|
|
- var orig = vertexBuffer.getData();
|
|
|
- if (!forceCopy && (!copyWhenShared || this._meshes.length === 1)) {
|
|
|
- return orig;
|
|
|
+ var data = vertexBuffer.getData();
|
|
|
+ if (!data) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- else {
|
|
|
- var len = orig.length;
|
|
|
- var copy = [];
|
|
|
- for (var i = 0; i < len; i++) {
|
|
|
- copy.push(orig[i]);
|
|
|
+ var defaultStride = BABYLON.VertexBuffer.DeduceStride(vertexBuffer.getKind());
|
|
|
+ var defaultByteStride = defaultStride * BABYLON.VertexBuffer.GetTypeByteLength(vertexBuffer.type);
|
|
|
+ var count = this._totalVertices * defaultStride;
|
|
|
+ if (vertexBuffer.type !== BABYLON.VertexBuffer.FLOAT || vertexBuffer.byteStride !== defaultByteStride) {
|
|
|
+ var copy_1 = new Array(count);
|
|
|
+ vertexBuffer.forEach(count, function (value, index) {
|
|
|
+ copy_1[index] = value;
|
|
|
+ });
|
|
|
+ return copy_1;
|
|
|
+ }
|
|
|
+ if (!(data instanceof Array || data instanceof Float32Array) || vertexBuffer.byteOffset !== 0 || data.length !== count) {
|
|
|
+ if (data instanceof Array) {
|
|
|
+ var offset = vertexBuffer.byteOffset / 4;
|
|
|
+ return BABYLON.Tools.Slice(data, offset, offset + count);
|
|
|
}
|
|
|
- return copy;
|
|
|
+ else if (data instanceof ArrayBuffer) {
|
|
|
+ return new Float32Array(data, vertexBuffer.byteOffset, count);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return new Float32Array(data.buffer, data.byteOffset + vertexBuffer.byteOffset, count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (forceCopy || (copyWhenShared && this._meshes.length !== 1)) {
|
|
|
+ return BABYLON.Tools.Slice(data);
|
|
|
}
|
|
|
+ return data;
|
|
|
};
|
|
|
/**
|
|
|
* Returns a boolean defining if the vertex data for the requested `kind` is updatable
|
|
@@ -36620,12 +36854,12 @@ var BABYLON;
|
|
|
mesh._boundingInfo = this._boundingInfo;
|
|
|
}
|
|
|
};
|
|
|
- Geometry.prototype.updateExtend = function (data, stride) {
|
|
|
+ Geometry.prototype._updateExtend = function (data) {
|
|
|
if (data === void 0) { data = null; }
|
|
|
if (!data) {
|
|
|
- data = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].getData();
|
|
|
+ data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
|
}
|
|
|
- this._extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices, this.boundingBias, stride);
|
|
|
+ this._extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices, this.boundingBias, 3);
|
|
|
};
|
|
|
Geometry.prototype._applyToMesh = function (mesh) {
|
|
|
var numOfMeshes = this._meshes.length;
|
|
@@ -36639,7 +36873,7 @@ var BABYLON;
|
|
|
buffer.references = numOfMeshes;
|
|
|
if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
if (!this._extend) {
|
|
|
- this.updateExtend(this._vertexBuffers[kind].getData());
|
|
|
+ this._updateExtend();
|
|
|
}
|
|
|
mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
|
|
|
mesh._createGlobalSubMesh(false);
|
|
@@ -57584,7 +57818,7 @@ var BABYLON;
|
|
|
return this;
|
|
|
};
|
|
|
LinesMesh.prototype._draw = function (subMesh, fillMode, instancesCount) {
|
|
|
- if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
|
|
|
+ if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
|
|
|
return this;
|
|
|
}
|
|
|
var engine = this.getScene().getEngine();
|
|
@@ -91448,7 +91682,14 @@ var BABYLON;
|
|
|
NullEngine.prototype.updateDynamicIndexBuffer = function (indexBuffer, indices, offset) {
|
|
|
if (offset === void 0) { offset = 0; }
|
|
|
};
|
|
|
- NullEngine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, offset, count) {
|
|
|
+ /**
|
|
|
+ * Updates a dynamic vertex buffer.
|
|
|
+ * @param vertexBuffer the vertex buffer to update
|
|
|
+ * @param data the data used to update the vertex buffer
|
|
|
+ * @param byteOffset the byte offset of the data (optional)
|
|
|
+ * @param byteLength the byte length of the data (optional)
|
|
|
+ */
|
|
|
+ NullEngine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, byteOffset, byteLength) {
|
|
|
};
|
|
|
NullEngine.prototype._bindTextureDirectly = function (target, texture) {
|
|
|
if (this._boundTexturesCache[this._activeChannel] !== texture) {
|