spite / THREE.MeshLine

Mesh replacement for THREE.Line
MIT License
2.13k stars 379 forks source link

Is there a reason MeshLine does not inherit from Geometry? #78

Open drcmda opened 5 years ago

drcmda commented 5 years ago

I have to admit i am new to this fantastic lib, but i don't understand why MeshLine has to be a factory class, from the docs it seems like we are supposed to do line.geometry in order to work with it. Couldn't it straight inherit from BufferGeometry instead as well as letting us pass point data via constructor? So that we could do:

const geo = new THREE.MeshLineGeometry(points)
const mat = new THREE.MeshLineMaterial({...})
const mesh = new THREE.Mesh(geo, mat)

I am writing a lib that's supposed to remove imperative object handling in three, and it works well with most datatypes, but the oop stuff in MeshLine is throwing a wrench into it, forcing the user to go out of the declarative, see: https://codesandbox.io/s/kky7yk087v

trusktr commented 4 years ago

It totally could be like that. Not sure why it isn't. Most likely it was simply some imperative code somewhere before being published, and it was easy to just stick it in a class while not modifying the implementation much.

drcmda commented 4 years ago

Ryan King has made this: https://github.com/ryanking1809/three-line-raycast

This allows you to use THREE's own Line2 and LineSegments2 with full raycasting just by dropping it in.

I like it best so far and it can be fully declarative: https://codesandbox.io/s/react-three-fiber-sharper-threejs-qci13 👍