当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Geometry.computeBoundingBox方法代码示例

本文整理汇总了TypeScript中THREE.Geometry.computeBoundingBox方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Geometry.computeBoundingBox方法的具体用法?TypeScript Geometry.computeBoundingBox怎么用?TypeScript Geometry.computeBoundingBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在THREE.Geometry的用法示例。


在下文中一共展示了Geometry.computeBoundingBox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function( value ) {

  const idx = geoPool.indexOf( value );
  if ( idx !== -1 ) {
    // 複数のmeshでthreejs geometryインスタンスを共有したい
    return geoCorePool[ idx ];
  } else {
    geoPool.push( value );
    let geometry;

    if ( value.type === "Buffer" ) {
      geometry = new THREE.BufferGeometry;
    } else if ( value.type === "Custom" ) {
      geometry = new THREE.Geometry;
      value.vertices.forEach( function( vec ) {
        geometry.vertices.push( new THREE.Vector3( vec[ 0 ], vec[ 1 ], vec[ 2 ] ) );
      });

      if ( value.faceVertexUvs ) {
        value.faceVertexUvs.forEach( function( faceVertexUv, i ) {
          geometry.faceVertexUvs[ i ] = geometry.faceVertexUvs[ i ] || [];
          faceVertexUv.forEach( function( uv ) {
            geometry.faceVertexUvs[ i ].push([
              new THREE.Vector2( uv[ 0 ][ 0 ], uv[ 0 ][ 1 ] ),
              new THREE.Vector2( uv[ 1 ][ 0 ], uv[ 1 ][ 1 ] ),
              new THREE.Vector2( uv[ 2 ][ 0 ], uv[ 2 ][ 1 ] ),
            ]);
          });
        });
      }

      if ( value.faces ) {
        value.faces.forEach( function( face ) {
          geometry.faces.push( new THREE.Face3(
            face[ 0 ],
            face[ 1 ],
            face[ 2 ],
            face[ 3 ] && new THREE.Vector3( face[ 3 ][ 0 ], face[ 3 ][ 1 ], face[ 3 ][ 2 ] ),
            face[ 4 ] && new THREE.Color( face[ 4 ] ),
            face[ 5 ]
          ));
        });

        if ( !value.faces[ 0 ][ 3 ] ) {
          geometry.computeFaceNormals();
          geometry.computeVertexNormals();
        }
      }

      geometry.computeBoundingBox();
      geometry.computeBoundingSphere();

    } else {
      geometry = new THREE[ value.type + "Geometry" ](
        value.value[ 0 ],
        value.value[ 1 ],
        value.value[ 2 ],
        value.value[ 3 ],
        value.value[ 4 ],
        value.value[ 5 ],
        value.value[ 6 ],
        value.value[ 7 ] );
    }

    if ( value.attrs ) {
      let tmp = value.attrs;
      let length = tmp.position.length / 3;
      let index = attrsPool.indexOf( tmp );

      if ( index !== -1 ) {
        geometry.attributes = attrsCorePool[ index ];
      } else {

        for ( let key in tmp ) {
          if ( key === "needsUpdate" ) {
            continue;
          }

          if ( key === "index" ) {
            geometry.setIndex( Array.isArray( tmp[ key ] ) ? new THREE.Uint16Attribute( tmp[ key ], 1 )
              : new THREE.BufferAttribute( tmp[ key ], 1 ) );
          } else {
            geometry.addAttribute( key, Array.isArray( tmp[ key ] ) ?
              new THREE.Float32Attribute( tmp[ key ], tmp[ key ].length / length )
                : new THREE.BufferAttribute( tmp[ key ], tmp[ key ].length / length ) );
          }
        }

        attrsPool.push( tmp );
        attrsCorePool.push( geometry.attributes );
        indexAttrsCorePool.push( geometry.getIndex() );

        Object.defineProperty( tmp, "needsUpdate", {
          get: function () {
            return attrsCorePool[ attrsPool.indexOf( this ) ].position.needsUpdate;
          },
          set: function ( bool ) {
            let index = attrsPool.indexOf( this );
            for ( let key in this ) {
              if ( key === "needsUpdate" ) {
//.........这里部分代码省略.........
开发者ID:amatelus,项目名称:solufa,代码行数:101,代码来源:createGeometry.ts


注:本文中的THREE.Geometry.computeBoundingBox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。