three-mesh-bvh icon indicating copy to clipboard operation
three-mesh-bvh copied to clipboard

This error will occur when creating bvh using the geometry of a relatively large file.

Open Sea-DH1 opened this issue 9 months ago • 5 comments

Describe the bug

I have a large stl file, more than 1GB in total, and when using computeBoundsTree, I get this error 123

Here is the line of code in bvh that prompts the error image

Can load files without using bvh. This is the file information. image

Sea-DH1 avatar May 10 '24 16:05 Sea-DH1

With over 260 million float elements for both the position and normal buffers you're model is over 2GB in memory - that's just about at the memory cap for most desktop browser tabs. There's not a lot this project can do if there's no browser memory left and it crashes on a buffer allocation.

Depending on your use case you can artificially increase the memory cap with command line flags and preprocess the model BVH to save to disk before loading it so it doesn't have to be generated on load.

gkjohnson avatar May 10 '24 23:05 gkjohnson

Hello, how to preprocess the model BVH?

Sea-DH1 avatar May 11 '24 03:05 Sea-DH1

Hello, how to preprocess the model BVH?

There's no prebuilt tool for this so you'll have to implement the file storage and loading yourself. But the basic process would be:

  • Generate the BVH offline using something like Node or Puppeteer with a higher memory cap
  • Use the serialize to get a minimal, serialized version of the bvh and associated buffers.
  • Save the data and buffers in an optimal way (ie don't just JSON stringify because the typed arrays will be expanded to arrays)
  • Load the bvh file into the browser, read it into an object shaped the same as the originally serialized version.
  • Deserialize the BVH using the deserialize function.

gkjohnson avatar May 11 '24 03:05 gkjohnson

When using Serialization and Deserialization, an error will be reported when intersectsGeometry, indirect is true

This is a demo demo

Sea-DH1 avatar May 13 '24 17:05 Sea-DH1

Thanks for the easy repro. Just fixed the issue in #664 - it'll be available in the next release.

gkjohnson avatar May 14 '24 10:05 gkjohnson