ami-cjs.js
Version:
<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>
226 lines (195 loc) • 7.25 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _shadersLocalizer = require('../shaders/shaders.localizer.uniform');
var _shadersLocalizer2 = _interopRequireDefault(_shadersLocalizer);
var _shadersLocalizer3 = require('../shaders/shaders.localizer.vertex');
var _shadersLocalizer4 = _interopRequireDefault(_shadersLocalizer3);
var _shadersLocalizer5 = require('../shaders/shaders.localizer.fragment');
var _shadersLocalizer6 = _interopRequireDefault(_shadersLocalizer5);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Imports ***/
/**
* @module helpers/localizer
*/
var HelpersLocalizer = function (_THREE$Object3D) {
_inherits(HelpersLocalizer, _THREE$Object3D);
function HelpersLocalizer(stack, geometry, referencePlane) {
_classCallCheck(this, HelpersLocalizer);
var _this = _possibleConstructorReturn(this, (HelpersLocalizer.__proto__ || Object.getPrototypeOf(HelpersLocalizer)).call(this));
//
_this._stack = stack;
_this._referencePlane = referencePlane;
_this._plane1 = null;
_this._color1 = null;
_this._plane2 = null;
_this._color2 = null;
_this._plane3 = null;
_this._color3 = null;
_this._canvasWidth = 0;
_this._canvasHeight = 0;
_this._shadersFragment = _shadersLocalizer6.default;
_this._shadersVertex = _shadersLocalizer4.default;
_this._uniforms = _shadersLocalizer2.default.uniforms();
_this._material = null;
_this._geometry = geometry;
_this._create();
return _this;
}
_createClass(HelpersLocalizer, [{
key: '_create',
value: function _create() {
this._prepareMaterial();
this._mesh = new THREE.Mesh(this._geometry, this._material);
this._mesh.applyMatrix(this._stack._ijk2LPS);
this.add(this._mesh);
}
}, {
key: '_prepareMaterial',
value: function _prepareMaterial() {
if (!this.material) {
// reference plane
this._uniforms.uSlice.value = this._referencePlane;
// localizer planes
if (this._plane1) {
this._uniforms.uPlane1.value = this._plane1;
this._uniforms.uPlaneColor1.value = this._color1;
}
if (this._plane2) {
this._uniforms.uPlane2.value = this._plane2;
this._uniforms.uPlaneColor2.value = this._color2;
}
if (this._plane3) {
this._uniforms.uPlane3.value = this._plane3;
this._uniforms.uPlaneColor3.value = this._color3;
}
//
this._uniforms.uCanvasWidth.value = this._canvasWidth;
this._uniforms.uCanvasHeight.value = this._canvasHeight;
// generate material
var fs = new _shadersLocalizer6.default(this._uniforms);
var vs = new _shadersLocalizer4.default();
this._material = new THREE.ShaderMaterial({ side: THREE.DoubleSide,
uniforms: this._uniforms,
vertexShader: vs.compute(),
fragmentShader: fs.compute()
});
this._material.transparent = true;
}
}
}, {
key: 'update',
value: function update() {
if (this._mesh) {
this.remove(this._mesh);
this._mesh.geometry.dispose();
this._mesh.geometry = null;
this._mesh = null;
}
this._create();
}
}, {
key: 'geometry',
get: function get() {
return this._geometry;
},
set: function set(geometry) {
this._geometry = geometry;
if (this._mesh) {
this.remove(this._mesh);
this._mesh.geometry.dispose();
this._mesh.geometry = null;
this._mesh = null;
}
this._create();
}
}, {
key: 'referencePlane',
get: function get() {
return this._referencePlane;
},
set: function set(referencePlane) {
this._referencePlane = referencePlane;
this._uniforms.uSlice.value = this._referencePlane;
}
}, {
key: 'plane1',
get: function get() {
return this._plane1;
},
set: function set(plane1) {
this._plane1 = plane1;
this._uniforms.uPlane1.value = this._plane1;
}
}, {
key: 'color1',
get: function get() {
return this._color1;
},
set: function set(color1) {
this._color1 = color1;
this._uniforms.uPlaneColor1.value = this._color1;
}
}, {
key: 'plane2',
get: function get() {
return this._plane2;
},
set: function set(plane2) {
this._plane2 = plane2;
this._uniforms.uPlane2.value = this._plane2;
}
}, {
key: 'color2',
get: function get() {
return this._color2;
},
set: function set(color2) {
this._color2 = color2;
this._uniforms.uPlaneColor2.value = this._color2;
}
}, {
key: 'plane3',
get: function get() {
return this._plane3;
},
set: function set(plane3) {
this._plane3 = plane3;
this._uniforms.uPlane3.value = this._plane3;
}
}, {
key: 'color3',
get: function get() {
return this._color3;
},
set: function set(color3) {
this._color3 = color3;
this._uniforms.uPlaneColor3.value = this._color3;
}
}, {
key: 'canvasWidth',
get: function get() {
return this._canvasWidth;
},
set: function set(canvasWidth) {
this._canvasWidth = canvasWidth;
this._uniforms.uCanvasWidth.value = this._canvasWidth;
}
}, {
key: 'canvasHeight',
get: function get() {
return this._canvasHeight;
},
set: function set(canvasHeight) {
this._canvasHeight = canvasHeight;
this._uniforms.uCanvasHeight.value = this._canvasHeight;
}
}]);
return HelpersLocalizer;
}(THREE.Object3D);
exports.default = HelpersLocalizer;
module.exports = exports['default'];