UNPKG

whs-cube-spheres

Version:

This plugin has a container with multiple spheres.

1,837 lines (1,372 loc) 147 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("THREE")); else if(typeof define === 'function' && define.amd) define(["THREE"], factory); else if(typeof exports === 'object') exports["DatGUIModule"] = factory(require("THREE")); else root["DatGUIModule"] = factory(root["THREE"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_7__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.l = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 8); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatCameraModule = undefined; 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 _DatAPI2 = __webpack_require__(10); 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 DatCameraModule = exports.DatCameraModule = function (_DatAPI) { _inherits(DatCameraModule, _DatAPI); function DatCameraModule() { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var gui = arguments[1]; _classCallCheck(this, DatCameraModule); var _this = _possibleConstructorReturn(this, (DatCameraModule.__proto__ || Object.getPrototypeOf(DatCameraModule)).call(this)); _this.bridge = { camera: function camera(_camera, self) { // console.log(this); if (!self.params.camera) return _camera; self.foldObject(_camera, this.params.camera, self.fold, function () { _camera.updateProjectionMatrix(); }); return _camera; }, onWrap: function onWrap(a, self) { self.guiTransforms(this.native, self.fold); } }; _this.params = Object.assign({ name: 'Unknown camera', transforms: true, camera: true }, params); _this.gui = gui; _this.fold = _this.gui.addFolder(_this.params.name); return _this; } _createClass(DatCameraModule, [{ key: 'integrate', value: function integrate(self) { if (this.native) { self.bridge.camera.bind(this)(this.native, self); self.bridge.onWrap.bind(this)(this.native, self); } } }]); return DatCameraModule; }(_DatAPI2.DatAPI); ; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatLightModule = undefined; 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 _DatAPI2 = __webpack_require__(10); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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 DatLightModule = exports.DatLightModule = function (_DatAPI) { _inherits(DatLightModule, _DatAPI); function DatLightModule() { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var gui = arguments[1]; _classCallCheck(this, DatLightModule); var _this = _possibleConstructorReturn(this, (DatLightModule.__proto__ || Object.getPrototypeOf(DatLightModule)).call(this)); _this.bridge = { light: function light(_light, self) { if (!self.params.light) return _light; self.foldObject(_light, this.params.light, self.fold.addFolder('light')); self.foldObject(_light.shadow, this.params.shadow, self.fold.addFolder('shadow')); return _light; }, onWrap: function onWrap(a, self) { self.guiTransforms(this.native, self.fold); } }; _this.params = Object.assign({ name: 'Unknown light', light: true, shadow: true, transforms: true, gui: false }, params); _this.gui = gui; _this.fold = _this.gui.addFolder(_this.params.name); return _this; } _createClass(DatLightModule, [{ key: 'addColor', value: function addColor(object, property) { var instance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.fold; var color = object[property]; instance.addColor(_defineProperty({}, property, color.getHex()), property).onChange(function (value) { if (typeof value === 'string') value.replace('#', '0x'); color.setHex(value); }); } }, { key: 'integrate', value: function integrate(self) { if (this.native) { self.bridge.light.bind(this)(this.native, self); self.bridge.onWrap.bind(this)(this.native, self); } } }]); return DatLightModule; }(_DatAPI2.DatAPI); ; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatMeshModule = undefined; 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 _materials2 = __webpack_require__(3); var _materials3 = _interopRequireDefault(_materials2); var _DatAPI2 = __webpack_require__(10); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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 DatMeshModule = function (_DatAPI) { _inherits(DatMeshModule, _DatAPI); function DatMeshModule() { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var gui = arguments[1]; _classCallCheck(this, DatMeshModule); var _this = _possibleConstructorReturn(this, (DatMeshModule.__proto__ || Object.getPrototypeOf(DatMeshModule)).call(this)); _this.bridge = { material: function material(_material, self) { if (!self.params.material) return _material; var folder = self.fold.addFolder('material'); self.guiMaterial(this, _material, folder); return _material; }, geometry: function geometry(_geometry, self) { if (!self.params.geometry) return _geometry; if (!this.g_) throw new Error('WHS.DynamicGeometryModule should be used in a component (before gui)'); var folder = self.fold.addFolder('geometry'); self.guiGeometry(this, folder); return _geometry; }, mesh: function mesh(_mesh, self) { var _this2 = this; if (!self.customMaterials) return _mesh; self.customMaterials.current = _mesh.material; var matAlias = { material: 'current' }; var keys = Object.keys(self.customMaterials); var folder = self.fold.addFolder('other materials'); folder.add({ material: 'current' }, 'material', keys).onChange(function (v) { _mesh.material = self.customMaterials[v]; folder.removeFolder('customize'); self.guiMaterial(_this2, _mesh.material, folder.addFolder('customize')); }); return _mesh; }, onWrap: function onWrap(a, self) { self.guiTransforms(this.native, self.fold); } }; _this.params = Object.assign({ name: 'Unknown mesh', geometry: true, material: true, transforms: true, gui: false }, params); _this.gui = gui; _this.fold = _this.gui.addFolder(_this.params.name); _this.customMaterials = false; return _this; } _createClass(DatMeshModule, [{ key: 'addColor', value: function addColor(object, property) { var instance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.fold; var color = object[property]; instance.addColor(_defineProperty({}, property, color.getHex()), property).onChange(function (value) { if (typeof value === 'string') value.replace('#', '0x'); color.setHex(value); }); } }, { key: 'guiMaterial', value: function guiMaterial(component, material) { var _this3 = this; var instance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.fold; var paramsProcessor = function paramsProcessor(params) { for (var key in params) { if (params[key] && material[key] !== undefined) { switch (params[key]) { case 'color': _this3.addColor(material, key, instance); break; case 'boolean': instance.add(material, key); break; case 'number': instance.add(material, key); break; case 'texture': // TODO break; default: instance.add(material, key, params[key]); } } } }; paramsProcessor(_materials3.default[material.type]); paramsProcessor(_materials3.default.any); } }, { key: 'guiGeometry', value: function guiGeometry(component) { var instance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.fold; if (!component.g_) throw new Error('DatGUIModule requires WHS.DynamicGeometryModule for geometry updates.'); var geomParams = component.params.geometry; var geomData = this.params.geometry; var _loop = function _loop(key) { var data = geomData[key]; var range = data && data.range ? data.range : [0, 100]; instance.add(geomParams, key).min(range[0]).max(range[1]).step(key.indexOf('Segments') > 0 ? 1 : 0.1).onChange(function (value) { component.g_(_defineProperty({}, key, value)); }); }; for (var key in geomParams) { _loop(key); } } }, { key: 'materials', value: function materials() { var _materials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; this.customMaterials = _materials; return this; } }, { key: 'integrate', value: function integrate(self) { if (this.native) { self.bridge.material.bind(this)(this.native.material, self); self.bridge.geometry.bind(this)(this.native.geometry, self); self.bridge.onWrap.bind(this)(this.native, self); } } }]); return DatMeshModule; }(_DatAPI2.DatAPI); exports.DatMeshModule = DatMeshModule; ; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _three = __webpack_require__(7); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var additional = { wireframe: { wireframe: 'boolean', wireframeLinecap: ['butt', 'round', 'square'], wireframeLinejoin: ['round', 'bevel', 'miter'], wireframeLinewidth: 'number' }, refr: { reflectivity: 'number', refractionRatio: 'number' }, light: { lightMap: 'texture', lightMapIntensity: 'number' }, displacement: { displacementScale: 'number', displacementBias: 'number', displacementMap: 'texture' }, emissive: { emissive: 'color', emissiveMap: 'texture', emissiveIntensity: 'number' } }; var add = function add(origin) { for (var _len = arguments.length, addv = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { addv[_key - 1] = arguments[_key]; } return Object.assign.apply(Object, [origin].concat(_toConsumableArray(addv.map(function (value) { return additional[value]; })))); }; exports.default = { any: add({ side: { FrontSide: _three.FrontSide, BackSide: _three.BackSide, DoubleSide: _three.DoubleSide }, shading: { SmoothShading: _three.SmoothShading, FlatShading: _three.FlatShading }, blending: { NoBlending: _three.NoBlending, NormalBlending: _three.NormalBlending, AdditiveBlending: _three.AdditiveBlending, SubtractiveBlending: _three.SubtractiveBlending, MultiplyBlending: _three.MultiplyBlending, CustomBlending: _three.CustomBlending }, depthFunc: { NeverDepth: _three.NeverDepth, AlwaysDepth: _three.AlwaysDepth, LessDepth: _three.LessDepth, LessEqualDepth: _three.LessEqualDepth, GreaterEqualDepth: _three.GreaterEqualDepth, GreaterDepth: _three.GreaterDepth, NotEqualDepth: _three.NotEqualDepth } }, 'wireframe'), MeshBasicMaterial: { color: 'color', lights: 'boolean', linewidth: 'number', linecap: ['butt', 'round', 'square'], linejoin: ['round', 'bevel', 'miter'] }, MeshLambertMaterial: add({ color: 'color' }, 'emissive', 'refr', 'light'), MeshPhongMaterial: add({ color: 'color' }, 'displacement', 'emissive'), MeshDepthMaterial: {} // To be continued... }; module.exports = exports['default']; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(6) module.exports.color = __webpack_require__(5) /***/ }), /* 5 */ /***/ (function(module, exports) { /** * dat-gui JavaScript Controller Library * http://code.google.com/p/dat-gui * * Copyright 2011 Data Arts Team, Google Creative Lab * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 */ /** @namespace */ var dat = module.exports = dat || {}; /** @namespace */ dat.color = dat.color || {}; /** @namespace */ dat.utils = dat.utils || {}; dat.utils.common = (function () { var ARR_EACH = Array.prototype.forEach; var ARR_SLICE = Array.prototype.slice; /** * Band-aid methods for things that should be a lot easier in JavaScript. * Implementation and structure inspired by underscore.js * http://documentcloud.github.com/underscore/ */ return { BREAK: {}, extend: function(target) { this.each(ARR_SLICE.call(arguments, 1), function(obj) { for (var key in obj) if (!this.isUndefined(obj[key])) target[key] = obj[key]; }, this); return target; }, defaults: function(target) { this.each(ARR_SLICE.call(arguments, 1), function(obj) { for (var key in obj) if (this.isUndefined(target[key])) target[key] = obj[key]; }, this); return target; }, compose: function() { var toCall = ARR_SLICE.call(arguments); return function() { var args = ARR_SLICE.call(arguments); for (var i = toCall.length -1; i >= 0; i--) { args = [toCall[i].apply(this, args)]; } return args[0]; } }, each: function(obj, itr, scope) { if (ARR_EACH && obj.forEach === ARR_EACH) { obj.forEach(itr, scope); } else if (obj.length === obj.length + 0) { // Is number but not NaN for (var key = 0, l = obj.length; key < l; key++) if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) return; } else { for (var key in obj) if (itr.call(scope, obj[key], key) === this.BREAK) return; } }, defer: function(fnc) { setTimeout(fnc, 0); }, toArray: function(obj) { if (obj.toArray) return obj.toArray(); return ARR_SLICE.call(obj); }, isUndefined: function(obj) { return obj === undefined; }, isNull: function(obj) { return obj === null; }, isNaN: function(obj) { return obj !== obj; }, isArray: Array.isArray || function(obj) { return obj.constructor === Array; }, isObject: function(obj) { return obj === Object(obj); }, isNumber: function(obj) { return obj === obj+0; }, isString: function(obj) { return obj === obj+''; }, isBoolean: function(obj) { return obj === false || obj === true; }, isFunction: function(obj) { return Object.prototype.toString.call(obj) === '[object Function]'; } }; })(); dat.color.toString = (function (common) { return function(color) { if (color.a == 1 || common.isUndefined(color.a)) { var s = color.hex.toString(16); while (s.length < 6) { s = '0' + s; } return '#' + s; } else { return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')'; } } })(dat.utils.common); dat.Color = dat.color.Color = (function (interpret, math, toString, common) { var Color = function() { this.__state = interpret.apply(this, arguments); if (this.__state === false) { throw 'Failed to interpret color arguments'; } this.__state.a = this.__state.a || 1; }; Color.COMPONENTS = ['r','g','b','h','s','v','hex','a']; common.extend(Color.prototype, { toString: function() { return toString(this); }, toOriginal: function() { return this.__state.conversion.write(this); } }); defineRGBComponent(Color.prototype, 'r', 2); defineRGBComponent(Color.prototype, 'g', 1); defineRGBComponent(Color.prototype, 'b', 0); defineHSVComponent(Color.prototype, 'h'); defineHSVComponent(Color.prototype, 's'); defineHSVComponent(Color.prototype, 'v'); Object.defineProperty(Color.prototype, 'a', { get: function() { return this.__state.a; }, set: function(v) { this.__state.a = v; } }); Object.defineProperty(Color.prototype, 'hex', { get: function() { if (!this.__state.space !== 'HEX') { this.__state.hex = math.rgb_to_hex(this.r, this.g, this.b); } return this.__state.hex; }, set: function(v) { this.__state.space = 'HEX'; this.__state.hex = v; } }); function defineRGBComponent(target, component, componentHexIndex) { Object.defineProperty(target, component, { get: function() { if (this.__state.space === 'RGB') { return this.__state[component]; } recalculateRGB(this, component, componentHexIndex); return this.__state[component]; }, set: function(v) { if (this.__state.space !== 'RGB') { recalculateRGB(this, component, componentHexIndex); this.__state.space = 'RGB'; } this.__state[component] = v; } }); } function defineHSVComponent(target, component) { Object.defineProperty(target, component, { get: function() { if (this.__state.space === 'HSV') return this.__state[component]; recalculateHSV(this); return this.__state[component]; }, set: function(v) { if (this.__state.space !== 'HSV') { recalculateHSV(this); this.__state.space = 'HSV'; } this.__state[component] = v; } }); } function recalculateRGB(color, component, componentHexIndex) { if (color.__state.space === 'HEX') { color.__state[component] = math.component_from_hex(color.__state.hex, componentHexIndex); } else if (color.__state.space === 'HSV') { common.extend(color.__state, math.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); } else { throw 'Corrupted color state'; } } function recalculateHSV(color) { var result = math.rgb_to_hsv(color.r, color.g, color.b); common.extend(color.__state, { s: result.s, v: result.v } ); if (!common.isNaN(result.h)) { color.__state.h = result.h; } else if (common.isUndefined(color.__state.h)) { color.__state.h = 0; } } return Color; })(dat.color.interpret = (function (toString, common) { var result, toReturn; var interpret = function() { toReturn = false; var original = arguments.length > 1 ? common.toArray(arguments) : arguments[0]; common.each(INTERPRETATIONS, function(family) { if (family.litmus(original)) { common.each(family.conversions, function(conversion, conversionName) { result = conversion.read(original); if (toReturn === false && result !== false) { toReturn = result; result.conversionName = conversionName; result.conversion = conversion; return common.BREAK; } }); return common.BREAK; } }); return toReturn; }; var INTERPRETATIONS = [ // Strings { litmus: common.isString, conversions: { THREE_CHAR_HEX: { read: function(original) { var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i); if (test === null) return false; return { space: 'HEX', hex: parseInt( '0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString()) }; }, write: toString }, SIX_CHAR_HEX: { read: function(original) { var test = original.match(/^#([A-F0-9]{6})$/i); if (test === null) return false; return { space: 'HEX', hex: parseInt('0x' + test[1].toString()) }; }, write: toString }, CSS_RGB: { read: function(original) { var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); if (test === null) return false; return { space: 'RGB', r: parseFloat(test[1]), g: parseFloat(test[2]), b: parseFloat(test[3]) }; }, write: toString }, CSS_RGBA: { read: function(original) { var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/); if (test === null) return false; return { space: 'RGB', r: parseFloat(test[1]), g: parseFloat(test[2]), b: parseFloat(test[3]), a: parseFloat(test[4]) }; }, write: toString } } }, // Numbers { litmus: common.isNumber, conversions: { HEX: { read: function(original) { return { space: 'HEX', hex: original, conversionName: 'HEX' } }, write: function(color) { return color.hex; } } } }, // Arrays { litmus: common.isArray, conversions: { RGB_ARRAY: { read: function(original) { if (original.length != 3) return false; return { space: 'RGB', r: original[0], g: original[1], b: original[2] }; }, write: function(color) { return [color.r, color.g, color.b]; } }, RGBA_ARRAY: { read: function(original) { if (original.length != 4) return false; return { space: 'RGB', r: original[0], g: original[1], b: original[2], a: original[3] }; }, write: function(color) { return [color.r, color.g, color.b, color.a]; } } } }, // Objects { litmus: common.isObject, conversions: { RGBA_OBJ: { read: function(original) { if (common.isNumber(original.r) && common.isNumber(original.g) && common.isNumber(original.b) && common.isNumber(original.a)) { return { space: 'RGB', r: original.r, g: original.g, b: original.b, a: original.a } } return false; }, write: function(color) { return { r: color.r, g: color.g, b: color.b, a: color.a } } }, RGB_OBJ: { read: function(original) { if (common.isNumber(original.r) && common.isNumber(original.g) && common.isNumber(original.b)) { return { space: 'RGB', r: original.r, g: original.g, b: original.b } } return false; }, write: function(color) { return { r: color.r, g: color.g, b: color.b } } }, HSVA_OBJ: { read: function(original) { if (common.isNumber(original.h) && common.isNumber(original.s) && common.isNumber(original.v) && common.isNumber(original.a)) { return { space: 'HSV', h: original.h, s: original.s, v: original.v, a: original.a } } return false; }, write: function(color) { return { h: color.h, s: color.s, v: color.v, a: color.a } } }, HSV_OBJ: { read: function(original) { if (common.isNumber(original.h) && common.isNumber(original.s) && common.isNumber(original.v)) { return { space: 'HSV', h: original.h, s: original.s, v: original.v } } return false; }, write: function(color) { return { h: color.h, s: color.s, v: color.v } } } } } ]; return interpret; })(dat.color.toString, dat.utils.common), dat.color.math = (function () { var tmpComponent; return { hsv_to_rgb: function(h, s, v) { var hi = Math.floor(h / 60) % 6; var f = h / 60 - Math.floor(h / 60); var p = v * (1.0 - s); var q = v * (1.0 - (f * s)); var t = v * (1.0 - ((1.0 - f) * s)); var c = [ [v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q] ][hi]; return { r: c[0] * 255, g: c[1] * 255, b: c[2] * 255 }; }, rgb_to_hsv: function(r, g, b) { var min = Math.min(r, g, b), max = Math.max(r, g, b), delta = max - min, h, s; if (max != 0) { s = delta / max; } else { return { h: NaN, s: 0, v: 0 }; } if (r == max) { h = (g - b) / delta; } else if (g == max) { h = 2 + (b - r) / delta; } else { h = 4 + (r - g) / delta; } h /= 6; if (h < 0) { h += 1; } return { h: h * 360, s: s, v: max / 255 }; }, rgb_to_hex: function(r, g, b) { var hex = this.hex_with_component(0, 2, r); hex = this.hex_with_component(hex, 1, g); hex = this.hex_with_component(hex, 0, b); return hex; }, component_from_hex: function(hex, componentIndex) { return (hex >> (componentIndex * 8)) & 0xFF; }, hex_with_component: function(hex, componentIndex, value) { return value << (tmpComponent = componentIndex * 8) | (hex & ~ (0xFF << tmpComponent)); } } })(), dat.color.toString, dat.utils.common); /***/ }), /* 6 */ /***/ (function(module, exports) { /** * dat-gui JavaScript Controller Library * http://code.google.com/p/dat-gui * * Copyright 2011 Data Arts Team, Google Creative Lab * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 */ /** @namespace */ var dat = module.exports = dat || {}; /** @namespace */ dat.gui = dat.gui || {}; /** @namespace */ dat.utils = dat.utils || {}; /** @namespace */ dat.controllers = dat.controllers || {}; /** @namespace */ dat.dom = dat.dom || {}; /** @namespace */ dat.color = dat.color || {}; dat.utils.css = (function () { return { load: function (url, doc) { doc = doc || document; var link = doc.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = url; doc.getElementsByTagName('head')[0].appendChild(link); }, inject: function(css, doc) { doc = doc || document; var injected = document.createElement('style'); injected.type = 'text/css'; injected.innerHTML = css; doc.getElementsByTagName('head')[0].appendChild(injected); } } })(); dat.utils.common = (function () { var ARR_EACH = Array.prototype.forEach; var ARR_SLICE = Array.prototype.slice; /** * Band-aid methods for things that should be a lot easier in JavaScript. * Implementation and structure inspired by underscore.js * http://documentcloud.github.com/underscore/ */ return { BREAK: {}, extend: function(target) { this.each(ARR_SLICE.call(arguments, 1), function(obj) { for (var key in obj) if (!this.isUndefined(obj[key])) target[key] = obj[key]; }, this); return target; }, defaults: function(target) { this.each(ARR_SLICE.call(arguments, 1), function(obj) { for (var key in obj) if (this.isUndefined(target[key])) target[key] = obj[key]; }, this); return target; }, compose: function() { var toCall = ARR_SLICE.call(arguments); return function() { var args = ARR_SLICE.call(arguments); for (var i = toCall.length -1; i >= 0; i--) { args = [toCall[i].apply(this, args)]; } return args[0]; } }, each: function(obj, itr, scope) { if (ARR_EACH && obj.forEach === ARR_EACH) { obj.forEach(itr, scope); } else if (obj.length === obj.length + 0) { // Is number but not NaN for (var key = 0, l = obj.length; key < l; key++) if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) return; } else { for (var key in obj) if (itr.call(scope, obj[key], key) === this.BREAK) return; } }, defer: function(fnc) { setTimeout(fnc, 0); }, toArray: function(obj) { if (obj.toArray) return obj.toArray(); return ARR_SLICE.call(obj); }, isUndefined: function(obj) { return obj === undefined; }, isNull: function(obj) { return obj === null; }, isNaN: function(obj) { return obj !== obj; }, isArray: Array.isArray || function(obj) { return obj.constructor === Array; }, isObject: function(obj) { return obj === Object(obj); }, isNumber: function(obj) { return obj === obj+0; }, isString: function(obj) { return obj === obj+''; }, isBoolean: function(obj) { return obj === false || obj === true; }, isFunction: function(obj) { return Object.prototype.toString.call(obj) === '[object Function]'; } }; })(); dat.controllers.Controller = (function (common) { /** * @class An "abstract" class that represents a given property of an object. * * @param {Object} object The object to be manipulated * @param {string} property The name of the property to be manipulated * * @member dat.controllers */ var Controller = function(object, property) { this.initialValue = object[property]; /** * Those who extend this class will put their DOM elements in here. * @type {DOMElement} */ this.domElement = document.createElement('div'); /** * The object to manipulate * @type {Object} */ this.object = object; /** * The name of the property to manipulate * @type {String} */ this.property = property; /** * The function to be called on change. * @type {Function} * @ignore */ this.__onChange = undefined; /** * The function to be called on finishing change. * @type {Function} * @ignore */ this.__onFinishChange = undefined; }; common.extend( Controller.prototype, /** @lends dat.controllers.Controller.prototype */ { /** * Specify that a function fire every time someone changes the value with * this Controller. * * @param {Function} fnc This function will be called whenever the value * is modified via this Controller. * @returns {dat.controllers.Controller} this */ onChange: function(fnc) { this.__onChange = fnc; return this; }, /** * Specify that a function fire every time someone "finishes" changing * the value wih this Controller. Useful for values that change * incrementally like numbers or strings. * * @param {Function} fnc This function will be called whenever * someone "finishes" changing the value via this Controller. * @returns {dat.controllers.Controller} this */ onFinishChange: function(fnc) { this.__onFinishChange = fnc; return this; }, /** * Change the value of <code>object[property]</code> * * @param {Object} newValue The new value of <code>object[property]</code> */ setValue: function(newValue) { this.object[this.property] = newValue; if (this.__onChange) { this.__onChange.call(this, newValue); } this.updateDisplay(); return this; }, /** * Gets the value of <code>object[property]</code> * * @returns {Object} The current value of <code>object[property]</code> */ getValue: function() { return this.object[this.property]; }, /** * Refreshes the visual display of a Controller in order to keep sync * with the object's current value. * @returns {dat.controllers.Controller} this */ updateDisplay: function() { return this; }, /** * @returns {Boolean} true if the value has deviated from initialValue */ isModified: function() { return this.initialValue !== this.getValue() } } ); return Controller; })(dat.utils.common); dat.dom.dom = (function (common) { var EVENT_MAP = { 'HTMLEvents': ['change'], 'MouseEvents': ['click','mousemove','mousedown','mouseup', 'mouseover'], 'KeyboardEvents': ['keydown'] }; var EVENT_MAP_INV = {}; common.each(EVENT_MAP, function(v, k) { common.each(v, function(e) { EVENT_MAP_INV[e] = k; }); }); var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/; function cssValueToPixels(val) { if (val === '0' || common.isUndefined(val)) return 0; var match = val.match(CSS_VALUE_PIXELS); if (!common.isNull(match)) { return parseFloat(match[1]); } // TODO ...ems? %? return 0; } /** * @namespace * @member dat.dom */ var dom = { /** * * @param elem * @param selectable */ makeSelectable: function(elem, selectable) { if (elem === undefined || elem.style === undefined) return; elem.onselectstart = selectable ? function() { return false; } : function() { }; elem.style.MozUserSelect = selectable ? 'auto' : 'none'; elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none'; elem.unselectable = selectable ? 'on' : 'off'; }, /** * * @param elem * @param horizontal * @param vertical */ makeFullscreen: function(elem, horizontal, vertical) { if (common.isUndefined(horizontal)) horizontal = true; if (common.isUndefined(vertical)) vertical = true; elem.style.position = 'absolute'; if (horizontal) { elem.style.left = 0; elem.style.right = 0; } if (vertical) { elem.style.top = 0; elem.style.bottom = 0; } }, /** * * @param elem * @param eventType * @param params */ fakeEvent: function(elem, eventType, params, aux) { params = params || {}; var className = EVENT_MAP_INV[eventType]; if (!className) { throw new Error('Event type ' + eventType + ' not supported.'); } var evt = document.createEvent(className); switch (className) { case 'MouseEvents': var clientX = params.x || params.clientX || 0; var clientY = params.y || params.clientY || 0; evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, //screen X 0, //screen Y clientX, //client X clientY, //client Y false, false, false, false, 0, null); break; case 'KeyboardEvents': var init = evt.initKeyboardEvent || evt.initKeyEvent; // webkit || moz common.defaults(params, { cancelable: true, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, keyCode: undefined, charCode: undefined }); init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode); break; default: evt.initEvent(eventType, params.bubbles || false, params.cancelable || true); break; } common.defaults(evt, aux); elem.dispatchEvent(evt); }, /** * * @param elem * @param event * @param func * @param bool */ bind: function(elem, event, func, bool) { bool = bool || false; if (elem.addEventListener) elem.addEventListener(event, func, bool); else if (elem.attachEvent) elem.attachEvent('on' + event, func); return dom; }, /** * * @param elem * @param event * @param func * @param bool */ unbind: function(elem, event, func, bool) { bool = bool || false; if (elem.removeEventListener) elem.removeEventListener(event, func, bool); else if (elem.detachEvent) elem.detachEvent('on' + event, func); return dom; }, /** * * @param elem * @param className */ addClass: function(elem, className) { if (elem.className === undefined) { elem.className = className; } else if (elem.className !== className) { var classes = elem.className.split(/ +/); if (classes.indexOf(className) == -1) { classes.push(className); elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, ''); } } return dom; }, /** * * @param elem * @param className */ removeClass: function(elem, className) { if (className) { if (elem.className === undefined) { // elem.className = className; } else if (elem.className === className) { elem.removeAttribute('class'); } else { var classes = elem.className.split(/ +/); var index = classes.indexOf(className); if (index != -1) { classes.splice(index, 1); elem.className = classes.join(' '); } } } else { elem.className = undefined; } return dom; }, hasClass: function(elem, className) { return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false; }, /** * * @param elem */ getWidth: function(elem) { var style = getComputedStyle(elem); return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style['width']); }, /** * * @param