Skip to content
Snippets Groups Projects
CompositeCell.js 1.41 KiB
Newer Older
Amanda Ghassaei's avatar
Amanda Ghassaei committed
/**
 * Created by aghassaei on 6/12/15.
 */


Amanda Ghassaei's avatar
Amanda Ghassaei committed
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', 'globals', 'materials'],
    function(_, THREE, three, lattice, appState, DMASuperCell, globals, materials){
Amanda Ghassaei's avatar
Amanda Ghassaei committed

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    function CompositeCell(json, superCell){
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        DMASuperCell.call(this, json, superCell);
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    }
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    CompositeCell.prototype = Object.create(DMASuperCell.prototype);

    CompositeCell.prototype._getGeometry = function(){
        var dimensions = materials[this.materialName].dimensions;
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        var geo = new THREE.BoxGeometry(dimensions.x*lattice.xScale(), dimensions.y*lattice.yScale(), dimensions.z*lattice.zScale());
        geo.applyMatrix(new THREE.Matrix4().makeTranslation(dimensions.x/2-0.5, dimensions.y/2-0.5, dimensions.z/2-0.5));
        return geo;
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    };

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    CompositeCell.prototype._rotateCell = function(object3D){
        if (lattice.get("connectionType") == "gik") {
            if (this.index.z %2 != 0) return object3D.rotateZ(Math.PI/2);
            return object3D;
        }
        return DMASuperCell.prototype._rotateCell.call(this, object3D);
    };

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    CompositeCell.prototype._buildWireframe = function(mesh){
        var wireframe = new THREE.BoxHelper(mesh);
        wireframe.material.color.set(0x000000);
        wireframe.matrixWorld = mesh.matrixWorld;
        wireframe.matrixAutoUpdate = true;
        return wireframe;
    };

    return CompositeCell;
});