From fd1230a1ac8da27f9562f409b4800bafb494a916 Mon Sep 17 00:00:00 2001 From: Pawel Golinski Date: Mon, 5 Sep 2022 17:01:18 +0200 Subject: [PATCH 1/3] exchange undo/paint --- build.js | 2 +- src/systems/painter.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.js b/build.js index f3bd1301..08e4b570 100644 --- a/build.js +++ b/build.js @@ -1 +1 @@ -(()=>{var e={453:(e,t,s)=>{const i=s(95);function r(){this.map=(new THREE.TextureLoader).load("assets/images/"+i.meta.image)}r.prototype={getUVConverters:function(e){return e?(e=e.replace("brushes/",""),{convertU:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),r.frame.x/s.w+t*r.frame.w/s.w},convertV:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),1-(r.frame.y/s.h+t*r.frame.h/s.h)}}):{convertU:function(e){return e},convertV:function(e){return e}}}},window.atlas=new r},967:()=>{window.BinaryManager=function(e){this.dataview=new DataView(e),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 e=this.dataview.getUint8(this.offset++,!0),t="",s=0;s{AFRAME.registerBrush("cubes",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.BoxGeometry(1,1,1),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=i*this.data.size*Math.random();return a.scale.set(n,n,n),a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_cubes.gif",spacing:.01})},295:(e,t,s)=>{var i=s(297),r=s(51);!function(){r((function(){var e={vertexColors:THREE.VertexColors,side:THREE.DoubleSide},t={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,map:window.atlas.map,side:THREE.DoubleSide},s={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,side:THREE.DoubleSide,map:window.atlas.map,transparent:!0,alphaTest:.5};i.addSharedBuffer("strip-flat",new THREE.MeshBasicMaterial(e)),i.addSharedBuffer("strip-shaded",new THREE.MeshStandardMaterial(t)),i.addSharedBuffer("strip-textured",new THREE.MeshStandardMaterial(s))}));for(var e,t,s,a,n,o,h={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("strip-"+this.materialOptions.type),this.sharedBuffer.restartPrimitive(),this.sharedBuffer.strip=!0,this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.first=!0},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(o=new THREE.Vector3,function(e,t,s,i,r){var a=this.materialOptions.converter;o.set(1,0,0),o.applyQuaternion(t),o.normalize();var n=s.clone(),h=s.clone(),u=this.data.size*i;if(n.add(o.clone().multiplyScalar(u/2)),h.add(o.clone().multiplyScalar(-u/2)),this.first&&this.prevIdx.position>0&&(this.first=!1,this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.idx.normal++,this.sharedBuffer.idx.color++,this.sharedBuffer.idx.uv++,this.idx=Object.assign({},this.sharedBuffer.idx)),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(h.x,h.y,h.z),this.sharedBuffer.idx.normal+=2,this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),"textured"===this.materialOptions.type){this.sharedBuffer.idx.uv+=2;for(var l,d,c=this.sharedBuffer.current.attributes.uv.array,m=0;m{var e,t,s,r,a;a=new THREE.ShaderMaterial({vertexShader:"varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }",fragmentShader:"uniform sampler2D tDiffuse; uniform float amount; uniform float time; varying vec2 vUv; vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } void main() { float h = mod(vUv.x - time / 3000.0, 1.0); vec4 color = vec4(hsv2rgb(vec3(h, 1.0, 0.5)), 1.0); gl_FragColor = color; }",side:THREE.DoubleSide,uniforms:{time:{type:"f",value:0}}}),AFRAME.registerBrush("line-rainbow",{init:function(e,t){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.indices=new Uint32Array(4.5*this.options.maxPoints*4.5),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.linepositions=new Float32Array(this.options.maxPoints),this.geometry.setDrawRange(0,0),this.geometry.setAttribute("position",new THREE.BufferAttribute(this.vertices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setIndex(new THREE.BufferAttribute(this.indices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("lineposition",new THREE.BufferAttribute(this.linepositions,1).setUsage(THREE.DynamicDrawUsage)),this.material=a;var s=new THREE.Mesh(this.geometry,this.material);s.frustumCulled=!1,s.vertices=this.vertices,this.object3D.add(s),this.drawing=document.querySelector(".a-drawing"),this.drawing.object3D.add(this.object3D)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,r=new THREE.Vector3,function(a,n,o,h,u){var l=0;for(i=0;i6&&(this.geometry.index.setXYZ(this.idx/3-4,this.idx/3-4,this.idx/3-3,this.idx/3-2),this.geometry.index.setXYZ(this.idx/3-3,this.idx/3-2,this.idx/3-3,this.idx/3-1)),this.geometry.attributes.position.needsUpdate=!0,this.geometry.index.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints*6),!0}),tick:function(e,t){this.material.uniforms.time.value=e},undo:function(){this.drawing.object3D.children.pop()}},{thumbnail:"brushes/thumb_rainbow.png",maxPoints:3e3})},891:()=>{AFRAME.registerBrush("single-sphere",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.6,metalness:.2,side:THREE.FrontSide,flatShading:!0}),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,this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){this.firstPoint||(this.firstPoint=s.clone(),this.mesh.position.set(this.firstPoint.x,this.firstPoint.y,this.firstPoint.z)),this.mesh.visible=!0;var a=this.firstPoint.distanceTo(s);return this.mesh.scale.set(a,a,a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_single_sphere.png",spacing:0})},988:()=>{AFRAME.registerBrush("spheres",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.IcosahedronGeometry(1,0),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=this.data.size/2*i;return a.scale.set(n,n,n),a.initialScale=a.scale.clone(),a.phase=Math.random()*Math.PI*2,a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},tick:function(e,t){for(var s=0;s{var i=s(297),r=s(51);!function(){r((function(){var e=new THREE.MeshStandardMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5,roughness:.75,metalness:.25}),t=new THREE.MeshBasicMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5});i.addSharedBuffer("tris-flat",t),i.addSharedBuffer("tris-shaded",e)}));for(var e,t,s,a,n,o,h,u,l={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("tris-"+this.materialOptions.type),this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.strip=!1,this.currAngle=0,this.subTextures=1,this.angleJitter=0,this.autoRotate=!1,void 0!==this.materialOptions.subTextures&&(this.subTextures=this.materialOptions.subTextures),!0===this.materialOptions.autoRotate&&(this.autoRotate=!0),void 0!==this.materialOptions.angleJitter&&(this.angleJitter=this.materialOptions.angleJitter,this.angleJitter=2*this.angleJitter-this.angleJitter)},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,a=new THREE.Vector3,n=new THREE.Vector3,o=new THREE.Vector3,h=new THREE.Vector3,u=Math.PI/2,function(i,r,l,d,c){t.set(1,0,0),t.applyQuaternion(r),t.normalize(),e.set(0,1,0),e.applyQuaternion(r),e.normalize();var m=this.data.size*d/2,p=Math.PI/4+Math.random()*this.angleJitter;this.autoRotate&&(this.currAngle+=.1,p+=this.currAngle),s.copy(l).add(h.copy(t.applyAxisAngle(e,p)).multiplyScalar(m)),a.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),n.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),o.copy(l).add(t.applyAxisAngle(e,u).multiplyScalar(m)),this.idx.position,this.idx.position,this.sharedBuffer.addVertex(s.x,s.y,s.z),this.sharedBuffer.addVertex(a.x,a.y,a.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(o.x,o.y,o.z),this.sharedBuffer.addVertex(s.x,s.y,s.z);for(var f=0;f<6;f++)this.sharedBuffer.addNormal(e.x,e.y,e.z),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b);this.data.numPoints;var g=0,b=1;if(this.subTextures>1){var v=Math.floor(Math.random()*this.subTextures);b=(g=1/this.subTextures*v)+1/this.subTextures}var y=this.materialOptions.converter;return this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.update(),!0})},d=[{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}],c=0;c{AFRAME.registerComponent("brush-tip",{schema:{controller:{type:"string"},hand:{type:"string",oneOf:["left","right"]}},init:function(){var e=e=>THREE.MathUtils.degToRad(e);this.controllers={"oculus-touch-controller-v3":{left:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(7),z:e(-7)}},right:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(-7),z:e(7)}}}},this.data.controller&&this.setController(this.data.controller,this.data.hand)},setController:function(e,t){e in this.controllers?(this.el.object3D.position.set(this.controllers[e][t].positionOffset.x,this.controllers[e][t].positionOffset.y,this.controllers[e][t].positionOffset.z),this.el.object3D.rotation.set(this.controllers[e][t].rotationOffset.x,this.controllers[e][t].rotationOffset.y,this.controllers[e][t].rotationOffset.z)):console.error(`${e} is not present in the controllers list!`)}})},620:()=>{var e,t,s;AFRAME.registerComponent("brush",{schema:{color:{type:"color",default:"#ef2d5e"},size:{default:.01,min:.001,max:.3},brush:{default:"smooth"},enabled:{default:!0}},init:function(){var e=this.data;this.color=new THREE.Color(e.color),this.el.emit("brushcolor-changed",{color:this.color}),this.el.emit("brushsize-changed",{brushSize:e.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 t=this;this.el.addEventListener("undo",(function(e){t.data.enabled&&(t.system.undo(),document.getElementById("ui_undo").play())})),this.el.addEventListener("paint",(function(e){if(t.data.enabled){var s=e.detail.value;t.sizeModifier=s,s>.1?t.active||(t.startNewStroke(),t.active=!0):(t.active&&(t.previousEntity=t.currentEntity,t.currentStroke=null),t.active=!1)}})),this.hand="right-hand"===this.el.id?"right":"left"},update:function(e){var t=this.data;e.color!==t.color&&(this.color.set(t.color),this.el.emit("brushcolor-changed",{color:this.color})),e.size!==t.size&&this.el.emit("brushsize-changed",{size:t.size})},tick:(e=new THREE.Vector3,t=new THREE.Quaternion,s=new THREE.Vector3,function(i,r){if(this.currentStroke&&this.active){this.obj.matrixWorld.decompose(e,t,s);var a=this.system.getPointerPosition(e,t,this.hand);this.currentStroke.addPoint(e,t,a,this.sizeModifier,i)}}),startNewStroke:function(){document.getElementById("ui_paint").play(),this.currentStroke=this.system.addNewStroke(this.data.brush,this.color,this.data.size),this.el.emit("stroke-started",{entity:this.el,stroke:this.currentStroke})}})},510:()=>{AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"}},init:function(){this.objectLoader=new THREE.ObjectLoader,this.objectLoader.setCrossOrigin("")},update:function(e){var t=this,s=this.data.src;s&&s!==e.src&&this.objectLoader.load(this.data.src,(function(e){var i=(new THREE.Matrix4).makeRotationX(-Math.PI/2);e.traverse((function(e){e instanceof THREE.Mesh&&e.position.applyMatrix4(i)})),t.el.setObject3D("mesh",e),t.el.emit("model-loaded",{format:"json",model:e,src:s})}))}})},788:()=>{AFRAME.registerComponent("logo-model",{schema:{opacity:{default:1}},init:function(){this.model=null,this.el.setAttribute("obj-model","obj: #logoobj; mtl: #logomtl"),this.el.addEventListener("model-loaded",this.setModel.bind(this))},setModel:function(e){this.model=e.detail.model},update:function(){null!=this.model&&(this.model.children[0].material.opacity=this.data.opacity)}})},101:()=>{AFRAME.registerSystem("paint-controls",{numberStrokes:0}),AFRAME.registerComponent("paint-controls",{dependencies:["brush"],schema:{hand:{default:"left"}},init:function(){var e=this.el,t=this,s="assets/images/controller-pressed.png",i=null;this.controller=null,this.modelLoaded=!1,this.onEnterVR=this.onEnterVR.bind(this),e.sceneEl.addEventListener("enter-vr",this.onEnterVR),e.object3D.visible=!1,this.onModelLoaded=this.onModelLoaded.bind(this),e.addEventListener("model-loaded",this.onModelLoaded),e.addEventListener("changeBrushSizeAbs",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=(s.detail.axis[1]||s.detail.axis[3])/300,r=e.components.brush.schema.size,a=THREE.Math.clamp(t.el.getAttribute("brush").size-i,r.min,r.max);t.el.setAttribute("brush","size",a)}})),e.addEventListener("changeBrushSizeInc",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=s.detail.axis[1]||s.detail.axis[3];t.touchStarted&&(t.touchStarted=!1,t.startAxis=(i+1)/2);var r=(i+1)/2,a=(t.startAxis-r)/2;t.startAxis=r;var n=t.el.getAttribute("brush").size,o=e.components.brush.schema.size,h=THREE.Math.clamp(n-a,o.min,o.max);t.el.setAttribute("brush","size",h)}})),t.touchStarted=!1,e.addEventListener("startChangeBrushSize",(function(){t.touchStarted=!0})),e.addEventListener("controllerconnected",(function(s){var r=s.detail.name,a=s.detail.component.data.hand;const n=(s,i)=>{this.brushTip=document.createElement("a-entity"),this.brushTip.id=`${i}-tip`,this.brushTip.setAttribute("gltf-model","#tipObj"),this.brushTip.setAttribute("brush-tip",`controller: ${s}; hand: ${i}`),this.brushTip.addEventListener("model-loaded",t.onModelLoaded),e.appendChild(this.brushTip)};if("windows-motion-controls"===r){var o=s.detail.component.el.components["gltf-model"].data;const e="045E-065D";o&&o.indexOf(e)>=0&&(r="windows-motion-samsung-controls")}if(i=Utils.getTooltips(r),r.indexOf("windows-motion")>=0);else if("oculus-touch-controls"===r){const t=e.components[r].displayModel[a].modelUrl;n(/[^\/]*(?=-(?:left|right)\.)/.exec(t)[0],a)}else{if("vive-controls"!==r)return;e.setAttribute("gltf-model","url(assets/models/vive-controller.glb)")}i&&i.forEach((function(e){e.setAttribute("visible",!0);Array.prototype.slice.call(e.querySelectorAll("[tooltip]")).forEach((function(e){e.setAttribute("animation",{dur:1e3,delay:2e3,property:"tooltip.opacity",from:1,to:0,startEvents:"tooltip-fade"})}))})),this.controller=r})),e.addEventListener("brushsize-changed",(function(e){t.changeBrushSize(e.detail.size)})),e.addEventListener("brushcolor-changed",(function(e){t.changeBrushColor(e.detail.color)})),e.sceneEl.systems.material.loadTexture(s,{src:s},(function(e){var s=t.highLightMaterial=new THREE.MeshBasicMaterial;s.map=e,s.needsUpdate=!0})),this.startAxis=0,this.numberStrokes=0,document.addEventListener("stroke-started",(function(e){if(e.detail.entity.components["paint-controls"]===t&&(t.numberStrokes++,t.system.numberStrokes++,3===t.system.numberStrokes)){Array.prototype.slice.call(document.querySelectorAll("[tooltip]")).forEach((function(e){e.emit("tooltip-fade")}))}}))},changeBrushColor:function(e){this.modelLoaded&&this.buttonMeshes.sizeHint&&(this.buttonMeshes.colorTip.material.color.copy(e),this.buttonMeshes.sizeHint.material.color.copy(e))},changeBrushSize:function(e){var t=e/2*10;this.modelLoaded&&this.buttonMeshes.sizeHint&&this.buttonMeshes.sizeHint.scale.set(t,1,t)},mapping:{axis0:"trackpad",axis1:"trackpad",button0:"trackpad",button1:"trigger",button2:"grip",button3:"menu",button4:"system"},update:function(){var e=this.data,t=this.el;t.setAttribute("vive-controls",{hand:e.hand,model:!1}),t.setAttribute("oculus-touch-controls",{hand:e.hand,model:!0}),t.setAttribute("windows-motion-controls",{hand:e.hand})},play:function(){},pause:function(){},onEnterVR:function(){this.el.object3D.visible=!0},onModelLoaded:function(e){if((e.target===this.el||e.target.id.includes("-tip"))&&!this.buttonMeshes){var t,s=e.detail.model;(t=this.buttonMeshes={}).sizeHint=s.getObjectByName("sizehint"),t.colorTip=s.getObjectByName("tip"),this.modelLoaded=!0,this.changeBrushSize(this.el.components.brush.data.size),this.changeBrushColor(this.el.components.brush.color)}},onButtonEvent:function(e,t){var s=this.mapping["button"+e];this.el.emit(s+t),this.updateModel(s,t)},updateModel:function(e,t){var s="up"===t?this.material:this.highLightMaterial,i=this.buttonMeshes,r=i&&i[e];if("down"===t&&r&&!this.material&&(s=this.material=r.material),s)return"grip"===e?(i.grip.left.material=s,void(i.grip.right.material=s)):void(r&&(r.material=s))}})},579:()=>{var e,t,s;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 e=this.data,t=this.raycaster;t.far=e.far,t.near=e.near,this.refreshObjects()},refreshObjects:function(){var e,t,s=this.data;if(s.objects)for(t=this.el.sceneEl.querySelectorAll(s.objects),this.objects=[],e=0;e{var e,t,s,i,r,a;AFRAME.registerComponent("ui",{schema:{brightness:{default:1,max:1,min:0},opacity:{default:0}},dependencies:["ui-raycaster"],init:function(){var e=this.el,t=this.uiEl=document.createElement("a-entity"),s=this.rayEl=document.createElement("a-entity");this.closed=!0,this.isTooltipPaused=!1,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),t.setAttribute("material",{color:"#ffffff",flatShading:!0,shader:"flat",transparent:!0,fog:!1,src:"#uinormal"}),t.setAttribute("obj-model","obj:#uiobj"),t.setAttribute("position","0 0.04 -0.15"),t.setAttribute("scale","0 0 0"),t.setAttribute("visible",!1),t.classList.add("apainter-ui"),e.appendChild(t),s.setAttribute("line",""),e.appendChild(s),e.setAttribute("ui-raycaster",{far:this.rayDistance,objects:".apainter-ui",rotation:-this.rayAngle}),this.controller=null;var i=this;e.addEventListener("controllerconnected",(function(s){var r=s.detail.name;i.tooltips=Utils.getTooltips(r),i.controller={name:r,hand:s.detail.component.data.hand},"oculus-touch-controls"===r?(i.uiEl.setAttribute("rotation","45 0 0"),t.setAttribute("position","0 0.13 -0.08"),i.rayAngle=0,e.setAttribute("ui-raycaster",{rotation:0})):"windows-motion-controls"===r&&(i.rayAngle=25,i.rayDistance=1,e.setAttribute("ui-raycaster",{rotation:-30,far:i.rayDistance})),i.el.isPlaying&&i.addToggleEvent()}))},initColorWheel:function(){var e=this.objects.hueWheel,t=new THREE.ShaderMaterial({uniforms:{brightness:{type:"f",value:this.hsv.v}},vertexShader:" varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); gl_Position = projectionMatrix * mvPosition; } ",fragmentShader:" #define M_PI2 6.28318530718\n uniform float brightness; varying vec2 vUv; vec3 hsb2rgb(in vec3 c){ vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); rgb = rgb * rgb * (3.0 - 2.0 * rgb); return c.z * mix( vec3(1.0), rgb, c.y); } void main() { vec2 toCenter = vec2(0.5) - vUv; float angle = atan(toCenter.y, toCenter.x); float radius = length(toCenter) * 2.0; vec3 color = hsb2rgb(vec3((angle / M_PI2) + 0.5, radius, brightness)); gl_FragColor = vec4(color, 1.0); } "});e.material=t},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),this.open=this.open.bind(this),this.close=this.close.bind(this)},tick:function(){!this.closed&&this.handEl&&(this.updateIntersections(),this.handleHover(),this.handlePressedButtons())},update:function(){this.messagesMaterial&&(this.messagesMaterial.opacity=this.data.opacity)},onTriggerChanged:function(e){var t=e.detail.value;this.lastTriggerValue=t,e.detail.value>=.25?this.triggeredPressed=!0:(this.triggeredPressed=!1,this.handleButtonUp())},handleButtonDown:function(e,t){var s=e.name;if(!this.activeWidget||this.activeWidget===s){switch(this.activeWidget=s,!0){case"brightness"===s:this.onBrightnessDown(t);break;case"brushnext"===s:this.pressedObjects[s]||this.nextPage();break;case"brushprev"===s:this.pressedObjects[s]||this.previousPage();break;case"clear"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.brush.clear(),this.playSound("ui_click1"));break;case"copy"===s:this.pressedObjects[s]||(this.copyBrush(),this.playSound("ui_click1"));break;case"hue"===s:this.onHueDown(t);break;case"save"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.painter.upload(),this.playSound("ui_click1"));break;case"sizebg"===s:this.onBrushSizeBackgroundDown(t);break;case this.brushRegexp.test(s):this.onBrushDown(s);break;case this.colorHistoryRegexp.test(s):this.onColorHistoryButtonDown(e);break;default:this.activeWidget=void 0}this.pressedObjects[s]=e}},copyBrush:function(){var e=this.el.getAttribute("brush");this.handEl.setAttribute("brush","brush",e.brush),this.handEl.setAttribute("brush","color",e.color),this.handEl.setAttribute("brush","size",e.size),this.colorHasChanged=!0},handleButtonUp:function(){var e=this.pressedObjects,t=this.unpressedObjects;this.activeWidget=void 0,Object.keys(e).forEach((function(s){var i=e[s].name;t[i]=e[i],delete e[i]}))},handlePressedButtons:function(){var e=this;this.triggeredPressed&&this.hoveredOnObjects.forEach((function(t){e.handleButtonDown(t.object,t.point)}))},onColorHistoryButtonDown:function(e){var t=e.material.color.getHexString();this.handEl.setAttribute("brush","color","#"+t),this.playSound("ui_click0",e.name)},onBrushDown:function(e){var t=this.brushButtonsMapping[e];t&&(this.selectBrushButton(e),this.handEl.setAttribute("brush","brush",t.toLowerCase()))},selectBrushButton:function(e){var t=this.uiEl.getObject3D("mesh").getObjectByName(e+"bg"),s=this.selectedObjects,i=this.selectedBrush;i&&(this.highlightMaterials[i.name]||this.initHighlightMaterial(t),i.material=this.highlightMaterials[i.name].normal,delete s[i.name]),s[t.name]=t,this.selectedBrush=t,this.playSound("ui_click1",e)},onHueDown:function(e){var t,s=this.objects.hueWheel,i=this.colorWheelSize;s.updateMatrixWorld(),s.worldToLocal(e),this.objects.hueCursor.position.copy(e);var r=((t={r:Math.sqrt(e.x*e.x+e.z*e.z),theta:Math.PI+Math.atan2(-e.z,e.x)}).theta*(180/Math.PI)+180)%360;this.hsv.h=r/360,this.hsv.s=t.r/i,this.updateColor(),this.playSound("ui_click0","hue")},updateColor:function(){var e=this.hsv2rgb(this.hsv),t="rgb("+e.r+", "+e.g+", "+e.b+")";this.handEl.setAttribute("brush","color",t),this.colorHasChanged=!0},hsv2rgb:function(e){var t,s,i,r,a,n,o,h,u=THREE.Math.clamp(e.h,0,1),l=THREE.Math.clamp(e.s,0,1),d=e.v;switch(n=d*(1-l),o=d*(1-(a=6*u-(r=Math.floor(6*u)))*l),h=d*(1-(1-a)*l),r%6){case 0:t=d,s=h,i=n;break;case 1:t=o,s=d,i=n;break;case 2:t=n,s=d,i=h;break;case 3:t=n,s=o,i=d;break;case 4:t=h,s=n,i=d;break;case 5:t=d,s=n,i=o}return{r:Math.round(255*t),g:Math.round(255*s),b:Math.round(255*i)}},rgb2hsv:function(e,t,s){var i,r=Math.max(e,t,s),a=Math.min(e,t,s),n=r-a,o=0===r?0:n/r,h=r;switch(1===arguments.length&&(t=e.g,s=e.b,e=e.r),r){case a:i=0;break;case e:i=t-s+n*(t=this.brushesPagesNum))for(this.objects.previousPage.visible=0!==e,e===this.brushesPagesNum-1?this.objects.nextPage.visible=!1:this.objects.nextPage.visible=!0,i=0;i=this.brushesPagesNum-1||(this.brushesPage++,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},previousPage:function(){0!==this.brushesPage&&(this.brushesPage--,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},initHighlightMaterial:function(e){var t=e.name,s=this.brushRegexp.test(t),i=-1!==t.indexOf("history"),r="hue"===t||"huecursor"===t,a={normal:e.material,hover:e.material,pressed:e.material,selected:e.material};s||i||r||(a.normal=e.material,a.hover=e.material.clone(),a.hover.map=this.system.hoverTexture,a.selected=e.material.clone(),a.selected.map=this.system.pressedTexture,a.pressed=e.material.clone(),a.pressed.map=this.system.pressedTexture),this.highlightMaterials[t]=a},toggleMenu:function(e){this.closed?(this.system.closeAll(),this.open(),this.system.opened=this.el):(this.close(),this.system.opened=void 0)},open:function(){var e=this.uiEl;if(this.closed){if(this.uiEl.setAttribute("visible",!0),this.uiEl.setAttribute("animation",{dur:100,easing:"easeOutExpo",property:"scale",from:{x:0,y:0,z:0},to:{x:1,y:1,z:1}}),this.el.setAttribute("brush","enabled",!1),this.rayEl.setAttribute("visible",!1),this.closed=!1,this.tooltips){var t=this;this.tooltips.forEach((function(s){s.getAttribute("visible")&&e.parentEl.id!==s.parentEl.id&&(t.isTooltipPaused=!0,s.setAttribute("visible",!1))}))}this.playSound("ui_menu")}},updateIntersections:function(){var e=this.raycaster=new THREE.Raycaster;return function(t){this.updateRaycaster(e),this.intersectedObjects=e.intersectObjects(this.menuEls,!0)}}(),onIntersection:function(e){var t=this.closed&&this.system.opened;this.el.components.brush.active||(this.rayEl.setAttribute("visible",!!t),this.el.setAttribute("brush","enabled",!1))},onIntersected:function(e){var t=e.detail.el;this.handEl&&this.removeHandListeners(),this.handEl=t,this.handRayEl=this.handEl.components.ui.rayEl,this.menuEls=this.uiEl.object3D.children,this.syncUI(),this.addHandListeners()},addHandListeners:function(){var e=this.handEl;e.addEventListener("componentchanged",this.onComponentChanged),e.addEventListener("stroke-started",this.onStrokeStarted),e.addEventListener("triggerchanged",this.onTriggerChanged)},removeHandListeners:function(){var e=this.handEl;e.removeEventListener("componentchanged",this.onComponentChanged),e.removeEventListener("stroke-started",this.onStrokeStarted),e.removeEventListener("triggerchanged",this.onTriggerChanged)},onComponentChanged:function(e){"brush"===e.detail.name&&this.syncUI()},syncUI:function(){var e;this.handEl&&this.objects&&(e=this.handEl.getAttribute("brush"),this.updateSizeSlider(e.size),this.updateColorUI(e.color),this.updateColorHistory())},initColorHistory:function(){for(var e,t=this.objects.currentColor,s=0;s{window.addEventListener("load",(function(e){var t=document.body;t.addEventListener("dragover",(function(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect="copy"}),!1),t.addEventListener("drop",(function(e){e.stopPropagation(),e.preventDefault();for(var t=e.dataTransfer.files,s=0;s{e.color.set("#333")})):r.material.color.set("#333")}s.setObject3D("mesh",t),s.className="templateitem",document.querySelector("a-scene").appendChild(s)},r.readAsText(i)):i.type.match(/image.*/)&&((r=new FileReader).onload=function(e){var t=new Image;t.src=e.target.result,t.onload=()=>{var s,i;t.width>t.height?(s=1,i=t.height/t.width):(i=1,s=t.width/t.height);var r=[3*Math.random()-1.5,1+Math.random()-.5,.2*Math.random()-1.4],a=document.createElement("a-image");a.setAttribute("src",e.target.result),a.setAttribute("position",r.join(" ")),a.setAttribute("width",s),a.setAttribute("height",i),a.className="templateitem",document.querySelector("a-scene").appendChild(a)}},r.readAsDataURL(i))}}),!1)}))},51:e=>{e.exports=function(e){function t(){var t=document.querySelector("a-scene");t.hasLoaded?e():t.addEventListener("loaded",e())}"complete"===document.readyState||"loaded"===document.readyState?t():document.addEventListener("DOMContentLoaded",t)}},115:e=>{function t(e){this.material=e,this.maxBufferSize=1e6,this.geometries=[],this.current=null,this.strip=!0,this.addBuffer(!1)}t.prototype={restartPrimitive:function(){if(this.idx.position>=this.current.attributes.position.count)this.addBuffer(!1);else if(0!==this.idx.position){var e=3*(this.idx.position-1),t=this.current.attributes.position.array;this.addVertex(t[e++],t[e++],t[e++]),this.idx.color++,this.idx.normal++,this.idx.uv++}},remove:function(e,t){var s=this.current.attributes.position.array;if(this.idx.position>t.position)for(key in this.idx)for(var i="uv"===key?2:3,r=(s=e[key]*i,(t[key]+1)*i),a=this.idx[key]*i,n=r;n0&&(this.previous=this.current),this.idx={position:0,uv:0,normal:0,color:0},this.geometries.push(t),this.current=t,this.previous&&e){var u=3*(this.maxBufferSize-2),l=3*(this.maxBufferSize-2),d=(this.maxBufferSize,3*(this.maxBufferSize-2)),c=this.previous.attributes.position.array;this.addVertex(c[u++],c[u++],c[u++]),this.addVertex(c[u++],c[u++],c[u++]);var m=this.previous.attributes.normal.array;this.addNormal(m[d++],m[d++],m[d++]),this.addNormal(m[d++],m[d++],m[d++]);var p=this.previous.attributes.color.array;this.addColor(p[l++],p[l++],p[l++]),this.addColor(p[l++],p[l++],p[l++]);a=this.previous.attributes.uv.array}},addColor:function(e,t,s){this.current.attributes.color.setXYZ(this.idx.color++,e,t,s)},addNormal:function(e,t,s){this.current.attributes.normal.setXYZ(this.idx.normal++,e,t,s)},addVertex:function(e,t,s){var i=this.current.attributes.position;this.idx.position===i.count&&(this.addBuffer(!0),i=this.current.attributes.position),i.setXYZ(this.idx.position++,e,t,s),this.strip?(this.idx.position+1)%2==0&&this.idx.position>1&&(this.current.index.setXYZ(this.idx.position-3,this.idx.position-3,this.idx.position-2,this.idx.position-1),this.current.index.setXYZ(this.idx.position-2,this.idx.position-1,this.idx.position-2,this.idx.position)):(this.idx.position+1)%3==0&&this.current.index.setXYZ(this.idx.position,this.idx.position-2,this.idx.position-1,this.idx.position)},addUV:function(e,t){this.current.attributes.uv.setXY(this.idx.uv++,e,t)},update:function(){this.current.setDrawRange(0,3*this.idx.position-4),this.current.attributes.color.updateRange.count=3*this.idx.position,this.current.attributes.color.needsUpdate=!0,this.current.attributes.normal.updateRange.count=3*this.idx.position,this.current.attributes.normal.needsUpdate=!0,this.current.attributes.position.updateRange.count=3*this.idx.position,this.current.attributes.position.needsUpdate=!0,this.current.attributes.uv.updateRange.count=2*this.idx.position,this.current.attributes.uv.needsUpdate=!0,this.current.index.updateRange.count=3*this.idx.position,this.current.index.needsUpdate=!0}},e.exports=t},297:(e,t,s)=>{var i=s(115);function r(){this.sharedBuffers={}}r.prototype={addSharedBuffer:function(e,t){var s=new i(t);this.sharedBuffers[e]=s},getSharedBuffer:function(e){return this.sharedBuffers[e]}},e.exports=new r},796:()=>{var e,t;AFRAME.BRUSHES={},APAINTER_STATS={brushes:{}},AFRAME.registerBrush=function(e,t,s){var i={};if(Object.keys(t).forEach((function(e){i[e]={value:t[e],writable:!0}})),AFRAME.BRUSHES[e])throw new Error("The brush `"+e+"` 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 r=function(){};r.prototype={options:Object.assign({spacing:0,maxPoints:0},s),reset:function(){},tick:function(e,t){},undo:function(){},remove:function(){},addPoint:function(e,t,s,i,r){},getJSON:function(e){for(var t=[],s=0;s=this.options.maxPoints||n.call(this,e,t,s,i,r)&&(this.data.numPoints++,this.data.points.push({position:e.clone(),orientation:t.clone(),pressure:i,timestamp:r}),this.data.prevPosition=e.clone(),this.data.prevPointerPosition=s.clone())}),AFRAME.BRUSHES[e]=o,o.used=!1,o},AFRAME.registerSystem("brush",{schema:{},brushes:{},strokes:[],getUsedBrushes:function(){return Object.keys(AFRAME.BRUSHES).filter((function(e){return AFRAME.BRUSHES[e].used}))},getBrushByName:function(e){return AFRAME.BRUSHES[e]},undo:function(){for(var e,t=this.strokes.length-1;t>=0;t--)if("local"===this.strokes[t].data.owner){e=this.strokes.splice(t,1)[0];break}e&&(e.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:e}))},removeById:function(e){var t=this.strokes[1];if(console.log(t,this.strokes),t){for(var s=this.strokes.length-1;s>1;s--)if(stroke=this.strokes[s],t.sharedBuffer===stroke.sharedBuffer){for(key in console.log(">>>",stroke.prevIdx,"->",stroke.idx,"target",t.prevIdx,"->",t.idx),t.idx){var i=t.idx[key]-t.prevIdx[key];stroke.idx[key]-=i,stroke.prevIdx[key]-=i}console.log("<<<",stroke.idx,stroke.prevIdx)}this.strokes.splice(1,1)[0].remove()}},clear:function(){for(var e=this.strokes.length-1;e>=0;e--)if("local"===this.strokes[e].data.owner){var t=this.strokes[e];t.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:t})}Object.keys(AFRAME.BRUSHES).forEach((function(e){AFRAME.BRUSHES[e].used=!1})),this.strokes=[]},init:function(){this.version=1,this.clear(),this.controllerName=null;var e=this;this.sceneEl.addEventListener("controllerconnected",(function(t){e.controllerName=t.detail.name}))},tick:function(e,t){if(this.strokes.length)for(var s=0;s1&&(m=1);var f=this.getPointerPosition(l,c);u.addPoint(l,c,f,m,0)}}},addNewStroke:function(e,t,s,i,r){APAINTER_STATS.brushes[e]||(APAINTER_STATS.brushes[e]=0),APAINTER_STATS.brushes[e]++,i=i||"local",r=r||Date.now();var a=this.getBrushByName(e);if(!a){var n=Object.keys(AFRAME.BRUSHES)[0];a=AFRAME.BRUSHES[n],console.warn("Invalid brush name: `"+e+"` using `"+n+"`")}a.used=!0;var o=new a;o.brush=a,o.init(t,s,i,r),this.strokes.push(o);var h=document.querySelector(".a-drawing");return h||((h=document.createElement("a-entity")).className="a-drawing",document.querySelector("a-scene").appendChild(h)),o},getJSON:function(){var e={version:1,strokes:[],author:"",brushes:this.getUsedBrushes()};for(i=0;i{var i=s(618).saveAs;AFRAME.registerSystem("painter",{init:function(){var e={behaviours:{},mappings:{painting:{common:{"grip.down":"undo","trigger.changed":"paint"},"vive-controls":{axismove:"changeBrushSizeInc","trackpad.touchstart":"startChangeBrushSize","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"},"oculus-touch-controls":{axismove:"changeBrushSizeAbs","abutton.down":"toggleMenu","xbutton.down":"toggleMenu","ybutton.down":"aim","ybutton.up":"teleport","bbutton.down":"aim","bbutton.up":"teleport"},"windows-motion-controls":{axismove:"changeBrushSizeAbs","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"}}}};this.sceneEl.addEventListener("loaded",(function(){AFRAME.registerInputMappings(e),AFRAME.currentInputMapping="painting"})),this.version="1.2",this.brushSystem=this.sceneEl.systems.brush,this.showTemplateItems=!0;var t=function(){var e,t=/\+/g,s=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(t," "))},r=window.location.search.substring(1),a={};for(e=s.exec(r);e;)a[i(e[1])]=i(e[2]),e=s.exec(r);return a}();if(t.url||t.urljson){var s=void 0===t.urljson;this.brushSystem.loadFromUrl(t.url||t.urljson,s),document.getElementById("logo").setAttribute("visible",!1),document.getElementById("acamera").setAttribute("orbit-controls","initialPosition: 0 1.6 3"),document.getElementById("apainter-logo").classList.remove("hidden")}else{document.getElementById("acamera").setAttribute("position","0 1.6 0")}void 0!==t.bgcolor&&(document.body.style.backgroundColor="#"+t.bgcolor),void 0!==t.sky&&this.sceneEl.addEventListener("loaded",(function(e){""===t.sky?document.getElementById("sky").setAttribute("visible",!1):document.getElementById("sky").setAttribute("material","src",t.sky)})),void 0!==t.floor&&this.sceneEl.addEventListener("loaded",(function(e){""===t.floor?document.getElementById("ground").setAttribute("visible",!1):document.getElementById("ground").setAttribute("material","src",t.floor)})),this.paintingStarted=!1;var i=this;document.addEventListener("stroke-started",(function(e){if(!i.paintingStarted){document.getElementById("logo").emit("painting-started"),i.paintingStarted=!0}})),document.addEventListener("keyup",(function(e){if(!e.shiftKey&&!e.ctrlKey){if(8===e.keyCode&&i.brushSystem.undo(),67===e.keyCode&&i.brushSystem.clear(),71===e.keyCode){var t=document.querySelector(".a-drawing");i.sceneEl.systems["gltf-exporter"].export(t)}if(78===e.keyCode){var s=document.querySelectorAll("[paint-controls]"),r=Object.keys(AFRAME.BRUSHES),a=r.indexOf(s[0].components.brush.data.brush);a=(a+1)%r.length,[].forEach.call(s,(function(e){e.setAttribute("brush","brush",r[a])}))}if(84===e.keyCode&&i.brushSystem.generateTestLines(),82===e.keyCode&&i.brushSystem.generateRandomStrokes(1),76===e.keyCode&&i.brushSystem.loadFromUrl("demo.apa",!0),85===e.keyCode&&i.upload(),86===e.keyCode&&i.save(),74===e.keyCode&&i.saveJSON(),79===e.keyCode){i.showTemplateItems=!i.showTemplateItems;for(var n=document.querySelectorAll(".templateitem"),o=0;o{if(!e.ok)throw new Error(`Network request failed with status ${e.status}: ${e.statusText}`);return e.json()})).then((s=>{console.log("Uploaded link: ",t+s.secure_url),e.sceneEl.emit("drawing-upload-completed",{url:t+s.secure_url})})).catch((t=>{console.error(t),e.sceneEl.emit("drawing-upload-error",{errorInfo:t})}))}})},493:()=>{AFRAME.registerSystem("ui",{init:function(){this.initTextures()},initTextures:function(){var e=this,t="assets/images/ui-hover.png",s="assets/images/ui-pressed.png";this.sceneEl.systems.material.loadTexture(t,{src:t},(function(t){e.hoverTexture=t})),this.sceneEl.systems.material.loadTexture(s,{src:s},(function(t){e.pressedTexture=t}))},closeAll:function(){var e,t=document.querySelectorAll("[ui]");for(e=0;e{window.addEventListener("load",(function(e){var t=document.getElementById("apainter-ui"),s=document.querySelector("#apainter-ui .share"),i=document.getElementById("apainter-share-url"),r=document.querySelector("#apainter-ui .progress"),a=document.querySelector("#apainter-ui .bar");document.addEventListener("drawing-upload-completed",(function(e){s.classList.remove("hide"),r.classList.add("hide"),i.value=e.detail.url})),document.addEventListener("drawing-upload-started",(function(e){t.style.display="block",s.classList.add("hide"),r.classList.remove("hide")})),document.addEventListener("drawing-upload-progress",(function(e){a.style.width=Math.floor(100*e.detail.progress)+"%"})),new Clipboard(".button.copy").on("error",(function(e){console.error("Error copying to clipboard:",e.action,e.trigger)}))}))},555:()=>{window.Utils=function(){function e(e){return parseFloat(e.toFixed(6))}return{numberToFixed:e,arrayNumbersToFixed:function(t){for(var s=0;s{"use strict";e.exports=JSON.parse('{"meta":{"image":"brush_atlas.png","size":{"w":3584,"h":2944},"scale":"1"},"frames":{"stamp_grass.png":{"frame":{"x":0,"y":128,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"lines4.png":{"frame":{"x":0,"y":0,"w":2048,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":2048,"h":128},"sourceSize":{"w":2048,"h":128}},"stamp_fur2.png":{"frame":{"x":0,"y":640,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"stamp_bush.png":{"frame":{"x":0,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_gear.png":{"frame":{"x":1024,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_fur1.png":{"frame":{"x":2048,"y":0,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"lines3.png":{"frame":{"x":2048,"y":512,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_gradient.png":{"frame":{"x":2048,"y":768,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines5.png":{"frame":{"x":2048,"y":1024,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_flat.png":{"frame":{"x":2048,"y":1280,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_textured.png":{"frame":{"x":0,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"squared_textured.png":{"frame":{"x":1024,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge2.png":{"frame":{"x":2048,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge3.png":{"frame":{"x":0,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge1.png":{"frame":{"x":1024,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines2.png":{"frame":{"x":2048,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"stamp_leaf3.png":{"frame":{"x":1536,"y":128,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_dots.png":{"frame":{"x":1536,"y":640,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"thumb_stamp_star.png":{"frame":{"x":2304,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_grunge1.png":{"frame":{"x":512,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge2.png":{"frame":{"x":1024,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge3.png":{"frame":{"x":1536,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge4.png":{"frame":{"x":2048,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge5.png":{"frame":{"x":2560,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf1.png":{"frame":{"x":3072,"y":0,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf2.png":{"frame":{"x":3072,"y":512,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_column.png":{"frame":{"x":3072,"y":1024,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_snow.png":{"frame":{"x":3072,"y":1536,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_squares.png":{"frame":{"x":3072,"y":2048,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"lines1.png":{"frame":{"x":0,"y":2688,"w":256,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":256,"h":256},"sourceSize":{"w":256,"h":256}},"thumb_rainbow.png":{"frame":{"x":3072,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_single_sphere.png":{"frame":{"x":3200,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur1.png":{"frame":{"x":3328,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur2.png":{"frame":{"x":3456,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_grass.png":{"frame":{"x":2048,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_snow.png":{"frame":{"x":2176,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_star.png":{"frame":{"x":0,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}}}}')}},t={};function s(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,s),a.exports}s.amdD=function(){throw new Error("define cannot be used indirect")},s.amdO={},window.saveAs=s(618).saveAs,s(453),s(821),s(967),s(297),s(115),s(555),s(369),s(796),s(493),s(810),s(620),s(142),s(510),s(101),s(688),s(579),s(788),s(295),s(623),s(988),s(830),s(775),s(891)})(); \ No newline at end of file +(()=>{var e={453:(e,t,s)=>{const i=s(95);function r(){this.map=(new THREE.TextureLoader).load("assets/images/"+i.meta.image)}r.prototype={getUVConverters:function(e){return e?(e=e.replace("brushes/",""),{convertU:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),r.frame.x/s.w+t*r.frame.w/s.w},convertV:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),1-(r.frame.y/s.h+t*r.frame.h/s.h)}}):{convertU:function(e){return e},convertV:function(e){return e}}}},window.atlas=new r},967:()=>{window.BinaryManager=function(e){this.dataview=new DataView(e),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 e=this.dataview.getUint8(this.offset++,!0),t="",s=0;s{AFRAME.registerBrush("cubes",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.BoxGeometry(1,1,1),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=i*this.data.size*Math.random();return a.scale.set(n,n,n),a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_cubes.gif",spacing:.01})},295:(e,t,s)=>{var i=s(297),r=s(51);!function(){r((function(){var e={vertexColors:THREE.VertexColors,side:THREE.DoubleSide},t={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,map:window.atlas.map,side:THREE.DoubleSide},s={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,side:THREE.DoubleSide,map:window.atlas.map,transparent:!0,alphaTest:.5};i.addSharedBuffer("strip-flat",new THREE.MeshBasicMaterial(e)),i.addSharedBuffer("strip-shaded",new THREE.MeshStandardMaterial(t)),i.addSharedBuffer("strip-textured",new THREE.MeshStandardMaterial(s))}));for(var e,t,s,a,n,o,h={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("strip-"+this.materialOptions.type),this.sharedBuffer.restartPrimitive(),this.sharedBuffer.strip=!0,this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.first=!0},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(o=new THREE.Vector3,function(e,t,s,i,r){var a=this.materialOptions.converter;o.set(1,0,0),o.applyQuaternion(t),o.normalize();var n=s.clone(),h=s.clone(),u=this.data.size*i;if(n.add(o.clone().multiplyScalar(u/2)),h.add(o.clone().multiplyScalar(-u/2)),this.first&&this.prevIdx.position>0&&(this.first=!1,this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.idx.normal++,this.sharedBuffer.idx.color++,this.sharedBuffer.idx.uv++,this.idx=Object.assign({},this.sharedBuffer.idx)),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(h.x,h.y,h.z),this.sharedBuffer.idx.normal+=2,this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),"textured"===this.materialOptions.type){this.sharedBuffer.idx.uv+=2;for(var l,d,c=this.sharedBuffer.current.attributes.uv.array,m=0;m{var e,t,s,r,a;a=new THREE.ShaderMaterial({vertexShader:"varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }",fragmentShader:"uniform sampler2D tDiffuse; uniform float amount; uniform float time; varying vec2 vUv; vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } void main() { float h = mod(vUv.x - time / 3000.0, 1.0); vec4 color = vec4(hsv2rgb(vec3(h, 1.0, 0.5)), 1.0); gl_FragColor = color; }",side:THREE.DoubleSide,uniforms:{time:{type:"f",value:0}}}),AFRAME.registerBrush("line-rainbow",{init:function(e,t){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.indices=new Uint32Array(4.5*this.options.maxPoints*4.5),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.linepositions=new Float32Array(this.options.maxPoints),this.geometry.setDrawRange(0,0),this.geometry.setAttribute("position",new THREE.BufferAttribute(this.vertices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setIndex(new THREE.BufferAttribute(this.indices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("lineposition",new THREE.BufferAttribute(this.linepositions,1).setUsage(THREE.DynamicDrawUsage)),this.material=a;var s=new THREE.Mesh(this.geometry,this.material);s.frustumCulled=!1,s.vertices=this.vertices,this.object3D.add(s),this.drawing=document.querySelector(".a-drawing"),this.drawing.object3D.add(this.object3D)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,r=new THREE.Vector3,function(a,n,o,h,u){var l=0;for(i=0;i6&&(this.geometry.index.setXYZ(this.idx/3-4,this.idx/3-4,this.idx/3-3,this.idx/3-2),this.geometry.index.setXYZ(this.idx/3-3,this.idx/3-2,this.idx/3-3,this.idx/3-1)),this.geometry.attributes.position.needsUpdate=!0,this.geometry.index.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints*6),!0}),tick:function(e,t){this.material.uniforms.time.value=e},undo:function(){this.drawing.object3D.children.pop()}},{thumbnail:"brushes/thumb_rainbow.png",maxPoints:3e3})},891:()=>{AFRAME.registerBrush("single-sphere",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.6,metalness:.2,side:THREE.FrontSide,flatShading:!0}),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,this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){this.firstPoint||(this.firstPoint=s.clone(),this.mesh.position.set(this.firstPoint.x,this.firstPoint.y,this.firstPoint.z)),this.mesh.visible=!0;var a=this.firstPoint.distanceTo(s);return this.mesh.scale.set(a,a,a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_single_sphere.png",spacing:0})},988:()=>{AFRAME.registerBrush("spheres",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.IcosahedronGeometry(1,0),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=this.data.size/2*i;return a.scale.set(n,n,n),a.initialScale=a.scale.clone(),a.phase=Math.random()*Math.PI*2,a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},tick:function(e,t){for(var s=0;s{var i=s(297),r=s(51);!function(){r((function(){var e=new THREE.MeshStandardMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5,roughness:.75,metalness:.25}),t=new THREE.MeshBasicMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5});i.addSharedBuffer("tris-flat",t),i.addSharedBuffer("tris-shaded",e)}));for(var e,t,s,a,n,o,h,u,l={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("tris-"+this.materialOptions.type),this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.strip=!1,this.currAngle=0,this.subTextures=1,this.angleJitter=0,this.autoRotate=!1,void 0!==this.materialOptions.subTextures&&(this.subTextures=this.materialOptions.subTextures),!0===this.materialOptions.autoRotate&&(this.autoRotate=!0),void 0!==this.materialOptions.angleJitter&&(this.angleJitter=this.materialOptions.angleJitter,this.angleJitter=2*this.angleJitter-this.angleJitter)},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,a=new THREE.Vector3,n=new THREE.Vector3,o=new THREE.Vector3,h=new THREE.Vector3,u=Math.PI/2,function(i,r,l,d,c){t.set(1,0,0),t.applyQuaternion(r),t.normalize(),e.set(0,1,0),e.applyQuaternion(r),e.normalize();var m=this.data.size*d/2,p=Math.PI/4+Math.random()*this.angleJitter;this.autoRotate&&(this.currAngle+=.1,p+=this.currAngle),s.copy(l).add(h.copy(t.applyAxisAngle(e,p)).multiplyScalar(m)),a.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),n.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),o.copy(l).add(t.applyAxisAngle(e,u).multiplyScalar(m)),this.idx.position,this.idx.position,this.sharedBuffer.addVertex(s.x,s.y,s.z),this.sharedBuffer.addVertex(a.x,a.y,a.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(o.x,o.y,o.z),this.sharedBuffer.addVertex(s.x,s.y,s.z);for(var f=0;f<6;f++)this.sharedBuffer.addNormal(e.x,e.y,e.z),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b);this.data.numPoints;var g=0,b=1;if(this.subTextures>1){var v=Math.floor(Math.random()*this.subTextures);b=(g=1/this.subTextures*v)+1/this.subTextures}var y=this.materialOptions.converter;return this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.update(),!0})},d=[{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}],c=0;c{AFRAME.registerComponent("brush-tip",{schema:{controller:{type:"string"},hand:{type:"string",oneOf:["left","right"]}},init:function(){var e=e=>THREE.MathUtils.degToRad(e);this.controllers={"oculus-touch-controller-v3":{left:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(7),z:e(-7)}},right:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(-7),z:e(7)}}}},this.data.controller&&this.setController(this.data.controller,this.data.hand)},setController:function(e,t){e in this.controllers?(this.el.object3D.position.set(this.controllers[e][t].positionOffset.x,this.controllers[e][t].positionOffset.y,this.controllers[e][t].positionOffset.z),this.el.object3D.rotation.set(this.controllers[e][t].rotationOffset.x,this.controllers[e][t].rotationOffset.y,this.controllers[e][t].rotationOffset.z)):console.error(`${e} is not present in the controllers list!`)}})},620:()=>{var e,t,s;AFRAME.registerComponent("brush",{schema:{color:{type:"color",default:"#ef2d5e"},size:{default:.01,min:.001,max:.3},brush:{default:"smooth"},enabled:{default:!0}},init:function(){var e=this.data;this.color=new THREE.Color(e.color),this.el.emit("brushcolor-changed",{color:this.color}),this.el.emit("brushsize-changed",{brushSize:e.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 t=this;this.el.addEventListener("undo",(function(e){t.data.enabled&&(t.system.undo(),document.getElementById("ui_undo").play())})),this.el.addEventListener("paint",(function(e){if(t.data.enabled){var s=e.detail.value;t.sizeModifier=s,s>.1?t.active||(t.startNewStroke(),t.active=!0):(t.active&&(t.previousEntity=t.currentEntity,t.currentStroke=null),t.active=!1)}})),this.hand="right-hand"===this.el.id?"right":"left"},update:function(e){var t=this.data;e.color!==t.color&&(this.color.set(t.color),this.el.emit("brushcolor-changed",{color:this.color})),e.size!==t.size&&this.el.emit("brushsize-changed",{size:t.size})},tick:(e=new THREE.Vector3,t=new THREE.Quaternion,s=new THREE.Vector3,function(i,r){if(this.currentStroke&&this.active){this.obj.matrixWorld.decompose(e,t,s);var a=this.system.getPointerPosition(e,t,this.hand);this.currentStroke.addPoint(e,t,a,this.sizeModifier,i)}}),startNewStroke:function(){document.getElementById("ui_paint").play(),this.currentStroke=this.system.addNewStroke(this.data.brush,this.color,this.data.size),this.el.emit("stroke-started",{entity:this.el,stroke:this.currentStroke})}})},510:()=>{AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"}},init:function(){this.objectLoader=new THREE.ObjectLoader,this.objectLoader.setCrossOrigin("")},update:function(e){var t=this,s=this.data.src;s&&s!==e.src&&this.objectLoader.load(this.data.src,(function(e){var i=(new THREE.Matrix4).makeRotationX(-Math.PI/2);e.traverse((function(e){e instanceof THREE.Mesh&&e.position.applyMatrix4(i)})),t.el.setObject3D("mesh",e),t.el.emit("model-loaded",{format:"json",model:e,src:s})}))}})},788:()=>{AFRAME.registerComponent("logo-model",{schema:{opacity:{default:1}},init:function(){this.model=null,this.el.setAttribute("obj-model","obj: #logoobj; mtl: #logomtl"),this.el.addEventListener("model-loaded",this.setModel.bind(this))},setModel:function(e){this.model=e.detail.model},update:function(){null!=this.model&&(this.model.children[0].material.opacity=this.data.opacity)}})},101:()=>{AFRAME.registerSystem("paint-controls",{numberStrokes:0}),AFRAME.registerComponent("paint-controls",{dependencies:["brush"],schema:{hand:{default:"left"}},init:function(){var e=this.el,t=this,s="assets/images/controller-pressed.png",i=null;this.controller=null,this.modelLoaded=!1,this.onEnterVR=this.onEnterVR.bind(this),e.sceneEl.addEventListener("enter-vr",this.onEnterVR),e.object3D.visible=!1,this.onModelLoaded=this.onModelLoaded.bind(this),e.addEventListener("model-loaded",this.onModelLoaded),e.addEventListener("changeBrushSizeAbs",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=(s.detail.axis[1]||s.detail.axis[3])/300,r=e.components.brush.schema.size,a=THREE.Math.clamp(t.el.getAttribute("brush").size-i,r.min,r.max);t.el.setAttribute("brush","size",a)}})),e.addEventListener("changeBrushSizeInc",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=s.detail.axis[1]||s.detail.axis[3];t.touchStarted&&(t.touchStarted=!1,t.startAxis=(i+1)/2);var r=(i+1)/2,a=(t.startAxis-r)/2;t.startAxis=r;var n=t.el.getAttribute("brush").size,o=e.components.brush.schema.size,h=THREE.Math.clamp(n-a,o.min,o.max);t.el.setAttribute("brush","size",h)}})),t.touchStarted=!1,e.addEventListener("startChangeBrushSize",(function(){t.touchStarted=!0})),e.addEventListener("controllerconnected",(function(s){var r=s.detail.name,a=s.detail.component.data.hand;const n=(s,i)=>{this.brushTip=document.createElement("a-entity"),this.brushTip.id=`${i}-tip`,this.brushTip.setAttribute("gltf-model","#tipObj"),this.brushTip.setAttribute("brush-tip",`controller: ${s}; hand: ${i}`),this.brushTip.addEventListener("model-loaded",t.onModelLoaded),e.appendChild(this.brushTip)};if("windows-motion-controls"===r){var o=s.detail.component.el.components["gltf-model"].data;const e="045E-065D";o&&o.indexOf(e)>=0&&(r="windows-motion-samsung-controls")}if(i=Utils.getTooltips(r),r.indexOf("windows-motion")>=0);else if("oculus-touch-controls"===r){const t=e.components[r].displayModel[a].modelUrl;n(/[^\/]*(?=-(?:left|right)\.)/.exec(t)[0],a)}else{if("vive-controls"!==r)return;e.setAttribute("gltf-model","url(assets/models/vive-controller.glb)")}i&&i.forEach((function(e){e.setAttribute("visible",!0);Array.prototype.slice.call(e.querySelectorAll("[tooltip]")).forEach((function(e){e.setAttribute("animation",{dur:1e3,delay:2e3,property:"tooltip.opacity",from:1,to:0,startEvents:"tooltip-fade"})}))})),this.controller=r})),e.addEventListener("brushsize-changed",(function(e){t.changeBrushSize(e.detail.size)})),e.addEventListener("brushcolor-changed",(function(e){t.changeBrushColor(e.detail.color)})),e.sceneEl.systems.material.loadTexture(s,{src:s},(function(e){var s=t.highLightMaterial=new THREE.MeshBasicMaterial;s.map=e,s.needsUpdate=!0})),this.startAxis=0,this.numberStrokes=0,document.addEventListener("stroke-started",(function(e){if(e.detail.entity.components["paint-controls"]===t&&(t.numberStrokes++,t.system.numberStrokes++,3===t.system.numberStrokes)){Array.prototype.slice.call(document.querySelectorAll("[tooltip]")).forEach((function(e){e.emit("tooltip-fade")}))}}))},changeBrushColor:function(e){this.modelLoaded&&this.buttonMeshes.sizeHint&&(this.buttonMeshes.colorTip.material.color.copy(e),this.buttonMeshes.sizeHint.material.color.copy(e))},changeBrushSize:function(e){var t=e/2*10;this.modelLoaded&&this.buttonMeshes.sizeHint&&this.buttonMeshes.sizeHint.scale.set(t,1,t)},mapping:{axis0:"trackpad",axis1:"trackpad",button0:"trackpad",button1:"trigger",button2:"grip",button3:"menu",button4:"system"},update:function(){var e=this.data,t=this.el;t.setAttribute("vive-controls",{hand:e.hand,model:!1}),t.setAttribute("oculus-touch-controls",{hand:e.hand,model:!0}),t.setAttribute("windows-motion-controls",{hand:e.hand})},play:function(){},pause:function(){},onEnterVR:function(){this.el.object3D.visible=!0},onModelLoaded:function(e){if((e.target===this.el||e.target.id.includes("-tip"))&&!this.buttonMeshes){var t,s=e.detail.model;(t=this.buttonMeshes={}).sizeHint=s.getObjectByName("sizehint"),t.colorTip=s.getObjectByName("tip"),this.modelLoaded=!0,this.changeBrushSize(this.el.components.brush.data.size),this.changeBrushColor(this.el.components.brush.color)}},onButtonEvent:function(e,t){var s=this.mapping["button"+e];this.el.emit(s+t),this.updateModel(s,t)},updateModel:function(e,t){var s="up"===t?this.material:this.highLightMaterial,i=this.buttonMeshes,r=i&&i[e];if("down"===t&&r&&!this.material&&(s=this.material=r.material),s)return"grip"===e?(i.grip.left.material=s,void(i.grip.right.material=s)):void(r&&(r.material=s))}})},579:()=>{var e,t,s;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 e=this.data,t=this.raycaster;t.far=e.far,t.near=e.near,this.refreshObjects()},refreshObjects:function(){var e,t,s=this.data;if(s.objects)for(t=this.el.sceneEl.querySelectorAll(s.objects),this.objects=[],e=0;e{var e,t,s,i,r,a;AFRAME.registerComponent("ui",{schema:{brightness:{default:1,max:1,min:0},opacity:{default:0}},dependencies:["ui-raycaster"],init:function(){var e=this.el,t=this.uiEl=document.createElement("a-entity"),s=this.rayEl=document.createElement("a-entity");this.closed=!0,this.isTooltipPaused=!1,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),t.setAttribute("material",{color:"#ffffff",flatShading:!0,shader:"flat",transparent:!0,fog:!1,src:"#uinormal"}),t.setAttribute("obj-model","obj:#uiobj"),t.setAttribute("position","0 0.04 -0.15"),t.setAttribute("scale","0 0 0"),t.setAttribute("visible",!1),t.classList.add("apainter-ui"),e.appendChild(t),s.setAttribute("line",""),e.appendChild(s),e.setAttribute("ui-raycaster",{far:this.rayDistance,objects:".apainter-ui",rotation:-this.rayAngle}),this.controller=null;var i=this;e.addEventListener("controllerconnected",(function(s){var r=s.detail.name;i.tooltips=Utils.getTooltips(r),i.controller={name:r,hand:s.detail.component.data.hand},"oculus-touch-controls"===r?(i.uiEl.setAttribute("rotation","45 0 0"),t.setAttribute("position","0 0.13 -0.08"),i.rayAngle=0,e.setAttribute("ui-raycaster",{rotation:0})):"windows-motion-controls"===r&&(i.rayAngle=25,i.rayDistance=1,e.setAttribute("ui-raycaster",{rotation:-30,far:i.rayDistance})),i.el.isPlaying&&i.addToggleEvent()}))},initColorWheel:function(){var e=this.objects.hueWheel,t=new THREE.ShaderMaterial({uniforms:{brightness:{type:"f",value:this.hsv.v}},vertexShader:" varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); gl_Position = projectionMatrix * mvPosition; } ",fragmentShader:" #define M_PI2 6.28318530718\n uniform float brightness; varying vec2 vUv; vec3 hsb2rgb(in vec3 c){ vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); rgb = rgb * rgb * (3.0 - 2.0 * rgb); return c.z * mix( vec3(1.0), rgb, c.y); } void main() { vec2 toCenter = vec2(0.5) - vUv; float angle = atan(toCenter.y, toCenter.x); float radius = length(toCenter) * 2.0; vec3 color = hsb2rgb(vec3((angle / M_PI2) + 0.5, radius, brightness)); gl_FragColor = vec4(color, 1.0); } "});e.material=t},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),this.open=this.open.bind(this),this.close=this.close.bind(this)},tick:function(){!this.closed&&this.handEl&&(this.updateIntersections(),this.handleHover(),this.handlePressedButtons())},update:function(){this.messagesMaterial&&(this.messagesMaterial.opacity=this.data.opacity)},onTriggerChanged:function(e){var t=e.detail.value;this.lastTriggerValue=t,e.detail.value>=.25?this.triggeredPressed=!0:(this.triggeredPressed=!1,this.handleButtonUp())},handleButtonDown:function(e,t){var s=e.name;if(!this.activeWidget||this.activeWidget===s){switch(this.activeWidget=s,!0){case"brightness"===s:this.onBrightnessDown(t);break;case"brushnext"===s:this.pressedObjects[s]||this.nextPage();break;case"brushprev"===s:this.pressedObjects[s]||this.previousPage();break;case"clear"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.brush.clear(),this.playSound("ui_click1"));break;case"copy"===s:this.pressedObjects[s]||(this.copyBrush(),this.playSound("ui_click1"));break;case"hue"===s:this.onHueDown(t);break;case"save"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.painter.upload(),this.playSound("ui_click1"));break;case"sizebg"===s:this.onBrushSizeBackgroundDown(t);break;case this.brushRegexp.test(s):this.onBrushDown(s);break;case this.colorHistoryRegexp.test(s):this.onColorHistoryButtonDown(e);break;default:this.activeWidget=void 0}this.pressedObjects[s]=e}},copyBrush:function(){var e=this.el.getAttribute("brush");this.handEl.setAttribute("brush","brush",e.brush),this.handEl.setAttribute("brush","color",e.color),this.handEl.setAttribute("brush","size",e.size),this.colorHasChanged=!0},handleButtonUp:function(){var e=this.pressedObjects,t=this.unpressedObjects;this.activeWidget=void 0,Object.keys(e).forEach((function(s){var i=e[s].name;t[i]=e[i],delete e[i]}))},handlePressedButtons:function(){var e=this;this.triggeredPressed&&this.hoveredOnObjects.forEach((function(t){e.handleButtonDown(t.object,t.point)}))},onColorHistoryButtonDown:function(e){var t=e.material.color.getHexString();this.handEl.setAttribute("brush","color","#"+t),this.playSound("ui_click0",e.name)},onBrushDown:function(e){var t=this.brushButtonsMapping[e];t&&(this.selectBrushButton(e),this.handEl.setAttribute("brush","brush",t.toLowerCase()))},selectBrushButton:function(e){var t=this.uiEl.getObject3D("mesh").getObjectByName(e+"bg"),s=this.selectedObjects,i=this.selectedBrush;i&&(this.highlightMaterials[i.name]||this.initHighlightMaterial(t),i.material=this.highlightMaterials[i.name].normal,delete s[i.name]),s[t.name]=t,this.selectedBrush=t,this.playSound("ui_click1",e)},onHueDown:function(e){var t,s=this.objects.hueWheel,i=this.colorWheelSize;s.updateMatrixWorld(),s.worldToLocal(e),this.objects.hueCursor.position.copy(e);var r=((t={r:Math.sqrt(e.x*e.x+e.z*e.z),theta:Math.PI+Math.atan2(-e.z,e.x)}).theta*(180/Math.PI)+180)%360;this.hsv.h=r/360,this.hsv.s=t.r/i,this.updateColor(),this.playSound("ui_click0","hue")},updateColor:function(){var e=this.hsv2rgb(this.hsv),t="rgb("+e.r+", "+e.g+", "+e.b+")";this.handEl.setAttribute("brush","color",t),this.colorHasChanged=!0},hsv2rgb:function(e){var t,s,i,r,a,n,o,h,u=THREE.Math.clamp(e.h,0,1),l=THREE.Math.clamp(e.s,0,1),d=e.v;switch(n=d*(1-l),o=d*(1-(a=6*u-(r=Math.floor(6*u)))*l),h=d*(1-(1-a)*l),r%6){case 0:t=d,s=h,i=n;break;case 1:t=o,s=d,i=n;break;case 2:t=n,s=d,i=h;break;case 3:t=n,s=o,i=d;break;case 4:t=h,s=n,i=d;break;case 5:t=d,s=n,i=o}return{r:Math.round(255*t),g:Math.round(255*s),b:Math.round(255*i)}},rgb2hsv:function(e,t,s){var i,r=Math.max(e,t,s),a=Math.min(e,t,s),n=r-a,o=0===r?0:n/r,h=r;switch(1===arguments.length&&(t=e.g,s=e.b,e=e.r),r){case a:i=0;break;case e:i=t-s+n*(t=this.brushesPagesNum))for(this.objects.previousPage.visible=0!==e,e===this.brushesPagesNum-1?this.objects.nextPage.visible=!1:this.objects.nextPage.visible=!0,i=0;i=this.brushesPagesNum-1||(this.brushesPage++,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},previousPage:function(){0!==this.brushesPage&&(this.brushesPage--,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},initHighlightMaterial:function(e){var t=e.name,s=this.brushRegexp.test(t),i=-1!==t.indexOf("history"),r="hue"===t||"huecursor"===t,a={normal:e.material,hover:e.material,pressed:e.material,selected:e.material};s||i||r||(a.normal=e.material,a.hover=e.material.clone(),a.hover.map=this.system.hoverTexture,a.selected=e.material.clone(),a.selected.map=this.system.pressedTexture,a.pressed=e.material.clone(),a.pressed.map=this.system.pressedTexture),this.highlightMaterials[t]=a},toggleMenu:function(e){this.closed?(this.system.closeAll(),this.open(),this.system.opened=this.el):(this.close(),this.system.opened=void 0)},open:function(){var e=this.uiEl;if(this.closed){if(this.uiEl.setAttribute("visible",!0),this.uiEl.setAttribute("animation",{dur:100,easing:"easeOutExpo",property:"scale",from:{x:0,y:0,z:0},to:{x:1,y:1,z:1}}),this.el.setAttribute("brush","enabled",!1),this.rayEl.setAttribute("visible",!1),this.closed=!1,this.tooltips){var t=this;this.tooltips.forEach((function(s){s.getAttribute("visible")&&e.parentEl.id!==s.parentEl.id&&(t.isTooltipPaused=!0,s.setAttribute("visible",!1))}))}this.playSound("ui_menu")}},updateIntersections:function(){var e=this.raycaster=new THREE.Raycaster;return function(t){this.updateRaycaster(e),this.intersectedObjects=e.intersectObjects(this.menuEls,!0)}}(),onIntersection:function(e){var t=this.closed&&this.system.opened;this.el.components.brush.active||(this.rayEl.setAttribute("visible",!!t),this.el.setAttribute("brush","enabled",!1))},onIntersected:function(e){var t=e.detail.el;this.handEl&&this.removeHandListeners(),this.handEl=t,this.handRayEl=this.handEl.components.ui.rayEl,this.menuEls=this.uiEl.object3D.children,this.syncUI(),this.addHandListeners()},addHandListeners:function(){var e=this.handEl;e.addEventListener("componentchanged",this.onComponentChanged),e.addEventListener("stroke-started",this.onStrokeStarted),e.addEventListener("triggerchanged",this.onTriggerChanged)},removeHandListeners:function(){var e=this.handEl;e.removeEventListener("componentchanged",this.onComponentChanged),e.removeEventListener("stroke-started",this.onStrokeStarted),e.removeEventListener("triggerchanged",this.onTriggerChanged)},onComponentChanged:function(e){"brush"===e.detail.name&&this.syncUI()},syncUI:function(){var e;this.handEl&&this.objects&&(e=this.handEl.getAttribute("brush"),this.updateSizeSlider(e.size),this.updateColorUI(e.color),this.updateColorHistory())},initColorHistory:function(){for(var e,t=this.objects.currentColor,s=0;s{window.addEventListener("load",(function(e){var t=document.body;t.addEventListener("dragover",(function(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect="copy"}),!1),t.addEventListener("drop",(function(e){e.stopPropagation(),e.preventDefault();for(var t=e.dataTransfer.files,s=0;s{e.color.set("#333")})):r.material.color.set("#333")}s.setObject3D("mesh",t),s.className="templateitem",document.querySelector("a-scene").appendChild(s)},r.readAsText(i)):i.type.match(/image.*/)&&((r=new FileReader).onload=function(e){var t=new Image;t.src=e.target.result,t.onload=()=>{var s,i;t.width>t.height?(s=1,i=t.height/t.width):(i=1,s=t.width/t.height);var r=[3*Math.random()-1.5,1+Math.random()-.5,.2*Math.random()-1.4],a=document.createElement("a-image");a.setAttribute("src",e.target.result),a.setAttribute("position",r.join(" ")),a.setAttribute("width",s),a.setAttribute("height",i),a.className="templateitem",document.querySelector("a-scene").appendChild(a)}},r.readAsDataURL(i))}}),!1)}))},51:e=>{e.exports=function(e){function t(){var t=document.querySelector("a-scene");t.hasLoaded?e():t.addEventListener("loaded",e())}"complete"===document.readyState||"loaded"===document.readyState?t():document.addEventListener("DOMContentLoaded",t)}},115:e=>{function t(e){this.material=e,this.maxBufferSize=1e6,this.geometries=[],this.current=null,this.strip=!0,this.addBuffer(!1)}t.prototype={restartPrimitive:function(){if(this.idx.position>=this.current.attributes.position.count)this.addBuffer(!1);else if(0!==this.idx.position){var e=3*(this.idx.position-1),t=this.current.attributes.position.array;this.addVertex(t[e++],t[e++],t[e++]),this.idx.color++,this.idx.normal++,this.idx.uv++}},remove:function(e,t){var s=this.current.attributes.position.array;if(this.idx.position>t.position)for(key in this.idx)for(var i="uv"===key?2:3,r=(s=e[key]*i,(t[key]+1)*i),a=this.idx[key]*i,n=r;n0&&(this.previous=this.current),this.idx={position:0,uv:0,normal:0,color:0},this.geometries.push(t),this.current=t,this.previous&&e){var u=3*(this.maxBufferSize-2),l=3*(this.maxBufferSize-2),d=(this.maxBufferSize,3*(this.maxBufferSize-2)),c=this.previous.attributes.position.array;this.addVertex(c[u++],c[u++],c[u++]),this.addVertex(c[u++],c[u++],c[u++]);var m=this.previous.attributes.normal.array;this.addNormal(m[d++],m[d++],m[d++]),this.addNormal(m[d++],m[d++],m[d++]);var p=this.previous.attributes.color.array;this.addColor(p[l++],p[l++],p[l++]),this.addColor(p[l++],p[l++],p[l++]);a=this.previous.attributes.uv.array}},addColor:function(e,t,s){this.current.attributes.color.setXYZ(this.idx.color++,e,t,s)},addNormal:function(e,t,s){this.current.attributes.normal.setXYZ(this.idx.normal++,e,t,s)},addVertex:function(e,t,s){var i=this.current.attributes.position;this.idx.position===i.count&&(this.addBuffer(!0),i=this.current.attributes.position),i.setXYZ(this.idx.position++,e,t,s),this.strip?(this.idx.position+1)%2==0&&this.idx.position>1&&(this.current.index.setXYZ(this.idx.position-3,this.idx.position-3,this.idx.position-2,this.idx.position-1),this.current.index.setXYZ(this.idx.position-2,this.idx.position-1,this.idx.position-2,this.idx.position)):(this.idx.position+1)%3==0&&this.current.index.setXYZ(this.idx.position,this.idx.position-2,this.idx.position-1,this.idx.position)},addUV:function(e,t){this.current.attributes.uv.setXY(this.idx.uv++,e,t)},update:function(){this.current.setDrawRange(0,3*this.idx.position-4),this.current.attributes.color.updateRange.count=3*this.idx.position,this.current.attributes.color.needsUpdate=!0,this.current.attributes.normal.updateRange.count=3*this.idx.position,this.current.attributes.normal.needsUpdate=!0,this.current.attributes.position.updateRange.count=3*this.idx.position,this.current.attributes.position.needsUpdate=!0,this.current.attributes.uv.updateRange.count=2*this.idx.position,this.current.attributes.uv.needsUpdate=!0,this.current.index.updateRange.count=3*this.idx.position,this.current.index.needsUpdate=!0}},e.exports=t},297:(e,t,s)=>{var i=s(115);function r(){this.sharedBuffers={}}r.prototype={addSharedBuffer:function(e,t){var s=new i(t);this.sharedBuffers[e]=s},getSharedBuffer:function(e){return this.sharedBuffers[e]}},e.exports=new r},796:()=>{var e,t;AFRAME.BRUSHES={},APAINTER_STATS={brushes:{}},AFRAME.registerBrush=function(e,t,s){var i={};if(Object.keys(t).forEach((function(e){i[e]={value:t[e],writable:!0}})),AFRAME.BRUSHES[e])throw new Error("The brush `"+e+"` 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 r=function(){};r.prototype={options:Object.assign({spacing:0,maxPoints:0},s),reset:function(){},tick:function(e,t){},undo:function(){},remove:function(){},addPoint:function(e,t,s,i,r){},getJSON:function(e){for(var t=[],s=0;s=this.options.maxPoints||n.call(this,e,t,s,i,r)&&(this.data.numPoints++,this.data.points.push({position:e.clone(),orientation:t.clone(),pressure:i,timestamp:r}),this.data.prevPosition=e.clone(),this.data.prevPointerPosition=s.clone())}),AFRAME.BRUSHES[e]=o,o.used=!1,o},AFRAME.registerSystem("brush",{schema:{},brushes:{},strokes:[],getUsedBrushes:function(){return Object.keys(AFRAME.BRUSHES).filter((function(e){return AFRAME.BRUSHES[e].used}))},getBrushByName:function(e){return AFRAME.BRUSHES[e]},undo:function(){for(var e,t=this.strokes.length-1;t>=0;t--)if("local"===this.strokes[t].data.owner){e=this.strokes.splice(t,1)[0];break}e&&(e.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:e}))},removeById:function(e){var t=this.strokes[1];if(console.log(t,this.strokes),t){for(var s=this.strokes.length-1;s>1;s--)if(stroke=this.strokes[s],t.sharedBuffer===stroke.sharedBuffer){for(key in console.log(">>>",stroke.prevIdx,"->",stroke.idx,"target",t.prevIdx,"->",t.idx),t.idx){var i=t.idx[key]-t.prevIdx[key];stroke.idx[key]-=i,stroke.prevIdx[key]-=i}console.log("<<<",stroke.idx,stroke.prevIdx)}this.strokes.splice(1,1)[0].remove()}},clear:function(){for(var e=this.strokes.length-1;e>=0;e--)if("local"===this.strokes[e].data.owner){var t=this.strokes[e];t.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:t})}Object.keys(AFRAME.BRUSHES).forEach((function(e){AFRAME.BRUSHES[e].used=!1})),this.strokes=[]},init:function(){this.version=1,this.clear(),this.controllerName=null;var e=this;this.sceneEl.addEventListener("controllerconnected",(function(t){e.controllerName=t.detail.name}))},tick:function(e,t){if(this.strokes.length)for(var s=0;s1&&(m=1);var f=this.getPointerPosition(l,c);u.addPoint(l,c,f,m,0)}}},addNewStroke:function(e,t,s,i,r){APAINTER_STATS.brushes[e]||(APAINTER_STATS.brushes[e]=0),APAINTER_STATS.brushes[e]++,i=i||"local",r=r||Date.now();var a=this.getBrushByName(e);if(!a){var n=Object.keys(AFRAME.BRUSHES)[0];a=AFRAME.BRUSHES[n],console.warn("Invalid brush name: `"+e+"` using `"+n+"`")}a.used=!0;var o=new a;o.brush=a,o.init(t,s,i,r),this.strokes.push(o);var h=document.querySelector(".a-drawing");return h||((h=document.createElement("a-entity")).className="a-drawing",document.querySelector("a-scene").appendChild(h)),o},getJSON:function(){var e={version:1,strokes:[],author:"",brushes:this.getUsedBrushes()};for(i=0;i{var i=s(618).saveAs;AFRAME.registerSystem("painter",{init:function(){var e={behaviours:{},mappings:{painting:{common:{"grip.down":"paint","trigger.changed":"undo"},"vive-controls":{axismove:"changeBrushSizeInc","trackpad.touchstart":"startChangeBrushSize","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"},"oculus-touch-controls":{axismove:"changeBrushSizeAbs","abutton.down":"toggleMenu","xbutton.down":"toggleMenu","ybutton.down":"aim","ybutton.up":"teleport","bbutton.down":"aim","bbutton.up":"teleport"},"windows-motion-controls":{axismove:"changeBrushSizeAbs","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"}}}};this.sceneEl.addEventListener("loaded",(function(){AFRAME.registerInputMappings(e),AFRAME.currentInputMapping="painting"})),this.version="1.2",this.brushSystem=this.sceneEl.systems.brush,this.showTemplateItems=!0;var t=function(){var e,t=/\+/g,s=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(t," "))},r=window.location.search.substring(1),a={};for(e=s.exec(r);e;)a[i(e[1])]=i(e[2]),e=s.exec(r);return a}();if(t.url||t.urljson){var s=void 0===t.urljson;this.brushSystem.loadFromUrl(t.url||t.urljson,s),document.getElementById("logo").setAttribute("visible",!1),document.getElementById("acamera").setAttribute("orbit-controls","initialPosition: 0 1.6 3"),document.getElementById("apainter-logo").classList.remove("hidden")}else{document.getElementById("acamera").setAttribute("position","0 1.6 0")}void 0!==t.bgcolor&&(document.body.style.backgroundColor="#"+t.bgcolor),void 0!==t.sky&&this.sceneEl.addEventListener("loaded",(function(e){""===t.sky?document.getElementById("sky").setAttribute("visible",!1):document.getElementById("sky").setAttribute("material","src",t.sky)})),void 0!==t.floor&&this.sceneEl.addEventListener("loaded",(function(e){""===t.floor?document.getElementById("ground").setAttribute("visible",!1):document.getElementById("ground").setAttribute("material","src",t.floor)})),this.paintingStarted=!1;var i=this;document.addEventListener("stroke-started",(function(e){if(!i.paintingStarted){document.getElementById("logo").emit("painting-started"),i.paintingStarted=!0}})),document.addEventListener("keyup",(function(e){if(!e.shiftKey&&!e.ctrlKey){if(8===e.keyCode&&i.brushSystem.undo(),67===e.keyCode&&i.brushSystem.clear(),71===e.keyCode){var t=document.querySelector(".a-drawing");i.sceneEl.systems["gltf-exporter"].export(t)}if(78===e.keyCode){var s=document.querySelectorAll("[paint-controls]"),r=Object.keys(AFRAME.BRUSHES),a=r.indexOf(s[0].components.brush.data.brush);a=(a+1)%r.length,[].forEach.call(s,(function(e){e.setAttribute("brush","brush",r[a])}))}if(84===e.keyCode&&i.brushSystem.generateTestLines(),82===e.keyCode&&i.brushSystem.generateRandomStrokes(1),76===e.keyCode&&i.brushSystem.loadFromUrl("demo.apa",!0),85===e.keyCode&&i.upload(),86===e.keyCode&&i.save(),74===e.keyCode&&i.saveJSON(),79===e.keyCode){i.showTemplateItems=!i.showTemplateItems;for(var n=document.querySelectorAll(".templateitem"),o=0;o{if(!e.ok)throw new Error(`Network request failed with status ${e.status}: ${e.statusText}`);return e.json()})).then((s=>{console.log("Uploaded link: ",t+s.secure_url),e.sceneEl.emit("drawing-upload-completed",{url:t+s.secure_url})})).catch((t=>{console.error(t),e.sceneEl.emit("drawing-upload-error",{errorInfo:t})}))}})},493:()=>{AFRAME.registerSystem("ui",{init:function(){this.initTextures()},initTextures:function(){var e=this,t="assets/images/ui-hover.png",s="assets/images/ui-pressed.png";this.sceneEl.systems.material.loadTexture(t,{src:t},(function(t){e.hoverTexture=t})),this.sceneEl.systems.material.loadTexture(s,{src:s},(function(t){e.pressedTexture=t}))},closeAll:function(){var e,t=document.querySelectorAll("[ui]");for(e=0;e{window.addEventListener("load",(function(e){var t=document.getElementById("apainter-ui"),s=document.querySelector("#apainter-ui .share"),i=document.getElementById("apainter-share-url"),r=document.querySelector("#apainter-ui .progress"),a=document.querySelector("#apainter-ui .bar");document.addEventListener("drawing-upload-completed",(function(e){s.classList.remove("hide"),r.classList.add("hide"),i.value=e.detail.url})),document.addEventListener("drawing-upload-started",(function(e){t.style.display="block",s.classList.add("hide"),r.classList.remove("hide")})),document.addEventListener("drawing-upload-progress",(function(e){a.style.width=Math.floor(100*e.detail.progress)+"%"})),new Clipboard(".button.copy").on("error",(function(e){console.error("Error copying to clipboard:",e.action,e.trigger)}))}))},555:()=>{window.Utils=function(){function e(e){return parseFloat(e.toFixed(6))}return{numberToFixed:e,arrayNumbersToFixed:function(t){for(var s=0;s{"use strict";e.exports=JSON.parse('{"meta":{"image":"brush_atlas.png","size":{"w":3584,"h":2944},"scale":"1"},"frames":{"stamp_grass.png":{"frame":{"x":0,"y":128,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"lines4.png":{"frame":{"x":0,"y":0,"w":2048,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":2048,"h":128},"sourceSize":{"w":2048,"h":128}},"stamp_fur2.png":{"frame":{"x":0,"y":640,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"stamp_bush.png":{"frame":{"x":0,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_gear.png":{"frame":{"x":1024,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_fur1.png":{"frame":{"x":2048,"y":0,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"lines3.png":{"frame":{"x":2048,"y":512,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_gradient.png":{"frame":{"x":2048,"y":768,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines5.png":{"frame":{"x":2048,"y":1024,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_flat.png":{"frame":{"x":2048,"y":1280,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_textured.png":{"frame":{"x":0,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"squared_textured.png":{"frame":{"x":1024,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge2.png":{"frame":{"x":2048,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge3.png":{"frame":{"x":0,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge1.png":{"frame":{"x":1024,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines2.png":{"frame":{"x":2048,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"stamp_leaf3.png":{"frame":{"x":1536,"y":128,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_dots.png":{"frame":{"x":1536,"y":640,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"thumb_stamp_star.png":{"frame":{"x":2304,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_grunge1.png":{"frame":{"x":512,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge2.png":{"frame":{"x":1024,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge3.png":{"frame":{"x":1536,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge4.png":{"frame":{"x":2048,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge5.png":{"frame":{"x":2560,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf1.png":{"frame":{"x":3072,"y":0,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf2.png":{"frame":{"x":3072,"y":512,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_column.png":{"frame":{"x":3072,"y":1024,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_snow.png":{"frame":{"x":3072,"y":1536,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_squares.png":{"frame":{"x":3072,"y":2048,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"lines1.png":{"frame":{"x":0,"y":2688,"w":256,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":256,"h":256},"sourceSize":{"w":256,"h":256}},"thumb_rainbow.png":{"frame":{"x":3072,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_single_sphere.png":{"frame":{"x":3200,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur1.png":{"frame":{"x":3328,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur2.png":{"frame":{"x":3456,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_grass.png":{"frame":{"x":2048,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_snow.png":{"frame":{"x":2176,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_star.png":{"frame":{"x":0,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}}}}')}},t={};function s(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,s),a.exports}s.amdD=function(){throw new Error("define cannot be used indirect")},s.amdO={},window.saveAs=s(618).saveAs,s(453),s(821),s(967),s(297),s(115),s(555),s(369),s(796),s(493),s(810),s(620),s(142),s(510),s(101),s(688),s(579),s(788),s(295),s(623),s(988),s(830),s(775),s(891)})(); \ No newline at end of file diff --git a/src/systems/painter.js b/src/systems/painter.js index dbd6d075..dbf2ffc6 100644 --- a/src/systems/painter.js +++ b/src/systems/painter.js @@ -9,8 +9,8 @@ AFRAME.registerSystem('painter', { mappings: { painting: { common: { - 'grip.down': 'undo', - 'trigger.changed': 'paint' + 'grip.down': 'paint', + 'trigger.changed': 'undo' }, 'vive-controls': { From 44550f67d4e356cc7caee40d6541d9a7a33f1ec4 Mon Sep 17 00:00:00 2001 From: Pawel Golinski Date: Mon, 5 Sep 2022 19:42:19 +0200 Subject: [PATCH 2/3] gripchanged, triggeddown --- build.js | 2 +- src/systems/painter.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.js b/build.js index 08e4b570..6a1a076b 100644 --- a/build.js +++ b/build.js @@ -1 +1 @@ -(()=>{var e={453:(e,t,s)=>{const i=s(95);function r(){this.map=(new THREE.TextureLoader).load("assets/images/"+i.meta.image)}r.prototype={getUVConverters:function(e){return e?(e=e.replace("brushes/",""),{convertU:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),r.frame.x/s.w+t*r.frame.w/s.w},convertV:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),1-(r.frame.y/s.h+t*r.frame.h/s.h)}}):{convertU:function(e){return e},convertV:function(e){return e}}}},window.atlas=new r},967:()=>{window.BinaryManager=function(e){this.dataview=new DataView(e),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 e=this.dataview.getUint8(this.offset++,!0),t="",s=0;s{AFRAME.registerBrush("cubes",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.BoxGeometry(1,1,1),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=i*this.data.size*Math.random();return a.scale.set(n,n,n),a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_cubes.gif",spacing:.01})},295:(e,t,s)=>{var i=s(297),r=s(51);!function(){r((function(){var e={vertexColors:THREE.VertexColors,side:THREE.DoubleSide},t={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,map:window.atlas.map,side:THREE.DoubleSide},s={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,side:THREE.DoubleSide,map:window.atlas.map,transparent:!0,alphaTest:.5};i.addSharedBuffer("strip-flat",new THREE.MeshBasicMaterial(e)),i.addSharedBuffer("strip-shaded",new THREE.MeshStandardMaterial(t)),i.addSharedBuffer("strip-textured",new THREE.MeshStandardMaterial(s))}));for(var e,t,s,a,n,o,h={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("strip-"+this.materialOptions.type),this.sharedBuffer.restartPrimitive(),this.sharedBuffer.strip=!0,this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.first=!0},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(o=new THREE.Vector3,function(e,t,s,i,r){var a=this.materialOptions.converter;o.set(1,0,0),o.applyQuaternion(t),o.normalize();var n=s.clone(),h=s.clone(),u=this.data.size*i;if(n.add(o.clone().multiplyScalar(u/2)),h.add(o.clone().multiplyScalar(-u/2)),this.first&&this.prevIdx.position>0&&(this.first=!1,this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.idx.normal++,this.sharedBuffer.idx.color++,this.sharedBuffer.idx.uv++,this.idx=Object.assign({},this.sharedBuffer.idx)),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(h.x,h.y,h.z),this.sharedBuffer.idx.normal+=2,this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),"textured"===this.materialOptions.type){this.sharedBuffer.idx.uv+=2;for(var l,d,c=this.sharedBuffer.current.attributes.uv.array,m=0;m{var e,t,s,r,a;a=new THREE.ShaderMaterial({vertexShader:"varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }",fragmentShader:"uniform sampler2D tDiffuse; uniform float amount; uniform float time; varying vec2 vUv; vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } void main() { float h = mod(vUv.x - time / 3000.0, 1.0); vec4 color = vec4(hsv2rgb(vec3(h, 1.0, 0.5)), 1.0); gl_FragColor = color; }",side:THREE.DoubleSide,uniforms:{time:{type:"f",value:0}}}),AFRAME.registerBrush("line-rainbow",{init:function(e,t){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.indices=new Uint32Array(4.5*this.options.maxPoints*4.5),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.linepositions=new Float32Array(this.options.maxPoints),this.geometry.setDrawRange(0,0),this.geometry.setAttribute("position",new THREE.BufferAttribute(this.vertices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setIndex(new THREE.BufferAttribute(this.indices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("lineposition",new THREE.BufferAttribute(this.linepositions,1).setUsage(THREE.DynamicDrawUsage)),this.material=a;var s=new THREE.Mesh(this.geometry,this.material);s.frustumCulled=!1,s.vertices=this.vertices,this.object3D.add(s),this.drawing=document.querySelector(".a-drawing"),this.drawing.object3D.add(this.object3D)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,r=new THREE.Vector3,function(a,n,o,h,u){var l=0;for(i=0;i6&&(this.geometry.index.setXYZ(this.idx/3-4,this.idx/3-4,this.idx/3-3,this.idx/3-2),this.geometry.index.setXYZ(this.idx/3-3,this.idx/3-2,this.idx/3-3,this.idx/3-1)),this.geometry.attributes.position.needsUpdate=!0,this.geometry.index.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints*6),!0}),tick:function(e,t){this.material.uniforms.time.value=e},undo:function(){this.drawing.object3D.children.pop()}},{thumbnail:"brushes/thumb_rainbow.png",maxPoints:3e3})},891:()=>{AFRAME.registerBrush("single-sphere",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.6,metalness:.2,side:THREE.FrontSide,flatShading:!0}),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,this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){this.firstPoint||(this.firstPoint=s.clone(),this.mesh.position.set(this.firstPoint.x,this.firstPoint.y,this.firstPoint.z)),this.mesh.visible=!0;var a=this.firstPoint.distanceTo(s);return this.mesh.scale.set(a,a,a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_single_sphere.png",spacing:0})},988:()=>{AFRAME.registerBrush("spheres",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.IcosahedronGeometry(1,0),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=this.data.size/2*i;return a.scale.set(n,n,n),a.initialScale=a.scale.clone(),a.phase=Math.random()*Math.PI*2,a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},tick:function(e,t){for(var s=0;s{var i=s(297),r=s(51);!function(){r((function(){var e=new THREE.MeshStandardMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5,roughness:.75,metalness:.25}),t=new THREE.MeshBasicMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5});i.addSharedBuffer("tris-flat",t),i.addSharedBuffer("tris-shaded",e)}));for(var e,t,s,a,n,o,h,u,l={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("tris-"+this.materialOptions.type),this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.strip=!1,this.currAngle=0,this.subTextures=1,this.angleJitter=0,this.autoRotate=!1,void 0!==this.materialOptions.subTextures&&(this.subTextures=this.materialOptions.subTextures),!0===this.materialOptions.autoRotate&&(this.autoRotate=!0),void 0!==this.materialOptions.angleJitter&&(this.angleJitter=this.materialOptions.angleJitter,this.angleJitter=2*this.angleJitter-this.angleJitter)},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,a=new THREE.Vector3,n=new THREE.Vector3,o=new THREE.Vector3,h=new THREE.Vector3,u=Math.PI/2,function(i,r,l,d,c){t.set(1,0,0),t.applyQuaternion(r),t.normalize(),e.set(0,1,0),e.applyQuaternion(r),e.normalize();var m=this.data.size*d/2,p=Math.PI/4+Math.random()*this.angleJitter;this.autoRotate&&(this.currAngle+=.1,p+=this.currAngle),s.copy(l).add(h.copy(t.applyAxisAngle(e,p)).multiplyScalar(m)),a.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),n.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),o.copy(l).add(t.applyAxisAngle(e,u).multiplyScalar(m)),this.idx.position,this.idx.position,this.sharedBuffer.addVertex(s.x,s.y,s.z),this.sharedBuffer.addVertex(a.x,a.y,a.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(o.x,o.y,o.z),this.sharedBuffer.addVertex(s.x,s.y,s.z);for(var f=0;f<6;f++)this.sharedBuffer.addNormal(e.x,e.y,e.z),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b);this.data.numPoints;var g=0,b=1;if(this.subTextures>1){var v=Math.floor(Math.random()*this.subTextures);b=(g=1/this.subTextures*v)+1/this.subTextures}var y=this.materialOptions.converter;return this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.update(),!0})},d=[{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}],c=0;c{AFRAME.registerComponent("brush-tip",{schema:{controller:{type:"string"},hand:{type:"string",oneOf:["left","right"]}},init:function(){var e=e=>THREE.MathUtils.degToRad(e);this.controllers={"oculus-touch-controller-v3":{left:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(7),z:e(-7)}},right:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(-7),z:e(7)}}}},this.data.controller&&this.setController(this.data.controller,this.data.hand)},setController:function(e,t){e in this.controllers?(this.el.object3D.position.set(this.controllers[e][t].positionOffset.x,this.controllers[e][t].positionOffset.y,this.controllers[e][t].positionOffset.z),this.el.object3D.rotation.set(this.controllers[e][t].rotationOffset.x,this.controllers[e][t].rotationOffset.y,this.controllers[e][t].rotationOffset.z)):console.error(`${e} is not present in the controllers list!`)}})},620:()=>{var e,t,s;AFRAME.registerComponent("brush",{schema:{color:{type:"color",default:"#ef2d5e"},size:{default:.01,min:.001,max:.3},brush:{default:"smooth"},enabled:{default:!0}},init:function(){var e=this.data;this.color=new THREE.Color(e.color),this.el.emit("brushcolor-changed",{color:this.color}),this.el.emit("brushsize-changed",{brushSize:e.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 t=this;this.el.addEventListener("undo",(function(e){t.data.enabled&&(t.system.undo(),document.getElementById("ui_undo").play())})),this.el.addEventListener("paint",(function(e){if(t.data.enabled){var s=e.detail.value;t.sizeModifier=s,s>.1?t.active||(t.startNewStroke(),t.active=!0):(t.active&&(t.previousEntity=t.currentEntity,t.currentStroke=null),t.active=!1)}})),this.hand="right-hand"===this.el.id?"right":"left"},update:function(e){var t=this.data;e.color!==t.color&&(this.color.set(t.color),this.el.emit("brushcolor-changed",{color:this.color})),e.size!==t.size&&this.el.emit("brushsize-changed",{size:t.size})},tick:(e=new THREE.Vector3,t=new THREE.Quaternion,s=new THREE.Vector3,function(i,r){if(this.currentStroke&&this.active){this.obj.matrixWorld.decompose(e,t,s);var a=this.system.getPointerPosition(e,t,this.hand);this.currentStroke.addPoint(e,t,a,this.sizeModifier,i)}}),startNewStroke:function(){document.getElementById("ui_paint").play(),this.currentStroke=this.system.addNewStroke(this.data.brush,this.color,this.data.size),this.el.emit("stroke-started",{entity:this.el,stroke:this.currentStroke})}})},510:()=>{AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"}},init:function(){this.objectLoader=new THREE.ObjectLoader,this.objectLoader.setCrossOrigin("")},update:function(e){var t=this,s=this.data.src;s&&s!==e.src&&this.objectLoader.load(this.data.src,(function(e){var i=(new THREE.Matrix4).makeRotationX(-Math.PI/2);e.traverse((function(e){e instanceof THREE.Mesh&&e.position.applyMatrix4(i)})),t.el.setObject3D("mesh",e),t.el.emit("model-loaded",{format:"json",model:e,src:s})}))}})},788:()=>{AFRAME.registerComponent("logo-model",{schema:{opacity:{default:1}},init:function(){this.model=null,this.el.setAttribute("obj-model","obj: #logoobj; mtl: #logomtl"),this.el.addEventListener("model-loaded",this.setModel.bind(this))},setModel:function(e){this.model=e.detail.model},update:function(){null!=this.model&&(this.model.children[0].material.opacity=this.data.opacity)}})},101:()=>{AFRAME.registerSystem("paint-controls",{numberStrokes:0}),AFRAME.registerComponent("paint-controls",{dependencies:["brush"],schema:{hand:{default:"left"}},init:function(){var e=this.el,t=this,s="assets/images/controller-pressed.png",i=null;this.controller=null,this.modelLoaded=!1,this.onEnterVR=this.onEnterVR.bind(this),e.sceneEl.addEventListener("enter-vr",this.onEnterVR),e.object3D.visible=!1,this.onModelLoaded=this.onModelLoaded.bind(this),e.addEventListener("model-loaded",this.onModelLoaded),e.addEventListener("changeBrushSizeAbs",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=(s.detail.axis[1]||s.detail.axis[3])/300,r=e.components.brush.schema.size,a=THREE.Math.clamp(t.el.getAttribute("brush").size-i,r.min,r.max);t.el.setAttribute("brush","size",a)}})),e.addEventListener("changeBrushSizeInc",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=s.detail.axis[1]||s.detail.axis[3];t.touchStarted&&(t.touchStarted=!1,t.startAxis=(i+1)/2);var r=(i+1)/2,a=(t.startAxis-r)/2;t.startAxis=r;var n=t.el.getAttribute("brush").size,o=e.components.brush.schema.size,h=THREE.Math.clamp(n-a,o.min,o.max);t.el.setAttribute("brush","size",h)}})),t.touchStarted=!1,e.addEventListener("startChangeBrushSize",(function(){t.touchStarted=!0})),e.addEventListener("controllerconnected",(function(s){var r=s.detail.name,a=s.detail.component.data.hand;const n=(s,i)=>{this.brushTip=document.createElement("a-entity"),this.brushTip.id=`${i}-tip`,this.brushTip.setAttribute("gltf-model","#tipObj"),this.brushTip.setAttribute("brush-tip",`controller: ${s}; hand: ${i}`),this.brushTip.addEventListener("model-loaded",t.onModelLoaded),e.appendChild(this.brushTip)};if("windows-motion-controls"===r){var o=s.detail.component.el.components["gltf-model"].data;const e="045E-065D";o&&o.indexOf(e)>=0&&(r="windows-motion-samsung-controls")}if(i=Utils.getTooltips(r),r.indexOf("windows-motion")>=0);else if("oculus-touch-controls"===r){const t=e.components[r].displayModel[a].modelUrl;n(/[^\/]*(?=-(?:left|right)\.)/.exec(t)[0],a)}else{if("vive-controls"!==r)return;e.setAttribute("gltf-model","url(assets/models/vive-controller.glb)")}i&&i.forEach((function(e){e.setAttribute("visible",!0);Array.prototype.slice.call(e.querySelectorAll("[tooltip]")).forEach((function(e){e.setAttribute("animation",{dur:1e3,delay:2e3,property:"tooltip.opacity",from:1,to:0,startEvents:"tooltip-fade"})}))})),this.controller=r})),e.addEventListener("brushsize-changed",(function(e){t.changeBrushSize(e.detail.size)})),e.addEventListener("brushcolor-changed",(function(e){t.changeBrushColor(e.detail.color)})),e.sceneEl.systems.material.loadTexture(s,{src:s},(function(e){var s=t.highLightMaterial=new THREE.MeshBasicMaterial;s.map=e,s.needsUpdate=!0})),this.startAxis=0,this.numberStrokes=0,document.addEventListener("stroke-started",(function(e){if(e.detail.entity.components["paint-controls"]===t&&(t.numberStrokes++,t.system.numberStrokes++,3===t.system.numberStrokes)){Array.prototype.slice.call(document.querySelectorAll("[tooltip]")).forEach((function(e){e.emit("tooltip-fade")}))}}))},changeBrushColor:function(e){this.modelLoaded&&this.buttonMeshes.sizeHint&&(this.buttonMeshes.colorTip.material.color.copy(e),this.buttonMeshes.sizeHint.material.color.copy(e))},changeBrushSize:function(e){var t=e/2*10;this.modelLoaded&&this.buttonMeshes.sizeHint&&this.buttonMeshes.sizeHint.scale.set(t,1,t)},mapping:{axis0:"trackpad",axis1:"trackpad",button0:"trackpad",button1:"trigger",button2:"grip",button3:"menu",button4:"system"},update:function(){var e=this.data,t=this.el;t.setAttribute("vive-controls",{hand:e.hand,model:!1}),t.setAttribute("oculus-touch-controls",{hand:e.hand,model:!0}),t.setAttribute("windows-motion-controls",{hand:e.hand})},play:function(){},pause:function(){},onEnterVR:function(){this.el.object3D.visible=!0},onModelLoaded:function(e){if((e.target===this.el||e.target.id.includes("-tip"))&&!this.buttonMeshes){var t,s=e.detail.model;(t=this.buttonMeshes={}).sizeHint=s.getObjectByName("sizehint"),t.colorTip=s.getObjectByName("tip"),this.modelLoaded=!0,this.changeBrushSize(this.el.components.brush.data.size),this.changeBrushColor(this.el.components.brush.color)}},onButtonEvent:function(e,t){var s=this.mapping["button"+e];this.el.emit(s+t),this.updateModel(s,t)},updateModel:function(e,t){var s="up"===t?this.material:this.highLightMaterial,i=this.buttonMeshes,r=i&&i[e];if("down"===t&&r&&!this.material&&(s=this.material=r.material),s)return"grip"===e?(i.grip.left.material=s,void(i.grip.right.material=s)):void(r&&(r.material=s))}})},579:()=>{var e,t,s;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 e=this.data,t=this.raycaster;t.far=e.far,t.near=e.near,this.refreshObjects()},refreshObjects:function(){var e,t,s=this.data;if(s.objects)for(t=this.el.sceneEl.querySelectorAll(s.objects),this.objects=[],e=0;e{var e,t,s,i,r,a;AFRAME.registerComponent("ui",{schema:{brightness:{default:1,max:1,min:0},opacity:{default:0}},dependencies:["ui-raycaster"],init:function(){var e=this.el,t=this.uiEl=document.createElement("a-entity"),s=this.rayEl=document.createElement("a-entity");this.closed=!0,this.isTooltipPaused=!1,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),t.setAttribute("material",{color:"#ffffff",flatShading:!0,shader:"flat",transparent:!0,fog:!1,src:"#uinormal"}),t.setAttribute("obj-model","obj:#uiobj"),t.setAttribute("position","0 0.04 -0.15"),t.setAttribute("scale","0 0 0"),t.setAttribute("visible",!1),t.classList.add("apainter-ui"),e.appendChild(t),s.setAttribute("line",""),e.appendChild(s),e.setAttribute("ui-raycaster",{far:this.rayDistance,objects:".apainter-ui",rotation:-this.rayAngle}),this.controller=null;var i=this;e.addEventListener("controllerconnected",(function(s){var r=s.detail.name;i.tooltips=Utils.getTooltips(r),i.controller={name:r,hand:s.detail.component.data.hand},"oculus-touch-controls"===r?(i.uiEl.setAttribute("rotation","45 0 0"),t.setAttribute("position","0 0.13 -0.08"),i.rayAngle=0,e.setAttribute("ui-raycaster",{rotation:0})):"windows-motion-controls"===r&&(i.rayAngle=25,i.rayDistance=1,e.setAttribute("ui-raycaster",{rotation:-30,far:i.rayDistance})),i.el.isPlaying&&i.addToggleEvent()}))},initColorWheel:function(){var e=this.objects.hueWheel,t=new THREE.ShaderMaterial({uniforms:{brightness:{type:"f",value:this.hsv.v}},vertexShader:" varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); gl_Position = projectionMatrix * mvPosition; } ",fragmentShader:" #define M_PI2 6.28318530718\n uniform float brightness; varying vec2 vUv; vec3 hsb2rgb(in vec3 c){ vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); rgb = rgb * rgb * (3.0 - 2.0 * rgb); return c.z * mix( vec3(1.0), rgb, c.y); } void main() { vec2 toCenter = vec2(0.5) - vUv; float angle = atan(toCenter.y, toCenter.x); float radius = length(toCenter) * 2.0; vec3 color = hsb2rgb(vec3((angle / M_PI2) + 0.5, radius, brightness)); gl_FragColor = vec4(color, 1.0); } "});e.material=t},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),this.open=this.open.bind(this),this.close=this.close.bind(this)},tick:function(){!this.closed&&this.handEl&&(this.updateIntersections(),this.handleHover(),this.handlePressedButtons())},update:function(){this.messagesMaterial&&(this.messagesMaterial.opacity=this.data.opacity)},onTriggerChanged:function(e){var t=e.detail.value;this.lastTriggerValue=t,e.detail.value>=.25?this.triggeredPressed=!0:(this.triggeredPressed=!1,this.handleButtonUp())},handleButtonDown:function(e,t){var s=e.name;if(!this.activeWidget||this.activeWidget===s){switch(this.activeWidget=s,!0){case"brightness"===s:this.onBrightnessDown(t);break;case"brushnext"===s:this.pressedObjects[s]||this.nextPage();break;case"brushprev"===s:this.pressedObjects[s]||this.previousPage();break;case"clear"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.brush.clear(),this.playSound("ui_click1"));break;case"copy"===s:this.pressedObjects[s]||(this.copyBrush(),this.playSound("ui_click1"));break;case"hue"===s:this.onHueDown(t);break;case"save"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.painter.upload(),this.playSound("ui_click1"));break;case"sizebg"===s:this.onBrushSizeBackgroundDown(t);break;case this.brushRegexp.test(s):this.onBrushDown(s);break;case this.colorHistoryRegexp.test(s):this.onColorHistoryButtonDown(e);break;default:this.activeWidget=void 0}this.pressedObjects[s]=e}},copyBrush:function(){var e=this.el.getAttribute("brush");this.handEl.setAttribute("brush","brush",e.brush),this.handEl.setAttribute("brush","color",e.color),this.handEl.setAttribute("brush","size",e.size),this.colorHasChanged=!0},handleButtonUp:function(){var e=this.pressedObjects,t=this.unpressedObjects;this.activeWidget=void 0,Object.keys(e).forEach((function(s){var i=e[s].name;t[i]=e[i],delete e[i]}))},handlePressedButtons:function(){var e=this;this.triggeredPressed&&this.hoveredOnObjects.forEach((function(t){e.handleButtonDown(t.object,t.point)}))},onColorHistoryButtonDown:function(e){var t=e.material.color.getHexString();this.handEl.setAttribute("brush","color","#"+t),this.playSound("ui_click0",e.name)},onBrushDown:function(e){var t=this.brushButtonsMapping[e];t&&(this.selectBrushButton(e),this.handEl.setAttribute("brush","brush",t.toLowerCase()))},selectBrushButton:function(e){var t=this.uiEl.getObject3D("mesh").getObjectByName(e+"bg"),s=this.selectedObjects,i=this.selectedBrush;i&&(this.highlightMaterials[i.name]||this.initHighlightMaterial(t),i.material=this.highlightMaterials[i.name].normal,delete s[i.name]),s[t.name]=t,this.selectedBrush=t,this.playSound("ui_click1",e)},onHueDown:function(e){var t,s=this.objects.hueWheel,i=this.colorWheelSize;s.updateMatrixWorld(),s.worldToLocal(e),this.objects.hueCursor.position.copy(e);var r=((t={r:Math.sqrt(e.x*e.x+e.z*e.z),theta:Math.PI+Math.atan2(-e.z,e.x)}).theta*(180/Math.PI)+180)%360;this.hsv.h=r/360,this.hsv.s=t.r/i,this.updateColor(),this.playSound("ui_click0","hue")},updateColor:function(){var e=this.hsv2rgb(this.hsv),t="rgb("+e.r+", "+e.g+", "+e.b+")";this.handEl.setAttribute("brush","color",t),this.colorHasChanged=!0},hsv2rgb:function(e){var t,s,i,r,a,n,o,h,u=THREE.Math.clamp(e.h,0,1),l=THREE.Math.clamp(e.s,0,1),d=e.v;switch(n=d*(1-l),o=d*(1-(a=6*u-(r=Math.floor(6*u)))*l),h=d*(1-(1-a)*l),r%6){case 0:t=d,s=h,i=n;break;case 1:t=o,s=d,i=n;break;case 2:t=n,s=d,i=h;break;case 3:t=n,s=o,i=d;break;case 4:t=h,s=n,i=d;break;case 5:t=d,s=n,i=o}return{r:Math.round(255*t),g:Math.round(255*s),b:Math.round(255*i)}},rgb2hsv:function(e,t,s){var i,r=Math.max(e,t,s),a=Math.min(e,t,s),n=r-a,o=0===r?0:n/r,h=r;switch(1===arguments.length&&(t=e.g,s=e.b,e=e.r),r){case a:i=0;break;case e:i=t-s+n*(t=this.brushesPagesNum))for(this.objects.previousPage.visible=0!==e,e===this.brushesPagesNum-1?this.objects.nextPage.visible=!1:this.objects.nextPage.visible=!0,i=0;i=this.brushesPagesNum-1||(this.brushesPage++,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},previousPage:function(){0!==this.brushesPage&&(this.brushesPage--,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},initHighlightMaterial:function(e){var t=e.name,s=this.brushRegexp.test(t),i=-1!==t.indexOf("history"),r="hue"===t||"huecursor"===t,a={normal:e.material,hover:e.material,pressed:e.material,selected:e.material};s||i||r||(a.normal=e.material,a.hover=e.material.clone(),a.hover.map=this.system.hoverTexture,a.selected=e.material.clone(),a.selected.map=this.system.pressedTexture,a.pressed=e.material.clone(),a.pressed.map=this.system.pressedTexture),this.highlightMaterials[t]=a},toggleMenu:function(e){this.closed?(this.system.closeAll(),this.open(),this.system.opened=this.el):(this.close(),this.system.opened=void 0)},open:function(){var e=this.uiEl;if(this.closed){if(this.uiEl.setAttribute("visible",!0),this.uiEl.setAttribute("animation",{dur:100,easing:"easeOutExpo",property:"scale",from:{x:0,y:0,z:0},to:{x:1,y:1,z:1}}),this.el.setAttribute("brush","enabled",!1),this.rayEl.setAttribute("visible",!1),this.closed=!1,this.tooltips){var t=this;this.tooltips.forEach((function(s){s.getAttribute("visible")&&e.parentEl.id!==s.parentEl.id&&(t.isTooltipPaused=!0,s.setAttribute("visible",!1))}))}this.playSound("ui_menu")}},updateIntersections:function(){var e=this.raycaster=new THREE.Raycaster;return function(t){this.updateRaycaster(e),this.intersectedObjects=e.intersectObjects(this.menuEls,!0)}}(),onIntersection:function(e){var t=this.closed&&this.system.opened;this.el.components.brush.active||(this.rayEl.setAttribute("visible",!!t),this.el.setAttribute("brush","enabled",!1))},onIntersected:function(e){var t=e.detail.el;this.handEl&&this.removeHandListeners(),this.handEl=t,this.handRayEl=this.handEl.components.ui.rayEl,this.menuEls=this.uiEl.object3D.children,this.syncUI(),this.addHandListeners()},addHandListeners:function(){var e=this.handEl;e.addEventListener("componentchanged",this.onComponentChanged),e.addEventListener("stroke-started",this.onStrokeStarted),e.addEventListener("triggerchanged",this.onTriggerChanged)},removeHandListeners:function(){var e=this.handEl;e.removeEventListener("componentchanged",this.onComponentChanged),e.removeEventListener("stroke-started",this.onStrokeStarted),e.removeEventListener("triggerchanged",this.onTriggerChanged)},onComponentChanged:function(e){"brush"===e.detail.name&&this.syncUI()},syncUI:function(){var e;this.handEl&&this.objects&&(e=this.handEl.getAttribute("brush"),this.updateSizeSlider(e.size),this.updateColorUI(e.color),this.updateColorHistory())},initColorHistory:function(){for(var e,t=this.objects.currentColor,s=0;s{window.addEventListener("load",(function(e){var t=document.body;t.addEventListener("dragover",(function(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect="copy"}),!1),t.addEventListener("drop",(function(e){e.stopPropagation(),e.preventDefault();for(var t=e.dataTransfer.files,s=0;s{e.color.set("#333")})):r.material.color.set("#333")}s.setObject3D("mesh",t),s.className="templateitem",document.querySelector("a-scene").appendChild(s)},r.readAsText(i)):i.type.match(/image.*/)&&((r=new FileReader).onload=function(e){var t=new Image;t.src=e.target.result,t.onload=()=>{var s,i;t.width>t.height?(s=1,i=t.height/t.width):(i=1,s=t.width/t.height);var r=[3*Math.random()-1.5,1+Math.random()-.5,.2*Math.random()-1.4],a=document.createElement("a-image");a.setAttribute("src",e.target.result),a.setAttribute("position",r.join(" ")),a.setAttribute("width",s),a.setAttribute("height",i),a.className="templateitem",document.querySelector("a-scene").appendChild(a)}},r.readAsDataURL(i))}}),!1)}))},51:e=>{e.exports=function(e){function t(){var t=document.querySelector("a-scene");t.hasLoaded?e():t.addEventListener("loaded",e())}"complete"===document.readyState||"loaded"===document.readyState?t():document.addEventListener("DOMContentLoaded",t)}},115:e=>{function t(e){this.material=e,this.maxBufferSize=1e6,this.geometries=[],this.current=null,this.strip=!0,this.addBuffer(!1)}t.prototype={restartPrimitive:function(){if(this.idx.position>=this.current.attributes.position.count)this.addBuffer(!1);else if(0!==this.idx.position){var e=3*(this.idx.position-1),t=this.current.attributes.position.array;this.addVertex(t[e++],t[e++],t[e++]),this.idx.color++,this.idx.normal++,this.idx.uv++}},remove:function(e,t){var s=this.current.attributes.position.array;if(this.idx.position>t.position)for(key in this.idx)for(var i="uv"===key?2:3,r=(s=e[key]*i,(t[key]+1)*i),a=this.idx[key]*i,n=r;n0&&(this.previous=this.current),this.idx={position:0,uv:0,normal:0,color:0},this.geometries.push(t),this.current=t,this.previous&&e){var u=3*(this.maxBufferSize-2),l=3*(this.maxBufferSize-2),d=(this.maxBufferSize,3*(this.maxBufferSize-2)),c=this.previous.attributes.position.array;this.addVertex(c[u++],c[u++],c[u++]),this.addVertex(c[u++],c[u++],c[u++]);var m=this.previous.attributes.normal.array;this.addNormal(m[d++],m[d++],m[d++]),this.addNormal(m[d++],m[d++],m[d++]);var p=this.previous.attributes.color.array;this.addColor(p[l++],p[l++],p[l++]),this.addColor(p[l++],p[l++],p[l++]);a=this.previous.attributes.uv.array}},addColor:function(e,t,s){this.current.attributes.color.setXYZ(this.idx.color++,e,t,s)},addNormal:function(e,t,s){this.current.attributes.normal.setXYZ(this.idx.normal++,e,t,s)},addVertex:function(e,t,s){var i=this.current.attributes.position;this.idx.position===i.count&&(this.addBuffer(!0),i=this.current.attributes.position),i.setXYZ(this.idx.position++,e,t,s),this.strip?(this.idx.position+1)%2==0&&this.idx.position>1&&(this.current.index.setXYZ(this.idx.position-3,this.idx.position-3,this.idx.position-2,this.idx.position-1),this.current.index.setXYZ(this.idx.position-2,this.idx.position-1,this.idx.position-2,this.idx.position)):(this.idx.position+1)%3==0&&this.current.index.setXYZ(this.idx.position,this.idx.position-2,this.idx.position-1,this.idx.position)},addUV:function(e,t){this.current.attributes.uv.setXY(this.idx.uv++,e,t)},update:function(){this.current.setDrawRange(0,3*this.idx.position-4),this.current.attributes.color.updateRange.count=3*this.idx.position,this.current.attributes.color.needsUpdate=!0,this.current.attributes.normal.updateRange.count=3*this.idx.position,this.current.attributes.normal.needsUpdate=!0,this.current.attributes.position.updateRange.count=3*this.idx.position,this.current.attributes.position.needsUpdate=!0,this.current.attributes.uv.updateRange.count=2*this.idx.position,this.current.attributes.uv.needsUpdate=!0,this.current.index.updateRange.count=3*this.idx.position,this.current.index.needsUpdate=!0}},e.exports=t},297:(e,t,s)=>{var i=s(115);function r(){this.sharedBuffers={}}r.prototype={addSharedBuffer:function(e,t){var s=new i(t);this.sharedBuffers[e]=s},getSharedBuffer:function(e){return this.sharedBuffers[e]}},e.exports=new r},796:()=>{var e,t;AFRAME.BRUSHES={},APAINTER_STATS={brushes:{}},AFRAME.registerBrush=function(e,t,s){var i={};if(Object.keys(t).forEach((function(e){i[e]={value:t[e],writable:!0}})),AFRAME.BRUSHES[e])throw new Error("The brush `"+e+"` 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 r=function(){};r.prototype={options:Object.assign({spacing:0,maxPoints:0},s),reset:function(){},tick:function(e,t){},undo:function(){},remove:function(){},addPoint:function(e,t,s,i,r){},getJSON:function(e){for(var t=[],s=0;s=this.options.maxPoints||n.call(this,e,t,s,i,r)&&(this.data.numPoints++,this.data.points.push({position:e.clone(),orientation:t.clone(),pressure:i,timestamp:r}),this.data.prevPosition=e.clone(),this.data.prevPointerPosition=s.clone())}),AFRAME.BRUSHES[e]=o,o.used=!1,o},AFRAME.registerSystem("brush",{schema:{},brushes:{},strokes:[],getUsedBrushes:function(){return Object.keys(AFRAME.BRUSHES).filter((function(e){return AFRAME.BRUSHES[e].used}))},getBrushByName:function(e){return AFRAME.BRUSHES[e]},undo:function(){for(var e,t=this.strokes.length-1;t>=0;t--)if("local"===this.strokes[t].data.owner){e=this.strokes.splice(t,1)[0];break}e&&(e.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:e}))},removeById:function(e){var t=this.strokes[1];if(console.log(t,this.strokes),t){for(var s=this.strokes.length-1;s>1;s--)if(stroke=this.strokes[s],t.sharedBuffer===stroke.sharedBuffer){for(key in console.log(">>>",stroke.prevIdx,"->",stroke.idx,"target",t.prevIdx,"->",t.idx),t.idx){var i=t.idx[key]-t.prevIdx[key];stroke.idx[key]-=i,stroke.prevIdx[key]-=i}console.log("<<<",stroke.idx,stroke.prevIdx)}this.strokes.splice(1,1)[0].remove()}},clear:function(){for(var e=this.strokes.length-1;e>=0;e--)if("local"===this.strokes[e].data.owner){var t=this.strokes[e];t.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:t})}Object.keys(AFRAME.BRUSHES).forEach((function(e){AFRAME.BRUSHES[e].used=!1})),this.strokes=[]},init:function(){this.version=1,this.clear(),this.controllerName=null;var e=this;this.sceneEl.addEventListener("controllerconnected",(function(t){e.controllerName=t.detail.name}))},tick:function(e,t){if(this.strokes.length)for(var s=0;s1&&(m=1);var f=this.getPointerPosition(l,c);u.addPoint(l,c,f,m,0)}}},addNewStroke:function(e,t,s,i,r){APAINTER_STATS.brushes[e]||(APAINTER_STATS.brushes[e]=0),APAINTER_STATS.brushes[e]++,i=i||"local",r=r||Date.now();var a=this.getBrushByName(e);if(!a){var n=Object.keys(AFRAME.BRUSHES)[0];a=AFRAME.BRUSHES[n],console.warn("Invalid brush name: `"+e+"` using `"+n+"`")}a.used=!0;var o=new a;o.brush=a,o.init(t,s,i,r),this.strokes.push(o);var h=document.querySelector(".a-drawing");return h||((h=document.createElement("a-entity")).className="a-drawing",document.querySelector("a-scene").appendChild(h)),o},getJSON:function(){var e={version:1,strokes:[],author:"",brushes:this.getUsedBrushes()};for(i=0;i{var i=s(618).saveAs;AFRAME.registerSystem("painter",{init:function(){var e={behaviours:{},mappings:{painting:{common:{"grip.down":"paint","trigger.changed":"undo"},"vive-controls":{axismove:"changeBrushSizeInc","trackpad.touchstart":"startChangeBrushSize","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"},"oculus-touch-controls":{axismove:"changeBrushSizeAbs","abutton.down":"toggleMenu","xbutton.down":"toggleMenu","ybutton.down":"aim","ybutton.up":"teleport","bbutton.down":"aim","bbutton.up":"teleport"},"windows-motion-controls":{axismove:"changeBrushSizeAbs","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"}}}};this.sceneEl.addEventListener("loaded",(function(){AFRAME.registerInputMappings(e),AFRAME.currentInputMapping="painting"})),this.version="1.2",this.brushSystem=this.sceneEl.systems.brush,this.showTemplateItems=!0;var t=function(){var e,t=/\+/g,s=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(t," "))},r=window.location.search.substring(1),a={};for(e=s.exec(r);e;)a[i(e[1])]=i(e[2]),e=s.exec(r);return a}();if(t.url||t.urljson){var s=void 0===t.urljson;this.brushSystem.loadFromUrl(t.url||t.urljson,s),document.getElementById("logo").setAttribute("visible",!1),document.getElementById("acamera").setAttribute("orbit-controls","initialPosition: 0 1.6 3"),document.getElementById("apainter-logo").classList.remove("hidden")}else{document.getElementById("acamera").setAttribute("position","0 1.6 0")}void 0!==t.bgcolor&&(document.body.style.backgroundColor="#"+t.bgcolor),void 0!==t.sky&&this.sceneEl.addEventListener("loaded",(function(e){""===t.sky?document.getElementById("sky").setAttribute("visible",!1):document.getElementById("sky").setAttribute("material","src",t.sky)})),void 0!==t.floor&&this.sceneEl.addEventListener("loaded",(function(e){""===t.floor?document.getElementById("ground").setAttribute("visible",!1):document.getElementById("ground").setAttribute("material","src",t.floor)})),this.paintingStarted=!1;var i=this;document.addEventListener("stroke-started",(function(e){if(!i.paintingStarted){document.getElementById("logo").emit("painting-started"),i.paintingStarted=!0}})),document.addEventListener("keyup",(function(e){if(!e.shiftKey&&!e.ctrlKey){if(8===e.keyCode&&i.brushSystem.undo(),67===e.keyCode&&i.brushSystem.clear(),71===e.keyCode){var t=document.querySelector(".a-drawing");i.sceneEl.systems["gltf-exporter"].export(t)}if(78===e.keyCode){var s=document.querySelectorAll("[paint-controls]"),r=Object.keys(AFRAME.BRUSHES),a=r.indexOf(s[0].components.brush.data.brush);a=(a+1)%r.length,[].forEach.call(s,(function(e){e.setAttribute("brush","brush",r[a])}))}if(84===e.keyCode&&i.brushSystem.generateTestLines(),82===e.keyCode&&i.brushSystem.generateRandomStrokes(1),76===e.keyCode&&i.brushSystem.loadFromUrl("demo.apa",!0),85===e.keyCode&&i.upload(),86===e.keyCode&&i.save(),74===e.keyCode&&i.saveJSON(),79===e.keyCode){i.showTemplateItems=!i.showTemplateItems;for(var n=document.querySelectorAll(".templateitem"),o=0;o{if(!e.ok)throw new Error(`Network request failed with status ${e.status}: ${e.statusText}`);return e.json()})).then((s=>{console.log("Uploaded link: ",t+s.secure_url),e.sceneEl.emit("drawing-upload-completed",{url:t+s.secure_url})})).catch((t=>{console.error(t),e.sceneEl.emit("drawing-upload-error",{errorInfo:t})}))}})},493:()=>{AFRAME.registerSystem("ui",{init:function(){this.initTextures()},initTextures:function(){var e=this,t="assets/images/ui-hover.png",s="assets/images/ui-pressed.png";this.sceneEl.systems.material.loadTexture(t,{src:t},(function(t){e.hoverTexture=t})),this.sceneEl.systems.material.loadTexture(s,{src:s},(function(t){e.pressedTexture=t}))},closeAll:function(){var e,t=document.querySelectorAll("[ui]");for(e=0;e{window.addEventListener("load",(function(e){var t=document.getElementById("apainter-ui"),s=document.querySelector("#apainter-ui .share"),i=document.getElementById("apainter-share-url"),r=document.querySelector("#apainter-ui .progress"),a=document.querySelector("#apainter-ui .bar");document.addEventListener("drawing-upload-completed",(function(e){s.classList.remove("hide"),r.classList.add("hide"),i.value=e.detail.url})),document.addEventListener("drawing-upload-started",(function(e){t.style.display="block",s.classList.add("hide"),r.classList.remove("hide")})),document.addEventListener("drawing-upload-progress",(function(e){a.style.width=Math.floor(100*e.detail.progress)+"%"})),new Clipboard(".button.copy").on("error",(function(e){console.error("Error copying to clipboard:",e.action,e.trigger)}))}))},555:()=>{window.Utils=function(){function e(e){return parseFloat(e.toFixed(6))}return{numberToFixed:e,arrayNumbersToFixed:function(t){for(var s=0;s{"use strict";e.exports=JSON.parse('{"meta":{"image":"brush_atlas.png","size":{"w":3584,"h":2944},"scale":"1"},"frames":{"stamp_grass.png":{"frame":{"x":0,"y":128,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"lines4.png":{"frame":{"x":0,"y":0,"w":2048,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":2048,"h":128},"sourceSize":{"w":2048,"h":128}},"stamp_fur2.png":{"frame":{"x":0,"y":640,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"stamp_bush.png":{"frame":{"x":0,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_gear.png":{"frame":{"x":1024,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_fur1.png":{"frame":{"x":2048,"y":0,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"lines3.png":{"frame":{"x":2048,"y":512,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_gradient.png":{"frame":{"x":2048,"y":768,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines5.png":{"frame":{"x":2048,"y":1024,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_flat.png":{"frame":{"x":2048,"y":1280,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_textured.png":{"frame":{"x":0,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"squared_textured.png":{"frame":{"x":1024,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge2.png":{"frame":{"x":2048,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge3.png":{"frame":{"x":0,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge1.png":{"frame":{"x":1024,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines2.png":{"frame":{"x":2048,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"stamp_leaf3.png":{"frame":{"x":1536,"y":128,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_dots.png":{"frame":{"x":1536,"y":640,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"thumb_stamp_star.png":{"frame":{"x":2304,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_grunge1.png":{"frame":{"x":512,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge2.png":{"frame":{"x":1024,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge3.png":{"frame":{"x":1536,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge4.png":{"frame":{"x":2048,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge5.png":{"frame":{"x":2560,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf1.png":{"frame":{"x":3072,"y":0,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf2.png":{"frame":{"x":3072,"y":512,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_column.png":{"frame":{"x":3072,"y":1024,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_snow.png":{"frame":{"x":3072,"y":1536,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_squares.png":{"frame":{"x":3072,"y":2048,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"lines1.png":{"frame":{"x":0,"y":2688,"w":256,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":256,"h":256},"sourceSize":{"w":256,"h":256}},"thumb_rainbow.png":{"frame":{"x":3072,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_single_sphere.png":{"frame":{"x":3200,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur1.png":{"frame":{"x":3328,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur2.png":{"frame":{"x":3456,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_grass.png":{"frame":{"x":2048,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_snow.png":{"frame":{"x":2176,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_star.png":{"frame":{"x":0,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}}}}')}},t={};function s(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,s),a.exports}s.amdD=function(){throw new Error("define cannot be used indirect")},s.amdO={},window.saveAs=s(618).saveAs,s(453),s(821),s(967),s(297),s(115),s(555),s(369),s(796),s(493),s(810),s(620),s(142),s(510),s(101),s(688),s(579),s(788),s(295),s(623),s(988),s(830),s(775),s(891)})(); \ No newline at end of file +(()=>{var e={453:(e,t,s)=>{const i=s(95);function r(){this.map=(new THREE.TextureLoader).load("assets/images/"+i.meta.image)}r.prototype={getUVConverters:function(e){return e?(e=e.replace("brushes/",""),{convertU:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),r.frame.x/s.w+t*r.frame.w/s.w},convertV:function(t){var s=i.meta.size,r=i.frames[e];return(t>1||t<0)&&(t=0),1-(r.frame.y/s.h+t*r.frame.h/s.h)}}):{convertU:function(e){return e},convertV:function(e){return e}}}},window.atlas=new r},967:()=>{window.BinaryManager=function(e){this.dataview=new DataView(e),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 e=this.dataview.getUint8(this.offset++,!0),t="",s=0;s{AFRAME.registerBrush("cubes",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.BoxGeometry(1,1,1),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=i*this.data.size*Math.random();return a.scale.set(n,n,n),a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_cubes.gif",spacing:.01})},295:(e,t,s)=>{var i=s(297),r=s(51);!function(){r((function(){var e={vertexColors:THREE.VertexColors,side:THREE.DoubleSide},t={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,map:window.atlas.map,side:THREE.DoubleSide},s={roughness:.75,metalness:.25,vertexColors:THREE.VertexColors,side:THREE.DoubleSide,map:window.atlas.map,transparent:!0,alphaTest:.5};i.addSharedBuffer("strip-flat",new THREE.MeshBasicMaterial(e)),i.addSharedBuffer("strip-shaded",new THREE.MeshStandardMaterial(t)),i.addSharedBuffer("strip-textured",new THREE.MeshStandardMaterial(s))}));for(var e,t,s,a,n,o,h={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("strip-"+this.materialOptions.type),this.sharedBuffer.restartPrimitive(),this.sharedBuffer.strip=!0,this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.first=!0},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(o=new THREE.Vector3,function(e,t,s,i,r){var a=this.materialOptions.converter;o.set(1,0,0),o.applyQuaternion(t),o.normalize();var n=s.clone(),h=s.clone(),u=this.data.size*i;if(n.add(o.clone().multiplyScalar(u/2)),h.add(o.clone().multiplyScalar(-u/2)),this.first&&this.prevIdx.position>0&&(this.first=!1,this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.idx.normal++,this.sharedBuffer.idx.color++,this.sharedBuffer.idx.uv++,this.idx=Object.assign({},this.sharedBuffer.idx)),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(h.x,h.y,h.z),this.sharedBuffer.idx.normal+=2,this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b),"textured"===this.materialOptions.type){this.sharedBuffer.idx.uv+=2;for(var l,d,c=this.sharedBuffer.current.attributes.uv.array,m=0;m{var e,t,s,r,a;a=new THREE.ShaderMaterial({vertexShader:"varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }",fragmentShader:"uniform sampler2D tDiffuse; uniform float amount; uniform float time; varying vec2 vUv; vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } void main() { float h = mod(vUv.x - time / 3000.0, 1.0); vec4 color = vec4(hsv2rgb(vec3(h, 1.0, 0.5)), 1.0); gl_FragColor = color; }",side:THREE.DoubleSide,uniforms:{time:{type:"f",value:0}}}),AFRAME.registerBrush("line-rainbow",{init:function(e,t){this.idx=0,this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*this.options.maxPoints*3),this.indices=new Uint32Array(4.5*this.options.maxPoints*4.5),this.uvs=new Float32Array(2*this.options.maxPoints*2),this.linepositions=new Float32Array(this.options.maxPoints),this.geometry.setDrawRange(0,0),this.geometry.setAttribute("position",new THREE.BufferAttribute(this.vertices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setIndex(new THREE.BufferAttribute(this.indices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("lineposition",new THREE.BufferAttribute(this.linepositions,1).setUsage(THREE.DynamicDrawUsage)),this.material=a;var s=new THREE.Mesh(this.geometry,this.material);s.frustumCulled=!1,s.vertices=this.vertices,this.object3D.add(s),this.drawing=document.querySelector(".a-drawing"),this.drawing.object3D.add(this.object3D)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,r=new THREE.Vector3,function(a,n,o,h,u){var l=0;for(i=0;i6&&(this.geometry.index.setXYZ(this.idx/3-4,this.idx/3-4,this.idx/3-3,this.idx/3-2),this.geometry.index.setXYZ(this.idx/3-3,this.idx/3-2,this.idx/3-3,this.idx/3-1)),this.geometry.attributes.position.needsUpdate=!0,this.geometry.index.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*this.data.numPoints*6),!0}),tick:function(e,t){this.material.uniforms.time.value=e},undo:function(){this.drawing.object3D.children.pop()}},{thumbnail:"brushes/thumb_rainbow.png",maxPoints:3e3})},891:()=>{AFRAME.registerBrush("single-sphere",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.6,metalness:.2,side:THREE.FrontSide,flatShading:!0}),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,this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){this.firstPoint||(this.firstPoint=s.clone(),this.mesh.position.set(this.firstPoint.x,this.firstPoint.y,this.firstPoint.z)),this.mesh.visible=!0;var a=this.firstPoint.distanceTo(s);return this.mesh.scale.set(a,a,a),!0},undo:function(){this.drawingEl.object3D.children.pop()}},{thumbnail:"brushes/thumb_single_sphere.png",spacing:0})},988:()=>{AFRAME.registerBrush("spheres",{init:function(e,t){this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.5,metalness:.5,side:THREE.DoubleSide,flatShading:!0}),this.geometry=new THREE.IcosahedronGeometry(1,0),this.drawingEl=document.querySelector(".a-drawing"),this.drawingEl.object3D.add(this.object3D)},addPoint:function(e,t,s,i,r){var a=new THREE.Mesh(this.geometry,this.material),n=this.data.size/2*i;return a.scale.set(n,n,n),a.initialScale=a.scale.clone(),a.phase=Math.random()*Math.PI*2,a.position.copy(s),a.quaternion.copy(t),this.object3D.add(a),!0},tick:function(e,t){for(var s=0;s{var i=s(297),r=s(51);!function(){r((function(){var e=new THREE.MeshStandardMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5,roughness:.75,metalness:.25}),t=new THREE.MeshBasicMaterial({side:THREE.DoubleSide,map:window.atlas.map,vertexColors:THREE.VertexColors,transparent:!0,alphaTest:.5});i.addSharedBuffer("tris-flat",t),i.addSharedBuffer("tris-shaded",e)}));for(var e,t,s,a,n,o,h,u,l={init:function(e,t){this.sharedBuffer=i.getSharedBuffer("tris-"+this.materialOptions.type),this.prevIdx=Object.assign({},this.sharedBuffer.idx),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.strip=!1,this.currAngle=0,this.subTextures=1,this.angleJitter=0,this.autoRotate=!1,void 0!==this.materialOptions.subTextures&&(this.subTextures=this.materialOptions.subTextures),!0===this.materialOptions.autoRotate&&(this.autoRotate=!0),void 0!==this.materialOptions.angleJitter&&(this.angleJitter=this.materialOptions.angleJitter,this.angleJitter=2*this.angleJitter-this.angleJitter)},remove:function(){this.sharedBuffer.remove(this.prevIdx,this.idx)},undo:function(){this.sharedBuffer.undo(this.prevIdx)},addPoint:(e=new THREE.Vector3,t=new THREE.Vector3,s=new THREE.Vector3,a=new THREE.Vector3,n=new THREE.Vector3,o=new THREE.Vector3,h=new THREE.Vector3,u=Math.PI/2,function(i,r,l,d,c){t.set(1,0,0),t.applyQuaternion(r),t.normalize(),e.set(0,1,0),e.applyQuaternion(r),e.normalize();var m=this.data.size*d/2,p=Math.PI/4+Math.random()*this.angleJitter;this.autoRotate&&(this.currAngle+=.1,p+=this.currAngle),s.copy(l).add(h.copy(t.applyAxisAngle(e,p)).multiplyScalar(m)),a.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),n.copy(l).add(h.copy(t.applyAxisAngle(e,u)).multiplyScalar(m)),o.copy(l).add(t.applyAxisAngle(e,u).multiplyScalar(m)),this.idx.position,this.idx.position,this.sharedBuffer.addVertex(s.x,s.y,s.z),this.sharedBuffer.addVertex(a.x,a.y,a.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(n.x,n.y,n.z),this.sharedBuffer.addVertex(o.x,o.y,o.z),this.sharedBuffer.addVertex(s.x,s.y,s.z);for(var f=0;f<6;f++)this.sharedBuffer.addNormal(e.x,e.y,e.z),this.sharedBuffer.addColor(this.data.color.r,this.data.color.g,this.data.color.b);this.data.numPoints;var g=0,b=1;if(this.subTextures>1){var v=Math.floor(Math.random()*this.subTextures);b=(g=1/this.subTextures*v)+1/this.subTextures}var y=this.materialOptions.converter;return this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(0)),this.sharedBuffer.addUV(y.convertU(b),y.convertV(1)),this.sharedBuffer.addUV(y.convertU(g),y.convertV(1)),this.idx=Object.assign({},this.sharedBuffer.idx),this.sharedBuffer.update(),!0})},d=[{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}],c=0;c{AFRAME.registerComponent("brush-tip",{schema:{controller:{type:"string"},hand:{type:"string",oneOf:["left","right"]}},init:function(){var e=e=>THREE.MathUtils.degToRad(e);this.controllers={"oculus-touch-controller-v3":{left:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(7),z:e(-7)}},right:{positionOffset:{x:0,y:-.025,z:-.042},rotationOffset:{x:e(-45),y:e(-7),z:e(7)}}}},this.data.controller&&this.setController(this.data.controller,this.data.hand)},setController:function(e,t){e in this.controllers?(this.el.object3D.position.set(this.controllers[e][t].positionOffset.x,this.controllers[e][t].positionOffset.y,this.controllers[e][t].positionOffset.z),this.el.object3D.rotation.set(this.controllers[e][t].rotationOffset.x,this.controllers[e][t].rotationOffset.y,this.controllers[e][t].rotationOffset.z)):console.error(`${e} is not present in the controllers list!`)}})},620:()=>{var e,t,s;AFRAME.registerComponent("brush",{schema:{color:{type:"color",default:"#ef2d5e"},size:{default:.01,min:.001,max:.3},brush:{default:"smooth"},enabled:{default:!0}},init:function(){var e=this.data;this.color=new THREE.Color(e.color),this.el.emit("brushcolor-changed",{color:this.color}),this.el.emit("brushsize-changed",{brushSize:e.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 t=this;this.el.addEventListener("undo",(function(e){t.data.enabled&&(t.system.undo(),document.getElementById("ui_undo").play())})),this.el.addEventListener("paint",(function(e){if(t.data.enabled){var s=e.detail.value;t.sizeModifier=s,s>.1?t.active||(t.startNewStroke(),t.active=!0):(t.active&&(t.previousEntity=t.currentEntity,t.currentStroke=null),t.active=!1)}})),this.hand="right-hand"===this.el.id?"right":"left"},update:function(e){var t=this.data;e.color!==t.color&&(this.color.set(t.color),this.el.emit("brushcolor-changed",{color:this.color})),e.size!==t.size&&this.el.emit("brushsize-changed",{size:t.size})},tick:(e=new THREE.Vector3,t=new THREE.Quaternion,s=new THREE.Vector3,function(i,r){if(this.currentStroke&&this.active){this.obj.matrixWorld.decompose(e,t,s);var a=this.system.getPointerPosition(e,t,this.hand);this.currentStroke.addPoint(e,t,a,this.sizeModifier,i)}}),startNewStroke:function(){document.getElementById("ui_paint").play(),this.currentStroke=this.system.addNewStroke(this.data.brush,this.color,this.data.size),this.el.emit("stroke-started",{entity:this.el,stroke:this.currentStroke})}})},510:()=>{AFRAME.registerComponent("json-model",{schema:{src:{type:"asset"}},init:function(){this.objectLoader=new THREE.ObjectLoader,this.objectLoader.setCrossOrigin("")},update:function(e){var t=this,s=this.data.src;s&&s!==e.src&&this.objectLoader.load(this.data.src,(function(e){var i=(new THREE.Matrix4).makeRotationX(-Math.PI/2);e.traverse((function(e){e instanceof THREE.Mesh&&e.position.applyMatrix4(i)})),t.el.setObject3D("mesh",e),t.el.emit("model-loaded",{format:"json",model:e,src:s})}))}})},788:()=>{AFRAME.registerComponent("logo-model",{schema:{opacity:{default:1}},init:function(){this.model=null,this.el.setAttribute("obj-model","obj: #logoobj; mtl: #logomtl"),this.el.addEventListener("model-loaded",this.setModel.bind(this))},setModel:function(e){this.model=e.detail.model},update:function(){null!=this.model&&(this.model.children[0].material.opacity=this.data.opacity)}})},101:()=>{AFRAME.registerSystem("paint-controls",{numberStrokes:0}),AFRAME.registerComponent("paint-controls",{dependencies:["brush"],schema:{hand:{default:"left"}},init:function(){var e=this.el,t=this,s="assets/images/controller-pressed.png",i=null;this.controller=null,this.modelLoaded=!1,this.onEnterVR=this.onEnterVR.bind(this),e.sceneEl.addEventListener("enter-vr",this.onEnterVR),e.object3D.visible=!1,this.onModelLoaded=this.onModelLoaded.bind(this),e.addEventListener("model-loaded",this.onModelLoaded),e.addEventListener("changeBrushSizeAbs",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=(s.detail.axis[1]||s.detail.axis[3])/300,r=e.components.brush.schema.size,a=THREE.Math.clamp(t.el.getAttribute("brush").size-i,r.min,r.max);t.el.setAttribute("brush","size",a)}})),e.addEventListener("changeBrushSizeInc",(function(s){if(0!==s.detail.axis[1]||0!==s.detail.axis[3]){var i=s.detail.axis[1]||s.detail.axis[3];t.touchStarted&&(t.touchStarted=!1,t.startAxis=(i+1)/2);var r=(i+1)/2,a=(t.startAxis-r)/2;t.startAxis=r;var n=t.el.getAttribute("brush").size,o=e.components.brush.schema.size,h=THREE.Math.clamp(n-a,o.min,o.max);t.el.setAttribute("brush","size",h)}})),t.touchStarted=!1,e.addEventListener("startChangeBrushSize",(function(){t.touchStarted=!0})),e.addEventListener("controllerconnected",(function(s){var r=s.detail.name,a=s.detail.component.data.hand;const n=(s,i)=>{this.brushTip=document.createElement("a-entity"),this.brushTip.id=`${i}-tip`,this.brushTip.setAttribute("gltf-model","#tipObj"),this.brushTip.setAttribute("brush-tip",`controller: ${s}; hand: ${i}`),this.brushTip.addEventListener("model-loaded",t.onModelLoaded),e.appendChild(this.brushTip)};if("windows-motion-controls"===r){var o=s.detail.component.el.components["gltf-model"].data;const e="045E-065D";o&&o.indexOf(e)>=0&&(r="windows-motion-samsung-controls")}if(i=Utils.getTooltips(r),r.indexOf("windows-motion")>=0);else if("oculus-touch-controls"===r){const t=e.components[r].displayModel[a].modelUrl;n(/[^\/]*(?=-(?:left|right)\.)/.exec(t)[0],a)}else{if("vive-controls"!==r)return;e.setAttribute("gltf-model","url(assets/models/vive-controller.glb)")}i&&i.forEach((function(e){e.setAttribute("visible",!0);Array.prototype.slice.call(e.querySelectorAll("[tooltip]")).forEach((function(e){e.setAttribute("animation",{dur:1e3,delay:2e3,property:"tooltip.opacity",from:1,to:0,startEvents:"tooltip-fade"})}))})),this.controller=r})),e.addEventListener("brushsize-changed",(function(e){t.changeBrushSize(e.detail.size)})),e.addEventListener("brushcolor-changed",(function(e){t.changeBrushColor(e.detail.color)})),e.sceneEl.systems.material.loadTexture(s,{src:s},(function(e){var s=t.highLightMaterial=new THREE.MeshBasicMaterial;s.map=e,s.needsUpdate=!0})),this.startAxis=0,this.numberStrokes=0,document.addEventListener("stroke-started",(function(e){if(e.detail.entity.components["paint-controls"]===t&&(t.numberStrokes++,t.system.numberStrokes++,3===t.system.numberStrokes)){Array.prototype.slice.call(document.querySelectorAll("[tooltip]")).forEach((function(e){e.emit("tooltip-fade")}))}}))},changeBrushColor:function(e){this.modelLoaded&&this.buttonMeshes.sizeHint&&(this.buttonMeshes.colorTip.material.color.copy(e),this.buttonMeshes.sizeHint.material.color.copy(e))},changeBrushSize:function(e){var t=e/2*10;this.modelLoaded&&this.buttonMeshes.sizeHint&&this.buttonMeshes.sizeHint.scale.set(t,1,t)},mapping:{axis0:"trackpad",axis1:"trackpad",button0:"trackpad",button1:"trigger",button2:"grip",button3:"menu",button4:"system"},update:function(){var e=this.data,t=this.el;t.setAttribute("vive-controls",{hand:e.hand,model:!1}),t.setAttribute("oculus-touch-controls",{hand:e.hand,model:!0}),t.setAttribute("windows-motion-controls",{hand:e.hand})},play:function(){},pause:function(){},onEnterVR:function(){this.el.object3D.visible=!0},onModelLoaded:function(e){if((e.target===this.el||e.target.id.includes("-tip"))&&!this.buttonMeshes){var t,s=e.detail.model;(t=this.buttonMeshes={}).sizeHint=s.getObjectByName("sizehint"),t.colorTip=s.getObjectByName("tip"),this.modelLoaded=!0,this.changeBrushSize(this.el.components.brush.data.size),this.changeBrushColor(this.el.components.brush.color)}},onButtonEvent:function(e,t){var s=this.mapping["button"+e];this.el.emit(s+t),this.updateModel(s,t)},updateModel:function(e,t){var s="up"===t?this.material:this.highLightMaterial,i=this.buttonMeshes,r=i&&i[e];if("down"===t&&r&&!this.material&&(s=this.material=r.material),s)return"grip"===e?(i.grip.left.material=s,void(i.grip.right.material=s)):void(r&&(r.material=s))}})},579:()=>{var e,t,s;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 e=this.data,t=this.raycaster;t.far=e.far,t.near=e.near,this.refreshObjects()},refreshObjects:function(){var e,t,s=this.data;if(s.objects)for(t=this.el.sceneEl.querySelectorAll(s.objects),this.objects=[],e=0;e{var e,t,s,i,r,a;AFRAME.registerComponent("ui",{schema:{brightness:{default:1,max:1,min:0},opacity:{default:0}},dependencies:["ui-raycaster"],init:function(){var e=this.el,t=this.uiEl=document.createElement("a-entity"),s=this.rayEl=document.createElement("a-entity");this.closed=!0,this.isTooltipPaused=!1,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),t.setAttribute("material",{color:"#ffffff",flatShading:!0,shader:"flat",transparent:!0,fog:!1,src:"#uinormal"}),t.setAttribute("obj-model","obj:#uiobj"),t.setAttribute("position","0 0.04 -0.15"),t.setAttribute("scale","0 0 0"),t.setAttribute("visible",!1),t.classList.add("apainter-ui"),e.appendChild(t),s.setAttribute("line",""),e.appendChild(s),e.setAttribute("ui-raycaster",{far:this.rayDistance,objects:".apainter-ui",rotation:-this.rayAngle}),this.controller=null;var i=this;e.addEventListener("controllerconnected",(function(s){var r=s.detail.name;i.tooltips=Utils.getTooltips(r),i.controller={name:r,hand:s.detail.component.data.hand},"oculus-touch-controls"===r?(i.uiEl.setAttribute("rotation","45 0 0"),t.setAttribute("position","0 0.13 -0.08"),i.rayAngle=0,e.setAttribute("ui-raycaster",{rotation:0})):"windows-motion-controls"===r&&(i.rayAngle=25,i.rayDistance=1,e.setAttribute("ui-raycaster",{rotation:-30,far:i.rayDistance})),i.el.isPlaying&&i.addToggleEvent()}))},initColorWheel:function(){var e=this.objects.hueWheel,t=new THREE.ShaderMaterial({uniforms:{brightness:{type:"f",value:this.hsv.v}},vertexShader:" varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); gl_Position = projectionMatrix * mvPosition; } ",fragmentShader:" #define M_PI2 6.28318530718\n uniform float brightness; varying vec2 vUv; vec3 hsb2rgb(in vec3 c){ vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0 ); rgb = rgb * rgb * (3.0 - 2.0 * rgb); return c.z * mix( vec3(1.0), rgb, c.y); } void main() { vec2 toCenter = vec2(0.5) - vUv; float angle = atan(toCenter.y, toCenter.x); float radius = length(toCenter) * 2.0; vec3 color = hsb2rgb(vec3((angle / M_PI2) + 0.5, radius, brightness)); gl_FragColor = vec4(color, 1.0); } "});e.material=t},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),this.open=this.open.bind(this),this.close=this.close.bind(this)},tick:function(){!this.closed&&this.handEl&&(this.updateIntersections(),this.handleHover(),this.handlePressedButtons())},update:function(){this.messagesMaterial&&(this.messagesMaterial.opacity=this.data.opacity)},onTriggerChanged:function(e){var t=e.detail.value;this.lastTriggerValue=t,e.detail.value>=.25?this.triggeredPressed=!0:(this.triggeredPressed=!1,this.handleButtonUp())},handleButtonDown:function(e,t){var s=e.name;if(!this.activeWidget||this.activeWidget===s){switch(this.activeWidget=s,!0){case"brightness"===s:this.onBrightnessDown(t);break;case"brushnext"===s:this.pressedObjects[s]||this.nextPage();break;case"brushprev"===s:this.pressedObjects[s]||this.previousPage();break;case"clear"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.brush.clear(),this.playSound("ui_click1"));break;case"copy"===s:this.pressedObjects[s]||(this.copyBrush(),this.playSound("ui_click1"));break;case"hue"===s:this.onHueDown(t);break;case"save"===s:this.pressedObjects[s]||(this.el.sceneEl.systems.painter.upload(),this.playSound("ui_click1"));break;case"sizebg"===s:this.onBrushSizeBackgroundDown(t);break;case this.brushRegexp.test(s):this.onBrushDown(s);break;case this.colorHistoryRegexp.test(s):this.onColorHistoryButtonDown(e);break;default:this.activeWidget=void 0}this.pressedObjects[s]=e}},copyBrush:function(){var e=this.el.getAttribute("brush");this.handEl.setAttribute("brush","brush",e.brush),this.handEl.setAttribute("brush","color",e.color),this.handEl.setAttribute("brush","size",e.size),this.colorHasChanged=!0},handleButtonUp:function(){var e=this.pressedObjects,t=this.unpressedObjects;this.activeWidget=void 0,Object.keys(e).forEach((function(s){var i=e[s].name;t[i]=e[i],delete e[i]}))},handlePressedButtons:function(){var e=this;this.triggeredPressed&&this.hoveredOnObjects.forEach((function(t){e.handleButtonDown(t.object,t.point)}))},onColorHistoryButtonDown:function(e){var t=e.material.color.getHexString();this.handEl.setAttribute("brush","color","#"+t),this.playSound("ui_click0",e.name)},onBrushDown:function(e){var t=this.brushButtonsMapping[e];t&&(this.selectBrushButton(e),this.handEl.setAttribute("brush","brush",t.toLowerCase()))},selectBrushButton:function(e){var t=this.uiEl.getObject3D("mesh").getObjectByName(e+"bg"),s=this.selectedObjects,i=this.selectedBrush;i&&(this.highlightMaterials[i.name]||this.initHighlightMaterial(t),i.material=this.highlightMaterials[i.name].normal,delete s[i.name]),s[t.name]=t,this.selectedBrush=t,this.playSound("ui_click1",e)},onHueDown:function(e){var t,s=this.objects.hueWheel,i=this.colorWheelSize;s.updateMatrixWorld(),s.worldToLocal(e),this.objects.hueCursor.position.copy(e);var r=((t={r:Math.sqrt(e.x*e.x+e.z*e.z),theta:Math.PI+Math.atan2(-e.z,e.x)}).theta*(180/Math.PI)+180)%360;this.hsv.h=r/360,this.hsv.s=t.r/i,this.updateColor(),this.playSound("ui_click0","hue")},updateColor:function(){var e=this.hsv2rgb(this.hsv),t="rgb("+e.r+", "+e.g+", "+e.b+")";this.handEl.setAttribute("brush","color",t),this.colorHasChanged=!0},hsv2rgb:function(e){var t,s,i,r,a,n,o,h,u=THREE.Math.clamp(e.h,0,1),l=THREE.Math.clamp(e.s,0,1),d=e.v;switch(n=d*(1-l),o=d*(1-(a=6*u-(r=Math.floor(6*u)))*l),h=d*(1-(1-a)*l),r%6){case 0:t=d,s=h,i=n;break;case 1:t=o,s=d,i=n;break;case 2:t=n,s=d,i=h;break;case 3:t=n,s=o,i=d;break;case 4:t=h,s=n,i=d;break;case 5:t=d,s=n,i=o}return{r:Math.round(255*t),g:Math.round(255*s),b:Math.round(255*i)}},rgb2hsv:function(e,t,s){var i,r=Math.max(e,t,s),a=Math.min(e,t,s),n=r-a,o=0===r?0:n/r,h=r;switch(1===arguments.length&&(t=e.g,s=e.b,e=e.r),r){case a:i=0;break;case e:i=t-s+n*(t=this.brushesPagesNum))for(this.objects.previousPage.visible=0!==e,e===this.brushesPagesNum-1?this.objects.nextPage.visible=!1:this.objects.nextPage.visible=!0,i=0;i=this.brushesPagesNum-1||(this.brushesPage++,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},previousPage:function(){0!==this.brushesPage&&(this.brushesPage--,this.loadBrushes(this.brushesPage,this.brushesPerPage),this.playSound("ui_click1"))},initHighlightMaterial:function(e){var t=e.name,s=this.brushRegexp.test(t),i=-1!==t.indexOf("history"),r="hue"===t||"huecursor"===t,a={normal:e.material,hover:e.material,pressed:e.material,selected:e.material};s||i||r||(a.normal=e.material,a.hover=e.material.clone(),a.hover.map=this.system.hoverTexture,a.selected=e.material.clone(),a.selected.map=this.system.pressedTexture,a.pressed=e.material.clone(),a.pressed.map=this.system.pressedTexture),this.highlightMaterials[t]=a},toggleMenu:function(e){this.closed?(this.system.closeAll(),this.open(),this.system.opened=this.el):(this.close(),this.system.opened=void 0)},open:function(){var e=this.uiEl;if(this.closed){if(this.uiEl.setAttribute("visible",!0),this.uiEl.setAttribute("animation",{dur:100,easing:"easeOutExpo",property:"scale",from:{x:0,y:0,z:0},to:{x:1,y:1,z:1}}),this.el.setAttribute("brush","enabled",!1),this.rayEl.setAttribute("visible",!1),this.closed=!1,this.tooltips){var t=this;this.tooltips.forEach((function(s){s.getAttribute("visible")&&e.parentEl.id!==s.parentEl.id&&(t.isTooltipPaused=!0,s.setAttribute("visible",!1))}))}this.playSound("ui_menu")}},updateIntersections:function(){var e=this.raycaster=new THREE.Raycaster;return function(t){this.updateRaycaster(e),this.intersectedObjects=e.intersectObjects(this.menuEls,!0)}}(),onIntersection:function(e){var t=this.closed&&this.system.opened;this.el.components.brush.active||(this.rayEl.setAttribute("visible",!!t),this.el.setAttribute("brush","enabled",!1))},onIntersected:function(e){var t=e.detail.el;this.handEl&&this.removeHandListeners(),this.handEl=t,this.handRayEl=this.handEl.components.ui.rayEl,this.menuEls=this.uiEl.object3D.children,this.syncUI(),this.addHandListeners()},addHandListeners:function(){var e=this.handEl;e.addEventListener("componentchanged",this.onComponentChanged),e.addEventListener("stroke-started",this.onStrokeStarted),e.addEventListener("triggerchanged",this.onTriggerChanged)},removeHandListeners:function(){var e=this.handEl;e.removeEventListener("componentchanged",this.onComponentChanged),e.removeEventListener("stroke-started",this.onStrokeStarted),e.removeEventListener("triggerchanged",this.onTriggerChanged)},onComponentChanged:function(e){"brush"===e.detail.name&&this.syncUI()},syncUI:function(){var e;this.handEl&&this.objects&&(e=this.handEl.getAttribute("brush"),this.updateSizeSlider(e.size),this.updateColorUI(e.color),this.updateColorHistory())},initColorHistory:function(){for(var e,t=this.objects.currentColor,s=0;s{window.addEventListener("load",(function(e){var t=document.body;t.addEventListener("dragover",(function(e){e.stopPropagation(),e.preventDefault(),e.dataTransfer.dropEffect="copy"}),!1),t.addEventListener("drop",(function(e){e.stopPropagation(),e.preventDefault();for(var t=e.dataTransfer.files,s=0;s{e.color.set("#333")})):r.material.color.set("#333")}s.setObject3D("mesh",t),s.className="templateitem",document.querySelector("a-scene").appendChild(s)},r.readAsText(i)):i.type.match(/image.*/)&&((r=new FileReader).onload=function(e){var t=new Image;t.src=e.target.result,t.onload=()=>{var s,i;t.width>t.height?(s=1,i=t.height/t.width):(i=1,s=t.width/t.height);var r=[3*Math.random()-1.5,1+Math.random()-.5,.2*Math.random()-1.4],a=document.createElement("a-image");a.setAttribute("src",e.target.result),a.setAttribute("position",r.join(" ")),a.setAttribute("width",s),a.setAttribute("height",i),a.className="templateitem",document.querySelector("a-scene").appendChild(a)}},r.readAsDataURL(i))}}),!1)}))},51:e=>{e.exports=function(e){function t(){var t=document.querySelector("a-scene");t.hasLoaded?e():t.addEventListener("loaded",e())}"complete"===document.readyState||"loaded"===document.readyState?t():document.addEventListener("DOMContentLoaded",t)}},115:e=>{function t(e){this.material=e,this.maxBufferSize=1e6,this.geometries=[],this.current=null,this.strip=!0,this.addBuffer(!1)}t.prototype={restartPrimitive:function(){if(this.idx.position>=this.current.attributes.position.count)this.addBuffer(!1);else if(0!==this.idx.position){var e=3*(this.idx.position-1),t=this.current.attributes.position.array;this.addVertex(t[e++],t[e++],t[e++]),this.idx.color++,this.idx.normal++,this.idx.uv++}},remove:function(e,t){var s=this.current.attributes.position.array;if(this.idx.position>t.position)for(key in this.idx)for(var i="uv"===key?2:3,r=(s=e[key]*i,(t[key]+1)*i),a=this.idx[key]*i,n=r;n0&&(this.previous=this.current),this.idx={position:0,uv:0,normal:0,color:0},this.geometries.push(t),this.current=t,this.previous&&e){var u=3*(this.maxBufferSize-2),l=3*(this.maxBufferSize-2),d=(this.maxBufferSize,3*(this.maxBufferSize-2)),c=this.previous.attributes.position.array;this.addVertex(c[u++],c[u++],c[u++]),this.addVertex(c[u++],c[u++],c[u++]);var m=this.previous.attributes.normal.array;this.addNormal(m[d++],m[d++],m[d++]),this.addNormal(m[d++],m[d++],m[d++]);var p=this.previous.attributes.color.array;this.addColor(p[l++],p[l++],p[l++]),this.addColor(p[l++],p[l++],p[l++]);a=this.previous.attributes.uv.array}},addColor:function(e,t,s){this.current.attributes.color.setXYZ(this.idx.color++,e,t,s)},addNormal:function(e,t,s){this.current.attributes.normal.setXYZ(this.idx.normal++,e,t,s)},addVertex:function(e,t,s){var i=this.current.attributes.position;this.idx.position===i.count&&(this.addBuffer(!0),i=this.current.attributes.position),i.setXYZ(this.idx.position++,e,t,s),this.strip?(this.idx.position+1)%2==0&&this.idx.position>1&&(this.current.index.setXYZ(this.idx.position-3,this.idx.position-3,this.idx.position-2,this.idx.position-1),this.current.index.setXYZ(this.idx.position-2,this.idx.position-1,this.idx.position-2,this.idx.position)):(this.idx.position+1)%3==0&&this.current.index.setXYZ(this.idx.position,this.idx.position-2,this.idx.position-1,this.idx.position)},addUV:function(e,t){this.current.attributes.uv.setXY(this.idx.uv++,e,t)},update:function(){this.current.setDrawRange(0,3*this.idx.position-4),this.current.attributes.color.updateRange.count=3*this.idx.position,this.current.attributes.color.needsUpdate=!0,this.current.attributes.normal.updateRange.count=3*this.idx.position,this.current.attributes.normal.needsUpdate=!0,this.current.attributes.position.updateRange.count=3*this.idx.position,this.current.attributes.position.needsUpdate=!0,this.current.attributes.uv.updateRange.count=2*this.idx.position,this.current.attributes.uv.needsUpdate=!0,this.current.index.updateRange.count=3*this.idx.position,this.current.index.needsUpdate=!0}},e.exports=t},297:(e,t,s)=>{var i=s(115);function r(){this.sharedBuffers={}}r.prototype={addSharedBuffer:function(e,t){var s=new i(t);this.sharedBuffers[e]=s},getSharedBuffer:function(e){return this.sharedBuffers[e]}},e.exports=new r},796:()=>{var e,t;AFRAME.BRUSHES={},APAINTER_STATS={brushes:{}},AFRAME.registerBrush=function(e,t,s){var i={};if(Object.keys(t).forEach((function(e){i[e]={value:t[e],writable:!0}})),AFRAME.BRUSHES[e])throw new Error("The brush `"+e+"` 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 r=function(){};r.prototype={options:Object.assign({spacing:0,maxPoints:0},s),reset:function(){},tick:function(e,t){},undo:function(){},remove:function(){},addPoint:function(e,t,s,i,r){},getJSON:function(e){for(var t=[],s=0;s=this.options.maxPoints||n.call(this,e,t,s,i,r)&&(this.data.numPoints++,this.data.points.push({position:e.clone(),orientation:t.clone(),pressure:i,timestamp:r}),this.data.prevPosition=e.clone(),this.data.prevPointerPosition=s.clone())}),AFRAME.BRUSHES[e]=o,o.used=!1,o},AFRAME.registerSystem("brush",{schema:{},brushes:{},strokes:[],getUsedBrushes:function(){return Object.keys(AFRAME.BRUSHES).filter((function(e){return AFRAME.BRUSHES[e].used}))},getBrushByName:function(e){return AFRAME.BRUSHES[e]},undo:function(){for(var e,t=this.strokes.length-1;t>=0;t--)if("local"===this.strokes[t].data.owner){e=this.strokes.splice(t,1)[0];break}e&&(e.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:e}))},removeById:function(e){var t=this.strokes[1];if(console.log(t,this.strokes),t){for(var s=this.strokes.length-1;s>1;s--)if(stroke=this.strokes[s],t.sharedBuffer===stroke.sharedBuffer){for(key in console.log(">>>",stroke.prevIdx,"->",stroke.idx,"target",t.prevIdx,"->",t.idx),t.idx){var i=t.idx[key]-t.prevIdx[key];stroke.idx[key]-=i,stroke.prevIdx[key]-=i}console.log("<<<",stroke.idx,stroke.prevIdx)}this.strokes.splice(1,1)[0].remove()}},clear:function(){for(var e=this.strokes.length-1;e>=0;e--)if("local"===this.strokes[e].data.owner){var t=this.strokes[e];t.undo(),document.querySelector(".a-drawing").emit("stroke-removed",{stroke:t})}Object.keys(AFRAME.BRUSHES).forEach((function(e){AFRAME.BRUSHES[e].used=!1})),this.strokes=[]},init:function(){this.version=1,this.clear(),this.controllerName=null;var e=this;this.sceneEl.addEventListener("controllerconnected",(function(t){e.controllerName=t.detail.name}))},tick:function(e,t){if(this.strokes.length)for(var s=0;s1&&(m=1);var f=this.getPointerPosition(l,c);u.addPoint(l,c,f,m,0)}}},addNewStroke:function(e,t,s,i,r){APAINTER_STATS.brushes[e]||(APAINTER_STATS.brushes[e]=0),APAINTER_STATS.brushes[e]++,i=i||"local",r=r||Date.now();var a=this.getBrushByName(e);if(!a){var n=Object.keys(AFRAME.BRUSHES)[0];a=AFRAME.BRUSHES[n],console.warn("Invalid brush name: `"+e+"` using `"+n+"`")}a.used=!0;var o=new a;o.brush=a,o.init(t,s,i,r),this.strokes.push(o);var h=document.querySelector(".a-drawing");return h||((h=document.createElement("a-entity")).className="a-drawing",document.querySelector("a-scene").appendChild(h)),o},getJSON:function(){var e={version:1,strokes:[],author:"",brushes:this.getUsedBrushes()};for(i=0;i{var i=s(618).saveAs;AFRAME.registerSystem("painter",{init:function(){var e={behaviours:{},mappings:{painting:{common:{"grip.changed":"paint","trigger.down":"undo"},"vive-controls":{axismove:"changeBrushSizeInc","trackpad.touchstart":"startChangeBrushSize","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"},"oculus-touch-controls":{axismove:"changeBrushSizeAbs","abutton.down":"toggleMenu","xbutton.down":"toggleMenu","ybutton.down":"aim","ybutton.up":"teleport","bbutton.down":"aim","bbutton.up":"teleport"},"windows-motion-controls":{axismove:"changeBrushSizeAbs","menu.down":"toggleMenu","trackpad.down":"aim","trackpad.up":"teleport"}}}};this.sceneEl.addEventListener("loaded",(function(){AFRAME.registerInputMappings(e),AFRAME.currentInputMapping="painting"})),this.version="1.2",this.brushSystem=this.sceneEl.systems.brush,this.showTemplateItems=!0;var t=function(){var e,t=/\+/g,s=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(t," "))},r=window.location.search.substring(1),a={};for(e=s.exec(r);e;)a[i(e[1])]=i(e[2]),e=s.exec(r);return a}();if(t.url||t.urljson){var s=void 0===t.urljson;this.brushSystem.loadFromUrl(t.url||t.urljson,s),document.getElementById("logo").setAttribute("visible",!1),document.getElementById("acamera").setAttribute("orbit-controls","initialPosition: 0 1.6 3"),document.getElementById("apainter-logo").classList.remove("hidden")}else{document.getElementById("acamera").setAttribute("position","0 1.6 0")}void 0!==t.bgcolor&&(document.body.style.backgroundColor="#"+t.bgcolor),void 0!==t.sky&&this.sceneEl.addEventListener("loaded",(function(e){""===t.sky?document.getElementById("sky").setAttribute("visible",!1):document.getElementById("sky").setAttribute("material","src",t.sky)})),void 0!==t.floor&&this.sceneEl.addEventListener("loaded",(function(e){""===t.floor?document.getElementById("ground").setAttribute("visible",!1):document.getElementById("ground").setAttribute("material","src",t.floor)})),this.paintingStarted=!1;var i=this;document.addEventListener("stroke-started",(function(e){if(!i.paintingStarted){document.getElementById("logo").emit("painting-started"),i.paintingStarted=!0}})),document.addEventListener("keyup",(function(e){if(!e.shiftKey&&!e.ctrlKey){if(8===e.keyCode&&i.brushSystem.undo(),67===e.keyCode&&i.brushSystem.clear(),71===e.keyCode){var t=document.querySelector(".a-drawing");i.sceneEl.systems["gltf-exporter"].export(t)}if(78===e.keyCode){var s=document.querySelectorAll("[paint-controls]"),r=Object.keys(AFRAME.BRUSHES),a=r.indexOf(s[0].components.brush.data.brush);a=(a+1)%r.length,[].forEach.call(s,(function(e){e.setAttribute("brush","brush",r[a])}))}if(84===e.keyCode&&i.brushSystem.generateTestLines(),82===e.keyCode&&i.brushSystem.generateRandomStrokes(1),76===e.keyCode&&i.brushSystem.loadFromUrl("demo.apa",!0),85===e.keyCode&&i.upload(),86===e.keyCode&&i.save(),74===e.keyCode&&i.saveJSON(),79===e.keyCode){i.showTemplateItems=!i.showTemplateItems;for(var n=document.querySelectorAll(".templateitem"),o=0;o{if(!e.ok)throw new Error(`Network request failed with status ${e.status}: ${e.statusText}`);return e.json()})).then((s=>{console.log("Uploaded link: ",t+s.secure_url),e.sceneEl.emit("drawing-upload-completed",{url:t+s.secure_url})})).catch((t=>{console.error(t),e.sceneEl.emit("drawing-upload-error",{errorInfo:t})}))}})},493:()=>{AFRAME.registerSystem("ui",{init:function(){this.initTextures()},initTextures:function(){var e=this,t="assets/images/ui-hover.png",s="assets/images/ui-pressed.png";this.sceneEl.systems.material.loadTexture(t,{src:t},(function(t){e.hoverTexture=t})),this.sceneEl.systems.material.loadTexture(s,{src:s},(function(t){e.pressedTexture=t}))},closeAll:function(){var e,t=document.querySelectorAll("[ui]");for(e=0;e{window.addEventListener("load",(function(e){var t=document.getElementById("apainter-ui"),s=document.querySelector("#apainter-ui .share"),i=document.getElementById("apainter-share-url"),r=document.querySelector("#apainter-ui .progress"),a=document.querySelector("#apainter-ui .bar");document.addEventListener("drawing-upload-completed",(function(e){s.classList.remove("hide"),r.classList.add("hide"),i.value=e.detail.url})),document.addEventListener("drawing-upload-started",(function(e){t.style.display="block",s.classList.add("hide"),r.classList.remove("hide")})),document.addEventListener("drawing-upload-progress",(function(e){a.style.width=Math.floor(100*e.detail.progress)+"%"})),new Clipboard(".button.copy").on("error",(function(e){console.error("Error copying to clipboard:",e.action,e.trigger)}))}))},555:()=>{window.Utils=function(){function e(e){return parseFloat(e.toFixed(6))}return{numberToFixed:e,arrayNumbersToFixed:function(t){for(var s=0;s{"use strict";e.exports=JSON.parse('{"meta":{"image":"brush_atlas.png","size":{"w":3584,"h":2944},"scale":"1"},"frames":{"stamp_grass.png":{"frame":{"x":0,"y":128,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"lines4.png":{"frame":{"x":0,"y":0,"w":2048,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":2048,"h":128},"sourceSize":{"w":2048,"h":128}},"stamp_fur2.png":{"frame":{"x":0,"y":640,"w":1536,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1536,"h":512},"sourceSize":{"w":1536,"h":512}},"stamp_bush.png":{"frame":{"x":0,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_gear.png":{"frame":{"x":1024,"y":1152,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"stamp_fur1.png":{"frame":{"x":2048,"y":0,"w":1024,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":512},"sourceSize":{"w":1024,"h":512}},"lines3.png":{"frame":{"x":2048,"y":512,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_gradient.png":{"frame":{"x":2048,"y":768,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines5.png":{"frame":{"x":2048,"y":1024,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_flat.png":{"frame":{"x":2048,"y":1280,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"silky_textured.png":{"frame":{"x":0,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"squared_textured.png":{"frame":{"x":1024,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge2.png":{"frame":{"x":2048,"y":1664,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge3.png":{"frame":{"x":0,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"line_grunge1.png":{"frame":{"x":1024,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"lines2.png":{"frame":{"x":2048,"y":1920,"w":1024,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":1024,"h":256},"sourceSize":{"w":1024,"h":256}},"stamp_leaf3.png":{"frame":{"x":1536,"y":128,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_dots.png":{"frame":{"x":1536,"y":640,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"thumb_stamp_star.png":{"frame":{"x":2304,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_grunge1.png":{"frame":{"x":512,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge2.png":{"frame":{"x":1024,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge3.png":{"frame":{"x":1536,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge4.png":{"frame":{"x":2048,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_grunge5.png":{"frame":{"x":2560,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf1.png":{"frame":{"x":3072,"y":0,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_leaf2.png":{"frame":{"x":3072,"y":512,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_column.png":{"frame":{"x":3072,"y":1024,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_snow.png":{"frame":{"x":3072,"y":1536,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"stamp_squares.png":{"frame":{"x":3072,"y":2048,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}},"lines1.png":{"frame":{"x":0,"y":2688,"w":256,"h":256},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":256,"h":256},"sourceSize":{"w":256,"h":256}},"thumb_rainbow.png":{"frame":{"x":3072,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_single_sphere.png":{"frame":{"x":3200,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur1.png":{"frame":{"x":3328,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_fur2.png":{"frame":{"x":3456,"y":2560,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_grass.png":{"frame":{"x":2048,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"thumb_stamp_snow.png":{"frame":{"x":2176,"y":1536,"w":128,"h":128},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":128,"h":128},"sourceSize":{"w":128,"h":128}},"stamp_star.png":{"frame":{"x":0,"y":2176,"w":512,"h":512},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":512,"h":512},"sourceSize":{"w":512,"h":512}}}}')}},t={};function s(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,s),a.exports}s.amdD=function(){throw new Error("define cannot be used indirect")},s.amdO={},window.saveAs=s(618).saveAs,s(453),s(821),s(967),s(297),s(115),s(555),s(369),s(796),s(493),s(810),s(620),s(142),s(510),s(101),s(688),s(579),s(788),s(295),s(623),s(988),s(830),s(775),s(891)})(); \ No newline at end of file diff --git a/src/systems/painter.js b/src/systems/painter.js index dbf2ffc6..f1abfed3 100644 --- a/src/systems/painter.js +++ b/src/systems/painter.js @@ -9,8 +9,8 @@ AFRAME.registerSystem('painter', { mappings: { painting: { common: { - 'grip.down': 'paint', - 'trigger.changed': 'undo' + 'grip.changed': 'paint', + 'trigger.down': 'undo' }, 'vive-controls': { From f50941fdb63db9f42f387847fdc1ba1aea38d710 Mon Sep 17 00:00:00 2001 From: Pawel Golinski Date: Tue, 6 Sep 2022 16:56:08 +0200 Subject: [PATCH 3/3] hand painting --- index.html | 10 +++++--- src/components/brush.js | 43 +++++++++++++++++++++++++++++++- src/components/paint-controls.js | 2 ++ src/systems/brush.js | 9 ++++++- src/systems/painter.js | 5 ++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 94e722c6..567bdde0 100644 --- a/index.html +++ b/index.html @@ -53,7 +53,7 @@ - - - --> + + + diff --git a/src/components/brush.js b/src/components/brush.js index 6fd08aea..f3232867 100644 --- a/src/components/brush.js +++ b/src/components/brush.js @@ -26,6 +26,8 @@ AFRAME.registerComponent('brush', { this.model = this.el.getObject3D('mesh'); this.drawing = false; + this.self = this; + var self = this; this.el.addEventListener('undo', function(evt) { @@ -34,6 +36,34 @@ AFRAME.registerComponent('brush', { document.getElementById('ui_undo').play(); }); + console.log('system is'); + console.log(this.system); + console.log('el is'); + console.log(this); + console.log('obj is'); + console.log(this.obj); + + this.el.addEventListener('paint-hand-start', function (evt) { + // console.log(self.el.components['hand-tracking-controls'].indexTipPosition); + // console.log(this.components['hand-tracking-controls'].indexTipPosition); + if (!self.active) { + console.log('starting stroke'); + self.startNewStroke(); + self.active = true; + } + this.hand = 'right'; + }); + + this.el.addEventListener('paint-hand-end', function (evt) { + if (self.active) { + self.previousEntity = self.currentEntity; + self.currentStroke = null; + } + self.active = false; + this.hand = 'right'; + console.log('ending stroke'); + }); + this.el.addEventListener('paint', function (evt) { if (!self.data.enabled) { return; } // Trigger @@ -72,9 +102,20 @@ AFRAME.registerComponent('brush', { return function tick (time, delta) { if (this.currentStroke && this.active) { + // console.log('wutbegin'); + // console.log(this); + // console.log(this.el.components['hand-tracking-controls'].indexTipPosition); + // console.log('wutend'); + + const lol = this.el.components['hand-tracking-controls'].indexTipPosition.clone(); + console.log(lol); this.obj.matrixWorld.decompose(position, rotation, scale); + console.log(lol); + position = lol; + var pointerPosition = this.system.getPointerPosition(position, rotation, this.hand); - this.currentStroke.addPoint(position, rotation, pointerPosition, this.sizeModifier, time); + //console.log(pointerPosition); + this.currentStroke.addPoint(position, rotation, pointerPosition, 3.0, time); } }; })(), diff --git a/src/components/paint-controls.js b/src/components/paint-controls.js index d4fca1f1..91c4851b 100644 --- a/src/components/paint-controls.js +++ b/src/components/paint-controls.js @@ -65,6 +65,8 @@ AFRAME.registerComponent('paint-controls', { }); el.addEventListener('controllerconnected', function (evt) { + console.log(evt); + var controllerName = evt.detail.name; var hand = evt.detail.component.data.hand; diff --git a/src/systems/brush.js b/src/systems/brush.js index a1373437..b1d21cc5 100644 --- a/src/systems/brush.js +++ b/src/systems/brush.js @@ -411,7 +411,14 @@ AFRAME.registerSystem('brush', { right: new THREE.Vector3(0, 0, 1), }, mult: -.12 - } + }, + 'hand-tracking-controls': { + vec: { + left: new THREE.Vector3(-2, 0, 2.8), + right: new THREE.Vector3(2, 0, 2.8) + }, + mult: -0.025 + }, }; return function getPointerPosition (position, orientation, hand) { diff --git a/src/systems/painter.js b/src/systems/painter.js index f1abfed3..04d0a36b 100644 --- a/src/systems/painter.js +++ b/src/systems/painter.js @@ -13,6 +13,11 @@ AFRAME.registerSystem('painter', { 'trigger.down': 'undo' }, + 'hand-tracking-controls': { + 'pinchmoved': 'paint-hand-start', + 'pinchended': 'paint-hand-end', + }, + 'vive-controls': { 'axismove': 'changeBrushSizeInc', 'trackpad.touchstart': 'startChangeBrushSize',