简体   繁体   English

Three.js 中的缓存场景

[英]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. PIXI.js 具有Container#cacheAsBitmap ,它使容器将自身“渲染”为图像,保存,渲染图像而不是其子级,并且当添加或删除或更新子级时,缓存会更新。

What's the alternative for Three.js (but instead of an image it would be a mesh)? Three.js 的替代方案是什么(但它不是图像,而是网格)?

I may not be understanding your question properly, but your reply to Sabee's answer was helpful.我可能没有正确理解您的问题,但您对 Sabee 回答的回复很有帮助。 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.您还可以使用 GPU 加速的实例化仅使用几何体的一个副本来实现类似的效果。

I'll refer to Dusan Bosnjak's excellent Medium series on instancing, which starts here: https://medium.com/@pailhead011/instancing-with-three-js-36b4b62bc127我将参考 Dusan Bosnjak 关于实例化的优秀 Medium 系列,从这里开始: 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同样,以下是有关实例化的three.js 示例: https ://threejs.org/examples/?q = instanc#webgl_buffergeometry_instancing_dynamic

Pixi.js is a 2D javascript library, using WebGL to render the images(frames) into html5 canvas. Pixi.js 是一个 2D javascript 库,使用 WebGL 将图像(帧)渲染到 html5 画布中。 Three.js allows the creation of Graphical Processing Unit (GPU)-accelerated 3D animations using WebGL. Three.js 允许使用 WebGL 创建图形处理单元 (GPU) 加速的 3D 动画。 The browser cannot store rendered 3D frames, this work allows the GPU Accelerated Render Cache, which depends on what hardware's they run.浏览器无法存储渲染的 3D 帧,这项工作允许 GPU 加速渲染缓存,这取决于它们运行的​​硬件。 Helpful post understanding what's going on behind the scenes. 有用的帖子了解幕后发生的事情。

But you can cahce your assets in browser like images, json objects of 3D models and etc. In Three.js Cache class is a global object, used by assets loaders (TextureLoader, ImageLoader, AudioLoader ...), by default is disabled ( false ).但是您可以在浏览器中缓存您的资产,如图像、3D 模型的 json 对象等。在 Three.js Cache 类是一个全局对象,由资产加载器(TextureLoader、ImageLoader、AudioLoader ...)使用,默认情况下是禁用的( false )。 To enable it you can set THREE.Cache.enabled = true ;要启用它,您可以设置THREE.Cache.enabled = true ;

I think by default the browser should cache the textures for performance reasons, but if you want to be sure simply enable the cache by force code it in Three.js.我认为默认情况下浏览器应该出于性能原因缓存纹理,但如果您想确保只需通过在 Three.js 中强制编码来启用缓存。 Also the creator of Three.js answered this question . Three.js 的创建者也回答了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM