setVerticesData() and getVerticesData() don’t allow any attributes to be set/get other than the limited, built-in kinds.
The typical solution I’ve seen on playgrounds is to make use of an unused kind, for example color, to set attributes that have nothing to do with color, making both the javascript and shader code less legible and more error prone IMO.
So here’s the javascript override code that I’ve been using in my projects, to allow creating new attributes that work with setVerticesData() and getVerticesData(), so that I’m not limited to the built in attribute kinds, for example when making a custom shader with ShaderMaterial.
Let me know if making a patch based on this solution or something similar sounds good and I’ll make a PR for it. For example, how about making _CustomStrides a private static member of VertexBuffer and making a static method called RegisterKind that accepts params kind and stride and uses them to set VertexBuffer._CustomStrides[kind] = stride, which would be used in a typescript version of the below DeduceStride function?
VertexBuffer.CustomStrides = {};
VertexBuffer.DeduceStride = function (kind) {
if (VertexBuffer.CustomStrides[kind]) {
return VertexBuffer.CustomStrides[kind];
}
// NOTE: BELOW IS THE EXACT SAME AS THE EXISTING METHOD
switch (kind) {
case VertexBuffer.UVKind:
case VertexBuffer.UV2Kind:
case VertexBuffer.UV3Kind:
case VertexBuffer.UV4Kind:
case VertexBuffer.UV5Kind:
case VertexBuffer.UV6Kind:
return 2;
case VertexBuffer.NormalKind:
case VertexBuffer.PositionKind:
return 3;
case VertexBuffer.ColorKind:
case VertexBuffer.MatricesIndicesKind:
case VertexBuffer.MatricesIndicesExtraKind:
case VertexBuffer.MatricesWeightsKind:
case VertexBuffer.MatricesWeightsExtraKind:
case VertexBuffer.TangentKind:
return 4;
default:
throw new Error("Invalid kind '" + kind + "'");
}
};