Skip to content

Commit 248a296

Browse files
deltakoshDavid Catuhe
and
David Catuhe
authored
Fix color affectation when dealing with color3 component (#16259)
Co-authored-by: David Catuhe <[email protected]>
1 parent 79d4f9c commit 248a296

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

.build/config.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"versionDefinition": "patch",
3-
"preid": "rc",
4-
"nonce": 335
5-
}
2+
"versionDefinition": "patch",
3+
"preid": "rc",
4+
"nonce": 336
5+
}

packages/dev/core/src/Meshes/geometry.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1042,21 +1042,27 @@ export class Geometry implements IGetSetVerticesData {
10421042
let stopChecking = false;
10431043
let kind;
10441044
for (kind in this._vertexBuffers) {
1045-
this.copyVerticesData(kind, vertexData as any);
1045+
const data = this.getVerticesData(kind);
1046+
if (data) {
1047+
if (data instanceof Float32Array) {
1048+
vertexData.set(new Float32Array(<Float32Array>data), kind);
1049+
} else {
1050+
vertexData.set((<number[]>data).slice(0), kind);
1051+
}
10461052

1047-
if (!stopChecking) {
1048-
const vb = this.getVertexBuffer(kind);
1053+
if (!stopChecking) {
1054+
const vb = this.getVertexBuffer(kind);
10491055

1050-
if (vb) {
1051-
updatable = vb.isUpdatable();
1052-
stopChecking = !updatable;
1056+
if (vb) {
1057+
updatable = vb.isUpdatable();
1058+
stopChecking = !updatable;
1059+
}
10531060
}
10541061
}
10551062
}
10561063

10571064
const geometry = new Geometry(id, this._scene, vertexData, updatable);
10581065

1059-
geometry._totalVertices = this._totalVertices;
10601066
geometry.delayLoadState = this.delayLoadState;
10611067
geometry.delayLoadingFile = this.delayLoadingFile;
10621068
geometry._delayLoadingFunction = this._delayLoadingFunction;

packages/dev/core/src/Meshes/mesh.vertexData.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface IGetSetVerticesData {
5050
* @param updatable defines if the vertex must be flagged as updatable (false as default)
5151
* @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified
5252
*/
53-
setVerticesData(kind: string, data: FloatArray, updatable: boolean): void;
53+
setVerticesData(kind: string, data: FloatArray, updatable: boolean, stride?: number): void;
5454
/**
5555
* Update a specific associated vertex buffer
5656
* @param kind defines which buffer to write to (positions, indices, normals, etc). Possible `kind` values :
@@ -470,7 +470,8 @@ export class VertexData implements IVertexDataLike {
470470
}
471471

472472
if (this.colors) {
473-
meshOrGeometry.setVerticesData(VertexBuffer.ColorKind, this.colors, updatable);
473+
const stride = this.positions && this.colors.length === this.positions!.length ? 3 : 4;
474+
meshOrGeometry.setVerticesData(VertexBuffer.ColorKind, this.colors, updatable, stride);
474475
if (this.hasVertexAlpha && (meshOrGeometry as any).hasVertexAlpha !== undefined) {
475476
(meshOrGeometry as any).hasVertexAlpha = true;
476477
}

0 commit comments

Comments
 (0)