Mesh Not Displaying with `setVerticesBuffer`, But Displays Correctly with `VertexData`

Problem Description:
I am encountering an issue while developing 3D graphics with Babylon.js. I attempted to set mesh vertex positions directly using the setVerticesBuffer method, but the mesh does not display. However, when I apply the same position data using a VertexData object, the mesh displays correctly. I would like to understand the potential reasons for this behavior and seek a resolution.

Attempted Solutions:

  1. I checked the shader for attribute and uniform variable settings to ensure nothing was missed.
  2. I tried using setVerticesBuffer for both color and position, but it seems the position data still isn’t being applied correctly.
  3. I made sure the updatable parameter of VertexBuffer is set to true to allow for potential future updates.

Relevant Code:

// Shader and material initialization code
Effect.ShadersStore[`coarsePathVertexShader`] = `
precision highp float;
attribute vec3 position;
attribute vec4 color;
uniform mat4 worldViewProjection;
uniform float size;
varying vec4 vColor;
void main() {
    gl_Position = worldViewProjection * vec4(position, 1.0);
    gl_PointSize = size;
    vColor = color;
}`;
// Method 1:
    // const positionsBuffer = new BABYLON.VertexBuffer(engine, points, "position", true, false, 3, false);
    // mesh.setVerticesBuffer(positionsBuffer);

//Method 2 :
    const vertexData = new BABYLON.VertexData();
    vertexData.positions = points;
    vertexData.applyToMesh(mesh, false);

Playground Example:
Please refer to my Babylon.js Playground example to see the specific manifestation of the issue: [Playground Link] (Playground)

Request for Help:
I am seeking guidance or suggestions from experienced developers to help resolve this issue. If you have encountered a similar problem or know of potential solutions, your feedback is greatly welcomed.

1 Like

you need convert mesh to flat shaded first like so,
mesh.convertToFlatShadedMesh();

I’m guessing there’s some shared data that’s indexed otherwise? idk, the PG below solves it. folks wiser than I will have to explain y tho

This is the way to unindex Babylon.js Playground

1 Like