A-Frame / THREE.js, Simplify modifier on gltf[glb] models

六月ゝ 毕业季﹏ 提交于 2020-01-15 10:34:30

问题


One of the examples in three simplify modifier found here https://github.com/mrdoob/three.js/blob/dev/examples/js/modifiers/SimplifyModifier.js

I understand it takes in a geometry, and simplifies it.

is there a way to do this with a gltf model?


回答1:


Yes — refer to the simplifier example for full code, but the gist is that you can use SimplifyModifier as usual, except that you need to traverse the model in case it contains multiple meshes:

var loader = new THREE.GLTFLoader();
loader.load( 'foo.glb', function ( gltf ) {

  var model = gltf.scene;
  var modifer = new THREE.SimplifyModifier();

  model.traverse( function ( o ) {

    if ( o.isMesh ) {

      var numVertices = o.geometry.attributes.position.count;
      o.geometry = modifer.modify( o.geometry, Math.floor( numVertices * 0.9375 ) );

    }

  } );

  scene.add( model );

}, undefined, function ( e ) {

  console.error( e );

} );


来源:https://stackoverflow.com/questions/52087673/a-frame-three-js-simplify-modifier-on-gltfglb-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!