Code Monkey home page Code Monkey logo

Comments (6)

gkjohnson avatar gkjohnson commented on May 16, 2024

@mquander Thoughts on how an NPM package should be structured?

What are your opinions on automatically binding to the THREE.js prototypes vs requiring explicit registration by the user? I figure that MeshBVH and MeshBVHVisualizer should be exported from the main package, as well.

from three-mesh-bvh.

mqp avatar mqp commented on May 16, 2024

Although Javascript culture doesn't line up perfectly with my beliefs, I strongly prefer being explicit and making it clear what's going on. I would expose the function you're using to override the prototype and expect people to write code like

import { MeshBVH } from 'threejs-fast-raycast';

// make BVH-enabled raycasting the default for every mesh with a bvh on its geometry
THREE.Mesh.prototype.raycast = MeshBVH.acceleratedRaycast;

// ...then:
const { bvh, index } = MeshBVH.buildTree(obj.mesh.geometry);
obj.mesh.geometry.bvh = bvh;
obj.mesh.geometry.setIndex(index);

I specifically prefer the BVH storage on the geometry and the index-swapping to be visible to programmers, because those are big chunks of memory that they should be clearly aware of and ready to dispose of if they cease to become useful. I think if programmers don't have a mental model of what the BVH computation is producing and what happens to it, they will make more mistakes.

(I'm actually not even happy with how "magical" MeshBVH.acceleratedRaycast is but I don't have a confident suggestion of how to improve it, given the existing three.js raycast infrastructure.)

from three-mesh-bvh.

gkjohnson avatar gkjohnson commented on May 16, 2024

I agree -- I'll think about how to update the API when I get a chance

from three-mesh-bvh.

gkjohnson avatar gkjohnson commented on May 16, 2024

@mquander Okay what do you think -- are we ready for a first publish to NPM?

from three-mesh-bvh.

mqp avatar mqp commented on May 16, 2024

My only complaint is that I don't really like computeBoundsTree and disposeBoundsTree as an API -- I would remove them. I can understand if you don't want to, though.

Other than that, I see no reason not to publish.

from three-mesh-bvh.

gkjohnson avatar gkjohnson commented on May 16, 2024

Okay I think I'll publish as-is for now and we can re-evaluate the API in a future release.

from three-mesh-bvh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.