Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backward compatibability for param kind to be "color" for thin instance methods #12433

Merged
merged 3 commits into from
Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions packages/dev/core/src/Meshes/thinInstanceMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -168,6 +173,11 @@ Mesh.prototype.thinInstanceSetMatrixAt = function (index: number, matrix: DeepIm
};

Mesh.prototype.thinInstanceSetAttributeAt = function (kind: string, index: number, value: Array<number>, refresh: boolean = true): boolean {
// preserve backward compatibility
if (kind === VertexBuffer.ColorKind) {
deltakosh marked this conversation as resolved.
Show resolved Hide resolved
kind = VertexBuffer.ColorInstanceKind;
}

if (!this._userThinInstanceBuffersStorage || !this._userThinInstanceBuffersStorage.data[kind] || index >= this._thinInstanceDataStorage.instancesCount) {
return false;
}
Expand Down Expand Up @@ -200,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++) {
Expand Down Expand Up @@ -273,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);
}
}
};

Expand All @@ -283,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);
}
}
};

Expand Down Expand Up @@ -345,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])) {
Expand Down