【发布时间】:2020-02-20 22:57:30
【问题描述】:
我是 three.js 的初学者,也将它用于 BIM 项目, 当我加载 ~25mb 的 gltf 文件时,我几乎无法移动整个对象,并且 stats.js 监视器显示 fps 为 0~2 的最大值 gltf 文件:https://github.com/xeolabs/xeogl/tree/master/examples/models/gltf/schependomlaan 我使用 三个 js 和 vuejs
//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