aframe-extras
Version:
Add-ons and examples for A-Frame VR.
327 lines (288 loc) • 9.85 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(self, () => {
return /******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./src/primitives/a-grid.js":
/*!**********************************!*\
!*** ./src/primitives/a-grid.js ***!
\**********************************/
/***/ (() => {
/**
* Flat grid.
*
* Defaults to 75x75.
*/
AFRAME.registerPrimitive('a-grid', {
defaultComponents: {
geometry: {
primitive: 'plane',
width: 75,
height: 75
},
rotation: {x: -90, y: 0, z: 0},
material: {
src: 'url(https://cdn.jsdelivr.net/gh/donmccurdy/aframe-extras@v1.16.3/assets/grid.png)',
repeat: '75 75'
}
},
mappings: {
width: 'geometry.width',
height: 'geometry.height',
src: 'material.src'
}
});
/***/ }),
/***/ "./src/primitives/a-ocean.js":
/*!***********************************!*\
!*** ./src/primitives/a-ocean.js ***!
\***********************************/
/***/ (() => {
/**
* Flat-shaded ocean primitive.
*
* Based on a Codrops tutorial:
* http://tympanus.net/codrops/2016/04/26/the-aviator-animating-basic-3d-scene-threejs/
*/
AFRAME.registerPrimitive('a-ocean', {
defaultComponents: {
ocean: {},
rotation: {x: -90, y: 0, z: 0}
},
mappings: {
width: 'ocean.width',
depth: 'ocean.depth',
density: 'ocean.density',
amplitude: 'ocean.amplitude',
amplitudeVariance: 'ocean.amplitudeVariance',
speed: 'ocean.speed',
speedVariance: 'ocean.speedVariance',
color: 'ocean.color',
opacity: 'ocean.opacity'
}
});
AFRAME.registerComponent('ocean', {
schema: {
// Dimensions of the ocean area.
width: {default: 10, min: 0},
depth: {default: 10, min: 0},
// Density of waves.
density: {default: 10},
// Wave amplitude and variance.
amplitude: {default: 0.1},
amplitudeVariance: {default: 0.3},
// Wave speed and variance.
speed: {default: 1},
speedVariance: {default: 2},
// Material.
color: {default: '#7AD2F7', type: 'color'},
opacity: {default: 0.8}
},
/**
* Use play() instead of init(), because component mappings – unavailable as dependencies – are
* not guaranteed to have parsed when this component is initialized.
*/
play: function () {
const el = this.el;
const data = this.data;
let material = el.components.material;
const geometry = new THREE.PlaneGeometry(data.width, data.depth, data.density, data.density);
this.waves = [];
const posAttribute = geometry.getAttribute('position');
for (let i = 0; i < posAttribute.count; i++) {
this.waves.push({
z: posAttribute.getZ(i),
ang: Math.random() * Math.PI * 2,
amp: data.amplitude + Math.random() * data.amplitudeVariance,
speed: (data.speed + Math.random() * data.speedVariance) / 1000 // radians / frame
});
}
if (!material) {
material = {};
material.material = new THREE.MeshPhongMaterial({
color: data.color,
transparent: data.opacity < 1,
opacity: data.opacity,
flatShading: true,
});
}
this.mesh = new THREE.Mesh(geometry, material.material);
el.setObject3D('mesh', this.mesh);
},
remove: function () {
this.el.removeObject3D('mesh');
},
tick: function (t, dt) {
if (!dt) return;
const posAttribute = this.mesh.geometry.getAttribute('position');
for (let i = 0; i < posAttribute.count; i++){
const vprops = this.waves[i];
const value = vprops.z + Math.sin(vprops.ang) * vprops.amp;
posAttribute.setZ(i, value);
vprops.ang += vprops.speed * dt;
}
posAttribute.needsUpdate = true;
}
});
/***/ }),
/***/ "./src/primitives/a-tube.js":
/*!**********************************!*\
!*** ./src/primitives/a-tube.js ***!
\**********************************/
/***/ (() => {
/**
* Tube following a custom path.
*
* Usage:
*
* ```html
* <a-tube path="5 0 5, 5 0 -5, -5 0 -5" radius="0.5"></a-tube>
* ```
*/
AFRAME.registerPrimitive('a-tube', {
defaultComponents: {
tube: {},
},
mappings: {
path: 'tube.path',
segments: 'tube.segments',
radius: 'tube.radius',
'radial-segments': 'tube.radialSegments',
closed: 'tube.closed'
}
});
AFRAME.registerComponent('tube', {
schema: {
path: {default: []},
segments: {default: 64},
radius: {default: 1},
radialSegments: {default: 8},
closed: {default: false}
},
init: function () {
const el = this.el,
data = this.data;
let material = el.components.material;
if (!data.path.length) {
console.error('[a-tube] `path` property expected but not found.');
return;
}
const curve = new THREE.CatmullRomCurve3(data.path.map(function (point) {
point = point.split(' ');
return new THREE.Vector3(Number(point[0]), Number(point[1]), Number(point[2]));
}));
const geometry = new THREE.TubeGeometry(
curve, data.segments, data.radius, data.radialSegments, data.closed
);
if (!material) {
material = {};
material.material = new THREE.MeshPhongMaterial();
}
this.mesh = new THREE.Mesh(geometry, material.material);
this.el.setObject3D('mesh', this.mesh);
},
update: function (prevData) {
if (!Object.keys(prevData).length) return;
this.remove();
this.init();
},
remove: function () {
if (this.mesh) this.el.removeObject3D('mesh');
}
});
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
(() => {
"use strict";
/*!*********************************!*\
!*** ./src/primitives/index.js ***!
\*********************************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _a_grid_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./a-grid.js */ "./src/primitives/a-grid.js");
/* harmony import */ var _a_grid_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a_grid_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _a_ocean_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./a-ocean.js */ "./src/primitives/a-ocean.js");
/* harmony import */ var _a_ocean_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_a_ocean_js__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _a_tube_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./a-tube.js */ "./src/primitives/a-tube.js");
/* harmony import */ var _a_tube_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_a_tube_js__WEBPACK_IMPORTED_MODULE_2__);
})();
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=aframe-extras.primitives.js.map