案例:Three 顶点颜色     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
  <meta charset="UTF-8">
5
  <style>
6
    body {
7
      margin: 0;
8
      overflow: hidden;
9
      /* 隐藏body窗口区域滚动条 */
10
    }
11
  </style>
12
  <!--引入three.js三维引擎-->
13
  <script src="/js/threejs/threer92.js"></script>
14
  <script src="/example/threejs/solarsystem/files/OrbitControls.js"></script>
15
</head>
16
17
<body>
18
  <script>
19
    //创建场景
20
    var scene = new THREE.Scene();
21
22
    //创建一个Buffer类型几何体对象
23
    var geometry = new THREE.BufferGeometry();
24
    //类型数组创建顶点数据
25
    var vertices = new Float32Array([
26
        0, 0, 0, //顶点1坐标
27
        50, 0, 0, //顶点2坐标
28
        0, 100, 0, //顶点3坐标
29
        0, 0, 10, //顶点4坐标
30
        0, 0, 100, //顶点5坐标
31
        50, 0, 10, //顶点6坐标
32
    ]);
33
    // 创建属性缓冲区对象
34
    var attribue = new THREE.BufferAttribute(vertices, 3); //3个为一组,表示一个顶点的xyz坐标
35
    // 设置几何体attributes属性的位置属性
36
    geometry.attributes.position = attribue;
37
    var colors = new Float32Array([
38
      1, 0, 0, //顶点1颜色
39
      0, 1, 0, //顶点2颜色
40
      0, 0, 1, //顶点3颜色
41
42
      1, 1, 0, //顶点4颜色
43
      0, 1, 1, //顶点5颜色
44
      1, 0, 1, //顶点6颜色
45
    ]);
46
    // 设置几何体attributes属性的颜色color属性
47
    geometry.attributes.color = new THREE.BufferAttribute(colors, 3); //3个为一组,表示一个顶点的颜色数据RGB
48