Jump to content

Mesh.setVerticesData() should accept custom vertex attributes (other than color, uv etc.)


Recommended Posts

Hello everyone!


Currently when I'm adding vertex attributes other than those specified in VertexBuffer (PositionKind etc.) via Mesh.setVerticesData(), it throws an error:

Uncaught (in promise) Error: Invalid kind 'test'


I think it would be useful to be able to add attributes of any kind. For example:

I have a terrain mesh with a custom shader that takes "color" (vec3) and "moisture, temperature" (vec2) vertex attributes.

It uses moisture and temperature to mix between 4 greyscale ground textures (wet and hot; dry and hot; wet and cold; dry and cold) and colorizes it.

Now I have two options:

- use UV2Kind, UV3Kind.. - it will work in this use case, but they are all vec2 and I may need a couple of vec3 in the future

- manually create a Buffer and attach it to the mesh via mesh.setVerticesBuffer() - I'm trying to figure out how to do it.

InstancedMesh is using setVerticesBuffer():


I'm unsure how to use it with a typical, non-instanced mesh. I would be very thankful for an example.

I wasn't sure whether to post in Bugs or Questions, please move the thread if you consider it more a question than a bug.


I figured out a way:

var vertexBuffer = new VertexBuffer(
this.engine, builtMesh.groundData, "test", false, false, 2);

But still, wouldn't it be more convenient with setVerticesData?

Link to comment
Share on other sites

I know why it didn't work..

I was calling it like this:

mesh.setVerticesData("test", builtMesh.groundData);

When it should be this:

mesh.setVerticesData("test", builtMesh.groundData, false, 2);

The stride must be specified, otherwise Babylon will try to deduce it and fail. Logical. My bad. Problem solved :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...