@goodfish/jarvy 0.2.0 → 0.4.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.
@@ -0,0 +1 @@
1
+ var Q=Object.defineProperty;var U=(a,t,e)=>t in a?Q(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var h=(a,t,e)=>U(a,typeof t!="symbol"?t+"":t,e);function D(a,t,e,o){const s=new a.Shape,i=-t/2,r=-e/2;return s.moveTo(i+o,r),s.lineTo(i+t-o,r),s.quadraticCurveTo(i+t,r,i+t,r+o),s.lineTo(i+t,r+e-o),s.quadraticCurveTo(i+t,r+e,i+t-o,r+e),s.lineTo(i+o,r+e),s.quadraticCurveTo(i,r+e,i,r+e-o),s.lineTo(i,r+o),s.quadraticCurveTo(i,r,i+o,r),s}function $(a){a.ColorManagement.enabled=!1;const t=new a.Scene,e=new a.PerspectiveCamera(35,1,.1,50);t.add(new a.HemisphereLight(16777215,7828845,.8*Math.PI));const o=new a.DirectionalLight(16777215,.85*Math.PI);o.position.set(-1.6,3.6,1.8),o.castShadow=!0,o.shadow.mapSize.set(1024,1024),o.shadow.bias=-5e-4,o.shadow.normalBias=.02,Object.assign(o.shadow.camera,{left:-2,right:2,top:2,bottom:-2,near:.5,far:10}),t.add(o);const s=new a.DirectionalLight(16777215,.35*Math.PI);s.position.set(2,1,4),t.add(s);const i=new a.Mesh(new a.PlaneGeometry(8,8),new a.ShadowMaterial({opacity:.32}));return i.rotation.x=-Math.PI/2,i.position.y=-.78,i.receiveShadow=!0,t.add(i),{scene:t,camera:e,ground:i}}function T(a,t){t.outputColorSpace=a.LinearSRGBColorSpace,t.shadowMap.enabled=!0,t.shadowMap.type=a.PCFShadowMap}function R(a,t,e=3.5){a.aspect=t,a.position.set(0,.5,Math.max(e,e*1.15/t*.9)),a.lookAt(0,-.02,0),a.updateProjectionMatrix()}class H{constructor(t,e){h(this,"root");h(this,"head");h(this,"eyes");h(this,"body");h(this,"parts");h(this,"paws");h(this,"paper");h(this,"mouth");h(this,"motion","static");h(this,"motionAt",0);h(this,"disposables",[]);h(this,"shown","normal");h(this,"yaw",.55);h(this,"pitch",0);h(this,"lookX",0);h(this,"lookY",0);h(this,"drawn",!1);h(this,"blinkAt",1500);h(this,"blinkStart",-1e9);h(this,"shakeAt",-1e9);h(this,"start",performance.now());const o=w=>(this.disposables.push(w),w);this.body=o(new t.MeshStandardMaterial({color:e,roughness:.55,metalness:0}));const s=o(new t.MeshBasicMaterial({color:2302495}));this.root=new t.Group,this.head=new t.Group,this.root.add(this.head);const i=o(new t.ExtrudeGeometry(D(t,1.2,.86,.2),{depth:.5,bevelEnabled:!0,bevelSize:.1,bevelThickness:.1,bevelSegments:6,curveSegments:14}));i.center();const r=new t.Mesh(i,this.body);r.castShadow=!0,r.receiveShadow=!0,this.head.add(r);const p=new t.Shape;p.moveTo(-.14,0),p.lineTo(.14,0),p.lineTo(0,.34),p.closePath();const u=o(new t.ExtrudeGeometry(p,{depth:.1,bevelEnabled:!0,bevelSize:.03,bevelThickness:.03,bevelSegments:3}));u.translate(0,0,-.05);for(const w of[-1,1]){const n=new t.Mesh(u,this.body);n.castShadow=!0,n.position.set(w*.42,.44,.04),n.rotation.z=-w*.2,this.head.add(n)}this.eyes=new t.Group,this.eyes.position.set(.12,.04,.352),this.head.add(this.eyes);const d=o(new t.ExtrudeGeometry(D(t,.08,.22,.04),{depth:.012,bevelEnabled:!1})),S=Math.PI*.85,m=.085,f=o(new t.TorusGeometry(m,.024,8,24,S)),b=o(new t.SphereGeometry(.024,10,8)),l=Array.from({length:91},(w,n)=>{const k=n/90,M=k*Math.PI*5,g=.012+k*.085;return new t.Vector3(Math.cos(M)*g,Math.sin(M)*g,0)}),G=o(new t.TubeGeometry(new t.CatmullRomCurve3(l),120,.012,6,!1));this.parts=[-.17,.17].map(w=>{const n=new t.Group;n.position.x=w,this.eyes.add(n);const k=new t.Mesh(d,s);n.add(k);const M=new t.Group,g=new t.Mesh(f,s);g.rotation.z=Math.PI/2-S/2,M.add(g);for(const x of[Math.PI/2-S/2,Math.PI/2+S/2]){const v=new t.Mesh(b,s);v.position.set(Math.cos(x)*m,Math.sin(x)*m,0),M.add(v)}M.position.set(0,-.04,.02),n.add(M);const Y=new t.Mesh(G,s);return Y.position.z=.014,n.add(Y),{group:n,pill:k,arc:M,spiral:Y}});const z=o(new t.SphereGeometry(1,24,16));this.paws=[-.42,.42].map(w=>{const n=new t.Mesh(z,this.body);return n.castShadow=!0,n.receiveShadow=!0,n.scale.set(.17,.1,.15),n.position.set(w,-.66,.22),this.root.add(n),n}),this.paper=new t.Mesh(o(new t.BoxGeometry(.62,.44,.012)),o(new t.MeshStandardMaterial({color:16184298,roughness:.9}))),this.paper.position.set(0,-.36,.62),this.paper.rotation.x=-.55,this.paper.castShadow=!0,this.paper.visible=!1,this.root.add(this.paper),this.mouth=new t.Mesh(o(new t.CircleGeometry(.07,20)),s),this.mouth.position.set(.12,-.2,.364),this.mouth.visible=!1,this.head.add(this.mouth),this.root.rotation.y=.55,this.show("normal")}setColor(t){this.body.color.setHex(t)}show(t){this.shown=t;for(const e of this.parts)e.pill.visible=t==="normal"||t==="sad"||t==="angry",e.arc.visible=t==="happy",e.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 e=t==="sad"?.32:t==="angry"?-.38:0;this.parts.forEach((o,s)=>{o.group.scale.y=t==="angry"?.78:1,o.group.rotation.z=s?e:-e});for(const o of this.paws)o.position.y=-.66,o.scale.set(.17,.1,.15)}shake(t){this.shakeAt=t}frame(t,e){const o=(t-this.start)/1e3,s=e.motion,i=!!e.reduced;s!==this.motion&&(this.motion=s,this.motionAt=t);const r=(t-this.motionAt)/1e3,p=s==="yawn"?Math.sin(Math.PI*Math.min(1,r%3.2/1.8)):0,u=s==="stretch"?Math.sin(Math.PI*Math.min(1,r%3.6/1.8)):0,d=s==="sleep",S=s==="idle"&&this.shown!=="dizzy",m=!d&&this.shown==="dizzy",f=this.shown==="sad",b=this.shown==="angry",l=(c,y)=>i?0:Math.sin(o*c)*y,G=s==="work"||s==="think",z=e.faceX??1,w=(s==="turn"?.05:s==="ask"?.14:s==="read"?.55*.6:.55)*z,n=s==="idle"||s==="static"?1:d?.25:.45,k=m?0:e.lookX*.22*n,M=m?0:e.lookY*.1*n,g=w+k+(s==="busy"?l(9,.12):0)+(m?l(2.1,.1):0),Y=(G?.14:0)+M+(d?.16:0)+(f?.1:0)+(b?.06:0)+(s==="read"?.24+l(.7,.02):0)+(s==="groom"?.1:0)-.2*p-.14*u,x=(m?l(3.2,.07):0)+(s==="think"?l(1.3,.025):0)+(s==="busy"?l(9,.05):0)+(s==="ask"?.24+l(1.1,.03):0)+(s==="groom"?-.14:0)+(s==="turn"?l(2.4,.03):0),v=(c,y,A)=>this.drawn?c+(y-c)*A:y;this.yaw=v(this.yaw,g,.07),this.pitch=v(this.pitch,Y,.1),this.root.rotation.y=this.yaw,this.head.rotation.x=this.pitch,this.head.rotation.z+=(x-this.head.rotation.z)*.2;const q=i?0:s==="work"?Math.sin(o*(e.fast?20:14)):s==="think"?Math.sin(o*4.5)*.45:0,C=Math.max(0,q),_=Math.max(0,-q),j=m?0:e.lookX*(S?.6:.45*n),F=m?0:e.lookY*(S?-.55:.4*n),O=j||(s==="work"?i?0:C>_?-.6:.6:s==="think"?l(.9,.5):s==="busy"?l(9,.5):s==="read"?i?0:r*.8%1*1.2-.6:0),V=F||(G||s==="read"?-1:d?-.3:0);this.lookX=v(this.lookX,O,.2),this.lookY=v(this.lookY,V,.15),this.drawn=!0;const L=Math.max(-.2,Math.min(.2,(g-this.yaw)*.6));this.eyes.position.x=.12*z+L+this.lookX*.06,this.eyes.position.y=.04+this.lookY*.09-(f?.03:0)-(b?.015:0);const J=!d&&(this.shown==="normal"||f||b);s!=="static"&&J&&t-this.start>this.blinkAt&&t-this.blinkStart>400&&(this.blinkStart=t,this.blinkAt=t-this.start+2200+Math.random()*3200),e.mood!==this.shown&&t-this.blinkStart>400&&(this.blinkStart=t);const I=(t-this.blinkStart)/160;e.mood!==this.shown&&I>=.5&&this.show(e.mood);for(const c of this.parts)c.pill.visible=d||this.shown==="normal"||f||b,c.arc.visible=!d&&this.shown==="happy",c.spiral.visible=!d&&this.shown==="dizzy";const K=Math.max(p,u*.9,s==="groom"?.9:0),N=(d?.1:I>=0&&I<=1?1-.92*Math.sin(Math.PI*I):1)*(1-.88*K),W=d?0:f?.32:b?-.38:0;this.parts.forEach((c,y)=>{c.group.scale.y=N*(b&&!d?.78:1),c.group.rotation.z+=((y?W:-W)-c.group.rotation.z)*.15,i||(c.spiral.rotation.z+=.14)}),this.paws.forEach((c,y)=>{const A=y?_:C,B=y?1:-1,X=s==="read"?[B*.3,-.44+l(.7,.01),.6]:s==="stretch"?[B*(.42+.2*u),-.66+.62*u,.22-.1*u]:s==="groom"&&y?[.2,-.2+l(7,.035),.5]:s==="turn"&&y?[.4,-.52+l(3,.05),.32]:[B*.42,-.66-.06*A,.22];c.position.x+=(X[0]-c.position.x)*.2,c.position.y+=(X[1]-c.position.y)*.2,c.position.z+=(X[2]-c.position.z)*.2,c.scale.set(.17*(1+.25*A),.1*(1-.3*A),.15*(1+.25*A))}),this.paper.visible=s==="read",this.mouth.visible=p>.05,this.mouth.position.x=.12*z+L,this.mouth.scale.set(.8+.3*p,.2+1.3*p,1),this.root.scale.y=1+.05*u,this.head.position.y=(s==="static"?0:d?l(1.2,.02)-.02:l(2,.01))-.03*(C+_)+.04*p+.06*u;const P=(t-this.shakeAt)/600;this.root.position.x=!i&&P>=0&&P<1?Math.sin(P*Math.PI*6)*.06*(1-P):0}dispose(){for(const t of this.disposables)t.dispose()}}export{H as CatFigure,T as configureRenderer,$ as createStage,R as frameCamera};