I’ve spent some time attempting make LineSegments follow a skinned mesh, so that my rigged object can have EdgeGeometry. To little avail, because there is quite a lot of stuff that goes on in the engine that decides which uniforms to attach and which shader chunk becomes active with certain attribute combinations. I’m sure there is a way to get it working with carefully crafted ShaderMaterials and by extending the LineSegments class, but I haven’t managed that yet. Please don’t read that as a complaint.
Then I came up with this:
import _ from 'lodash';
import { BufferGeometry, LineBasicMaterial, Skeleton, SkinnedMesh } from 'three';
export class SkinnedLineSegments extends SkinnedMesh {
isLine = true;
isLineSegments = true;
constructor(geometry: BufferGeometry, skeleton: Skeleton) {
const material = new LineBasicMaterial({ transparent: true, color: 0x000000 });
super(geometry, material);
_.set(this, 'isMesh', false);
this.skeleton = skeleton;
}
}
And shockingly: it just works. I’m not happy about it, because I’m forcefully overwriting a read only attribute, essentially gaslighting a Mesh in to believing it is a Line. And that’s why I’m here. I’m in need of absolution that this is an acceptable solution to the problem. Essentially three lines of code is so tempting… I do see that this is messing with engine internals and thus probably isn’t future proof… Any better ideas, please?