From 1d1de0c47c173466fdb2714d83528d0c4c1498e1 Mon Sep 17 00:00:00 2001 From: BlakeOne <30273164+BlakeOne@users.noreply.github.com> Date: Sun, 24 Apr 2022 22:02:13 -0700 Subject: [PATCH 1/2] Fix thinInstanceSetAttributeAt to work with "color" kind --- packages/dev/core/src/Meshes/thinInstanceMesh.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/dev/core/src/Meshes/thinInstanceMesh.ts b/packages/dev/core/src/Meshes/thinInstanceMesh.ts index d1666e2b41c..d67d55e3870 100644 --- a/packages/dev/core/src/Meshes/thinInstanceMesh.ts +++ b/packages/dev/core/src/Meshes/thinInstanceMesh.ts @@ -168,6 +168,10 @@ Mesh.prototype.thinInstanceSetMatrixAt = function (index: number, matrix: DeepIm }; Mesh.prototype.thinInstanceSetAttributeAt = function (kind: string, index: number, value: Array, refresh: boolean = true): boolean { + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + if (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.data[kind] || index >= this._thinInstanceDataStorage.instancesCount) { return false; } From cc3abb5384486b829a40ea82754c38c5c214af3c Mon Sep 17 00:00:00 2001 From: BlakeOne <30273164+BlakeOne@users.noreply.github.com> Date: Wed, 27 Apr 2022 14:54:55 -0700 Subject: [PATCH 2/2] Update thinInstanceMesh.ts --- .../dev/core/src/Meshes/thinInstanceMesh.ts | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/dev/core/src/Meshes/thinInstanceMesh.ts b/packages/dev/core/src/Meshes/thinInstanceMesh.ts index 7abda5bff5e..15cdee49281 100644 --- a/packages/dev/core/src/Meshes/thinInstanceMesh.ts +++ b/packages/dev/core/src/Meshes/thinInstanceMesh.ts @@ -131,6 +131,11 @@ Mesh.prototype.thinInstanceAddSelf = function (refresh: boolean = true): number }; Mesh.prototype.thinInstanceRegisterAttribute = function (kind: string, stride: number): void { + // preserve backward compatibility + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + this.removeVerticesData(kind); this._thinInstanceInitializeUserStorage(); @@ -168,6 +173,7 @@ Mesh.prototype.thinInstanceSetMatrixAt = function (index: number, matrix: DeepIm }; Mesh.prototype.thinInstanceSetAttributeAt = function (kind: string, index: number, value: Array, refresh: boolean = true): boolean { + // preserve backward compatibility if (kind === VertexBuffer.ColorKind) { kind = VertexBuffer.ColorInstanceKind; } @@ -204,6 +210,11 @@ Object.defineProperty(Mesh.prototype, "thinInstanceCount", { }); Mesh.prototype._thinInstanceCreateMatrixBuffer = function (kind: string, buffer: Float32Array, staticBuffer: boolean = false): Buffer { + // preserve backward compatibility + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + const matrixBuffer = new Buffer(this.getEngine(), buffer, !staticBuffer, 16, false, true); for (let i = 0; i < 4; i++) { @@ -277,8 +288,15 @@ Mesh.prototype.thinInstanceBufferUpdated = function (kind: string): void { this._thinInstanceDataStorage.matrixBuffer?.updateDirectly(this._thinInstanceDataStorage.matrixData!, 0, this._thinInstanceDataStorage.instancesCount); } else if (kind === "previousMatrix") { this._thinInstanceDataStorage.previousMatrixBuffer?.updateDirectly(this._thinInstanceDataStorage.previousMatrixData!, 0, this._thinInstanceDataStorage.instancesCount); - } else if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) { - this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(this._userThinInstanceBuffersStorage.data[kind], 0); + } else { + // preserve backward compatibility + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + + if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) { + this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(this._userThinInstanceBuffersStorage.data[kind], 0); + } } }; @@ -287,8 +305,15 @@ Mesh.prototype.thinInstancePartialBufferUpdate = function (kind: string, data: F if (this._thinInstanceDataStorage.matrixBuffer) { this._thinInstanceDataStorage.matrixBuffer.updateDirectly(data, offset); } - } else if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) { - this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(data, offset); + } else { + // preserve backward compatibility + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + + if (this._userThinInstanceBuffersStorage?.vertexBuffers[kind]) { + this._userThinInstanceBuffersStorage.vertexBuffers[kind]!.updateDirectly(data, offset); + } } }; @@ -349,6 +374,11 @@ Mesh.prototype.thinInstanceRefreshBoundingInfo = function (forceRefreshParentInf }; Mesh.prototype._thinInstanceUpdateBufferSize = function (kind: string, numInstances: number = 1) { + // preserve backward compatibility + if (kind === VertexBuffer.ColorKind) { + kind = VertexBuffer.ColorInstanceKind; + } + const kindIsMatrix = kind === "matrix"; if (!kindIsMatrix && (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.strides[kind])) {