Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache scene in Three.js

PIXI.js has Container#cacheAsBitmap which causes the container to "render" itself to an image, save that, render the image instead of its children and when a child is added or removed or updated, the cache is updated.

What's the alternative for Three.js (but instead of an image it would be a mesh)?

like image 871
Lolums Avatar asked Dec 14 '25 14:12

Lolums


1 Answers

I may not be understanding your question properly, but your reply to Sabee's answer was helpful. It sounds like you're looking to either merge multiple geometries into a single mesh or implement a form of model instancing, with the goal of reducing draw calls.

There is more than one way to accomplish this, depending on your requirements. You can merge multiple geometries into a single geometry object, and provide either one material or an array of materials (where each index corresponds to one of the merged geometries). You can also use GPU-accelerated instancing to achieve a similar effect with only a single copy of the geometry.

I'll refer to Dusan Bosnjak's excellent Medium series on instancing, which starts here: https://medium.com/@pailhead011/instancing-with-three-js-36b4b62bc127

As well, here are the three.js examples regarding instancing: https://threejs.org/examples/?q=instanc#webgl_buffergeometry_instancing_dynamic

like image 148
dev.pat Avatar answered Dec 18 '25 09:12

dev.pat