PCS and SPS (digest) always take 1st UV slot irrespective of texture

Hi everyone,

I cannot build a PCS/SPS with a different UV set (i.e. Texture.coordinatesIndex to VertexBuffer.UVKind / UV2Kind, etc.). Babylon always picks UVKind - other kinds not evaluated. Therefore, in my case, PCS/SPS meshes become black.

Only solution I could think of was to override the PCS and SPS classes. But this is difficult to maintain because the methods you have to override are quite large :frowning:

Current changes that seem to work fine:


//L224 (++; last param)
protected _setPointsColorOrUV(mesh, pointsGroup, isVolume: boolean, colorFromTexture?: boolean, hasTexture?: boolean, color?, range?: number, uvSetIndex: 1|2|3|4=1) {

//L234 (++)
const UVKind = uvSetIndex === 2 ? VertexBuffer.UV2Kind :
               uvSetIndex === 3 ? VertexBuffer.UV3Kind :
               uvSetIndex === 4 ? VertexBuffer.UV4Kind :
const meshUV = mesh.getVerticesData(UVKind);

protected _colorFromTexture(mesh, pointsGroup, isVolume: boolean): void {

//L511 (++)
  const uvSetIndex = textureList[n].coordinatesIndex;
  this._setPointsColorOrUV(clone, pointsGroup, isVolume, true, true, undefined, undefined, uvSetIndex);



function todo {}
// but probably only adding selection logic to L348 from mesh.material

Best wishes


You’re right, it’s a bug, here’s the PR that fixes it:

1 Like

@Evgeni_Popov Sorry to bother you again but I think the same issue exists in the SolidParticleSystem within the digest()-method (https://github.com/BabylonJS/Babylon.js/blob/0097ddea184b18d05e6217bc7bda1beebf3ab63a/packages/dev/core/src/Particles/solidParticleSystem.ts#L348).

The fix should roughly be the same (https://playground.babylonjs.com/#WLDCUC#206). But, in the playground, see line 170. You might be required to clone the source material instead of just assigning it. Not sure if this can be handled on the SPS side for the user?

Thanks for reporting, here’s the PR:

This time I don’t consider it to be a bug because the SPS does not/can’t assume that you are going to assign the same material than the one used by the mesh you passed to the digest method.

You could call digest several times with different meshes, and if some materials use uv set 0 and others use uv set 1 for the diffuse texture, then you will have to create a specific material for this SPS mesh, the SPS can’t automatically create a material suitable for the mesh. So, I consider it’s the user responsibility to create (if necessary) the material used by the SPS mesh.

That’s why you will have to explicitely enable this mode by passing uvKind: -1 through the options when calling digest: