【问题标题】:stats.js shows FPS 0~2, render movement too slowstats.js 显示 FPS 0~2,渲染移动太慢
【发布时间】:2020-02-20 22:57:30
【问题描述】:

我是 three.js 的初学者,也将它用于 BIM 项目, 当我加载 ~25mbgltf 文件时,我几乎无法移动整个对象,并且 stats.js 监视器显示 fps 为 0~2 的最大值 gltf 文件:https://github.com/xeolabs/xeogl/tree/master/examples/models/gltf/schependomlaan 我使用 三个 jsvuejs

//package.json
"stats.js": "^0.17.0",
"three": "^0.109.0",

import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

this.scene = new THREE.Scene();

this.stats = new Stats();
this.stats.showPanel( 0, 1, 2 ); // 0: fps, 1: ms, 2: mb, 3+: custom
let div = document.createElement('div')
div.appendChild(this.stats.dom)

div.style.position = 'absolute';
div.style.top = 0;
div.style.left = 0;
document.getElementsByClassName('gltfViewer')[0].appendChild( div );
// Camera 
this.camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1500 );
this.camera.position.set( this.pos, this.pos, this.pos );
// renderer
this.raycaster = new THREE.Raycaster();
this.renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gltfViewerCanvas'), alpha: false });
this.renderer.setClearColor( 0xefefef );
this.renderer.setPixelRatio( window.devicePixelRatio );
this.renderer.setSize(window.innerWidth, window.innerHeight);
// adding controls

this.controls = new OrbitControls( this.camera, this.renderer.domElement );
this.controls.dampingFactor = 0.1;
this.controls.rotateSpeed = 0.12;
this.controls.enableDamping = true;
this.controls.update();

window.addEventListener('resize', _ => this.render());
this.controls.addEventListener('change', _ => this.render());

// light
var ambientLight = new THREE.AmbientLight( 0xcccccc );
this.scene.add( ambientLight );

var directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position.set( 0, 1, 1 ).normalize();
this.scene.add( directionalLight );
// loading gltf file

// Instantiate a loader
this.gltfLoader = new GLTFLoader();

// Optional: Provide a DRACOLoader instance to decode compressed mesh data
this.dracoLoader = new DRACOLoader();
this.dracoLoader.setDecoderPath( 'three/examples/js/libs/draco' );
this.gltfLoader.setDRACOLoader( this.dracoLoader );

// Load a glTF resource
this.gltfLoader.load( this.src, this.onGLTFLoaded, this.onGLTFLoading, this.onGLTFLoadingError );
//onGLTFLoaded()
this.scene.add( optimizedGltf.scene );
// gltf.scene.getObjectById(404).visible = false;
this.listGltfObjects(gltf);

this.render();
// render ()

this.renderer.render( this.scene, this.camera );
this.stats.update();
// on mounted component :
animate()
// animate() 
this.stats.begin()
this.render();
this.stats.end();

即使在使用 https://github.com/AnalyticalGraphicsInc/gltf-pipeline 应用 Draco 压缩之后,也没有任何变化。

谢谢

【问题讨论】:

  • window.addEventListener('resize', _ => this.render()); this.controls.addEventListener('change', _ => this.render()); 你不想要这个。每当您调整窗口大小或移动相机时,您都会强制渲染不同步。您不需要在这里强制渲染,只需设置一个动画循环,它应该会使事情变得更快。 three.js basic scene guide
  • 在尝试它确实上升到 1~4 fps 之后:/ 不多
  • 从提供的 sn-p 中,我无法说出任何其他会导致这种情况的直接事情,只是出于好奇,您能否使用包含动画循环函数和函数 @ 的代码编辑您的帖子987654327@?
  • 请注意,Draco 压缩会减少网络大小,但不会减少必须发送到 GPU 并渲染的最终未压缩数据量。如果您的原始网格是 100mb 并且您将其压缩到 25mb,您仍将获得原始 100mb 网格的帧速率。另外:使用 glTF-Pipeline 的 -b 选项将大小再减少 50%,降至 13MB,但同样不会影响 FPS。
  • 关于性能:该模型包含 4280 个网格,每个网格都需要 GPU 绘制调用。这就是你低 QPS 的根源。您需要将这些网格(在 Blender 之类的程序中,或在加载三个.js 后)合并到尽可能少的位置。像这样的模型应该需要

标签: vue.js three.js frame-rate gltf bim


【解决方案1】:

关于文件大小——

Draco 压缩会减少网络大小,但不会减少必须发送到 GPU 并渲染的最终未压缩数据量。如果您的原始网格是 100mb 并且您将其压缩到 25mb,您仍将获得原始 100mb 网格的帧速率。另外:使用 glTF-Pipeline 的 -b 选项会将大小再减少 50%,降至 13MB,但同样不会影响 FPS。

关于帧率——

此模型包含 4280 个网格1,每个网格都需要 GPU 绘制调用。这就是 QPS 低的根源,不幸的是,这是 BIM 模型中的常见问题。您需要将这些网格(在 Blender 之类的程序中,或在加载三个.js 后)合并到尽可能少的位置。像这样的模型应该需要

1 要查看此内容,请尝试在 https://gltf-viewer.donmccurdy.com/ 上打开模型并打开 JavaScript 控制台。您应该会看到场景图的打印输出,其中包含许多不同的网格。

【讨论】:

  • 感谢您向我解释,如果我要合并所有网格,我还能单独操作每个对象吗?比如选择一个窗口并获取它的属性?
  • 不幸的是,没有。为此,您可能需要使用 THREE.InstancedMesh 之类的东西,这需要更多的设置工作,但允许您单独移动对象。
  • 感谢您向我解释,如果您可以在threejs之后向我​​展示一些示例教程合并网格实例化对象?在测试了太多示例后我迷路了,但它没有用:/
  • @ElAlamiAnas 你解决了这个问题吗?你能分享你的代码或经验吗?
  • @NaveenKumarV 嗨,很抱歉迟到了,但我的问题中的代码是我所做的,还有问题是它是一个具有超过 12k 网格的 IFC 模型导致问题的原因,谢谢跨度>
猜你喜欢
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多