gdcore-tools 2.0.0-gd-v5.5.225-autobuild → 2.0.0-gd-v5.5.226-autobuild

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.
@@ -1,2 +1,2 @@
1
- var gdjs;(function(l){const x={3:0,2:1,5:2,4:3,0:4,1:5},M={0:3,1:2,2:5,3:4,4:0,5:1},n={0:[0,0],1:[1,0],2:[0,1],3:[1,1]},R={0:[0,1],1:[0,0],2:[1,1],3:[1,0]};let g;const _=()=>(g||(g=new THREE.MeshBasicMaterial({transparent:!0,opacity:0,alphaTest:1})),g),T=(h,i)=>h.isFaceAtIndexVisible(i)?h.getInstanceContainer().getGame().getImageManager().getThreeMaterial(h.getFaceAtIndexResourceName(i),{useTransparentTexture:h.shouldUseTransparentTexture(),forceBasicMaterial:h._materialType===l.Cube3DRuntimeObject.MaterialType.Basic}):_();class f extends l.RuntimeObject3DRenderer{constructor(i,t){const o=new THREE.BoxGeometry(1,1,1),m=new Array(6).fill(0).map((e,d)=>T(i,M[d])),b=new THREE.Mesh(o,m);super(i,t,b);this._boxMesh=b,this._cube3DRuntimeObject=i,this.updateSize(),this.updatePosition(),this.updateRotation(),this.updateTint()}updateTint(){const i=[],t=l.rgbOrHexToRGBColor(this._cube3DRuntimeObject.getColor()).map(o=>o/255);for(let o=0;o<this._boxMesh.geometry.attributes.position.count;o++)i.push(...t);this._boxMesh.geometry.setAttribute("color",new THREE.BufferAttribute(new Float32Array(i),3))}updateFace(i){const t=x[i];t!==void 0&&(this._boxMesh.material[t]=T(this._cube3DRuntimeObject,i),this._cube3DRuntimeObject.isFaceAtIndexVisible(i)&&this.updateTextureUvMapping(i))}updateSize(){super.updateSize(),this.updateTextureUvMapping()}updateTextureUvMapping(i){const t=this._boxMesh.geometry.getAttribute("position"),o=this._boxMesh.geometry.getAttribute("uv"),m=i===void 0?0:x[i]*4,b=i===void 0?23:x[i]*4+3;for(let e=m;e<=b;e++){const d=Math.floor(e/4),r=this._boxMesh.material[d];if(!r||!r.map)continue;const c=this._cube3DRuntimeObject.shouldRepeatTextureOnFaceAtIndex(M[d]),u=this._cube3DRuntimeObject.getFacesOrientation()==="Y";let a,s;switch(d){case 0:c?u?(a=-(this._boxMesh.scale.z/r.map.source.data.width)*(t.getZ(e)-.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):(a=-(this._boxMesh.scale.y/r.map.source.data.width)*(t.getY(e)-.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):u?[a,s]=n[e%4]:[a,s]=R[e%4];break;case 1:c?u?(a=this._boxMesh.scale.z/r.map.source.data.width*(t.getZ(e)+.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):(a=this._boxMesh.scale.y/r.map.source.data.width*(t.getY(e)+.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):u?[a,s]=n[e%4]:([a,s]=R[e%4],a=-a,s=-s);break;case 2:c?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):[a,s]=n[e%4];break;case 3:c?u?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=-(this._boxMesh.scale.z/r.map.source.data.height)*(t.getZ(e)+.5)):(a=-(this._boxMesh.scale.x/r.map.source.data.width)*(t.getX(e)-.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):([a,s]=n[e%4],u||(a=-a,s=-s));break;case 4:c?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):[a,s]=n[e%4];break;case 5:const p=this._cube3DRuntimeObject.getBackFaceUpThroughWhichAxisRotation()==="X";c?(a=(p?1:-1)*(this._boxMesh.scale.x/r.map.source.data.width)*(t.getX(e)+(p?1:-1)*.5),s=(p?1:-1)*(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+(p?-1:1)*.5)):([a,s]=n[e%4],p&&(a=-a,s=-s));break;default:[a,s]=n[e%4]}o.setXY(e,a,s)}o.needsUpdate=!0}_updateMaterials(){for(let i=0;i<6;i++)this.updateFace(i)}}l.Cube3DRuntimeObjectRenderer=f})(gdjs||(gdjs={}));
1
+ var gdjs;(function(p){const x={3:0,2:1,5:2,4:3,0:4,1:5},M={0:3,1:2,2:5,3:4,4:0,5:1},n={0:[0,0],1:[1,0],2:[0,1],3:[1,1]},R={0:[0,1],1:[0,0],2:[1,1],3:[1,0]};let g;const _=()=>(g||(g=new THREE.MeshBasicMaterial({transparent:!0,opacity:0,alphaTest:1})),g),T=(h,i)=>h.isFaceAtIndexVisible(i)?h.getInstanceContainer().getGame().getImageManager().getThreeMaterial(h.getFaceAtIndexResourceName(i),{useTransparentTexture:h.shouldUseTransparentTexture(),forceBasicMaterial:h._materialType===p.Cube3DRuntimeObject.MaterialType.Basic,vertexColors:!0}):_();class f extends p.RuntimeObject3DRenderer{constructor(i,t){const o=new THREE.BoxGeometry(1,1,1),m=new Array(6).fill(0).map((e,d)=>T(i,M[d])),b=new THREE.Mesh(o,m);super(i,t,b);this._boxMesh=b,this._cube3DRuntimeObject=i,this.updateSize(),this.updatePosition(),this.updateRotation(),this.updateTint()}updateTint(){const i=[],t=p.rgbOrHexToRGBColor(this._cube3DRuntimeObject.getColor()).map(o=>o/255);for(let o=0;o<this._boxMesh.geometry.attributes.position.count;o++)i.push(...t);this._boxMesh.geometry.setAttribute("color",new THREE.BufferAttribute(new Float32Array(i),3))}updateFace(i){const t=x[i];t!==void 0&&(this._boxMesh.material[t]=T(this._cube3DRuntimeObject,i),this._cube3DRuntimeObject.isFaceAtIndexVisible(i)&&this.updateTextureUvMapping(i))}updateSize(){super.updateSize(),this.updateTextureUvMapping()}updateTextureUvMapping(i){const t=this._boxMesh.geometry.getAttribute("position"),o=this._boxMesh.geometry.getAttribute("uv"),m=i===void 0?0:x[i]*4,b=i===void 0?23:x[i]*4+3;for(let e=m;e<=b;e++){const d=Math.floor(e/4),r=this._boxMesh.material[d];if(!r||!r.map)continue;const c=this._cube3DRuntimeObject.shouldRepeatTextureOnFaceAtIndex(M[d]),u=this._cube3DRuntimeObject.getFacesOrientation()==="Y";let a,s;switch(d){case 0:c?u?(a=-(this._boxMesh.scale.z/r.map.source.data.width)*(t.getZ(e)-.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):(a=-(this._boxMesh.scale.y/r.map.source.data.width)*(t.getY(e)-.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):u?[a,s]=n[e%4]:[a,s]=R[e%4];break;case 1:c?u?(a=this._boxMesh.scale.z/r.map.source.data.width*(t.getZ(e)+.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):(a=this._boxMesh.scale.y/r.map.source.data.width*(t.getY(e)+.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):u?[a,s]=n[e%4]:([a,s]=R[e%4],a=-a,s=-s);break;case 2:c?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):[a,s]=n[e%4];break;case 3:c?u?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=-(this._boxMesh.scale.z/r.map.source.data.height)*(t.getZ(e)+.5)):(a=-(this._boxMesh.scale.x/r.map.source.data.width)*(t.getX(e)-.5),s=this._boxMesh.scale.z/r.map.source.data.height*(t.getZ(e)-.5)):([a,s]=n[e%4],u||(a=-a,s=-s));break;case 4:c?(a=this._boxMesh.scale.x/r.map.source.data.width*(t.getX(e)+.5),s=-(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+.5)):[a,s]=n[e%4];break;case 5:const l=this._cube3DRuntimeObject.getBackFaceUpThroughWhichAxisRotation()==="X";c?(a=(l?1:-1)*(this._boxMesh.scale.x/r.map.source.data.width)*(t.getX(e)+(l?1:-1)*.5),s=(l?1:-1)*(this._boxMesh.scale.y/r.map.source.data.height)*(t.getY(e)+(l?-1:1)*.5)):([a,s]=n[e%4],l&&(a=-a,s=-s));break;default:[a,s]=n[e%4]}o.setXY(e,a,s)}o.needsUpdate=!0}_updateMaterials(){for(let i=0;i<6;i++)this.updateFace(i)}}p.Cube3DRuntimeObjectRenderer=f})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=Cube3DRuntimeObjectPixiRenderer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../GDevelop/Extensions/3D/Cube3DRuntimeObjectPixiRenderer.ts"],
4
- "sourcesContent": ["namespace gdjs {\n // Three.js materials for a cube and the order of faces in the object is different,\n // so we keep the mapping from one to the other.\n const faceIndexToMaterialIndex = {\n 3: 0, // right\n 2: 1, // left\n 5: 2, // bottom\n 4: 3, // top\n 0: 4, // front\n 1: 5, // back\n };\n const materialIndexToFaceIndex = {\n 0: 3,\n 1: 2,\n 2: 5,\n 3: 4,\n 4: 0,\n 5: 1,\n };\n\n const noRepeatTextureVertexIndexToUvMapping = {\n 0: [0, 0],\n 1: [1, 0],\n 2: [0, 1],\n 3: [1, 1],\n };\n\n const noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ = {\n 0: [0, 1],\n 1: [0, 0],\n 2: [1, 1],\n 3: [1, 0],\n };\n\n let transparentMaterial: THREE.MeshBasicMaterial;\n const getTransparentMaterial = () => {\n if (!transparentMaterial)\n transparentMaterial = new THREE.MeshBasicMaterial({\n transparent: true,\n opacity: 0,\n // Set the alpha test to to ensure the faces behind are rendered\n // (no \"back face culling\" that would still be done if alphaTest is not set).\n alphaTest: 1,\n });\n\n return transparentMaterial;\n };\n\n const getFaceMaterial = (\n runtimeObject: gdjs.Cube3DRuntimeObject,\n faceIndex: integer\n ) => {\n if (!runtimeObject.isFaceAtIndexVisible(faceIndex))\n return getTransparentMaterial();\n\n return runtimeObject\n .getInstanceContainer()\n .getGame()\n .getImageManager()\n .getThreeMaterial(runtimeObject.getFaceAtIndexResourceName(faceIndex), {\n useTransparentTexture: runtimeObject.shouldUseTransparentTexture(),\n forceBasicMaterial:\n runtimeObject._materialType ===\n gdjs.Cube3DRuntimeObject.MaterialType.Basic,\n });\n };\n\n class Cube3DRuntimeObjectPixiRenderer extends gdjs.RuntimeObject3DRenderer {\n private _cube3DRuntimeObject: gdjs.Cube3DRuntimeObject;\n private _boxMesh: THREE.Mesh;\n\n constructor(\n runtimeObject: gdjs.Cube3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n const geometry = new THREE.BoxGeometry(1, 1, 1);\n\n const materials: THREE.Material[] = new Array(6)\n .fill(0)\n .map((_, index) =>\n getFaceMaterial(runtimeObject, materialIndexToFaceIndex[index])\n );\n\n const boxMesh = new THREE.Mesh(geometry, materials);\n\n super(runtimeObject, instanceContainer, boxMesh);\n this._boxMesh = boxMesh;\n this._cube3DRuntimeObject = runtimeObject;\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n this.updateTint();\n }\n\n updateTint() {\n const tints: number[] = [];\n\n const normalizedTint = gdjs\n .rgbOrHexToRGBColor(this._cube3DRuntimeObject.getColor())\n .map((component) => component / 255);\n\n for (\n let i = 0;\n i < this._boxMesh.geometry.attributes.position.count;\n i++\n ) {\n tints.push(...normalizedTint);\n }\n\n this._boxMesh.geometry.setAttribute(\n 'color',\n new THREE.BufferAttribute(new Float32Array(tints), 3)\n );\n }\n\n updateFace(faceIndex: integer) {\n const materialIndex = faceIndexToMaterialIndex[faceIndex];\n if (materialIndex === undefined) return;\n\n this._boxMesh.material[materialIndex] = getFaceMaterial(\n this._cube3DRuntimeObject,\n faceIndex\n );\n if (this._cube3DRuntimeObject.isFaceAtIndexVisible(faceIndex)) {\n this.updateTextureUvMapping(faceIndex);\n }\n }\n\n updateSize(): void {\n super.updateSize();\n this.updateTextureUvMapping();\n }\n\n /**\n * Updates the UV mapping of the geometry in order to repeat a material\n * over the different faces of the cube.\n * The mesh must be configured with a list of materials in order\n * for the method to work.\n * @param faceIndex The face index to update. If undefined, updates all the faces.\n */\n updateTextureUvMapping(faceIndex?: number) {\n // @ts-ignore - position is stored as a Float32BufferAttribute\n const pos: THREE.BufferAttribute =\n this._boxMesh.geometry.getAttribute('position');\n // @ts-ignore - uv is stored as a Float32BufferAttribute\n const uvMapping: THREE.BufferAttribute =\n this._boxMesh.geometry.getAttribute('uv');\n const startIndex =\n faceIndex === undefined ? 0 : faceIndexToMaterialIndex[faceIndex] * 4;\n const endIndex =\n faceIndex === undefined\n ? 23\n : faceIndexToMaterialIndex[faceIndex] * 4 + 3;\n for (\n let vertexIndex = startIndex;\n vertexIndex <= endIndex;\n vertexIndex++\n ) {\n const materialIndex = Math.floor(\n vertexIndex /\n // Each face of the cube has 4 points\n 4\n );\n const material = this._boxMesh.material[materialIndex];\n if (!material || !material.map) {\n continue;\n }\n\n const shouldRepeatTexture =\n this._cube3DRuntimeObject.shouldRepeatTextureOnFaceAtIndex(\n materialIndexToFaceIndex[materialIndex]\n );\n\n const shouldOrientateFacesTowardsY =\n this._cube3DRuntimeObject.getFacesOrientation() === 'Y';\n\n let x: float, y: float;\n switch (materialIndex) {\n case 0:\n // Right face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n -(this._boxMesh.scale.z / material.map.source.data.width) *\n (pos.getZ(vertexIndex) - 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n x =\n -(this._boxMesh.scale.y / material.map.source.data.width) *\n (pos.getY(vertexIndex) - 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n if (shouldOrientateFacesTowardsY) {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n } else {\n [x, y] =\n noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[\n vertexIndex % 4\n ];\n }\n }\n break;\n case 1:\n // Left face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n (this._boxMesh.scale.z / material.map.source.data.width) *\n (pos.getZ(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n x =\n (this._boxMesh.scale.y / material.map.source.data.width) *\n (pos.getY(vertexIndex) + 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n if (shouldOrientateFacesTowardsY) {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n } else {\n [x, y] =\n noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[\n vertexIndex % 4\n ];\n x = -x;\n y = -y;\n }\n }\n break;\n case 2:\n // Bottom face\n if (shouldRepeatTexture) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n break;\n case 3:\n // Top face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) + 0.5);\n } else {\n x =\n -(this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) - 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n if (!shouldOrientateFacesTowardsY) {\n x = -x;\n y = -y;\n }\n }\n break;\n case 4:\n // Front face\n if (shouldRepeatTexture) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n break;\n case 5:\n // Back face\n const shouldBackFaceBeUpThroughXAxisRotation =\n this._cube3DRuntimeObject.getBackFaceUpThroughWhichAxisRotation() ===\n 'X';\n\n if (shouldRepeatTexture) {\n x =\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) *\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) +\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) * 0.5);\n y =\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) *\n (this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) +\n (shouldBackFaceBeUpThroughXAxisRotation ? -1 : 1) * 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n if (shouldBackFaceBeUpThroughXAxisRotation) {\n x = -x;\n y = -y;\n }\n }\n break;\n default:\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n uvMapping.setXY(vertexIndex, x, y);\n }\n uvMapping.needsUpdate = true;\n }\n\n _updateMaterials() {\n for (let index = 0; index < 6; index++) {\n this.updateFace(index);\n }\n }\n }\n\n export const Cube3DRuntimeObjectRenderer = Cube3DRuntimeObjectPixiRenderer;\n export type Cube3DRuntimeObjectRenderer = Cube3DRuntimeObjectPixiRenderer;\n}\n"],
5
- "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAGE,KAAM,GAA2B,CAC/B,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,GAEC,EAA2B,CAC/B,EAAG,EACH,EAAG,EAC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AEH,KAAM,GACJ,KAAK,qBAAqB,0CAC1B,IAEF,AAAI,EACF,GACG,GAAyC,EAAI,IAC7C,MAAK,SAAS,MAAM,EAAI,EAAS,IAAI,OAAO,KAAK,OACjD,GAAI,KAAK,GACP,GAAyC,EAAI,IAAM,IACxD,EACG,GAAyC,EAAI,IAC7C,MAAK,SAAS,MAAM,EAAI,EAAS,IAAI,OAAO,KAAK,QACjD,GAAI,KAAK,GACP,GAAyC,GAAK,GAAK,KAExD,EAAC,EAAG,GAAK,EAAsC,EAAc,GACzD,GACF,GAAI,CAAC,EACL,EAAI,CAAC,IAGT,cAEA,CAAC,EAAG,GAAK,EAAsC,EAAc,GAEjE,EAAU,MAAM,EAAa,EAAG,GAElC,EAAU,YAAc,GAG1B,kBAAmB,CACjB,OAAS,GAAQ,EAAG,EAAQ,EAAG,IAC7B,KAAK,WAAW,IAKf,AAAM,8BAA8B,IA3UnC",
4
+ "sourcesContent": ["namespace gdjs {\n // Three.js materials for a cube and the order of faces in the object is different,\n // so we keep the mapping from one to the other.\n const faceIndexToMaterialIndex = {\n 3: 0, // right\n 2: 1, // left\n 5: 2, // bottom\n 4: 3, // top\n 0: 4, // front\n 1: 5, // back\n };\n const materialIndexToFaceIndex = {\n 0: 3,\n 1: 2,\n 2: 5,\n 3: 4,\n 4: 0,\n 5: 1,\n };\n\n const noRepeatTextureVertexIndexToUvMapping = {\n 0: [0, 0],\n 1: [1, 0],\n 2: [0, 1],\n 3: [1, 1],\n };\n\n const noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ = {\n 0: [0, 1],\n 1: [0, 0],\n 2: [1, 1],\n 3: [1, 0],\n };\n\n let transparentMaterial: THREE.MeshBasicMaterial;\n const getTransparentMaterial = () => {\n if (!transparentMaterial)\n transparentMaterial = new THREE.MeshBasicMaterial({\n transparent: true,\n opacity: 0,\n // Set the alpha test to to ensure the faces behind are rendered\n // (no \"back face culling\" that would still be done if alphaTest is not set).\n alphaTest: 1,\n });\n\n return transparentMaterial;\n };\n\n const getFaceMaterial = (\n runtimeObject: gdjs.Cube3DRuntimeObject,\n faceIndex: integer\n ) => {\n if (!runtimeObject.isFaceAtIndexVisible(faceIndex))\n return getTransparentMaterial();\n\n return runtimeObject\n .getInstanceContainer()\n .getGame()\n .getImageManager()\n .getThreeMaterial(runtimeObject.getFaceAtIndexResourceName(faceIndex), {\n useTransparentTexture: runtimeObject.shouldUseTransparentTexture(),\n forceBasicMaterial:\n runtimeObject._materialType ===\n gdjs.Cube3DRuntimeObject.MaterialType.Basic,\n vertexColors: true,\n });\n };\n\n class Cube3DRuntimeObjectPixiRenderer extends gdjs.RuntimeObject3DRenderer {\n private _cube3DRuntimeObject: gdjs.Cube3DRuntimeObject;\n private _boxMesh: THREE.Mesh;\n\n constructor(\n runtimeObject: gdjs.Cube3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n const geometry = new THREE.BoxGeometry(1, 1, 1);\n\n const materials: THREE.Material[] = new Array(6)\n .fill(0)\n .map((_, index) =>\n getFaceMaterial(runtimeObject, materialIndexToFaceIndex[index])\n );\n\n const boxMesh = new THREE.Mesh(geometry, materials);\n\n super(runtimeObject, instanceContainer, boxMesh);\n this._boxMesh = boxMesh;\n this._cube3DRuntimeObject = runtimeObject;\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n this.updateTint();\n }\n\n updateTint() {\n const tints: number[] = [];\n\n const normalizedTint = gdjs\n .rgbOrHexToRGBColor(this._cube3DRuntimeObject.getColor())\n .map((component) => component / 255);\n\n for (\n let i = 0;\n i < this._boxMesh.geometry.attributes.position.count;\n i++\n ) {\n tints.push(...normalizedTint);\n }\n\n this._boxMesh.geometry.setAttribute(\n 'color',\n new THREE.BufferAttribute(new Float32Array(tints), 3)\n );\n }\n\n updateFace(faceIndex: integer) {\n const materialIndex = faceIndexToMaterialIndex[faceIndex];\n if (materialIndex === undefined) return;\n\n this._boxMesh.material[materialIndex] = getFaceMaterial(\n this._cube3DRuntimeObject,\n faceIndex\n );\n if (this._cube3DRuntimeObject.isFaceAtIndexVisible(faceIndex)) {\n this.updateTextureUvMapping(faceIndex);\n }\n }\n\n updateSize(): void {\n super.updateSize();\n this.updateTextureUvMapping();\n }\n\n /**\n * Updates the UV mapping of the geometry in order to repeat a material\n * over the different faces of the cube.\n * The mesh must be configured with a list of materials in order\n * for the method to work.\n * @param faceIndex The face index to update. If undefined, updates all the faces.\n */\n updateTextureUvMapping(faceIndex?: number) {\n // @ts-ignore - position is stored as a Float32BufferAttribute\n const pos: THREE.BufferAttribute =\n this._boxMesh.geometry.getAttribute('position');\n // @ts-ignore - uv is stored as a Float32BufferAttribute\n const uvMapping: THREE.BufferAttribute =\n this._boxMesh.geometry.getAttribute('uv');\n const startIndex =\n faceIndex === undefined ? 0 : faceIndexToMaterialIndex[faceIndex] * 4;\n const endIndex =\n faceIndex === undefined\n ? 23\n : faceIndexToMaterialIndex[faceIndex] * 4 + 3;\n for (\n let vertexIndex = startIndex;\n vertexIndex <= endIndex;\n vertexIndex++\n ) {\n const materialIndex = Math.floor(\n vertexIndex /\n // Each face of the cube has 4 points\n 4\n );\n const material = this._boxMesh.material[materialIndex];\n if (!material || !material.map) {\n continue;\n }\n\n const shouldRepeatTexture =\n this._cube3DRuntimeObject.shouldRepeatTextureOnFaceAtIndex(\n materialIndexToFaceIndex[materialIndex]\n );\n\n const shouldOrientateFacesTowardsY =\n this._cube3DRuntimeObject.getFacesOrientation() === 'Y';\n\n let x: float, y: float;\n switch (materialIndex) {\n case 0:\n // Right face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n -(this._boxMesh.scale.z / material.map.source.data.width) *\n (pos.getZ(vertexIndex) - 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n x =\n -(this._boxMesh.scale.y / material.map.source.data.width) *\n (pos.getY(vertexIndex) - 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n if (shouldOrientateFacesTowardsY) {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n } else {\n [x, y] =\n noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[\n vertexIndex % 4\n ];\n }\n }\n break;\n case 1:\n // Left face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n (this._boxMesh.scale.z / material.map.source.data.width) *\n (pos.getZ(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n x =\n (this._boxMesh.scale.y / material.map.source.data.width) *\n (pos.getY(vertexIndex) + 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n if (shouldOrientateFacesTowardsY) {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n } else {\n [x, y] =\n noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[\n vertexIndex % 4\n ];\n x = -x;\n y = -y;\n }\n }\n break;\n case 2:\n // Bottom face\n if (shouldRepeatTexture) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n break;\n case 3:\n // Top face\n if (shouldRepeatTexture) {\n if (shouldOrientateFacesTowardsY) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) + 0.5);\n } else {\n x =\n -(this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) - 0.5);\n y =\n (this._boxMesh.scale.z / material.map.source.data.height) *\n (pos.getZ(vertexIndex) - 0.5);\n }\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n if (!shouldOrientateFacesTowardsY) {\n x = -x;\n y = -y;\n }\n }\n break;\n case 4:\n // Front face\n if (shouldRepeatTexture) {\n x =\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) + 0.5);\n y =\n -(this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) + 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n break;\n case 5:\n // Back face\n const shouldBackFaceBeUpThroughXAxisRotation =\n this._cube3DRuntimeObject.getBackFaceUpThroughWhichAxisRotation() ===\n 'X';\n\n if (shouldRepeatTexture) {\n x =\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) *\n (this._boxMesh.scale.x / material.map.source.data.width) *\n (pos.getX(vertexIndex) +\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) * 0.5);\n y =\n (shouldBackFaceBeUpThroughXAxisRotation ? 1 : -1) *\n (this._boxMesh.scale.y / material.map.source.data.height) *\n (pos.getY(vertexIndex) +\n (shouldBackFaceBeUpThroughXAxisRotation ? -1 : 1) * 0.5);\n } else {\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n if (shouldBackFaceBeUpThroughXAxisRotation) {\n x = -x;\n y = -y;\n }\n }\n break;\n default:\n [x, y] = noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];\n }\n uvMapping.setXY(vertexIndex, x, y);\n }\n uvMapping.needsUpdate = true;\n }\n\n _updateMaterials() {\n for (let index = 0; index < 6; index++) {\n this.updateFace(index);\n }\n }\n }\n\n export const Cube3DRuntimeObjectRenderer = Cube3DRuntimeObjectPixiRenderer;\n export type Cube3DRuntimeObjectRenderer = Cube3DRuntimeObjectPixiRenderer;\n}\n"],
5
+ "mappings": "AAAA,GAAU,MAAV,UAAU,E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IAC3B,EACE,CAAE,MAAK,SAAS,MAAM,EAAI,EAAS,IAAI,OAAO,KAAK,QAClD,GAAI,KAAK,GAAe,KAE3B,CAAC,EAAG,GAAK,EAAsC,EAAc,GAE/D,UACG,GAEH,KAAM,GACJ,KAAK,qBAAqB,0CAC1B,IAEF,AAAI,EACF,GACG,GAAyC,EAAI,IAC7C,MAAK,SAAS,MAAM,EAAI,EAAS,IAAI,OAAO,KAAK,OACjD,GAAI,KAAK,GACP,GAAyC,EAAI,IAAM,IACxD,EACG,GAAyC,EAAI,IAC7C,MAAK,SAAS,MAAM,EAAI,EAAS,IAAI,OAAO,KAAK,QACjD,GAAI,KAAK,GACP,GAAyC,GAAK,GAAK,KAExD,EAAC,EAAG,GAAK,EAAsC,EAAc,GACzD,GACF,GAAI,CAAC,EACL,EAAI,CAAC,IAGT,cAEA,CAAC,EAAG,GAAK,EAAsC,EAAc,GAEjE,EAAU,MAAM,EAAa,EAAG,GAElC,EAAU,YAAc,GAG1B,kBAAmB,CACjB,OAAS,GAAQ,EAAG,EAAQ,EAAG,IAC7B,KAAK,WAAW,IAKf,AAAM,8BAA8B,IA5UnC",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){class u{constructor(e,t,i){this._isContainerDirty=!0;this._object=e,this._instanceContainer=t,this._threeGroup=new THREE.Group,this._threeGroup.rotation.order="ZYX";const r=i.getLayer("");r&&r.getRenderer().add3DRendererObject(this._threeGroup)}get3DRendererObject(){return this._threeGroup}getRendererObject(){return null}reinitialize(e,t){this._object=e,this._isContainerDirty=!0;const i=t.getLayer("");i&&i.getRenderer().add3DRendererObject(this._threeGroup)}_updateThreeGroup(){const e=this.get3DRendererObject(),t=this._object.getScaleX(),i=this._object.getScaleY(),r=this._object.getScaleZ(),n=this._object.getUnscaledCenterX()*t,s=this._object.getUnscaledCenterY()*i,o=this._object.getUnscaledCenterZ()*r;e.rotation.set(a.toRad(this._object.getRotationX()),a.toRad(this._object.getRotationY()),a.toRad(this._object.angle)),e.position.set(this._object.isFlippedX()?n:-n,this._object.isFlippedY()?s:-s,this._object.isFlippedZ()?o:-o),e.position.applyEuler(e.rotation),e.position.x+=this._object.getX()+n,e.position.y+=this._object.getY()+s,e.position.z+=this._object.getZ()+o,e.scale.set(this._object.isFlippedX()?-t:t,this._object.isFlippedY()?-i:i,this._object.isFlippedZ()?-r:r),e.visible=!this._object.hidden,this._isContainerDirty=!1}ensureUpToDate(){this._isContainerDirty&&this._updateThreeGroup()}update(){this._isContainerDirty=!0}updateX(){this._isContainerDirty=!0}updateY(){this._isContainerDirty=!0}updateAngle(){this._isContainerDirty=!0}updatePosition(){this._isContainerDirty=!0}updateRotation(){this._isContainerDirty=!0}updateSize(){this._isContainerDirty=!0}updateVisibility(){this._threeGroup.visible=!this._object.hidden}updateOpacity(){}setLayerIndex(e,t){}static getAnimationFrameTextureManager(e){return e._threeAnimationFrameTextureManager||(e._threeAnimationFrameTextureManager=new c(e)),e._threeAnimationFrameTextureManager}}a.CustomRuntimeObject3DRenderer=u;class c{constructor(e){this._imageManager=e}getAnimationFrameTexture(e){return this._imageManager.getThreeMaterial(e,{useTransparentTexture:!0,forceBasicMaterial:!0})}getAnimationFrameWidth(e){const t=e.map;return t?t.image.width:0}getAnimationFrameHeight(e){const t=e.map;return t?t.image.height:0}}})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){class u{constructor(e,t,i){this._isContainerDirty=!0;this._object=e,this._instanceContainer=t,this._threeGroup=new THREE.Group,this._threeGroup.rotation.order="ZYX";const r=i.getLayer("");r&&r.getRenderer().add3DRendererObject(this._threeGroup)}get3DRendererObject(){return this._threeGroup}getRendererObject(){return null}reinitialize(e,t){this._object=e,this._isContainerDirty=!0;const i=t.getLayer("");i&&i.getRenderer().add3DRendererObject(this._threeGroup)}_updateThreeGroup(){const e=this.get3DRendererObject(),t=this._object.getScaleX(),i=this._object.getScaleY(),r=this._object.getScaleZ(),n=this._object.getUnscaledCenterX()*t,s=this._object.getUnscaledCenterY()*i,o=this._object.getUnscaledCenterZ()*r;e.rotation.set(a.toRad(this._object.getRotationX()),a.toRad(this._object.getRotationY()),a.toRad(this._object.angle)),e.position.set(this._object.isFlippedX()?n:-n,this._object.isFlippedY()?s:-s,this._object.isFlippedZ()?o:-o),e.position.applyEuler(e.rotation),e.position.x+=this._object.getX()+n,e.position.y+=this._object.getY()+s,e.position.z+=this._object.getZ()+o,e.scale.set(this._object.isFlippedX()?-t:t,this._object.isFlippedY()?-i:i,this._object.isFlippedZ()?-r:r),e.visible=!this._object.hidden,this._isContainerDirty=!1}ensureUpToDate(){this._isContainerDirty&&this._updateThreeGroup()}update(){this._isContainerDirty=!0}updateX(){this._isContainerDirty=!0}updateY(){this._isContainerDirty=!0}updateAngle(){this._isContainerDirty=!0}updatePosition(){this._isContainerDirty=!0}updateRotation(){this._isContainerDirty=!0}updateSize(){this._isContainerDirty=!0}updateVisibility(){this._threeGroup.visible=!this._object.hidden}updateOpacity(){}setLayerIndex(e,t){}static getAnimationFrameTextureManager(e){return e._threeAnimationFrameTextureManager||(e._threeAnimationFrameTextureManager=new c(e)),e._threeAnimationFrameTextureManager}}a.CustomRuntimeObject3DRenderer=u;class c{constructor(e){this._imageManager=e}getAnimationFrameTexture(e){return this._imageManager.getThreeMaterial(e,{useTransparentTexture:!0,forceBasicMaterial:!0,vertexColors:!1})}getAnimationFrameWidth(e){const t=e.map;return t?t.image.width:0}getAnimationFrameHeight(e){const t=e.map;return t?t.image.height:0}}})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=CustomRuntimeObject3DRenderer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../GDevelop/Extensions/3D/CustomRuntimeObject3DRenderer.ts"],
4
- "sourcesContent": ["namespace gdjs {\n export interface PixiImageManager {\n _threeAnimationFrameTextureManager: ThreeAnimationFrameTextureManager;\n }\n /**\n * The renderer for a {@link gdjs.CustomRuntimeObject3D} using Three.js.\n */\n export class CustomRuntimeObject3DRenderer\n implements gdjs.RuntimeInstanceContainerRenderer\n {\n _object: gdjs.CustomRuntimeObject3D;\n _instanceContainer: gdjs.CustomRuntimeObjectInstanceContainer;\n _isContainerDirty: boolean = true;\n _threeGroup: THREE.Group;\n\n constructor(\n object: gdjs.CustomRuntimeObject3D,\n instanceContainer: gdjs.CustomRuntimeObjectInstanceContainer,\n parent: gdjs.RuntimeInstanceContainer\n ) {\n this._object = object;\n this._instanceContainer = instanceContainer;\n\n this._threeGroup = new THREE.Group();\n this._threeGroup.rotation.order = 'ZYX';\n\n const layer = parent.getLayer('');\n if (layer) {\n layer.getRenderer().add3DRendererObject(this._threeGroup);\n }\n }\n\n get3DRendererObject(): THREE.Object3D {\n return this._threeGroup;\n }\n\n getRendererObject() {\n return null;\n }\n\n reinitialize(\n object: gdjs.CustomRuntimeObject3D,\n parent: gdjs.RuntimeInstanceContainer\n ) {\n this._object = object;\n this._isContainerDirty = true;\n const layer = parent.getLayer('');\n if (layer) {\n layer.getRenderer().add3DRendererObject(this._threeGroup);\n }\n }\n\n _updateThreeGroup() {\n const threeObject3D = this.get3DRendererObject();\n\n const scaleX = this._object.getScaleX();\n const scaleY = this._object.getScaleY();\n const scaleZ = this._object.getScaleZ();\n const pivotX = this._object.getUnscaledCenterX() * scaleX;\n const pivotY = this._object.getUnscaledCenterY() * scaleY;\n const pivotZ = this._object.getUnscaledCenterZ() * scaleZ;\n\n threeObject3D.rotation.set(\n gdjs.toRad(this._object.getRotationX()),\n gdjs.toRad(this._object.getRotationY()),\n gdjs.toRad(this._object.angle)\n );\n\n threeObject3D.position.set(\n this._object.isFlippedX() ? pivotX : -pivotX,\n this._object.isFlippedY() ? pivotY : -pivotY,\n this._object.isFlippedZ() ? pivotZ : -pivotZ\n );\n threeObject3D.position.applyEuler(threeObject3D.rotation);\n threeObject3D.position.x += this._object.getX() + pivotX;\n threeObject3D.position.y += this._object.getY() + pivotY;\n threeObject3D.position.z += this._object.getZ() + pivotZ;\n\n threeObject3D.scale.set(\n this._object.isFlippedX() ? -scaleX : scaleX,\n this._object.isFlippedY() ? -scaleY : scaleY,\n this._object.isFlippedZ() ? -scaleZ : scaleZ\n );\n\n threeObject3D.visible = !this._object.hidden;\n\n this._isContainerDirty = false;\n }\n\n /**\n * Call this to make sure the object is ready to be rendered.\n */\n ensureUpToDate() {\n if (this._isContainerDirty) {\n this._updateThreeGroup();\n }\n }\n\n update(): void {\n this._isContainerDirty = true;\n }\n\n updateX(): void {\n this._isContainerDirty = true;\n }\n\n updateY(): void {\n this._isContainerDirty = true;\n }\n\n updateAngle(): void {\n this._isContainerDirty = true;\n }\n\n updatePosition() {\n this._isContainerDirty = true;\n }\n\n updateRotation() {\n this._isContainerDirty = true;\n }\n\n updateSize() {\n this._isContainerDirty = true;\n }\n\n updateVisibility(): void {\n this._threeGroup.visible = !this._object.hidden;\n }\n\n updateOpacity(): void {\n // Opacity is not handled by 3D custom objects.\n }\n\n setLayerIndex(layer: gdjs.RuntimeLayer, index: float): void {\n // Layers are not handled for 3D custom objects.\n }\n\n static getAnimationFrameTextureManager(\n imageManager: gdjs.PixiImageManager\n ): ThreeAnimationFrameTextureManager {\n if (!imageManager._threeAnimationFrameTextureManager) {\n imageManager._threeAnimationFrameTextureManager =\n new ThreeAnimationFrameTextureManager(imageManager);\n }\n return imageManager._threeAnimationFrameTextureManager;\n }\n }\n\n class ThreeAnimationFrameTextureManager\n implements gdjs.AnimationFrameTextureManager<THREE.Material>\n {\n private _imageManager: gdjs.PixiImageManager;\n\n constructor(imageManager: gdjs.PixiImageManager) {\n this._imageManager = imageManager;\n }\n\n getAnimationFrameTexture(imageName: string) {\n return this._imageManager.getThreeMaterial(imageName, {\n useTransparentTexture: true,\n forceBasicMaterial: true,\n });\n }\n\n getAnimationFrameWidth(material: THREE.Material) {\n const map = (\n material as THREE.MeshBasicMaterial | THREE.MeshStandardMaterial\n ).map;\n return map ? map.image.width : 0;\n }\n\n getAnimationFrameHeight(material: THREE.Material) {\n const map = (\n material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AAK,QAAQ,aAAe,CAAC,EAAS,EACtC,KAAK,QAAQ,aAAe,CAAC,EAAS,GAGxC,EAAc,QAAU,CAAC,KAAK,QAAQ,OAEtC,KAAK,kBAAoB,GAM3B,gBAAiB,CACf,AAAI,KAAK,mBACP,KAAK,oBAIT,QAAe,CACb,KAAK,kBAAoB,GAG3B,SAAgB,CACd,KAAK,kBAAoB,GAG3B,SAAgB,CACd,KAAK,kBAAoB,GAG3B,aAAoB,CAClB,KAAK,kBAAoB,GAG3B,gBAAiB,CACf,KAAK,kBAAoB,GAG3B,gBAAiB,CACf,KAAK,kBAAoB,GAG3B,YAAa,CACX,KAAK,kBAAoB,GAG3B,kBAAyB,CACvB,KAAK,YAAY,QAAU,CAAC,KAAK,QAAQ,OAG3C,eAAsB,EAItB,cAAc,EAA0B,EAAoB,QAIrD,iCACL,EACmC,CACnC,MAAK,GAAa,oCAChB,GAAa,mCACX,GAAI,GAAkC,IAEnC,EAAa,oCA1IjB,EAAM,gCA8Ib,OAEA,CAGE,YAAY,EAAqC,CAC/C,KAAK,cAAgB,EAGvB,yBAAyB,EAAmB,CAC1C,MAAO,MAAK,cAAc,iBAAiB,EAAW,CACpD,sBAAuB,GACvB,mBAAoB,KAIxB,uBAAuB,EAA0B,CAC/C,KAAM,GACJ,EACA,IACF,MAAO,GAAM,EAAI,MAAM,MAAQ,EAGjC,wBAAwB,EAA0B,CAChD,KAAM,GACJ,EACA,IACF,MAAO,GAAM,EAAI,MAAM,OAAS,MAhL5B",
4
+ "sourcesContent": ["namespace gdjs {\n export interface PixiImageManager {\n _threeAnimationFrameTextureManager: ThreeAnimationFrameTextureManager;\n }\n /**\n * The renderer for a {@link gdjs.CustomRuntimeObject3D} using Three.js.\n */\n export class CustomRuntimeObject3DRenderer\n implements gdjs.RuntimeInstanceContainerRenderer\n {\n _object: gdjs.CustomRuntimeObject3D;\n _instanceContainer: gdjs.CustomRuntimeObjectInstanceContainer;\n _isContainerDirty: boolean = true;\n _threeGroup: THREE.Group;\n\n constructor(\n object: gdjs.CustomRuntimeObject3D,\n instanceContainer: gdjs.CustomRuntimeObjectInstanceContainer,\n parent: gdjs.RuntimeInstanceContainer\n ) {\n this._object = object;\n this._instanceContainer = instanceContainer;\n\n this._threeGroup = new THREE.Group();\n this._threeGroup.rotation.order = 'ZYX';\n\n const layer = parent.getLayer('');\n if (layer) {\n layer.getRenderer().add3DRendererObject(this._threeGroup);\n }\n }\n\n get3DRendererObject(): THREE.Object3D {\n return this._threeGroup;\n }\n\n getRendererObject() {\n return null;\n }\n\n reinitialize(\n object: gdjs.CustomRuntimeObject3D,\n parent: gdjs.RuntimeInstanceContainer\n ) {\n this._object = object;\n this._isContainerDirty = true;\n const layer = parent.getLayer('');\n if (layer) {\n layer.getRenderer().add3DRendererObject(this._threeGroup);\n }\n }\n\n _updateThreeGroup() {\n const threeObject3D = this.get3DRendererObject();\n\n const scaleX = this._object.getScaleX();\n const scaleY = this._object.getScaleY();\n const scaleZ = this._object.getScaleZ();\n const pivotX = this._object.getUnscaledCenterX() * scaleX;\n const pivotY = this._object.getUnscaledCenterY() * scaleY;\n const pivotZ = this._object.getUnscaledCenterZ() * scaleZ;\n\n threeObject3D.rotation.set(\n gdjs.toRad(this._object.getRotationX()),\n gdjs.toRad(this._object.getRotationY()),\n gdjs.toRad(this._object.angle)\n );\n\n threeObject3D.position.set(\n this._object.isFlippedX() ? pivotX : -pivotX,\n this._object.isFlippedY() ? pivotY : -pivotY,\n this._object.isFlippedZ() ? pivotZ : -pivotZ\n );\n threeObject3D.position.applyEuler(threeObject3D.rotation);\n threeObject3D.position.x += this._object.getX() + pivotX;\n threeObject3D.position.y += this._object.getY() + pivotY;\n threeObject3D.position.z += this._object.getZ() + pivotZ;\n\n threeObject3D.scale.set(\n this._object.isFlippedX() ? -scaleX : scaleX,\n this._object.isFlippedY() ? -scaleY : scaleY,\n this._object.isFlippedZ() ? -scaleZ : scaleZ\n );\n\n threeObject3D.visible = !this._object.hidden;\n\n this._isContainerDirty = false;\n }\n\n /**\n * Call this to make sure the object is ready to be rendered.\n */\n ensureUpToDate() {\n if (this._isContainerDirty) {\n this._updateThreeGroup();\n }\n }\n\n update(): void {\n this._isContainerDirty = true;\n }\n\n updateX(): void {\n this._isContainerDirty = true;\n }\n\n updateY(): void {\n this._isContainerDirty = true;\n }\n\n updateAngle(): void {\n this._isContainerDirty = true;\n }\n\n updatePosition() {\n this._isContainerDirty = true;\n }\n\n updateRotation() {\n this._isContainerDirty = true;\n }\n\n updateSize() {\n this._isContainerDirty = true;\n }\n\n updateVisibility(): void {\n this._threeGroup.visible = !this._object.hidden;\n }\n\n updateOpacity(): void {\n // Opacity is not handled by 3D custom objects.\n }\n\n setLayerIndex(layer: gdjs.RuntimeLayer, index: float): void {\n // Layers are not handled for 3D custom objects.\n }\n\n static getAnimationFrameTextureManager(\n imageManager: gdjs.PixiImageManager\n ): ThreeAnimationFrameTextureManager {\n if (!imageManager._threeAnimationFrameTextureManager) {\n imageManager._threeAnimationFrameTextureManager =\n new ThreeAnimationFrameTextureManager(imageManager);\n }\n return imageManager._threeAnimationFrameTextureManager;\n }\n }\n\n class ThreeAnimationFrameTextureManager\n implements gdjs.AnimationFrameTextureManager<THREE.Material>\n {\n private _imageManager: gdjs.PixiImageManager;\n\n constructor(imageManager: gdjs.PixiImageManager) {\n this._imageManager = imageManager;\n }\n\n getAnimationFrameTexture(imageName: string) {\n return this._imageManager.getThreeMaterial(imageName, {\n useTransparentTexture: true,\n forceBasicMaterial: true,\n vertexColors: false,\n });\n }\n\n getAnimationFrameWidth(material: THREE.Material) {\n const map = (\n material as THREE.MeshBasicMaterial | THREE.MeshStandardMaterial\n ).map;\n return map ? map.image.width : 0;\n }\n\n getAnimationFrameHeight(material: THREE.Material) {\n const map = (\n material as THREE.MeshBasicMaterial | THREE.MeshStandardMaterial\n ).map;\n return map ? map.image.height : 0;\n }\n }\n}\n"],
5
+ "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAOS,OAEP,CAME,YACE,EAC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CACf,AAAI,KAAK,mBACP,KAAK,oBAIT,QAAe,CACb,KAAK,kBAAoB,GAG3B,SAAgB,CACd,KAAK,kBAAoB,GAG3B,SAAgB,CACd,KAAK,kBAAoB,GAG3B,aAAoB,CAClB,KAAK,kBAAoB,GAG3B,gBAAiB,CACf,KAAK,kBAAoB,GAG3B,gBAAiB,CACf,KAAK,kBAAoB,GAG3B,YAAa,CACX,KAAK,kBAAoB,GAG3B,kBAAyB,CACvB,KAAK,YAAY,QAAU,CAAC,KAAK,QAAQ,OAG3C,eAAsB,EAItB,cAAc,EAA0B,EAAoB,QAIrD,iCACL,EACmC,CACnC,MAAK,GAAa,oCAChB,GAAa,mCACX,GAAI,GAAkC,IAEnC,EAAa,oCA1IjB,EAAM,gCA8Ib,OAEA,CAGE,YAAY,EAAqC,CAC/C,KAAK,cAAgB,EAGvB,yBAAyB,EAAmB,CAC1C,MAAO,MAAK,cAAc,iBAAiB,EAAW,CACpD,sBAAuB,GACvB,mBAAoB,GACpB,aAAc,KAIlB,uBAAuB,EAA0B,CAC/C,KAAM,GACJ,EACA,IACF,MAAO,GAAM,EAAI,MAAM,MAAQ,EAGjC,wBAAwB,EAA0B,CAChD,KAAM,GACJ,EACA,IACF,MAAO,GAAM,EAAI,MAAM,OAAS,MAjL5B",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){const s=1/(1<<16),g=i=>{i.metalness&&(i.metalness=0)},O=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)g(t.material[e]);else g(t.material)},T=i=>i.traverse(O),M=i=>{const t=new THREE.MeshBasicMaterial;return i.color&&(t.color=i.color),i.map&&(t.map=i.map),t},b=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)t.material[e]=M(t.material[e]);else t.material=M(t.material)},D=i=>i.traverse(b);class j extends a.RuntimeObject3DRenderer{constructor(t,e){const r=e.getGame().getModel3DManager().getModel(t._modelResourceName),o=new THREE.Group,h=new THREE.Group;h.rotation.order="ZYX",h.add(o);super(t,e,h);this._model3DRuntimeObject=t,this._threeObject=o,this._originalModel=r,this._modelOriginPoint=[0,0,0],this.updateSize(),this.updatePosition(),this.updateRotation(),this._animationMixer=new THREE.AnimationMixer(o),this._action=null}updateAnimation(t){this._animationMixer.update(t)}updatePosition(){const t=this.getOriginPoint(),e=this.getCenterPoint();this.get3DRendererObject().position.set(this._object.getX()-this._object.getWidth()*(t[0]-e[0]),this._object.getY()-this._object.getHeight()*(t[1]-e[1]),this._object.getZ()-this._object.getDepth()*(t[2]-e[2]))}getOriginPoint(){return this._model3DRuntimeObject._originPoint||this._modelOriginPoint}getCenterPoint(){return this._model3DRuntimeObject._centerPoint||this._modelOriginPoint}_updateDefaultTransformation(t,e,r,o,h,R,p,l){t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(o)),t.updateMatrixWorld(!0);const n=new THREE.Box3().setFromObject(t);!this._model3DRuntimeObject._originPoint&&n.expandByPoint(new THREE.Vector3(0,0,0));const m=n.max.x-n.min.x,c=n.max.y-n.min.y,d=n.max.z-n.min.z;this._modelOriginPoint[0]=m<s?0:-n.min.x/m,this._modelOriginPoint[1]=c<s?0:-n.min.y/c,this._modelOriginPoint[2]=d<s?0:-n.min.z/d,this._modelOriginPoint[1]=1-this._modelOriginPoint[1];const u=this._model3DRuntimeObject._centerPoint;u&&t.position.set(-(n.min.x+m*u[0]),-(n.min.y+c*(1-u[1])),-(n.min.z+d*u[2])),t.scale.set(1,1,1),t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(o));const H=m<s?1:1/m,P=c<s?1:1/c,x=d<s?1:1/d,f=new THREE.Matrix4;if(f.makeScale(H,-P,x),t.updateMatrix(),t.applyMatrix4(f),l){const A=m<s?Number.POSITIVE_INFINITY:h/m,I=c<s?Number.POSITIVE_INFINITY:R/c,v=d<s?Number.POSITIVE_INFINITY:p/d;let _=Math.min(A,I,v);Number.isFinite(_)||(_=1),this._object._setOriginalWidth(_*m),this._object._setOriginalHeight(_*c),this._object._setOriginalDepth(_*d)}}_reloadModel(t,e){this._originalModel=e.getGame().getModel3DManager().getModel(t._modelResourceName)}_updateModel(t,e,r,o,h,R,p){const l=new THREE.Group;l.rotation.order="ZYX";const n=THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);l.add(n),this._replaceMaterials(l),this._updateDefaultTransformation(l,t,e,r,o,h,R,p),this.get3DRendererObject().remove(this._threeObject),this.get3DRendererObject().add(l),this._threeObject=l,this._animationMixer=new THREE.AnimationMixer(n);const E=this._model3DRuntimeObject.isAnimationPaused();this._model3DRuntimeObject.setAnimationIndex(this._model3DRuntimeObject.getAnimationIndex()),E&&this.pauseAnimation()}_replaceMaterials(t){this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness?T(t):this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.Basic&&D(t)}getAnimationCount(){return this._originalModel.animations.length}getAnimationName(t){return this._originalModel.animations[t].name}hasAnimationEnded(){return this._action?!this._action.isRunning():!0}animationPaused(){if(!!this._action)return this._action.paused}pauseAnimation(){!this._action||(this._action.paused=!0)}resumeAnimation(){!this._action||(this._action.paused=!1)}playAnimation(t,e){const r=THREE.AnimationClip.findByName(this._originalModel.animations,t);if(!r){console.error(`The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${t}`);return}const o=this._action;this._action=this._animationMixer.clipAction(r),this._action.setLoop(e?THREE.LoopRepeat:THREE.LoopOnce,Number.POSITIVE_INFINITY),this._action.clampWhenFinished=!0,o&&o!==this._action&&(this._action.enabled=!0,this._action.crossFadeFrom(o,this._model3DRuntimeObject._crossfadeDuration,!1)),this._action.play(),this._animationMixer.update(0)}getAnimationElapsedTime(){return this._action?this._action.time:0}setAnimationElapsedTime(t){this._action&&(this._action.time=t)}getAnimationDuration(t){const e=THREE.AnimationClip.findByName(this._originalModel.animations,t);return e?e.duration:0}}a.Model3DRuntimeObjectRenderer=j})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){const s=1/(1<<16),g=i=>{i.metalness&&(i.metalness=0)},O=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)g(t.material[e]);else g(t.material)},T=i=>i.traverse(O),M=i=>{const t=new THREE.MeshBasicMaterial;return i.color&&(t.color=i.color),i.map&&(t.map=i.map),t},D=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)t.material[e]=M(t.material[e]);else t.material=M(t.material)},b=i=>i.traverse(D);class j extends a.RuntimeObject3DRenderer{constructor(t,e){const r=e.getGame().getModel3DManager().getModel(t._modelResourceName),o=new THREE.Group,h=new THREE.Group;h.rotation.order="ZYX",h.add(o);super(t,e,h);this._model3DRuntimeObject=t,this._threeObject=o,this._originalModel=r,this._modelOriginPoint=[0,0,0],this.updateSize(),this.updatePosition(),this.updateRotation(),this._animationMixer=new THREE.AnimationMixer(o),this._action=null}updateAnimation(t){this._animationMixer.update(t)}updatePosition(){const t=this.getOriginPoint(),e=this.getCenterPoint();this.get3DRendererObject().position.set(this._object.getX()-this._object.getWidth()*(t[0]-e[0]),this._object.getY()-this._object.getHeight()*(t[1]-e[1]),this._object.getZ()-this._object.getDepth()*(t[2]-e[2]))}getOriginPoint(){return this._model3DRuntimeObject._originPoint||this._modelOriginPoint}getCenterPoint(){return this._model3DRuntimeObject._centerPoint||this._modelOriginPoint}_updateDefaultTransformation(t,e,r,o,h,R,p,l){t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(o)),t.updateMatrixWorld(!0);const n=new THREE.Box3().setFromObject(t);!this._model3DRuntimeObject._originPoint&&n.expandByPoint(new THREE.Vector3(0,0,0));const m=n.max.x-n.min.x,c=n.max.y-n.min.y,d=n.max.z-n.min.z;this._modelOriginPoint[0]=m<s?0:-n.min.x/m,this._modelOriginPoint[1]=c<s?0:-n.min.y/c,this._modelOriginPoint[2]=d<s?0:-n.min.z/d,this._modelOriginPoint[1]=1-this._modelOriginPoint[1];const u=this._model3DRuntimeObject._centerPoint;u&&t.position.set(-(n.min.x+m*u[0]),-(n.min.y+c*(1-u[1])),-(n.min.z+d*u[2])),t.scale.set(1,1,1),t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(o));const H=m<s?1:1/m,P=c<s?1:1/c,x=d<s?1:1/d,f=new THREE.Matrix4;if(f.makeScale(H,-P,x),t.updateMatrix(),t.applyMatrix4(f),l){const A=m<s?Number.POSITIVE_INFINITY:h/m,I=c<s?Number.POSITIVE_INFINITY:R/c,v=d<s?Number.POSITIVE_INFINITY:p/d;let _=Math.min(A,I,v);Number.isFinite(_)||(_=1),this._object._setOriginalWidth(_*m),this._object._setOriginalHeight(_*c),this._object._setOriginalDepth(_*d)}}_reloadModel(t,e){this._originalModel=e.getGame().getModel3DManager().getModel(t._modelResourceName)}_updateModel(t,e,r,o,h,R,p){const l=new THREE.Group;l.rotation.order="ZYX";const n=THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);l.add(n),this._replaceMaterials(l),this._updateDefaultTransformation(l,t,e,r,o,h,R,p),this.get3DRendererObject().remove(this._threeObject),this.get3DRendererObject().add(l),this._threeObject=l,this._animationMixer=new THREE.AnimationMixer(n);const E=this._model3DRuntimeObject.isAnimationPaused();this._model3DRuntimeObject.setAnimationIndex(this._model3DRuntimeObject.getAnimationIndex()),E&&this.pauseAnimation()}_replaceMaterials(t){this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness?T(t):this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.Basic&&b(t)}getAnimationCount(){return this._originalModel.animations.length}getAnimationName(t){return this._originalModel.animations[t].name}hasAnimationEnded(){return this._action?!this._action.isRunning():!0}animationPaused(){if(!!this._action)return this._action.paused}pauseAnimation(){!this._action||(this._action.paused=!0)}resumeAnimation(){!this._action||(this._action.paused=!1)}playAnimation(t,e){const r=THREE.AnimationClip.findByName(this._originalModel.animations,t);if(!r){console.error(`The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${t}`);return}const o=this._action;this._action=this._animationMixer.clipAction(r),this._action.reset(),this._action.setLoop(e?THREE.LoopRepeat:THREE.LoopOnce,Number.POSITIVE_INFINITY),this._action.clampWhenFinished=!0,o&&o!==this._action&&this._action.crossFadeFrom(o,this._model3DRuntimeObject._crossfadeDuration,!1),this._action.play(),this._animationMixer.update(0)}getAnimationElapsedTime(){return this._action?this._action.time:0}setAnimationElapsedTime(t){this._action&&(this._action.time=t)}getAnimationDuration(t){const e=THREE.AnimationClip.findByName(this._originalModel.animations,t);return e?e.duration:0}}a.Model3DRuntimeObjectRenderer=j})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=Model3DRuntimeObject3DRenderer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../GDevelop/Extensions/3D/Model3DRuntimeObject3DRenderer.ts"],
4
- "sourcesContent": ["namespace gdjs {\n type FloatPoint3D = [float, float, float];\n\n const epsilon = 1 / (1 << 16);\n\n const removeMetalness = (material: THREE.Material): void => {\n //@ts-ignore\n if (material.metalness) {\n //@ts-ignore\n material.metalness = 0;\n }\n };\n\n const removeMetalnessFromMesh = (node: THREE.Object3D) => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n removeMetalness(mesh.material[index]);\n }\n } else {\n removeMetalness(mesh.material);\n }\n };\n\n const traverseToRemoveMetalnessFromMeshes = (node: THREE.Object3D) =>\n node.traverse(removeMetalnessFromMesh);\n\n const convertToBasicMaterial = (\n material: THREE.Material\n ): THREE.MeshBasicMaterial => {\n const basicMaterial = new THREE.MeshBasicMaterial();\n //@ts-ignore\n if (material.color) {\n //@ts-ignore\n basicMaterial.color = material.color;\n }\n //@ts-ignore\n if (material.map) {\n //@ts-ignore\n basicMaterial.map = material.map;\n }\n return basicMaterial;\n };\n\n const setBasicMaterialTo = (node: THREE.Object3D): void => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n mesh.material[index] = convertToBasicMaterial(mesh.material[index]);\n }\n } else {\n mesh.material = convertToBasicMaterial(mesh.material);\n }\n };\n\n const traverseToSetBasicMaterialFromMeshes = (node: THREE.Object3D) =>\n node.traverse(setBasicMaterialTo);\n\n class Model3DRuntimeObject3DRenderer extends gdjs.RuntimeObject3DRenderer {\n private _model3DRuntimeObject: gdjs.Model3DRuntimeObject;\n /**\n * The 3D model stretched in a 1x1x1 cube.\n */\n private _threeObject: THREE.Object3D;\n private _originalModel: THREE_ADDONS.GLTF;\n private _animationMixer: THREE.AnimationMixer;\n private _action: THREE.AnimationAction | null;\n\n /**\n * The model origin evaluated according to the object configuration.\n *\n * Coordinates are between 0 and 1.\n */\n private _modelOriginPoint: FloatPoint3D;\n\n constructor(\n runtimeObject: gdjs.Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n // GLB files with skeleton must not have any transformation to work properly.\n const originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n // _updateModel will actually add a clone of the model.\n const model = new THREE.Group();\n\n // Create a group to transform the object according to\n // position, angle and dimensions.\n const group = new THREE.Group();\n group.rotation.order = 'ZYX';\n group.add(model);\n super(runtimeObject, instanceContainer, group);\n\n this._model3DRuntimeObject = runtimeObject;\n this._threeObject = model;\n this._originalModel = originalModel;\n this._modelOriginPoint = [0, 0, 0];\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n\n this._animationMixer = new THREE.AnimationMixer(model);\n this._action = null;\n }\n\n updateAnimation(timeDelta: float) {\n this._animationMixer.update(timeDelta);\n }\n\n updatePosition() {\n const originPoint = this.getOriginPoint();\n const centerPoint = this.getCenterPoint();\n this.get3DRendererObject().position.set(\n this._object.getX() -\n this._object.getWidth() * (originPoint[0] - centerPoint[0]),\n this._object.getY() -\n this._object.getHeight() * (originPoint[1] - centerPoint[1]),\n this._object.getZ() -\n this._object.getDepth() * (originPoint[2] - centerPoint[2])\n );\n }\n\n getOriginPoint() {\n return this._model3DRuntimeObject._originPoint || this._modelOriginPoint;\n }\n\n getCenterPoint() {\n return this._model3DRuntimeObject._centerPoint || this._modelOriginPoint;\n }\n\n private _updateDefaultTransformation(\n threeObject: THREE.Object3D,\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // These formulas are also used in:\n // - Model3DEditor.modelSize\n // - Model3DRendered2DInstance\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n threeObject.updateMatrixWorld(true);\n const boundingBox = new THREE.Box3().setFromObject(threeObject);\n\n const shouldKeepModelOrigin = !this._model3DRuntimeObject._originPoint;\n if (shouldKeepModelOrigin) {\n // Keep the origin as part of the model.\n // For instance, a model can be 1 face of a cube and we want to keep the\n // inside as part of the object even if it's just void.\n // It also avoids to have the origin outside of the object box.\n boundingBox.expandByPoint(new THREE.Vector3(0, 0, 0));\n }\n\n const modelWidth = boundingBox.max.x - boundingBox.min.x;\n const modelHeight = boundingBox.max.y - boundingBox.min.y;\n const modelDepth = boundingBox.max.z - boundingBox.min.z;\n this._modelOriginPoint[0] =\n modelWidth < epsilon ? 0 : -boundingBox.min.x / modelWidth;\n this._modelOriginPoint[1] =\n modelHeight < epsilon ? 0 : -boundingBox.min.y / modelHeight;\n this._modelOriginPoint[2] =\n modelDepth < epsilon ? 0 : -boundingBox.min.z / modelDepth;\n\n // The model is flipped on Y axis.\n this._modelOriginPoint[1] = 1 - this._modelOriginPoint[1];\n\n // Center the model.\n const centerPoint = this._model3DRuntimeObject._centerPoint;\n if (centerPoint) {\n threeObject.position.set(\n -(boundingBox.min.x + modelWidth * centerPoint[0]),\n // The model is flipped on Y axis.\n -(boundingBox.min.y + modelHeight * (1 - centerPoint[1])),\n -(boundingBox.min.z + modelDepth * centerPoint[2])\n );\n }\n\n // Rotate the model.\n threeObject.scale.set(1, 1, 1);\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n\n // Stretch the model in a 1x1x1 cube.\n const scaleX = modelWidth < epsilon ? 1 : 1 / modelWidth;\n const scaleY = modelHeight < epsilon ? 1 : 1 / modelHeight;\n const scaleZ = modelDepth < epsilon ? 1 : 1 / modelDepth;\n\n const scaleMatrix = new THREE.Matrix4();\n // Flip on Y because the Y axis is on the opposite side of direct basis.\n // It avoids models to be like a mirror refection.\n scaleMatrix.makeScale(scaleX, -scaleY, scaleZ);\n threeObject.updateMatrix();\n threeObject.applyMatrix4(scaleMatrix);\n\n if (keepAspectRatio) {\n // Reduce the object dimensions to keep aspect ratio.\n const widthRatio =\n modelWidth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalWidth / modelWidth;\n const heightRatio =\n modelHeight < epsilon\n ? Number.POSITIVE_INFINITY\n : originalHeight / modelHeight;\n const depthRatio =\n modelDepth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalDepth / modelDepth;\n let scaleRatio = Math.min(widthRatio, heightRatio, depthRatio);\n if (!Number.isFinite(scaleRatio)) {\n scaleRatio = 1;\n }\n\n this._object._setOriginalWidth(scaleRatio * modelWidth);\n this._object._setOriginalHeight(scaleRatio * modelHeight);\n this._object._setOriginalDepth(scaleRatio * modelDepth);\n }\n }\n\n /**\n * `_updateModel` should always be called after this method.\n * Ideally, use `Model3DRuntimeObject#_reloadModel` instead.\n */\n _reloadModel(\n runtimeObject: Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n }\n\n _updateModel(\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // Start from the original model because:\n // - _replaceMaterials is destructive\n // - _updateDefaultTransformation may need to work with meshes in local space\n\n // This group hold the rotation defined by properties.\n const threeObject = new THREE.Group();\n threeObject.rotation.order = 'ZYX';\n const root = THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);\n threeObject.add(root);\n\n this._replaceMaterials(threeObject);\n\n this._updateDefaultTransformation(\n threeObject,\n rotationX,\n rotationY,\n rotationZ,\n originalWidth,\n originalHeight,\n originalDepth,\n keepAspectRatio\n );\n\n // Replace the 3D object.\n this.get3DRendererObject().remove(this._threeObject);\n this.get3DRendererObject().add(threeObject);\n this._threeObject = threeObject;\n\n // Start the current animation on the new 3D object.\n this._animationMixer = new THREE.AnimationMixer(root);\n const isAnimationPaused = this._model3DRuntimeObject.isAnimationPaused();\n this._model3DRuntimeObject.setAnimationIndex(\n this._model3DRuntimeObject.getAnimationIndex()\n );\n if (isAnimationPaused) {\n this.pauseAnimation();\n }\n }\n\n /**\n * Replace materials to better work with lights (or no light).\n */\n private _replaceMaterials(threeObject: THREE.Object3D) {\n if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness\n ) {\n traverseToRemoveMetalnessFromMeshes(threeObject);\n } else if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.Basic\n ) {\n traverseToSetBasicMaterialFromMeshes(threeObject);\n }\n }\n\n getAnimationCount() {\n return this._originalModel.animations.length;\n }\n\n getAnimationName(animationIndex: integer) {\n return this._originalModel.animations[animationIndex].name;\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n if (!this._action) {\n return true;\n }\n return !this._action.isRunning();\n }\n\n animationPaused() {\n if (!this._action) {\n return;\n }\n return this._action.paused;\n }\n\n pauseAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = true;\n }\n\n resumeAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = false;\n }\n\n playAnimation(animationName: string, shouldLoop: boolean) {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n if (!clip) {\n console.error(\n `The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${animationName}`\n );\n return;\n }\n const previousAction = this._action;\n this._action = this._animationMixer.clipAction(clip);\n this._action.setLoop(\n shouldLoop ? THREE.LoopRepeat : THREE.LoopOnce,\n Number.POSITIVE_INFINITY\n );\n this._action.clampWhenFinished = true;\n\n if (previousAction && previousAction !== this._action) {\n this._action.enabled = true;\n this._action.crossFadeFrom(\n previousAction,\n this._model3DRuntimeObject._crossfadeDuration,\n false\n );\n }\n this._action.play();\n // Make sure the first frame is displayed.\n this._animationMixer.update(0);\n }\n\n getAnimationElapsedTime(): float {\n return this._action ? this._action.time : 0;\n }\n\n setAnimationElapsedTime(time: float): void {\n if (this._action) {\n this._action.time = time;\n }\n }\n\n getAnimationDuration(animationName: string): float {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n return clip ? clip.duration : 0;\n }\n }\n\n export const Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n export type Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n}\n"],
5
- "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAGE,KAAM,GAAU,EAAK,IAAK,IAEpB,EAAkB,AAAC,GAAmC,CAE1D,AAAI,EAAS,WAEX,GAAS,UAAY,IAInB,EAA0B,AAAC,GAAyB,CACxD,KAAM,GAAO,EACb,GAAI,EAAC,EAAK,SAGV,GAAI,MAAM,QAAQ,EAAK,UACrB,OAAS,GAAQ,EAAG,EAAQ,EAAK,SAAS,OAAQ,IAChD,EAAgB,EAAK,SAAS,QAGhC,GAAgB,EAAK,WAInB,EAAsC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QAGV,MAAO,MAAK,QAAQ,OAGtB,gBAAiB,CACf,AAAI,CAAC,KAAK,SAGV,MAAK,QAAQ,OAAS,IAGxB,iBAAkB,CAChB,AAAI,CAAC,KAAK,SAGV,MAAK,QAAQ,OAAS,IAGxB,cAAc,EAAuB,EAAqB,CACxD,KAAM,GAAO,MAAM,cAAc,WAC/B,KAAK,eAAe,WACpB,GAEF,GAAI,CAAC,EAAM,CACT,QAAQ,MACN,iBAAiB,KAAK,sBAAsB,wDAAwD,KAEtG,OAEF,KAAM,GAAiB,KAAK,QAC5B,KAAK,QAAU,KAAK,gBAAgB,WAAW,GAC/C,KAAK,QAAQ,QACX,EAAa,MAAM,WAAa,MAAM,SACtC,OAAO,mBAET,KAAK,QAAQ,kBAAoB,GAE7B,GAAkB,IAAmB,KAAK,SAC5C,MAAK,QAAQ,QAAU,GACvB,KAAK,QAAQ,cACX,EACA,KAAK,sBAAsB,mBAC3B,KAGJ,KAAK,QAAQ,OAEb,KAAK,gBAAgB,OAAO,GAG9B,yBAAiC,CAC/B,MAAO,MAAK,QAAU,KAAK,QAAQ,KAAO,EAG5C,wBAAwB,EAAmB,CACzC,AAAI,KAAK,SACP,MAAK,QAAQ,KAAO,GAIxB,qBAAqB,EAA8B,CACjD,KAAM,GAAO,MAAM,cAAc,WAC/B,KAAK,eAAe,WACpB,GAEF,MAAO,GAAO,EAAK,SAAW,GAI3B,AAAM,+BAA+B,IA3ZpC",
4
+ "sourcesContent": ["namespace gdjs {\n type FloatPoint3D = [float, float, float];\n\n const epsilon = 1 / (1 << 16);\n\n const removeMetalness = (material: THREE.Material): void => {\n //@ts-ignore\n if (material.metalness) {\n //@ts-ignore\n material.metalness = 0;\n }\n };\n\n const removeMetalnessFromMesh = (node: THREE.Object3D) => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n removeMetalness(mesh.material[index]);\n }\n } else {\n removeMetalness(mesh.material);\n }\n };\n\n const traverseToRemoveMetalnessFromMeshes = (node: THREE.Object3D) =>\n node.traverse(removeMetalnessFromMesh);\n\n const convertToBasicMaterial = (\n material: THREE.Material\n ): THREE.MeshBasicMaterial => {\n const basicMaterial = new THREE.MeshBasicMaterial();\n //@ts-ignore\n if (material.color) {\n //@ts-ignore\n basicMaterial.color = material.color;\n }\n //@ts-ignore\n if (material.map) {\n //@ts-ignore\n basicMaterial.map = material.map;\n }\n return basicMaterial;\n };\n\n const setBasicMaterialTo = (node: THREE.Object3D): void => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n mesh.material[index] = convertToBasicMaterial(mesh.material[index]);\n }\n } else {\n mesh.material = convertToBasicMaterial(mesh.material);\n }\n };\n\n const traverseToSetBasicMaterialFromMeshes = (node: THREE.Object3D) =>\n node.traverse(setBasicMaterialTo);\n\n class Model3DRuntimeObject3DRenderer extends gdjs.RuntimeObject3DRenderer {\n private _model3DRuntimeObject: gdjs.Model3DRuntimeObject;\n /**\n * The 3D model stretched in a 1x1x1 cube.\n */\n private _threeObject: THREE.Object3D;\n private _originalModel: THREE_ADDONS.GLTF;\n private _animationMixer: THREE.AnimationMixer;\n private _action: THREE.AnimationAction | null;\n\n /**\n * The model origin evaluated according to the object configuration.\n *\n * Coordinates are between 0 and 1.\n */\n private _modelOriginPoint: FloatPoint3D;\n\n constructor(\n runtimeObject: gdjs.Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n // GLB files with skeleton must not have any transformation to work properly.\n const originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n // _updateModel will actually add a clone of the model.\n const model = new THREE.Group();\n\n // Create a group to transform the object according to\n // position, angle and dimensions.\n const group = new THREE.Group();\n group.rotation.order = 'ZYX';\n group.add(model);\n super(runtimeObject, instanceContainer, group);\n\n this._model3DRuntimeObject = runtimeObject;\n this._threeObject = model;\n this._originalModel = originalModel;\n this._modelOriginPoint = [0, 0, 0];\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n\n this._animationMixer = new THREE.AnimationMixer(model);\n this._action = null;\n }\n\n updateAnimation(timeDelta: float) {\n this._animationMixer.update(timeDelta);\n }\n\n updatePosition() {\n const originPoint = this.getOriginPoint();\n const centerPoint = this.getCenterPoint();\n this.get3DRendererObject().position.set(\n this._object.getX() -\n this._object.getWidth() * (originPoint[0] - centerPoint[0]),\n this._object.getY() -\n this._object.getHeight() * (originPoint[1] - centerPoint[1]),\n this._object.getZ() -\n this._object.getDepth() * (originPoint[2] - centerPoint[2])\n );\n }\n\n getOriginPoint() {\n return this._model3DRuntimeObject._originPoint || this._modelOriginPoint;\n }\n\n getCenterPoint() {\n return this._model3DRuntimeObject._centerPoint || this._modelOriginPoint;\n }\n\n private _updateDefaultTransformation(\n threeObject: THREE.Object3D,\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // These formulas are also used in:\n // - Model3DEditor.modelSize\n // - Model3DRendered2DInstance\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n threeObject.updateMatrixWorld(true);\n const boundingBox = new THREE.Box3().setFromObject(threeObject);\n\n const shouldKeepModelOrigin = !this._model3DRuntimeObject._originPoint;\n if (shouldKeepModelOrigin) {\n // Keep the origin as part of the model.\n // For instance, a model can be 1 face of a cube and we want to keep the\n // inside as part of the object even if it's just void.\n // It also avoids to have the origin outside of the object box.\n boundingBox.expandByPoint(new THREE.Vector3(0, 0, 0));\n }\n\n const modelWidth = boundingBox.max.x - boundingBox.min.x;\n const modelHeight = boundingBox.max.y - boundingBox.min.y;\n const modelDepth = boundingBox.max.z - boundingBox.min.z;\n this._modelOriginPoint[0] =\n modelWidth < epsilon ? 0 : -boundingBox.min.x / modelWidth;\n this._modelOriginPoint[1] =\n modelHeight < epsilon ? 0 : -boundingBox.min.y / modelHeight;\n this._modelOriginPoint[2] =\n modelDepth < epsilon ? 0 : -boundingBox.min.z / modelDepth;\n\n // The model is flipped on Y axis.\n this._modelOriginPoint[1] = 1 - this._modelOriginPoint[1];\n\n // Center the model.\n const centerPoint = this._model3DRuntimeObject._centerPoint;\n if (centerPoint) {\n threeObject.position.set(\n -(boundingBox.min.x + modelWidth * centerPoint[0]),\n // The model is flipped on Y axis.\n -(boundingBox.min.y + modelHeight * (1 - centerPoint[1])),\n -(boundingBox.min.z + modelDepth * centerPoint[2])\n );\n }\n\n // Rotate the model.\n threeObject.scale.set(1, 1, 1);\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n\n // Stretch the model in a 1x1x1 cube.\n const scaleX = modelWidth < epsilon ? 1 : 1 / modelWidth;\n const scaleY = modelHeight < epsilon ? 1 : 1 / modelHeight;\n const scaleZ = modelDepth < epsilon ? 1 : 1 / modelDepth;\n\n const scaleMatrix = new THREE.Matrix4();\n // Flip on Y because the Y axis is on the opposite side of direct basis.\n // It avoids models to be like a mirror refection.\n scaleMatrix.makeScale(scaleX, -scaleY, scaleZ);\n threeObject.updateMatrix();\n threeObject.applyMatrix4(scaleMatrix);\n\n if (keepAspectRatio) {\n // Reduce the object dimensions to keep aspect ratio.\n const widthRatio =\n modelWidth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalWidth / modelWidth;\n const heightRatio =\n modelHeight < epsilon\n ? Number.POSITIVE_INFINITY\n : originalHeight / modelHeight;\n const depthRatio =\n modelDepth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalDepth / modelDepth;\n let scaleRatio = Math.min(widthRatio, heightRatio, depthRatio);\n if (!Number.isFinite(scaleRatio)) {\n scaleRatio = 1;\n }\n\n this._object._setOriginalWidth(scaleRatio * modelWidth);\n this._object._setOriginalHeight(scaleRatio * modelHeight);\n this._object._setOriginalDepth(scaleRatio * modelDepth);\n }\n }\n\n /**\n * `_updateModel` should always be called after this method.\n * Ideally, use `Model3DRuntimeObject#_reloadModel` instead.\n */\n _reloadModel(\n runtimeObject: Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n }\n\n _updateModel(\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // Start from the original model because:\n // - _replaceMaterials is destructive\n // - _updateDefaultTransformation may need to work with meshes in local space\n\n // This group hold the rotation defined by properties.\n const threeObject = new THREE.Group();\n threeObject.rotation.order = 'ZYX';\n const root = THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);\n threeObject.add(root);\n\n this._replaceMaterials(threeObject);\n\n this._updateDefaultTransformation(\n threeObject,\n rotationX,\n rotationY,\n rotationZ,\n originalWidth,\n originalHeight,\n originalDepth,\n keepAspectRatio\n );\n\n // Replace the 3D object.\n this.get3DRendererObject().remove(this._threeObject);\n this.get3DRendererObject().add(threeObject);\n this._threeObject = threeObject;\n\n // Start the current animation on the new 3D object.\n this._animationMixer = new THREE.AnimationMixer(root);\n const isAnimationPaused = this._model3DRuntimeObject.isAnimationPaused();\n this._model3DRuntimeObject.setAnimationIndex(\n this._model3DRuntimeObject.getAnimationIndex()\n );\n if (isAnimationPaused) {\n this.pauseAnimation();\n }\n }\n\n /**\n * Replace materials to better work with lights (or no light).\n */\n private _replaceMaterials(threeObject: THREE.Object3D) {\n if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness\n ) {\n traverseToRemoveMetalnessFromMeshes(threeObject);\n } else if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.Basic\n ) {\n traverseToSetBasicMaterialFromMeshes(threeObject);\n }\n }\n\n getAnimationCount() {\n return this._originalModel.animations.length;\n }\n\n getAnimationName(animationIndex: integer) {\n return this._originalModel.animations[animationIndex].name;\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n if (!this._action) {\n return true;\n }\n return !this._action.isRunning();\n }\n\n animationPaused() {\n if (!this._action) {\n return;\n }\n return this._action.paused;\n }\n\n pauseAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = true;\n }\n\n resumeAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = false;\n }\n\n playAnimation(animationName: string, shouldLoop: boolean) {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n if (!clip) {\n console.error(\n `The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${animationName}`\n );\n return;\n }\n const previousAction = this._action;\n this._action = this._animationMixer.clipAction(clip);\n\n // The action must be reset before being reconfigured with setLoop to prevent previous action parameters causing problems\n // such as animations not playing (not sure to which extends it can cause problems nor the origin of these problems)\n this._action.reset();\n this._action.setLoop(\n shouldLoop ? THREE.LoopRepeat : THREE.LoopOnce,\n Number.POSITIVE_INFINITY\n );\n this._action.clampWhenFinished = true;\n\n if (previousAction && previousAction !== this._action) {\n this._action.crossFadeFrom(\n previousAction,\n this._model3DRuntimeObject._crossfadeDuration,\n false\n );\n }\n this._action.play();\n // Make sure the first frame is displayed.\n this._animationMixer.update(0);\n }\n\n getAnimationElapsedTime(): float {\n return this._action ? this._action.time : 0;\n }\n\n setAnimationElapsedTime(time: float): void {\n if (this._action) {\n this._action.time = time;\n }\n }\n\n getAnimationDuration(animationName: string): float {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n return clip ? clip.duration : 0;\n }\n }\n\n export const Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n export type Model3DRuntimeObjectRenderer =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AAAM,+BAA+B,IA9ZpC",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(s){const i=n=>n instanceof pixi_spine.Spine,c=n=>!!n&&n.type===pixi_spine.AttachmentType.Point;class a{constructor(e,t){this.instanceContainer=t;this._isAnimationComplete=!0;this._object=e,this._rendererObject=this.constructRendererObject(),i(this._rendererObject)&&(this._rendererObject.autoUpdate=!1),this.updatePosition(),this.updateAngle(),this.updateOpacity(),this.updateScale(),t.getLayer("").getRenderer().addRendererObject(this._rendererObject,e.getZOrder())}updateAnimation(e){!i(this._rendererObject)||this._rendererObject.update(e)}getRendererObject(){return this._rendererObject}getOriginOffset(){if(!i(this._rendererObject))return new PIXI.Point(0,0);const e=this._rendererObject.getLocalBounds(void 0,!0);return new PIXI.Point(e.x*this._rendererObject.scale.x,e.y*this._rendererObject.scale.y)}onDestroy(){this._rendererObject.destroy()}updateScale(){const e=Math.max(this._object._originalScale*this._object.getScaleX(),0),t=Math.max(this._object._originalScale*this._object.getScaleY(),0);this._rendererObject.scale.x=this._object.isFlippedX()?-e:e,this._rendererObject.scale.y=this._object.isFlippedY()?-t:t}updatePosition(){this._rendererObject.position.x=this._object.x,this._rendererObject.position.y=this._object.y}updateAngle(){this._rendererObject.rotation=s.toRad(this._object.angle)}updateOpacity(){this._rendererObject.alpha=this._object.getOpacity()/255}getWidth(){return this._rendererObject.width}getHeight(){return this._rendererObject.height}setWidth(e){this._rendererObject.width=e}setHeight(e){this._rendererObject.height=e}getUnscaledWidth(){return Math.abs(this._rendererObject.width*this._object._originalScale/this._rendererObject.scale.x)}getUnscaledHeight(){return Math.abs(this._rendererObject.height*this._object._originalScale/this._rendererObject.scale.y)}setMixing(e,t,r){!i(this._rendererObject)||this._rendererObject.stateData.setMix(e,t,r)}setAnimation(e,t){if(i(this._rendererObject)){const r={complete:()=>{this._isAnimationComplete=!0,this._rendererObject.state.removeListener(r)}};this._isAnimationComplete=!1,this._rendererObject.state.addListener(r),this._rendererObject.state.setAnimation(0,e,t),this._rendererObject.update(0)}}getAnimationDuration(e){if(!i(this._rendererObject))return 0;const t=this._rendererObject.spineData.findAnimation(e);return t?t.duration:0}getAnimationElapsedTime(){if(!i(this._rendererObject))return 0;const e=this._rendererObject.state.tracks;return e.length===0?0:e[0].getAnimationTime()}setAnimationElapsedTime(e){if(!i(this._rendererObject))return;const t=this._rendererObject.state.tracks;if(t.length===0)return;const r=t[0];r.trackTime=e}isAnimationComplete(){return this._isAnimationComplete}getPointAttachmentPosition(e,t){if(t||(t=e),!i(this._rendererObject))return new pixi_spine.Vector2(this._rendererObject.x,this._rendererObject.y);const r=this._rendererObject.skeleton.findSlot(t);if(!r)throw new Error(`Unable to find ${t} slot name for ${e} point attachment.`);const o=this._rendererObject.skeleton.getAttachmentByName(t,e);if(!c(o))throw new Error(`Unable to find ${e} point attachment with ${t} slot name.`);return new PIXI.Matrix().rotate(this._rendererObject.rotation).scale(this._rendererObject.scale.x,this._rendererObject.scale.y).translate(this._rendererObject.x,this._rendererObject.y).apply(o.computeWorldPosition(r.bone,new pixi_spine.Vector2))}constructRendererObject(){const t=this.instanceContainer.getGame().getSpineManager();return!t||!t.isSpineLoaded(this._object.spineResourceName)?new PIXI.Container:new pixi_spine.Spine(t.getSpine(this._object.spineResourceName))}}s.SpineRuntimeObjectPixiRenderer=a,s.SpineRuntimeObjectRenderer=a})(gdjs||(gdjs={}));
1
+ var gdjs;(function(s){const i=n=>n instanceof pixi_spine.Spine,c=n=>!!n&&n.type===pixi_spine.AttachmentType.Point;class a{constructor(e,t){this.instanceContainer=t;this._isAnimationComplete=!0;this._object=e,this._rendererObject=this.constructRendererObject(),i(this._rendererObject)&&(this._rendererObject.autoUpdate=!1),this.updatePosition(),this.updateAngle(),this.updateOpacity(),this.updateScale(),t.getLayer("").getRenderer().addRendererObject(this._rendererObject,e.getZOrder())}updateAnimation(e){!i(this._rendererObject)||this._rendererObject.update(e)}getRendererObject(){return this._rendererObject}getOriginOffset(){if(!i(this._rendererObject))return new PIXI.Point(0,0);const e=this._rendererObject.getLocalBounds(void 0,!0);return new PIXI.Point(e.x*this._rendererObject.scale.x,e.y*this._rendererObject.scale.y)}onDestroy(){this._rendererObject.destroy()}updateScale(){const e=Math.max(this._object._originalScale*this._object.getScaleX(),0),t=Math.max(this._object._originalScale*this._object.getScaleY(),0);this._rendererObject.scale.x=this._object.isFlippedX()?-e:e,this._rendererObject.scale.y=this._object.isFlippedY()?-t:t}updatePosition(){this._rendererObject.position.x=this._object.x,this._rendererObject.position.y=this._object.y}updateAngle(){this._rendererObject.rotation=s.toRad(this._object.angle)}updateOpacity(){this._rendererObject.alpha=this._object.getOpacity()/255}getWidth(){return this._rendererObject.width}getHeight(){return this._rendererObject.height}setWidth(e){this._rendererObject.width=e}setHeight(e){this._rendererObject.height=e}getUnscaledWidth(){return Math.abs(this._rendererObject.width*this._object._originalScale/this._rendererObject.scale.x)}getUnscaledHeight(){return Math.abs(this._rendererObject.height*this._object._originalScale/this._rendererObject.scale.y)}setMixing(e,t,r){!i(this._rendererObject)||this._rendererObject.stateData.setMix(e,t,r)}setAnimation(e,t){if(i(this._rendererObject)){const r={complete:()=>{this._isAnimationComplete=!0,this._rendererObject.state.removeListener(r)}};this._isAnimationComplete=!1,this._rendererObject.state.addListener(r),this._rendererObject.state.setAnimation(0,e,t),this._rendererObject.update(0)}}getAnimationDuration(e){if(!i(this._rendererObject))return 0;const t=this._rendererObject.spineData.findAnimation(e);return t?t.duration:0}getAnimationElapsedTime(){if(!i(this._rendererObject))return 0;const e=this._rendererObject.state.tracks;return e.length===0?0:e[0].getAnimationTime()}setAnimationElapsedTime(e){if(!i(this._rendererObject))return;const t=this._rendererObject.state.tracks;if(t.length===0)return;const r=t[0];r.trackTime=e}isAnimationComplete(){if(!i(this._rendererObject))return!0;const e=this._rendererObject.state.tracks[0];return e?this._isAnimationComplete&&!e.loop:!0}getPointAttachmentPosition(e,t){if(t||(t=e),!i(this._rendererObject))return new pixi_spine.Vector2(this._rendererObject.x,this._rendererObject.y);const r=this._rendererObject.skeleton.findSlot(t);if(!r)throw new Error(`Unable to find ${t} slot name for ${e} point attachment.`);const o=this._rendererObject.skeleton.getAttachmentByName(t,e);if(!c(o))throw new Error(`Unable to find ${e} point attachment with ${t} slot name.`);return new PIXI.Matrix().rotate(this._rendererObject.rotation).scale(this._rendererObject.scale.x,this._rendererObject.scale.y).translate(this._rendererObject.x,this._rendererObject.y).apply(o.computeWorldPosition(r.bone,new pixi_spine.Vector2))}constructRendererObject(){const t=this.instanceContainer.getGame().getSpineManager();return!t||!t.isSpineLoaded(this._object.spineResourceName)?new PIXI.Container:new pixi_spine.Spine(t.getSpine(this._object.spineResourceName))}}s.SpineRuntimeObjectPixiRenderer=a,s.SpineRuntimeObjectRenderer=a})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=spineruntimeobject-pixi-renderer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../GDevelop/Extensions/Spine/spineruntimeobject-pixi-renderer.ts"],
4
- "sourcesContent": ["namespace gdjs {\n const isSpine = (obj: any): obj is pixi_spine.Spine =>\n obj instanceof pixi_spine.Spine;\n\n // See https://github.com/pixijs/spine/issues/562\n // IPointAttachment is not declared and exported but its implementation does exist and it is used in runtime\n interface IPointAttachment extends pixi_spine.IVertexAttachment {\n computeWorldPosition(\n bone: pixi_spine.IBone,\n point: pixi_spine.Vector2\n ): pixi_spine.Vector2;\n computeWorldRotation(bone: pixi_spine.IBone): number;\n }\n\n const isPointAttachment = (\n attachment: pixi_spine.IAttachment\n ): attachment is IPointAttachment =>\n !!attachment && attachment.type === pixi_spine.AttachmentType.Point;\n\n export class SpineRuntimeObjectPixiRenderer {\n private _object: gdjs.SpineRuntimeObject;\n private _rendererObject: pixi_spine.Spine | PIXI.Container;\n private _isAnimationComplete = true;\n\n /**\n * @param runtimeObject The object to render\n * @param instanceContainer The container in which the object is\n */\n constructor(\n runtimeObject: gdjs.SpineRuntimeObject,\n private instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._object = runtimeObject;\n this._rendererObject = this.constructRendererObject();\n if (isSpine(this._rendererObject)) {\n this._rendererObject.autoUpdate = false;\n }\n\n this.updatePosition();\n this.updateAngle();\n this.updateOpacity();\n this.updateScale();\n\n instanceContainer\n .getLayer('')\n .getRenderer()\n .addRendererObject(this._rendererObject, runtimeObject.getZOrder());\n }\n\n updateAnimation(timeDelta: float) {\n if (!isSpine(this._rendererObject)) {\n return;\n }\n this._rendererObject.update(timeDelta);\n }\n\n getRendererObject(): pixi_spine.Spine | PIXI.Container {\n return this._rendererObject;\n }\n\n getOriginOffset(): PIXI.Point {\n if (!isSpine(this._rendererObject)) return new PIXI.Point(0, 0);\n\n const localBounds = this._rendererObject.getLocalBounds(undefined, true);\n\n return new PIXI.Point(\n localBounds.x * this._rendererObject.scale.x,\n localBounds.y * this._rendererObject.scale.y\n );\n }\n\n onDestroy(): void {\n this._rendererObject.destroy();\n }\n\n updateScale(): void {\n const scaleX = Math.max(\n this._object._originalScale * this._object.getScaleX(),\n 0\n );\n const scaleY = Math.max(\n this._object._originalScale * this._object.getScaleY(),\n 0\n );\n this._rendererObject.scale.x = this._object.isFlippedX()\n ? -scaleX\n : scaleX;\n this._rendererObject.scale.y = this._object.isFlippedY()\n ? -scaleY\n : scaleY;\n }\n\n updatePosition(): void {\n this._rendererObject.position.x = this._object.x;\n this._rendererObject.position.y = this._object.y;\n }\n\n updateAngle(): void {\n this._rendererObject.rotation = gdjs.toRad(this._object.angle);\n }\n\n updateOpacity(): void {\n this._rendererObject.alpha = this._object.getOpacity() / 255;\n }\n\n getWidth(): float {\n return this._rendererObject.width;\n }\n\n getHeight(): float {\n return this._rendererObject.height;\n }\n\n setWidth(width: float): void {\n this._rendererObject.width = width;\n }\n\n setHeight(height: float): void {\n this._rendererObject.height = height;\n }\n\n getUnscaledWidth(): float {\n return Math.abs(\n (this._rendererObject.width * this._object._originalScale) /\n this._rendererObject.scale.x\n );\n }\n\n getUnscaledHeight(): float {\n return Math.abs(\n (this._rendererObject.height * this._object._originalScale) /\n this._rendererObject.scale.y\n );\n }\n\n setMixing(from: string, to: string, duration: number): void {\n if (!isSpine(this._rendererObject)) return;\n\n this._rendererObject.stateData.setMix(from, to, duration);\n }\n\n setAnimation(animation: string, loop: boolean): void {\n if (isSpine(this._rendererObject)) {\n const onCompleteListener: pixi_spine.IAnimationStateListener = {\n complete: () => {\n this._isAnimationComplete = true;\n (this._rendererObject as pixi_spine.Spine).state.removeListener(\n onCompleteListener\n );\n },\n };\n\n this._isAnimationComplete = false;\n this._rendererObject.state.addListener(onCompleteListener);\n this._rendererObject.state.setAnimation(0, animation, loop);\n this._rendererObject.update(0);\n }\n }\n\n getAnimationDuration(sourceAnimationName: string) {\n if (!isSpine(this._rendererObject)) {\n return 0;\n }\n const animation =\n this._rendererObject.spineData.findAnimation(sourceAnimationName);\n return animation ? animation.duration : 0;\n }\n\n getAnimationElapsedTime(): number {\n if (!isSpine(this._rendererObject)) {\n return 0;\n }\n const tracks = this._rendererObject.state.tracks;\n if (tracks.length === 0) {\n return 0;\n }\n // This should be fine because only 1 track is used.\n const track = tracks[0];\n // @ts-ignore TrackEntry.getAnimationTime is not exposed.\n return track.getAnimationTime();\n }\n\n setAnimationElapsedTime(time: number): void {\n if (!isSpine(this._rendererObject)) {\n return;\n }\n const tracks = this._rendererObject.state.tracks;\n if (tracks.length === 0) {\n return;\n }\n const track = tracks[0];\n track.trackTime = time;\n }\n\n isAnimationComplete(): boolean {\n return this._isAnimationComplete;\n }\n\n getPointAttachmentPosition(\n attachmentName: string,\n slotName?: string\n ): pixi_spine.Vector2 {\n if (!slotName) {\n slotName = attachmentName;\n }\n if (!isSpine(this._rendererObject)) {\n return new pixi_spine.Vector2(\n this._rendererObject.x,\n this._rendererObject.y\n );\n }\n const slot = this._rendererObject.skeleton.findSlot(slotName);\n if (!slot) {\n throw new Error(\n `Unable to find ${slotName} slot name for ${attachmentName} point attachment.`\n );\n }\n const attachment = this._rendererObject.skeleton.getAttachmentByName(\n slotName,\n attachmentName\n );\n if (!isPointAttachment(attachment)) {\n throw new Error(\n `Unable to find ${attachmentName} point attachment with ${slotName} slot name.`\n );\n }\n\n return new PIXI.Matrix()\n .rotate(this._rendererObject.rotation)\n .scale(this._rendererObject.scale.x, this._rendererObject.scale.y)\n .translate(this._rendererObject.x, this._rendererObject.y)\n .apply(\n attachment.computeWorldPosition(slot.bone, new pixi_spine.Vector2())\n );\n }\n\n private constructRendererObject(): pixi_spine.Spine | PIXI.Container {\n const game = this.instanceContainer.getGame();\n const spineManager = game.getSpineManager();\n\n if (\n !spineManager ||\n !spineManager.isSpineLoaded(this._object.spineResourceName)\n ) {\n return new PIXI.Container();\n }\n\n return new pixi_spine.Spine(\n spineManager.getSpine(this._object.spineResourceName)!\n );\n }\n }\n export const SpineRuntimeObjectRenderer = SpineRuntimeObjectPixiRenderer;\n}\n"],
5
- "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAU,AAAC,GACf,YAAe,YAAW,MAYtB,EAAoB,AACxB,GAEA,CAAC,CAAC,GAAc,EAAW,OAAS,WAAW,eAAe,MAEzD,OAAqC,CAS1C,YACE,EACQ,EACR,CADQ,yBARF,0BAAuB,GAU7B,KAAK,QAAU,EACf,KAAK,gBAAkB,KAAK,0BACxB,EAAQ,KAAK,kBACf,MAAK,gBAAgB,WAAa,IAGpC,KAAK,iBACL,KAAK,cACL,KAAK,gBACL,KAAK,cAEL,EACG,SAAS,IACT,cACA,kBAAkB,KAAK,gBAAiB,EAAc,aAG3D,gBAAgB,EAAkB,CAChC,AAAI,CAAC,EAAQ,KAAK,kBAGlB,KAAK,gBAAgB,OAAO,GAG9B,mBAAuD,CACrD,MAAO,MAAK,gBAGd,iBAA8B,CAC5B,GAAI,CAAC,EAAQ,KAAK,iBAAkB,MAAO,IAAI,MAAK,MAAM,EAAG,GAE7D,KAAM,GAAc,KAAK,gBAAgB,eAAe,OAAW,IAEnE,MAAO,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AAI,YAAW,UAIxD,yBAA6D,CAEnE,KAAM,GAAe,AADR,KAAK,kBAAkB,UACV,kBAE1B,MACE,CAAC,GACD,CAAC,EAAa,cAAc,KAAK,QAAQ,mBAElC,GAAI,MAAK,UAGX,GAAI,YAAW,MACpB,EAAa,SAAS,KAAK,QAAQ,qBArOlC,EAAM,iCAyOA,6BAA6B,IA5PlC",
4
+ "sourcesContent": ["namespace gdjs {\n const isSpine = (obj: any): obj is pixi_spine.Spine =>\n obj instanceof pixi_spine.Spine;\n\n // See https://github.com/pixijs/spine/issues/562\n // IPointAttachment is not declared and exported but its implementation does exist and it is used in runtime\n interface IPointAttachment extends pixi_spine.IVertexAttachment {\n computeWorldPosition(\n bone: pixi_spine.IBone,\n point: pixi_spine.Vector2\n ): pixi_spine.Vector2;\n computeWorldRotation(bone: pixi_spine.IBone): number;\n }\n\n const isPointAttachment = (\n attachment: pixi_spine.IAttachment\n ): attachment is IPointAttachment =>\n !!attachment && attachment.type === pixi_spine.AttachmentType.Point;\n\n export class SpineRuntimeObjectPixiRenderer {\n private _object: gdjs.SpineRuntimeObject;\n private _rendererObject: pixi_spine.Spine | PIXI.Container;\n private _isAnimationComplete = true;\n\n /**\n * @param runtimeObject The object to render\n * @param instanceContainer The container in which the object is\n */\n constructor(\n runtimeObject: gdjs.SpineRuntimeObject,\n private instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._object = runtimeObject;\n this._rendererObject = this.constructRendererObject();\n if (isSpine(this._rendererObject)) {\n this._rendererObject.autoUpdate = false;\n }\n\n this.updatePosition();\n this.updateAngle();\n this.updateOpacity();\n this.updateScale();\n\n instanceContainer\n .getLayer('')\n .getRenderer()\n .addRendererObject(this._rendererObject, runtimeObject.getZOrder());\n }\n\n updateAnimation(timeDelta: float) {\n if (!isSpine(this._rendererObject)) {\n return;\n }\n this._rendererObject.update(timeDelta);\n }\n\n getRendererObject(): pixi_spine.Spine | PIXI.Container {\n return this._rendererObject;\n }\n\n getOriginOffset(): PIXI.Point {\n if (!isSpine(this._rendererObject)) return new PIXI.Point(0, 0);\n\n const localBounds = this._rendererObject.getLocalBounds(undefined, true);\n\n return new PIXI.Point(\n localBounds.x * this._rendererObject.scale.x,\n localBounds.y * this._rendererObject.scale.y\n );\n }\n\n onDestroy(): void {\n this._rendererObject.destroy();\n }\n\n updateScale(): void {\n const scaleX = Math.max(\n this._object._originalScale * this._object.getScaleX(),\n 0\n );\n const scaleY = Math.max(\n this._object._originalScale * this._object.getScaleY(),\n 0\n );\n this._rendererObject.scale.x = this._object.isFlippedX()\n ? -scaleX\n : scaleX;\n this._rendererObject.scale.y = this._object.isFlippedY()\n ? -scaleY\n : scaleY;\n }\n\n updatePosition(): void {\n this._rendererObject.position.x = this._object.x;\n this._rendererObject.position.y = this._object.y;\n }\n\n updateAngle(): void {\n this._rendererObject.rotation = gdjs.toRad(this._object.angle);\n }\n\n updateOpacity(): void {\n this._rendererObject.alpha = this._object.getOpacity() / 255;\n }\n\n getWidth(): float {\n return this._rendererObject.width;\n }\n\n getHeight(): float {\n return this._rendererObject.height;\n }\n\n setWidth(width: float): void {\n this._rendererObject.width = width;\n }\n\n setHeight(height: float): void {\n this._rendererObject.height = height;\n }\n\n getUnscaledWidth(): float {\n return Math.abs(\n (this._rendererObject.width * this._object._originalScale) /\n this._rendererObject.scale.x\n );\n }\n\n getUnscaledHeight(): float {\n return Math.abs(\n (this._rendererObject.height * this._object._originalScale) /\n this._rendererObject.scale.y\n );\n }\n\n setMixing(from: string, to: string, duration: number): void {\n if (!isSpine(this._rendererObject)) return;\n\n this._rendererObject.stateData.setMix(from, to, duration);\n }\n\n setAnimation(animation: string, loop: boolean): void {\n if (isSpine(this._rendererObject)) {\n const onCompleteListener: pixi_spine.IAnimationStateListener = {\n complete: () => {\n this._isAnimationComplete = true;\n (this._rendererObject as pixi_spine.Spine).state.removeListener(\n onCompleteListener\n );\n },\n };\n\n this._isAnimationComplete = false;\n this._rendererObject.state.addListener(onCompleteListener);\n this._rendererObject.state.setAnimation(0, animation, loop);\n this._rendererObject.update(0);\n }\n }\n\n getAnimationDuration(sourceAnimationName: string) {\n if (!isSpine(this._rendererObject)) {\n return 0;\n }\n const animation =\n this._rendererObject.spineData.findAnimation(sourceAnimationName);\n return animation ? animation.duration : 0;\n }\n\n getAnimationElapsedTime(): number {\n if (!isSpine(this._rendererObject)) {\n return 0;\n }\n const tracks = this._rendererObject.state.tracks;\n if (tracks.length === 0) {\n return 0;\n }\n // This should be fine because only 1 track is used.\n const track = tracks[0];\n // @ts-ignore TrackEntry.getAnimationTime is not exposed.\n return track.getAnimationTime();\n }\n\n setAnimationElapsedTime(time: number): void {\n if (!isSpine(this._rendererObject)) {\n return;\n }\n const tracks = this._rendererObject.state.tracks;\n if (tracks.length === 0) {\n return;\n }\n const track = tracks[0];\n track.trackTime = time;\n }\n\n isAnimationComplete(): boolean {\n if (!isSpine(this._rendererObject)) {\n return true;\n }\n const track = this._rendererObject.state.tracks[0];\n if (!track) {\n return true;\n }\n return this._isAnimationComplete && !track.loop;\n }\n\n getPointAttachmentPosition(\n attachmentName: string,\n slotName?: string\n ): pixi_spine.Vector2 {\n if (!slotName) {\n slotName = attachmentName;\n }\n if (!isSpine(this._rendererObject)) {\n return new pixi_spine.Vector2(\n this._rendererObject.x,\n this._rendererObject.y\n );\n }\n const slot = this._rendererObject.skeleton.findSlot(slotName);\n if (!slot) {\n throw new Error(\n `Unable to find ${slotName} slot name for ${attachmentName} point attachment.`\n );\n }\n const attachment = this._rendererObject.skeleton.getAttachmentByName(\n slotName,\n attachmentName\n );\n if (!isPointAttachment(attachment)) {\n throw new Error(\n `Unable to find ${attachmentName} point attachment with ${slotName} slot name.`\n );\n }\n\n return new PIXI.Matrix()\n .rotate(this._rendererObject.rotation)\n .scale(this._rendererObject.scale.x, this._rendererObject.scale.y)\n .translate(this._rendererObject.x, this._rendererObject.y)\n .apply(\n attachment.computeWorldPosition(slot.bone, new pixi_spine.Vector2())\n );\n }\n\n private constructRendererObject(): pixi_spine.Spine | PIXI.Container {\n const game = this.instanceContainer.getGame();\n const spineManager = game.getSpineManager();\n\n if (\n !spineManager ||\n !spineManager.isSpineLoaded(this._object.spineResourceName)\n ) {\n return new PIXI.Container();\n }\n\n return new pixi_spine.Spine(\n spineManager.getSpine(this._object.spineResourceName)!\n );\n }\n }\n export const SpineRuntimeObjectRenderer = SpineRuntimeObjectPixiRenderer;\n}\n"],
5
+ "mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAU,AAAC,GACf,YAAe,YAAW,MAYtB,EAAoB,AACxB,GAEA,CAAC,CAAC,GAAc,EAAW,OAAS,WAAW,eAAe,MAEzD,OAAqC,CAS1C,YACE,EACQ,EACR,CADQ,yBARF,0BAAuB,GAU7B,KAAK,QAAU,EACf,KAAK,gBAAkB,KAAK,0BACxB,EAAQ,KAAK,kBACf,MAAK,gBAAgB,WAAa,IAGpC,KAAK,iBACL,KAAK,cACL,KAAK,gBACL,KAAK,cAEL,EACG,SAAS,IACT,cACA,kBAAkB,KAAK,gBAAiB,EAAc,aAG3D,gBAAgB,EAAkB,CAChC,AAAI,CAAC,EAAQ,KAAK,kBAGlB,KAAK,gBAAgB,OAAO,GAG9B,mBAAuD,CACrD,MAAO,MAAK,gBAGd,iBAA8B,CAC5B,GAAI,CAAC,EAAQ,KAAK,iBAAkB,MAAO,IAAI,MAAK,MAAM,EAAG,GAE7D,KAAM,GAAc,KAAK,gBAAgB,eAAe,OAAW,IAEnE,MAAO,IAAI,MAAK,MACd,EAAY,EAAI,KAAK,gBAAgB,MAAM,EAC3C,EAAY,EAAI,KAAK,gBAAgB,MAAM,GAI/C,WAAkB,CAChB,KAAK,gBAAgB,UAGvB,aAAoB,CAClB,KAAM,GAAS,KAAK,IAClB,KAAK,QAAQ,eAAiB,KAAK,QAAQ,YAC3C,GAEI,EAAS,KAAK,IAClB,KAAK,QAAQ,eAAiB,KAAK,QAAQ,YAC3C,GAEF,KAAK,gBAAgB,MAAM,EAAI,KAAK,QAAQ,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OlC,EAAM,iCAgPA,6BAA6B,IAnQlC",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){const h=new a.Logger("Audio manager"),f=["audio"],_={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class g{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=g;class p{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._cachedSpatialPosition={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e,a.registerRuntimeScenePostEventsCallback(this._clearCachedSpatialPosition.bind(this));const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return f}static clampRate(e){return e>4?4:e<.5?.5:e}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);if(!n){const c=r?r.file:e;n=new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(c)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(c)},volume:0},_)),l.set(r,n)}return new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(o.file)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},_)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i),r=this._cachedSpatialPosition[s];r&&l.once("play",()=>{l.setSpatialPosition(...r)}),this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setSoundSpatialPositionOnChannel(e,s,t,o){const i=this.getSoundOnChannel(e);i&&!i.paused()?i.setSpatialPosition(s,t,o):this._cachedSpatialPosition[e]=[s,t,o]}_clearCachedSpatialPosition(){this._cachedSpatialPosition={}}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}const t=(i,l)=>new Promise((r,n)=>{const c=l?this._loadedMusics:this._loadedSounds;c[i]=new Howl(Object.assign({},_,{src:[this._resourceLoader.getFullUrl(i)],onload:r,onloaderror:(S,w)=>n(w),html5:l,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(i)},volume:0}))}),o=s.file;if(s.preloadAsMusic)try{await t(o,!0)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}if(s.preloadAsSound)try{await t(o,!1)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}else if(s.preloadInCache||!s.preloadAsMusic)try{await new Promise((i,l)=>{const r=new XMLHttpRequest;r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(o),r.addEventListener("load",i),r.addEventListener("error",n=>l("XHR error: "+o)),r.addEventListener("abort",n=>l("XHR abort: "+o)),r.open("GET",this._resourceLoader.getFullUrl(o)),r.send()})}catch(i){h.warn("There was an error while preloading an audio file: "+i)}}dispose(){this.unloadAll()}}a.HowlerSoundManager=p,a.SoundManager=p})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){const h=new a.Logger("Audio manager"),c=["audio"],_={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class p{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=p;class f{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._cachedSpatialPosition={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e,a.registerRuntimeScenePostEventsCallback(this._clearCachedSpatialPosition.bind(this));const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return c}static clampRate(e){return e>4?4:e<.5?.5:e}_getSoundUrlsFromResource(e){return[this._resourceLoader.getFullUrl(e.file)]}_getDefaultSoundUrl(e){return this._resourceLoader.getFullUrl(e.file)}_preloadAudioFile(e,s){const t=e.file;return new Promise((o,i)=>{const l=s?this._loadedMusics:this._loadedSounds;l[t]=new Howl(Object.assign({},_,{src:this._getSoundUrlsFromResource(e),onload:o,onloaderror:(r,n)=>i(n),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(t)},volume:0}))})}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);return n||(n=new Howl(Object.assign({src:this._getSoundUrlsFromResource(r),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(r.file)},volume:0},_)),l.set(r,n)),new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:this._getSoundUrlsFromResource(o),html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},_)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i),r=this._cachedSpatialPosition[s];r&&l.once("play",()=>{l.setSpatialPosition(...r)}),this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setSoundSpatialPositionOnChannel(e,s,t,o){const i=this.getSoundOnChannel(e);i&&!i.paused()?i.setSpatialPosition(s,t,o):this._cachedSpatialPosition[e]=[s,t,o]}_clearCachedSpatialPosition(){this._cachedSpatialPosition={}}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}if(s.preloadAsMusic)try{await this._preloadAudioFile(s,!0)}catch(t){h.warn("There was an error while preloading an audio file: "+t)}if(s.preloadAsSound)try{await this._preloadAudioFile(s,!1)}catch(t){h.warn("There was an error while preloading an audio file: "+t)}else if(s.preloadInCache||!s.preloadAsMusic)try{const t=s.file;await new Promise((o,i)=>{const l=new XMLHttpRequest;l.withCredentials=this._resourceLoader.checkIfCredentialsRequired(t),l.addEventListener("load",o),l.addEventListener("error",r=>i("XHR error: "+t)),l.addEventListener("abort",r=>i("XHR abort: "+t)),l.open("GET",this._getDefaultSoundUrl(s)),l.send()})}catch(t){h.warn("There was an error while preloading an audio file: "+t)}}dispose(){this.unloadAll()}}a.HowlerSoundManager=f,a.SoundManager=f})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=howler-sound-manager.js.map