• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript THREE.BufferGeometry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中THREE.BufferGeometry的典型用法代码示例。如果您正苦于以下问题:TypeScript BufferGeometry类的具体用法?TypeScript BufferGeometry怎么用?TypeScript BufferGeometry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: default

export default ( value ) => {

    if ( value.type === "Buffer" ) {
      const geometry = new THREE.BufferGeometry;
      for ( let key in value.attrs ) {
        if ( key ) { // if使わないとlintに怒られる
          geometry.addAttribute( key, new THREE.BufferAttribute( new Float32Array( value.attrs[ key ] ),
            key === "index" ? 1 : key === "uv" ? 2 : 3 ) );
        }
      }


      return geometry;
    } else {
      const 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.faceVertexUvs ) {
        value.faceVertexUvs.forEach( ( array, i0 ) => {
          geometry.faceVertexUvs[ i0 ] = geometry.faceVertexUvs[ i0 ] || [];
          array.forEach( ( uvs, i1 ) => {
            geometry.faceVertexUvs[ i0 ][ i1 ] = geometry.faceVertexUvs[ i0 ][ i1 ] || [];
            uvs.forEach( ( uv, i2 ) => {
                geometry.faceVertexUvs[ i0 ][ i1 ][ i2 ] = new THREE.Vector2( uv[ 0 ], uv[ 1 ] );
            });
          });
        });
      }*/

      if ( value.attrs ) {
        for ( let key in value.attrs ) {
          if ( key ) {
            geometry.addAttribute( key, new THREE.BufferAttribute( new Float32Array( value.attrs[ key ] ),
              key === "index" ? 1 : key === "uv" ? 2 : 3 ) );
          }
        }
      }

      return geometry;
    }
};
开发者ID:luca3104,项目名称:solufa,代码行数:48,代码来源:createGeometry.ts


示例2: _addMesh

    private _addMesh(tag: Tag): void {
        let geometry: THREE.BufferGeometry = new THREE.BufferGeometry();

        let polygonPoints2d: number[][] = tag.polygonPoints2d;

        let sides: number = polygonPoints2d.length - 1;
        let sections: number = 8;

        let positions: Float32Array = new Float32Array(sides * sections * 3);

        for (let i: number = 0; i < sides; ++i) {
            let startX: number = polygonPoints2d[i][0];
            let startY: number = polygonPoints2d[i][1];

            let endX: number = polygonPoints2d[i + 1][0];
            let endY: number = polygonPoints2d[i + 1][1];

            let intervalX: number = (endX - startX) / (sections - 1);
            let intervalY: number = (endY - startY) / (sections - 1);

            for (let j: number = 0; j < sections; ++j) {
                let rectPosition: number[] = [
                    startX + j * intervalX,
                    startY + j * intervalY,
                ];

                let position: number[] = tag.getPoint3d(rectPosition[0], rectPosition[1]);
                let index: number = 3 * sections * i + 3 * j;

                positions[index] = position[0];
                positions[index + 1] = position[1];
                positions[index + 2] = position[2];
            }
        }

        geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));

        let material: THREE.LineBasicMaterial = new THREE.LineBasicMaterial({ color: 0x00FF00, linewidth: 1 } );
        let line: THREE.Line = new THREE.Line(geometry, material);

        this._meshes[tag.id] = line;
        this._scene.add(line);
    }
开发者ID:BogusCurry,项目名称:mapillary-js,代码行数:43,代码来源:TagGLRenderer.ts


示例3: _getImageSphereGeo

    private _getImageSphereGeo(transform: Transform, node: Node): THREE.BufferGeometry {
        let t: THREE.Matrix4 = new THREE.Matrix4().getInverse(transform.srt);

        // push everything at least 5 meters in front of the camera
        let minZ: number = 5.0 * transform.scale;
        let maxZ: number = this._imageSphereRadius * transform.scale;

        let vertices: number[] = node.mesh.vertices;
        let numVertices: number = vertices.length / 3;
        let positions: Float32Array = new Float32Array(vertices.length);
        for (let i: number = 0; i < numVertices; ++i) {
            let index: number = 3 * i;
            let x: number = vertices[index + 0];
            let y: number = vertices[index + 1];
            let z: number = vertices[index + 2];

            let l: number = Math.sqrt(x * x + y * y + z * z);
            let boundedL: number = Math.max(minZ, Math.min(l, maxZ));
            let factor: number = boundedL / l;
            let p: THREE.Vector3 = new THREE.Vector3(x * factor, y * factor, z * factor);

            p.applyMatrix4(t);

            positions[index + 0] = p.x;
            positions[index + 1] = p.y;
            positions[index + 2] = p.z;
        }

        let faces: number[] = node.mesh.faces;
        let indices: Uint16Array = new Uint16Array(faces.length);
        for (let i: number = 0; i < faces.length; ++i) {
            indices[i] = faces[i];
        }

        let geometry: THREE.BufferGeometry = new THREE.BufferGeometry();

        geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
        geometry.setIndex(new THREE.BufferAttribute(indices, 1));

        return geometry;
    }
开发者ID:Caboosey,项目名称:mapillary-js,代码行数:41,代码来源:ImagePlaneFactory.ts


示例4: _getFlatImagePlaneGeo

    private _getFlatImagePlaneGeo(transform: Transform): THREE.BufferGeometry {
        let width: number = transform.width;
        let height: number = transform.height;
        let size: number = Math.max(width, height);
        let dx: number = width / 2.0 / size;
        let dy: number = height / 2.0 / size;

        let vertices: THREE.Vector3[] = [];
        vertices.push(transform.pixelToVertex(-dx, -dy, this._imagePlaneDepth));
        vertices.push(transform.pixelToVertex( dx, -dy, this._imagePlaneDepth));
        vertices.push(transform.pixelToVertex( dx, dy, this._imagePlaneDepth));
        vertices.push(transform.pixelToVertex(-dx, dy, this._imagePlaneDepth));

        let positions: Float32Array = new Float32Array(12);
        for (let i: number = 0; i < vertices.length; i++) {
            let index: number = 3 * i;
            positions[index + 0] = vertices[i].x;
            positions[index + 1] = vertices[i].y;
            positions[index + 2] = vertices[i].z;
        }

        let indices: Uint16Array = new Uint16Array(6);
        indices[0] = 0;
        indices[1] = 1;
        indices[2] = 3;
        indices[3] = 1;
        indices[4] = 2;
        indices[5] = 3;

        let geometry: THREE.BufferGeometry = new THREE.BufferGeometry();

        geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
        geometry.setIndex(new THREE.BufferAttribute(indices, 1));

        return geometry;
    }
开发者ID:Caboosey,项目名称:mapillary-js,代码行数:36,代码来源:ImagePlaneFactory.ts


示例5: function


//.........这里部分代码省略.........
          throw new Error("Unexpected vertex/normal/uv line: '" + line + "'")
        }
      } else if (lineFirstChar === 'f') {
        if ((result = this.regexp.face_vertex_uv_normal.exec(line)) !== null) {
          // f vertex/uv/normal vertex/uv/normal vertex/uv/normal
          // 0                        1    2    3    4    5    6    7    8    9   10         11         12
          // ["f 1/1/1 2/2/2 3/3/3", "1", "1", "1", "2", "2", "2", "3", "3", "3", undefined, undefined, undefined]

          state.addFace(
            result[ 1 ], result[ 4 ], result[ 7 ], result[ 10 ],
            // result[ 2 ], result[ 5 ], result[ 8 ], result[ 11 ],  // ignore uv part
            result[ 3 ], result[ 6 ], result[ 9 ], result[ 12 ]
          )
        } else if (this.regexp.face_vertex_uv.exec(line) !== null) {

          // ignore uv line

        } else if ((result = this.regexp.face_vertex_normal.exec(line)) !== null) {
          // f vertex//normal vertex//normal vertex//normal
          // 0                     1    2    3    4    5    6   7          8
          // ["f 1//1 2//2 3//3", "1", "1", "2", "2", "3", "3", undefined, undefined]

          state.addFace(
            result[ 1 ], result[ 3 ], result[ 5 ], result[ 7 ],
            result[ 2 ], result[ 4 ], result[ 6 ], result[ 8 ]
          )
        } else if ((result = this.regexp.face_vertex.exec(line)) !== null) {
          // f vertex vertex vertex
          // 0            1    2    3   4
          // ["f 1 2 3", "1", "2", "3", undefined]

          state.addFace(
            result[ 1 ], result[ 2 ], result[ 3 ], result[ 4 ]
          )
        } else {
          throw new Error("Unexpected face line: '" + line + "'")
        }
      } else if (lineFirstChar === 'l') {
        var lineParts = line.substring(1).trim().split(' ')
        var lineVertices = []
        var lineUVs = []

        if (line.indexOf('/') === -1) {
          lineVertices = lineParts
        } else {
          for (var li = 0, llen = lineParts.length; li < llen; li++) {
            var parts = lineParts[ li ].split('/')

            if (parts[ 0 ] !== '') lineVertices.push(parts[ 0 ])
            if (parts[ 1 ] !== '') lineUVs.push(parts[ 1 ])
          }
        }
        state.addLineGeometry(lineVertices, lineUVs)
      } else if ((result = this.regexp.object_pattern.exec(line)) !== null) {
        // o object_name
        // or
        // g group_name

        var name = result[ 0 ].substr(1).trim()
        state.startObject(name)

        // ignore material related lines
        // eslint-disable-next-line no-empty
      } else if (this.regexp.material_use_pattern.test(line)) {
        // eslint-disable-next-line no-empty
      } else if (this.regexp.material_library_pattern.test(line)) {
        // eslint-disable-next-line no-empty
      } else if (this.regexp.smoothing_pattern.exec(line) !== null) {
      } else {
        // Handle null terminated files without exception
        if (line === '\0') continue

        throw new Error("Unexpected line: '" + line + "'")
      }
    }

    var container = []

    for (i = 0, l = state.objects.length; i < l; i++) {
      var object = state.objects[ i ]
      var geometry = object.geometry

      // Skip o/g line declarations that did not follow with any faces
      if (geometry.vertices.length === 0) continue

      var buffergeometry = new BufferGeometry()

      buffergeometry.addAttribute('position', new BufferAttribute(new Float32Array(geometry.vertices), 3))

      if (geometry.normals.length > 0) {
        buffergeometry.addAttribute('normal', new BufferAttribute(new Float32Array(geometry.normals), 3))
      } else {
        buffergeometry.computeVertexNormals()
      }

      container.push(buffergeometry)
    }

    return container
  }
开发者ID:arose,项目名称:ngl,代码行数:101,代码来源:obj-parser.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript THREE.Color类代码示例发布时间:2022-05-25
下一篇:
TypeScript THREE.Box3类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap