本文介绍Threejs中物体(geometory)相关内容

threejs中常见几何体包括:平面体、立方体、圆、锥体、柱体、圆环、四面、八面、十二面缓冲、挤压缓冲体、形状缓冲几何体、圆环扭结、管道体等等

1. 空间的中的物体由一个个三维的点构成

  • 直接给点
const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( [
    -1.0, -1.0,  1.0, // v0
    1.0, -1.0,  1.0, // v1
    1.0,  1.0,  1.0, // v2

     1.0,  1.0,  1.0, // v3
    -1.0,  1.0,  1.0, // v4
    -1.0, -1.0,  1.0  // v5
] );

geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  • 索引给点
    const geometry = new THREE.BufferGeometry();
    const vertices = new Float32Array( [
        -1.0, -1.0,  1.0, // v0
        1.0, -1.0,  1.0, // v1
        1.0,  1.0,  1.0, // v2
    
        //  1.0,  1.0,  1.0, // v3
        -1.0,  1.0,  1.0, // v4
        // -1.0, -1.0,  1.0  // v5
    ] );
    
    geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
    const indexs = new Uint16Array(
    [
        0, 1,2,2, 3, 0
    ]
    )
    geometry.index = new THREE.BufferAttribute(indexs, 1)