Add some timing and hex info logs

This commit is contained in:
Tyler Hallada 2019-02-04 23:45:28 -05:00
parent ec1a200aaf
commit 3b75f81d49

View File

@ -5,10 +5,9 @@ var OrbitControls = require("three-orbit-controls")(THREE);
const scene = new THREE.Scene(); const scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000); var camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
console.time("IcosahedronGeometry"); console.time("init geo");
var geometry = new THREE.IcosahedronGeometry(10, 6); var geometry = new THREE.IcosahedronGeometry(10, 8);
console.log(geometry); console.timeEnd("init geo");
console.timeEnd("IcosahedronGeometry");
console.time("Hexsphere"); console.time("Hexsphere");
var vertToFaces = {}; var vertToFaces = {};
@ -55,10 +54,17 @@ for (var i = 0; i < geometry.faces.length; i += 1) {
faceCentroids[i] = centroid; faceCentroids[i] = centroid;
} }
console.time("find dual"); console.time("dual");
var midVertCache = {}; var midVertCache = {};
var hexCount = 0;
var pentCount = 0;
for (var i = 0; i < originalVertCount; i += 1) { for (var i = 0; i < originalVertCount; i += 1) {
var faces = vertToFaces[i]; var faces = vertToFaces[i];
if (faces.length === 6) {
hexCount += 1;
} else if (faces.length === 5) {
pentCount += 1;
}
var color = new THREE.Color(Math.random(), Math.random(), Math.random()); var color = new THREE.Color(Math.random(), Math.random(), Math.random());
for (var j = 0; j < faces.length; j += 1) { for (var j = 0; j < faces.length; j += 1) {
var faceIndex = faces[j]; var faceIndex = faces[j];
@ -106,20 +112,25 @@ for (var i = 0; i < originalVertCount; i += 1) {
); );
} }
} }
console.timeEnd("find dual"); console.timeEnd("dual");
console.log(`hexagons: ${hexCount}`);
console.log(`pentagons: ${pentCount}`);
function disposeArray() { function disposeArray() {
this.array = null; this.array = null;
} }
console.time("find geo");
var newGeometry = new THREE.BufferGeometry(); var newGeometry = new THREE.BufferGeometry();
newGeometry.addAttribute("position", new THREE.Float32BufferAttribute(newVertices, 3)); newGeometry.addAttribute("position", new THREE.Float32BufferAttribute(newVertices, 3));
newGeometry.addAttribute("color", new THREE.Float32BufferAttribute(colors, 3)); newGeometry.addAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
// newGeometry.computeFaceNormals(); // newGeometry.computeFaceNormals();
// newGeometry.computeVertexNormals(); // newGeometry.computeVertexNormals();
// newGeometry.normalize(); // newGeometry.normalize();
console.timeEnd("find geo");
console.time("other render");
var material = new THREE.MeshBasicMaterial({ vertexColors: THREE.VertexColors, side: THREE.DoubleSide }); var material = new THREE.MeshBasicMaterial({ vertexColors: THREE.VertexColors, side: THREE.DoubleSide });
var sphere = new THREE.Mesh(newGeometry, material); var sphere = new THREE.Mesh(newGeometry, material);
scene.add(sphere); scene.add(sphere);
@ -132,6 +143,7 @@ controls.update()
var renderer = new THREE.WebGLRenderer(); var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight ); renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement ); document.body.appendChild( renderer.domElement );
console.timeEnd("other render");
console.timeEnd("Hexsphere"); console.timeEnd("Hexsphere");
window.addEventListener('resize', onWindowResize, false); window.addEventListener('resize', onWindowResize, false);