mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 12:22:03 +08:00
136 lines
54 KiB
JavaScript
136 lines
54 KiB
JavaScript
import{toRef as Le,watch as d,ref as Zr,defineComponent as a,watchEffect as Yr,inject as K,provide as Jr,getCurrentInstance as Qr,onUnmounted as es,createApp as ts}from"vue";import{Vector3 as ie,Raycaster as rs,Plane as ss,Vector2 as T,InstancedMesh as ye,WebGLRenderer as is,OrthographicCamera as ns,PerspectiveCamera as os,Scene as as,Color as Y,Texture as hs,Group as ds,WebGLCubeRenderTarget as us,RGBAFormat as cs,LinearMipmapLinearFilter as ls,CubeCamera as ms,Mesh as ps,BufferGeometry as fs,BufferAttribute as ys,BoxGeometry as Oe,CircleGeometry as gs,ConeGeometry as bs,CylinderGeometry as vs,DodecahedronGeometry as Ss,ExtrudeGeometry as Ps,IcosahedronGeometry as xs,LatheGeometry as ws,OctahedronGeometry as Cs,PlaneGeometry as Ne,PolyhedronGeometry as Ms,RingGeometry as Gs,SphereGeometry as Ls,ShapeGeometry as Os,TetrahedronGeometry as Ns,TorusGeometry as $s,TorusKnotGeometry as Es,CatmullRomCurve3 as $e,Curve as zs,TubeGeometry as Rs,SpotLight as ge,DirectionalLight as be,AmbientLight as js,HemisphereLight as ks,PointLight as Is,RectAreaLight as _s,MeshBasicMaterial as Ee,MeshLambertMaterial as Ts,MeshPhongMaterial as As,MeshPhysicalMaterial as Bs,PointsMaterial as Ds,ShadowMaterial as Fs,MeshStandardMaterial as Us,MeshToonMaterial as Hs,TextureLoader as J,MeshMatcapMaterial as Ks,ShaderMaterial as ve,ShaderChunk as V,UniformsUtils as ze,ShaderLib as Vs,CubeReflectionMapping as Xs,CubeTextureLoader as qs,VideoTexture as Ws,DoubleSide as Zs,SpriteMaterial as Ys,Sprite as Js,Points as Qs}from"three";import{OrbitControls as ei}from"three/examples/jsm/controls/OrbitControls.js";import{RectAreaLightUniformsLib as ti}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{RectAreaLightHelper as ri}from"three/examples/jsm/helpers/RectAreaLightHelper.js";import{TextGeometry as si}from"three/examples/jsm/geometries/TextGeometry.js";import{FontLoader as ii}from"three/examples/jsm/loaders/FontLoader.js";import{GLTFLoader as ni}from"three/examples/jsm/loaders/GLTFLoader.js";import{FBXLoader as oi}from"three/examples/jsm/loaders/FBXLoader.js";import{EffectComposer as ai}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as hi}from"three/examples/jsm/postprocessing/RenderPass.js";import{BokehPass as di}from"three/examples/jsm/postprocessing/BokehPass.js";import{FilmPass as ui}from"three/examples/jsm/postprocessing/FilmPass.js";import{ShaderPass as ne}from"three/examples/jsm/postprocessing/ShaderPass.js";import{FXAAShader as ci}from"three/examples/jsm/shaders/FXAAShader.js";import{HalftonePass as li}from"three/examples/jsm/postprocessing/HalftonePass.js";import{SMAAPass as mi}from"three/examples/jsm/postprocessing/SMAAPass.js";import{SSAOPass as pi}from"three/examples/jsm/postprocessing/SSAOPass.js";import{UnrealBloomPass as fi}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";function X(e,t,r){t instanceof Object&&Object.entries(t).forEach(([s,i])=>{r?r(e,s,i):e[s]=i})}function A(e,t,r,s=!0,i){s&&X(r,e[t],i);const n=Le(e,t);return d(n,o=>{X(r,o,i)})}function Re(e,t,r=!0,s){r&&X(t,e,s);const i=Zr(e);return d(i,n=>{X(t,n,s)},{deep:!0})}function q(e,t){t instanceof Object&&Object.entries(t).forEach(([r,s])=>{e[r]=s})}function je(e,t,r){t.forEach(s=>{m(e,s,r,s)})}function m(e,t,r,s){const i=s||t,n=Le(e,t);n.value instanceof Object?(q(r[i],n.value),d(n,o=>{q(r[i],o)},{deep:!0})):(n.value!==void 0&&(r[i]=e[t]),d(n,o=>{r[i]=o}))}function Q(e,t=[]){const r={};return Object.entries(e).forEach(([s,i])=>{(!t||!t.includes(s))&&(r[s]=i)}),r}function ke(e,t,r){return r=r<0?0:r,r=r>1?1:r,e+(t-e)*r}function Ie(e,t,r){return e<t?t:e>r?r:e}const yi="https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d",gi="0404E8_0404B5_0404CB_3333FC";function Se(e=gi,t=1024){const r=`${e}${bi(t)}.png`;return`${yi}/${t}/${r}`}function bi(e){switch(e){case 64:return"-64px";case 128:return"-128px";case 256:return"-256px";case 512:return"-512px";default:return""}}function vi(e){const{camera:t,resetPosition:r=new ie(0,0,0)}=e,s=new rs,i=r.clone(),n=new ss(new ie(0,0,1),0);return{position:i,updatePosition:o=>{s.setFromCamera(o,t),t.getWorldDirection(n.normal),s.ray.intersectPlane(n,i)},intersect:(o,c,G=!1)=>(s.setFromCamera(o,t),s.intersectObjects(c,G))}}function _e(e){const{camera:t,domElement:r,intersectObjects:s,intersectRecursive:i=!1,touch:n=!0,resetOnEnd:o=!1,onEnter:c=()=>{},onMove:G=()=>{},onLeave:L=()=>{},onClick:y=()=>{},onIntersectEnter:O=()=>{},onIntersectOver:E=()=>{},onIntersectMove:b=()=>{},onIntersectLeave:F=()=>{},onIntersectClick:U=()=>{}}=e,p=new T(0,0),f=new T(0,0),z=vi({camera:t}),h=z.position,u={position:p,positionN:f,positionV3:h,intersectObjects:s,listeners:!1,addListeners:qr,removeListeners:Wr,intersect:xe};return u;function N(){p.set(0,0),f.set(0,0),h.set(0,0,0)}function P(l){let x,_;l.touches&&l.touches.length>0?(x=l.touches[0].clientX,_=l.touches[0].clientY):(x=l.clientX,_=l.clientY);const R=r.getBoundingClientRect();p.x=x-R.left,p.y=_-R.top,f.x=p.x/R.width*2-1,f.y=-(p.y/R.height)*2+1,z.updatePosition(f)}function xe(){const l=Ce();if(l.length){const x=z.intersect(f,l,i),_=[...l],R=[];x.forEach(j=>{var D,k,v;const{object:w}=j,C=pe(w);if(w instanceof ye){if(R.indexOf(w)!==-1)return;R.push(w)}if(!w.userData.over){w.userData.over=!0;const fe={type:"pointerover",over:!0,component:C,intersect:j},Ge={...fe,type:"pointerenter"};E(fe),O(Ge),(D=C==null?void 0:C.onPointerOver)==null||D.call(C,fe),(k=C==null?void 0:C.onPointerEnter)==null||k.call(C,Ge)}const Me={type:"pointermove",component:C,intersect:j};b(Me),(v=C==null?void 0:C.onPointerMove)==null||v.call(C,Me),_.splice(_.indexOf(w),1)}),_.forEach(j=>{var D,k;const v=pe(j);if(j.userData.over){j.userData.over=!1;const w={type:"pointerover",over:!1,component:v},C={...w,type:"pointerleave"};E(w),F(C),(D=v==null?void 0:v.onPointerOver)==null||D.call(v,w),(k=v==null?void 0:v.onPointerLeave)==null||k.call(v,C)}})}}function te(l){P(l),c({type:"pointerenter",position:p,positionN:f,positionV3:h})}function re(l){P(l),G({type:"pointermove",position:p,positionN:f,positionV3:h}),xe()}function we(l){P(l);const x=Ce();if(x.length){const _=z.intersect(f,x,i),R=[];_.forEach(j=>{var D;const{object:k}=j,v=pe(k);if(k instanceof ye){if(R.indexOf(k)!==-1)return;R.push(k)}const w={type:"click",component:v,intersect:j};U(w),(D=v==null?void 0:v.onClick)==null||D.call(v,w)})}y({type:"click",position:p,positionN:f,positionV3:h})}function se(){o&&N(),L({type:"pointerleave"})}function pe(l){if(l.userData.component)return l.userData.component;let x=l.parent;for(;x;){if(x.userData.component)return x.userData.component;x=x.parent}}function Ce(){return typeof s=="function"?s():s}function qr(){r.addEventListener("mouseenter",te),r.addEventListener("mousemove",re),r.addEventListener("mouseleave",se),r.addEventListener("click",we),n&&(r.addEventListener("touchstart",te),r.addEventListener("touchmove",re),r.addEventListener("touchend",se)),u.listeners=!0}function Wr(){r.removeEventListener("mouseenter",te),r.removeEventListener("mousemove",re),r.removeEventListener("mouseleave",se),r.removeEventListener("click",we),r.removeEventListener("touchstart",te),r.removeEventListener("touchmove",re),r.removeEventListener("touchend",se),u.listeners=!1}}function Si(e){const t={antialias:!0,alpha:!1,autoClear:!0,orbitCtrl:!1,pointer:!1,resize:!1,width:300,height:150};e&&Object.entries(e).forEach(([h,u])=>{t[h]=u});const r={width:1,height:1,wWidth:1,wHeight:1,ratio:1},s=[],i=[],n=c(),o={config:t,renderer:n,size:r,init:G,dispose:U,render:O,renderC:E,setSize:f,addIntersectObject:b,removeIntersectObject:F};return o;function c(){const h=new is({canvas:t.canvas,antialias:t.antialias,alpha:t.alpha,...t.params});return h.autoClear=t.autoClear,h}function G(){if(!o.scene)return console.error("Missing Scene"),!1;if(!o.camera)return console.error("Missing Camera"),!1;if(t.resize?(p(),window.addEventListener("resize",p)):t.width&&t.height&&f(t.width,t.height),L(),t.orbitCtrl){const h=new ei(o.camera,o.renderer.domElement);t.orbitCtrl instanceof Object&&Object.entries(t.orbitCtrl).forEach(([u,N])=>{h[u]=N}),y(()=>{h.update()}),o.cameraCtrl=h}return!0}function L(){let h={camera:o.camera,domElement:o.renderer.domElement,intersectObjects:i};t.pointer&&t.pointer instanceof Object&&(h={...h,...t.pointer});const u=o.pointer=_e(h);(t.pointer||i.length)&&(u.addListeners(),h.intersectMode==="frame"&&y(u.intersect))}function y(h){s.push(h)}function O(){s.forEach(h=>h()),o.renderer.render(o.scene,o.camera)}function E(){s.forEach(h=>h()),o.composer.render()}function b(h){i.indexOf(h)===-1&&i.push(h),o.pointer&&!o.pointer.listeners&&o.pointer.addListeners()}function F(h){const u=i.indexOf(h);u!==-1&&i.splice(u,1),o.pointer&&!t.pointer&&i.length===0&&o.pointer.removeListeners()}function U(){window.removeEventListener("resize",p),o.pointer&&o.pointer.removeListeners(),o.cameraCtrl&&o.cameraCtrl.dispose(),o.renderer&&o.renderer.dispose()}function p(){var h;if(t.resize==="window")f(window.innerWidth,window.innerHeight);else{const u=o.renderer.domElement.parentNode;u&&f(u.clientWidth,u.clientHeight)}(h=t.onResize)==null||h.call(t,r)}function f(h,u){r.width=h,r.height=u,r.ratio=h/u,o.renderer.setSize(h,u,!1);const N=o.camera;if(N.type==="PerspectiveCamera"){const P=N;P.aspect=r.ratio,P.updateProjectionMatrix()}if(N.type==="OrthographicCamera"){const P=N;r.wWidth=P.right-P.left,r.wHeight=P.top-P.bottom}else{const P=z();r.wWidth=P[0],r.wHeight=P[1]}}function z(){const h=o.camera,u=h.fov*Math.PI/180,N=2*Math.tan(u/2)*Math.abs(h.position.z);return[N*h.aspect,N]}}const $=Symbol("Renderer");var Te=a({name:"Renderer",props:{params:{type:Object,default:()=>({})},antialias:Boolean,alpha:Boolean,autoClear:{type:Boolean,default:!0},orbitCtrl:{type:[Boolean,Object],default:!1},pointer:{type:[Boolean,Object],default:!1},resize:{type:[Boolean,String],default:!1},shadow:Boolean,width:String,height:String,pixelRatio:Number,xr:Boolean,props:{type:Object,default:()=>({})},onReady:Function},inheritAttrs:!1,setup(e,{attrs:t}){const r=[],s=[],i=[],n=[],o=[],c=document.createElement("canvas");Object.entries(t).forEach(([O,E])=>{const b=O.match(/^on([A-Z][a-zA-Z]*)$/);b?c.addEventListener(b[1].toLowerCase(),E):c.setAttribute(O,E)});const G={canvas:c,params:e.params,antialias:e.antialias,alpha:e.alpha,autoClear:e.autoClear,orbitCtrl:e.orbitCtrl,pointer:e.pointer,resize:e.resize};e.width&&(G.width=parseInt(e.width)),e.height&&(G.height=parseInt(e.height));const L=Si(G);A(e,"props",L.renderer),Yr(()=>{e.pixelRatio&&L.renderer.setPixelRatio(e.pixelRatio)});const y=()=>{};return{canvas:c,three:L,renderer:L.renderer,size:L.size,renderFn:y,raf:!0,initCallbacks:r,mountedCallbacks:s,beforeRenderCallbacks:i,afterRenderCallbacks:n,resizeCallbacks:o}},computed:{camera:{get:function(){return this.three.camera},set:function(e){this.three.camera=e}},scene:{get:function(){return this.three.scene},set:function(e){this.three.scene=e}},composer:{get:function(){return this.three.composer},set:function(e){this.three.composer=e}}},provide(){return{[$]:this}},mounted(){var e;this.$el.parentNode.insertBefore(this.canvas,this.$el),this.three.init()&&(this.three.pointer&&(this.$pointer=this.three.pointer),this.three.config.onResize=t=>{this.resizeCallbacks.forEach(r=>r({type:"resize",renderer:this,size:t}))},this.shadow&&(this.renderer.shadowMap.enabled=!0),this.renderFn=this.three.composer?this.three.renderC:this.three.render,this.initCallbacks.forEach(t=>t({type:"init",renderer:this})),(e=this.onReady)==null||e.call(this,this),this.xr?(this.renderer.xr.enabled=!0,this.renderer.setAnimationLoop(this.render)):requestAnimationFrame(this.renderLoop)),this.mountedCallbacks.forEach(t=>t({type:"mounted",renderer:this}))},beforeUnmount(){this.canvas.remove(),this.beforeRenderCallbacks=[],this.afterRenderCallbacks=[],this.raf=!1,this.three.dispose()},methods:{onInit(e){this.addListener("init",e)},onMounted(e){this.addListener("mounted",e)},onBeforeRender(e){this.addListener("beforerender",e)},offBeforeRender(e){this.removeListener("beforerender",e)},onAfterRender(e){this.addListener("afterrender",e)},offAfterRender(e){this.removeListener("afterrender",e)},onResize(e){this.addListener("resize",e)},offResize(e){this.removeListener("resize",e)},addListener(e,t){this.getCallbacks(e).push(t)},removeListener(e,t){const r=this.getCallbacks(e),s=r.indexOf(t);s!==-1&&r.splice(s,1)},getCallbacks(e){return e==="init"?this.initCallbacks:e==="mounted"?this.mountedCallbacks:e==="beforerender"?this.beforeRenderCallbacks:e==="afterrender"?this.afterRenderCallbacks:this.resizeCallbacks},render(e){this.beforeRenderCallbacks.forEach(t=>t({type:"beforerender",renderer:this,time:e})),this.renderFn({renderer:this,time:e}),this.afterRenderCallbacks.forEach(t=>t({type:"afterrender",renderer:this,time:e}))},renderLoop(e){this.raf&&requestAnimationFrame(this.renderLoop),this.render(e)}},render(){return this.$slots.default?this.$slots.default():[]},__hmrId:"Renderer"}),Ae=a({props:{props:{type:Object,default:()=>({})}},render(){return this.$slots.default?this.$slots.default():[]}});function oe(e,t,r,s=!0){e[t]=r,s&&e.updateProjectionMatrix()}var Be=a({extends:Ae,name:"OrthographicCamera",props:{left:{type:Number,default:-1},right:{type:Number,default:1},top:{type:Number,default:1},bottom:{type:Number,default:-1},near:{type:Number,default:.1},far:{type:Number,default:2e3},zoom:{type:Number,default:1},position:{type:Object,default:()=>({x:0,y:0,z:0})}},setup(e){const t=K($);if(!t){console.error("Renderer not found");return}const r=new ns(e.left,e.right,e.top,e.bottom,e.near,e.far);return t.camera=r,m(e,"position",r),A(e,"props",r,!0,oe),["left","right","top","bottom","near","far","zoom"].forEach(s=>{d(()=>e[s],i=>{oe(r,s,i)})}),{renderer:t,camera:r}},__hmrId:"OrthographicCamera"}),ae=a({extends:Ae,name:"PerspectiveCamera",props:{aspect:{type:Number,default:1},far:{type:Number,default:2e3},fov:{type:Number,default:50},near:{type:Number,default:.1},position:{type:Object,default:()=>({x:0,y:0,z:0})},lookAt:{type:Object,default:null}},setup(e){var t;const r=K($);if(!r){console.error("Renderer not found");return}const s=new os(e.fov,e.aspect,e.near,e.far);return r.camera=s,m(e,"position",s),e.lookAt&&s.lookAt((t=e.lookAt.x)!=null?t:0,e.lookAt.y,e.lookAt.z),d(()=>e.lookAt,i=>{var n;s.lookAt((n=i.x)!=null?n:0,i.y,i.z)},{deep:!0}),A(e,"props",s,!0,oe),["aspect","far","fov","near"].forEach(i=>{d(()=>e[i],n=>{oe(s,i,n)})}),{renderer:r,camera:s}},__hmrId:"PerspectiveCamera"});const he=Symbol("Scene");var De=a({name:"Scene",props:{background:[String,Number,Object]},setup(e){const t=K($),r=new as;if(!t){console.error("Renderer not found");return}t.scene=r,Jr(he,r);const s=i=>{!i||(typeof i=="string"||typeof i=="number"?r.background instanceof Y?r.background.set(i):r.background=new Y(i):i instanceof hs&&(r.background=i))};return s(e.background),d(()=>e.background,s),{scene:r,add:i=>{r.add(i)},remove:i=>{r.remove(i)}}},render(){return this.$slots.default?this.$slots.default():[]},__hmrId:"Scene"});const Pi={onPointerEnter:Function,onPointerOver:Function,onPointerMove:Function,onPointerLeave:Function,onPointerDown:Function,onPointerUp:Function,onClick:Function};var B=a({name:"Object3D",inject:{renderer:$,scene:he},emits:["created","ready"],props:{position:{type:Object,default:()=>({x:0,y:0,z:0})},rotation:{type:Object,default:()=>({x:0,y:0,z:0})},scale:{type:Object,default:()=>({x:1,y:1,z:1,order:"XYZ"})},lookAt:{type:Object,default:null},userData:{type:Object,default:()=>({})},visible:{type:Boolean,default:!0},props:{type:Object,default:()=>({})},disableAdd:{type:Boolean,default:!1},disableRemove:{type:Boolean,default:!1},...Pi},setup(){return{}},created(){this.renderer||console.error("Missing parent Renderer"),this.scene||console.error("Missing parent Scene")},unmounted(){this.disableRemove||this.removeFromParent(),this.o3d&&this.renderer&&this.renderer.three.removeIntersectObject(this.o3d)},methods:{initObject3D(e){var t;this.o3d=e,e.userData.component=this,(this.onPointerEnter||this.onPointerOver||this.onPointerMove||this.onPointerLeave||this.onPointerDown||this.onPointerUp||this.onClick)&&this.renderer&&this.renderer.three.addIntersectObject(e),m(this,"position",e),m(this,"rotation",e),m(this,"scale",e),m(this,"userData",e.userData),m(this,"visible",e),A(this,"props",e),this.$emit("created",e),this.lookAt&&e.lookAt((t=this.lookAt.x)!=null?t:0,this.lookAt.y,this.lookAt.z),d(()=>this.lookAt,r=>{var s;e.lookAt((s=r.x)!=null?s:0,r.y,r.z)},{deep:!0}),this.parent=this.getParent(),this.disableAdd||(this.addToParent()?this.$emit("ready",this):console.error("Missing parent (Scene, Group...)"))},getParent(){let e=this.$parent;if(!e){const t=Qr();t&&t.parent&&(e=t.parent.ctx)}for(;e;){if(e.add)return e;e=e.$parent}},addToParent(e){const t=e||this.o3d;return this.parent?(this.parent.add(t),!0):!1},removeFromParent(e){const t=e||this.o3d;return this.parent?(this.parent.remove(t),!0):!1},add(e){var t;(t=this.o3d)==null||t.add(e)},remove(e){var t;(t=this.o3d)==null||t.remove(e)}},render(){return this.$slots.default?this.$slots.default():[]},__hmrId:"Object3D"}),Fe=a({name:"Group",extends:B,setup(){return{group:new ds}},created(){this.initObject3D(this.group)},__hmrId:"Group"});const ee=()=>{};var Ue=a({name:"Raycaster",props:{onPointerEnter:{type:Function,default:ee},onPointerOver:{type:Function,default:ee},onPointerMove:{type:Function,default:ee},onPointerLeave:{type:Function,default:ee},onClick:{type:Function,default:ee},intersectMode:{type:String,default:"move"},intersectRecursive:{type:Boolean,default:!1}},setup(){return{renderer:K($)}},mounted(){if(!this.renderer){console.error("Renderer not found");return}const e=this.renderer;this.renderer.onMounted(()=>{!e.camera||(this.pointer=_e({camera:e.camera,domElement:e.canvas,intersectObjects:()=>e.scene?e.scene.children:[],intersectRecursive:this.intersectRecursive,onIntersectEnter:this.onPointerEnter,onIntersectOver:this.onPointerOver,onIntersectMove:this.onPointerMove,onIntersectLeave:this.onPointerLeave,onIntersectClick:this.onClick}),this.pointer.addListeners(),this.intersectMode==="frame"&&e.onBeforeRender(this.pointer.intersect))})},unmounted(){var e;this.pointer&&(this.pointer.removeListeners(),(e=this.renderer)==null||e.offBeforeRender(this.pointer.intersect))},render(){return[]},__hmrId:"Raycaster"}),He=a({extends:B,props:{cubeRTSize:{type:Number,default:256},cubeCameraNear:{type:Number,default:.1},cubeCameraFar:{type:Number,default:2e3},autoUpdate:Boolean,hideMeshes:{type:Array,default:()=>[]}},setup(e){const t=K($);if(!t||!t.scene)return console.error("Missing Renderer / Scene"),{};const r=t.renderer,s=t.scene,i=new us(e.cubeRTSize,{format:cs,generateMipmaps:!0,minFilter:ls}),n=new ms(e.cubeCameraNear,e.cubeCameraFar,i),o=()=>{e.hideMeshes.forEach(c=>{c.visible=!1}),n.update(r,s),e.hideMeshes.forEach(c=>{c.visible=!0})};return e.autoUpdate?(t.onBeforeRender(o),es(()=>{t.offBeforeRender(o)})):t.onMounted(o),{cubeRT:i,cubeCamera:n,updateRT:o}},created(){this.cubeCamera&&this.initObject3D(this.cubeCamera)},render(){return[]},__hmrId:"CubeCamera"});const W=Symbol("Mesh"),H=a({name:"Mesh",extends:B,props:{castShadow:Boolean,receiveShadow:Boolean},setup(){return{}},provide(){return{[W]:this}},mounted(){!this.mesh&&!this.loading&&this.initMesh()},methods:{initMesh(){const e=new ps(this.geometry,this.material);m(this,"castShadow",e),m(this,"receiveShadow",e),this.mesh=e,this.initObject3D(e)},createGeometry(){},addGeometryWatchers(e){Object.keys(e).forEach(t=>{d(()=>this[t],()=>{this.refreshGeometry()})})},setGeometry(e){this.geometry=e,this.mesh&&(this.mesh.geometry=e)},setMaterial(e){if(Array.isArray(e)||!this.material)this.material=e,this.mesh&&(this.mesh.material=e);else{let t=this.material;Array.isArray(t)?t.push(e):t=[t,e],this.material=t,this.mesh&&(this.mesh.material=t)}},refreshGeometry(){const e=this.geometry;this.createGeometry(),this.mesh&&this.geometry&&(this.mesh.geometry=this.geometry),e==null||e.dispose()}},unmounted(){if(this.geometry&&this.geometry.dispose(),this.material)if(Array.isArray(this.material))for(const e of this.material)e.dispose();else this.material.dispose()},__hmrId:"Mesh"});function S(e,t,r){return a({name:e,extends:H,props:t,created(){this.createGeometry(),this.addGeometryWatchers(t)},methods:{createGeometry(){this.geometry=r(this)}}})}const de=a({emits:["created"],props:{rotateX:Number,rotateY:Number,rotateZ:Number,attributes:{type:Array,default:()=>[]}},inject:{mesh:W},setup(){return{}},created(){if(!this.mesh){console.error("Missing parent Mesh");return}this.createGeometry(),this.rotateGeometry(),this.geometry&&this.mesh.setGeometry(this.geometry),Object.keys(this.$props).forEach(e=>{d(()=>this[e],this.refreshGeometry)})},unmounted(){var e;(e=this.geometry)==null||e.dispose()},methods:{createGeometry(){const e={},t=new fs;this.attributes.forEach(r=>{if(r.name&&r.itemSize&&r.array){const s=e[r.name]=new ys(r.array,r.itemSize,r.normalized);t.setAttribute(r.name,s)}}),t.computeBoundingBox(),t.userData.component=this,this.geometry=t,this.$emit("created",t)},rotateGeometry(){!this.geometry||(this.rotateX&&this.geometry.rotateX(this.rotateX),this.rotateY&&this.geometry.rotateY(this.rotateY),this.rotateZ&&this.geometry.rotateZ(this.rotateZ))},refreshGeometry(){const e=this.geometry;this.createGeometry(),this.rotateGeometry(),this.geometry&&this.mesh&&this.mesh.setGeometry(this.geometry),e==null||e.dispose()}},render(){return[]}});function g(e,t,r){return a({name:e,extends:de,props:t,methods:{createGeometry(){this.geometry=r(this),this.geometry.userData.component=this,this.$emit("created",this.geometry)}}})}const Ke={size:Number,width:{type:Number,default:1},height:{type:Number,default:1},depth:{type:Number,default:1},widthSegments:{type:Number,default:1},heightSegments:{type:Number,default:1},depthSegments:{type:Number,default:1}};function Ve(e){return e.size?new Oe(e.size,e.size,e.size,e.widthSegments,e.heightSegments,e.depthSegments):new Oe(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}var Xe=g("BoxGeometry",Ke,Ve);const qe={radius:{type:Number,default:1},segments:{type:Number,default:8},thetaStart:{type:Number,default:0},thetaLength:{type:Number,default:Math.PI*2}};function We(e){return new gs(e.radius,e.segments,e.thetaStart,e.thetaLength)}var Ze=g("CircleGeometry",qe,We);const Ye={radius:{type:Number,default:1},height:{type:Number,default:1},radialSegments:{type:Number,default:8},heightSegments:{type:Number,default:1},openEnded:{type:Boolean,default:!1},thetaStart:{type:Number,default:0},thetaLength:{type:Number,default:Math.PI*2}};function Je(e){return new bs(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}var Qe=g("ConeGeometry",Ye,Je);const et={radiusTop:{type:Number,default:1},radiusBottom:{type:Number,default:1},height:{type:Number,default:1},radialSegments:{type:Number,default:8},heightSegments:{type:Number,default:1},openEnded:{type:Boolean,default:!1},thetaStart:{type:Number,default:0},thetaLength:{type:Number,default:Math.PI*2}};function tt(e){return new vs(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}var rt=g("CylinderGeometry",et,tt);const st={radius:{type:Number,default:1},detail:{type:Number,default:0}};function it(e){return new Ss(e.radius,e.detail)}var nt=g("DodecahedronGeometry",st,it);const xi={shapes:{type:[Object,Array]},options:{type:Object}};function wi(e){return new Ps(e.shapes,e.options)}var ot=g("ExtrudeGeometry",xi,wi);const at={radius:{type:Number,default:1},detail:{type:Number,default:0}};function ht(e){return new xs(e.radius,e.detail)}var dt=g("IcosahedronGeometry",at,ht);const ut={points:Array,segments:{type:Number,default:12},phiStart:{type:Number,default:0},phiLength:{type:Number,default:Math.PI*2}};function ct(e){return new ws(e.points,e.segments,e.phiStart,e.phiLength)}var lt=g("LatheGeometry",ut,ct);const mt={radius:{type:Number,default:1},detail:{type:Number,default:0}};function pt(e){return new Cs(e.radius,e.detail)}var ft=g("OctahedronGeometry",mt,pt);const yt={width:{type:Number,default:1},height:{type:Number,default:1},widthSegments:{type:Number,default:1},heightSegments:{type:Number,default:1}};function gt(e){return new Ne(e.width,e.height,e.widthSegments,e.heightSegments)}var bt=g("PlaneGeometry",yt,gt);const vt={vertices:Array,indices:Array,radius:{type:Number,default:1},detail:{type:Number,default:0}};function St(e){return new Ms(e.vertices,e.indices,e.radius,e.detail)}var Pt=g("PolyhedronGeometry",vt,St);const xt={innerRadius:{type:Number,default:.5},outerRadius:{type:Number,default:1},thetaSegments:{type:Number,default:8},phiSegments:{type:Number,default:1},thetaStart:{type:Number,default:0},thetaLength:{type:Number,default:Math.PI*2}};function wt(e){return new Gs(e.innerRadius,e.outerRadius,e.thetaSegments,e.phiSegments,e.thetaStart,e.thetaLength)}var Ct=g("RingGeometry",xt,wt);const Mt={radius:{type:Number,default:1},widthSegments:{type:Number,default:12},heightSegments:{type:Number,default:12},phiStart:{type:Number,default:0},phiLength:{type:Number,default:Math.PI*2},thetaStart:{type:Number,default:0},thetaLength:{type:Number,default:Math.PI}};function Gt(e){return new Ls(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}var Lt=g("SphereGeometry",Mt,Gt);const Ci={shapes:{type:[Object,Array]},curveSegments:{type:Number}};function Mi(e){return new Os(e.shapes,e.curveSegments)}var Ot=g("ShapeGeometry",Ci,Mi);const Nt={radius:{type:Number,default:1},detail:{type:Number,default:0}};function $t(e){return new Ns(e.radius,e.detail)}var Et=g("TetrahedronGeometry",Nt,$t);const zt={radius:{type:Number,default:1},tube:{type:Number,default:.4},radialSegments:{type:Number,default:8},tubularSegments:{type:Number,default:6},arc:{type:Number,default:Math.PI*2}};function Rt(e){return new $s(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}var jt=g("TorusGeometry",zt,Rt);const kt={radius:{type:Number,default:1},tube:{type:Number,default:.4},tubularSegments:{type:Number,default:64},radialSegments:{type:Number,default:8},p:{type:Number,default:2},q:{type:Number,default:3}};function It(e){return new Es(e.radius,e.tube,e.tubularSegments,e.radialSegments,e.p,e.q)}var _t=g("TorusKnotGeometry",kt,It);const Pe={points:Array,path:zs,tubularSegments:{type:Number,default:64},radius:{type:Number,default:1},radialSegments:{type:Number,default:8},closed:{type:Boolean,default:!1}};function Tt(e){let t;return e.points?t=new $e(e.points):e.path?t=e.path:console.error("Missing path curve or points."),new Rs(t,e.tubularSegments,e.radius,e.radiusSegments,e.closed)}var At=a({extends:de,props:Pe,methods:{createGeometry(){this.geometry=Tt(this)},updatePoints(e){Bt(this.geometry,e)}}});function Bt(e,t){const r=new $e(t),{radialSegments:s,radius:i,tubularSegments:n,closed:o}=e.parameters,c=r.computeFrenetFrames(n,o);e.tangents=c.tangents,e.normals=c.normals,e.binormals=c.binormals,e.parameters.path=r;const G=e.getAttribute("position"),L=e.getAttribute("normal"),y=new ie,O=new ie;for(let b=0;b<n;b++)E(b);E(n),e.attributes.position.needsUpdate=!0,e.attributes.normal.needsUpdate=!0;function E(b){r.getPointAt(b/n,O);const F=c.normals[b],U=c.binormals[b];for(let p=0;p<=s;p++){const f=p/s*Math.PI*2,z=Math.sin(f),h=-Math.cos(f);y.x=h*F.x+z*U.x,y.y=h*F.y+z*U.y,y.z=h*F.z+z*U.z,y.normalize();const u=b*(s+1)+p;L.setXYZ(u,y.x,y.y,y.z),G.setXYZ(u,O.x+i*y.x,O.y+i*y.y,O.z+i*y.z)}}}var Z=a({extends:B,name:"Light",props:{color:{type:String,default:"#ffffff"},intensity:{type:Number,default:1},castShadow:{type:Boolean,default:!1},shadowMapSize:{type:Object,default:()=>({x:512,y:512})},shadowCamera:{type:Object,default:()=>({})}},setup(){return{}},unmounted(){(this.light instanceof ge||this.light instanceof be)&&this.removeFromParent(this.light.target)},methods:{initLight(e){this.light=e,e.shadow&&(e.castShadow=this.castShadow,q(e.shadow.mapSize,this.shadowMapSize),q(e.shadow.camera,this.shadowCamera)),["color","intensity","castShadow"].forEach(t=>{d(()=>this[t],r=>{t==="color"?e.color.set(r):e[t]=r})}),this.initObject3D(e),(e instanceof ge||e instanceof be)&&(m(this,"target",e.target,"position"),this.addToParent(e.target))}},__hmrId:"Light"}),Dt=a({extends:Z,created(){this.initLight(new js(this.color,this.intensity))},__hmrId:"AmbientLight"}),Ft=a({extends:Z,props:{target:{type:Object,default:()=>({x:0,y:0,z:0})}},created(){this.initLight(new be(this.color,this.intensity))},__hmrId:"DirectionalLight"}),Ut=a({extends:Z,props:{groundColor:{type:String,default:"#444444"}},created(){const e=new ks(this.color,this.groundColor,this.intensity);d(()=>this.groundColor,t=>{e.groundColor.set(t)}),this.initLight(e)},__hmrId:"HemisphereLight"}),Ht=a({extends:Z,props:{distance:{type:Number,default:0},decay:{type:Number,default:1}},created(){this.initLight(new Is(this.color,this.intensity,this.distance,this.decay))},__hmrId:"PointLight"}),Kt=a({extends:Z,props:{width:{type:Number,default:10},height:{type:Number,default:10},helper:Boolean},created(){ti.init();const e=new _s(this.color,this.intensity,this.width,this.height);if(["width","height"].forEach(t=>{d(()=>this[t],r=>{e[t]=r})}),this.helper){const t=new ri(e);e.add(t)}this.initLight(e)},__hmrId:"RectAreaLight"}),Vt=a({extends:Z,props:{angle:{type:Number,default:Math.PI/3},decay:{type:Number,default:1},distance:{type:Number,default:0},penumbra:{type:Number,default:0},target:Object},created(){const e=new ge(this.color,this.intensity,this.distance,this.angle,this.penumbra,this.decay);["angle","decay","distance","penumbra"].forEach(t=>{d(()=>this[t],r=>{e[t]=r})}),this.initLight(e)},__hmrId:"SpotLight"});const ue=Symbol("Material"),ce=a({emits:["created"],props:{color:{type:String,default:"#ffffff"},props:{type:Object,default:()=>({})}},inject:{mesh:W},setup(){return{}},provide(){return{[ue]:this}},created(){if(!this.mesh){console.error("Missing parent Mesh");return}if(this.createMaterial){const e=this.material=this.createMaterial();d(()=>this.color,t=>{e.color.set(t)}),A(this,"props",e,!1,this.setProp),this.$emit("created",e),this.mesh.setMaterial(e)}},unmounted(){var e;(e=this.material)==null||e.dispose()},methods:{getMaterialParams(){return{...Q(this.$props,["props"]),...this.props}},setProp(e,t,r,s=!1){const i=e[t];i instanceof Y?i.set(r):e[t]=r,e.needsUpdate=s},setTexture(e,t="map"){this.setProp(this.material,t,e,!0)}},render(){return this.$slots.default?this.$slots.default():[]},__hmrId:"Material"});function I(e,t,r){return a({name:e,extends:ce,props:t,methods:{createMaterial(){return r(this.getMaterialParams())}}})}const Xt=I("BasicMaterial",{props:{type:Object,default:()=>({})}},e=>new Ee(e)),qt=I("LambertMaterial",{props:{type:Object,default:()=>({})}},e=>new Ts(e)),Wt=I("PhongMaterial",{props:{type:Object,default:()=>({})}},e=>new As(e)),Zt=I("PhysicalMaterial",{props:{type:Object,default:()=>({})}},e=>new Bs(e)),Yt=I("PointsMaterial",{props:{type:Object,default:()=>({})}},e=>new Ds(e)),Jt=I("ShadowMaterial",{color:{type:String,default:"#000000"},props:{type:Object,default:()=>({})}},e=>new Fs(e)),Qt=I("StandardMaterial",{props:{type:Object,default:()=>({})}},e=>new Us(e)),er=I("ToonMaterial",{props:{type:Object,default:()=>({})}},e=>new Hs(e));var tr=I("MatcapMaterial",{src:String,name:{type:String,default:"0404E8_0404B5_0404CB_3333FC"}},e=>{const t=e.src?e.src:Se(e.name),r=Q(e,["src","name"]);return r.matcap=new J().load(t),new Ks(r)});const Gi=`
|
|
varying vec2 vUv;
|
|
void main(){
|
|
vUv = uv;
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
|
|
}
|
|
`,Li=`
|
|
varying vec2 vUv;
|
|
void main() {
|
|
gl_FragColor = vec4(vUv.x, vUv.y, 0., 1.0);
|
|
}
|
|
`;var rr=I("ShaderMaterial",{props:{type:Object,default:()=>({uniforms:{},vertexShader:Gi,fragmentShader:Li})}},e=>new ve(Q(e,["color"])));function Oi(e,t,r){return e.split(t).join(r)}const Ni=V.meshphong_frag.slice(0,V.meshphong_frag.indexOf("void main() {")),$i=V.meshphong_frag.slice(V.meshphong_frag.indexOf("void main() {")),Ei={uniforms:ze.merge([Vs.phong.uniforms,{thicknessColor:{value:new Y(16777215)},thicknessDistortion:{value:.1},thicknessAmbient:{value:0},thicknessAttenuation:{value:.1},thicknessPower:{value:2},thicknessScale:{value:10}}]),vertexShader:`
|
|
#define USE_UV
|
|
${V.meshphong_vert}
|
|
`,fragmentShader:`
|
|
#define USE_UV
|
|
#define SUBSURFACE
|
|
|
|
${Ni}
|
|
|
|
uniform float thicknessPower;
|
|
uniform float thicknessScale;
|
|
uniform float thicknessDistortion;
|
|
uniform float thicknessAmbient;
|
|
uniform float thicknessAttenuation;
|
|
uniform vec3 thicknessColor;
|
|
|
|
void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) {
|
|
#ifdef USE_COLOR
|
|
vec3 thickness = vColor * thicknessColor;
|
|
#else
|
|
vec3 thickness = thicknessColor;
|
|
#endif
|
|
vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion));
|
|
float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale;
|
|
vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;
|
|
reflectedLight.directDiffuse += scatteringIllu * thicknessAttenuation * directLight.color;
|
|
}
|
|
`+$i.replace("#include <lights_fragment_begin>",Oi(V.lights_fragment_begin,"RE_Direct( directLight, geometry, material, reflectedLight );",`
|
|
RE_Direct( directLight, geometry, material, reflectedLight );
|
|
#if defined( SUBSURFACE ) && defined( USE_UV )
|
|
RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);
|
|
#endif
|
|
`))};var sr=a({extends:ce,props:{uniforms:{type:Object,default:()=>({diffuse:"#ffffff",thicknessColor:"#ffffff",thicknessDistortion:.4,thicknessAmbient:.01,thicknessAttenuation:.7,thicknessPower:2,thicknessScale:4})}},methods:{createMaterial(){const e=Ei,t=ze.clone(e.uniforms);return A(this,"uniforms",t,!0,(r,s,i)=>{const n=r[s].value;n instanceof Y?n.set(i):r[s].value=i}),new ve({...e,lights:!0,...this.props,uniforms:t})}}}),le=a({inject:{material:ue},props:{name:{type:String,default:"map"},uniform:String,src:String,onLoad:Function,onProgress:Function,onError:Function,props:{type:Object,default:()=>({})}},setup(){return{}},created(){this.refreshTexture(),d(()=>this.src,this.refreshTexture)},unmounted(){var e,t;(e=this.material)==null||e.setTexture(null,this.name),(t=this.texture)==null||t.dispose()},methods:{createTexture(){if(this.src)return new J().load(this.src,this.onLoaded,this.onProgress,this.onError)},initTexture(){!this.texture||(A(this,"props",this.texture),this.material&&(this.material.setTexture(this.texture,this.name),this.material.material instanceof ve&&this.uniform&&(this.material.material.uniforms[this.uniform]={value:this.texture})))},refreshTexture(){var e;(e=this.texture)==null||e.dispose(),this.texture=this.createTexture(),this.initTexture()},onLoaded(e){var t;(t=this.onLoad)==null||t.call(this,e)}},render(){return[]}}),ir=a({extends:le,props:{name:{type:String,default:"envMap"},path:{type:String,required:!0},urls:{type:Array,default:()=>["px.jpg","nx.jpg","py.jpg","ny.jpg","pz.jpg","nz.jpg"]},props:{type:Object,default:()=>({mapping:Xs})}},created(){d(()=>this.path,this.refreshTexture),d(()=>this.urls,this.refreshTexture)},methods:{createTexture(){return new qs().setPath(this.path).load(this.urls,this.onLoaded,this.onProgress,this.onError)}}}),nr=a({extends:le,props:{videoId:{type:String,required:!0}},created(){d(()=>this.videoId,this.refreshTexture)},methods:{createTexture(){const e=document.getElementById(this.videoId);return new Ws(e)}}}),or=S("Box",Ke,Ve),ar=S("Circle",qe,We),hr=S("Cone",Ye,Je),dr=S("Cylinder",et,tt),ur=S("Dodecahedron",st,it),cr=S("Icosahedron",at,ht),lr=S("Lathe",ut,ct),mr=S("Octahedron",mt,pt),pr=S("Plane",yt,gt),fr=S("Polyhedron",vt,St),yr=S("Ring",xt,wt),gr=S("Sphere",Mt,Gt),br=S("Tetrahedron",Nt,$t);const zi={text:{type:String,required:!0,default:"Text"},fontSrc:{type:String,required:!0},size:{type:Number,default:80},height:{type:Number,default:5},depth:{type:Number,default:1},curveSegments:{type:Number,default:12},bevelEnabled:{type:Boolean,default:!1},bevelThickness:{type:Number,default:10},bevelSize:{type:Number,default:8},bevelOffset:{type:Number,default:0},bevelSegments:{type:Number,default:5},align:{type:[Boolean,String],default:!1}};var vr=a({extends:H,props:zi,setup(){return{}},created(){if(!this.fontSrc){console.error('Missing required prop: "font-src"');return}["text","size","height","curveSegments","bevelEnabled","bevelThickness","bevelSize","bevelOffset","bevelSegments","align"].forEach(t=>{d(()=>this[t],()=>{this.font&&this.refreshGeometry()})});const e=new ii;this.loading=!0,e.load(this.fontSrc,t=>{this.loading=!1,this.font=t,this.createGeometry(),this.initMesh()})},methods:{createGeometry(){this.geometry=new si(this.text,{font:this.font,size:this.size,height:this.height,depth:this.depth,curveSegments:this.curveSegments,bevelEnabled:this.bevelEnabled,bevelThickness:this.bevelThickness,bevelSize:this.bevelSize,bevelOffset:this.bevelOffset,bevelSegments:this.bevelSegments}),this.align==="center"&&this.geometry.center()}}}),Sr=S("Torus",zt,Rt),Pr=S("TorusKnot",kt,It),xr=a({extends:H,props:Pe,created(){this.createGeometry(),this.addGeometryWatchers(Pe)},methods:{createGeometry(){this.geometry=Tt(this)},updatePoints(e){Bt(this.geometry,e)}},__hmrId:"Tube"}),wr=a({emits:["loaded"],extends:H,props:{src:{type:String,required:!0},width:Number,height:Number,widthSegments:{type:Number,default:1},heightSegments:{type:Number,default:1},keepSize:Boolean},setup(){return{}},created(){!this.renderer||(this.geometry=new Ne(1,1,this.widthSegments,this.heightSegments),this.material=new Ee({side:Zs,map:this.loadTexture()}),d(()=>this.src,this.refreshTexture),["width","height"].forEach(e=>{d(()=>this[e],this.resize)}),this.resize(),this.keepSize&&this.renderer.onResize(this.resize))},unmounted(){var e;(e=this.renderer)==null||e.offResize(this.resize)},methods:{loadTexture(){return new J().load(this.src,this.onLoaded)},refreshTexture(){var e;(e=this.texture)==null||e.dispose(),this.material&&(this.material.map=this.loadTexture(),this.material.needsUpdate=!0)},onLoaded(e){this.texture=e,this.resize(),this.$emit("loaded",e)},resize(){if(!this.renderer||!this.texture)return;const e=this.renderer.size,t=this.texture.image.width,r=this.texture.image.height,s=t/r;let i=1,n=1;this.width&&this.height?(i=this.width*e.wWidth/e.width,n=this.height*e.wHeight/e.height):this.width?(i=this.width*e.wWidth/e.width,n=i/s):this.height?(n=this.height*e.wHeight/e.height,i=n*s):s>1?i=n*s:n=i/s,this.mesh&&(this.mesh.scale.x=i,this.mesh.scale.y=n)}},__hmrId:"Image"}),Cr=a({extends:H,props:{count:{type:Number,required:!0}},methods:{initMesh(){if(this.renderer){if(!this.geometry||!this.material)return console.error("Missing geometry and/or material"),!1;this.mesh=new ye(this.geometry,this.material,this.count),this.mesh.userData.component=this,m(this,"castShadow",this.mesh),m(this,"receiveShadow",this.mesh),(this.onPointerEnter||this.onPointerOver||this.onPointerMove||this.onPointerLeave||this.onPointerDown||this.onPointerUp||this.onClick)&&this.renderer.three.addIntersectObject(this.mesh),this.initObject3D(this.mesh)}}},__hmrId:"InstancedMesh"}),Mr=a({extends:B,emits:["loaded"],props:{src:{type:String,required:!0}},setup(){return{}},created(){this.texture=new J().load(this.src,this.onLoaded),this.material=new Ys({map:this.texture}),this.sprite=new Js(this.material),this.initObject3D(this.sprite)},unmounted(){var e,t;(e=this.texture)==null||e.dispose(),(t=this.material)==null||t.dispose()},methods:{onLoaded(){this.updateUV(),this.$emit("loaded")},updateUV(){if(!this.texture||!this.sprite)return;const e=this.texture.image.width,t=this.texture.image.height,r=e/t;let s=.5,i=.5;r>1?s=.5*r:i=.5/r;const n=this.sprite.geometry.attributes.position.array;n[0]=-s,n[1]=-i,n[5]=s,n[6]=-i,n[10]=s,n[11]=i,n[15]=-s,n[16]=i,this.sprite.geometry.attributes.position.needsUpdate=!0}},__hmrId:"Sprite"}),Gr=a({extends:B,setup(){return{}},provide(){return{[W]:this}},mounted(){this.mesh=this.points=new Qs(this.geometry,this.material),this.initObject3D(this.mesh)},methods:{setGeometry(e){this.geometry=e,this.mesh&&(this.mesh.geometry=e)},setMaterial(e){this.material=e,this.mesh&&(this.mesh.material=e)}}}),Lr=a({extends:B,emits:["before-load","load","progress","error"],props:{src:{type:String,required:!0}},data(){return{progress:0}},methods:{onLoad(e){this.$emit("load",e)},onProgress(e){this.progress=e.loaded/e.total,this.$emit("progress",e)},onError(e){this.$emit("error",e)}}}),Or=a({extends:Lr,created(){const e=new ni;this.$emit("before-load",e),e.load(this.src,t=>{this.onLoad(t),this.initObject3D(t.scene)},this.onProgress,this.onError)}}),Nr=a({extends:Lr,created(){const e=new oi;this.$emit("before-load",e),e.load(this.src,t=>{this.onLoad(t),this.initObject3D(t)},this.onProgress,this.onError)}});const me=Symbol("Composer");var $r=a({setup(){return{renderer:K($)}},provide(){return{[me]:this}},created(){if(!this.renderer){console.error("Renderer not found");return}const e=this.renderer,t=new ai(this.renderer.renderer);this.composer=t,this.renderer.composer=t,e.addListener("init",()=>{e.renderer.autoClear=!1,this.resize(),e.addListener("resize",this.resize)})},unmounted(){var e;(e=this.renderer)==null||e.removeListener("resize",this.resize)},methods:{addPass(e){var t;(t=this.composer)==null||t.addPass(e)},removePass(e){var t;(t=this.composer)==null||t.removePass(e)},resize(){this.composer&&this.renderer&&this.composer.setSize(this.renderer.size.width,this.renderer.size.height)}},render(){return this.$slots.default?this.$slots.default():[]},__hmrId:"EffectComposer"}),M=a({inject:{renderer:$,composer:me},emits:["ready"],setup(){return{}},created(){this.composer||console.error("Missing parent EffectComposer"),this.renderer||console.error("Missing parent Renderer")},unmounted(){var e,t,r;this.pass&&((e=this.composer)==null||e.removePass(this.pass),(r=(t=this.pass).dispose)==null||r.call(t))},methods:{initEffectPass(e){var t;this.pass=e,(t=this.composer)==null||t.addPass(e),this.$emit("ready",e)}},render(){return[]},__hmrId:"EffectPass"}),Er=a({extends:M,created(){if(!this.renderer)return;if(!this.renderer.scene){console.error("Missing Scene");return}if(!this.renderer.camera){console.error("Missing Camera");return}const e=new hi(this.renderer.scene,this.renderer.camera);this.initEffectPass(e)},__hmrId:"RenderPass"});const zr={focus:{type:Number,default:1},aperture:{type:Number,default:.025},maxblur:{type:Number,default:.01}};var Rr=a({extends:M,props:zr,created(){if(!this.renderer)return;if(!this.renderer.scene){console.error("Missing Scene");return}if(!this.renderer.camera){console.error("Missing Camera");return}const e={focus:this.focus,aperture:this.aperture,maxblur:this.maxblur,width:this.renderer.size.width,height:this.renderer.size.height},t=new di(this.renderer.scene,this.renderer.camera,e);Object.keys(zr).forEach(r=>{d(()=>this[r],s=>{t.uniforms[r].value=s})}),this.initEffectPass(t)},__hmrId:"BokehPass"});const jr={noiseIntensity:{type:Number,default:.5},scanlinesIntensity:{type:Number,default:.05},scanlinesCount:{type:Number,default:4096},grayscale:{type:Number,default:0}};var kr=a({extends:M,props:jr,created(){const e=new ui(this.noiseIntensity,this.scanlinesIntensity,this.scanlinesCount,this.grayscale);Object.keys(jr).forEach(t=>{d(()=>this[t],r=>{e.uniforms[t].value=r})}),this.initEffectPass(e)},__hmrId:"FilmPass"}),Ir=a({extends:M,created(){var e;const t=new ne(ci);(e=this.renderer)==null||e.addListener("resize",this.resize),this.initEffectPass(t)},unmounted(){var e;(e=this.renderer)==null||e.removeListener("resize",this.resize)},methods:{resize({size:e}){if(this.pass){const{resolution:t}=this.pass.material.uniforms;t.value.x=1/e.width,t.value.y=1/e.height}}},__hmrId:"FXAAPass"});const _r={shape:{type:Number,default:1},radius:{type:Number,default:4},rotateR:{type:Number,default:Math.PI/12*1},rotateG:{type:Number,default:Math.PI/12*2},rotateB:{type:Number,default:Math.PI/12*3},scatter:{type:Number,default:0}};var Tr=a({extends:M,props:_r,created(){if(!this.renderer)return;const e=new li(this.renderer.size.width,this.renderer.size.height,{});Object.keys(_r).forEach(t=>{e.uniforms[t].value=this[t],d(()=>this[t],r=>{e.uniforms[t].value=r})}),this.initEffectPass(e)},__hmrId:"HalftonePass"}),Ar=a({extends:M,created(){if(!this.renderer)return;const e=new mi(this.renderer.size.width,this.renderer.size.height);this.initEffectPass(e)},__hmrId:"SMAAPass"}),Br=a({extends:M,props:{options:{type:Object,default:()=>({})}},created(){if(!this.renderer)return;if(!this.renderer.scene){console.error("Missing Scene");return}if(!this.renderer.camera){console.error("Missing Camera");return}const e=new pi(this.renderer.scene,this.renderer.camera,this.renderer.size.width,this.renderer.size.height);Object.keys(this.options).forEach(t=>{e[t]=this.options[t]}),this.initEffectPass(e)},__hmrId:"SSAOPass"}),Dr={uniforms:{},vertexShader:`
|
|
varying vec2 vUv;
|
|
void main() {
|
|
vUv = uv;
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
}
|
|
`,fragmentShader:`
|
|
varying vec2 vUv;
|
|
void main() {
|
|
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
|
}
|
|
`},Fr={uniforms:{tDiffuse:{value:null},blurRadius:{value:0},gradientRadius:{value:0},start:{value:new T},end:{value:new T},delta:{value:new T},texSize:{value:new T}},vertexShader:Dr.vertexShader,fragmentShader:`
|
|
uniform sampler2D tDiffuse;
|
|
uniform float blurRadius;
|
|
uniform float gradientRadius;
|
|
uniform vec2 start;
|
|
uniform vec2 end;
|
|
uniform vec2 delta;
|
|
uniform vec2 texSize;
|
|
varying vec2 vUv;
|
|
|
|
float random(vec3 scale, float seed) {
|
|
/* use the fragment position for a different seed per-pixel */
|
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
}
|
|
|
|
void main() {
|
|
vec4 color = vec4(0.0);
|
|
float total = 0.0;
|
|
|
|
/* randomize the lookup values to hide the fixed number of samples */
|
|
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
|
|
vec2 normal = normalize(vec2(start.y - end.y, end.x - start.x));
|
|
float radius = smoothstep(0.0, 1.0, abs(dot(vUv * texSize - start, normal)) / gradientRadius) * blurRadius;
|
|
for (float t = -30.0; t <= 30.0; t++) {
|
|
float percent = (t + offset - 0.5) / 30.0;
|
|
float weight = 1.0 - abs(percent);
|
|
vec4 texel = texture2D(tDiffuse, vUv + delta / texSize * percent * radius);
|
|
// vec4 texel2 = texture2D(tDiffuse, vUv + vec2(-delta.y, delta.x) / texSize * percent * radius);
|
|
|
|
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
texel.rgb *= texel.a;
|
|
// texel2.rgb *= texel2.a;
|
|
|
|
color += texel * weight;
|
|
total += 2.0 * weight;
|
|
}
|
|
|
|
gl_FragColor = color / total;
|
|
|
|
/* switch back from pre-multiplied alpha */
|
|
gl_FragColor.rgb /= gl_FragColor.a + 0.00001;
|
|
}
|
|
`};const Ri={blurRadius:{type:Number,default:10},gradientRadius:{type:Number,default:100},start:{type:Object,default:()=>({x:0,y:100})},end:{type:Object,default:()=>({x:10,y:100})}};var Ur=a({extends:M,props:Ri,setup(){return{uniforms1:{},uniforms2:{}}},created(){if(!this.composer)return;this.pass1=new ne(Fr),this.pass2=new ne(Fr);const e=this.uniforms1=this.pass1.uniforms,t=this.uniforms2=this.pass2.uniforms;t.blurRadius=e.blurRadius,t.gradientRadius=e.gradientRadius,t.start=e.start,t.end=e.end,t.texSize=e.texSize,m(this,"blurRadius",e.blurRadius,"value"),m(this,"gradientRadius",e.gradientRadius,"value"),this.updateFocusLine(),["start","end"].forEach(r=>{d(()=>this[r],this.updateFocusLine,{deep:!0})}),this.pass1.setSize=(r,s)=>{e.texSize.value.set(r,s)},this.initEffectPass(this.pass1),this.composer.addPass(this.pass2)},unmounted(){this.composer&&this.pass2&&this.composer.removePass(this.pass2)},methods:{updateFocusLine(){this.uniforms1.start.value.copy(this.start),this.uniforms1.end.value.copy(this.end);const e=new T().copy(this.end).sub(this.start).normalize();this.uniforms1.delta.value.copy(e),this.uniforms2.delta.value.set(-e.y,e.x)}},__hmrId:"TiltShiftPass"});const Hr={strength:{type:Number,default:1.5},radius:{type:Number,default:0},threshold:{type:Number,default:0}};var Kr=a({extends:M,props:Hr,created(){if(!this.renderer)return;const e=new T(this.renderer.size.width,this.renderer.size.height),t=new fi(e,this.strength,this.radius,this.threshold);Object.keys(Hr).forEach(r=>{d(()=>this[r],s=>{t.uniforms[r].value=s})}),this.initEffectPass(t)},__hmrId:"UnrealBloomPass"}),ji={uniforms:{tDiffuse:{value:null},center:{value:new T(.5,.5)},strength:{value:0}},vertexShader:Dr.vertexShader,fragmentShader:`
|
|
uniform sampler2D tDiffuse;
|
|
uniform vec2 center;
|
|
uniform float strength;
|
|
varying vec2 vUv;
|
|
|
|
float random(vec3 scale, float seed) {
|
|
/* use the fragment position for a different seed per-pixel */
|
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
}
|
|
|
|
void main() {
|
|
vec4 color = vec4(0.0);
|
|
float total = 0.0;
|
|
vec2 toCenter = center - vUv;
|
|
|
|
/* randomize the lookup values to hide the fixed number of samples */
|
|
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
|
|
|
|
for (float t = 0.0; t <= 40.0; t++) {
|
|
float percent = (t + offset) / 40.0;
|
|
float weight = 4.0 * (percent - percent * percent);
|
|
vec4 texel = texture2D(tDiffuse, vUv + toCenter * percent * strength);
|
|
|
|
/* switch to pre-multiplied alpha to correctly blur transparent images */
|
|
texel.rgb *= texel.a;
|
|
|
|
color += texel * weight;
|
|
total += weight;
|
|
}
|
|
|
|
gl_FragColor = color / total;
|
|
|
|
/* switch back from pre-multiplied alpha */
|
|
gl_FragColor.rgb /= gl_FragColor.a + 0.00001;
|
|
}
|
|
`},Vr=a({extends:M,props:{center:{type:Object,default:()=>({x:.5,y:.5})},strength:{type:Number,default:.5}},created(){const e=new ne(ji);m(this,"center",e.uniforms.center,"value"),m(this,"strength",e.uniforms.strength,"value"),this.initEffectPass(e)},__hmrId:"ZoomBlurPass"}),ki=Object.freeze({__proto__:null,Renderer:Te,RendererInjectionKey:$,OrthographicCamera:Be,PerspectiveCamera:ae,Camera:ae,Group:Fe,Scene:De,SceneInjectionKey:he,Object3D:B,Raycaster:Ue,CubeCamera:He,BufferGeometry:de,BoxGeometry:Xe,CircleGeometry:Ze,ConeGeometry:Qe,CylinderGeometry:rt,DodecahedronGeometry:nt,ExtrudeGeometry:ot,IcosahedronGeometry:dt,LatheGeometry:lt,OctahedronGeometry:ft,PlaneGeometry:bt,PolyhedronGeometry:Pt,RingGeometry:Ct,SphereGeometry:Lt,ShapeGeometry:Ot,TetrahedronGeometry:Et,TorusGeometry:jt,TorusKnotGeometry:_t,TubeGeometry:At,AmbientLight:Dt,DirectionalLight:Ft,HemisphereLight:Ut,PointLight:Ht,RectAreaLight:Kt,SpotLight:Vt,Material:ce,BasicMaterial:Xt,LambertMaterial:qt,PhongMaterial:Wt,PhysicalMaterial:Zt,PointsMaterial:Yt,ShadowMaterial:Jt,StandardMaterial:Qt,ToonMaterial:er,MaterialInjectionKey:ue,MatcapMaterial:tr,ShaderMaterial:rr,SubSurfaceMaterial:sr,Texture:le,CubeTexture:ir,VideoTexture:nr,Mesh:H,MeshInjectionKey:W,Box:or,Circle:ar,Cone:hr,Cylinder:dr,Dodecahedron:ur,Icosahedron:cr,Lathe:lr,Octahedron:mr,Plane:pr,Polyhedron:fr,Ring:yr,Sphere:gr,Tetrahedron:br,Text:vr,Torus:Sr,TorusKnot:Pr,Tube:xr,Image:wr,InstancedMesh:Cr,Sprite:Mr,Points:Gr,GltfModel:Or,FbxModel:Nr,EffectComposer:$r,ComposerInjectionKey:me,RenderPass:Er,EffectPass:M,BokehPass:Rr,FilmPass:kr,FXAAPass:Ir,HalftonePass:Tr,SMAAPass:Ar,SSAOPass:Br,TiltShiftPass:Ur,UnrealBloomPass:Kr,ZoomBlurPass:Vr,applyObjectProps:X,bindObjectProp:A,bindObjectProps:Re,setFromProp:q,bindProps:je,bindProp:m,propsValues:Q,lerp:ke,limit:Ie,getMatcapUrl:Se});const Xr={install(e){["Camera","OrthographicCamera","PerspectiveCamera","Raycaster","Renderer","Scene","Group","CubeCamera","AmbientLight","DirectionalLight","HemisphereLight","PointLight","RectAreaLight","SpotLight","BasicMaterial","LambertMaterial","MatcapMaterial","PhongMaterial","PhysicalMaterial","PointsMaterial","ShaderMaterial","StandardMaterial","SubSurfaceMaterial","ToonMaterial","Texture","CubeTexture","BufferGeometry","Mesh","Box","BoxGeometry","Circle","CircleGeometry","Cone","ConeGeometry","Cylinder","CylinderGeometry","Dodecahedron","DodecahedronGeometry","Icosahedron","IcosahedronGeometry","Lathe","LatheGeometry","Octahedron","OctahedronGeometry","Plane","PlaneGeometry","Polyhedron","PolyhedronGeometry","Ring","RingGeometry","Sphere","SphereGeometry","Tetrahedron","TetrahedronGeometry","Text","Torus","TorusGeometry","TorusKnot","TorusKnotGeometry","Tube","TubeGeometry","Image","InstancedMesh","Points","Sprite","FbxModel","GltfModel","BokehPass","EffectComposer","FilmPass","FXAAPass","HalftonePass","RenderPass","SAOPass","SMAAPass","SSAOPass","TiltShiftPass","UnrealBloomPass","ZoomBlurPass"].forEach(t=>{e.component(t,ki[t])})}};function Ii(e){return ts(e).use(Xr)}function _i(){const e={loader:new J,count:0,textures:[],loadProgress:0,loadTextures:t,dispose:s};return e;function t(i,n){e.count=i.length,e.textures.splice(0),e.loadProgress=0,Promise.all(i.map(r)).then(n)}function r(i,n){return new Promise(o=>{e.loader.load(i.src,c=>{e.loadProgress+=1/e.count,e.textures[n]=c,o(c)})})}function s(){e.textures.forEach(i=>i.dispose())}}export{Dt as AmbientLight,Xt as BasicMaterial,Rr as BokehPass,or as Box,Xe as BoxGeometry,de as BufferGeometry,ae as Camera,ar as Circle,Ze as CircleGeometry,me as ComposerInjectionKey,hr as Cone,Qe as ConeGeometry,He as CubeCamera,ir as CubeTexture,dr as Cylinder,rt as CylinderGeometry,Ft as DirectionalLight,ur as Dodecahedron,nt as DodecahedronGeometry,$r as EffectComposer,M as EffectPass,ot as ExtrudeGeometry,Ir as FXAAPass,Nr as FbxModel,kr as FilmPass,Or as GltfModel,Fe as Group,Tr as HalftonePass,Ut as HemisphereLight,cr as Icosahedron,dt as IcosahedronGeometry,wr as Image,Cr as InstancedMesh,qt as LambertMaterial,lr as Lathe,lt as LatheGeometry,tr as MatcapMaterial,ce as Material,ue as MaterialInjectionKey,H as Mesh,W as MeshInjectionKey,B as Object3D,mr as Octahedron,ft as OctahedronGeometry,Be as OrthographicCamera,ae as PerspectiveCamera,Wt as PhongMaterial,Zt as PhysicalMaterial,pr as Plane,bt as PlaneGeometry,Ht as PointLight,Gr as Points,Yt as PointsMaterial,fr as Polyhedron,Pt as PolyhedronGeometry,Ue as Raycaster,Kt as RectAreaLight,Er as RenderPass,Te as Renderer,$ as RendererInjectionKey,yr as Ring,Ct as RingGeometry,Ar as SMAAPass,Br as SSAOPass,De as Scene,he as SceneInjectionKey,rr as ShaderMaterial,Jt as ShadowMaterial,Ot as ShapeGeometry,gr as Sphere,Lt as SphereGeometry,Vt as SpotLight,Mr as Sprite,Qt as StandardMaterial,sr as SubSurfaceMaterial,br as Tetrahedron,Et as TetrahedronGeometry,vr as Text,le as Texture,Ur as TiltShiftPass,er as ToonMaterial,Sr as Torus,jt as TorusGeometry,Pr as TorusKnot,_t as TorusKnotGeometry,Xr as TroisJSVuePlugin,xr as Tube,At as TubeGeometry,Kr as UnrealBloomPass,nr as VideoTexture,Vr as ZoomBlurPass,X as applyObjectProps,A as bindObjectProp,Re as bindObjectProps,m as bindProp,je as bindProps,Ii as createApp,Se as getMatcapUrl,ke as lerp,Ie as limit,Q as propsValues,q as setFromProp,_i as useTextures};
|
|
//# sourceMappingURL=trois.module.min.js.map
|