UNPKG

4.5 kBJavaScriptView Raw
1/******/ (function(modules) { // webpackBootstrap
2/******/ // The module cache
3/******/ var installedModules = {};
4
5/******/ // The require function
6/******/ function __webpack_require__(moduleId) {
7
8/******/ // Check if module is in cache
9/******/ if(installedModules[moduleId])
10/******/ return installedModules[moduleId].exports;
11
12/******/ // Create a new module (and put it into the cache)
13/******/ var module = installedModules[moduleId] = {
14/******/ exports: {},
15/******/ id: moduleId,
16/******/ loaded: false
17/******/ };
18
19/******/ // Execute the module function
20/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
22/******/ // Flag the module as loaded
23/******/ module.loaded = true;
24
25/******/ // Return the exports of the module
26/******/ return module.exports;
27/******/ }
28
29
30/******/ // expose the modules object (__webpack_modules__)
31/******/ __webpack_require__.m = modules;
32
33/******/ // expose the module cache
34/******/ __webpack_require__.c = installedModules;
35
36/******/ // __webpack_public_path__
37/******/ __webpack_require__.p = "";
38
39/******/ // Load entry module and return exports
40/******/ return __webpack_require__(0);
41/******/ })
42/************************************************************************/
43/******/ ([
44/* 0 */
45/***/ (function(module, exports) {
46
47 /* global AFRAME */
48
49 if (typeof AFRAME === 'undefined') {
50 throw new Error('Component attempted to register before AFRAME was available.');
51 }
52
53 /**
54 * Mirror Material component for A-Frame by Alfredo Consebola 2017.
55 */
56 AFRAME.registerComponent('mirror', {
57 schema: {
58 resolution: { type:'number', default: 128},
59 refraction: { type:'number', default: 0.95},
60 color: {type:'color', default: 0xffffff},
61 distance: {type:'number', default: 3000},
62 interval: { type:'number', default: 1000},
63 repeat: { type:'boolean', default: false}
64 },
65
66 /**
67 * Set if component needs multiple instancing.
68 */
69 multiple: false,
70
71 /**
72 * Called once when component is attached. Generally for initial setup.
73 */
74 init: function(){
75 this.counter = this.data.interval;
76
77 this.cam = new THREE.CubeCamera( 0.5, this.data.distance, this.data.resolution);
78 this.el.object3D.add( this.cam );
79 this.mirrorMaterial = new THREE.MeshBasicMaterial( { color: this.data.color, refractionRatio: this.data.refraction, envMap: this.cam.renderTarget.texture } );
80 this.done = false;
81 var mirrormat = this.mirrorMaterial;
82 this.mesh = this.el.getObject3D('mesh');
83 if(this.mesh){
84 this.mesh.traverse( function( child ) {
85 if ( child instanceof THREE.Mesh ) child.material = mirrormat;
86 });
87 }
88 },
89
90 tick: function(t,dt){
91 if(!this.done){
92 if( this.counter > 0){
93 this.counter-=dt;
94 }else{
95 this.mesh = this.el.getObject3D('mesh');
96
97 if(this.mesh){
98 this.mesh.visible = false;
99 AFRAME.scenes[0].renderer.autoClear = true;
100 this.cam.position.copy(this.el.object3D.worldToLocal(this.el.object3D.getWorldPosition()));
101 this.cam.updateCubeMap( AFRAME.scenes[0].renderer, this.el.sceneEl.object3D );
102
103 var mirrormat = this.mirrorMaterial;
104 this.mesh.traverse( function( child ) {
105 if ( child instanceof THREE.Mesh ) child.material = mirrormat;
106 });
107 this.mesh.visible = true;
108
109 if(!this.data.repeat){
110 this.done = true;
111 this.counter = this.data.interval;
112 }
113 }
114 }
115 }
116 },
117
118 /**
119 * Called when component is attached and when component data changes.
120 * Generally modifies the entity based on the data.
121 */
122 update: function (oldData) {},
123
124 /**
125 * Called when a component is removed (e.g., via removeAttribute).
126 * Generally undoes all modifications to the entity.
127 */
128 remove: function () {},
129
130 /**
131 * Called on each scene tick.
132 */
133 // tick: function (t) { },
134
135 /**
136 * Called when entity pauses.
137 * Use to stop or remove any dynamic or background behavior such as events.
138 */
139 pause: function () { },
140
141 /**
142 * Called when entity resumes.
143 * Use to continue or add any dynamic or background behavior such as events.
144 */
145 play: function () { }
146 });
147
148
149/***/ })
150/******/ ]);
\No newline at end of file