Skip to content

Commit 6289b0b

Browse files
mvaligurskyMartin Valigursky
andauthored
[Fix] Drc loader example uses loaded colors correctly (playcanvas#3356)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 7e65888 commit 6289b0b

File tree

1 file changed

+12
-1
lines changed
  • examples/src/examples/loaders

1 file changed

+12
-1
lines changed

examples/src/examples/loaders/drc.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,22 @@ class LoadersGlExample extends Example {
6464
// @ts-ignore: cannot find CORE and DRACO
6565
const modelData = await CORE.load(url, DRACO.DracoLoader);
6666

67+
// loaded colors only contain RGB, convert it to an array of RGBA with alpha of 255
68+
const srcColors = modelData.attributes.COLOR_0.value;
69+
const numVertices = srcColors.length / modelData.attributes.COLOR_0.size;
70+
const colors32 = new Uint8Array(numVertices * 4);
71+
for (let i = 0; i < numVertices; i++) {
72+
colors32[i * 4 + 0] = srcColors[i * 3 + 0];
73+
colors32[i * 4 + 1] = srcColors[i * 3 + 1];
74+
colors32[i * 4 + 2] = srcColors[i * 3 + 2];
75+
colors32[i * 4 + 3] = 255;
76+
}
77+
6778
// based on the loaded data, create the mesh with position and color vertex data
6879
const mesh = new pc.Mesh(app.graphicsDevice);
6980
mesh.clear(true, false);
7081
mesh.setPositions(modelData.attributes.POSITION.value, modelData.attributes.POSITION.size);
71-
mesh.setColors32(modelData.attributes.COLOR_0.value, modelData.attributes.COLOR_0.size);
82+
mesh.setColors32(colors32);
7283
mesh.update(pc.PRIMITIVE_POINTS);
7384

7485
// Create shader to render mesh as circular points with color

0 commit comments

Comments
 (0)