|
@@ -6,7 +6,7 @@ const scene = new THREE.Scene();
|
6
|
6
|
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
|
7
|
7
|
|
8
|
8
|
console.time("init geo");
|
9
|
|
-const geometry = new THREE.IcosahedronGeometry(10, 0);
|
|
9
|
+const geometry = new THREE.IcosahedronGeometry(10, 6);
|
10
|
10
|
console.timeEnd("init geo");
|
11
|
11
|
|
12
|
12
|
console.time("Hexsphere");
|
|
@@ -44,16 +44,10 @@ for (let i = 0; i < geometry.faces.length; i += 1) {
|
44
|
44
|
const vertexA = geometry.vertices[face.a];
|
45
|
45
|
const vertexB = geometry.vertices[face.b];
|
46
|
46
|
const vertexC = geometry.vertices[face.c];
|
47
|
|
- // var centroid = new THREE.Vector3(
|
48
|
|
- // (vertexA.x + vertexB.x + vertexC.x) / 3,
|
49
|
|
- // (vertexA.y + vertexB.y + vertexC.y) / 3,
|
50
|
|
- // (vertexA.z + vertexB.z + vertexC.z) / 3,
|
51
|
|
- // );
|
52
|
47
|
const vabHalf = vertexB.clone().sub(vertexA).divideScalar(2);
|
53
|
48
|
const pabHalf = vertexA.clone().add(vabHalf);
|
54
|
49
|
const centroid = vertexC.clone().sub(pabHalf).multiplyScalar(1/3).add(pabHalf);
|
55
|
50
|
|
56
|
|
- // var centroidIndex = (newVertices.push(centroid.x, centroid.y, centroid.z) / 3) - 1;
|
57
|
51
|
faceCentroids[i] = centroid;
|
58
|
52
|
}
|
59
|
53
|
|
|
@@ -65,6 +59,15 @@ const findAdjacentFace = (vertexIndex, faces) => {
|
65
|
59
|
}
|
66
|
60
|
}
|
67
|
61
|
|
|
62
|
+const findCenterPoint = faces => {
|
|
63
|
+ const centerPoint = new THREE.Vector3(0, 0, 0);
|
|
64
|
+ for (let i = 0; i < faces.length; i += 1) {
|
|
65
|
+ centerPoint.add(faceCentroids[faces[i]]);
|
|
66
|
+ }
|
|
67
|
+ centerPoint.divideScalar(faces.length);
|
|
68
|
+ return centerPoint;
|
|
69
|
+}
|
|
70
|
+
|
68
|
71
|
console.time("dual");
|
69
|
72
|
const midVertCache = {};
|
70
|
73
|
let hexCount = 0;
|
|
@@ -77,16 +80,13 @@ for (let i = 0; i < originalVertCount; i += 1) {
|
77
|
80
|
pentCount += 1;
|
78
|
81
|
}
|
79
|
82
|
const color = new THREE.Color(Math.random(), Math.random(), Math.random());
|
|
83
|
+ const centerPoint = findCenterPoint(faces);
|
80
|
84
|
for (let j = 0; j < faces.length; j += 1) {
|
81
|
85
|
const faceIndex = faces[j];
|
82
|
86
|
const face = geometry.faces[faceIndex];
|
83
|
87
|
const sortedVerts = [face.a, face.b, face.c].filter(vert => vert !== i);
|
84
|
88
|
sortedVerts.unshift(i)
|
85
|
89
|
|
86
|
|
- const vertexA = geometry.vertices[sortedVerts[0]];
|
87
|
|
- const vertexB = geometry.vertices[sortedVerts[1]];
|
88
|
|
- const vertexC = geometry.vertices[sortedVerts[2]];
|
89
|
|
-
|
90
|
90
|
const centroid = faceCentroids[faceIndex];
|
91
|
91
|
|
92
|
92
|
const adjBFace = findAdjacentFace(sortedVerts[1], faces);
|
|
@@ -108,11 +108,11 @@ for (let i = 0; i < originalVertCount; i += 1) {
|
108
|
108
|
}
|
109
|
109
|
|
110
|
110
|
newVertices.push(
|
111
|
|
- vertexA.x, vertexA.y, vertexA.z,
|
|
111
|
+ centerPoint.x, centerPoint.y, centerPoint.z,
|
112
|
112
|
centroid.x, centroid.y, centroid.z,
|
113
|
113
|
midBCentroid.x, midBCentroid.y, midBCentroid.z,
|
114
|
114
|
|
115
|
|
- vertexA.x, vertexA.y, vertexA.z,
|
|
115
|
+ centerPoint.x, centerPoint.y, centerPoint.z,
|
116
|
116
|
centroid.x, centroid.y, centroid.z,
|
117
|
117
|
midCCentroid.x, midCCentroid.y, midCCentroid.z,
|
118
|
118
|
);
|
|
@@ -140,9 +140,8 @@ console.time("find geo");
|
140
|
140
|
const newGeometry = new THREE.BufferGeometry();
|
141
|
141
|
newGeometry.addAttribute("position", new THREE.Float32BufferAttribute(newVertices, 3));
|
142
|
142
|
newGeometry.addAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
|
143
|
|
-// newGeometry.computeFaceNormals();
|
144
|
|
-// newGeometry.computeVertexNormals();
|
145
|
|
-// newGeometry.normalize();
|
|
143
|
+newGeometry.computeFaceNormals();
|
|
144
|
+newGeometry.computeVertexNormals();
|
146
|
145
|
console.timeEnd("find geo");
|
147
|
146
|
|
148
|
147
|
|