简体   繁体   中英

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

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?

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 );

} );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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