将Three.js中的网格导出可以提高性能吗?

时间:2022-06-29 06:09:50

So I am working on a Three.js project and the program seems to lag in some places. Specifically, the most performance lag occurs when rendering the text Meshes I have created like so:

所以我正在开发一个Three.js项目,该程序似乎在某些地方滞后。具体来说,渲染我创建的文本网格时会发生最大的性能滞后:

var text1Geo = new THREE.TextGeometry("Hello", {font: font});
text1Mesh = new THREE.Mesh(text1Geo, textMaterial);
text1Mesh.position.set(-6500, 150, -500);
text1Mesh.castShadow = true;
scene.add(text1Mesh);

I am wondering if it would improve performance if I exported the text as an obj using the OBJExporter and then instead of creating a THREE.TextGeometry I could just load the mesh into the scene using an OBJLoader. Would this improve the performance. If you would like to see the entire project and source code please go here. Any other tips or advice on how to improve performance is much appreciated. Thanks!

我想知道如果我使用OBJExporter将文本导出为obj然后而不是创建THREE.TextGeometry我是否可以使用OBJLoader将网格加载到场景中,它是否会提高性能。这会改善性能吗?如果您想查看整个项目和源代码,请转到此处。关于如何提高性能的任何其他提示或建议非常感谢。谢谢!

1 个解决方案

#1


0  

No.

An experiment is still in order, but the answer is to cache the text geometry.

实验仍然有序,但答案是缓存文本几何。

Instead of having something like

而不是像

loadText( 'url.obj' , (t)=>{ /*...do stuff...*/});

you can have

你可以有

computeText(){ 
  var t = new THREE.TextGeometry();
  ...
}

computeText();
//...do stuff...

My assumption is that obj is unfriendly when it comes to parsing, but i might be wrong. A formatted json would perhaps be better, or binary.

我的假设是obj在解析时不友好,但我可能错了。格式化的json可能更好,或者二进制。

So, instead of downloading an .obj, parsing it, indexing, and then doing something, just compute it before you start rendering.

因此,不是下载.obj,解析它,索引,然后做某事,而是在开始渲染之前计算它。

You'd most likely experience lag nonetheless when this thing hits the gpu, be it computed or downloaded.

尽管如此,当这个东西击中gpu时,你很可能会遇到延迟,无论是计算还是下载。

#1


0  

No.

An experiment is still in order, but the answer is to cache the text geometry.

实验仍然有序,但答案是缓存文本几何。

Instead of having something like

而不是像

loadText( 'url.obj' , (t)=>{ /*...do stuff...*/});

you can have

你可以有

computeText(){ 
  var t = new THREE.TextGeometry();
  ...
}

computeText();
//...do stuff...

My assumption is that obj is unfriendly when it comes to parsing, but i might be wrong. A formatted json would perhaps be better, or binary.

我的假设是obj在解析时不友好,但我可能错了。格式化的json可能更好,或者二进制。

So, instead of downloading an .obj, parsing it, indexing, and then doing something, just compute it before you start rendering.

因此,不是下载.obj,解析它,索引,然后做某事,而是在开始渲染之前计算它。

You'd most likely experience lag nonetheless when this thing hits the gpu, be it computed or downloaded.

尽管如此,当这个东西击中gpu时,你很可能会遇到延迟,无论是计算还是下载。