UNPKG

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>

75 lines (58 loc) 4.77 kB
'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 _shaders = require('../shaders.base'); var _shaders2 = _interopRequireDefault(_shaders); 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; } var IntersectBox = function (_ShadersBase) { _inherits(IntersectBox, _ShadersBase); function IntersectBox() { _classCallCheck(this, IntersectBox); var _this = _possibleConstructorReturn(this, (IntersectBox.__proto__ || Object.getPrototypeOf(IntersectBox)).call(this)); _this.name = 'intersectBox'; // default properties names _this._rayOrigin = 'rayOrigin'; _this._rayDirection = 'rayDirection'; _this._aabbMin = 'aabbMin'; _this._aabbMax = 'aabbMax'; _this._tNear = 'tNear'; _this._tFar = 'tFar'; _this._intersect = 'intersect'; return _this; } _createClass(IntersectBox, [{ key: 'api', value: function api() { var baseFragment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._base; var rayOrigin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._rayOrigin; var rayDirection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this._rayDirection; var aabbMin = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : this._aabbMin; var aabbMax = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this._aabbMax; var tNear = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this._tNear; var tFar = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : this._tFar; var intersect = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : this._intersect; this._base = baseFragment; return this.compute(rayOrigin, rayDirection, aabbMin, aabbMax, tNear, tFar, intersect); } }, { key: 'compute', value: function compute(rayOrigin, rayDirection, aabbMin, aabbMax, tNear, tFar, intersect) { this.computeDefinition(); this._base._functions[this._name] = this._definition; return this._name + '(' + rayOrigin + ', ' + rayDirection + ', ' + aabbMin + ', ' + aabbMax + ', ' + tNear + ', ' + tFar + ', ' + intersect + ');'; } }, { key: 'computeDefinition', value: function computeDefinition() { this._definition = '\nvoid ' + this._name + '(vec3 rayOrigin, vec3 rayDirection, vec3 boxMin, vec3 boxMax, out float tNear, out float tFar, out bool intersect){\n // compute intersection of ray with all six bbox planes\n vec3 invRay = vec3(1.) / rayDirection;\n vec3 tBot = invRay * (boxMin - rayOrigin);\n vec3 tTop = invRay * (boxMax - rayOrigin);\n // re-order intersections to find smallest and largest on each axis\n vec3 tMin = min(tTop, tBot);\n vec3 tMax = max(tTop, tBot);\n // find the largest tMin and the smallest tMax\n float largest_tMin = max(max(tMin.x, tMin.y), max(tMin.x, tMin.z));\n float smallest_tMax = min(min(tMax.x, tMax.y), min(tMax.x, tMax.z));\n tNear = largest_tMin;\n tFar = smallest_tMax;\n intersect = smallest_tMax > largest_tMin;\n}\n\n '; } }]); return IntersectBox; }(_shaders2.default); exports.default = new IntersectBox(); module.exports = exports['default'];