forked from aframevr/a-painter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
3 lines (3 loc) · 72.5 KB
/
build.js
1
2
3
!function(t){function e(s){if(i[s])return i[s].exports;var n=i[s]={exports:{},id:s,loaded:!1};return t[s].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){window.saveAs=i(1).saveAs,i(4),i(5),i(6),i(7),i(8),i(9),i(10),i(11),i(12),i(13),i(14),i(15),i(16),i(17),i(18),i(19),i(20),i(21),i(22),i(23),i(24)},function(t,e,i){var s,n,r=r||function(t){"use strict";if(!("undefined"==typeof t||"undefined"!=typeof navigator&&/MSIE [1-9]\./.test(navigator.userAgent))){var e=t.document,i=function(){return t.URL||t.webkitURL||t},s=e.createElementNS("http://www.w3.org/1999/xhtml","a"),n="download"in s,r=function(t){var e=new MouseEvent("click");t.dispatchEvent(e)},o=/constructor/i.test(t.HTMLElement),a=/CriOS\/[\d]+/.test(navigator.userAgent),h=function(e){(t.setImmediate||t.setTimeout)(function(){throw e},0)},l="application/octet-stream",c=4e4,u=function(t){var e=function(){"string"==typeof t?i().revokeObjectURL(t):t.remove()};setTimeout(e,c)},d=function(t,e,i){e=[].concat(e);for(var s=e.length;s--;){var n=t["on"+e[s]];if("function"==typeof n)try{n.call(t,i||t)}catch(t){h(t)}}},m=function(t){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(t.type)?new Blob([String.fromCharCode(65279),t],{type:t.type}):t},p=function(e,h,c){c||(e=m(e));var p,b=this,g=e.type,f=g===l,v=function(){d(b,"writestart progress write writeend".split(" "))},E=function(){if((a||f&&o)&&t.FileReader){var s=new FileReader;return s.onloadend=function(){var e=a?s.result:s.result.replace(/^data:[^;]*;/,"data:attachment/file;"),i=t.open(e,"_blank");i||(t.location.href=e),e=void 0,b.readyState=b.DONE,v()},s.readAsDataURL(e),void(b.readyState=b.INIT)}if(p||(p=i().createObjectURL(e)),f)t.location.href=p;else{var n=t.open(p,"_blank");n||(t.location.href=p)}b.readyState=b.DONE,v(),u(p)};return b.readyState=b.INIT,n?(p=i().createObjectURL(e),void setTimeout(function(){s.href=p,s.download=h,r(s),v(),u(p),b.readyState=b.DONE})):void E()},b=p.prototype,g=function(t,e,i){return new p(t,e||t.name||"download",i)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(t,e,i){return e=e||t.name||"download",i||(t=m(t)),navigator.msSaveOrOpenBlob(t,e)}:(b.abort=function(){},b.readyState=b.INIT=0,b.WRITING=1,b.DONE=2,b.error=b.onwritestart=b.onprogress=b.onwrite=b.onabort=b.onerror=b.onwriteend=null,g)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof t&&t.exports?t.exports.saveAs=r:null!==i(2)&&null!==i(3)&&(s=[],n=function(){return r}.apply(e,s),!(void 0!==n&&(t.exports=n)))},function(t,e){t.exports=function(){throw new Error("define cannot be used indirect")}},function(t,e){(function(e){t.exports=e}).call(e,{})},function(t,e){window.addEventListener("load",function(t){var e=document.body;e.addEventListener("dragover",function(t){t.stopPropagation(),t.preventDefault(),t.dataTransfer.dropEffect="copy"},!1),e.addEventListener("drop",function(t){t.stopPropagation(),t.preventDefault();for(var e=t.dataTransfer.files,i=0;i<e.length;i++){var s=e[i];if(".apa"===s.name.substr(s.name.length-4).toLowerCase()){var n=new FileReader;n.onload=function(t){document.querySelector("a-scene").systems.brush.loadBinary(t.target.result)},n.readAsArrayBuffer(s)}else if(".json"===s.name.substr(s.name.length-5).toLowerCase()){var n=new FileReader;n.onload=function(t){document.querySelector("a-scene").systems.brush.loadJSON(JSON.parse(t.target.result))},n.readAsText(s)}else".obj"===s.name.substr(s.name.length-4).toLowerCase()?(n=new FileReader,n.onload=function(t){for(var e=new AFRAME.THREE.OBJLoader,i=e.parse(t.target.result),s=document.createElement("a-entity"),n=0;n<i.children.length;n++){var r=i.children[n];r.material.color.set("#333")}s.setObject3D("mesh",i),s.className="templateitem",document.querySelector("a-scene").appendChild(s)},n.readAsText(s)):s.type.match(/image.*/)&&(n=new FileReader,n.onload=function(t){var e=new Image;e.src=t.target.result;var i,s;e.width>e.height?(i=1,s=e.height/e.width):(s=1,i=e.width/e.height);var n=[3*Math.random()-1.5,1+Math.random()-.5,-1.4+.2*Math.random()],r=document.createElement("a-image");r.setAttribute("src",t.target.result),r.setAttribute("position",n.join(" ")),r.setAttribute("width",i),r.setAttribute("height",s),r.className="templateitem",document.querySelector("a-scene").appendChild(r)},n.readAsDataURL(s))}},!1)})},function(t,e){window.BinaryManager=function(t){this.dataview=new DataView(t),this.offset=0,this.isLittleEndian=!0},window.BinaryManager.prototype={readQuaternion:function(){return new THREE.Quaternion(this.readFloat(),this.readFloat(),this.readFloat(),this.readFloat())},readVector3:function(){return new THREE.Vector3(this.readFloat(),this.readFloat(),this.readFloat())},readString:function(){for(var t=this.dataview.getUint8(this.offset++,!0),e="",i=0;i<t;i++)e+=String.fromCharCode(this.dataview.getUint8(this.offset++,!0));return e},readColor:function(){return new THREE.Color(this.readFloat(),this.readFloat(),this.readFloat())},readFloat:function(){var t=this.dataview.getFloat32(this.offset,!0);return this.offset+=4,t},readUint32:function(){var t=this.dataview.getUint32(this.offset,!0);return this.offset+=4,t},readUint16:function(){var t=this.dataview.getUint16(this.offset,!0);return this.offset+=2,t},readUint8:function(){var t=this.dataview.getUint8(this.offset,!0);return this.offset++,t},writeVector:function(t){this.writeFloat32Array(t.toArray())},writeColor:function(t){this.writeFloat32Array(t.toArray())},writeString:function(t){this.writeUint8(t.length);for(var e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e))},writeUint8:function(t){this.dataview.setUint8(this.offset,t,this.isLittleEndian),this.offset++},writeUint16:function(t){this.dataview.setUint16(this.offset,t,this.isLittleEndian),this.offset+=2},writeUint32:function(t){this.dataview.setUint32(this.offset,t,this.isLittleEndian),this.offset+=4},writeFloat32:function(t){this.dataview.setFloat32(this.offset,t,this.isLittleEndian),this.offset+=4},writeFloat32Array:function(t){for(var e=0;e<t.length;e++)this.writeFloat32(t[e])},getDataView:function(){return this.dataview}}},function(t,e){THREE.OrbitControls=function(t,e){function i(){return 2*Math.PI/60/60*k.autoRotateSpeed}function s(){return Math.pow(.95,k.zoomSpeed)}function n(t){I.theta-=t}function r(t){I.phi-=t}function o(t){k.object instanceof THREE.PerspectiveCamera?_/=t:k.object instanceof THREE.OrthographicCamera?(k.object.zoom=Math.max(k.minZoom,Math.min(k.maxZoom,k.object.zoom*t)),k.object.updateProjectionMatrix(),W=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),k.enableZoom=!1)}function a(t){k.object instanceof THREE.PerspectiveCamera?_*=t:k.object instanceof THREE.OrthographicCamera?(k.object.zoom=Math.max(k.minZoom,Math.min(k.maxZoom,k.object.zoom/t)),k.object.updateProjectionMatrix(),W=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),k.enableZoom=!1)}function h(t){J.set(t.clientX,t.clientY)}function l(t){K.set(t.clientX,t.clientY)}function c(t){Y.set(t.clientX,t.clientY)}function u(t){q.set(t.clientX,t.clientY),Z.subVectors(q,J);var e=k.domElement===document?k.domElement.body:k.domElement;n(2*Math.PI*Z.x/e.clientWidth*k.rotateSpeed),r(2*Math.PI*Z.y/e.clientHeight*k.rotateSpeed),J.copy(q),k.update()}function d(t){G.set(t.clientX,t.clientY),$.subVectors(G,K),$.y>0?o(s()):$.y<0&&a(s()),K.copy(G),k.update()}function m(t){X.set(t.clientX,t.clientY),Q.subVectors(X,Y),it(Q.x,Q.y),Y.copy(X),k.update()}function p(t){}function b(t){t.deltaY<0?a(s()):t.deltaY>0&&o(s()),k.update()}function g(t){switch(t.keyCode){case k.keys.UP:it(0,k.keyPanSpeed),k.update();break;case k.keys.BOTTOM:it(0,-k.keyPanSpeed),k.update();break;case k.keys.LEFT:it(k.keyPanSpeed,0),k.update();break;case k.keys.RIGHT:it(-k.keyPanSpeed,0),k.update()}}function f(t){J.set(t.touches[0].pageX,t.touches[0].pageY)}function v(t){var e=t.touches[0].pageX-t.touches[1].pageX,i=t.touches[0].pageY-t.touches[1].pageY,s=Math.sqrt(e*e+i*i);K.set(0,s)}function E(t){Y.set(t.touches[0].pageX,t.touches[0].pageY)}function y(t){q.set(t.touches[0].pageX,t.touches[0].pageY),Z.subVectors(q,J);var e=k.domElement===document?k.domElement.body:k.domElement;n(2*Math.PI*Z.x/e.clientWidth*k.rotateSpeed),r(2*Math.PI*Z.y/e.clientHeight*k.rotateSpeed),J.copy(q),k.update()}function w(t){var e=t.touches[0].pageX-t.touches[1].pageX,i=t.touches[0].pageY-t.touches[1].pageY,n=Math.sqrt(e*e+i*i);G.set(0,n),$.subVectors(G,K),$.y>0?a(s()):$.y<0&&o(s()),K.copy(G),k.update()}function x(t){X.set(t.touches[0].pageX,t.touches[0].pageY),Q.subVectors(X,Y),it(Q.x,Q.y),Y.copy(X),k.update()}function A(t){}function R(t){if(k.enabled!==!1){if(t.preventDefault(),t.button===k.mouseButtons.ORBIT){if(k.enableRotate===!1)return;h(t),z=U.ROTATE}else if(t.button===k.mouseButtons.ZOOM){if(k.enableZoom===!1)return;l(t),z=U.DOLLY}else if(t.button===k.mouseButtons.PAN){if(k.enablePan===!1)return;c(t),z=U.PAN}z!==U.NONE&&(document.addEventListener("mousemove",T,!1),document.addEventListener("mouseup",M,!1),k.dispatchEvent(L))}}function T(t){if(k.enabled!==!1)if(t.preventDefault(),z===U.ROTATE){if(k.enableRotate===!1)return;u(t)}else if(z===U.DOLLY){if(k.enableZoom===!1)return;d(t)}else if(z===U.PAN){if(k.enablePan===!1)return;m(t)}}function M(t){k.enabled!==!1&&(p(t),document.removeEventListener("mousemove",T,!1),document.removeEventListener("mouseup",M,!1),k.dispatchEvent(F),z=U.NONE)}function O(t){k.enabled===!1||k.enableZoom===!1||z!==U.NONE&&z!==U.ROTATE||(t.preventDefault(),t.stopPropagation(),b(t),k.dispatchEvent(L),k.dispatchEvent(F))}function S(t){k.enabled!==!1&&k.enableKeys!==!1&&k.enablePan!==!1&&g(t)}function j(t){if(k.enabled!==!1){switch(t.touches.length){case 1:if(k.enableRotate===!1)return;f(t),z=U.TOUCH_ROTATE;break;case 2:if(k.enableZoom===!1)return;v(t),z=U.TOUCH_DOLLY;break;case 3:if(k.enablePan===!1)return;E(t),z=U.TOUCH_PAN;break;default:z=U.NONE}z!==U.NONE&&k.dispatchEvent(L)}}function H(t){if(k.enabled!==!1)switch(t.preventDefault(),t.stopPropagation(),t.touches.length){case 1:if(k.enableRotate===!1)return;if(z!==U.TOUCH_ROTATE)return;y(t);break;case 2:if(k.enableZoom===!1)return;if(z!==U.TOUCH_DOLLY)return;w(t);break;case 3:if(k.enablePan===!1)return;if(z!==U.TOUCH_PAN)return;x(t);break;default:z=U.NONE}}function P(t){k.enabled!==!1&&(A(t),k.dispatchEvent(F),z=U.NONE)}function C(t){t.preventDefault()}this.object=t,this.domElement=void 0!==e?e:document,this.enabled=!0,this.target=new THREE.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-(1/0),this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.25,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.enableKeys=!0,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},this.mouseButtons={ORBIT:THREE.MOUSE.LEFT,ZOOM:THREE.MOUSE.MIDDLE,PAN:THREE.MOUSE.RIGHT},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.getPolarAngle=function(){return D.phi},this.getAzimuthalAngle=function(){return D.theta},this.reset=function(){k.target.copy(k.target0),k.object.position.copy(k.position0),k.object.zoom=k.zoom0,k.object.updateProjectionMatrix(),k.dispatchEvent(B),k.update(),z=U.NONE},this.update=function(){var e=new THREE.Vector3,s=(new THREE.Quaternion).setFromUnitVectors(t.up,new THREE.Vector3(0,1,0)),r=s.clone().inverse(),o=new THREE.Vector3,a=new THREE.Quaternion;return function(){var t=k.object.position;return e.copy(t).sub(k.target),e.applyQuaternion(s),D.setFromVector3(e),k.autoRotate&&z===U.NONE&&n(i()),D.theta+=I.theta,D.phi+=I.phi,D.theta=Math.max(k.minAzimuthAngle,Math.min(k.maxAzimuthAngle,D.theta)),D.phi=Math.max(k.minPolarAngle,Math.min(k.maxPolarAngle,D.phi)),D.makeSafe(),D.radius*=_,D.radius=Math.max(k.minDistance,Math.min(k.maxDistance,D.radius)),k.target.add(V),e.setFromSpherical(D),e.applyQuaternion(r),t.copy(k.target).add(e),k.object.lookAt(k.target),k.enableDamping===!0?(I.theta*=1-k.dampingFactor,I.phi*=1-k.dampingFactor):I.set(0,0,0),_=1,V.set(0,0,0),!!(W||o.distanceToSquared(k.object.position)>N||8*(1-a.dot(k.object.quaternion))>N)&&(k.dispatchEvent(B),o.copy(k.object.position),a.copy(k.object.quaternion),W=!1,!0)}}(),this.dispose=function(){k.domElement.removeEventListener("contextmenu",C,!1),k.domElement.removeEventListener("mousedown",R,!1),k.domElement.removeEventListener("wheel",O,!1),k.domElement.removeEventListener("touchstart",j,!1),k.domElement.removeEventListener("touchend",P,!1),k.domElement.removeEventListener("touchmove",H,!1),document.removeEventListener("mousemove",T,!1),document.removeEventListener("mouseup",M,!1),window.removeEventListener("keydown",S,!1)};var k=this,B={type:"change"},L={type:"start"},F={type:"end"},U={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},z=U.NONE,N=1e-6,D=new THREE.Spherical,I=new THREE.Spherical,_=1,V=new THREE.Vector3,W=!1,J=new THREE.Vector2,q=new THREE.Vector2,Z=new THREE.Vector2,Y=new THREE.Vector2,X=new THREE.Vector2,Q=new THREE.Vector2,K=new THREE.Vector2,G=new THREE.Vector2,$=new THREE.Vector2,tt=function(){var t=new THREE.Vector3;return function(e,i){t.setFromMatrixColumn(i,0),t.multiplyScalar(-e),V.add(t)}}(),et=function(){var t=new THREE.Vector3;return function(e,i){t.setFromMatrixColumn(i,1),t.multiplyScalar(e),V.add(t)}}(),it=function(){var t=new THREE.Vector3;return function(e,i){var s=k.domElement===document?k.domElement.body:k.domElement;if(k.object instanceof THREE.PerspectiveCamera){var n=k.object.position;t.copy(n).sub(k.target);var r=t.length();r*=Math.tan(k.object.fov/2*Math.PI/180),tt(2*e*r/s.clientHeight,k.object.matrix),et(2*i*r/s.clientHeight,k.object.matrix)}else k.object instanceof THREE.OrthographicCamera?(tt(e*(k.object.right-k.object.left)/k.object.zoom/s.clientWidth,k.object.matrix),et(i*(k.object.top-k.object.bottom)/k.object.zoom/s.clientHeight,k.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),k.enablePan=!1)}}();k.domElement.addEventListener("contextmenu",C,!1),k.domElement.addEventListener("mousedown",R,!1),k.domElement.addEventListener("wheel",O,!1),k.domElement.addEventListener("touchstart",j,!1),k.domElement.addEventListener("touchend",P,!1),k.domElement.addEventListener("touchmove",H,!1),window.addEventListener("keydown",S,!1),this.update()},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.OrbitControls.prototype.constructor=THREE.OrbitControls,Object.defineProperties(THREE.OrbitControls.prototype,{center:{get:function(){return console.warn("THREE.OrbitControls: .center has been renamed to .target"),this.target}},noZoom:{get:function(){return console.warn("THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead."),!this.enableZoom},set:function(t){console.warn("THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead."),this.enableZoom=!t}},noRotate:{get:function(){return console.warn("THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead."),!this.enableRotate},set:function(t){console.warn("THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead."),this.enableRotate=!t}},noPan:{get:function(){return console.warn("THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead."),!this.enablePan},set:function(t){console.warn("THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead."),this.enablePan=!t}},noKeys:{get:function(){return console.warn("THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead."),!this.enableKeys},set:function(t){console.warn("THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead."),this.enableKeys=!t}},staticMoving:{get:function(){return console.warn("THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead."),!this.enableDamping},set:function(t){console.warn("THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead."),this.enableDamping=!t}},dynamicDampingFactor:{get:function(){return console.warn("THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead."),this.dampingFactor},set:function(t){console.warn("THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead."),this.dampingFactor=t}}})},function(t,e){window.Utils=function(){function t(t){return parseFloat(t.toFixed(i))}function e(e){for(var i=0;i<e.length;i++)e[i]=t(e[i]);return this}const i=6;return{numberToFixed:t,arrayNumbersToFixed:e}}},function(t,e){window.addEventListener("load",function(t){var e=document.getElementById("apainter-ui"),i=document.querySelector("#apainter-ui .share"),s=document.getElementById("apainter-share-url"),n=document.querySelector("#apainter-ui .progress"),r=document.querySelector("#apainter-ui .bar");document.addEventListener("drawing-upload-completed",function(t){i.classList.remove("hide"),n.classList.add("hide"),s.value=t.detail.url}),document.addEventListener("drawing-upload-started",function(t){e.style.display="block",i.classList.add("hide"),n.classList.remove("hide")}),document.addEventListener("drawing-upload-progress",function(t){r.style.width=Math.floor(100*t.detail.progress)+"%"});var o=new Clipboard(".button.copy");o.on("error",function(t){console.error("Error copying to clipboard:",t.action,t.trigger)})})},function(t,e){var s=1;AFRAME.BRUSHES={},AFRAME.registerBrush=function(t,e,i){function s(t){return function(e,i,s,n){this.object3D=new THREE.Object3D,this.data={points:[],size:i,prevPosition:null,prevPointerPosition:null,numPoints:0,color:e.clone(),timestamp:n,owner:s},t.call(this,e,i)}}function n(t){return function(e,i,s,n,r){this.data.prevPosition&&this.data.prevPosition.distanceTo(e)<=this.options.spacing||0!==this.options.maxPoints&&this.data.numPoints>=this.options.maxPoints||t.call(this,e,i,s,n,r)&&(this.data.numPoints++,this.data.points.push({position:e.clone(),orientation:i.clone(),pressure:n,timestamp:r}),this.data.prevPosition=e.clone(),this.data.prevPointerPosition=s.clone())}}var r={};if(Object.keys(e).forEach(function(t){r[t]={value:e[t],writable:!0}}),AFRAME.BRUSHES[t])throw new Error("The brush `"+t+"` has been already registered. Check that you are not loading two versions of the same brush or two different brushes of the same name.");var o=function(){},a={spacing:0,maxPoints:0};o.prototype={options:Object.assign(a,i),reset:function(){},tick:function(t,e){},addPoint:function(t,e,i,s,n){},getJSON:function(t){for(var e=[],i=0;i<this.data.points.length;i++){var s=this.data.points[i];e.push({orientation:Utils.arrayNumbersToFixed(s.orientation.toArray()),position:Utils.arrayNumbersToFixed(s.position.toArray()),pressure:Utils.numberToFixed(s.pressure),timestamp:s.timestamp})}return{brush:{index:t.getUsedBrushes().indexOf(this.brushName),color:Utils.arrayNumbersToFixed(this.data.color.toArray()),size:Utils.numberToFixed(this.data.size)},points:e}},getBinary:function(t){var e=21+36*this.data.points.length,i=new BinaryManager(new ArrayBuffer(e));i.writeUint8(t.getUsedBrushes().indexOf(this.brushName)),i.writeColor(this.data.color),i.writeFloat32(this.data.size),i.writeUint32(this.data.points.length);for(var s=0;s<this.data.points.length;s++){var n=this.data.points[s];i.writeFloat32Array(n.position.toArray()),i.writeFloat32Array(n.orientation.toArray()),i.writeFloat32(n.pressure),i.writeUint32(n.timestamp)}return i.getDataView()}};var h=function(){};return h.prototype=Object.create(o.prototype,r),h.prototype.brushName=t,h.prototype.constructor=h,h.prototype.init=s(h.prototype.init),h.prototype.addPoint=n(h.prototype.addPoint),AFRAME.BRUSHES[t]=h,h.used=!1,h},AFRAME.registerSystem("brush",{schema:{},brushes:{},strokes:[],getUsedBrushes:function(){return Object.keys(AFRAME.BRUSHES).filter(function(t){return AFRAME.BRUSHES[t].used})},getBrushByName:function(t){return AFRAME.BRUSHES[t]},undo:function(){for(var t,e=this.strokes.length-1;e>=0;e--)if("local"===this.strokes[e].data.owner){t=this.strokes.splice(e,1)[0];break}if(t){var i=t.entity;i.emit("stroke-removed",{entity:i}),i.parentNode.removeChild(i)}},clear:function(){for(var t=0;t<this.strokes.length;t++)if("local"===this.strokes[t].data.owner){var e=this.strokes[t].entity;e.emit("stroke-removed",{entity:e}),e.parentNode.removeChild(e)}Object.keys(AFRAME.BRUSHES).forEach(function(t){AFRAME.BRUSHES[t].used=!1}),this.strokes=[]},init:function(){this.version=s,this.clear(),this.controllerName=null;var t=this;this.sceneEl.addEventListener("controllerconnected",function(e){t.controllerName=e.detail.name})},tick:function(t,e){if(this.strokes.length)for(var i=0;i<this.strokes.length;i++)this.strokes[i].tick(t,e)},generateRandomStrokes:function(t){function e(){return 2*Math.random()-1}for(var i=0;i<t;i++){var s="flat",n=new THREE.Color(Math.random(),Math.random(),Math.random()),r=.1*Math.random(),o=parseInt(500*Math.random()),a=this.addNewStroke(s,n,r),h=document.querySelector("#left-hand");h.emit("stroke-started",{entity:h,stroke:a});for(var l=new THREE.Vector3(e(),e(),e()),c=new THREE.Vector3,u=new THREE.Quaternion,d=.2,m=0;m<o;m++){c.set(e(),e(),e()),c.multiplyScalar(e()/20),u.setFromUnitVectors(l.clone().normalize(),c.clone().normalize()),l=l.add(c);var p=0,b=this.getPointerPosition(l,u);a.addPoint(l,u,b,d,p)}}},addNewStroke:function(t,e,i,s,n){s=s||"local",n=n||Date.now();var r=this.getBrushByName(t);if(!r){var o=Object.keys(AFRAME.BRUSHES)[0];r=AFRAME.BRUSHES[o],console.warn("Invalid brush name: `"+t+"` using `"+o+"`")}r.used=!0;var a=new r;a.brush=r,a.init(e,i,s,n),this.strokes.push(a);var h=document.querySelector(".a-drawing");h||(h=document.createElement("a-entity"),h.className="a-drawing",document.querySelector("a-scene").appendChild(h));var l=document.createElement("a-entity");return l.className="a-stroke",h.appendChild(l),l.setObject3D("mesh",a.object3D),a.entity=l,a},getJSON:function(){var t={version:s,strokes:[],author:"",brushes:this.getUsedBrushes()};for(i=0;i<this.strokes.length;i++)t.strokes.push(this.strokes[i].getJSON(this));return t},getBinary:function(){var t=[],e="apainter",i=this.getUsedBrushes(),n=e.length+i.join(" ").length+9,r=new BinaryManager(new ArrayBuffer(n));r.writeString(e),r.writeUint16(s),r.writeUint8(i.length);for(var o=0;o<i.length;o++)r.writeString(i[o]);for(r.writeUint32(this.strokes.length),t.push(r.getDataView()),o=0;o<this.strokes.length;o++)t.push(this.strokes[o].getBinary(this));return t},getPointerPosition:function(){var t=new THREE.Vector3,e={"vive-controls":{vec:new THREE.Vector3(0,.7,1),mult:-.03},"oculus-touch-controls":{vec:new THREE.Vector3(0,0,2.8),mult:-.05},"windows-motion-controls":{vec:new THREE.Vector3(0,0,1),mult:-.12}};return function(i,s){if(!this.controllerName)return i;var n=e[this.controllerName],r=n.vec.clone().applyQuaternion(s).normalize().multiplyScalar(n.mult);return t.copy(i).add(r),t}}(),loadJSON:function(t){t.version!==s&&console.error("Invalid version: ",t.version,"(Expected: "+s+")");for(var e=0;e<t.strokes.length;e++)for(var i=t.strokes[e],n=i.brush,r=this.addNewStroke(t.brushes[n.index],(new THREE.Color).fromArray(n.color),n.size),o=0;o<i.points.length;o++){var a=i.points[o],h=(new THREE.Vector3).fromArray(a.position),l=(new THREE.Quaternion).fromArray(a.orientation),c=a.pressure,u=a.timestamp,d=this.getPointerPosition(h,l);r.addPoint(h,l,d,c,u)}},loadBinary:function(t){var e=new BinaryManager(t),i=e.readString();if("apainter"!==i)return void console.error("Invalid `magic` header");var n=e.readUint16();n!==s&&console.error("Invalid version: ",n,"(Expected: "+s+")");for(var r=e.readUint8(),o=[],a=0;a<r;a++)o.push(e.readString());for(var h=e.readUint32(),l=0;l<h;l++)for(var c=e.readUint8(),u=e.readColor(),d=e.readFloat(),m=e.readUint32(),p=this.addNewStroke(o[c],u,d),b=0;b<m;b++){var g=e.readVector3(),f=e.readQuaternion(),v=e.readFloat(),E=e.readUint32(),y=this.getPointerPosition(g,f);p.addPoint(g,f,y,v,E)}},loadFromUrl:function(t,e){var i=new THREE.XHRLoader(this.manager);i.crossOrigin="anonymous",e===!0&&i.setResponseType("arraybuffer");var s=this;i.load(t,function(t){e===!0?s.loadBinary(t):s.loadJSON(JSON.parse(t))})}})},function(t,e){AFRAME.registerSystem("ui",{init:function(){this.initTextures()},initTextures:function(){function t(t){i.hoverTexture=t}function e(t){i.pressedTexture=t}var i=this,s="assets/images/ui-hover.png",n="assets/images/ui-pressed.png";this.sceneEl.systems.material.loadTexture(s,{src:s},t),this.sceneEl.systems.material.loadTexture(n,{src:n},e)},closeAll:function(){var t,e=document.querySelectorAll("[ui]");for(t=0;t<e.length;t++)e[t].components.ui.close()}})},function(t,e,i){var s=i(1).saveAs;AFRAME.registerSystem("painter",{init:function(){function t(){var t,e=/\+/g,i=/([^&=]+)=?([^&]*)/g,s=function(t){return decodeURIComponent(t.replace(e," "))},n=window.location.search.substring(1),r={};for(t=i.exec(n);t;)r[s(t[1])]=s(t[2]),t=i.exec(n);return r}this.version="1.1",this.brushSystem=this.sceneEl.systems.brush,this.showTemplateItems=!0;var e=t();if(e.url||e.urljson){var i=void 0===e.urljson;this.brushSystem.loadFromUrl(e.url||e.urljson,i),document.getElementById("logo").setAttribute("visible",!1),document.getElementById("acamera").setAttribute("orbit-controls","position","0 1.6 3"),document.getElementById("apainter-logo").classList.remove("hidden")}void 0!==e.bgcolor&&(document.body.style.backgroundColor="#"+e.bgcolor),void 0!==e.sky&&this.sceneEl.addEventListener("loaded",function(t){""===e.sky?document.getElementById("sky").setAttribute("visible",!1):document.getElementById("sky").setAttribute("material","src",e.sky)}),void 0!==e.floor&&this.sceneEl.addEventListener("loaded",function(t){""===e.floor?document.getElementById("ground").setAttribute("visible",!1):document.getElementById("ground").setAttribute("material","src",e.floor)}),this.startPainting=!1;var s=this;document.addEventListener("stroke-started",function(t){if(!s.startPainting){var e=document.getElementById("logo"),i=e.getObject3D("mesh");new AFRAME.TWEEN.Tween({alpha:1}).to({alpha:0},4e3).onComplete(function(){e.setAttribute("visible",!1)}).onUpdate(function(){i.children[0].material.opacity=this.alpha}).start();s.startPainting=!0}}),document.addEventListener("keyup",function(t){if(!t.shiftKey&&!t.ctrlKey){if(8===t.keyCode&&s.brushSystem.undo(),67===t.keyCode&&s.brushSystem.clear(),71===t.keyCode){var e=document.querySelector(".a-drawing");s.sceneEl.systems["gltf-exporter"].export(e)}if(78===t.keyCode){var i=document.querySelectorAll("[paint-controls]"),n=Object.keys(AFRAME.BRUSHES),r=n.indexOf(i[0].components.brush.data.brush);r=(r+1)%n.length,[].forEach.call(i,function(t){t.setAttribute("brush","brush",n[r])})}if(82===t.keyCode&&s.brushSystem.generateRandomStrokes(1),76===t.keyCode&&s.brushSystem.loadFromUrl("demo.apa",!0),85===t.keyCode&&s.upload(),86===t.keyCode&&s.save(),74===t.keyCode&&s.saveJSON(),79===t.keyCode){s.showTemplateItems=!s.showTemplateItems;for(var o=document.querySelectorAll(".templateitem"),a=0;a<o.length;a++)o[a].setAttribute("visible",s.showTemplateItems)}}}),console.info("A-PAINTER Version: "+this.version)},saveJSON:function(){var t=this.brushSystem.getJSON(),e=new Blob([JSON.stringify(t)],{type:"application/json"});s(e,"demo.json")},save:function(){var t=this.brushSystem.getBinary(),e=new Blob(t,{type:"application/octet-binary"});s(e,"demo.apa")},upload:function(t,e){this.sceneEl.emit("drawing-upload-started");var i=this,s="https://aframe.io/a-painter/?url=",n=this.brushSystem.getBinary(),r=new Blob(n,{type:"application/octet-binary"}),o="uploadcare";if("fileio"===o){var a=new window.FormData;a.append("file",r);var h=new window.XMLHttpRequest;h.open("POST","https://file.io"),h.onreadystatechange=function(n){if(4===h.readyState){var r=JSON.parse(h.response);r.success&&(console.log("Uploaded link: ",s+r.link),i.sceneEl.emit("drawing-upload-completed",{url:s+r.link}),t&&t())}else i.sceneEl.emit("drawing-upload-error",{errorInfo:null,fileInfo:null}),e&&e()},h.send(a)}else{var l=uploadcare.fileFrom("object",r);l.done(function(e){console.log("Uploaded link: ",s+e.cdnUrl),i.sceneEl.emit("drawing-upload-completed",{url:s+e.cdnUrl}),t&&t()}).fail(function(t,s){i.sceneEl.emit("drawing-upload-error",{errorInfo:t,fileInfo:s}),e&&e(t)}).progress(function(t){i.sceneEl.emit("drawing-upload-progress",{progress:t.progress})})}}})},function(t,e){AFRAME.registerComponent("brush",{schema:{color:{type:"color",default:"#ef2d5e"},size:{default:.01,min:.001,max:.3},brush:{default:"flat"},enabled:{default:!0}},init:function(){var t=this.data;this.color=new THREE.Color(t.color),this.el.emit("brushcolor-changed",{color:this.color}),this.el.emit("brushsize-changed",{brushSize:t.size}),this.active=!1,this.obj=this.el.object3D,this.currentStroke=null,this.strokeEntities=[],this.sizeModifier=0,this.textures={},this.currentMap=0,this.model=this.el.getObject3D("mesh"),this.drawing=!1;var e=this;this.previousAxis=0,this.el.addEventListener("buttondown",function(t){e.data.enabled&&2===t.detail.id&&e.system.undo()}),this.el.addEventListener("buttonchanged",function(t){if(e.data.enabled&&1===t.detail.id){var i=t.detail.state.value;e.sizeModifier=i,i>.1?e.active||(e.startNewStroke(),e.active=!0):(e.active&&(e.previousEntity=e.currentEntity,e.currentStroke=null),e.active=!1)}})},update:function(t){var e=this.data;t.color!==e.color&&(this.color.set(e.color),this.el.emit("brushcolor-changed",{color:this.color})),t.size!==e.size&&this.el.emit("brushsize-changed",{size:e.size})},tick:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Vector3;return function(s,n){if(this.currentStroke&&this.active){this.obj.matrixWorld.decompose(t,e,i);var r=this.system.getPointerPosition(t,e);this.currentStroke.addPoint(t,e,r,this.sizeModifier,s)}}}(),startNewStroke:function(){this.currentStroke=this.system.addNewStroke(this.data.brush,this.color,this.data.size),this.el.emit("stroke-started",{entity:this.el,stroke:this.currentStroke})}})},function(t,e){var i=AFRAME.utils;AFRAME.registerComponent("if-no-vr-headset",{schema:{default:{},parse:i.styleParser.parse},update:function(){var t=this;return this.el.sceneEl.isMobile?void this.setProperties():void navigator.getVRDisplays().then(function(e){e.length&&"Emulated HTC Vive DVT"!==e[0].displayName||t.setProperties()})},setProperties:function(){var t=this.data,e=this.el;Object.keys(t).forEach(function(i){e.setAttribute(i,t[i])})}})},function(t,e){AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"}},init:function(){this.objectLoader=new THREE.ObjectLoader,this.objectLoader.setCrossOrigin("")},update:function(t){var e=this,i=this.data.src;i&&i!==t.src&&this.objectLoader.load(this.data.src,function(t){var s=(new THREE.Matrix4).makeRotationX(-Math.PI/2);t.traverse(function(t){t instanceof THREE.Mesh&&t.position.applyMatrix4(s)}),e.el.setObject3D("mesh",t),e.el.emit("model-loaded",{format:"json",model:t,src:i})})}})},function(t,e){AFRAME.registerComponent("orbit-controls",{dependencies:["camera"],schema:{position:{default:"0 1.6 0.1",type:"vec3"}},init:function(){var t=this.el.sceneEl,e=this.setupControls.bind(this);this.el.sceneEl.is("vr-mode")||this.el.setAttribute("position",this.data.position),t.canvas?e():t.addEventListener("render-target-loaded",e),this.onEnterVR=this.onEnterVR.bind(this),this.onExitVR=this.onExitVR.bind(this),t.addEventListener("enter-vr",this.onEnterVR),t.addEventListener("exit-vr",this.onExitVR)},onExitVR:function(){this.el.setAttribute("position",this.data.position),this.controls.enabled=!0},onEnterVR:function(){if(AFRAME.utils.device.checkHeadsetConnected()||this.el.sceneEl.isMobile){var t=this.el.getAttribute("position"),e=this.el.getObject3D("camera");this.controls.enabled=!1,e.position.set(0,0,0),e.rotation.set(0,0,0),
this.el.sceneEl.isMobile||this.el.setAttribute("position",{x:t.x-this.data.position.x,y:t.y-this.data.position.y,z:t.z-this.data.position.z})}},setupControls:function(){var t=this.el.sceneEl.renderer,e=this.el.getObject3D("camera"),i=this.controls=new THREE.OrbitControls(e,t.domElement),s=this.el.getAttribute("position");i.target.setX(-s.x),i.target.setZ(-s.z),i.enableDamping=!0,i.dampingFactor=1,i.enableZoom=!0},play:function(){this.controls&&(this.controls.enable=!0)},pause:function(){this.controls&&(this.controls.enable=!1)},remove:function(){this.pause()}})},function(t,e){AFRAME.registerSystem("paint-controls",{numberStrokes:0}),AFRAME.registerComponent("paint-controls",{dependencies:["brush"],schema:{hand:{default:"left"}},init:function(){function t(t){var e=i.highLightMaterial=new THREE.MeshBasicMaterial;e.map=t,e.needsUpdate=!0}var e=this.el,i=this,s="assets/images/controller-pressed.png",n=null;this.controller=null,this.modelLoaded=!1,this.onModelLoaded=this.onModelLoaded.bind(this),e.addEventListener("model-loaded",this.onModelLoaded);var r=function(t){if((0!==t.detail.axis[0]||0!==t.detail.axis[1])&&i.previousAxis!==t.detail.axis[1]){var s=t.detail.axis[1]/300,n=e.components.brush.schema.size,r=THREE.Math.clamp(i.el.getAttribute("brush").size-s,n.min,n.max);i.el.setAttribute("brush","size",r)}};e.addEventListener("controllerconnected",function(t){var s=t.detail.name;if("windows-motion-controls"===s)e.setAttribute("teleport-controls",{button:"trackpad"}),n=Array.prototype.slice.call(document.querySelectorAll(".windows-motion-tooltips")),e.addEventListener("axismove",function(t){r(t)}),e.addEventListener("trackpadtouchstart",function(){i.touchStarted=!0}),i.touchStarted=!1;else if("oculus-touch-controls"===s){var o=t.detail.component.data.hand;e.setAttribute("teleport-controls",{button:"left"===o?"ybutton":"bbutton"}),e.setAttribute("obj-model",{obj:"assets/models/oculus-"+o+"-controller.obj",mtl:"https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-"+o+".mtl"}),n=Array.prototype.slice.call(document.querySelectorAll(".oculus-tooltips")),e.addEventListener("axismove",function(t){r(t)})}else{if("vive-controls"!==s)return;e.setAttribute("json-model",{src:"assets/models/controller_vive.json"}),e.setAttribute("teleport-controls",{button:"trackpad"}),n=Array.prototype.slice.call(document.querySelectorAll(".vive-tooltips")),e.addEventListener("axismove",function(t){if((0!==t.detail.axis[0]||0!==t.detail.axis[1])&&i.previousAxis!==t.detail.axis[1]){i.touchStarted&&(i.touchStarted=!1,i.startAxis=(t.detail.axis[1]+1)/2);var s=(t.detail.axis[1]+1)/2,n=(i.startAxis-s)/2;i.startAxis=s;var r=i.el.getAttribute("brush").size,o=e.components.brush.schema.size,a=THREE.Math.clamp(r-n,o.min,o.max);i.el.setAttribute("brush","size",a)}}),e.addEventListener("trackpadtouchstart",function(){i.touchStarted=!0}),i.touchStarted=!1}n&&n.forEach(function(t){t.setAttribute("visible",!0)}),this.controller=s}),e.addEventListener("brushsize-changed",function(t){i.changeBrushSize(t.detail.size)}),e.addEventListener("brushcolor-changed",function(t){i.changeBrushColor(t.detail.color)}),e.sceneEl.systems.material.loadTexture(s,{src:s},t),this.startAxis=0,this.numberStrokes=0,document.addEventListener("stroke-started",function(t){if(t.detail.entity.components["paint-controls"]===i&&(i.numberStrokes++,i.system.numberStrokes++,3===i.system.numberStrokes)){var e=Array.prototype.slice.call(document.querySelectorAll("[tooltip]")),s={opacity:1},n=new AFRAME.TWEEN.Tween(s).to({opacity:0},4e3).onComplete(function(){e.forEach(function(t){t.setAttribute("visible",!1)})}).delay(2e3).onUpdate(function(){e.forEach(function(t){t.setAttribute("tooltip",{opacity:s.opacity})})});n.start()}})},changeBrushColor:function(t){this.modelLoaded&&this.buttonMeshes.sizeHint&&(this.buttonMeshes.colorTip.material.color.copy(t),this.buttonMeshes.sizeHint.material.color.copy(t))},changeBrushSize:function(t){var e=t/2*10;this.modelLoaded&&this.buttonMeshes.sizeHint&&this.buttonMeshes.sizeHint.scale.set(e,e,1)},mapping:{axis0:"trackpad",axis1:"trackpad",button0:"trackpad",button1:"trigger",button2:"grip",button3:"menu",button4:"system"},update:function(){var t=this.data,e=this.el;e.setAttribute("vive-controls",{hand:t.hand,model:!1}),e.setAttribute("oculus-touch-controls",{hand:t.hand,model:!1}),e.setAttribute("windows-motion-controls",{hand:t.hand})},play:function(){},pause:function(){},onModelLoaded:function(t){var e,i=t.detail.model;t.detail.target===this.el&&(e=this.buttonMeshes={},e.sizeHint=i.getObjectByName("sizehint"),e.colorTip=i.getObjectByName("tip"),this.modelLoaded=!0,this.changeBrushSize(this.el.components.brush.data.size),this.changeBrushColor(this.el.components.brush.color))},onButtonEvent:function(t,e){var i=this.mapping["button"+t];this.el.emit(i+e),this.updateModel(i,e)},updateModel:function(t,e){var i="up"===e?this.material:this.highLightMaterial,s=this.buttonMeshes,n=s&&s[t];if("down"===e&&n&&!this.material&&(i=this.material=n.material),i)return"grip"===t?(s.grip.left.material=i,void(s.grip.right.material=i)):void(n&&(n.material=i))}})},function(t,e){AFRAME.registerComponent("ui",{schema:{brightness:{default:1,max:1,min:0}},dependencies:["ui-raycaster"],init:function(){var t=this.el,e=this.uiEl=document.createElement("a-entity"),i=this.rayEl=document.createElement("a-entity");this.closed=!0,this.colorStack=["#272727","#727272","#FFFFFF","#24CAFF","#249F90","#F2E646","#EF2D5E"],this.bindMethods(),this.colorHasChanged=!0,this.highlightMaterials={},this.intersectedObjects=[],this.hoveredOffObjects=[],this.hoveredOnObjects=[],this.pressedObjects={},this.selectedObjects={},this.unpressedObjects={},this.brushButtonsMapping={},this.brushRegexp=/^(?!.*(fg|bg)$)brush[0-9]+/,this.colorHistoryRegexp=/^(?!.*(fg|bg)$)colorhistory[0-9]+$/,this.hsv={h:0,s:0,v:1},this.rayAngle=45,this.rayDistance=.2,this.cursorOffset=new THREE.Vector3(.06409,.01419,-.10242),e.setAttribute("material",{color:"#ffffff",flatShading:!0,shader:"flat",transparent:!0,fog:!1,src:"#uinormal"}),e.setAttribute("obj-model","obj:#uiobj"),e.setAttribute("position","0 0.04 -0.15"),e.setAttribute("scale","0 0 0"),e.setAttribute("visible",!1),e.classList.add("apainter-ui"),t.appendChild(e),i.setAttribute("line",""),t.appendChild(i),t.setAttribute("ui-raycaster",{far:this.rayDistance,objects:".apainter-ui",rotation:-this.rayAngle}),this.controller=null;var s=this;t.addEventListener("controllerconnected",function(i){var n=i.detail.name;s.controller={name:n,hand:i.detail.component.data.hand},"oculus-touch-controls"===n?(s.uiEl.setAttribute("rotation","45 0 0"),e.setAttribute("position","0 0.13 -0.08"),s.rayAngle=0,t.setAttribute("ui-raycaster",{rotation:0})):"windows-motion-controls"===n&&(s.rayAngle=25,t.setAttribute("ui-raycaster",{rotation:-30})),s.el.isPlaying&&s.addToggleEvent()})},initColorWheel:function(){var t=this.objects.hueWheel,e="\t varying vec2 vUv;\t void main() {\t vUv = uv;\t vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\t gl_Position = projectionMatrix * mvPosition;\t }\t ",i="\t #define M_PI2 6.28318530718\n \t uniform float brightness;\t varying vec2 vUv;\t vec3 hsb2rgb(in vec3 c){\t vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, \t 0.0, \t 1.0 );\t rgb = rgb * rgb * (3.0 - 2.0 * rgb);\t return c.z * mix( vec3(1.0), rgb, c.y);\t }\t \t void main() {\t vec2 toCenter = vec2(0.5) - vUv;\t float angle = atan(toCenter.y, toCenter.x);\t float radius = length(toCenter) * 2.0;\t vec3 color = hsb2rgb(vec3((angle / M_PI2) + 0.5, radius, brightness));\t gl_FragColor = vec4(color, 1.0);\t }\t ",s=new THREE.ShaderMaterial({uniforms:{brightness:{type:"f",value:this.hsv.v}},vertexShader:e,fragmentShader:i});t.material=s},bindMethods:function(){this.onComponentChanged=this.onComponentChanged.bind(this),this.onTriggerChanged=this.onTriggerChanged.bind(this),this.onIntersection=this.onIntersection.bind(this),this.onIntersected=this.onIntersected.bind(this),this.onIntersectionCleared=this.onIntersectionCleared.bind(this),this.onIntersectedCleared=this.onIntersectedCleared.bind(this),this.onModelLoaded=this.onModelLoaded.bind(this),this.onStrokeStarted=this.onStrokeStarted.bind(this),this.toggleMenu=this.toggleMenu.bind(this)},tick:function(){this.el.components["ui-raycaster"].refreshObjects(),!this.closed&&this.handEl&&(this.updateIntersections(),this.handleHover(),this.handlePressedButtons())},onTriggerChanged:function(t){var e=t.detail.value;this.lastTriggerValue=e,t.detail.value>=.25?this.triggeredPressed=!0:(this.triggeredPressed=!1,this.handleButtonUp())},handleButtonDown:function(t,e){var i=t.name;if(!this.activeWidget||this.activeWidget===i){switch(this.activeWidget=i,!0){case"brightness"===i:this.onBrightnessDown(e);break;case"brushnext"===i:this.pressedObjects[i]||this.nextPage();break;case"brushprev"===i:this.pressedObjects[i]||this.previousPage();break;case"clear"===i:this.pressedObjects[i]||this.el.sceneEl.systems.brush.clear();break;case"copy"===i:this.pressedObjects[i]||this.copyBrush();break;case"hue"===i:this.onHueDown(e);break;case"save"===i:this.pressedObjects[i]||this.el.sceneEl.systems.painter.upload();break;case"sizebg"===i:this.onBrushSizeBackgroundDown(e);break;case this.brushRegexp.test(i):this.onBrushDown(i);break;case this.colorHistoryRegexp.test(i):this.onColorHistoryButtonDown(t);break;default:this.activeWidget=void 0}this.pressedObjects[i]=t}},copyBrush:function(){var t=this.el.getAttribute("brush");this.handEl.setAttribute("brush","brush",t.brush),this.handEl.setAttribute("brush","color",t.color),this.handEl.setAttribute("brush","size",t.size),this.colorHasChanged=!0},handleButtonUp:function(){var t=this.pressedObjects,e=this.unpressedObjects;this.activeWidget=void 0,Object.keys(t).forEach(function(i){var s=t[i].name;switch(!0){case"size"===s:}e[s]=t[s],delete t[s]})},handlePressedButtons:function(){var t=this;this.triggeredPressed&&this.hoveredOnObjects.forEach(function(e){t.handleButtonDown(e.object,e.point)})},onColorHistoryButtonDown:function(t){var e=t.material.color.getHexString();this.handEl.setAttribute("brush","color","#"+e)},onBrushDown:function(t){var e=this.brushButtonsMapping[t];e&&(this.selectBrushButton(t),this.handEl.setAttribute("brush","brush",e.toLowerCase()))},selectBrushButton:function(t){var e=this.uiEl.getObject3D("mesh").getObjectByName(t+"bg"),i=this.selectedObjects,s=this.selectedBrush;s&&(this.highlightMaterials[s.name]||this.initHighlightMaterial(e),s.material=this.highlightMaterials[s.name].normal,delete i[s.name]),i[e.name]=e,this.selectedBrush=e},onHueDown:function(t){var e,i=this.objects.hueWheel,s=this.colorWheelSize;i.updateMatrixWorld(),i.worldToLocal(t),this.objects.hueCursor.position.copy(t),e={r:Math.sqrt(t.x*t.x+t.z*t.z),theta:Math.PI+Math.atan2(-t.z,t.x)};var n=(e.theta*(180/Math.PI)+180)%360;this.hsv.h=n/360,this.hsv.s=e.r/s,this.updateColor()},updateColor:function(){var t=this.hsv2rgb(this.hsv),e="rgb("+t.r+", "+t.g+", "+t.b+")";this.handEl.setAttribute("brush","color",e),this.colorHasChanged=!0},hsv2rgb:function(t){var e,i,s,n,r,o,a,h,l=THREE.Math.clamp(t.h,0,1),c=THREE.Math.clamp(t.s,0,1),u=t.v;switch(n=Math.floor(6*l),r=6*l-n,o=u*(1-c),a=u*(1-r*c),h=u*(1-(1-r)*c),n%6){case 0:e=u,i=h,s=o;break;case 1:e=a,i=u,s=o;break;case 2:e=o,i=u,s=h;break;case 3:e=o,i=a,s=u;break;case 4:e=h,i=o,s=u;break;case 5:e=u,i=o,s=a}return{r:Math.round(255*e),g:Math.round(255*i),b:Math.round(255*s)}},rgb2hsv:function(t,e,i){var s,n=Math.max(t,e,i),r=Math.min(t,e,i),o=n-r,a=0===n?0:o/n,h=n;switch(1===arguments.length&&(e=t.g,i=t.b,t=t.r),n){case r:s=0;break;case t:s=e-i+o*(e<i?6:0),s/=6*o;break;case e:s=i-t+2*o,s/=6*o;break;case i:s=t-e+4*o,s/=6*o}return{h:s,s:a,v:h}},onBrightnessDown:function(t){var e=this.objects.brightnessSlider,i=e.geometry.boundingBox,s=i.max.z-i.min.z;e.updateMatrixWorld(),e.worldToLocal(t);var n=1-(t.z-i.min.z)/s;n=THREE.Math.clamp(1.29*n-.12,0,1),this.objects.hueWheel.material.uniforms.brightness.value=n,this.objects.brightnessCursor.rotation.y=1.5*n-1.5,this.hsv.v=n,this.updateColor()},onBrushSizeBackgroundDown:function(t){var e=this.objects.sizeSlider,i=e.geometry.boundingBox,s=i.max.x-i.min.x;e.updateMatrixWorld(),e.worldToLocal(t);var n=(t.x-i.min.x)/s;n*=AFRAME.components.brush.schema.size.max,this.handEl.setAttribute("brush","size",n)},handleHover:function(){this.updateHoverObjects(),this.updateMaterials()},updateHoverObjects:function(){var t=this.intersectedObjects;t=t.filter(function(t){return"bb"!==t.object.name&&"msg_save"!==t.object.name}),this.hoveredOffObjects=this.hoveredOnObjects.filter(function(e){return t.indexOf(e)===-1}),this.hoveredOnObjects=t},updateMaterials:function(){var t=new THREE.Vector3;return function(){var e=this,i=this.pressedObjects,s=this.unpressedObjects,n=this.selectedObjects;this.hoveredOffObjects.forEach(function(t){var i=t.object;i.material=e.highlightMaterials[i.name].normal}),this.hoveredOnObjects.forEach(function(i){var s=i.object;t.copy(i.point),e.highlightMaterials[s.name]||e.initHighlightMaterial(s),e.handRayEl.object3D.worldToLocal(t),e.handRayEl.setAttribute("line","end",t),s.material=e.highlightMaterials[s.name].hover}),Object.keys(i).forEach(function(t){var s=i[t],n=e.highlightMaterials[s.name];s.material=n.pressed||s.material}),Object.keys(s).forEach(function(t){var i=s[t],n=e.highlightMaterials[i.name];i.material=n.normal,delete s[t]}),Object.keys(n).forEach(function(t){var i=n[t],s=e.highlightMaterials[i.name];s&&(i.material=s.selected)})}}(),addToggleEvent:function(){var t=this.el;"oculus-touch-controls"===this.controller.name?"left"===this.controller.hand?t.addEventListener("xbuttondown",this.toggleMenu):t.addEventListener("abuttondown",this.toggleMenu):"vive-controls"!==this.controller.name&&"windows-motion-controls"!==this.controller.name||t.addEventListener("menudown",this.toggleMenu)},removeToggleEvent:function(){var t=this.el;"oculus-touch-controls"===this.controller.name?"left"===this.controller.hand?t.removeEventListener("xbuttondown",this.toggleMenu):t.removeEventListener("abuttondown",this.toggleMenu):"vive-controls"!==this.controller.name&&"windows-motion-controls"!==this.controller.name||t.removeEventListener("menudown",this.toggleMenu)},play:function(){var t=this.el,e=this.handEl;this.controller&&this.addToggleEvent(),t.addEventListener("model-loaded",this.onModelLoaded),t.addEventListener("raycaster-intersection",this.onIntersection),t.addEventListener("raycaster-intersection-cleared",this.onIntersectionCleared),t.addEventListener("raycaster-intersected",this.onIntersected),t.addEventListener("raycaster-intersected-cleared",this.onIntersectedCleared),e&&this.addHandListeners()},pause:function(){var t=this.el,e=this.handEl;this.controller&&this.removeToggleEvent(),t.removeEventListener("raycaster-intersection",this.onIntersection),t.removeEventListener("raycaster-intersection-cleared",this.onIntersectionCleared),t.removeEventListener("raycaster-intersected",this.onIntersected),t.removeEventListener("raycaster-intersected-cleared",this.onIntersectedCleared),e&&this.removeHandListeners()},onModelLoaded:function(t){function e(t){t.visible=!0;var e={opacity:0},i=new AFRAME.TWEEN.Tween(e).to({opacity:1},500).onUpdate(function(){r.messagesMaterial.opacity=e.opacity}).chain(new AFRAME.TWEEN.Tween(e).to({opacity:0},500).delay(3e3).onComplete(function(){t.visible=!1}).onUpdate(function(){r.messagesMaterial.opacity=e.opacity}));i.start()}var i=this.uiEl,s=i.getObject3D("mesh");if(s=t.detail.model,"obj"===t.detail.format&&s.getObjectByName("brightnesscursor")){this.objects={},this.objects.brightnessCursor=s.getObjectByName("brightnesscursor"),this.objects.brightnessSlider=s.getObjectByName("brightness"),this.objects.brightnessSlider.geometry.computeBoundingBox(),this.objects.previousPage=s.getObjectByName("brushprev"),this.objects.nextPage=s.getObjectByName("brushnext"),this.objects.hueCursor=s.getObjectByName("huecursor"),this.objects.hueWheel=s.getObjectByName("hue"),this.objects.hueWheel.geometry.computeBoundingSphere(),this.colorWheelSize=this.objects.hueWheel.geometry.boundingSphere.radius,this.objects.sizeCursor=s.getObjectByName("size"),this.objects.sizeCursor.position.copy(this.cursorOffset),this.objects.colorHistory=[];for(var n=0;n<7;n++)this.objects.colorHistory[n]=s.getObjectByName("colorhistory"+n);this.objects.currentColor=s.getObjectByName("currentcolor"),this.objects.sizeSlider=s.getObjectByName("sizebg"),this.objects.sizeSlider.geometry.computeBoundingBox(),s.getObjectByName("bb").material=new THREE.MeshBasicMaterial({color:2395940,alphaTest:0,visible:!1});var r=this;this.messagesMaterial=new THREE.MeshBasicMaterial({map:null,transparent:!0,opacity:0}),this.objects.messageSave=s.getObjectByName("msg_save"),this.objects.messageSave.material=this.messagesMaterial,this.objects.messageSave.visible=!1,this.objects.messageError=s.getObjectByName("msg_error"),this.objects.messageError.visible=!1,this.objects.messageError.material=this.messagesMaterial;var o="assets/images/messages.png";this.el.sceneEl.systems.material.loadTexture(o,{src:o},function(t){var e=r.messagesMaterial;e.map=t,e.needsUpdate=!0}),this.el.sceneEl.addEventListener("drawing-upload-completed",function(t){e(r.objects.messageSave)}),this.el.sceneEl.addEventListener("drawing-upload-error",function(t){e(r.objects.messageError)}),this.initColorWheel(),this.initColorHistory(),this.initBrushesMenu(),this.setCursorTransparency(),this.updateColorUI(this.el.getAttribute("brush").color),this.updateSizeSlider(this.el.getAttribute("brush").size)}},initBrushesMenu:function(){var t=this.objects.previousPage,e=this.objects.nextPage,i=Object.keys(AFRAME.BRUSHES);this.initHighlightMaterial(e),this.initHighlightMaterial(t),t.visible=!1,e.visible=!1,this.brushesPerPage=15,this.brushesPagesNum=Math.ceil(i.length/this.brushesPerPage),this.brushesPage=0,this.loadBrushes(this.brushesPage,this.brushesPerPage)},setCursorTransparency:function(){var t=this.objects.hueCursor,e=this.objects.brightnessCursor,i=this.objects.sizeCursor;i.material.alphaTest=.5,t.material.alphaTest=.5,e.material.alphaTest=.5,i.material.transparent=!0,t.material.transparent=!0,e.material.transparent=!0},loadBrushes:function(){var t={};return function(e,i){function s(e,i,s){function r(t){var e=c.getObjectByName("brush"+i);d.brushButtonsMapping["brush"+i]=o,n(t,e)}var o=e?(e.charAt(0).toUpperCase()+e.slice(1)).toLowerCase():void 0;return s&&!t[o]?void d.el.sceneEl.systems.material.loadTexture(s,{src:s},r):void r()}function n(e,i){var s=d.brushButtonsMapping[i.name],n=t[s]||new THREE.MeshBasicMaterial;e?(n.map=e,n.alphaTest=.5,n.transparent=!0):t[s]||(n.visible=!1),t[s]=n,d.highlightMaterials[i.name]={normal:n,hover:n,pressed:n,selected:n},i.material=n}var r,o,a,h,l=0,c=this.uiEl.getObject3D("mesh"),u=Object.keys(AFRAME.BRUSHES),d=this;if(!(e<0||e>=this.brushesPagesNum))for(0===e?this.objects.previousPage.visible=!1:this.objects.previousPage.visible=!0,e===this.brushesPagesNum-1?this.objects.nextPage.visible=!1:this.objects.nextPage.visible=!0,h=0;h<i;h++)a=e*i+h,r=u[a],o=r&&AFRAME.BRUSHES[r].prototype.options.thumbnail,s(r,l,o),l+=1}}(),nextPage:function(){this.brushesPage>=this.brushesPagesNum-1||(this.brushesPage++,this.loadBrushes(this.brushesPage,this.brushesPerPage))},previousPage:function(){0!==this.brushesPage&&(this.brushesPage--,this.loadBrushes(this.brushesPage,this.brushesPerPage))},initHighlightMaterial:function(t){var e=t.name,i=this.brushRegexp.test(e),s=e.indexOf("history")!==-1,n="hue"===e||"huecursor"===e,r={normal:t.material,hover:t.material,pressed:t.material,selected:t.material};i||s||n||(r.normal=t.material,r.hover=t.material.clone(),r.hover.map=this.system.hoverTexture,r.selected=t.material.clone(),r.selected.map=this.system.pressedTexture,r.pressed=t.material.clone(),r.pressed.map=this.system.pressedTexture),this.highlightMaterials[e]=r},toggleMenu:function(t){this.closed?(this.system.closeAll(),this.open(),this.system.opened=this.el):(this.close(),this.system.opened=void 0)},open:function(){var t,e=this.uiEl,i={x:0,y:0,z:0};this.closed&&(this.uiEl.setAttribute("visible",!0),t=new AFRAME.TWEEN.Tween(i).to({x:1,y:1,z:1},100).onUpdate(function(){e.setAttribute("scale",this)}).easing(AFRAME.TWEEN.Easing.Exponential.Out),t.start(),this.el.setAttribute("brush","enabled",!1),this.rayEl.setAttribute("visible",!1),this.closed=!1)},updateIntersections:function(){var t=this.raycaster=new THREE.Raycaster;return function(e){this.updateRaycaster(t),this.intersectedObjects=t.intersectObjects(this.menuEls,!0)}}(),onIntersection:function(t){var e=this.closed&&this.system.opened;this.el.components.brush.active||(this.rayEl.setAttribute("visible",!!e),this.el.setAttribute("brush","enabled",!1))},onIntersected:function(t){var e=t.detail.el;this.handEl&&this.removeHandListeners(),this.handEl=e,this.handRayEl=this.handEl.components.ui.rayEl,this.menuEls=this.uiEl.object3D.children,this.syncUI(),this.addHandListeners()},addHandListeners:function(){var t=this.handEl;t.addEventListener("componentchanged",this.onComponentChanged),t.addEventListener("stroke-started",this.onStrokeStarted),t.addEventListener("triggerchanged",this.onTriggerChanged)},removeHandListeners:function(){var t=this.handEl;t.removeEventListener("componentchanged",this.onComponentChanged),t.removeEventListener("stroke-started",this.onStrokeStarted),t.removeEventListener("triggerchanged",this.onTriggerChanged)},onComponentChanged:function(t){"brush"===t.detail.name&&this.syncUI()},syncUI:function(){var t;this.handEl&&this.objects&&(t=this.handEl.getAttribute("brush"),this.updateSizeSlider(t.size),this.updateColorUI(t.color),this.updateColorHistory())},initColorHistory:function(){for(var t,e=this.objects.currentColor,i=0;i<this.objects.colorHistory.length;i++)t=this.objects.colorHistory[i],t.material=t.material.clone(),t.material.map=this.system.selectedTexture;e.material=e.material.clone(),e.material.map=this.system.selectedTexture,this.updateColorHistory()},updateColorHistory:function(){var t=this.handEl&&this.handEl.getAttribute("brush").color,e=this.colorStack;t||(t=this.el.components.brush.schema.color.default),this.objects.currentColor.material.color.set(t);for(var i=0;i<e.length;i++)t=e[e.length-i-1],this.objects.colorHistory[i].material.color.set(t)},updateSizeSlider:function(t){var e=this.objects.sizeSlider,i=e.geometry.boundingBox,s=this.objects.sizeCursor,n=i.max.x-i.min.x,r=t/AFRAME.components.brush.schema.size.max,o=r*n;s.position.setX(o-this.cursorOffset.x);var a=r+.3;s.scale.set(a,1,a)},updateColorUI:function(t){var e=new THREE.Color(t),i=this.hsv=this.rgb2hsv(e.r,e.g,e.b),s=2*i.h*Math.PI,n=i.s*this.colorWheelSize,r=n*Math.cos(s),o=n*Math.sin(s);this.objects.hueCursor.position.setX(r),this.objects.hueCursor.position.setZ(-o),this.objects.hueWheel.material.uniforms.brightness.value=this.hsv.v,this.objects.brightnessCursor.rotation.y=1.5*this.hsv.v-1.5},updateBrushSelector:function(t){var e=this,i=Object.keys(this.brushButtonsMapping),s=this.brushButtonsMapping;i.forEach(function(i){s[i]===t&&e.selectBrushButton(i)})},onIntersectionCleared:function(){this.checkMenuIntersections=!1,this.rayEl.setAttribute("visible",!1),this.el.setAttribute("brush","enabled",!0)},onIntersectedCleared:function(t){this.handEl&&this.handEl.removeEventListener("triggerchanged",this.onTriggerChanged)},onStrokeStarted:function(){var t,e=this.colorStack;this.colorHasChanged&&(t=this.handEl.getAttribute("brush").color,this.colorHasChanged=!1,7===e.length&&e.shift(),e.push(t),this.syncUI())},updateRaycaster:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Vector3,s=new THREE.Vector3;return function(n){var r=this.handEl.object3D;r.updateMatrixWorld(),r.matrixWorld.decompose(s,e,i),t.set(0,0,-1),t.applyAxisAngle(new THREE.Vector3(1,0,0),2*-(this.rayAngle/360)*Math.PI),t.applyQuaternion(e),n.far=this.rayDistance,n.set(s,t)}}(),close:function(){var t,e=this.uiEl,i={x:1,y:1,z:1};this.closed||(t=new AFRAME.TWEEN.Tween(i).to({x:0,y:0,z:0},100).onUpdate(function(){e.setAttribute("scale",this)}).onComplete(function(){e.setAttribute("visible",!1)}).easing(AFRAME.TWEEN.Easing.Exponential.Out),t.start(),this.el.setAttribute("brush","enabled",!0),this.closed=!0)}})},function(t,e){AFRAME.registerComponent("ui-raycaster",{schema:{far:{default:1/0},interval:{default:100},near:{default:0},objects:{default:""},recursive:{default:!0},rotation:{default:0}},init:function(){this.direction=new THREE.Vector3,this.intersectedEls=[],this.objects=null,this.prevCheckTime=void 0,this.raycaster=new THREE.Raycaster,this.updateOriginDirection(),this.refreshObjects=this.refreshObjects.bind(this)},play:function(){this.el.sceneEl.addEventListener("child-attached",this.refreshObjects),this.el.sceneEl.addEventListener("child-detached",this.refreshObjects)},pause:function(){this.el.sceneEl.removeEventListener("child-attached",this.refreshObjects),this.el.sceneEl.removeEventListener("child-detached",this.refreshObjects)},update:function(){var t=this.data,e=this.raycaster;e.far=t.far,e.near=t.near,this.refreshObjects()},refreshObjects:function(){var t,e,i=this.data;if(i.objects)for(e=this.el.sceneEl.querySelectorAll(i.objects),this.objects=[],t=0;t<e.length;t++)this.objects.push(e[t].object3D);else this.objects=this.el.sceneEl.object3D.children},tick:function(t){var e,i,s,n=this.el,r=this.data,o=this.prevCheckTime;o&&t-o<r.interval||(s=this.intersectedEls.slice(),this.updateOriginDirection(),i=this.raycaster.intersectObjects(this.objects,r.recursive),i=i.filter(function(t){return!!t.object.el}),e=this.intersectedEls=i.map(function(t){return t.object.el}),i.forEach(function(t){var e=t.object.el;e.emit("raycaster-intersected",{el:n,intersection:t})}),i.length&&n.emit("raycaster-intersection",{els:e,intersections:i}),s.forEach(function(t){e.indexOf(t)===-1&&(n.emit("raycaster-intersection-cleared",{el:t}),t.emit("raycaster-intersected-cleared",{el:n}))}))},updateOriginDirection:function(){var t=new THREE.Quaternion,e=new THREE.Vector3,i=new THREE.Vector3;return function(){var s=this.el,n=this.direction,r=s.object3D;r.updateMatrixWorld(),r.matrixWorld.decompose(e,t,i),n.set(0,0,-1),n.applyAxisAngle(new THREE.Vector3(1,0,0),this.data.rotation/360*2*Math.PI),n.applyQuaternion(t),this.raycaster.set(e,n)}}()})},function(t,e){!function(){for(var t={init:function(t,e){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.normals=new Float32Array(3*this.options.maxPoints*3),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.geometry.setDrawRange(0,0),this.geometry.addAttribute("position",new THREE.BufferAttribute(this.vertices,3).setDynamic(!0)),this.geometry.addAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setDynamic(!0)),this.geometry.addAttribute("normal",new THREE.BufferAttribute(this.normals,3).setDynamic(!0));var i=new THREE.Mesh(this.geometry,this.getMaterial());i.drawMode=THREE.TriangleStripDrawMode,i.frustumCulled=!1,i.vertices=this.vertices,this.object3D.add(i)},getMaterial:function(){var t=this.materialOptions.map,e=this.materialOptions.type,i={},s={};t&&(s={map:t,transparent:!0,alphaTest:.5}),i="shaded"===e?{color:this.data.color,roughness:.75,metalness:.25,side:THREE.DoubleSide}:{color:this.data.color,side:THREE.DoubleSide};var n=Object.assign(i,s,this.materialOptions);return delete n.type,"shaded"===e?new THREE.MeshStandardMaterial(n):new THREE.MeshBasicMaterial(n)},addPoint:function(t,e,i,n,r){var o=0;for(s=0;s<this.data.numPoints;s++)this.uvs[o++]=s/(this.data.numPoints-1),this.uvs[o++]=0,this.uvs[o++]=s/(this.data.numPoints-1),this.uvs[o++]=1;var a=new THREE.Vector3;a.set(1,0,0),a.applyQuaternion(e),a.normalize();var h=i.clone(),l=i.clone(),c=this.data.size*n;return h.add(a.clone().multiplyScalar(c/2)),l.add(a.clone().multiplyScalar(-c/2)),this.vertices[this.idx++]=h.x,this.vertices[this.idx++]=h.y,this.vertices[this.idx++]=h.z,this.vertices[this.idx++]=l.x,this.vertices[this.idx++]=l.y,this.vertices[this.idx++]=l.z,this.computeVertexNormals(),this.geometry.attributes.normal.needsUpdate=!0,this.geometry.attributes.position.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints),!0},computeVertexNormals:function(){for(var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,s=new THREE.Vector3,n=new THREE.Vector3,r=0,o=this.idx;r<o;r++)this.normals[r]=0;var a=!0;for(r=0,o=this.idx;r<o;r+=3)a?(t.fromArray(this.vertices,r),e.fromArray(this.vertices,r+3),i.fromArray(this.vertices,r+6)):(t.fromArray(this.vertices,r+3),e.fromArray(this.vertices,r),i.fromArray(this.vertices,r+6)),a=!a,s.subVectors(i,e),n.subVectors(t,e),s.cross(n),s.normalize(),this.normals[r]+=s.x,this.normals[r+1]+=s.y,this.normals[r+2]+=s.z,this.normals[r+3]+=s.x,this.normals[r+4]+=s.y,this.normals[r+5]+=s.z,this.normals[r+6]+=s.x,this.normals[r+7]+=s.y,this.normals[r+8]+=s.z;for(r=6,o=this.idx-6;r<o;r++)this.normals[r]=this.normals[r]/3;this.normals[3]=this.normals[3]/2,this.normals[4]=this.normals[4]/2,this.normals[5]=this.normals[5]/2,this.normals[this.idx-6]=this.normals[this.idx-6]/2,this.normals[this.idx-6+1]=this.normals[this.idx-6+1]/2,this.normals[this.idx-6+2]=this.normals[this.idx-6+2]/2,this.geometry.normalizeNormals()}},e=[{name:"flat",materialOptions:{type:"flat"},thumbnail:"brushes/thumb_flat.gif"},{name:"smooth",materialOptions:{type:"shaded"},thumbnail:"brushes/thumb_smooth.gif"},{name:"squared-textured",materialOptions:{type:"textured",textureSrc:"brushes/squared_textured.png"},thumbnail:"brushes/thumb_squared_textured.gif"},{name:"line-gradient",materialOptions:{type:"textured",textureSrc:"brushes/line_gradient.png"},thumbnail:"brushes/thumb_line_gradient.gif"},{name:"silky-flat",materialOptions:{type:"textured",textureSrc:"brushes/silky_flat.png"},thumbnail:"brushes/thumb_silky_flat.gif"},{name:"silky-textured",materialOptions:{type:"textured",textureSrc:"brushes/silky_textured.png"},thumbnail:"brushes/thumb_silky_textured.gif"},{name:"lines1",materialOptions:{type:"textured",textureSrc:"brushes/lines1.png"},thumbnail:"brushes/thumb_lines1.gif"},{name:"lines2",materialOptions:{type:"textured",textureSrc:"brushes/lines2.png"},thumbnail:"brushes/thumb_lines2.gif"},{name:"lines3",materialOptions:{type:"textured",textureSrc:"brushes/lines3.png"},thumbnail:"brushes/thumb_lines3.gif"},{name:"lines4",materialOptions:{type:"textured",textureSrc:"brushes/lines4.png"},thumbnail:"brushes/thumb_lines4.gif"},{name:"lines5",materialOptions:{type:"textured",textureSrc:"brushes/lines5.png"},thumbnail:"brushes/thumb_lines5.gif"},{name:"line-grunge1",materialOptions:{type:"textured",textureSrc:"brushes/line_grunge1.png"},thumbnail:"brushes/thumb_line_grunge1.gif"},{name:"line-grunge2",materialOptions:{type:"textured",textureSrc:"brushes/line_grunge2.png"},thumbnail:"brushes/thumb_line_grunge2.gif"},{name:"line-grunge3",materialOptions:{type:"textured",textureSrc:"brushes/line_grunge3.png"},thumbnail:"brushes/thumb_line_grunge3.gif"}],i=new THREE.TextureLoader,s=0;s<e.length;s++){var n=e[s];n.materialOptions.textureSrc&&(n.materialOptions.map=i.load(n.materialOptions.textureSrc),delete n.materialOptions.textureSrc),AFRAME.registerBrush(n.name,Object.assign({},t,{materialOptions:n.materialOptions}),{thumbnail:n.thumbnail,maxPoints:3e3})}}()},function(t,e){!function(){for(var t={init:function(t,e){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3*2),this.normals=new Float32Array(3*this.options.maxPoints*3*2),this.uvs=new Float32Array(2*this.options.maxPoints*3*2),this.geometry.setDrawRange(0,0),this.geometry.addAttribute("position",new THREE.BufferAttribute(this.vertices,3).setDynamic(!0)),this.geometry.addAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setDynamic(!0)),this.geometry.addAttribute("normal",new THREE.BufferAttribute(this.normals,3).setDynamic(!0));
var i=new THREE.Mesh(this.geometry,this.getMaterial());this.currAngle=0,this.subTextures=1,this.angleJitter=0,this.autoRotate=!1,void 0!==this.materialOptions.subTextures&&(this.subTextures=this.materialOptions.subTextures),this.materialOptions.autoRotate===!0&&(this.autoRotate=!0),void 0!==this.materialOptions.angleJitter&&(this.angleJitter=this.materialOptions.angleJitter,this.angleJitter=2*this.angleJitter-this.angleJitter),i.frustumCulled=!1,i.vertices=this.vertices,this.object3D.add(i)},getMaterial:function(){var t=this.materialOptions.map,e=this.materialOptions.type;return"shaded"===e?new THREE.MeshStandardMaterial({color:this.data.color,side:THREE.DoubleSide,map:t,transparent:!0,alphaTest:.5,roughness:.75,metalness:.25}):new THREE.MeshBasicMaterial({color:this.data.color,side:THREE.DoubleSide,map:t,transparent:!0,alphaTest:.5})},addPoint:function(t,e,i,s,n){var r=Math.PI/2,o=new THREE.Vector3;o.set(1,0,0),o.applyQuaternion(e),o.normalize();var a=new THREE.Vector3;a.set(0,1,0),a.applyQuaternion(e),a.normalize();var h=this.data.size*s/2,l=Math.PI/4+Math.random()*this.angleJitter;this.autoRotate&&(this.currAngle+=.1,l+=this.currAngle);var c=i.clone().add(o.applyAxisAngle(a,l).clone().multiplyScalar(h)),u=i.clone().add(o.applyAxisAngle(a,r).clone().multiplyScalar(h)),d=i.clone().add(o.applyAxisAngle(a,r).clone().multiplyScalar(h)),m=i.clone().add(o.applyAxisAngle(a,r).multiplyScalar(h)),p=this.idx;this.vertices[this.idx++]=c.x,this.vertices[this.idx++]=c.y,this.vertices[this.idx++]=c.z,this.vertices[this.idx++]=u.x,this.vertices[this.idx++]=u.y,this.vertices[this.idx++]=u.z,this.vertices[this.idx++]=d.x,this.vertices[this.idx++]=d.y,this.vertices[this.idx++]=d.z,this.vertices[this.idx++]=d.x,this.vertices[this.idx++]=d.y,this.vertices[this.idx++]=d.z,this.vertices[this.idx++]=m.x,this.vertices[this.idx++]=m.y,this.vertices[this.idx++]=m.z,this.vertices[this.idx++]=c.x,this.vertices[this.idx++]=c.y,this.vertices[this.idx++]=c.z;for(var b=0;b<6;b++)this.normals[p++]=a.x,this.normals[p++]=a.y,this.normals[p++]=a.z;var g=6*this.data.numPoints*2,f=0,v=1;if(this.subTextures>1){var E=Math.floor(Math.random()*this.subTextures);f=1/this.subTextures*E,v=f+1/this.subTextures}return this.uvs[g++]=f,this.uvs[g++]=1,this.uvs[g++]=f,this.uvs[g++]=0,this.uvs[g++]=v,this.uvs[g++]=0,this.uvs[g++]=v,this.uvs[g++]=0,this.uvs[g++]=v,this.uvs[g++]=1,this.uvs[g++]=f,this.uvs[g++]=1,this.geometry.attributes.normal.needsUpdate=!0,this.geometry.attributes.position.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,6*this.data.numPoints),!0}},e=[{name:"dots",materialOptions:{type:"shaded",textureSrc:"brushes/stamp_dots.png"},thumbnail:"brushes/thumb_stamp_dots.gif",spacing:.01},{name:"squares",materialOptions:{type:"shaded",textureSrc:"brushes/stamp_squares.png"},thumbnail:"brushes/thumb_stamp_squares.gif",spacing:.01},{name:"column",materialOptions:{type:"shaded",autoRotate:!0,textureSrc:"brushes/stamp_column.png"},thumbnail:"brushes/thumb_stamp_column.gif",spacing:.01},{name:"gear1",materialOptions:{type:"shaded",angleJitter:2*Math.PI,subTextures:2,textureSrc:"brushes/stamp_gear.png"},thumbnail:"brushes/thumb_stamp_gear.gif",spacing:.05},{name:"grunge1",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_grunge1.png"},thumbnail:"brushes/stamp_grunge1.png",spacing:.02},{name:"grunge2",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_grunge2.png"},thumbnail:"brushes/stamp_grunge2.png",spacing:.02},{name:"grunge3",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_grunge3.png"},thumbnail:"brushes/stamp_grunge3.png",spacing:.02},{name:"grunge4",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_grunge4.png"},thumbnail:"brushes/stamp_grunge4.png",spacing:.02},{name:"grunge5",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_grunge5.png"},thumbnail:"brushes/thumb_stamp_grunge5.gif",spacing:.02},{name:"leaf1",materialOptions:{type:"shaded",angleJitter:Math.PI,textureSrc:"brushes/stamp_leaf1.png"},thumbnail:"brushes/stamp_leaf1.png",spacing:.03},{name:"leaf2",materialOptions:{type:"shaded",angleJitter:60*Math.PI/180,textureSrc:"brushes/stamp_leaf2.png"},thumbnail:"brushes/thumb_stamp_leaf2.gif",spacing:.03},{name:"leaf3",materialOptions:{type:"shaded",angleJitter:60*Math.PI/180,textureSrc:"brushes/stamp_leaf3.png"},thumbnail:"brushes/thumb_stamp_leaf3.gif",spacing:.03},{name:"fur1",materialOptions:{type:"shaded",angleJitter:40*Math.PI/180,subTextures:2,textureSrc:"brushes/stamp_fur1.png"},thumbnail:"brushes/stamp_fur1.png",spacing:.01},{name:"fur2",materialOptions:{type:"shaded",angleJitter:10*Math.PI/180,subTextures:3,textureSrc:"brushes/stamp_fur2.png"},thumbnail:"brushes/stamp_fur2.png",spacing:.01},{name:"grass",materialOptions:{type:"shaded",angleJitter:10*Math.PI/180,subTextures:3,textureSrc:"brushes/stamp_grass.png"},thumbnail:"brushes/thumb_stamp_grass.png",spacing:.03},{name:"bush",materialOptions:{type:"shaded",subTextures:2,textureSrc:"brushes/stamp_bush.png"},thumbnail:"brushes/thumb_stamp_bush.gif",spacing:.04},{name:"star",materialOptions:{type:"shaded",textureSrc:"brushes/stamp_star.png"},thumbnail:"brushes/thumb_stamp_star.png",spacing:.06},{name:"snow",materialOptions:{type:"shaded",angleJitter:2*Math.PI,textureSrc:"brushes/stamp_snow.png"},thumbnail:"brushes/thumb_stamp_snow.png",spacing:.06}],i=new THREE.TextureLoader,s=0;s<e.length;s++){var n=e[s];n.materialOptions.textureSrc&&(n.materialOptions.map=i.load(n.materialOptions.textureSrc),delete n.materialOptions.textureSrc),AFRAME.registerBrush(n.name,Object.assign({},t,{materialOptions:n.materialOptions}),{thumbnail:n.thumbnail,spacing:n.spacing,maxPoints:3e3})}}()},function(t,e){AFRAME.registerBrush("spheres",{init:function(t,e){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,shading:THREE.FlatShading}),this.geometry=new THREE.IcosahedronGeometry(1,0)},addPoint:function(t,e,i,s,n){var r=new THREE.Mesh(this.geometry,this.material),o=this.data.size/2*s;return r.scale.set(o,o,o),r.initialScale=r.scale.clone(),r.phase=Math.random()*Math.PI*2,r.position.copy(i),r.rotation.copy(e),this.object3D.add(r),!0},tick:function(t,e){for(var i=0;i<this.object3D.children.length;i++){var s=this.object3D.children[i],n=(Math.sin(s.phase+t/500)+1)/2+.1;s.scale.copy(s.initialScale).multiplyScalar(n)}}},{thumbnail:"brushes/thumb_spheres.gif",spacing:.01})},function(t,e){AFRAME.registerBrush("cubes",{init:function(t,e){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,shading:THREE.FlatShading}),this.geometry=new THREE.BoxGeometry(1,1,1)},addPoint:function(t,e,i,s,n){var r=new THREE.Mesh(this.geometry,this.material),o=s*this.data.size*Math.random();return r.scale.set(o,o,o),r.position.copy(i),r.rotation.copy(e),this.object3D.add(r),!0}},{thumbnail:"brushes/thumb_cubes.gif",spacing:.01})},function(t,e){!function(){var t="varying vec2 vUv; \t void main() { \t vUv = uv; \t gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); \t }",e="uniform sampler2D tDiffuse; \t uniform float amount; \t uniform float time; \t varying vec2 vUv; \t \t vec3 hsv2rgb(vec3 c) { \t vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); \t vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); \t return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); \t } \t \t void main() { \t float h = mod(vUv.x - time / 3000.0, 1.0); \t vec4 color = vec4(hsv2rgb(vec3(h, 1.0, 0.5)), 1.0); \t gl_FragColor = color; \t }",s=new THREE.ShaderMaterial({vertexShader:t,fragmentShader:e,side:THREE.DoubleSide,uniforms:{time:{type:"f",value:0}}});AFRAME.registerBrush("line-rainbow",{init:function(t,e){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.linepositions=new Float32Array(this.options.maxPoints),this.geometry.setDrawRange(0,0),this.geometry.addAttribute("position",new THREE.BufferAttribute(this.vertices,3).setDynamic(!0)),this.geometry.addAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setDynamic(!0)),this.geometry.addAttribute("lineposition",new THREE.BufferAttribute(this.linepositions,1).setDynamic(!0)),this.material=s;var i=new THREE.Mesh(this.geometry,this.material);i.drawMode=THREE.TriangleStripDrawMode,i.frustumCulled=!1,i.vertices=this.vertices,this.object3D.add(i)},addPoint:function(t,e,s,n,r){var o=0;for(i=0;i<this.data.numPoints;i++)this.uvs[o++]=i/(this.data.numPoints-1),this.uvs[o++]=0,this.uvs[o++]=i/(this.data.numPoints-1),this.uvs[o++]=1;var a=new THREE.Vector3;a.set(1,0,0),a.applyQuaternion(e),a.normalize();var h=s.clone(),l=s.clone(),c=this.data.size*n;return h.add(a.clone().multiplyScalar(c/2)),l.add(a.clone().multiplyScalar(-c/2)),this.vertices[this.idx++]=h.x,this.vertices[this.idx++]=h.y,this.vertices[this.idx++]=h.z,this.vertices[this.idx++]=l.x,this.vertices[this.idx++]=l.y,this.vertices[this.idx++]=l.z,this.geometry.attributes.position.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints),!0},tick:function(t,e){this.material.uniforms.time.value=t}},{thumbnail:"brushes/thumb_rainbow.png",maxPoints:3e3})}()},function(t,e){AFRAME.registerBrush("single-sphere",{init:function(t,e){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.6,metalness:.2,side:THREE.FrontSide,shading:THREE.SmoothShading}),this.geometry=new THREE.IcosahedronGeometry(1,2),this.mesh=new THREE.Mesh(this.geometry,this.material),this.object3D.add(this.mesh),this.mesh.visible=!1},addPoint:function(t,e,i,s,n){this.firstPoint||(this.firstPoint=i.clone(),this.mesh.position.set(this.firstPoint.x,this.firstPoint.y,this.firstPoint.z)),this.mesh.visible=!0;var r=this.firstPoint.distanceTo(i);return this.mesh.scale.set(r,r,r),!0}},{thumbnail:"brushes/thumb_single_sphere.png",spacing:0})}]);