Skip to content

Latest commit

 

History

History
62 lines (38 loc) · 1.88 KB

几何体.md

File metadata and controls

62 lines (38 loc) · 1.88 KB

基础几何体

THREE.Geometry() //几何体基类

THREE.BoxGeometry() //立方体

THREE.PlaneGeometry() //平面、地面

THREE.SphereGeometry() //球体

THREE.CylinderGeometry() //圆柱体

更加自由的几何体

THREE.BufferGeometry() //带有缓存区的几何体,自由度最高的geometry类型

可以自由指定每个顶点的位置、颜色、法线(影响光照),将顶点位置数组、顶点颜色数组等放到一个缓存区中,以加快加载和运行速度。

也比THREE.Geometry() 要复杂许多。

法向量是垂直于面的

geometry里的faces比较重要,是几何体的基础,数据结构是一个数组,3个点组成一个面,存储的是顶点的索引值

	var geometry = new THREE.Geometry();
    var material = new THREE.MeshBasicMaterial({ vertexColors:THREE.VertexColors, side:THREE.DoubleSide});

    //vertexs
    var p1 = new THREE.Vector3( -100, 0, 0 );
    var p2 = new THREE.Vector3(  100, 0, 0 );
    var p3 = new THREE.Vector3(  0, 100, 0 );

    //colors
    var color1 = new THREE.Color(0xff0000);
    var color2 = new THREE.Color(0x00ff00);
    var color3 = new THREE.Color(0x0000ff);

    geometry.vertices.push(p1);
    geometry.vertices.push(p2);
    geometry.vertices.push(p3);

    //geometry.colors.push( color1, color2, color1 );
    var face = new THREE.Face3( 0, 2, 1);//面是逆时针画点, 0 2 1 绘制的就是反面, 0 1 2 绘制的正面,是否双面绘制需要设置材质的side:THREE.DoubleSide

    face.vertexColors[ 0 ] = color1;
    face.vertexColors[ 1 ] = color2;
    face.vertexColors[ 2 ] = color3;

    geometry.faces.push(  face);

    var mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);

模型的正面和反面

因为是右手坐标系,逆时针是正面,顺时针是反面。

这里的正反面与物体前面和后面不是一个概念