Skip to content
Snippets Groups Projects
GIKSuperCell.js 2.63 KiB
Newer Older
Amanda Ghassaei's avatar
eod
Amanda Ghassaei committed
/**
 * Created by aghassaei on 5/26/15.
 */

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

    var unitGeos = {};

    function makePartWithLength(length){
        var geo = new THREE.BoxGeometry(lattice.xScale(0),lattice.yScale(0),lattice.zScale(0));
        geo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1));
        geo.applyMatrix(new THREE.Matrix4().makeTranslation(length/2-0.5, 0, 0));
Amanda Ghassaei's avatar
eod
Amanda Ghassaei committed

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    function GIKSuperCell(json, superCell){
        this.length  = json.length || appState.get("superCellRange").x;
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
    GIKSuperCell.prototype = Object.create(DMASuperCell.prototype);
Amanda Ghassaei's avatar
eod
Amanda Ghassaei committed

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    GIKSuperCell.prototype._getSuperCellRange = function(){
        if (this.length) return new THREE.Vector3(this.length, 1, 1);
        console.warn("no length property for gik super cell");
        return null;
    };

    GIKSuperCell.prototype._makeSubCellForIndex = function(json, callback){
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        json.materialName = this.materialName;
        callback(new GIKCell(json, this));
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    };
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    GIKSuperCell.prototype._rotateCell = function(object3D){
        if (!this.index) return object3D;
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        if (this.index.z%2 != 0) object3D.rotateZ(Math.PI/2);
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        return object3D;
    };
Amanda Ghassaei's avatar
eod
Amanda Ghassaei committed

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    GIKSuperCell.prototype.getLength = function(){
        return this.length;
    };

    GIKSuperCell.prototype._getGeometry = function(){
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        var key = "length"+this.length;
        if (!unitGeos[key]) unitGeos[key] = makePartWithLength(this.length);
        return unitGeos[key];
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    };

    GIKSuperCell.prototype._buildWireframe = function(mesh){
        var wireframe = new THREE.BoxHelper(mesh);
        wireframe.material.color.set(0x000000);
        wireframe.matrixWorld = mesh.matrixWorld;
        wireframe.matrixAutoUpdate = true;
        return wireframe;
    };

    GIKSuperCell.prototype._getMeshName = function(){
        return "cell";
    };

    GIKSuperCell.prototype._isMiddleLayer = function(){
        return false;
    };

    GIKSuperCell.prototype._isTopLayerCell = function(){
        return this.superCell === null || this.superCell === undefined;
    };

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    GIKSuperCell.prototype.toJSON = function(){
Amanda Ghassaei's avatar
Amanda Ghassaei committed
        var data = DMASuperCell.prototype.toJSON.call(this);
        if (!this.length) console.warn("no length assigned to gik supercell");
        data.length = this.length;
        return data;
    };

    GIKSuperCell.prototype.destroy = function(){
        DMASuperCell.prototype.destroy.call(this);
        this.length = null;
Amanda Ghassaei's avatar
Amanda Ghassaei committed
    };

Amanda Ghassaei's avatar
Amanda Ghassaei committed
    return GIKSuperCell;
});