Three.js中的点线面

1.点

3D空间中点用向量表示

THREE.Vector3 = function ( x, y, z ) {
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
};

||0表示在x没有定义是其默认值为

或者也可以

var point1 = new THREE.Vector3();

point1.set(4,8,9);

2.线

核心代码:

geometry.vertices.push(p1);

geometry.vertices.push(p2);

geometry.colors.push( color1, color2);

line1 = new THREE.Line( geometry, material, THREE.LinePieces );

scene.add(line1);

其中材质的定义为

var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );

表示按照两个顶点的颜色进行插值配色。

3.面

Threejs使用的是右手坐标系,这源于opengl默认情况下,也是右手坐标系。

在Threejs中,一条线由点,材质和颜色组成。

点由THREE.Vector3表示,Threejs中没有提供单独画点的函数,它必须被放到一个THREE.Geometry形状中,这个结构中包含一个数组vertices,这个vertices就是存放无数的点(THREE.Vector3)的数组。这个表示可以如下图所示:three.js向量


猜你喜欢

转载自blog.csdn.net/qq_32631151/article/details/80895505