简体   繁体   English

A-Frame / THREE.js,在gltf [glb]模型上简化修饰符

[英]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 这里的三个简化修饰符中的一个示例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? 有没有办法用gltf模型做到这一点?

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: 是 - 请参阅完整代码的简化示例 ,但要点是您可以像往常一样使用SimplifyModifier,除非您需要遍历模型以防它包含多个网格:

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

} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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