From 7a0aa6e324648fdcca9c07bef8525008b956390a Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 24 Oct 2015 12:11:49 -0400 Subject: [PATCH] hex lattice rendering fix --- js/cells/HexagonalCell.js | 51 +++++++++++++++++++++++++++++++++--- js/cells/HexagonalRotCell.js | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 6 deletions(-) diff --git a/js/cells/HexagonalCell.js b/js/cells/HexagonalCell.js index e075af4d..f059f6ec 100644 --- a/js/cells/HexagonalCell.js +++ b/js/cells/HexagonalCell.js @@ -6,8 +6,53 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function(_, THREE, three, lattice, appState, DMACell){ - var unitCellGeo = new THREE.CylinderGeometry(1, 1, 1, 6); - unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); + var unitGeo = new THREE.Geometry(); + unitGeo.vertices = [ + new THREE.Vector3(0, -1, 0.5), + new THREE.Vector3(0.8660254037844386, -0.5, 0.5), + new THREE.Vector3(0.8660254037844387, 0.5, 0.5), + new THREE.Vector3(0, 1, 0.5), + new THREE.Vector3(-0.8660254037844384, 0.5, 0.5), + new THREE.Vector3(-0.8660254037844386, -0.5, 0.5), + new THREE.Vector3(0, -1, 0.5), + new THREE.Vector3(0, -1, -0.5), + new THREE.Vector3(0.8660254037844386, -0.5, -0.5), + new THREE.Vector3(0.8660254037844387, 0.5, -0.5), + new THREE.Vector3(0, 1, -0.5), + new THREE.Vector3(-0.8660254037844384, 0.5, -0.5), + new THREE.Vector3(-0.8660254037844386, -0.5, -0.5), + new THREE.Vector3(0, -1, -0.5), + new THREE.Vector3(0, 0, 0.5), + new THREE.Vector3(0, 0, -0.5) + ]; + unitGeo.faces = [ + new THREE.Face3(0, 7, 1), + new THREE.Face3(7, 8, 1), + new THREE.Face3(1, 8, 2), + new THREE.Face3(8, 9, 2), + new THREE.Face3(2, 9, 3), + new THREE.Face3(9, 10, 3), + new THREE.Face3(3, 10, 4), + new THREE.Face3(10, 11, 4), + new THREE.Face3(4, 11, 5), + new THREE.Face3(11, 12, 5), + new THREE.Face3(5, 12, 6), + new THREE.Face3(12, 13, 6), + new THREE.Face3(0, 1, 14), + new THREE.Face3(1, 2, 14), + new THREE.Face3(2, 3, 14), + new THREE.Face3(3, 4, 14), + new THREE.Face3(4, 5, 14), + new THREE.Face3(5, 6, 14), + new THREE.Face3(8, 7, 15), + new THREE.Face3(9, 8, 15), + new THREE.Face3(10, 9, 15), + new THREE.Face3(11, 10, 15), + new THREE.Face3(12, 11, 15), + new THREE.Face3(13, 12, 15) + ]; + unitGeo.computeFaceNormals(); + function HexagonalCell(json, superCell){ DMACell.call(this, json, superCell); @@ -15,7 +60,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], HexagonalCell.prototype = Object.create(DMACell.prototype); HexagonalCell.prototype._getGeometry = function(){ - return unitCellGeo; + return unitGeo; }; HexagonalCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell diff --git a/js/cells/HexagonalRotCell.js b/js/cells/HexagonalRotCell.js index edc2e2a1..d6bb65d7 100644 --- a/js/cells/HexagonalRotCell.js +++ b/js/cells/HexagonalRotCell.js @@ -7,8 +7,52 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'hexCell'], function(_, THREE, three, lattice, appState, HexCell){ - var unitCellGeo = new THREE.CylinderGeometry(1, 1, 1, 6); - unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI/2)); + var unitGeo = new THREE.Geometry(); + unitGeo.vertices = [ + new THREE.Vector3(1, 0.5, 0), + new THREE.Vector3(0.5, 0.5, -0.8660254037844386), + new THREE.Vector3(-0.5, 0.5, -0.8660254037844387), + new THREE.Vector3(-1, 0.5, 0), + new THREE.Vector3(-0.5, 0.5, 0.8660254037844384), + new THREE.Vector3(0.5, 0.5, 0.8660254037844386), + new THREE.Vector3(1, 0.5, 0), + new THREE.Vector3(1, -0.5, 0), + new THREE.Vector3(0.5, -0.5, -0.8660254037844386), + new THREE.Vector3(-0.5, -0.5, -0.8660254037844387), + new THREE.Vector3(-1, -0.5, 0), + new THREE.Vector3(-0.5, -0.5, 0.8660254037844384), + new THREE.Vector3(0.5, -0.5, 0.8660254037844386), + new THREE.Vector3(1, -0.5, 0), + new THREE.Vector3(0, 0.5, 0), + new THREE.Vector3(0, -0.5, 0) + ]; + unitGeo.faces = [ + new THREE.Face3(0, 7, 1), + new THREE.Face3(7, 8, 1), + new THREE.Face3(1, 8, 2), + new THREE.Face3(8, 9, 2), + new THREE.Face3(2, 9, 3), + new THREE.Face3(9, 10, 3), + new THREE.Face3(3, 10, 4), + new THREE.Face3(10, 11, 4), + new THREE.Face3(4, 11, 5), + new THREE.Face3(11, 12, 5), + new THREE.Face3(5, 12, 6), + new THREE.Face3(12, 13, 6), + new THREE.Face3(0, 1, 14), + new THREE.Face3(1, 2, 14), + new THREE.Face3(2, 3, 14), + new THREE.Face3(3, 4, 14), + new THREE.Face3(4, 5, 14), + new THREE.Face3(5, 6, 14), + new THREE.Face3(8, 7, 15), + new THREE.Face3(9, 8, 15), + new THREE.Face3(10, 9, 15), + new THREE.Face3(11, 10, 15), + new THREE.Face3(12, 11, 15), + new THREE.Face3(13, 12, 15) + ]; + unitGeo.computeFaceNormals(); function HexagonalCell(json, superCell){ HexCell.call(this, json, superCell); @@ -16,7 +60,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'hexCell'], HexagonalCell.prototype = Object.create(HexCell.prototype); HexagonalCell.prototype._getGeometry = function(){ - return unitCellGeo; + return unitGeo; }; HexagonalCell.prototype.aspectRatio = function(){ -- GitLab