@goodfish/jarvy 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1 @@
1
+ var _=Object.defineProperty;var B=(n,t,s)=>t in n?_(n,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[t]=s;var r=(n,t,s)=>B(n,typeof t!="symbol"?t+"":t,s);function C(n,t,s,e){const o=new n.Shape,i=-t/2,a=-s/2;return o.moveTo(i+e,a),o.lineTo(i+t-e,a),o.quadraticCurveTo(i+t,a,i+t,a+e),o.lineTo(i+t,a+s-e),o.quadraticCurveTo(i+t,a+s,i+t-e,a+s),o.lineTo(i+e,a+s),o.quadraticCurveTo(i,a+s,i,a+s-e),o.lineTo(i,a+e),o.quadraticCurveTo(i,a,i+e,a),o}function q(n){n.ColorManagement.enabled=!1;const t=new n.Scene,s=new n.PerspectiveCamera(35,1,.1,50);t.add(new n.HemisphereLight(16777215,7828845,.8*Math.PI));const e=new n.DirectionalLight(16777215,.85*Math.PI);e.position.set(-1.6,3.6,1.8),e.castShadow=!0,e.shadow.mapSize.set(1024,1024),e.shadow.bias=-5e-4,e.shadow.normalBias=.02,Object.assign(e.shadow.camera,{left:-2,right:2,top:2,bottom:-2,near:.5,far:10}),t.add(e);const o=new n.DirectionalLight(16777215,.35*Math.PI);o.position.set(2,1,4),t.add(o);const i=new n.Mesh(new n.PlaneGeometry(8,8),new n.ShadowMaterial({opacity:.32}));return i.rotation.x=-Math.PI/2,i.position.y=-.78,i.receiveShadow=!0,t.add(i),{scene:t,camera:s,ground:i}}function L(n,t){t.outputColorSpace=n.LinearSRGBColorSpace,t.shadowMap.enabled=!0,t.shadowMap.type=n.PCFShadowMap}function W(n,t,s=3.5){n.aspect=t,n.position.set(0,.5,Math.max(s,s*1.15/t*.9)),n.lookAt(0,-.02,0),n.updateProjectionMatrix()}class D{constructor(t,s){r(this,"root");r(this,"head");r(this,"eyes");r(this,"body");r(this,"parts");r(this,"paws");r(this,"disposables",[]);r(this,"shown","normal");r(this,"yaw",.55);r(this,"pitch",0);r(this,"lookX",0);r(this,"lookY",0);r(this,"blinkAt",1500);r(this,"blinkStart",-1e9);r(this,"shakeAt",-1e9);r(this,"start",performance.now());const e=l=>(this.disposables.push(l),l);this.body=e(new t.MeshStandardMaterial({color:s,roughness:.55,metalness:0}));const o=e(new t.MeshBasicMaterial({color:2302495}));this.root=new t.Group,this.head=new t.Group,this.root.add(this.head);const i=e(new t.ExtrudeGeometry(C(t,1.2,.86,.2),{depth:.5,bevelEnabled:!0,bevelSize:.1,bevelThickness:.1,bevelSegments:6,curveSegments:14}));i.center();const a=new t.Mesh(i,this.body);a.castShadow=!0,a.receiveShadow=!0,this.head.add(a);const w=new t.Shape;w.moveTo(-.14,0),w.lineTo(.14,0),w.lineTo(0,.34),w.closePath();const u=e(new t.ExtrudeGeometry(w,{depth:.1,bevelEnabled:!0,bevelSize:.03,bevelThickness:.03,bevelSegments:3}));u.translate(0,0,-.05);for(const l of[-1,1]){const h=new t.Mesh(u,this.body);h.castShadow=!0,h.position.set(l*.42,.44,.04),h.rotation.z=-l*.2,this.head.add(h)}this.eyes=new t.Group,this.eyes.position.set(.12,.04,.352),this.head.add(this.eyes);const b=e(new t.ExtrudeGeometry(C(t,.08,.22,.04),{depth:.012,bevelEnabled:!1})),p=Math.PI*.85,c=.085,f=e(new t.TorusGeometry(c,.024,8,24,p)),v=e(new t.SphereGeometry(.024,10,8)),P=Array.from({length:91},(l,h)=>{const M=h/90,y=M*Math.PI*5,k=.012+M*.085;return new t.Vector3(Math.cos(y)*k,Math.sin(y)*k,0)}),x=e(new t.TubeGeometry(new t.CatmullRomCurve3(P),120,.012,6,!1));this.parts=[-.17,.17].map(l=>{const h=new t.Group;h.position.x=l,this.eyes.add(h);const M=new t.Mesh(b,o);h.add(M);const y=new t.Group,k=new t.Mesh(f,o);k.rotation.z=Math.PI/2-p/2,y.add(k);for(const S of[Math.PI/2-p/2,Math.PI/2+p/2]){const G=new t.Mesh(v,o);G.position.set(Math.cos(S)*c,Math.sin(S)*c,0),y.add(G)}y.position.set(0,-.04,.02),h.add(y);const m=new t.Mesh(x,o);return m.position.z=.014,h.add(m),{group:h,pill:M,arc:y,spiral:m}});const z=e(new t.SphereGeometry(1,24,16));this.paws=[-.42,.42].map(l=>{const h=new t.Mesh(z,this.body);return h.castShadow=!0,h.receiveShadow=!0,h.scale.set(.17,.1,.15),h.position.set(l,-.66,.22),this.root.add(h),h}),this.root.rotation.y=.55,this.show("normal")}setColor(t){this.body.color.setHex(t)}show(t){this.shown=t;for(const s of this.parts)s.pill.visible=t==="normal"||t==="sad"||t==="angry",s.arc.visible=t==="happy",s.spiral.visible=t==="dizzy"}pose(t){this.show(t),this.root.rotation.y=.55,this.head.rotation.set(t==="sad"?.1:t==="angry"?.06:0,0,0),this.head.position.y=0,this.eyes.position.set(.12,.04-(t==="sad"?.03:0)-(t==="angry"?.015:0),.352);const s=t==="sad"?.32:t==="angry"?-.38:0;this.parts.forEach((e,o)=>{e.group.scale.y=t==="angry"?.78:1,e.group.rotation.z=o?s:-s});for(const e of this.paws)e.position.y=-.66,e.scale.set(.17,.1,.15)}shake(t){this.shakeAt=t}frame(t,s){const e=(t-this.start)/1e3,o=s.motion,i=!!s.reduced,a=o==="sleep",w=o==="idle"&&this.shown!=="dizzy",u=!a&&this.shown==="dizzy",b=this.shown==="sad",p=this.shown==="angry",c=(d,g)=>i?0:Math.sin(e*d)*g,f=o==="work"||o==="think",v=.55+(w?s.lookX*.18:0)+(o==="busy"?c(9,.12):0)+(u?c(2.1,.1):0),P=(f?.14:w?s.lookY*.08:0)+(a?.16:0)+(b?.1:0)+(p?.06:0),x=(u?c(3.2,.07):0)+(o==="think"?c(1.3,.025):0)+(o==="busy"?c(9,.05):0);this.yaw+=(v-this.yaw)*.07,this.pitch+=(P-this.pitch)*.1,this.root.rotation.y=this.yaw,this.head.rotation.x=this.pitch,this.head.rotation.z+=(x-this.head.rotation.z)*.2;const z=i?0:o==="work"?Math.sin(e*(s.fast?20:14)):o==="think"?Math.sin(e*4.5)*.45:0,l=Math.max(0,z),h=Math.max(0,-z),M=u?0:w?s.lookX*.6:o==="work"?i?0:l>h?-.6:.6:o==="think"?c(.9,.5):o==="busy"?c(9,.5):0,y=u?0:w?-s.lookY*.7:f?-1:a?-.3:0;this.lookX+=(M-this.lookX)*.2,this.lookY+=(y-this.lookY)*.15;const k=Math.max(-.2,Math.min(.2,(v-this.yaw)*.6));this.eyes.position.x=.12+k+this.lookX*.06,this.eyes.position.y=.04+this.lookY*.09-(b?.03:0)-(p?.015:0);const m=!a&&(this.shown==="normal"||b||p);o!=="static"&&m&&t-this.start>this.blinkAt&&t-this.blinkStart>400&&(this.blinkStart=t,this.blinkAt=t-this.start+2200+Math.random()*3200),s.mood!==this.shown&&t-this.blinkStart>400&&(this.blinkStart=t);const S=(t-this.blinkStart)/160;s.mood!==this.shown&&S>=.5&&this.show(s.mood);for(const d of this.parts)d.pill.visible=a||this.shown==="normal"||b||p,d.arc.visible=!a&&this.shown==="happy",d.spiral.visible=!a&&this.shown==="dizzy";const G=a?.1:S>=0&&S<=1?1-.92*Math.sin(Math.PI*S):1,I=a?0:b?.32:p?-.38:0;this.parts.forEach((d,g)=>{d.group.scale.y=G*(p&&!a?.78:1),d.group.rotation.z+=((g?I:-I)-d.group.rotation.z)*.15,i||(d.spiral.rotation.z+=.14)}),this.paws.forEach((d,g)=>{const Y=g?h:l;d.position.y=-.66-.06*Y,d.scale.set(.17*(1+.25*Y),.1*(1-.3*Y),.15*(1+.25*Y))}),this.head.position.y=(o==="static"?0:a?c(1.2,.02)-.02:c(2,.01))-.03*(l+h);const A=(t-this.shakeAt)/600;this.root.position.x=!i&&A>=0&&A<1?Math.sin(A*Math.PI*6)*.06*(1-A):0}dispose(){for(const t of this.disposables)t.dispose()}}export{D as CatFigure,L as configureRenderer,q as createStage,W as frameCamera};