Open spite opened 8 years ago
What about just rename to : LineGeometry, keep MeshLineMaterial and not encapsulate the Mesh functionality ?
I'm actually working with it and use differents custom LineGeometry / MeshLineMaterial to realize various effects, create a normal Three.Mesh feel natural & more flexible.
Also on a bit different topics but still in the refractoring, MeshLine/LineGeometry can have directly the "points", functionWidth in his constructor to get more friendly.
I think MeshLine is too different from Mesh to be able to work interchangeably. It does a series of operations a set some uniforms/attributes that are specific to it.
Do you have an example of what you propose?
It's a bit late (or very late). But due to an oversight, I reimplemented a version of MeshLine with the idea of keeping as close to the THREE.js's pattern of "create object, add it to scene, changes are updated nearly automatically". So the pattern I use might be a good example for use. THREE.MeshLineAlt (funny story, I actually started out that project without knowing yours exists, and managed to use the exact same naming as yours). Overall, my implementation go through the following.
The THREE.MeshLine object, once populated with at least a THREE.Geometry, can be added directly to the THREE.js's scene object, and changes to geometry object will reflect in the viewer. This is accomplished (albeit currently in a fairly inefficient manner of reconstructing the attribute buffer each time) by the following.
A. For the object (in our exapmle, THREE.MeshLine), check if the geometry is a THREE.Geometry (if it's a THREE.BufferGeometry instead, it doesn't do any update and use it as is, hence when my version cannot take a THREE.BufferGeometry).
B. If it's a THREE.Geometry, check if it has _bufferGeometry set. If not, set _bufferGeometry to a new THREE.BufferGeometry (the setting of _bufferGeometry in 2 is meant to bypass this, so three.js don't use the default BufferGeometry for it).
C. Given the _bufferGeometry, invoke updateFromObject (the one THREE.BufferMeshLineGeometry overrides).
Yes, I know. Originally it was supposed to encapsulate all the features of a THREE.Mesh with its own geometry and attributes, but it got complicated. Next refactor should have a proper THREE.Mesh as result.