I have exported a GLTF geometry in Blender with the 3 standard attributes:
Now I’m trying to add a custom one-dimensional attribute called “size” in the
[0, 1] range to do some custom GLSL shader stuff. Something akin to:
geometry.setAttribute( 'size', new THREE.BufferAttribute( sizeArray, 1 ) );
How can I export this custom attribute?
In Blender, I’ve used Vertex Weights (in a Vertex Group) to assign this one-dimensional attribute to each vertex, but I can’t find a way to export it.
(Red = 1, green = 0.5, blue = 0):
I’ve tried selecting “Include > Custom Properties”, but that gives me just a single
custom: 1 value, not a full
BufferAttribute. Is there a way to achieve this with GLTF? Also, can
THREE.GLTFLoader parse custom attributes?
THREE.GLTFLoader can parse custom attributes, but the Blender exporter can’t currently write them. See https://github.com/KhronosGroup/glTF-Blender-IO/pull/807 for a work-in-progress. You can test that with vertex colors, as documented there, but it doesn’t yet support vertex weights. That would probably be a good addition. Feedback welcome!
Bummer. I guess I could generate a second set of
UVs instead and just use the
U vector while ignoring the
V. Thanks, Don!
One other idea, you could use vertex colors — gltf supports any number of vertex color sets per mesh. Probably blender can put your weights into vertex colors with the python api, or you could hand paint them. Main downside being that they’ll be sRGB->linear decoded at export, so values will change a little.
Correct me if I’m wrong, but wouldn’t vertex colors provide me with a
vec3 attribute? I only need 1 dimension for “size”, so I’d be wasting 2 elements per vertex. Can vertex colors be exported in a single channel?
Correct — you’d have
vec3 with vertex colors,
vec2 with UVs, or
float with the (currently not exportable) vertex group weights.