@doki-land/live2d 0.0.1 → 0.0.3

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.
package/dist/l2d.umd.js CHANGED
@@ -1204,5 +1204,5 @@ void main(void)\r
1204
1204
  [Details] render texture count : {1}, mask count : {2}`,t-r,this._renderTextureCount,t);for(let I=0;I<x;I++){const B=this._clippingContextListForMask[b++];B._layoutChannelNo=0,B._layoutBounds.x=0,B._layoutBounds.y=0,B._layoutBounds.width=1,B._layoutBounds.height=1,B._bufferIndex=0}}}}getColorBuffer(){return this._maskColorBuffers}getClippingContextListForDraw(){return this._clippingContextListForDraw}getClippingMaskCount(){return this._clippingContextListForMask.length}setClippingMaskBufferSize(t){this._clippingMaskBufferSize=t}getClippingMaskBufferSize(){return this._clippingMaskBufferSize}getRenderTextureCount(){return this._renderTextureCount}}class B1{constructor(t,r){this.frameNo=t,this.textures=r}}class O1{constructor(t,r,i){this._isUsing=!1,this._owner=t,this._clippingIdList=r,this._clippingIdCount=i,this._allClippedDrawRect=new Au,this._layoutBounds=new Au,this._clippedDrawableIndexList=[],this._matrixForMask=new mi,this._matrixForDraw=new mi,this._bufferIndex=0}release(){const t=this;t._layoutBounds=void 0,t._allClippedDrawRect=void 0,t._clippedDrawableIndexList=void 0}addClippedDrawable(t){this._clippedDrawableIndexList.push(t)}getClippingManager(){return this._owner}setGl(t){this._owner.setGL(t)}}class N1{setGlEnable(t,r){r?this.gl.enable(t):this.gl.disable(t)}setGlEnableVertexAttribArray(t,r){r?this.gl.enableVertexAttribArray(t):this.gl.disableVertexAttribArray(t)}save(){if(this.gl==null){Ki(`'gl' is null. WebGLRenderingContext is required.
1205
1205
  Please call 'CubimRenderer_WebGL.startUp' function.`);return}this._lastArrayBufferBinding=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING),this._lastArrayBufferBinding=this.gl.getParameter(this.gl.ELEMENT_ARRAY_BUFFER_BINDING),this._lastProgram=this.gl.getParameter(this.gl.CURRENT_PROGRAM),this._lastActiveTexture=this.gl.getParameter(this.gl.ACTIVE_TEXTURE),this.gl.activeTexture(this.gl.TEXTURE1),this._lastTexture1Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this.gl.activeTexture(this.gl.TEXTURE0),this._lastTexture0Binding2D=this.gl.getParameter(this.gl.TEXTURE_BINDING_2D),this._lastVertexAttribArrayEnabled[0]=this.gl.getVertexAttrib(0,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[1]=this.gl.getVertexAttrib(1,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[2]=this.gl.getVertexAttrib(2,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastVertexAttribArrayEnabled[3]=this.gl.getVertexAttrib(3,this.gl.VERTEX_ATTRIB_ARRAY_ENABLED),this._lastScissorTest=this.gl.isEnabled(this.gl.SCISSOR_TEST),this._lastStencilTest=this.gl.isEnabled(this.gl.STENCIL_TEST),this._lastDepthTest=this.gl.isEnabled(this.gl.DEPTH_TEST),this._lastCullFace=this.gl.isEnabled(this.gl.CULL_FACE),this._lastBlend=this.gl.isEnabled(this.gl.BLEND),this._lastFrontFace=this.gl.getParameter(this.gl.FRONT_FACE),this._lastColorMask=this.gl.getParameter(this.gl.COLOR_WRITEMASK),this._lastBlending[0]=this.gl.getParameter(this.gl.BLEND_SRC_RGB),this._lastBlending[1]=this.gl.getParameter(this.gl.BLEND_DST_RGB),this._lastBlending[2]=this.gl.getParameter(this.gl.BLEND_SRC_ALPHA),this._lastBlending[3]=this.gl.getParameter(this.gl.BLEND_DST_ALPHA),this._lastFBO=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING),this._lastViewport=this.gl.getParameter(this.gl.VIEWPORT)}restore(){if(this.gl==null){Ki(`'gl' is null. WebGLRenderingContext is required.
1206
1206
  Please call 'CubimRenderer_WebGL.startUp' function.`);return}this.gl.useProgram(this._lastProgram),this.setGlEnableVertexAttribArray(0,this._lastVertexAttribArrayEnabled[0]),this.setGlEnableVertexAttribArray(1,this._lastVertexAttribArrayEnabled[1]),this.setGlEnableVertexAttribArray(2,this._lastVertexAttribArrayEnabled[2]),this.setGlEnableVertexAttribArray(3,this._lastVertexAttribArrayEnabled[3]),this.setGlEnable(this.gl.SCISSOR_TEST,this._lastScissorTest),this.setGlEnable(this.gl.STENCIL_TEST,this._lastStencilTest),this.setGlEnable(this.gl.DEPTH_TEST,this._lastDepthTest),this.setGlEnable(this.gl.CULL_FACE,this._lastCullFace),this.setGlEnable(this.gl.BLEND,this._lastBlend),this.gl.frontFace(this._lastFrontFace),this.gl.colorMask(this._lastColorMask[0],this._lastColorMask[1],this._lastColorMask[2],this._lastColorMask[3]),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._lastArrayBufferBinding),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._lastElementArrayBufferBinding),this.gl.activeTexture(this.gl.TEXTURE1),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture1Binding2D),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,this._lastTexture0Binding2D),this.gl.activeTexture(this._lastActiveTexture),this.gl.blendFuncSeparate(this._lastBlending[0],this._lastBlending[1],this._lastBlending[2],this._lastBlending[3])}setGl(t){this.gl=t}constructor(){this._lastVertexAttribArrayEnabled=new Array(4),this._lastColorMask=new Array(4),this._lastBlending=new Array(4),this._lastViewport=new Array(4)}}class xn{static getInstance(){return Zs==null&&(Zs=new xn),Zs}static deleteInstance(){Zs&&(Zs.release(),Zs=void 0)}constructor(){this._shaderSets=[]}release(){this.releaseShaderProgram()}setupShaderProgram(t,r,i,n,o,h,c,b,T,C,x,$,I,B,U){I||Ki("NoPremultipliedAlpha is not allowed"),this._shaderSets.length==0&&this.generateShaders();let G,z,J,Z;const it=t.getClippingContextBufferForMask();if(it!=null){const Q=this._shaderSets[0];this.gl.useProgram(Q.shaderProgram),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(Q.samplerTexture0Location,0),c.vertex==null&&(c.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,c.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(Q.attributePositionLocation),this.gl.vertexAttribPointer(Q.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),c.uv==null&&(c.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,c.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,h,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(Q.attributeTexCoordLocation),this.gl.vertexAttribPointer(Q.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0);const _t=it._layoutChannelNo,et=it.getClippingManager().getChannelFlagAsColor(_t);this.gl.uniform4f(Q.uniformChannelFlagLocation,et.R,et.G,et.B,et.A),this.gl.uniformMatrix4fv(Q.uniformClipMatrixLocation,!1,it._matrixForMask.getArray());const ft=it._layoutBounds;this.gl.uniform4f(Q.uniformBaseColorLocation,ft.x*2-1,ft.y*2-1,ft.getRight()*2-1,ft.getBottom()*2-1),this.gl.uniform4f(Q.uniformMultiplyColorLocation,x.R,x.G,x.B,x.A),this.gl.uniform4f(Q.uniformScreenColorLocation,$.R,$.G,$.B,$.A),G=this.gl.ZERO,z=this.gl.ONE_MINUS_SRC_COLOR,J=this.gl.ZERO,Z=this.gl.ONE_MINUS_SRC_ALPHA}else{const Q=t.getClippingContextBufferForDraw(),et=Q!=null?U?2:1:0;let ft;switch(T){case gs.CubismBlendMode_Normal:default:ft=this._shaderSets[1+et],G=this.gl.ONE,z=this.gl.ONE_MINUS_SRC_ALPHA,J=this.gl.ONE,Z=this.gl.ONE_MINUS_SRC_ALPHA;break;case gs.CubismBlendMode_Additive:ft=this._shaderSets[4+et],G=this.gl.ONE,z=this.gl.ONE,J=this.gl.ZERO,Z=this.gl.ONE;break;case gs.CubismBlendMode_Multiplicative:ft=this._shaderSets[7+et],G=this.gl.DST_COLOR,z=this.gl.ONE_MINUS_SRC_ALPHA,J=this.gl.ZERO,Z=this.gl.ONE;break}if(this.gl.useProgram(ft.shaderProgram),c.vertex==null&&(c.vertex=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,c.vertex),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(ft.attributePositionLocation),this.gl.vertexAttribPointer(ft.attributePositionLocation,2,this.gl.FLOAT,!1,0,0),c.uv==null&&(c.uv=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,c.uv),this.gl.bufferData(this.gl.ARRAY_BUFFER,h,this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(ft.attributeTexCoordLocation),this.gl.vertexAttribPointer(ft.attributeTexCoordLocation,2,this.gl.FLOAT,!1,0,0),Q!=null){this.gl.activeTexture(this.gl.TEXTURE1);const wt=Q.getClippingManager().getColorBuffer()[t.getClippingContextBufferForDraw()._bufferIndex];this.gl.bindTexture(this.gl.TEXTURE_2D,wt),this.gl.uniform1i(ft.samplerTexture1Location,1),this.gl.uniformMatrix4fv(ft.uniformClipMatrixLocation,!1,Q._matrixForDraw.getArray());const Dt=Q._layoutChannelNo,Rt=Q.getClippingManager().getChannelFlagAsColor(Dt);this.gl.uniform4f(ft.uniformChannelFlagLocation,Rt.R,Rt.G,Rt.B,Rt.A)}this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,r),this.gl.uniform1i(ft.samplerTexture0Location,0),this.gl.uniformMatrix4fv(ft.uniformMatrixLocation,!1,B.getArray()),this.gl.uniform4f(ft.uniformBaseColorLocation,C.R,C.G,C.B,C.A),this.gl.uniform4f(ft.uniformMultiplyColorLocation,x.R,x.G,x.B,x.A),this.gl.uniform4f(ft.uniformScreenColorLocation,$.R,$.G,$.B,$.A)}c.index==null&&(c.index=this.gl.createBuffer()),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,c.index),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,o,this.gl.DYNAMIC_DRAW),this.gl.blendFuncSeparate(G,z,J,Z)}releaseShaderProgram(){for(let t=0;t<this._shaderSets.length;t++)this.gl.deleteProgram(this._shaderSets[t].shaderProgram),this._shaderSets[t].shaderProgram=0;this._shaderSets=[]}generateShaders(){for(let t=0;t<k1;t++)this._shaderSets.push({});this._shaderSets[0].shaderProgram=this.loadShaderProgram(U1,G1),this._shaderSets[1].shaderProgram=this.loadShaderProgram(V1,X1),this._shaderSets[2].shaderProgram=this.loadShaderProgram(n2,z1),this._shaderSets[3].shaderProgram=this.loadShaderProgram(n2,W1),this._shaderSets[4].shaderProgram=this._shaderSets[1].shaderProgram,this._shaderSets[5].shaderProgram=this._shaderSets[2].shaderProgram,this._shaderSets[6].shaderProgram=this._shaderSets[3].shaderProgram,this._shaderSets[7].shaderProgram=this._shaderSets[1].shaderProgram,this._shaderSets[8].shaderProgram=this._shaderSets[2].shaderProgram,this._shaderSets[9].shaderProgram=this._shaderSets[3].shaderProgram,this._shaderSets[0].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[0].shaderProgram,"a_position"),this._shaderSets[0].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[0].shaderProgram,"a_texCoord"),this._shaderSets[0].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"s_texture0"),this._shaderSets[0].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_clipMatrix"),this._shaderSets[0].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_channelFlag"),this._shaderSets[0].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_baseColor"),this._shaderSets[0].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_multiplyColor"),this._shaderSets[0].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[0].shaderProgram,"u_screenColor"),this._shaderSets[1].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[1].shaderProgram,"a_position"),this._shaderSets[1].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[1].shaderProgram,"a_texCoord"),this._shaderSets[1].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"s_texture0"),this._shaderSets[1].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_matrix"),this._shaderSets[1].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_baseColor"),this._shaderSets[1].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_multiplyColor"),this._shaderSets[1].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[1].shaderProgram,"u_screenColor"),this._shaderSets[2].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[2].shaderProgram,"a_position"),this._shaderSets[2].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[2].shaderProgram,"a_texCoord"),this._shaderSets[2].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"s_texture0"),this._shaderSets[2].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"s_texture1"),this._shaderSets[2].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_matrix"),this._shaderSets[2].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_clipMatrix"),this._shaderSets[2].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_channelFlag"),this._shaderSets[2].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_baseColor"),this._shaderSets[2].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_multiplyColor"),this._shaderSets[2].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[2].shaderProgram,"u_screenColor"),this._shaderSets[3].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[3].shaderProgram,"a_position"),this._shaderSets[3].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[3].shaderProgram,"a_texCoord"),this._shaderSets[3].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"s_texture0"),this._shaderSets[3].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"s_texture1"),this._shaderSets[3].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_matrix"),this._shaderSets[3].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_clipMatrix"),this._shaderSets[3].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_channelFlag"),this._shaderSets[3].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_baseColor"),this._shaderSets[3].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_multiplyColor"),this._shaderSets[3].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[3].shaderProgram,"u_screenColor"),this._shaderSets[4].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[4].shaderProgram,"a_position"),this._shaderSets[4].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[4].shaderProgram,"a_texCoord"),this._shaderSets[4].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"s_texture0"),this._shaderSets[4].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_matrix"),this._shaderSets[4].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_baseColor"),this._shaderSets[4].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_multiplyColor"),this._shaderSets[4].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[4].shaderProgram,"u_screenColor"),this._shaderSets[5].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[5].shaderProgram,"a_position"),this._shaderSets[5].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[5].shaderProgram,"a_texCoord"),this._shaderSets[5].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"s_texture0"),this._shaderSets[5].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"s_texture1"),this._shaderSets[5].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_matrix"),this._shaderSets[5].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_clipMatrix"),this._shaderSets[5].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_channelFlag"),this._shaderSets[5].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_baseColor"),this._shaderSets[5].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_multiplyColor"),this._shaderSets[5].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[5].shaderProgram,"u_screenColor"),this._shaderSets[6].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[6].shaderProgram,"a_position"),this._shaderSets[6].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[6].shaderProgram,"a_texCoord"),this._shaderSets[6].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"s_texture0"),this._shaderSets[6].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"s_texture1"),this._shaderSets[6].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_matrix"),this._shaderSets[6].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_clipMatrix"),this._shaderSets[6].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_channelFlag"),this._shaderSets[6].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_baseColor"),this._shaderSets[6].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_multiplyColor"),this._shaderSets[6].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[6].shaderProgram,"u_screenColor"),this._shaderSets[7].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[7].shaderProgram,"a_position"),this._shaderSets[7].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[7].shaderProgram,"a_texCoord"),this._shaderSets[7].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"s_texture0"),this._shaderSets[7].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_matrix"),this._shaderSets[7].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_baseColor"),this._shaderSets[7].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_multiplyColor"),this._shaderSets[7].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[7].shaderProgram,"u_screenColor"),this._shaderSets[8].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[8].shaderProgram,"a_position"),this._shaderSets[8].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[8].shaderProgram,"a_texCoord"),this._shaderSets[8].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"s_texture0"),this._shaderSets[8].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"s_texture1"),this._shaderSets[8].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_matrix"),this._shaderSets[8].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_clipMatrix"),this._shaderSets[8].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_channelFlag"),this._shaderSets[8].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_baseColor"),this._shaderSets[8].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_multiplyColor"),this._shaderSets[8].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[8].shaderProgram,"u_screenColor"),this._shaderSets[9].attributePositionLocation=this.gl.getAttribLocation(this._shaderSets[9].shaderProgram,"a_position"),this._shaderSets[9].attributeTexCoordLocation=this.gl.getAttribLocation(this._shaderSets[9].shaderProgram,"a_texCoord"),this._shaderSets[9].samplerTexture0Location=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"s_texture0"),this._shaderSets[9].samplerTexture1Location=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"s_texture1"),this._shaderSets[9].uniformMatrixLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_matrix"),this._shaderSets[9].uniformClipMatrixLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_clipMatrix"),this._shaderSets[9].uniformChannelFlagLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_channelFlag"),this._shaderSets[9].uniformBaseColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_baseColor"),this._shaderSets[9].uniformMultiplyColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_multiplyColor"),this._shaderSets[9].uniformScreenColorLocation=this.gl.getUniformLocation(this._shaderSets[9].shaderProgram,"u_screenColor")}loadShaderProgram(t,r){const i=this.gl.createProgram(),n=this.compileShaderSource(this.gl.VERTEX_SHADER,t);if(!n)return Ki("Vertex shader compile error!"),0;const o=this.compileShaderSource(this.gl.FRAGMENT_SHADER,r);return o?(this.gl.attachShader(i,n),this.gl.attachShader(i,o),this.gl.linkProgram(i),this.gl.getProgramParameter(i,this.gl.LINK_STATUS)?(this.gl.deleteShader(n),this.gl.deleteShader(o),i):(Ki("Failed to link program: {0}",i),this.gl.deleteShader(n),this.gl.deleteShader(o),i&&this.gl.deleteProgram(i),0)):(Ki("Vertex shader compile error!"),0)}compileShaderSource(t,r){const i=r,n=this.gl.createShader(t);if(this.gl.shaderSource(n,i),this.gl.compileShader(n),!n){const h=this.gl.getShaderInfoLog(n);Ki("Shader compile log: {0} ",h)}return this.gl.getShaderParameter(n,this.gl.COMPILE_STATUS)?n:(this.gl.deleteShader(n),null)}setGl(t){this.gl=t}}const U1="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_myPos;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_clipMatrix * a_position; v_myPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",G1="precision mediump float;varying vec2 v_texCoord;varying vec4 v_myPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;void main(){ float isInside = step(u_baseColor.x, v_myPos.x/v_myPos.w) * step(u_baseColor.y, v_myPos.y/v_myPos.w) * step(v_myPos.x/v_myPos.w, u_baseColor.z) * step(v_myPos.y/v_myPos.w, u_baseColor.w); gl_FragColor = u_channelFlag * texture2D(s_texture0, v_texCoord).a * isInside;}",V1="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;uniform mat4 u_matrix;void main(){ gl_Position = u_matrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",n2="attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform mat4 u_matrix;uniform mat4 u_clipMatrix;void main(){ gl_Position = u_matrix * a_position; v_clipPos = u_clipMatrix * a_position; v_texCoord = a_texCoord; v_texCoord.y = 1.0 - v_texCoord.y;}",X1="precision mediump float;varying vec2 v_texCoord;uniform vec4 u_baseColor;uniform sampler2D s_texture0;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 color = texColor * u_baseColor; gl_FragColor = vec4(color.rgb, color.a);}",z1="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform vec4 u_baseColor;uniform vec4 u_channelFlag;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * maskVal; gl_FragColor = col_formask;}",W1="precision mediump float;varying vec2 v_texCoord;varying vec4 v_clipPos;uniform sampler2D s_texture0;uniform sampler2D s_texture1;uniform vec4 u_channelFlag;uniform vec4 u_baseColor;uniform vec4 u_multiplyColor;uniform vec4 u_screenColor;void main(){ vec4 texColor = texture2D(s_texture0, v_texCoord); texColor.rgb = texColor.rgb * u_multiplyColor.rgb; texColor.rgb = (texColor.rgb + u_screenColor.rgb * texColor.a) - (texColor.rgb * u_screenColor.rgb); vec4 col_formask = texColor * u_baseColor; vec4 clipMask = (1.0 - texture2D(s_texture1, v_clipPos.xy / v_clipPos.w)) * u_channelFlag; float maskVal = clipMask.r + clipMask.g + clipMask.b + clipMask.a; col_formask = col_formask * (1.0 - maskVal); gl_FragColor = col_formask;}";class o2 extends gu{initialize(t,r=1){t.isUsingMasking()&&(this._clippingManager=new s2,this._clippingManager.initialize(t,t.getDrawableCount(),t.getDrawableMasks(),t.getDrawableMaskCounts(),r));for(let i=t.getDrawableCount()-1;i>=0;i--)this._sortedDrawableIndexList[i]=0;super.initialize(t)}bindTexture(t,r){this._textures[t]=r}getBindedTextures(){return this._textures}setClippingMaskBufferSize(t){if(!this._model.isUsingMasking())return;const r=this._clippingManager.getRenderTextureCount();this._clippingManager.release(),this._clippingManager=new s2,this._clippingManager.setClippingMaskBufferSize(t),this._clippingManager.initialize(this.getModel(),this.getModel().getDrawableCount(),this.getModel().getDrawableMasks(),this.getModel().getDrawableMaskCounts(),r)}getClippingMaskBufferSize(){return this._model.isUsingMasking()?this._clippingManager.getClippingMaskBufferSize():-1}getRenderTextureCount(){return this._model.isUsingMasking()?this._clippingManager.getRenderTextureCount():-1}constructor(){super(),this._clippingContextBufferForMask=null,this._clippingContextBufferForDraw=null,this._rendererProfile=new N1,this.firstDraw=!0,this._textures={},this._sortedDrawableIndexList=[],this._bufferData={vertex:null,uv:null,index:null}}release(){var t,r,i;const n=this;this._clippingManager.release(),n._clippingManager=void 0,(t=this.gl)==null||t.deleteBuffer(this._bufferData.vertex),this._bufferData.vertex=null,(r=this.gl)==null||r.deleteBuffer(this._bufferData.uv),this._bufferData.uv=null,(i=this.gl)==null||i.deleteBuffer(this._bufferData.index),this._bufferData.index=null,n._bufferData=void 0,n._textures=void 0}doDrawModel(){if(this.gl==null){Ki(`'gl' is null. WebGLRenderingContext is required.
1207
- Please call 'CubimRenderer_WebGL.startUp' function.`);return}this._clippingManager!=null&&(this.preDraw(),this._clippingManager.setupClippingContext(this.getModel(),this)),this.preDraw();const t=this.getModel().getDrawableCount(),r=this.getModel().getDrawableRenderOrders();for(let i=0;i<t;++i){const n=r[i];this._sortedDrawableIndexList[n]=i}for(let i=0;i<t;++i){const n=this._sortedDrawableIndexList[i];if(!this.getModel().getDrawableDynamicFlagIsVisible(n))continue;const o=this._clippingManager!=null?this._clippingManager.getClippingContextListForDraw()[n]:null;if(o!=null&&this.isUsingHighPrecisionMask()){o._isUsing&&(this.gl.viewport(0,0,this._clippingManager.getClippingMaskBufferSize(),this._clippingManager.getClippingMaskBufferSize()),this.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,o.getClippingManager().getMaskRenderTexture()[o._bufferIndex]),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{const h=o._clippingIdCount;for(let c=0;c<h;c++){const b=o._clippingIdList[c];this._model.getDrawableDynamicFlagVertexPositionsDidChange(b)&&(this.setIsCulling(this._model.getDrawableCulling(b)!=!1),this.setClippingContextBufferForMask(o),this.drawMesh(this.getModel().getDrawableTextureIndex(b),this.getModel().getDrawableVertexIndexCount(b),this.getModel().getDrawableVertexCount(b),this.getModel().getDrawableVertexIndices(b),this.getModel().getDrawableVertices(b),this.getModel().getDrawableVertexUvs(b),this.getModel().getMultiplyColor(b),this.getModel().getScreenColor(b),this.getModel().getDrawableOpacity(b),gs.CubismBlendMode_Normal,!1))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,Na),this.setClippingContextBufferForMask(null),this.gl.viewport(ms[0],ms[1],ms[2],ms[3]),this.preDraw()}this.setClippingContextBufferForDraw(o),this.setIsCulling(this.getModel().getDrawableCulling(n)),this.drawMesh(this.getModel().getDrawableTextureIndex(n),this.getModel().getDrawableVertexIndexCount(n),this.getModel().getDrawableVertexCount(n),this.getModel().getDrawableVertexIndices(n),this.getModel().getDrawableVertices(n),this.getModel().getDrawableVertexUvs(n),this.getModel().getMultiplyColor(n),this.getModel().getScreenColor(n),this.getModel().getDrawableOpacity(n),this.getModel().getDrawableBlendMode(n),this.getModel().getDrawableInvertedMaskBit(n))}}drawMesh(t,r,i,n,o,h,c,b,T,C,x){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW);const $=this.getModelColor();this.getClippingContextBufferForMask()==null&&($.A*=T,this.isPremultipliedAlpha()&&($.R*=$.A,$.G*=$.A,$.B*=$.A));let I=null;this._textures[t]!=null&&(I=this._textures[t]),xn.getInstance().setupShaderProgram(this,I,i,o,n,h,this._bufferData,T,C,$,c,b,this.isPremultipliedAlpha(),this.getMvpMatrix(),x),this.gl.drawElements(this.gl.TRIANGLES,r,this.gl.UNSIGNED_SHORT,0),this.gl.useProgram(null),this.setClippingContextBufferForDraw(null),this.setClippingContextBufferForMask(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}static doStaticRelease(){xn.deleteInstance()}setRenderState(t,r){Na=t,ms=r}preDraw(){if(this.firstDraw&&(this.firstDraw=!1),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(const t of Object.entries(this._textures))this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}setClippingContextBufferForMask(t){this._clippingContextBufferForMask=t}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDraw(t){this._clippingContextBufferForDraw=t}getClippingContextBufferForDraw(){return this._clippingContextBufferForDraw}startUp(t){this.gl=t,this._clippingManager&&this._clippingManager.setGL(t),xn.getInstance().setGl(t),this._rendererProfile.setGl(t),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic")}}gu.staticRelease=()=>{o2.doStaticRelease()};const a2=new mi;class H1 extends Id{constructor(t,r,i){super(),bt(this,"settings"),bt(this,"coreModel"),bt(this,"motionManager"),bt(this,"lipSync",!0),bt(this,"breath",bu.create()),bt(this,"eyeBlink"),bt(this,"userData"),bt(this,"renderer",new o2),bt(this,"idParamAngleX",E1),bt(this,"idParamAngleY",C1),bt(this,"idParamAngleZ",S1),bt(this,"idParamEyeBallX",P1),bt(this,"idParamEyeBallY",$1),bt(this,"idParamBodyAngleX",D1),bt(this,"idParamBreath",R1),bt(this,"idParamMouthForm",M1),bt(this,"pixelsPerUnit",1),bt(this,"centeringTransform",new nr),this.coreModel=t,this.settings=r,this.motionManager=new T1(r,i),this.init()}init(){var t;super.init(),(t=this.settings.getEyeBlinkParameters())!=null&&t.length&&(this.eyeBlink=I1.create(this.settings)),this.breath.setParameters([new yo(this.idParamAngleX,0,15,6.5345,.5),new yo(this.idParamAngleY,0,8,3.5345,.5),new yo(this.idParamAngleZ,0,10,5.5345,.5),new yo(this.idParamBodyAngleX,0,4,15.5345,.5),new yo(this.idParamBreath,0,.5,3.2345,.5)]),this.renderer.initialize(this.coreModel),this.renderer.setIsPremultipliedAlpha(!0)}getSize(){return[this.coreModel.getModel().canvasinfo.CanvasWidth,this.coreModel.getModel().canvasinfo.CanvasHeight]}getLayout(){const t={};if(this.settings.layout)for(const[r,i]of Object.entries(this.settings.layout)){const n=r.charAt(0).toLowerCase()+r.slice(1);t[n]=i}return t}setupLayout(){super.setupLayout(),this.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit,this.centeringTransform.scale(this.pixelsPerUnit,this.pixelsPerUnit).translate(this.originalWidth/2,this.originalHeight/2)}updateWebGLContext(t,r){this.renderer.firstDraw=!0,this.renderer._bufferData={vertex:null,uv:null,index:null},this.renderer.startUp(t),this.renderer._clippingManager._currentFrameNo=r,this.renderer._clippingManager._maskTexture=void 0,xn.getInstance()._shaderSets=[]}bindTexture(t,r){this.renderer.bindTexture(t,r)}getHitAreaDefs(){var t,r;return(r=(t=this.settings.hitAreas)==null?void 0:t.map(i=>({id:i.Id,name:i.Name,index:this.coreModel.getDrawableIndex(i.Id)})))!=null?r:[]}getDrawableIDs(){return this.coreModel.getDrawableIds()}getDrawableIndex(t){return this.coreModel.getDrawableIndex(t)}getDrawableVertices(t){if(typeof t=="string"&&(t=this.coreModel.getDrawableIndex(t),t===-1))throw new TypeError("Unable to find drawable ID: "+t);const r=this.coreModel.getDrawableVertices(t).slice();for(let i=0;i<r.length;i+=2)r[i]=r[i]*this.pixelsPerUnit+this.originalWidth/2,r[i+1]=-r[i+1]*this.pixelsPerUnit+this.originalHeight/2;return r}updateTransform(t){this.drawingMatrix.copyFrom(this.centeringTransform).prepend(this.localTransform).prepend(t)}update(t,r){var i,n,o,h;super.update(t,r),t/=1e3,r/=1e3;const c=this.coreModel;this.emit("beforeMotionUpdate");const b=this.motionManager.update(this.coreModel,r);if(this.emit("afterMotionUpdate"),c.saveParameters(),(i=this.motionManager.expressionManager)==null||i.update(c,r),b||(n=this.eyeBlink)==null||n.updateParameters(c,t),this.updateFocus(),this.updateNaturalMovements(t*1e3,r*1e3),this.lipSync&&this.motionManager.currentAudio){let T=this.motionManager.mouthSync(),C=0;const x=1,$=1.2;T>0&&(C=.4),T=pn(T*$,C,x);for(let I=0;I<this.motionManager.lipSyncIds.length;++I)c.addParameterValueById(this.motionManager.lipSyncIds[I],T,.8)}(o=this.physics)==null||o.evaluate(c,t),(h=this.pose)==null||h.updateParameters(c,t),this.emit("beforeModelUpdate"),c.update(),c.loadParameters()}updateFocus(){this.coreModel.addParameterValueById(this.idParamEyeBallX,this.focusController.x),this.coreModel.addParameterValueById(this.idParamEyeBallY,this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleX,this.focusController.x*30),this.coreModel.addParameterValueById(this.idParamAngleY,this.focusController.y*30),this.coreModel.addParameterValueById(this.idParamAngleZ,this.focusController.x*this.focusController.y*-30),this.coreModel.addParameterValueById(this.idParamBodyAngleX,this.focusController.x*10)}updateFacialEmotion(t){this.coreModel.addParameterValueById(this.idParamMouthForm,t)}updateNaturalMovements(t,r){var i;(i=this.breath)==null||i.updateParameters(this.coreModel,t/1e3)}draw(t){const r=this.drawingMatrix,i=a2.getArray();i[0]=r.a,i[1]=r.b,i[4]=-r.c,i[5]=-r.d,i[12]=r.tx,i[13]=r.ty,this.renderer.setMvpMatrix(a2),this.renderer.setRenderState(t.getParameter(t.FRAMEBUFFER_BINDING),this.viewport),this.renderer.drawModel()}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}}class h2{constructor(t){this.groups=t.Groups,this.hitAreas=t.HitAreas,this.layout=t.Layout,this.moc=t.FileReferences.Moc,this.expressions=t.FileReferences.Expressions,this.motions=t.FileReferences.Motions,this.textures=t.FileReferences.Textures,this.physics=t.FileReferences.Physics,this.pose=t.FileReferences.Pose}getEyeBlinkParameters(){var t,r;return(r=(t=this.groups)==null?void 0:t.find(i=>i.Name==="EyeBlink"))==null?void 0:r.Ids}getLipSyncParameters(){var t,r;return(r=(t=this.groups)==null?void 0:t.find(i=>i.Name==="LipSync"))==null?void 0:r.Ids}}class bn extends Ia{constructor(t){if(super(t),bt(this,"moc"),bt(this,"textures"),!bn.isValidJSON(t))throw new TypeError("Invalid JSON.");Object.assign(this,new h2(t))}static isValidJSON(t){var r;return!!(t!=null&&t.FileReferences)&&typeof t.FileReferences.Moc=="string"&&((r=t.FileReferences.Textures)==null?void 0:r.length)>0&&t.FileReferences.Textures.every(i=>typeof i=="string")}replaceFiles(t){if(super.replaceFiles(t),this.motions)for(const[r,i]of Object.entries(this.motions))for(let n=0;n<i.length;n++)i[n].File=t(i[n].File,`motions.${r}[${n}].File`),i[n].Sound!==void 0&&(i[n].Sound=t(i[n].Sound,`motions.${r}[${n}].Sound`));if(this.expressions)for(let r=0;r<this.expressions.length;r++)this.expressions[r].File=t(this.expressions[r].File,`expressions[${r}].File`)}}Lm(bn,[h2]);let Ua,l2=20;function Y1(){return go.isStarted()?Promise.resolve():(Ua??(Ua=new Promise((s,t)=>{function r(){try{j1(),s()}catch(i){if(l2--,l2<0){const n=new Error("Failed to start up Cubism 4 framework.");n.cause=i,t(n);return}setTimeout(r,10)}}r()})),Ua)}function j1(s){s=Object.assign({logFunction:console.log,loggingLevel:yn.LogLevel_Verbose},s),go.startUp(s),go.initialize()}const q1=.001,u2=.5;class wu{static create(t){const r=new wu;typeof t.FadeInTime=="number"&&(r._fadeTimeSeconds=t.FadeInTime,r._fadeTimeSeconds<=0&&(r._fadeTimeSeconds=u2));const i=t.Groups,n=i.length;for(let o=0;o<n;++o){const h=i[o],c=h.length;let b=0;for(let T=0;T<c;++T){const C=h[T],x=new Ga;x.partId=C.Id;const $=C.Link;if($){const I=$.length;for(let B=0;B<I;++B){const U=new Ga;U.partId=$[B],x.link.push(U)}}r._partGroups.push(x),++b}r._partGroupCounts.push(b)}return r}updateParameters(t,r){t!=this._lastModel&&this.reset(t),this._lastModel=t,r<0&&(r=0);let i=0;for(let n=0;n<this._partGroupCounts.length;n++){const o=this._partGroupCounts[n];this.doFade(t,r,i,o),i+=o}this.copyPartOpacities(t)}reset(t){let r=0;for(let i=0;i<this._partGroupCounts.length;++i){const n=this._partGroupCounts[i];for(let o=r;o<r+n;++o){this._partGroups[o].initialize(t);const h=this._partGroups[o].partIndex,c=this._partGroups[o].parameterIndex;if(!(h<0)){t.setPartOpacityByIndex(h,o==r?1:0),t.setParameterValueByIndex(c,o==r?1:0);for(let b=0;b<this._partGroups[o].link.length;++b)this._partGroups[o].link[b].initialize(t)}}r+=n}}copyPartOpacities(t){for(let r=0;r<this._partGroups.length;++r){const i=this._partGroups[r];if(i.link.length==0)continue;const n=this._partGroups[r].partIndex,o=t.getPartOpacityByIndex(n);for(let h=0;h<i.link.length;++h){const b=i.link[h].partIndex;b<0||t.setPartOpacityByIndex(b,o)}}}doFade(t,r,i,n){let o=-1,h=1;const c=.5,b=.15;for(let T=i;T<i+n;++T){const C=this._partGroups[T].partIndex,x=this._partGroups[T].parameterIndex;if(t.getParameterValueByIndex(x)>q1){if(o>=0)break;o=T,h=t.getPartOpacityByIndex(C),h+=r/this._fadeTimeSeconds,h>1&&(h=1)}}o<0&&(o=0,h=1);for(let T=i;T<i+n;++T){const C=this._partGroups[T].partIndex;if(o==T)t.setPartOpacityByIndex(C,h);else{let x=t.getPartOpacityByIndex(C),$;h<c?$=h*(c-1)/c+1:$=(1-h)*c/(1-c),(1-$)*(1-h)>b&&($=1-b/(1-h)),x>$&&(x=$),t.setPartOpacityByIndex(C,x)}}}constructor(){this._fadeTimeSeconds=u2,this._lastModel=void 0,this._partGroups=[],this._partGroupCounts=[]}}class Ga{constructor(t){this.parameterIndex=0,this.partIndex=0,this.partId="",this.link=[],t!=null&&this.assignment(t)}assignment(t){return this.partId=t.partId,this.link=t.link.map(r=>r.clone()),this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){const t=new Ga;return t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=this.link.map(r=>r.clone()),t}}class c2{constructor(t=!1,r=new ai){this.isOverwritten=t,this.Color=r}}class f2{constructor(t=!1,r=new ai){this.isOverwritten=t,this.Color=r}}class Z1{constructor(t=!1,r=!1){this.isOverwritten=t,this.isCulling=r}}class Q1{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return this._model==null?0:this._model.canvasinfo.PixelsPerUnit}getCanvasWidth(){return this._model==null?0:this._model.canvasinfo.CanvasWidth/this._model.canvasinfo.PixelsPerUnit}getCanvasHeight(){return this._model==null?0:this._model.canvasinfo.CanvasHeight/this._model.canvasinfo.PixelsPerUnit}saveParameters(){const t=this._model.parameters.count,r=this._savedParameters.length;for(let i=0;i<t;++i)i<r?this._savedParameters[i]=this._parameterValues[i]:this._savedParameters.push(this._parameterValues[i])}getMultiplyColor(t){return this.getOverwriteFlagForModelMultiplyColors()||this.getOverwriteFlagForDrawableMultiplyColors(t)?this._userMultiplyColors[t].Color:this.getDrawableMultiplyColor(t)}getScreenColor(t){return this.getOverwriteFlagForModelScreenColors()||this.getOverwriteFlagForDrawableScreenColors(t)?this._userScreenColors[t].Color:this.getDrawableScreenColor(t)}setMultiplyColorByTextureColor(t,r){this.setMultiplyColorByRGBA(t,r.R,r.G,r.B,r.A)}setMultiplyColorByRGBA(t,r,i,n,o=1){this._userMultiplyColors[t].Color.R=r,this._userMultiplyColors[t].Color.G=i,this._userMultiplyColors[t].Color.B=n,this._userMultiplyColors[t].Color.A=o}setScreenColorByTextureColor(t,r){this.setScreenColorByRGBA(t,r.R,r.G,r.B,r.A)}setScreenColorByRGBA(t,r,i,n,o=1){this._userScreenColors[t].Color.R=r,this._userScreenColors[t].Color.G=i,this._userScreenColors[t].Color.B=n,this._userScreenColors[t].Color.A=o}getPartMultiplyColor(t){return this._userPartMultiplyColors[t].Color}getPartScreenColor(t){return this._userPartScreenColors[t].Color}setPartColor(t,r,i,n,o,h,c){if(h[t].Color.R=r,h[t].Color.G=i,h[t].Color.B=n,h[t].Color.A=o,h[t].isOverwritten)for(let b=0;b<this._partChildDrawables[t].length;++b){const T=this._partChildDrawables[t][b];c[T].Color.R=r,c[T].Color.G=i,c[T].Color.B=n,c[T].Color.A=o}}setPartMultiplyColorByTextureColor(t,r){this.setPartMultiplyColorByRGBA(t,r.R,r.G,r.B,r.A)}setPartMultiplyColorByRGBA(t,r,i,n,o){this.setPartColor(t,r,i,n,o,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,r){this.setPartScreenColorByRGBA(t,r.R,r.G,r.B,r.A)}setPartScreenColorByRGBA(t,r,i,n,o){this.setPartColor(t,r,i,n,o,this._userPartScreenColors,this._userScreenColors)}getOverwriteFlagForModelMultiplyColors(){return this._isOverwrittenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return this._isOverwrittenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){this._isOverwrittenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){this._isOverwrittenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return this._userMultiplyColors[t].isOverwritten}getOverwriteFlagForDrawableScreenColors(t){return this._userScreenColors[t].isOverwritten}setOverwriteFlagForDrawableMultiplyColors(t,r){this._userMultiplyColors[t].isOverwritten=r}setOverwriteFlagForDrawableScreenColors(t,r){this._userScreenColors[t].isOverwritten=r}getOverwriteColorForPartMultiplyColors(t){return this._userPartMultiplyColors[t].isOverwritten}getOverwriteColorForPartScreenColors(t){return this._userPartScreenColors[t].isOverwritten}setOverwriteColorForPartColors(t,r,i,n){i[t].isOverwritten=r;for(let o=0;o<this._partChildDrawables[t].length;++o){const h=this._partChildDrawables[t][o];n[h].isOverwritten=r,r&&(n[h].Color.R=i[t].Color.R,n[h].Color.G=i[t].Color.G,n[h].Color.B=i[t].Color.B,n[h].Color.A=i[t].Color.A)}}setOverwriteColorForPartMultiplyColors(t,r){this._userPartMultiplyColors[t].isOverwritten=r,this.setOverwriteColorForPartColors(t,r,this._userPartMultiplyColors,this._userMultiplyColors)}setOverwriteColorForPartScreenColors(t,r){this._userPartScreenColors[t].isOverwritten=r,this.setOverwriteColorForPartColors(t,r,this._userPartScreenColors,this._userScreenColors)}getDrawableCulling(t){if(this.getOverwriteFlagForModelCullings()||this.getOverwriteFlagForDrawableCullings(t))return this._userCullings[t].isCulling;const r=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(r[t])}setDrawableCulling(t,r){this._userCullings[t].isCulling=r}getOverwriteFlagForModelCullings(){return this._isOverwrittenCullings}setOverwriteFlagForModelCullings(t){this._isOverwrittenCullings=t}getOverwriteFlagForDrawableCullings(t){return this._userCullings[t].isOverwritten}setOverwriteFlagForDrawableCullings(t,r){this._userCullings[t].isOverwritten=r}getModelOapcity(){return this._modelOpacity}setModelOapcity(t){this._modelOpacity=t}getModel(){return this._model}getPartIndex(t){let r;const i=this._model.parts.count;for(r=0;r<i;++r)if(t==this._partIds[r])return r;return t in this._notExistPartId?this._notExistPartId[t]:(r=i+this._notExistPartId.length,this._notExistPartId[t]=r,this._notExistPartOpacities[r]=0,r)}getPartId(t){return this._model.parts.ids[t]}getPartCount(){return this._model.parts.count}setPartOpacityByIndex(t,r){if(t in this._notExistPartOpacities){this._notExistPartOpacities[t]=r;return}vn(0<=t&&t<this.getPartCount()),this._partOpacities[t]=r}setPartOpacityById(t,r){const i=this.getPartIndex(t);i<0||this.setPartOpacityByIndex(i,r)}getPartOpacityByIndex(t){return t in this._notExistPartOpacities?this._notExistPartOpacities[t]:(vn(0<=t&&t<this.getPartCount()),this._partOpacities[t])}getPartOpacityById(t){const r=this.getPartIndex(t);return r<0?0:this.getPartOpacityByIndex(r)}getParameterIndex(t){let r;const i=this._model.parameters.count;for(r=0;r<i;++r)if(t==this._parameterIds[r])return r;return t in this._notExistParameterId?this._notExistParameterId[t]:(r=this._model.parameters.count+Object.keys(this._notExistParameterId).length,this._notExistParameterId[t]=r,this._notExistParameterValues[r]=0,r)}getParameterCount(){return this._model.parameters.count}getParameterType(t){return this._model.parameters.types[t]}getParameterMaximumValue(t){return this._model.parameters.maximumValues[t]}getParameterMinimumValue(t){return this._model.parameters.minimumValues[t]}getParameterDefaultValue(t){return this._model.parameters.defaultValues[t]}getParameterValueByIndex(t){return t in this._notExistParameterValues?this._notExistParameterValues[t]:(vn(0<=t&&t<this.getParameterCount()),this._parameterValues[t])}getParameterValueById(t){const r=this.getParameterIndex(t);return this.getParameterValueByIndex(r)}setParameterValueByIndex(t,r,i=1){if(t in this._notExistParameterValues){this._notExistParameterValues[t]=i==1?r:this._notExistParameterValues[t]*(1-i)+r*i;return}vn(0<=t&&t<this.getParameterCount()),this._model.parameters.maximumValues[t]<r&&(r=this._model.parameters.maximumValues[t]),this._model.parameters.minimumValues[t]>r&&(r=this._model.parameters.minimumValues[t]),this._parameterValues[t]=i==1?r:this._parameterValues[t]=this._parameterValues[t]*(1-i)+r*i}setParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.setParameterValueByIndex(n,r,i)}addParameterValueByIndex(t,r,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+r*i)}addParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.addParameterValueByIndex(n,r,i)}multiplyParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.multiplyParameterValueByIndex(n,r,i)}multiplyParameterValueByIndex(t,r,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)*(1+(r-1)*i))}getDrawableIds(){return this._drawableIds.slice()}getDrawableIndex(t){const r=this._model.drawables.count;for(let i=0;i<r;++i)if(this._drawableIds[i]==t)return i;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(t){return this._model.drawables.ids[t]}getDrawableRenderOrders(){return this._model.drawables.renderOrders}getDrawableTextureIndices(t){return this.getDrawableTextureIndex(t)}getDrawableTextureIndex(t){return this._model.drawables.textureIndices[t]}getDrawableDynamicFlagVertexPositionsDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(r[t])}getDrawableVertexIndexCount(t){return this._model.drawables.indexCounts[t]}getDrawableVertexCount(t){return this._model.drawables.vertexCounts[t]}getDrawableVertices(t){return this.getDrawableVertexPositions(t)}getDrawableVertexIndices(t){return this._model.drawables.indices[t]}getDrawableVertexPositions(t){return this._model.drawables.vertexPositions[t]}getDrawableVertexUvs(t){return this._model.drawables.vertexUvs[t]}getDrawableOpacity(t){return this._model.drawables.opacities[t]}getDrawableMultiplyColor(t){const r=this._model.drawables.multiplyColors,i=t*4,n=new ai;return n.R=r[i],n.G=r[i+1],n.B=r[i+2],n.A=r[i+3],n}getDrawableScreenColor(t){const r=this._model.drawables.screenColors,i=t*4,n=new ai;return n.R=r[i],n.G=r[i+1],n.B=r[i+2],n.A=r[i+3],n}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const r=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(r[t])?gs.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(r[t])?gs.CubismBlendMode_Multiplicative:gs.CubismBlendMode_Normal}getDrawableInvertedMaskBit(t){const r=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(r[t])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let t=0;t<this._model.drawables.count;++t)if(!(this._model.drawables.maskCounts[t]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(r[t])}getDrawableDynamicFlagVisibilityDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(r[t])}getDrawableDynamicFlagOpacityDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(r[t])}getDrawableDynamicFlagRenderOrderDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(r[t])}getDrawableDynamicFlagBlendColorDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(r[t])}loadParameters(){let t=this._model.parameters.count;const r=this._savedParameters.length;t>r&&(t=r);for(let i=0;i<t;++i)this._parameterValues[i]=this._savedParameters[i]}initialize(){this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{const r=this._model.parameters.ids,i=this._model.parameters.count;for(let n=0;n<i;++n)this._parameterIds.push(r[n])}const t=this._model.parts.count;{const r=this._model.parts.ids;for(let i=0;i<t;++i)this._partIds.push(r[i])}{const r=this._model.drawables.ids,i=this._model.drawables.count,n=new Z1(!1,!1);for(let o=0;o<t;++o){const h=new ai(1,1,1,1),c=new ai(0,0,0,1),b=new f2(!1,h),T=new f2(!1,c);this._userPartMultiplyColors.push(b),this._userPartScreenColors.push(T),this._partChildDrawables.push([])}for(let o=0;o<i;++o){const h=new ai(1,1,1,1),c=new ai(0,0,0,1),b=new c2(!1,h),T=new c2(!1,c);this._drawableIds.push(r[o]),this._userMultiplyColors.push(b),this._userScreenColors.push(T),this._userCullings.push(n);const C=this.getDrawableParentPartIndex(o);C>=0&&this._partChildDrawables[C].push(o)}}}constructor(t){this._model=t,this._savedParameters=[],this._parameterIds=[],this._drawableIds=[],this._partIds=[],this._isOverwrittenModelMultiplyColors=!1,this._isOverwrittenModelScreenColors=!1,this._isOverwrittenCullings=!1,this._modelOpacity=1,this._userMultiplyColors=[],this._userScreenColors=[],this._userCullings=[],this._userPartMultiplyColors=[],this._userPartScreenColors=[],this._partChildDrawables=[],this._notExistPartId={},this._notExistParameterId={},this._notExistParameterValues={},this._notExistPartOpacities={},this.initialize()}release(){this._model.release(),this._model=void 0}}class Tu{static create(t,r){if(r&&!this.hasMocConsistency(t))throw new Error("Inconsistent MOC3.");const i=Live2DCubismCore.Moc.fromArrayBuffer(t);if(i){const n=new Tu(i);return n._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(i,t),n}throw new Error("Failed to CubismMoc.create().")}createModel(){let t;const r=Live2DCubismCore.Model.fromMoc(this._moc);if(r)return t=new Q1(r),++this._modelCount,t;throw new Error("Unknown error")}deleteModel(t){t!=null&&--this._modelCount}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){this._moc._release(),this._moc=void 0}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static hasMocConsistency(t){return Live2DCubismCore.Moc.prototype.hasMocConsistency(t)===1}}var Eu=(s=>(s[s.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",s))(Eu||{}),Qs=(s=>(s[s.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",s[s.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",s[s.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",s))(Qs||{});class K1{constructor(){this.initialPosition=new Re(0,0),this.position=new Re(0,0),this.lastPosition=new Re(0,0),this.lastGravity=new Re(0,0),this.force=new Re(0,0),this.velocity=new Re(0,0)}}class J1{constructor(){this.normalizationPosition={},this.normalizationAngle={}}}class ty{constructor(){this.source={}}}class ey{constructor(){this.destination={},this.translationScale=new Re(0,0)}}class ry{constructor(){this.settings=[],this.inputs=[],this.outputs=[],this.particles=[],this.gravity=new Re(0,0),this.wind=new Re(0,0),this.fps=0}}class iy{constructor(t){this._json=t}release(){this._json=void 0}getGravity(){const t=new Re(0,0);return t.x=this._json.Meta.EffectiveForces.Gravity.X,t.y=this._json.Meta.EffectiveForces.Gravity.Y,t}getWind(){const t=new Re(0,0);return t.x=this._json.Meta.EffectiveForces.Wind.X,t.y=this._json.Meta.EffectiveForces.Wind.Y,t}getFps(){return this._json.Meta.Fps||0}getSubRigCount(){return this._json.Meta.PhysicsSettingCount}getTotalInputCount(){return this._json.Meta.TotalInputCount}getTotalOutputCount(){return this._json.Meta.TotalOutputCount}getVertexCount(){return this._json.Meta.VertexCount}getNormalizationPositionMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Minimum}getNormalizationPositionMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Maximum}getNormalizationPositionDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Default}getNormalizationAngleMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Minimum}getNormalizationAngleMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Maximum}getNormalizationAngleDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Default}getInputCount(t){return this._json.PhysicsSettings[t].Input.length}getInputWeight(t,r){return this._json.PhysicsSettings[t].Input[r].Weight}getInputReflect(t,r){return this._json.PhysicsSettings[t].Input[r].Reflect}getInputType(t,r){return this._json.PhysicsSettings[t].Input[r].Type}getInputSourceId(t,r){return this._json.PhysicsSettings[t].Input[r].Source.Id}getOutputCount(t){return this._json.PhysicsSettings[t].Output.length}getOutputVertexIndex(t,r){return this._json.PhysicsSettings[t].Output[r].VertexIndex}getOutputAngleScale(t,r){return this._json.PhysicsSettings[t].Output[r].Scale}getOutputWeight(t,r){return this._json.PhysicsSettings[t].Output[r].Weight}getOutputDestinationId(t,r){return this._json.PhysicsSettings[t].Output[r].Destination.Id}getOutputType(t,r){return this._json.PhysicsSettings[t].Output[r].Type}getOutputReflect(t,r){return this._json.PhysicsSettings[t].Output[r].Reflect}getParticleCount(t){return this._json.PhysicsSettings[t].Vertices.length}getParticleMobility(t,r){return this._json.PhysicsSettings[t].Vertices[r].Mobility}getParticleDelay(t,r){return this._json.PhysicsSettings[t].Vertices[r].Delay}getParticleAcceleration(t,r){return this._json.PhysicsSettings[t].Vertices[r].Acceleration}getParticleRadius(t,r){return this._json.PhysicsSettings[t].Vertices[r].Radius}getParticlePosition(t,r){const i=new Re(0,0);return i.x=this._json.PhysicsSettings[t].Vertices[r].Position.X,i.y=this._json.PhysicsSettings[t].Vertices[r].Position.Y,i}}const d2="X",p2="Y",_2="Angle",sy=5,Cu=100,g2=.001,ny=5;class Su{static create(t){const r=new Su;return r.parse(t),r._physicsRig.gravity.y=0,r}static delete(t){t!=null&&t.release()}parse(t){this._physicsRig=new ry;const r=new iy(t);this._physicsRig.gravity=r.getGravity(),this._physicsRig.wind=r.getWind(),this._physicsRig.subRigCount=r.getSubRigCount(),this._physicsRig.fps=r.getFps(),this._currentRigOutputs=[],this._previousRigOutputs=[];let i=0,n=0,o=0;for(let h=0;h<this._physicsRig.subRigCount;++h){const c=new J1;c.normalizationPosition.minimum=r.getNormalizationPositionMinimumValue(h),c.normalizationPosition.maximum=r.getNormalizationPositionMaximumValue(h),c.normalizationPosition.defalut=r.getNormalizationPositionDefaultValue(h),c.normalizationAngle.minimum=r.getNormalizationAngleMinimumValue(h),c.normalizationAngle.maximum=r.getNormalizationAngleMaximumValue(h),c.normalizationAngle.defalut=r.getNormalizationAngleDefaultValue(h),c.inputCount=r.getInputCount(h),c.baseInputIndex=i,i+=c.inputCount;for(let C=0;C<c.inputCount;++C){const x=new ty;switch(x.sourceParameterIndex=-1,x.weight=r.getInputWeight(h,C),x.reflect=r.getInputReflect(h,C),r.getInputType(h,C)){case d2:x.type=Qs.CubismPhysicsSource_X,x.getNormalizedParameterValue=ay;break;case p2:x.type=Qs.CubismPhysicsSource_Y,x.getNormalizedParameterValue=hy;break;case _2:x.type=Qs.CubismPhysicsSource_Angle,x.getNormalizedParameterValue=ly;break}x.source.targetType=Eu.CubismPhysicsTargetType_Parameter,x.source.id=r.getInputSourceId(h,C),this._physicsRig.inputs.push(x)}c.outputCount=r.getOutputCount(h),c.baseOutputIndex=n;const b=new m2,T=new m2;for(let C=0;C<c.outputCount;++C){b.outputs[C]=0,T.outputs[C]=0;let x=this._physicsRig.outputs[n+C];switch(x||(x=new ey,this._physicsRig.outputs[n+C]=x),x.destinationParameterIndex=-1,x.vertexIndex=r.getOutputVertexIndex(h,C),x.angleScale=r.getOutputAngleScale(h,C),x.weight=r.getOutputWeight(h,C),x.destination.targetType=Eu.CubismPhysicsTargetType_Parameter,x.destination.id=r.getOutputDestinationId(h,C),r.getOutputType(h,C)){case d2:x.type=Qs.CubismPhysicsSource_X,x.getValue=uy,x.getScale=_y;break;case p2:x.type=Qs.CubismPhysicsSource_Y,x.getValue=cy,x.getScale=gy;break;case _2:x.type=Qs.CubismPhysicsSource_Angle,x.getValue=fy,x.getScale=my;break}x.reflect=r.getOutputReflect(h,C)}this._currentRigOutputs.push(b),this._previousRigOutputs.push(T),n+=c.outputCount,c.particleCount=r.getParticleCount(h),c.baseParticleIndex=o,o+=c.particleCount;for(let C=0;C<c.particleCount;++C){const x=new K1;x.mobility=r.getParticleMobility(h,C),x.delay=r.getParticleDelay(h,C),x.acceleration=r.getParticleAcceleration(h,C),x.radius=r.getParticleRadius(h,C),x.position=r.getParticlePosition(h,C),this._physicsRig.particles.push(x)}this._physicsRig.settings.push(c)}this.initialize(),r.release()}stabilization(t){var r,i,n,o;let h,c,b,T;const C=new Re;let x,$,I,B,U,G,z,J;U=t.getModel().parameters.values,G=t.getModel().parameters.maximumValues,z=t.getModel().parameters.minimumValues,J=t.getModel().parameters.defaultValues,((i=(r=this._parameterCaches)==null?void 0:r.length)!=null?i:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),((o=(n=this._parameterInputCaches)==null?void 0:n.length)!=null?o:0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let Z=0;Z<t.getParameterCount();++Z)this._parameterCaches[Z]=U[Z],this._parameterInputCaches[Z]=U[Z];for(let Z=0;Z<this._physicsRig.subRigCount;++Z){h={angle:0},C.x=0,C.y=0,x=this._physicsRig.settings[Z],$=this._physicsRig.inputs.slice(x.baseInputIndex),I=this._physicsRig.outputs.slice(x.baseOutputIndex),B=this._physicsRig.particles.slice(x.baseParticleIndex);for(let it=0;it<x.inputCount;++it)c=$[it].weight/Cu,$[it].sourceParameterIndex==-1&&($[it].sourceParameterIndex=t.getParameterIndex($[it].source.id)),$[it].getNormalizedParameterValue(C,h,U[$[it].sourceParameterIndex],z[$[it].sourceParameterIndex],G[$[it].sourceParameterIndex],J[$[it].sourceParameterIndex],x.normalizationPosition,x.normalizationAngle,$[it].reflect,c),this._parameterCaches[$[it].sourceParameterIndex]=U[$[it].sourceParameterIndex];b=Ke.degreesToRadian(-h.angle),C.x=C.x*Ke.cos(b)-C.y*Ke.sin(b),C.y=C.x*Ke.sin(b)+C.y*Ke.cos(b),vy(B,x.particleCount,C,h.angle,this._options.wind,g2*x.normalizationPosition.maximum);for(let it=0;it<x.outputCount;++it){const Q=I[it].vertexIndex;if(I[it].destinationParameterIndex==-1&&(I[it].destinationParameterIndex=t.getParameterIndex(I[it].destination.id)),Q<1||Q>=x.particleCount)continue;let _t=new Re;_t=B[Q].position.substract(B[Q-1].position),T=I[it].getValue(_t,B,Q,I[it].reflect,this._options.gravity),this._currentRigOutputs[Z].outputs[it]=T,this._previousRigOutputs[Z].outputs[it]=T;const et=I[it].destinationParameterIndex,ft=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(U.subarray(et))):U.slice(et);Pu(ft,z[et],G[et],T,I[it]);for(let wt=et,Dt=0;wt<this._parameterCaches.length;wt++,Dt++)U[wt]=this._parameterCaches[wt]=ft[Dt]}}}evaluate(t,r){var i,n,o,h;let c,b,T,C;const x=new Re;let $,I,B,U;if(0>=r)return;let G,z,J,Z,it;if(this._currentRemainTime+=r,this._currentRemainTime>ny&&(this._currentRemainTime=0),G=t.getModel().parameters.values,z=t.getModel().parameters.maximumValues,J=t.getModel().parameters.minimumValues,Z=t.getModel().parameters.defaultValues,((n=(i=this._parameterCaches)==null?void 0:i.length)!=null?n:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),((h=(o=this._parameterInputCaches)==null?void 0:o.length)!=null?h:0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let _t=0;_t<t.getParameterCount();++_t)this._parameterInputCaches[_t]=G[_t]}for(this._physicsRig.fps>0?it=1/this._physicsRig.fps:it=r;this._currentRemainTime>=it;){for(let et=0;et<this._physicsRig.subRigCount;++et){$=this._physicsRig.settings[et],B=this._physicsRig.outputs.slice($.baseOutputIndex);for(let ft=0;ft<$.outputCount;++ft)this._previousRigOutputs[et].outputs[ft]=this._currentRigOutputs[et].outputs[ft]}const _t=it/this._currentRemainTime;for(let et=0;et<t.getParameterCount();++et)this._parameterCaches[et]=this._parameterInputCaches[et]*(1-_t)+G[et]*_t,this._parameterInputCaches[et]=this._parameterCaches[et];for(let et=0;et<this._physicsRig.subRigCount;++et){c={angle:0},x.x=0,x.y=0,$=this._physicsRig.settings[et],I=this._physicsRig.inputs.slice($.baseInputIndex),B=this._physicsRig.outputs.slice($.baseOutputIndex),U=this._physicsRig.particles.slice($.baseParticleIndex);for(let ft=0;ft<$.inputCount;++ft)b=I[ft].weight/Cu,I[ft].sourceParameterIndex==-1&&(I[ft].sourceParameterIndex=t.getParameterIndex(I[ft].source.id)),I[ft].getNormalizedParameterValue(x,c,this._parameterCaches[I[ft].sourceParameterIndex],J[I[ft].sourceParameterIndex],z[I[ft].sourceParameterIndex],Z[I[ft].sourceParameterIndex],$.normalizationPosition,$.normalizationAngle,I[ft].reflect,b);T=Ke.degreesToRadian(-c.angle),x.x=x.x*Ke.cos(T)-x.y*Ke.sin(T),x.y=x.x*Ke.sin(T)+x.y*Ke.cos(T),yy(U,$.particleCount,x,c.angle,this._options.wind,g2*$.normalizationPosition.maximum,it,sy);for(let ft=0;ft<$.outputCount;++ft){const wt=B[ft].vertexIndex;if(B[ft].destinationParameterIndex==-1&&(B[ft].destinationParameterIndex=t.getParameterIndex(B[ft].destination.id)),wt<1||wt>=$.particleCount)continue;const Dt=new Re;Dt.x=U[wt].position.x-U[wt-1].position.x,Dt.y=U[wt].position.y-U[wt-1].position.y,C=B[ft].getValue(Dt,U,wt,B[ft].reflect,this._options.gravity),this._currentRigOutputs[et].outputs[ft]=C;const Rt=B[ft].destinationParameterIndex,pt=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(this._parameterCaches.subarray(Rt))):this._parameterCaches.slice(Rt);Pu(pt,J[Rt],z[Rt],C,B[ft]);for(let xt=Rt,Ct=0;xt<this._parameterCaches.length;xt++,Ct++)this._parameterCaches[xt]=pt[Ct]}}this._currentRemainTime-=it}const Q=this._currentRemainTime/it;this.interpolate(t,Q)}interpolate(t,r){let i,n,o,h,c;o=t.getModel().parameters.values,h=t.getModel().parameters.maximumValues,c=t.getModel().parameters.minimumValues;for(let b=0;b<this._physicsRig.subRigCount;++b){n=this._physicsRig.settings[b],i=this._physicsRig.outputs.slice(n.baseOutputIndex);for(let T=0;T<n.outputCount;++T){if(i[T].destinationParameterIndex==-1)continue;const C=i[T].destinationParameterIndex,x=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(o.subarray(C))):o.slice(C);Pu(x,c[C],h[C],this._previousRigOutputs[b].outputs[T]*(1-r)+this._currentRigOutputs[b].outputs[T]*r,i[T]);for(let $=C,I=0;$<o.length;$++,I++)o[$]=x[I]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._options=new oy,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=[],this._previousRigOutputs=[],this._currentRemainTime=0}release(){this._physicsRig=void 0}initialize(){let t,r,i;for(let n=0;n<this._physicsRig.subRigCount;++n){r=this._physicsRig.settings[n],t=this._physicsRig.particles.slice(r.baseParticleIndex),t[0].initialPosition=new Re(0,0),t[0].lastPosition=new Re(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new Re(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new Re(0,0),t[0].force=new Re(0,0);for(let o=1;o<r.particleCount;++o)i=new Re(0,0),i.y=t[o].radius,t[o].initialPosition=new Re(t[o-1].initialPosition.x+i.x,t[o-1].initialPosition.y+i.y),t[o].position=new Re(t[o].initialPosition.x,t[o].initialPosition.y),t[o].lastPosition=new Re(t[o].initialPosition.x,t[o].initialPosition.y),t[o].lastGravity=new Re(0,-1),t[o].lastGravity.y*=-1,t[o].velocity=new Re(0,0),t[o].force=new Re(0,0)}}}class oy{constructor(){this.gravity=new Re(0,0),this.wind=new Re(0,0)}}class m2{constructor(){this.outputs=[]}}function ay(s,t,r,i,n,o,h,c,b,T){s.x+=$u(r,i,n,o,h.minimum,h.maximum,h.defalut,b)*T}function hy(s,t,r,i,n,o,h,c,b,T){s.y+=$u(r,i,n,o,h.minimum,h.maximum,h.defalut,b)*T}function ly(s,t,r,i,n,o,h,c,b,T){t.angle+=$u(r,i,n,o,c.minimum,c.maximum,c.defalut,b)*T}function uy(s,t,r,i,n){let o=s.x;return i&&(o*=-1),o}function cy(s,t,r,i,n){let o=s.y;return i&&(o*=-1),o}function fy(s,t,r,i,n){let o;return r>=2?n=t[r-1].position.substract(t[r-2].position):n=n.multiplyByScaler(-1),o=Ke.directionToRadian(n,s),i&&(o*=-1),o}function dy(s,t){return Math.abs(Math.max(s,t)-Math.min(s,t))}function py(s,t){return Math.min(s,t)+dy(s,t)/2}function _y(s,t){return s.x}function gy(s,t){return s.y}function my(s,t){return t}function yy(s,t,r,i,n,o,h,c){let b,T,C,x,$=new Re(0,0),I=new Re(0,0),B=new Re(0,0),U=new Re(0,0);s[0].position=new Re(r.x,r.y),b=Ke.degreesToRadian(i),x=Ke.radianToDirection(b),x.normalize();for(let G=1;G<t;++G)s[G].force=x.multiplyByScaler(s[G].acceleration).add(n),s[G].lastPosition=new Re(s[G].position.x,s[G].position.y),T=s[G].delay*h*30,$=s[G].position.substract(s[G-1].position),C=Ke.directionToRadian(s[G].lastGravity,x)/c,$.x=Ke.cos(C)*$.x-$.y*Ke.sin(C),$.y=Ke.sin(C)*$.x+$.y*Ke.cos(C),s[G].position=s[G-1].position.add($),I=s[G].velocity.multiplyByScaler(T),B=s[G].force.multiplyByScaler(T).multiplyByScaler(T),s[G].position=s[G].position.add(I).add(B),U=s[G].position.substract(s[G-1].position),U.normalize(),s[G].position=s[G-1].position.add(U.multiplyByScaler(s[G].radius)),Ke.abs(s[G].position.x)<o&&(s[G].position.x=0),T!=0&&(s[G].velocity=s[G].position.substract(s[G].lastPosition),s[G].velocity=s[G].velocity.divisionByScalar(T),s[G].velocity=s[G].velocity.multiplyByScaler(s[G].mobility)),s[G].force=new Re(0,0),s[G].lastGravity=new Re(x.x,x.y)}function vy(s,t,r,i,n,o){let h,c,b=new Re(0,0);s[0].position=new Re(r.x,r.y),h=Ke.degreesToRadian(i),c=Ke.radianToDirection(h),c.normalize();for(let T=1;T<t;++T)s[T].force=c.multiplyByScaler(s[T].acceleration).add(n),s[T].lastPosition=new Re(s[T].position.x,s[T].position.y),s[T].velocity=new Re(0,0),b=s[T].force,b.normalize(),b=b.multiplyByScaler(s[T].radius),s[T].position=s[T-1].position.add(b),Ke.abs(s[T].position.x)<o&&(s[T].position.x=0),s[T].force=new Re(0,0),s[T].lastGravity=new Re(c.x,c.y)}function Pu(s,t,r,i,n){let o,h,c;o=n.getScale(n.translationScale,n.angleScale),h=i*o,h<t?(h<n.valueBelowMinimum&&(n.valueBelowMinimum=h),h=t):h>r&&(h>n.valueExceededMaximum&&(n.valueExceededMaximum=h),h=r),c=n.weight/Cu,c>=1||(h=s[0]*(1-c)+h*c),s[0]=h}function $u(s,t,r,i,n,o,h,c){let b=0;const T=Ke.max(r,t);T<s&&(s=T);const C=Ke.min(r,t);C>s&&(s=C);const x=Ke.min(n,o),$=Ke.max(n,o),I=h,B=py(C,T),U=s-B;switch(Math.sign(U)){case 1:{const G=$-I,z=T-B;z!=0&&(b=U*(G/z),b+=I);break}case-1:{const G=x-I,z=C-B;z!=0&&(b=U*(G/z),b+=I);break}case 0:{b=I;break}}return c?b:b*-1}oi.registerRuntime({version:4,ready:Y1,test(s){return s instanceof bn||bn.isValidJSON(s)},isValidMoc(s){if(s.byteLength<4)return!1;const t=new Int8Array(s,0,4);return String.fromCharCode(...t)==="MOC3"},createModelSettings(s){return new bn(s)},createCoreModel(s,t){const r=Tu.create(s,!!(t!=null&&t.checkMocConsistency));try{const i=r.createModel();return i.__moc=r,i}catch(i){try{r.release()}catch{}throw i}},createInternalModel(s,t,r){const i=new H1(s,t,r),n=s;return n.__moc&&(i.__moc=n.__moc,delete n.__moc,i.once("destroy",xy)),i},createPhysics(s,t){return Su.create(t)},createPose(s,t){return wu.create(t)}});function xy(){var s;(s=this.__moc)==null||s.release()}async function by(s){const{models:t,element_id:r,auto_fit:i=!0,auto_motion:n=!0,mouse_tracking:o=!0}=s,h=new Ul({view:document.getElementById(r),width:300,height:300,backgroundAlpha:0,autoDensity:!0,antialias:!0}),c=await _u.from(t[0]);if(h.stage.addChild(c),i){const b=Math.min(300/c.width,300/c.height);c.scale.set(b),c.x=(300-c.width*b)/2,c.y=(300-c.height*b)/2}return o&&Ay(c,h.view),n&&await wy(c),c}function Ay(s,t){document.addEventListener("mousemove",r=>{var b;const i=t.getBoundingClientRect(),n=i.left+i.width/2,o=i.top+i.height/2,h=(r.clientX-n)/i.width,c=(r.clientY-o)/i.height;s.internalModel&&((b=s.internalModel.focusController)==null||b.focus(h,c))})}async function wy(s){var t;try{const r=(t=s.internalModel)==null?void 0:t.motionManager.definitions;if(r)if(r.idle)await s.motion("idle");else if(r.tap_body)await s.motion("tap_body");else{const i=Object.keys(r)[0];i&&await s.motion(i)}}catch(r){console.warn("Failed to start idle animation:",r)}}async function Ty(s,t){_u.registerTicker(vr),be.add(sa),be.add(Dm)}qr.Live2DModel=_u,qr.MotionManager=fo,qr.PIXI=Cm,qr.SoundManager=Mr,qr.createLive2dModel=by,qr.initializeLive2D=Ty,Object.defineProperty(qr,Symbol.toStringTag,{value:"Module"})});
1207
+ Please call 'CubimRenderer_WebGL.startUp' function.`);return}this._clippingManager!=null&&(this.preDraw(),this._clippingManager.setupClippingContext(this.getModel(),this)),this.preDraw();const t=this.getModel().getDrawableCount(),r=this.getModel().getDrawableRenderOrders();for(let i=0;i<t;++i){const n=r[i];this._sortedDrawableIndexList[n]=i}for(let i=0;i<t;++i){const n=this._sortedDrawableIndexList[i];if(!this.getModel().getDrawableDynamicFlagIsVisible(n))continue;const o=this._clippingManager!=null?this._clippingManager.getClippingContextListForDraw()[n]:null;if(o!=null&&this.isUsingHighPrecisionMask()){o._isUsing&&(this.gl.viewport(0,0,this._clippingManager.getClippingMaskBufferSize(),this._clippingManager.getClippingMaskBufferSize()),this.preDraw(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,o.getClippingManager().getMaskRenderTexture()[o._bufferIndex]),this.gl.clearColor(1,1,1,1),this.gl.clear(this.gl.COLOR_BUFFER_BIT));{const h=o._clippingIdCount;for(let c=0;c<h;c++){const b=o._clippingIdList[c];this._model.getDrawableDynamicFlagVertexPositionsDidChange(b)&&(this.setIsCulling(this._model.getDrawableCulling(b)!=!1),this.setClippingContextBufferForMask(o),this.drawMesh(this.getModel().getDrawableTextureIndex(b),this.getModel().getDrawableVertexIndexCount(b),this.getModel().getDrawableVertexCount(b),this.getModel().getDrawableVertexIndices(b),this.getModel().getDrawableVertices(b),this.getModel().getDrawableVertexUvs(b),this.getModel().getMultiplyColor(b),this.getModel().getScreenColor(b),this.getModel().getDrawableOpacity(b),gs.CubismBlendMode_Normal,!1))}}this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,Na),this.setClippingContextBufferForMask(null),this.gl.viewport(ms[0],ms[1],ms[2],ms[3]),this.preDraw()}this.setClippingContextBufferForDraw(o),this.setIsCulling(this.getModel().getDrawableCulling(n)),this.drawMesh(this.getModel().getDrawableTextureIndex(n),this.getModel().getDrawableVertexIndexCount(n),this.getModel().getDrawableVertexCount(n),this.getModel().getDrawableVertexIndices(n),this.getModel().getDrawableVertices(n),this.getModel().getDrawableVertexUvs(n),this.getModel().getMultiplyColor(n),this.getModel().getScreenColor(n),this.getModel().getDrawableOpacity(n),this.getModel().getDrawableBlendMode(n),this.getModel().getDrawableInvertedMaskBit(n))}}drawMesh(t,r,i,n,o,h,c,b,T,C,x){this.isCulling()?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CCW);const $=this.getModelColor();this.getClippingContextBufferForMask()==null&&($.A*=T,this.isPremultipliedAlpha()&&($.R*=$.A,$.G*=$.A,$.B*=$.A));let I=null;this._textures[t]!=null&&(I=this._textures[t]),xn.getInstance().setupShaderProgram(this,I,i,o,n,h,this._bufferData,T,C,$,c,b,this.isPremultipliedAlpha(),this.getMvpMatrix(),x),this.gl.drawElements(this.gl.TRIANGLES,r,this.gl.UNSIGNED_SHORT,0),this.gl.useProgram(null),this.setClippingContextBufferForDraw(null),this.setClippingContextBufferForMask(null)}saveProfile(){this._rendererProfile.save()}restoreProfile(){this._rendererProfile.restore()}static doStaticRelease(){xn.deleteInstance()}setRenderState(t,r){Na=t,ms=r}preDraw(){if(this.firstDraw&&(this.firstDraw=!1),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.disable(this.gl.STENCIL_TEST),this.gl.disable(this.gl.DEPTH_TEST),this.gl.frontFace(this.gl.CW),this.gl.enable(this.gl.BLEND),this.gl.colorMask(!0,!0,!0,!0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.getAnisotropy()>0&&this._extension)for(const t of Object.entries(this._textures))this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texParameterf(this.gl.TEXTURE_2D,this._extension.TEXTURE_MAX_ANISOTROPY_EXT,this.getAnisotropy())}setClippingContextBufferForMask(t){this._clippingContextBufferForMask=t}getClippingContextBufferForMask(){return this._clippingContextBufferForMask}setClippingContextBufferForDraw(t){this._clippingContextBufferForDraw=t}getClippingContextBufferForDraw(){return this._clippingContextBufferForDraw}startUp(t){this.gl=t,this._clippingManager&&this._clippingManager.setGL(t),xn.getInstance().setGl(t),this._rendererProfile.setGl(t),this._extension=this.gl.getExtension("EXT_texture_filter_anisotropic")||this.gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this.gl.getExtension("MOZ_EXT_texture_filter_anisotropic")}}gu.staticRelease=()=>{o2.doStaticRelease()};const a2=new mi;class H1 extends Id{constructor(t,r,i){super(),bt(this,"settings"),bt(this,"coreModel"),bt(this,"motionManager"),bt(this,"lipSync",!0),bt(this,"breath",bu.create()),bt(this,"eyeBlink"),bt(this,"userData"),bt(this,"renderer",new o2),bt(this,"idParamAngleX",E1),bt(this,"idParamAngleY",C1),bt(this,"idParamAngleZ",S1),bt(this,"idParamEyeBallX",P1),bt(this,"idParamEyeBallY",$1),bt(this,"idParamBodyAngleX",D1),bt(this,"idParamBreath",R1),bt(this,"idParamMouthForm",M1),bt(this,"pixelsPerUnit",1),bt(this,"centeringTransform",new nr),this.coreModel=t,this.settings=r,this.motionManager=new T1(r,i),this.init()}init(){var t;super.init(),(t=this.settings.getEyeBlinkParameters())!=null&&t.length&&(this.eyeBlink=I1.create(this.settings)),this.breath.setParameters([new yo(this.idParamAngleX,0,15,6.5345,.5),new yo(this.idParamAngleY,0,8,3.5345,.5),new yo(this.idParamAngleZ,0,10,5.5345,.5),new yo(this.idParamBodyAngleX,0,4,15.5345,.5),new yo(this.idParamBreath,0,.5,3.2345,.5)]),this.renderer.initialize(this.coreModel),this.renderer.setIsPremultipliedAlpha(!0)}getSize(){return[this.coreModel.getModel().canvasinfo.CanvasWidth,this.coreModel.getModel().canvasinfo.CanvasHeight]}getLayout(){const t={};if(this.settings.layout)for(const[r,i]of Object.entries(this.settings.layout)){const n=r.charAt(0).toLowerCase()+r.slice(1);t[n]=i}return t}setupLayout(){super.setupLayout(),this.pixelsPerUnit=this.coreModel.getModel().canvasinfo.PixelsPerUnit,this.centeringTransform.scale(this.pixelsPerUnit,this.pixelsPerUnit).translate(this.originalWidth/2,this.originalHeight/2)}updateWebGLContext(t,r){this.renderer.firstDraw=!0,this.renderer._bufferData={vertex:null,uv:null,index:null},this.renderer.startUp(t),this.renderer._clippingManager._currentFrameNo=r,this.renderer._clippingManager._maskTexture=void 0,xn.getInstance()._shaderSets=[]}bindTexture(t,r){this.renderer.bindTexture(t,r)}getHitAreaDefs(){var t,r;return(r=(t=this.settings.hitAreas)==null?void 0:t.map(i=>({id:i.Id,name:i.Name,index:this.coreModel.getDrawableIndex(i.Id)})))!=null?r:[]}getDrawableIDs(){return this.coreModel.getDrawableIds()}getDrawableIndex(t){return this.coreModel.getDrawableIndex(t)}getDrawableVertices(t){if(typeof t=="string"&&(t=this.coreModel.getDrawableIndex(t),t===-1))throw new TypeError("Unable to find drawable ID: "+t);const r=this.coreModel.getDrawableVertices(t).slice();for(let i=0;i<r.length;i+=2)r[i]=r[i]*this.pixelsPerUnit+this.originalWidth/2,r[i+1]=-r[i+1]*this.pixelsPerUnit+this.originalHeight/2;return r}updateTransform(t){this.drawingMatrix.copyFrom(this.centeringTransform).prepend(this.localTransform).prepend(t)}update(t,r){var i,n,o,h;super.update(t,r),t/=1e3,r/=1e3;const c=this.coreModel;this.emit("beforeMotionUpdate");const b=this.motionManager.update(this.coreModel,r);if(this.emit("afterMotionUpdate"),c.saveParameters(),(i=this.motionManager.expressionManager)==null||i.update(c,r),b||(n=this.eyeBlink)==null||n.updateParameters(c,t),this.updateFocus(),this.updateNaturalMovements(t*1e3,r*1e3),this.lipSync&&this.motionManager.currentAudio){let T=this.motionManager.mouthSync(),C=0;const x=1,$=1.2;T>0&&(C=.4),T=pn(T*$,C,x);for(let I=0;I<this.motionManager.lipSyncIds.length;++I)c.addParameterValueById(this.motionManager.lipSyncIds[I],T,.8)}(o=this.physics)==null||o.evaluate(c,t),(h=this.pose)==null||h.updateParameters(c,t),this.emit("beforeModelUpdate"),c.update(),c.loadParameters()}updateFocus(){this.coreModel.addParameterValueById(this.idParamEyeBallX,this.focusController.x),this.coreModel.addParameterValueById(this.idParamEyeBallY,this.focusController.y),this.coreModel.addParameterValueById(this.idParamAngleX,this.focusController.x*30),this.coreModel.addParameterValueById(this.idParamAngleY,this.focusController.y*30),this.coreModel.addParameterValueById(this.idParamAngleZ,this.focusController.x*this.focusController.y*-30),this.coreModel.addParameterValueById(this.idParamBodyAngleX,this.focusController.x*10)}updateFacialEmotion(t){this.coreModel.addParameterValueById(this.idParamMouthForm,t)}updateNaturalMovements(t,r){var i;(i=this.breath)==null||i.updateParameters(this.coreModel,t/1e3)}draw(t){const r=this.drawingMatrix,i=a2.getArray();i[0]=r.a,i[1]=r.b,i[4]=-r.c,i[5]=-r.d,i[12]=r.tx,i[13]=r.ty,this.renderer.setMvpMatrix(a2),this.renderer.setRenderState(t.getParameter(t.FRAMEBUFFER_BINDING),this.viewport),this.renderer.drawModel()}destroy(){super.destroy(),this.renderer.release(),this.coreModel.release(),this.renderer=void 0,this.coreModel=void 0}}class h2{constructor(t){this.groups=t.Groups,this.hitAreas=t.HitAreas,this.layout=t.Layout,this.moc=t.FileReferences.Moc,this.expressions=t.FileReferences.Expressions,this.motions=t.FileReferences.Motions,this.textures=t.FileReferences.Textures,this.physics=t.FileReferences.Physics,this.pose=t.FileReferences.Pose}getEyeBlinkParameters(){var t,r;return(r=(t=this.groups)==null?void 0:t.find(i=>i.Name==="EyeBlink"))==null?void 0:r.Ids}getLipSyncParameters(){var t,r;return(r=(t=this.groups)==null?void 0:t.find(i=>i.Name==="LipSync"))==null?void 0:r.Ids}}class bn extends Ia{constructor(t){if(super(t),bt(this,"moc"),bt(this,"textures"),!bn.isValidJSON(t))throw new TypeError("Invalid JSON.");Object.assign(this,new h2(t))}static isValidJSON(t){var r;return!!(t!=null&&t.FileReferences)&&typeof t.FileReferences.Moc=="string"&&((r=t.FileReferences.Textures)==null?void 0:r.length)>0&&t.FileReferences.Textures.every(i=>typeof i=="string")}replaceFiles(t){if(super.replaceFiles(t),this.motions)for(const[r,i]of Object.entries(this.motions))for(let n=0;n<i.length;n++)i[n].File=t(i[n].File,`motions.${r}[${n}].File`),i[n].Sound!==void 0&&(i[n].Sound=t(i[n].Sound,`motions.${r}[${n}].Sound`));if(this.expressions)for(let r=0;r<this.expressions.length;r++)this.expressions[r].File=t(this.expressions[r].File,`expressions[${r}].File`)}}Lm(bn,[h2]);let Ua,l2=20;function Y1(){return go.isStarted()?Promise.resolve():(Ua??(Ua=new Promise((s,t)=>{function r(){try{j1(),s()}catch(i){if(l2--,l2<0){const n=new Error("Failed to start up Cubism 4 framework.");n.cause=i,t(n);return}setTimeout(r,10)}}r()})),Ua)}function j1(s){s=Object.assign({logFunction:console.log,loggingLevel:yn.LogLevel_Verbose},s),go.startUp(s),go.initialize()}const q1=.001,u2=.5;class wu{static create(t){const r=new wu;typeof t.FadeInTime=="number"&&(r._fadeTimeSeconds=t.FadeInTime,r._fadeTimeSeconds<=0&&(r._fadeTimeSeconds=u2));const i=t.Groups,n=i.length;for(let o=0;o<n;++o){const h=i[o],c=h.length;let b=0;for(let T=0;T<c;++T){const C=h[T],x=new Ga;x.partId=C.Id;const $=C.Link;if($){const I=$.length;for(let B=0;B<I;++B){const U=new Ga;U.partId=$[B],x.link.push(U)}}r._partGroups.push(x),++b}r._partGroupCounts.push(b)}return r}updateParameters(t,r){t!=this._lastModel&&this.reset(t),this._lastModel=t,r<0&&(r=0);let i=0;for(let n=0;n<this._partGroupCounts.length;n++){const o=this._partGroupCounts[n];this.doFade(t,r,i,o),i+=o}this.copyPartOpacities(t)}reset(t){let r=0;for(let i=0;i<this._partGroupCounts.length;++i){const n=this._partGroupCounts[i];for(let o=r;o<r+n;++o){this._partGroups[o].initialize(t);const h=this._partGroups[o].partIndex,c=this._partGroups[o].parameterIndex;if(!(h<0)){t.setPartOpacityByIndex(h,o==r?1:0),t.setParameterValueByIndex(c,o==r?1:0);for(let b=0;b<this._partGroups[o].link.length;++b)this._partGroups[o].link[b].initialize(t)}}r+=n}}copyPartOpacities(t){for(let r=0;r<this._partGroups.length;++r){const i=this._partGroups[r];if(i.link.length==0)continue;const n=this._partGroups[r].partIndex,o=t.getPartOpacityByIndex(n);for(let h=0;h<i.link.length;++h){const b=i.link[h].partIndex;b<0||t.setPartOpacityByIndex(b,o)}}}doFade(t,r,i,n){let o=-1,h=1;const c=.5,b=.15;for(let T=i;T<i+n;++T){const C=this._partGroups[T].partIndex,x=this._partGroups[T].parameterIndex;if(t.getParameterValueByIndex(x)>q1){if(o>=0)break;o=T,h=t.getPartOpacityByIndex(C),h+=r/this._fadeTimeSeconds,h>1&&(h=1)}}o<0&&(o=0,h=1);for(let T=i;T<i+n;++T){const C=this._partGroups[T].partIndex;if(o==T)t.setPartOpacityByIndex(C,h);else{let x=t.getPartOpacityByIndex(C),$;h<c?$=h*(c-1)/c+1:$=(1-h)*c/(1-c),(1-$)*(1-h)>b&&($=1-b/(1-h)),x>$&&(x=$),t.setPartOpacityByIndex(C,x)}}}constructor(){this._fadeTimeSeconds=u2,this._lastModel=void 0,this._partGroups=[],this._partGroupCounts=[]}}class Ga{constructor(t){this.parameterIndex=0,this.partIndex=0,this.partId="",this.link=[],t!=null&&this.assignment(t)}assignment(t){return this.partId=t.partId,this.link=t.link.map(r=>r.clone()),this}initialize(t){this.parameterIndex=t.getParameterIndex(this.partId),this.partIndex=t.getPartIndex(this.partId),t.setParameterValueByIndex(this.parameterIndex,1)}clone(){const t=new Ga;return t.partId=this.partId,t.parameterIndex=this.parameterIndex,t.partIndex=this.partIndex,t.link=this.link.map(r=>r.clone()),t}}class c2{constructor(t=!1,r=new ai){this.isOverwritten=t,this.Color=r}}class f2{constructor(t=!1,r=new ai){this.isOverwritten=t,this.Color=r}}class Z1{constructor(t=!1,r=!1){this.isOverwritten=t,this.isCulling=r}}class Q1{update(){this._model.update(),this._model.drawables.resetDynamicFlags()}getPixelsPerUnit(){return this._model==null?0:this._model.canvasinfo.PixelsPerUnit}getCanvasWidth(){return this._model==null?0:this._model.canvasinfo.CanvasWidth/this._model.canvasinfo.PixelsPerUnit}getCanvasHeight(){return this._model==null?0:this._model.canvasinfo.CanvasHeight/this._model.canvasinfo.PixelsPerUnit}saveParameters(){const t=this._model.parameters.count,r=this._savedParameters.length;for(let i=0;i<t;++i)i<r?this._savedParameters[i]=this._parameterValues[i]:this._savedParameters.push(this._parameterValues[i])}getMultiplyColor(t){return this.getOverwriteFlagForModelMultiplyColors()||this.getOverwriteFlagForDrawableMultiplyColors(t)?this._userMultiplyColors[t].Color:this.getDrawableMultiplyColor(t)}getScreenColor(t){return this.getOverwriteFlagForModelScreenColors()||this.getOverwriteFlagForDrawableScreenColors(t)?this._userScreenColors[t].Color:this.getDrawableScreenColor(t)}setMultiplyColorByTextureColor(t,r){this.setMultiplyColorByRGBA(t,r.R,r.G,r.B,r.A)}setMultiplyColorByRGBA(t,r,i,n,o=1){this._userMultiplyColors[t].Color.R=r,this._userMultiplyColors[t].Color.G=i,this._userMultiplyColors[t].Color.B=n,this._userMultiplyColors[t].Color.A=o}setScreenColorByTextureColor(t,r){this.setScreenColorByRGBA(t,r.R,r.G,r.B,r.A)}setScreenColorByRGBA(t,r,i,n,o=1){this._userScreenColors[t].Color.R=r,this._userScreenColors[t].Color.G=i,this._userScreenColors[t].Color.B=n,this._userScreenColors[t].Color.A=o}getPartMultiplyColor(t){return this._userPartMultiplyColors[t].Color}getPartScreenColor(t){return this._userPartScreenColors[t].Color}setPartColor(t,r,i,n,o,h,c){if(h[t].Color.R=r,h[t].Color.G=i,h[t].Color.B=n,h[t].Color.A=o,h[t].isOverwritten)for(let b=0;b<this._partChildDrawables[t].length;++b){const T=this._partChildDrawables[t][b];c[T].Color.R=r,c[T].Color.G=i,c[T].Color.B=n,c[T].Color.A=o}}setPartMultiplyColorByTextureColor(t,r){this.setPartMultiplyColorByRGBA(t,r.R,r.G,r.B,r.A)}setPartMultiplyColorByRGBA(t,r,i,n,o){this.setPartColor(t,r,i,n,o,this._userPartMultiplyColors,this._userMultiplyColors)}setPartScreenColorByTextureColor(t,r){this.setPartScreenColorByRGBA(t,r.R,r.G,r.B,r.A)}setPartScreenColorByRGBA(t,r,i,n,o){this.setPartColor(t,r,i,n,o,this._userPartScreenColors,this._userScreenColors)}getOverwriteFlagForModelMultiplyColors(){return this._isOverwrittenModelMultiplyColors}getOverwriteFlagForModelScreenColors(){return this._isOverwrittenModelScreenColors}setOverwriteFlagForModelMultiplyColors(t){this._isOverwrittenModelMultiplyColors=t}setOverwriteFlagForModelScreenColors(t){this._isOverwrittenModelScreenColors=t}getOverwriteFlagForDrawableMultiplyColors(t){return this._userMultiplyColors[t].isOverwritten}getOverwriteFlagForDrawableScreenColors(t){return this._userScreenColors[t].isOverwritten}setOverwriteFlagForDrawableMultiplyColors(t,r){this._userMultiplyColors[t].isOverwritten=r}setOverwriteFlagForDrawableScreenColors(t,r){this._userScreenColors[t].isOverwritten=r}getOverwriteColorForPartMultiplyColors(t){return this._userPartMultiplyColors[t].isOverwritten}getOverwriteColorForPartScreenColors(t){return this._userPartScreenColors[t].isOverwritten}setOverwriteColorForPartColors(t,r,i,n){i[t].isOverwritten=r;for(let o=0;o<this._partChildDrawables[t].length;++o){const h=this._partChildDrawables[t][o];n[h].isOverwritten=r,r&&(n[h].Color.R=i[t].Color.R,n[h].Color.G=i[t].Color.G,n[h].Color.B=i[t].Color.B,n[h].Color.A=i[t].Color.A)}}setOverwriteColorForPartMultiplyColors(t,r){this._userPartMultiplyColors[t].isOverwritten=r,this.setOverwriteColorForPartColors(t,r,this._userPartMultiplyColors,this._userMultiplyColors)}setOverwriteColorForPartScreenColors(t,r){this._userPartScreenColors[t].isOverwritten=r,this.setOverwriteColorForPartColors(t,r,this._userPartScreenColors,this._userScreenColors)}getDrawableCulling(t){if(this.getOverwriteFlagForModelCullings()||this.getOverwriteFlagForDrawableCullings(t))return this._userCullings[t].isCulling;const r=this._model.drawables.constantFlags;return!Live2DCubismCore.Utils.hasIsDoubleSidedBit(r[t])}setDrawableCulling(t,r){this._userCullings[t].isCulling=r}getOverwriteFlagForModelCullings(){return this._isOverwrittenCullings}setOverwriteFlagForModelCullings(t){this._isOverwrittenCullings=t}getOverwriteFlagForDrawableCullings(t){return this._userCullings[t].isOverwritten}setOverwriteFlagForDrawableCullings(t,r){this._userCullings[t].isOverwritten=r}getModelOapcity(){return this._modelOpacity}setModelOapcity(t){this._modelOpacity=t}getModel(){return this._model}getPartIndex(t){let r;const i=this._model.parts.count;for(r=0;r<i;++r)if(t==this._partIds[r])return r;return t in this._notExistPartId?this._notExistPartId[t]:(r=i+this._notExistPartId.length,this._notExistPartId[t]=r,this._notExistPartOpacities[r]=0,r)}getPartId(t){return this._model.parts.ids[t]}getPartCount(){return this._model.parts.count}setPartOpacityByIndex(t,r){if(t in this._notExistPartOpacities){this._notExistPartOpacities[t]=r;return}vn(0<=t&&t<this.getPartCount()),this._partOpacities[t]=r}setPartOpacityById(t,r){const i=this.getPartIndex(t);i<0||this.setPartOpacityByIndex(i,r)}getPartOpacityByIndex(t){return t in this._notExistPartOpacities?this._notExistPartOpacities[t]:(vn(0<=t&&t<this.getPartCount()),this._partOpacities[t])}getPartOpacityById(t){const r=this.getPartIndex(t);return r<0?0:this.getPartOpacityByIndex(r)}getParameterIndex(t){let r;const i=this._model.parameters.count;for(r=0;r<i;++r)if(t==this._parameterIds[r])return r;return t in this._notExistParameterId?this._notExistParameterId[t]:(r=this._model.parameters.count+Object.keys(this._notExistParameterId).length,this._notExistParameterId[t]=r,this._notExistParameterValues[r]=0,r)}getParameterCount(){return this._model.parameters.count}getParameterType(t){return this._model.parameters.types[t]}getParameterMaximumValue(t){return this._model.parameters.maximumValues[t]}getParameterMinimumValue(t){return this._model.parameters.minimumValues[t]}getParameterDefaultValue(t){return this._model.parameters.defaultValues[t]}getParameterValueByIndex(t){return t in this._notExistParameterValues?this._notExistParameterValues[t]:(vn(0<=t&&t<this.getParameterCount()),this._parameterValues[t])}getParameterValueById(t){const r=this.getParameterIndex(t);return this.getParameterValueByIndex(r)}setParameterValueByIndex(t,r,i=1){if(t in this._notExistParameterValues){this._notExistParameterValues[t]=i==1?r:this._notExistParameterValues[t]*(1-i)+r*i;return}vn(0<=t&&t<this.getParameterCount()),this._model.parameters.maximumValues[t]<r&&(r=this._model.parameters.maximumValues[t]),this._model.parameters.minimumValues[t]>r&&(r=this._model.parameters.minimumValues[t]),this._parameterValues[t]=i==1?r:this._parameterValues[t]=this._parameterValues[t]*(1-i)+r*i}setParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.setParameterValueByIndex(n,r,i)}addParameterValueByIndex(t,r,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)+r*i)}addParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.addParameterValueByIndex(n,r,i)}multiplyParameterValueById(t,r,i=1){const n=this.getParameterIndex(t);this.multiplyParameterValueByIndex(n,r,i)}multiplyParameterValueByIndex(t,r,i=1){this.setParameterValueByIndex(t,this.getParameterValueByIndex(t)*(1+(r-1)*i))}getDrawableIds(){return this._drawableIds.slice()}getDrawableIndex(t){const r=this._model.drawables.count;for(let i=0;i<r;++i)if(this._drawableIds[i]==t)return i;return-1}getDrawableCount(){return this._model.drawables.count}getDrawableId(t){return this._model.drawables.ids[t]}getDrawableRenderOrders(){return this._model.drawables.renderOrders}getDrawableTextureIndices(t){return this.getDrawableTextureIndex(t)}getDrawableTextureIndex(t){return this._model.drawables.textureIndices[t]}getDrawableDynamicFlagVertexPositionsDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVertexPositionsDidChangeBit(r[t])}getDrawableVertexIndexCount(t){return this._model.drawables.indexCounts[t]}getDrawableVertexCount(t){return this._model.drawables.vertexCounts[t]}getDrawableVertices(t){return this.getDrawableVertexPositions(t)}getDrawableVertexIndices(t){return this._model.drawables.indices[t]}getDrawableVertexPositions(t){return this._model.drawables.vertexPositions[t]}getDrawableVertexUvs(t){return this._model.drawables.vertexUvs[t]}getDrawableOpacity(t){return this._model.drawables.opacities[t]}getDrawableMultiplyColor(t){const r=this._model.drawables.multiplyColors,i=t*4,n=new ai;return n.R=r[i],n.G=r[i+1],n.B=r[i+2],n.A=r[i+3],n}getDrawableScreenColor(t){const r=this._model.drawables.screenColors,i=t*4,n=new ai;return n.R=r[i],n.G=r[i+1],n.B=r[i+2],n.A=r[i+3],n}getDrawableParentPartIndex(t){return this._model.drawables.parentPartIndices[t]}getDrawableBlendMode(t){const r=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasBlendAdditiveBit(r[t])?gs.CubismBlendMode_Additive:Live2DCubismCore.Utils.hasBlendMultiplicativeBit(r[t])?gs.CubismBlendMode_Multiplicative:gs.CubismBlendMode_Normal}getDrawableInvertedMaskBit(t){const r=this._model.drawables.constantFlags;return Live2DCubismCore.Utils.hasIsInvertedMaskBit(r[t])}getDrawableMasks(){return this._model.drawables.masks}getDrawableMaskCounts(){return this._model.drawables.maskCounts}isUsingMasking(){for(let t=0;t<this._model.drawables.count;++t)if(!(this._model.drawables.maskCounts[t]<=0))return!0;return!1}getDrawableDynamicFlagIsVisible(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasIsVisibleBit(r[t])}getDrawableDynamicFlagVisibilityDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasVisibilityDidChangeBit(r[t])}getDrawableDynamicFlagOpacityDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasOpacityDidChangeBit(r[t])}getDrawableDynamicFlagRenderOrderDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasRenderOrderDidChangeBit(r[t])}getDrawableDynamicFlagBlendColorDidChange(t){const r=this._model.drawables.dynamicFlags;return Live2DCubismCore.Utils.hasBlendColorDidChangeBit(r[t])}loadParameters(){let t=this._model.parameters.count;const r=this._savedParameters.length;t>r&&(t=r);for(let i=0;i<t;++i)this._parameterValues[i]=this._savedParameters[i]}initialize(){this._parameterValues=this._model.parameters.values,this._partOpacities=this._model.parts.opacities,this._parameterMaximumValues=this._model.parameters.maximumValues,this._parameterMinimumValues=this._model.parameters.minimumValues;{const r=this._model.parameters.ids,i=this._model.parameters.count;for(let n=0;n<i;++n)this._parameterIds.push(r[n])}const t=this._model.parts.count;{const r=this._model.parts.ids;for(let i=0;i<t;++i)this._partIds.push(r[i])}{const r=this._model.drawables.ids,i=this._model.drawables.count,n=new Z1(!1,!1);for(let o=0;o<t;++o){const h=new ai(1,1,1,1),c=new ai(0,0,0,1),b=new f2(!1,h),T=new f2(!1,c);this._userPartMultiplyColors.push(b),this._userPartScreenColors.push(T),this._partChildDrawables.push([])}for(let o=0;o<i;++o){const h=new ai(1,1,1,1),c=new ai(0,0,0,1),b=new c2(!1,h),T=new c2(!1,c);this._drawableIds.push(r[o]),this._userMultiplyColors.push(b),this._userScreenColors.push(T),this._userCullings.push(n);const C=this.getDrawableParentPartIndex(o);C>=0&&this._partChildDrawables[C].push(o)}}}constructor(t){this._model=t,this._savedParameters=[],this._parameterIds=[],this._drawableIds=[],this._partIds=[],this._isOverwrittenModelMultiplyColors=!1,this._isOverwrittenModelScreenColors=!1,this._isOverwrittenCullings=!1,this._modelOpacity=1,this._userMultiplyColors=[],this._userScreenColors=[],this._userCullings=[],this._userPartMultiplyColors=[],this._userPartScreenColors=[],this._partChildDrawables=[],this._notExistPartId={},this._notExistParameterId={},this._notExistParameterValues={},this._notExistPartOpacities={},this.initialize()}release(){this._model.release(),this._model=void 0}}class Tu{static create(t,r){if(r&&!this.hasMocConsistency(t))throw new Error("Inconsistent MOC3.");const i=Live2DCubismCore.Moc.fromArrayBuffer(t);if(i){const n=new Tu(i);return n._mocVersion=Live2DCubismCore.Version.csmGetMocVersion(i,t),n}throw new Error("Failed to CubismMoc.create().")}createModel(){let t;const r=Live2DCubismCore.Model.fromMoc(this._moc);if(r)return t=new Q1(r),++this._modelCount,t;throw new Error("Unknown error")}deleteModel(t){t!=null&&--this._modelCount}constructor(t){this._moc=t,this._modelCount=0,this._mocVersion=0}release(){this._moc._release(),this._moc=void 0}getLatestMocVersion(){return Live2DCubismCore.Version.csmGetLatestMocVersion()}getMocVersion(){return this._mocVersion}static hasMocConsistency(t){return Live2DCubismCore.Moc.prototype.hasMocConsistency(t)===1}}var Eu=(s=>(s[s.CubismPhysicsTargetType_Parameter=0]="CubismPhysicsTargetType_Parameter",s))(Eu||{}),Qs=(s=>(s[s.CubismPhysicsSource_X=0]="CubismPhysicsSource_X",s[s.CubismPhysicsSource_Y=1]="CubismPhysicsSource_Y",s[s.CubismPhysicsSource_Angle=2]="CubismPhysicsSource_Angle",s))(Qs||{});class K1{constructor(){this.initialPosition=new Re(0,0),this.position=new Re(0,0),this.lastPosition=new Re(0,0),this.lastGravity=new Re(0,0),this.force=new Re(0,0),this.velocity=new Re(0,0)}}class J1{constructor(){this.normalizationPosition={},this.normalizationAngle={}}}class ty{constructor(){this.source={}}}class ey{constructor(){this.destination={},this.translationScale=new Re(0,0)}}class ry{constructor(){this.settings=[],this.inputs=[],this.outputs=[],this.particles=[],this.gravity=new Re(0,0),this.wind=new Re(0,0),this.fps=0}}class iy{constructor(t){this._json=t}release(){this._json=void 0}getGravity(){const t=new Re(0,0);return t.x=this._json.Meta.EffectiveForces.Gravity.X,t.y=this._json.Meta.EffectiveForces.Gravity.Y,t}getWind(){const t=new Re(0,0);return t.x=this._json.Meta.EffectiveForces.Wind.X,t.y=this._json.Meta.EffectiveForces.Wind.Y,t}getFps(){return this._json.Meta.Fps||0}getSubRigCount(){return this._json.Meta.PhysicsSettingCount}getTotalInputCount(){return this._json.Meta.TotalInputCount}getTotalOutputCount(){return this._json.Meta.TotalOutputCount}getVertexCount(){return this._json.Meta.VertexCount}getNormalizationPositionMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Minimum}getNormalizationPositionMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Maximum}getNormalizationPositionDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Position.Default}getNormalizationAngleMinimumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Minimum}getNormalizationAngleMaximumValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Maximum}getNormalizationAngleDefaultValue(t){return this._json.PhysicsSettings[t].Normalization.Angle.Default}getInputCount(t){return this._json.PhysicsSettings[t].Input.length}getInputWeight(t,r){return this._json.PhysicsSettings[t].Input[r].Weight}getInputReflect(t,r){return this._json.PhysicsSettings[t].Input[r].Reflect}getInputType(t,r){return this._json.PhysicsSettings[t].Input[r].Type}getInputSourceId(t,r){return this._json.PhysicsSettings[t].Input[r].Source.Id}getOutputCount(t){return this._json.PhysicsSettings[t].Output.length}getOutputVertexIndex(t,r){return this._json.PhysicsSettings[t].Output[r].VertexIndex}getOutputAngleScale(t,r){return this._json.PhysicsSettings[t].Output[r].Scale}getOutputWeight(t,r){return this._json.PhysicsSettings[t].Output[r].Weight}getOutputDestinationId(t,r){return this._json.PhysicsSettings[t].Output[r].Destination.Id}getOutputType(t,r){return this._json.PhysicsSettings[t].Output[r].Type}getOutputReflect(t,r){return this._json.PhysicsSettings[t].Output[r].Reflect}getParticleCount(t){return this._json.PhysicsSettings[t].Vertices.length}getParticleMobility(t,r){return this._json.PhysicsSettings[t].Vertices[r].Mobility}getParticleDelay(t,r){return this._json.PhysicsSettings[t].Vertices[r].Delay}getParticleAcceleration(t,r){return this._json.PhysicsSettings[t].Vertices[r].Acceleration}getParticleRadius(t,r){return this._json.PhysicsSettings[t].Vertices[r].Radius}getParticlePosition(t,r){const i=new Re(0,0);return i.x=this._json.PhysicsSettings[t].Vertices[r].Position.X,i.y=this._json.PhysicsSettings[t].Vertices[r].Position.Y,i}}const d2="X",p2="Y",_2="Angle",sy=5,Cu=100,g2=.001,ny=5;class Su{static create(t){const r=new Su;return r.parse(t),r._physicsRig.gravity.y=0,r}static delete(t){t!=null&&t.release()}parse(t){this._physicsRig=new ry;const r=new iy(t);this._physicsRig.gravity=r.getGravity(),this._physicsRig.wind=r.getWind(),this._physicsRig.subRigCount=r.getSubRigCount(),this._physicsRig.fps=r.getFps(),this._currentRigOutputs=[],this._previousRigOutputs=[];let i=0,n=0,o=0;for(let h=0;h<this._physicsRig.subRigCount;++h){const c=new J1;c.normalizationPosition.minimum=r.getNormalizationPositionMinimumValue(h),c.normalizationPosition.maximum=r.getNormalizationPositionMaximumValue(h),c.normalizationPosition.defalut=r.getNormalizationPositionDefaultValue(h),c.normalizationAngle.minimum=r.getNormalizationAngleMinimumValue(h),c.normalizationAngle.maximum=r.getNormalizationAngleMaximumValue(h),c.normalizationAngle.defalut=r.getNormalizationAngleDefaultValue(h),c.inputCount=r.getInputCount(h),c.baseInputIndex=i,i+=c.inputCount;for(let C=0;C<c.inputCount;++C){const x=new ty;switch(x.sourceParameterIndex=-1,x.weight=r.getInputWeight(h,C),x.reflect=r.getInputReflect(h,C),r.getInputType(h,C)){case d2:x.type=Qs.CubismPhysicsSource_X,x.getNormalizedParameterValue=ay;break;case p2:x.type=Qs.CubismPhysicsSource_Y,x.getNormalizedParameterValue=hy;break;case _2:x.type=Qs.CubismPhysicsSource_Angle,x.getNormalizedParameterValue=ly;break}x.source.targetType=Eu.CubismPhysicsTargetType_Parameter,x.source.id=r.getInputSourceId(h,C),this._physicsRig.inputs.push(x)}c.outputCount=r.getOutputCount(h),c.baseOutputIndex=n;const b=new m2,T=new m2;for(let C=0;C<c.outputCount;++C){b.outputs[C]=0,T.outputs[C]=0;let x=this._physicsRig.outputs[n+C];switch(x||(x=new ey,this._physicsRig.outputs[n+C]=x),x.destinationParameterIndex=-1,x.vertexIndex=r.getOutputVertexIndex(h,C),x.angleScale=r.getOutputAngleScale(h,C),x.weight=r.getOutputWeight(h,C),x.destination.targetType=Eu.CubismPhysicsTargetType_Parameter,x.destination.id=r.getOutputDestinationId(h,C),r.getOutputType(h,C)){case d2:x.type=Qs.CubismPhysicsSource_X,x.getValue=uy,x.getScale=_y;break;case p2:x.type=Qs.CubismPhysicsSource_Y,x.getValue=cy,x.getScale=gy;break;case _2:x.type=Qs.CubismPhysicsSource_Angle,x.getValue=fy,x.getScale=my;break}x.reflect=r.getOutputReflect(h,C)}this._currentRigOutputs.push(b),this._previousRigOutputs.push(T),n+=c.outputCount,c.particleCount=r.getParticleCount(h),c.baseParticleIndex=o,o+=c.particleCount;for(let C=0;C<c.particleCount;++C){const x=new K1;x.mobility=r.getParticleMobility(h,C),x.delay=r.getParticleDelay(h,C),x.acceleration=r.getParticleAcceleration(h,C),x.radius=r.getParticleRadius(h,C),x.position=r.getParticlePosition(h,C),this._physicsRig.particles.push(x)}this._physicsRig.settings.push(c)}this.initialize(),r.release()}stabilization(t){var r,i,n,o;let h,c,b,T;const C=new Re;let x,$,I,B,U,G,z,J;U=t.getModel().parameters.values,G=t.getModel().parameters.maximumValues,z=t.getModel().parameters.minimumValues,J=t.getModel().parameters.defaultValues,((i=(r=this._parameterCaches)==null?void 0:r.length)!=null?i:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),((o=(n=this._parameterInputCaches)==null?void 0:n.length)!=null?o:0)<t.getParameterCount()&&(this._parameterInputCaches=new Float32Array(t.getParameterCount()));for(let Z=0;Z<t.getParameterCount();++Z)this._parameterCaches[Z]=U[Z],this._parameterInputCaches[Z]=U[Z];for(let Z=0;Z<this._physicsRig.subRigCount;++Z){h={angle:0},C.x=0,C.y=0,x=this._physicsRig.settings[Z],$=this._physicsRig.inputs.slice(x.baseInputIndex),I=this._physicsRig.outputs.slice(x.baseOutputIndex),B=this._physicsRig.particles.slice(x.baseParticleIndex);for(let it=0;it<x.inputCount;++it)c=$[it].weight/Cu,$[it].sourceParameterIndex==-1&&($[it].sourceParameterIndex=t.getParameterIndex($[it].source.id)),$[it].getNormalizedParameterValue(C,h,U[$[it].sourceParameterIndex],z[$[it].sourceParameterIndex],G[$[it].sourceParameterIndex],J[$[it].sourceParameterIndex],x.normalizationPosition,x.normalizationAngle,$[it].reflect,c),this._parameterCaches[$[it].sourceParameterIndex]=U[$[it].sourceParameterIndex];b=Ke.degreesToRadian(-h.angle),C.x=C.x*Ke.cos(b)-C.y*Ke.sin(b),C.y=C.x*Ke.sin(b)+C.y*Ke.cos(b),vy(B,x.particleCount,C,h.angle,this._options.wind,g2*x.normalizationPosition.maximum);for(let it=0;it<x.outputCount;++it){const Q=I[it].vertexIndex;if(I[it].destinationParameterIndex==-1&&(I[it].destinationParameterIndex=t.getParameterIndex(I[it].destination.id)),Q<1||Q>=x.particleCount)continue;let _t=new Re;_t=B[Q].position.substract(B[Q-1].position),T=I[it].getValue(_t,B,Q,I[it].reflect,this._options.gravity),this._currentRigOutputs[Z].outputs[it]=T,this._previousRigOutputs[Z].outputs[it]=T;const et=I[it].destinationParameterIndex,ft=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(U.subarray(et))):U.slice(et);Pu(ft,z[et],G[et],T,I[it]);for(let wt=et,Dt=0;wt<this._parameterCaches.length;wt++,Dt++)U[wt]=this._parameterCaches[wt]=ft[Dt]}}}evaluate(t,r){var i,n,o,h;let c,b,T,C;const x=new Re;let $,I,B,U;if(0>=r)return;let G,z,J,Z,it;if(this._currentRemainTime+=r,this._currentRemainTime>ny&&(this._currentRemainTime=0),G=t.getModel().parameters.values,z=t.getModel().parameters.maximumValues,J=t.getModel().parameters.minimumValues,Z=t.getModel().parameters.defaultValues,((n=(i=this._parameterCaches)==null?void 0:i.length)!=null?n:0)<t.getParameterCount()&&(this._parameterCaches=new Float32Array(t.getParameterCount())),((h=(o=this._parameterInputCaches)==null?void 0:o.length)!=null?h:0)<t.getParameterCount()){this._parameterInputCaches=new Float32Array(t.getParameterCount());for(let _t=0;_t<t.getParameterCount();++_t)this._parameterInputCaches[_t]=G[_t]}for(this._physicsRig.fps>0?it=1/this._physicsRig.fps:it=r;this._currentRemainTime>=it;){for(let et=0;et<this._physicsRig.subRigCount;++et){$=this._physicsRig.settings[et],B=this._physicsRig.outputs.slice($.baseOutputIndex);for(let ft=0;ft<$.outputCount;++ft)this._previousRigOutputs[et].outputs[ft]=this._currentRigOutputs[et].outputs[ft]}const _t=it/this._currentRemainTime;for(let et=0;et<t.getParameterCount();++et)this._parameterCaches[et]=this._parameterInputCaches[et]*(1-_t)+G[et]*_t,this._parameterInputCaches[et]=this._parameterCaches[et];for(let et=0;et<this._physicsRig.subRigCount;++et){c={angle:0},x.x=0,x.y=0,$=this._physicsRig.settings[et],I=this._physicsRig.inputs.slice($.baseInputIndex),B=this._physicsRig.outputs.slice($.baseOutputIndex),U=this._physicsRig.particles.slice($.baseParticleIndex);for(let ft=0;ft<$.inputCount;++ft)b=I[ft].weight/Cu,I[ft].sourceParameterIndex==-1&&(I[ft].sourceParameterIndex=t.getParameterIndex(I[ft].source.id)),I[ft].getNormalizedParameterValue(x,c,this._parameterCaches[I[ft].sourceParameterIndex],J[I[ft].sourceParameterIndex],z[I[ft].sourceParameterIndex],Z[I[ft].sourceParameterIndex],$.normalizationPosition,$.normalizationAngle,I[ft].reflect,b);T=Ke.degreesToRadian(-c.angle),x.x=x.x*Ke.cos(T)-x.y*Ke.sin(T),x.y=x.x*Ke.sin(T)+x.y*Ke.cos(T),yy(U,$.particleCount,x,c.angle,this._options.wind,g2*$.normalizationPosition.maximum,it,sy);for(let ft=0;ft<$.outputCount;++ft){const wt=B[ft].vertexIndex;if(B[ft].destinationParameterIndex==-1&&(B[ft].destinationParameterIndex=t.getParameterIndex(B[ft].destination.id)),wt<1||wt>=$.particleCount)continue;const Dt=new Re;Dt.x=U[wt].position.x-U[wt-1].position.x,Dt.y=U[wt].position.y-U[wt-1].position.y,C=B[ft].getValue(Dt,U,wt,B[ft].reflect,this._options.gravity),this._currentRigOutputs[et].outputs[ft]=C;const Rt=B[ft].destinationParameterIndex,pt=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(this._parameterCaches.subarray(Rt))):this._parameterCaches.slice(Rt);Pu(pt,J[Rt],z[Rt],C,B[ft]);for(let xt=Rt,Ct=0;xt<this._parameterCaches.length;xt++,Ct++)this._parameterCaches[xt]=pt[Ct]}}this._currentRemainTime-=it}const Q=this._currentRemainTime/it;this.interpolate(t,Q)}interpolate(t,r){let i,n,o,h,c;o=t.getModel().parameters.values,h=t.getModel().parameters.maximumValues,c=t.getModel().parameters.minimumValues;for(let b=0;b<this._physicsRig.subRigCount;++b){n=this._physicsRig.settings[b],i=this._physicsRig.outputs.slice(n.baseOutputIndex);for(let T=0;T<n.outputCount;++T){if(i[T].destinationParameterIndex==-1)continue;const C=i[T].destinationParameterIndex,x=!Float32Array.prototype.slice&&"subarray"in Float32Array.prototype?JSON.parse(JSON.stringify(o.subarray(C))):o.slice(C);Pu(x,c[C],h[C],this._previousRigOutputs[b].outputs[T]*(1-r)+this._currentRigOutputs[b].outputs[T]*r,i[T]);for(let $=C,I=0;$<o.length;$++,I++)o[$]=x[I]}}}setOptions(t){this._options=t}getOption(){return this._options}constructor(){this._options=new oy,this._options.gravity.y=-1,this._options.gravity.x=0,this._options.wind.x=0,this._options.wind.y=0,this._currentRigOutputs=[],this._previousRigOutputs=[],this._currentRemainTime=0}release(){this._physicsRig=void 0}initialize(){let t,r,i;for(let n=0;n<this._physicsRig.subRigCount;++n){r=this._physicsRig.settings[n],t=this._physicsRig.particles.slice(r.baseParticleIndex),t[0].initialPosition=new Re(0,0),t[0].lastPosition=new Re(t[0].initialPosition.x,t[0].initialPosition.y),t[0].lastGravity=new Re(0,-1),t[0].lastGravity.y*=-1,t[0].velocity=new Re(0,0),t[0].force=new Re(0,0);for(let o=1;o<r.particleCount;++o)i=new Re(0,0),i.y=t[o].radius,t[o].initialPosition=new Re(t[o-1].initialPosition.x+i.x,t[o-1].initialPosition.y+i.y),t[o].position=new Re(t[o].initialPosition.x,t[o].initialPosition.y),t[o].lastPosition=new Re(t[o].initialPosition.x,t[o].initialPosition.y),t[o].lastGravity=new Re(0,-1),t[o].lastGravity.y*=-1,t[o].velocity=new Re(0,0),t[o].force=new Re(0,0)}}}class oy{constructor(){this.gravity=new Re(0,0),this.wind=new Re(0,0)}}class m2{constructor(){this.outputs=[]}}function ay(s,t,r,i,n,o,h,c,b,T){s.x+=$u(r,i,n,o,h.minimum,h.maximum,h.defalut,b)*T}function hy(s,t,r,i,n,o,h,c,b,T){s.y+=$u(r,i,n,o,h.minimum,h.maximum,h.defalut,b)*T}function ly(s,t,r,i,n,o,h,c,b,T){t.angle+=$u(r,i,n,o,c.minimum,c.maximum,c.defalut,b)*T}function uy(s,t,r,i,n){let o=s.x;return i&&(o*=-1),o}function cy(s,t,r,i,n){let o=s.y;return i&&(o*=-1),o}function fy(s,t,r,i,n){let o;return r>=2?n=t[r-1].position.substract(t[r-2].position):n=n.multiplyByScaler(-1),o=Ke.directionToRadian(n,s),i&&(o*=-1),o}function dy(s,t){return Math.abs(Math.max(s,t)-Math.min(s,t))}function py(s,t){return Math.min(s,t)+dy(s,t)/2}function _y(s,t){return s.x}function gy(s,t){return s.y}function my(s,t){return t}function yy(s,t,r,i,n,o,h,c){let b,T,C,x,$=new Re(0,0),I=new Re(0,0),B=new Re(0,0),U=new Re(0,0);s[0].position=new Re(r.x,r.y),b=Ke.degreesToRadian(i),x=Ke.radianToDirection(b),x.normalize();for(let G=1;G<t;++G)s[G].force=x.multiplyByScaler(s[G].acceleration).add(n),s[G].lastPosition=new Re(s[G].position.x,s[G].position.y),T=s[G].delay*h*30,$=s[G].position.substract(s[G-1].position),C=Ke.directionToRadian(s[G].lastGravity,x)/c,$.x=Ke.cos(C)*$.x-$.y*Ke.sin(C),$.y=Ke.sin(C)*$.x+$.y*Ke.cos(C),s[G].position=s[G-1].position.add($),I=s[G].velocity.multiplyByScaler(T),B=s[G].force.multiplyByScaler(T).multiplyByScaler(T),s[G].position=s[G].position.add(I).add(B),U=s[G].position.substract(s[G-1].position),U.normalize(),s[G].position=s[G-1].position.add(U.multiplyByScaler(s[G].radius)),Ke.abs(s[G].position.x)<o&&(s[G].position.x=0),T!=0&&(s[G].velocity=s[G].position.substract(s[G].lastPosition),s[G].velocity=s[G].velocity.divisionByScalar(T),s[G].velocity=s[G].velocity.multiplyByScaler(s[G].mobility)),s[G].force=new Re(0,0),s[G].lastGravity=new Re(x.x,x.y)}function vy(s,t,r,i,n,o){let h,c,b=new Re(0,0);s[0].position=new Re(r.x,r.y),h=Ke.degreesToRadian(i),c=Ke.radianToDirection(h),c.normalize();for(let T=1;T<t;++T)s[T].force=c.multiplyByScaler(s[T].acceleration).add(n),s[T].lastPosition=new Re(s[T].position.x,s[T].position.y),s[T].velocity=new Re(0,0),b=s[T].force,b.normalize(),b=b.multiplyByScaler(s[T].radius),s[T].position=s[T-1].position.add(b),Ke.abs(s[T].position.x)<o&&(s[T].position.x=0),s[T].force=new Re(0,0),s[T].lastGravity=new Re(c.x,c.y)}function Pu(s,t,r,i,n){let o,h,c;o=n.getScale(n.translationScale,n.angleScale),h=i*o,h<t?(h<n.valueBelowMinimum&&(n.valueBelowMinimum=h),h=t):h>r&&(h>n.valueExceededMaximum&&(n.valueExceededMaximum=h),h=r),c=n.weight/Cu,c>=1||(h=s[0]*(1-c)+h*c),s[0]=h}function $u(s,t,r,i,n,o,h,c){let b=0;const T=Ke.max(r,t);T<s&&(s=T);const C=Ke.min(r,t);C>s&&(s=C);const x=Ke.min(n,o),$=Ke.max(n,o),I=h,B=py(C,T),U=s-B;switch(Math.sign(U)){case 1:{const G=$-I,z=T-B;z!=0&&(b=U*(G/z),b+=I);break}case-1:{const G=x-I,z=C-B;z!=0&&(b=U*(G/z),b+=I);break}case 0:{b=I;break}}return c?b:b*-1}oi.registerRuntime({version:4,ready:Y1,test(s){return s instanceof bn||bn.isValidJSON(s)},isValidMoc(s){if(s.byteLength<4)return!1;const t=new Int8Array(s,0,4);return String.fromCharCode(...t)==="MOC3"},createModelSettings(s){return new bn(s)},createCoreModel(s,t){const r=Tu.create(s,!!(t!=null&&t.checkMocConsistency));try{const i=r.createModel();return i.__moc=r,i}catch(i){try{r.release()}catch{}throw i}},createInternalModel(s,t,r){const i=new H1(s,t,r),n=s;return n.__moc&&(i.__moc=n.__moc,delete n.__moc,i.once("destroy",xy)),i},createPhysics(s,t){return Su.create(t)},createPose(s,t){return wu.create(t)}});function xy(){var s;(s=this.__moc)==null||s.release()}async function by(s){const{element_id:t="live2d-canvas",models:r,width:i=300,height:n=300,auto_fit:o=!0,auto_motion:h=!0,mouse_tracking:c=!0}=s;let b=Ay(t);const T=new Ul({view:b,width:i,height:n,backgroundAlpha:0,autoDensity:!0,antialias:!0}),C=await _u.from(r[0]);if(T.stage.addChild(C),o){const x=Math.min(i/C.width,n/C.height);C.scale.set(x),C.x=(i-C.width*x)/2,C.y=(n-C.height*x)/2}return c&&wy(C,T.view),h&&await Ty(C),C}function Ay(s){let t=document.getElementById(s);return t||(t=document.createElement("canvas"),t.id=s,document.body.appendChild(t),t.style.display="none",t.style.position="fixed"),t}function wy(s,t){document.addEventListener("mousemove",r=>{var b;const i=t.getBoundingClientRect(),n=i.left+i.width/2,o=i.top+i.height/2,h=(r.clientX-n)/i.width,c=(r.clientY-o)/i.height;s.internalModel&&((b=s.internalModel.focusController)==null||b.focus(h,c))})}async function Ty(s){var t;try{const r=(t=s.internalModel)==null?void 0:t.motionManager.definitions;if(r)if(r.idle)await s.motion("idle");else if(r.tap_body)await s.motion("tap_body");else{const i=Object.keys(r)[0];i&&await s.motion(i)}}catch(r){console.warn("Failed to start idle animation:",r)}}async function Ey(s,t){_u.registerTicker(vr),be.add(sa),be.add(Dm)}qr.Live2DModel=_u,qr.MotionManager=fo,qr.PIXI=Cm,qr.SoundManager=Mr,qr.createLive2dModel=by,qr.initializeLive2D=Ey,Object.defineProperty(qr,Symbol.toStringTag,{value:"Module"})});
1208
1208
  //# sourceMappingURL=l2d.umd.js.map