gdcore-tools 2.0.0-gd-v5.5.236-autobuild → 2.0.0-gd-v5.5.237-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.
- package/dist/Runtime/CustomRuntimeObject.js +1 -1
- package/dist/Runtime/CustomRuntimeObject.js.map +2 -2
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js +1 -1
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js.map +2 -2
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObjectPixiRenderer.js +1 -1
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObjectPixiRenderer.js.map +2 -2
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/DirectionalLight.js +1 -1
- package/dist/Runtime/Extensions/3D/DirectionalLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/HemisphereLight.js +1 -1
- package/dist/Runtime/Extensions/3D/HemisphereLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/JsExtension.js +5 -4
- package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +67 -0
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/JsExtension.js +48 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/JsExtension.js +26 -0
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js.map +2 -2
- package/dist/Runtime/events-tools/inputtools.js +1 -1
- package/dist/Runtime/events-tools/inputtools.js.map +2 -2
- package/dist/Runtime/runtimeobject.js +1 -1
- package/dist/Runtime/runtimeobject.js.map +2 -2
- package/dist/Runtime/types/project-data.d.ts +4 -0
- package/dist/lib/libGD.wasm +0 -0
- package/package.json +1 -1
|
@@ -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 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 const boxMesh = new THREE.Mesh(geometry, materials);\n\n super(runtimeObject, instanceContainer, boxMesh);\n this._boxMesh = boxMesh;\n this._cube3DRuntimeObject = runtimeObject;\n\n boxMesh.receiveShadow = this._cube3DRuntimeObject._isCastingShadow;\n boxMesh.castShadow = this._cube3DRuntimeObject._isReceivingShadow;\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 updateShadowCasting() {\n this._boxMesh.castShadow = this._cube3DRuntimeObject._isCastingShadow;\n }\n updateShadowReceiving() {\n this._boxMesh.receiveShadow =\n this._cube3DRuntimeObject._isReceivingShadow;\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,EACH,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,GAGC,EAAwC,CAC5C,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,IAGH,EAAoE,CACxE,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,IAGT,GAAI,GACJ,KAAM,GAAyB,IACxB,IACH,GAAsB,GAAI,OAAM,kBAAkB,CAChD,YAAa,GACb,QAAS,EAGT,UAAW,KAGR,GAGH,EAAkB,CACtB,EACA,IAEK,EAAc,qBAAqB,GAGjC,EACJ,uBACA,UACA,kBACA,iBAAiB,EAAc,2BAA2B,GAAY,CACrE,sBAAuB,EAAc,8BACrC,mBACE,EAAc,gBACd,EAAK,oBAAoB,aAAa,MACxC,aAAc,KAXT,IAeX,eAA8C,GAAK,uBAAwB,CAIzE,YACE,EACA,EACA,CACA,KAAM,GAAW,GAAI,OAAM,YAAY,EAAG,EAAG,GAEvC,EAA8B,GAAI,OAAM,GAC3C,KAAK,GACL,IAAI,CAAC,EAAG,IACP,EAAgB,EAAe,EAAyB,KAEtD,EAAU,GAAI,OAAM,KAAK,EAAU,GAEzC,MAAM,EAAe,EAAmB,GACxC,KAAK,SAAW,EAChB,KAAK,qBAAuB,EAE5B,EAAQ,cAAgB,KAAK,qBAAqB,
|
|
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 const boxMesh = new THREE.Mesh(geometry, materials);\n\n super(runtimeObject, instanceContainer, boxMesh);\n this._boxMesh = boxMesh;\n this._cube3DRuntimeObject = runtimeObject;\n\n boxMesh.receiveShadow = this._cube3DRuntimeObject._isReceivingShadow;\n boxMesh.castShadow = this._cube3DRuntimeObject._isCastingShadow;\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 updateShadowCasting() {\n this._boxMesh.castShadow = this._cube3DRuntimeObject._isCastingShadow;\n }\n updateShadowReceiving() {\n this._boxMesh.receiveShadow =\n this._cube3DRuntimeObject._isReceivingShadow;\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,EACH,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,GAGC,EAAwC,CAC5C,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,IAGH,EAAoE,CACxE,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,GACP,EAAG,CAAC,EAAG,IAGT,GAAI,GACJ,KAAM,GAAyB,IACxB,IACH,GAAsB,GAAI,OAAM,kBAAkB,CAChD,YAAa,GACb,QAAS,EAGT,UAAW,KAGR,GAGH,EAAkB,CACtB,EACA,IAEK,EAAc,qBAAqB,GAGjC,EACJ,uBACA,UACA,kBACA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,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,IApVnC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(r){class s extends r.CustomRuntimeObject{constructor(t,i){super(t,i);this._z=0;this._minZ=0;this._maxZ=0;this._scaleZ=1;this._flippedZ=!1;this._rotationX=0;this._rotationY=0;this._customCenterZ=0}_createRender(){const t=this._runtimeScene;return new r.CustomRuntimeObject3DRenderer(this,this._instanceContainer,t)}_reinitializeRenderer(){this.getRenderer().reinitialize(this,this.getParent())}getRenderer(){return super.getRenderer()}get3DRendererObject(){return this.getRenderer().get3DRendererObject()}extraInitializationFromInitialInstance(t){super.extraInitializationFromInitialInstance(t),t.depth!==void 0&&this.setDepth(t.depth),t.flippedX&&this.flipX(t.flippedX),t.flippedY&&this.flipY(t.flippedY),t.flippedZ&&this.flipZ(t.flippedZ)}getNetworkSyncData(){return{...super.getNetworkSyncData(),z:this.getZ(),d:this.getDepth(),rx:this.getRotationX(),ry:this.getRotationY(),ifz:this.isFlippedZ()}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t),t.z!==void 0&&this.setZ(t.z),t.d!==void 0&&this.setDepth(t.d),t.rx!==void 0&&this.setRotationX(t.rx),t.ry!==void 0&&this.setRotationY(t.ry),t.ifz!==void 0&&this.flipZ(t.ifz)}setZ(t){t!==this._z&&(this._z=t,this.getRenderer().updatePosition())}getZ(){return this._z}getDrawableZ(){let t=0;this._innerArea?t=this._innerArea.min[2]:(this._isUntransformedHitBoxesDirty&&this._updateUntransformedHitBoxes(),t=this._minZ);const i=this.getScaleZ();return this._flippedZ?this._z+(-t-this.getUnscaledDepth()+2*this.getUnscaledCenterZ())*i:this._z+t*i}getCenterZ(){return this.getDepth()/2}getCenterZInScene(){return this.getDrawableZ()+this.getCenterZ()}setCenterZInScene(t){this.setZ(t+this._z-(this.getDrawableZ()+this.getCenterZ()))}getUnrotatedAABBMinZ(){return this.getDrawableZ()}getUnrotatedAABBMaxZ(){return this.getDrawableZ()+this.getDepth()}setRotationX(t){this._rotationX=t,this.getRenderer().updateRotation()}setRotationY(t){this._rotationY=t,this.getRenderer().updateRotation()}getRotationX(){return this._rotationX}getRotationY(){return this._rotationY}turnAroundX(t){const i=r.CustomRuntimeObject3D._temporaryVector;i.set(1,0,0);const e=this.get3DRendererObject();e.rotateOnWorldAxis(i,r.toRad(t)),this._rotationX=r.toDegrees(e.rotation.x),this._rotationY=r.toDegrees(e.rotation.y),this.setAngle(r.toDegrees(e.rotation.z))}turnAroundY(t){const i=r.CustomRuntimeObject3D._temporaryVector;i.set(0,1,0);const e=this.get3DRendererObject();e.rotateOnWorldAxis(i,r.toRad(t)),this._rotationX=r.toDegrees(e.rotation.x),this._rotationY=r.toDegrees(e.rotation.y),this.setAngle(r.toDegrees(e.rotation.z))}turnAroundZ(t){const i=r.CustomRuntimeObject3D._temporaryVector;i.set(0,0,1);const e=this.get3DRendererObject();e.rotateOnWorldAxis(i,r.toRad(t)),this._rotationX=r.toDegrees(e.rotation.x),this._rotationY=r.toDegrees(e.rotation.y),this.setAngle(r.toDegrees(e.rotation.z))}getInnerAreaMinZ(){return this._innerArea?this._innerArea.min[2]:(this._isUntransformedHitBoxesDirty&&this._updateUntransformedHitBoxes(),this._minZ)}getInnerAreaMaxZ(){return this._innerArea?this._innerArea.max[2]:(this._isUntransformedHitBoxesDirty&&this._updateUntransformedHitBoxes(),this._maxZ)}getUnscaledDepth(){return this._innerArea?this._innerArea.max[2]-this._innerArea.min[2]:(this._isUntransformedHitBoxesDirty&&this._updateUntransformedHitBoxes(),this._maxZ-this._minZ)}_updateUntransformedHitBoxes(){super._updateUntransformedHitBoxes();let t=Number.MAX_VALUE,i=-Number.MAX_VALUE;for(const e of this._instanceContainer.getAdhocListOfAllInstances())!e.isIncludedInParentCollisionMask()||!r.Base3DHandler.is3D(e)||(t=Math.min(t,e.getUnrotatedAABBMinZ()),i=Math.max(i,e.getUnrotatedAABBMaxZ()));t===Number.MAX_VALUE&&(t=0,i=1),this._minZ=t,this._maxZ=i}getUnscaledCenterZ(){return this.hasCustomRotationCenter()?this._customCenterZ:this._innerArea?(this._innerArea.min[2]+this._innerArea.max[2])/2:(this._isUntransformedHitBoxesDirty&&this._updateUntransformedHitBoxes(),(this._minZ+this._maxZ)/2)}setRotationCenter3D(t,i,e){this._customCenterZ=e,this.setRotationCenter(t,i)}getDepth(){return this.getUnscaledDepth()*this.getScaleZ()}setDepth(t){const i=this.getUnscaledDepth();if(i===0)return;const e=t/i;this._innerArea&&this._isInnerAreaFollowingParentSize?(this._innerArea.min[2]*=e,this._innerArea.max[2]*=e):this.setScaleZ(e)}setScale(t){super.setScale(t),this.setScaleZ(t)}setScaleZ(t){this._innerArea&&this._isInnerAreaFollowingParentSize||(t<0&&(t=0),t!==Math.abs(this._scaleZ)&&(this._scaleZ=t*(this._flippedZ?-1:1),this.getRenderer().updateSize()))}getScale(){const t=this.getScaleX(),i=this.getScaleY(),e=this.getScaleZ();return t===i&&t===e?t:Math.pow(t*i*e,1/3)}getScaleZ(){return Math.abs(this._scaleZ)}flipZ(t){t!==this._flippedZ&&(this._flippedZ=t,this.getRenderer().updateSize())}isFlippedZ(){return this._flippedZ}}s._temporaryVector=new THREE.Vector3,r.CustomRuntimeObject3D=s})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=CustomRuntimeObject3D.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/3D/CustomRuntimeObject3D.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n /**\n * Base class for 3D custom objects.\n */\n export class CustomRuntimeObject3D\n extends gdjs.CustomRuntimeObject\n implements gdjs.Base3DHandler\n {\n /**\n * Position on the Z axis.\n */\n private _z: float = 0;\n private _minZ: float = 0;\n private _maxZ: float = 0;\n private _scaleZ: float = 1;\n private _flippedZ: boolean = false;\n /**\n * Euler angle with the `ZYX` order.\n *\n * Note that `_rotationZ` is `angle` from `gdjs.RuntimeObject`.\n */\n private _rotationX: float = 0;\n /**\n * Euler angle with the `ZYX` order.\n *\n * Note that `_rotationZ` is `angle` from `gdjs.RuntimeObject`.\n */\n private _rotationY: float = 0;\n private _customCenterZ: float = 0;\n private static _temporaryVector = new THREE.Vector3();\n\n constructor(\n parent: gdjs.RuntimeInstanceContainer,\n objectData: gdjs.Object3DData & gdjs.CustomObjectConfiguration\n ) {\n super(parent, objectData);\n }\n\n protected override _createRender() {\n const parent = this._runtimeScene;\n return new gdjs.CustomRuntimeObject3DRenderer(\n this,\n this._instanceContainer,\n parent\n );\n }\n\n protected override _reinitializeRenderer(): void {\n this.getRenderer().reinitialize(this, this.getParent());\n }\n\n override getRenderer(): gdjs.CustomRuntimeObject3DRenderer {\n return super.getRenderer() as gdjs.CustomRuntimeObject3DRenderer;\n }\n\n override get3DRendererObject() {\n // It can't be null because Three.js is always loaded\n // when a custom 3D object is used.\n return this.getRenderer().get3DRendererObject()!;\n }\n\n override extraInitializationFromInitialInstance(\n initialInstanceData: InstanceData\n ) {\n super.extraInitializationFromInitialInstance(initialInstanceData);\n if (initialInstanceData.depth !== undefined) {\n this.setDepth(initialInstanceData.depth);\n }\n if (initialInstanceData.flippedX) {\n this.flipX(initialInstanceData.flippedX);\n }\n if (initialInstanceData.flippedY) {\n this.flipY(initialInstanceData.flippedY);\n }\n if (initialInstanceData.flippedZ) {\n this.flipZ(initialInstanceData.flippedZ);\n }\n }\n\n /**\n * Set the object position on the Z axis.\n */\n setZ(z: float): void {\n if (z === this._z) return;\n this._z = z;\n this.getRenderer().updatePosition();\n }\n\n /**\n * Get the object position on the Z axis.\n */\n getZ(): float {\n return this._z;\n }\n\n /**\n * Get the Z position of the rendered object.\n *\n * For most objects, this will returns the same value as getZ(). But if the\n * object has an origin that is not the same as the point (0,0,0) of the\n * object displayed, getDrawableZ will differ.\n *\n * @return The Z position of the rendered object.\n */\n getDrawableZ(): float {\n let minZ = 0;\n if (this._innerArea) {\n minZ = this._innerArea.min[2];\n } else {\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n minZ = this._minZ;\n }\n const absScaleZ = this.getScaleZ();\n if (!this._flippedZ) {\n return this._z + minZ * absScaleZ;\n } else {\n return (\n this._z +\n (-minZ - this.getUnscaledDepth() + 2 * this.getUnscaledCenterZ()) *\n absScaleZ\n );\n }\n }\n\n /**\n * Return the Z position of the object center, **relative to the object Z\n * position** (`getDrawableX`).\n *\n * Use `getCenterZInScene` to get the position of the center in the scene.\n *\n * @return the Z position of the object center, relative to\n * `getDrawableZ()`.\n */\n getCenterZ(): float {\n return this.getDepth() / 2;\n }\n\n getCenterZInScene(): float {\n return this.getDrawableZ() + this.getCenterZ();\n }\n\n setCenterZInScene(z: float): void {\n this.setZ(z + this._z - (this.getDrawableZ() + this.getCenterZ()));\n }\n\n /**\n * Return the bottom Z of the object.\n * Rotations around X and Y are not taken into account.\n */\n getUnrotatedAABBMinZ(): number {\n return this.getDrawableZ();\n }\n\n /**\n * Return the top Z of the object.\n * Rotations around X and Y are not taken into account.\n */\n getUnrotatedAABBMaxZ(): number {\n return this.getDrawableZ() + this.getDepth();\n }\n\n /**\n * Set the object rotation on the X axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n setRotationX(angle: float): void {\n this._rotationX = angle;\n this.getRenderer().updateRotation();\n }\n\n /**\n * Set the object rotation on the Y axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n setRotationY(angle: float): void {\n this._rotationY = angle;\n this.getRenderer().updateRotation();\n }\n\n /**\n * Get the object rotation on the X axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n getRotationX(): float {\n return this._rotationX;\n }\n\n /**\n * Get the object rotation on the Y axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n getRotationY(): float {\n return this._rotationY;\n }\n\n /**\n * Turn the object around the scene x axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundX(deltaAngle: float): void {\n const axisX = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisX.set(1, 0, 0);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisX, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * Turn the object around the scene y axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundY(deltaAngle: float): void {\n const axisY = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisY.set(0, 1, 0);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisY, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * Turn the object around the scene z axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundZ(deltaAngle: float): void {\n const axisZ = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisZ.set(0, 0, 1);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisZ, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * @return the internal top bound of the object according to its children.\n */\n getInnerAreaMinZ(): number {\n if (this._innerArea) {\n return this._innerArea.min[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._minZ;\n }\n\n /**\n * @return the internal bottom bound of the object according to its children.\n */\n getInnerAreaMaxZ(): number {\n if (this._innerArea) {\n return this._innerArea.max[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._maxZ;\n }\n\n /**\n * @return the internal width of the object according to its children.\n */\n getUnscaledDepth(): float {\n if (this._innerArea) {\n return this._innerArea.max[2] - this._innerArea.min[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._maxZ - this._minZ;\n }\n\n override _updateUntransformedHitBoxes(): void {\n super._updateUntransformedHitBoxes();\n\n let minZ = Number.MAX_VALUE;\n let maxZ = -Number.MAX_VALUE;\n for (const childInstance of this._instanceContainer.getAdhocListOfAllInstances()) {\n if (!childInstance.isIncludedInParentCollisionMask()) {\n continue;\n }\n if (!gdjs.Base3DHandler.is3D(childInstance)) {\n continue;\n }\n minZ = Math.min(minZ, childInstance.getUnrotatedAABBMinZ());\n maxZ = Math.max(maxZ, childInstance.getUnrotatedAABBMaxZ());\n }\n if (minZ === Number.MAX_VALUE) {\n // The unscaled size can't be 0 because setWidth and setHeight wouldn't\n // have any effect.\n minZ = 0;\n maxZ = 1;\n }\n this._minZ = minZ;\n this._maxZ = maxZ;\n }\n\n /**\n * @returns the center Z from the local origin (0;0).\n */\n getUnscaledCenterZ(): float {\n if (this.hasCustomRotationCenter()) {\n return this._customCenterZ;\n }\n if (this._innerArea) {\n return (this._innerArea.min[2] + this._innerArea.max[2]) / 2;\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return (this._minZ + this._maxZ) / 2;\n }\n\n /**\n * The center of rotation is defined relatively to the origin (the object\n * position).\n * This avoids the center to move when children push the bounds.\n *\n * When no custom center is defined, it will move\n * to stay at the center of the children bounds.\n *\n * @param x coordinate of the custom center\n * @param y coordinate of the custom center\n */\n setRotationCenter3D(x: float, y: float, z: float) {\n this._customCenterZ = z;\n this.setRotationCenter(x, y);\n }\n\n /**\n * Get the object size on the Z axis (called \"depth\").\n */\n getDepth(): float {\n return this.getUnscaledDepth() * this.getScaleZ();\n }\n\n /**\n * Set the object size on the Z axis (called \"depth\").\n */\n setDepth(depth: float): void {\n const unscaledDepth = this.getUnscaledDepth();\n if (unscaledDepth === 0) {\n return;\n }\n const scaleZ = depth / unscaledDepth;\n if (this._innerArea && this._isInnerAreaFollowingParentSize) {\n this._innerArea.min[2] *= scaleZ;\n this._innerArea.max[2] *= scaleZ;\n } else {\n this.setScaleZ(scaleZ);\n }\n }\n\n /**\n * Change the scale on X, Y and Z axis of the object.\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScale(newScale: number): void {\n super.setScale(newScale);\n this.setScaleZ(newScale);\n }\n\n /**\n * Change the scale on Z axis of the object (changing its height).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleZ(newScale: number): void {\n if (this._innerArea && this._isInnerAreaFollowingParentSize) {\n // The scale is always 1;\n return;\n }\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleZ)) {\n return;\n }\n this._scaleZ = newScale * (this._flippedZ ? -1 : 1);\n this.getRenderer().updateSize();\n }\n\n /**\n * Get the scale of the object (or the geometric average of X, Y and Z scale in case they are different).\n *\n * @return the scale of the object (or the geometric average of X, Y and Z scale in case they are different).\n */\n getScale(): number {\n const scaleX = this.getScaleX();\n const scaleY = this.getScaleY();\n const scaleZ = this.getScaleZ();\n return scaleX === scaleY && scaleX === scaleZ\n ? scaleX\n : Math.pow(scaleX * scaleY * scaleZ, 1 / 3);\n }\n\n /**\n * Get the scale of the object on Z axis.\n *\n * @return the scale of the object on Z axis\n */\n getScaleZ(): float {\n return Math.abs(this._scaleZ);\n }\n\n flipZ(enable: boolean) {\n if (enable === this._flippedZ) {\n return;\n }\n this._flippedZ = enable;\n this.getRenderer().updateSize();\n }\n\n isFlippedZ(): boolean {\n return this._flippedZ;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n type CustomObject3DNetworkSyncDataType = CustomObjectNetworkSyncDataType & {\n z: float;\n d: float;\n rx: float;\n ry: float;\n ifz: boolean;\n };\n\n /**\n * Base class for 3D custom objects.\n */\n export class CustomRuntimeObject3D\n extends gdjs.CustomRuntimeObject\n implements gdjs.Base3DHandler\n {\n /**\n * Position on the Z axis.\n */\n private _z: float = 0;\n private _minZ: float = 0;\n private _maxZ: float = 0;\n private _scaleZ: float = 1;\n private _flippedZ: boolean = false;\n /**\n * Euler angle with the `ZYX` order.\n *\n * Note that `_rotationZ` is `angle` from `gdjs.RuntimeObject`.\n */\n private _rotationX: float = 0;\n /**\n * Euler angle with the `ZYX` order.\n *\n * Note that `_rotationZ` is `angle` from `gdjs.RuntimeObject`.\n */\n private _rotationY: float = 0;\n private _customCenterZ: float = 0;\n private static _temporaryVector = new THREE.Vector3();\n\n constructor(\n parent: gdjs.RuntimeInstanceContainer,\n objectData: gdjs.Object3DData & gdjs.CustomObjectConfiguration\n ) {\n super(parent, objectData);\n }\n\n protected override _createRender() {\n const parent = this._runtimeScene;\n return new gdjs.CustomRuntimeObject3DRenderer(\n this,\n this._instanceContainer,\n parent\n );\n }\n\n protected override _reinitializeRenderer(): void {\n this.getRenderer().reinitialize(this, this.getParent());\n }\n\n override getRenderer(): gdjs.CustomRuntimeObject3DRenderer {\n return super.getRenderer() as gdjs.CustomRuntimeObject3DRenderer;\n }\n\n override get3DRendererObject() {\n // It can't be null because Three.js is always loaded\n // when a custom 3D object is used.\n return this.getRenderer().get3DRendererObject()!;\n }\n\n override extraInitializationFromInitialInstance(\n initialInstanceData: InstanceData\n ) {\n super.extraInitializationFromInitialInstance(initialInstanceData);\n if (initialInstanceData.depth !== undefined) {\n this.setDepth(initialInstanceData.depth);\n }\n if (initialInstanceData.flippedX) {\n this.flipX(initialInstanceData.flippedX);\n }\n if (initialInstanceData.flippedY) {\n this.flipY(initialInstanceData.flippedY);\n }\n if (initialInstanceData.flippedZ) {\n this.flipZ(initialInstanceData.flippedZ);\n }\n }\n\n getNetworkSyncData(): CustomObject3DNetworkSyncDataType {\n return {\n ...super.getNetworkSyncData(),\n z: this.getZ(),\n d: this.getDepth(),\n rx: this.getRotationX(),\n ry: this.getRotationY(),\n ifz: this.isFlippedZ(),\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: CustomObject3DNetworkSyncDataType\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n if (networkSyncData.z !== undefined) this.setZ(networkSyncData.z);\n if (networkSyncData.d !== undefined) this.setDepth(networkSyncData.d);\n if (networkSyncData.rx !== undefined)\n this.setRotationX(networkSyncData.rx);\n if (networkSyncData.ry !== undefined)\n this.setRotationY(networkSyncData.ry);\n if (networkSyncData.ifz !== undefined) this.flipZ(networkSyncData.ifz);\n }\n\n /**\n * Set the object position on the Z axis.\n */\n setZ(z: float): void {\n if (z === this._z) return;\n this._z = z;\n this.getRenderer().updatePosition();\n }\n\n /**\n * Get the object position on the Z axis.\n */\n getZ(): float {\n return this._z;\n }\n\n /**\n * Get the Z position of the rendered object.\n *\n * For most objects, this will returns the same value as getZ(). But if the\n * object has an origin that is not the same as the point (0,0,0) of the\n * object displayed, getDrawableZ will differ.\n *\n * @return The Z position of the rendered object.\n */\n getDrawableZ(): float {\n let minZ = 0;\n if (this._innerArea) {\n minZ = this._innerArea.min[2];\n } else {\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n minZ = this._minZ;\n }\n const absScaleZ = this.getScaleZ();\n if (!this._flippedZ) {\n return this._z + minZ * absScaleZ;\n } else {\n return (\n this._z +\n (-minZ - this.getUnscaledDepth() + 2 * this.getUnscaledCenterZ()) *\n absScaleZ\n );\n }\n }\n\n /**\n * Return the Z position of the object center, **relative to the object Z\n * position** (`getDrawableX`).\n *\n * Use `getCenterZInScene` to get the position of the center in the scene.\n *\n * @return the Z position of the object center, relative to\n * `getDrawableZ()`.\n */\n getCenterZ(): float {\n return this.getDepth() / 2;\n }\n\n getCenterZInScene(): float {\n return this.getDrawableZ() + this.getCenterZ();\n }\n\n setCenterZInScene(z: float): void {\n this.setZ(z + this._z - (this.getDrawableZ() + this.getCenterZ()));\n }\n\n /**\n * Return the bottom Z of the object.\n * Rotations around X and Y are not taken into account.\n */\n getUnrotatedAABBMinZ(): number {\n return this.getDrawableZ();\n }\n\n /**\n * Return the top Z of the object.\n * Rotations around X and Y are not taken into account.\n */\n getUnrotatedAABBMaxZ(): number {\n return this.getDrawableZ() + this.getDepth();\n }\n\n /**\n * Set the object rotation on the X axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n setRotationX(angle: float): void {\n this._rotationX = angle;\n this.getRenderer().updateRotation();\n }\n\n /**\n * Set the object rotation on the Y axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n setRotationY(angle: float): void {\n this._rotationY = angle;\n this.getRenderer().updateRotation();\n }\n\n /**\n * Get the object rotation on the X axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n getRotationX(): float {\n return this._rotationX;\n }\n\n /**\n * Get the object rotation on the Y axis.\n *\n * This is an Euler angle. Objects use the `ZYX` order.\n */\n getRotationY(): float {\n return this._rotationY;\n }\n\n /**\n * Turn the object around the scene x axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundX(deltaAngle: float): void {\n const axisX = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisX.set(1, 0, 0);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisX, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * Turn the object around the scene y axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundY(deltaAngle: float): void {\n const axisY = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisY.set(0, 1, 0);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisY, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * Turn the object around the scene z axis at its center.\n * @param deltaAngle the rotation angle\n */\n turnAroundZ(deltaAngle: float): void {\n const axisZ = gdjs.CustomRuntimeObject3D._temporaryVector;\n axisZ.set(0, 0, 1);\n\n const mesh = this.get3DRendererObject();\n mesh.rotateOnWorldAxis(axisZ, gdjs.toRad(deltaAngle));\n this._rotationX = gdjs.toDegrees(mesh.rotation.x);\n this._rotationY = gdjs.toDegrees(mesh.rotation.y);\n this.setAngle(gdjs.toDegrees(mesh.rotation.z));\n }\n\n /**\n * @return the internal top bound of the object according to its children.\n */\n getInnerAreaMinZ(): number {\n if (this._innerArea) {\n return this._innerArea.min[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._minZ;\n }\n\n /**\n * @return the internal bottom bound of the object according to its children.\n */\n getInnerAreaMaxZ(): number {\n if (this._innerArea) {\n return this._innerArea.max[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._maxZ;\n }\n\n /**\n * @return the internal width of the object according to its children.\n */\n getUnscaledDepth(): float {\n if (this._innerArea) {\n return this._innerArea.max[2] - this._innerArea.min[2];\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return this._maxZ - this._minZ;\n }\n\n override _updateUntransformedHitBoxes(): void {\n super._updateUntransformedHitBoxes();\n\n let minZ = Number.MAX_VALUE;\n let maxZ = -Number.MAX_VALUE;\n for (const childInstance of this._instanceContainer.getAdhocListOfAllInstances()) {\n if (!childInstance.isIncludedInParentCollisionMask()) {\n continue;\n }\n if (!gdjs.Base3DHandler.is3D(childInstance)) {\n continue;\n }\n minZ = Math.min(minZ, childInstance.getUnrotatedAABBMinZ());\n maxZ = Math.max(maxZ, childInstance.getUnrotatedAABBMaxZ());\n }\n if (minZ === Number.MAX_VALUE) {\n // The unscaled size can't be 0 because setWidth and setHeight wouldn't\n // have any effect.\n minZ = 0;\n maxZ = 1;\n }\n this._minZ = minZ;\n this._maxZ = maxZ;\n }\n\n /**\n * @returns the center Z from the local origin (0;0).\n */\n getUnscaledCenterZ(): float {\n if (this.hasCustomRotationCenter()) {\n return this._customCenterZ;\n }\n if (this._innerArea) {\n return (this._innerArea.min[2] + this._innerArea.max[2]) / 2;\n }\n if (this._isUntransformedHitBoxesDirty) {\n this._updateUntransformedHitBoxes();\n }\n return (this._minZ + this._maxZ) / 2;\n }\n\n /**\n * The center of rotation is defined relatively to the origin (the object\n * position).\n * This avoids the center to move when children push the bounds.\n *\n * When no custom center is defined, it will move\n * to stay at the center of the children bounds.\n *\n * @param x coordinate of the custom center\n * @param y coordinate of the custom center\n */\n setRotationCenter3D(x: float, y: float, z: float) {\n this._customCenterZ = z;\n this.setRotationCenter(x, y);\n }\n\n /**\n * Get the object size on the Z axis (called \"depth\").\n */\n getDepth(): float {\n return this.getUnscaledDepth() * this.getScaleZ();\n }\n\n /**\n * Set the object size on the Z axis (called \"depth\").\n */\n setDepth(depth: float): void {\n const unscaledDepth = this.getUnscaledDepth();\n if (unscaledDepth === 0) {\n return;\n }\n const scaleZ = depth / unscaledDepth;\n if (this._innerArea && this._isInnerAreaFollowingParentSize) {\n this._innerArea.min[2] *= scaleZ;\n this._innerArea.max[2] *= scaleZ;\n } else {\n this.setScaleZ(scaleZ);\n }\n }\n\n /**\n * Change the scale on X, Y and Z axis of the object.\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScale(newScale: number): void {\n super.setScale(newScale);\n this.setScaleZ(newScale);\n }\n\n /**\n * Change the scale on Z axis of the object (changing its height).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleZ(newScale: number): void {\n if (this._innerArea && this._isInnerAreaFollowingParentSize) {\n // The scale is always 1;\n return;\n }\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleZ)) {\n return;\n }\n this._scaleZ = newScale * (this._flippedZ ? -1 : 1);\n this.getRenderer().updateSize();\n }\n\n /**\n * Get the scale of the object (or the geometric average of X, Y and Z scale in case they are different).\n *\n * @return the scale of the object (or the geometric average of X, Y and Z scale in case they are different).\n */\n getScale(): number {\n const scaleX = this.getScaleX();\n const scaleY = this.getScaleY();\n const scaleZ = this.getScaleZ();\n return scaleX === scaleY && scaleX === scaleZ\n ? scaleX\n : Math.pow(scaleX * scaleY * scaleZ, 1 / 3);\n }\n\n /**\n * Get the scale of the object on Z axis.\n *\n * @return the scale of the object on Z axis\n */\n getScaleZ(): float {\n return Math.abs(this._scaleZ);\n }\n\n flipZ(enable: boolean) {\n if (enable === this._flippedZ) {\n return;\n }\n this._flippedZ = enable;\n this.getRenderer().updateSize();\n }\n\n isFlippedZ(): boolean {\n return this._flippedZ;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAYS,eACG,GAAK,mBAEf,CAwBE,YACE,EACA,EACA,CACA,MAAM,EAAQ,GAxBR,QAAY,EACZ,WAAe,EACf,WAAe,EACf,aAAiB,EACjB,eAAqB,GAMrB,gBAAoB,EAMpB,gBAAoB,EACpB,oBAAwB,EAUb,eAAgB,CACjC,KAAM,GAAS,KAAK,cACpB,MAAO,IAAI,GAAK,8BACd,KACA,KAAK,mBACL,GAIe,uBAA8B,CAC/C,KAAK,cAAc,aAAa,KAAM,KAAK,aAGpC,aAAkD,CACzD,MAAO,OAAM,cAGN,qBAAsB,CAG7B,MAAO,MAAK,cAAc,sBAGnB,uCACP,EACA,CAC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AS,EAAS,EAAQ,EAAI,GAQ7C,WAAmB,CACjB,MAAO,MAAK,IAAI,KAAK,SAGvB,MAAM,EAAiB,CACrB,AAAI,IAAW,KAAK,WAGpB,MAAK,UAAY,EACjB,KAAK,cAAc,cAGrB,YAAsB,CACpB,MAAO,MAAK,WAvaC,AAzBV,EAyBU,iBAAmB,GAAI,OAAM,QAzBvC,EAAM,0BAZL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(e){const d=!1;e.PixiFiltersTools.registerFilterCreator("Scene3D::DirectionalLight",new class{makeFilter(u,c){return typeof THREE=="undefined"?new e.PixiFiltersTools.EmptyFilter:new class{constructor(){this.
|
|
1
|
+
var gdjs;(function(e){const d=!1;e.PixiFiltersTools.registerFilterCreator("Scene3D::DirectionalLight",new class{makeFilter(u,c){return typeof THREE=="undefined"?new e.PixiFiltersTools.EmptyFilter:new class{constructor(){this._top="Z+";this._elevation=45;this._rotation=0;this._shadowMapSize=1024;this._minimumShadowBias=0;this._distanceFromCamera=1500;this._frustumSize=4e3;this._isEnabled=!1;this._shadowMapDirty=!0;this._shadowCameraDirty=!0;this._light=new THREE.DirectionalLight,d?this._shadowCameraHelper=new THREE.CameraHelper(this._light.shadow.camera):this._shadowCameraHelper=null,this._light.shadow.camera.updateProjectionMatrix()}_updateShadowCamera(){!this._shadowCameraDirty||(this._shadowCameraDirty=!1,this._light.shadow.camera.near=1,this._light.shadow.camera.far=this._distanceFromCamera+1e4,this._light.shadow.camera.right=this._frustumSize/2,this._light.shadow.camera.left=-this._frustumSize/2,this._light.shadow.camera.top=this._frustumSize/2,this._light.shadow.camera.bottom=-this._frustumSize/2)}_updateShadowMapSize(){!this._shadowMapDirty||(this._shadowMapDirty=!1,this._light.shadow.mapSize.set(this._shadowMapSize,this._shadowMapSize),this._light.shadow.map?.dispose(),this._light.shadow.map=null,this._light.shadow.needsUpdate=!0)}isEnabled(t){return this._isEnabled}setEnabled(t,i){return this._isEnabled===i?!0:i?this.applyEffect(t):this.removeEffect(t)}applyEffect(t){const i=t.get3DRendererObject();return i?(i.add(this._light),i.add(this._light.target),this._shadowCameraHelper&&i.add(this._shadowCameraHelper),this._isEnabled=!0,!0):!1}removeEffect(t){const i=t.get3DRendererObject();return i?(i.remove(this._light),i.remove(this._light.target),this._shadowCameraHelper&&i.remove(this._shadowCameraHelper),this._isEnabled=!1,!0):!1}updatePreRender(t){this._updateShadowCamera(),this._updateShadowMapSize();const i=this._shadowMapSize<1024?2:this._shadowMapSize<2048?1.25:1;if(this._light.shadow.bias=-this._minimumShadowBias*i,!t.getRuntimeLayer)return;const s=t.getRuntimeLayer(),_=s.getCameraX(),f=s.getCameraY(),m=s.getCameraZ(s.getInitialCamera3DFieldOfView()),a=Math.floor(_/100)*100,o=Math.floor(f/100)*100,r=Math.floor(m/100)*100;if(this._top==="Y-"){const h=a+this._distanceFromCamera*Math.cos(e.toRad(-this._rotation+90))*Math.cos(e.toRad(this._elevation)),n=o-this._distanceFromCamera*Math.sin(e.toRad(this._elevation)),l=r+this._distanceFromCamera*Math.sin(e.toRad(-this._rotation+90))*Math.cos(e.toRad(this._elevation));this._light.position.set(h,n,l),this._light.target.position.set(a,o,r)}else{const h=a+this._distanceFromCamera*Math.cos(e.toRad(this._rotation))*Math.cos(e.toRad(this._elevation)),n=o+this._distanceFromCamera*Math.sin(e.toRad(this._rotation))*Math.cos(e.toRad(this._elevation)),l=r+this._distanceFromCamera*Math.sin(e.toRad(this._elevation));this._light.position.set(h,n,l),this._light.target.position.set(a,o,r)}}updateDoubleParameter(t,i){t==="intensity"?this._light.intensity=i:t==="elevation"?this._elevation=i:t==="rotation"?this._rotation=i:t==="distanceFromCamera"?this._distanceFromCamera=i:t==="frustumSize"?this._frustumSize=i:t==="minimumShadowBias"&&(this._minimumShadowBias=i)}getDoubleParameter(t){return t==="intensity"?this._light.intensity:t==="elevation"?this._elevation:t==="rotation"?this._rotation:t==="distanceFromCamera"?this._distanceFromCamera:t==="frustumSize"?this._frustumSize:t==="minimumShadowBias"?this._minimumShadowBias:0}updateStringParameter(t,i){t==="color"&&(this._light.color=new THREE.Color(e.rgbOrHexStringToNumber(i))),t==="top"&&(this._top=i),t==="shadowQuality"&&(i==="low"&&this._shadowMapSize!==512&&(this._shadowMapSize=512,this._shadowMapDirty=!0),i==="medium"&&this._shadowMapSize!==1024&&(this._shadowMapSize=1024,this._shadowMapDirty=!0),i==="high"&&this._shadowMapSize!==2048&&(this._shadowMapSize=2048,this._shadowMapDirty=!0))}updateColorParameter(t,i){t==="color"&&this._light.color.setHex(i)}getColorParameter(t){return t==="color"?this._light.color.getHex():0}updateBooleanParameter(t,i){t==="isCastingShadow"&&(this._light.castShadow=i)}getNetworkSyncData(){return{i:this._light.intensity,c:this._light.color.getHex(),e:this._elevation,r:this._rotation,t:this._top}}updateFromNetworkSyncData(t){this._light.intensity=t.i,this._light.color.setHex(t.c),this._elevation=t.e,this._rotation=t.r,this._top=t.t}}}})})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=DirectionalLight.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/3D/DirectionalLight.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n interface DirectionalLightFilterNetworkSyncData {\n i: number;\n c: number;\n e: number;\n r: number;\n t: string;\n }\n const shadowHelper = false;\n gdjs.PixiFiltersTools.registerFilterCreator(\n 'Scene3D::DirectionalLight',\n new (class implements gdjs.PixiFiltersTools.FilterCreator {\n makeFilter(\n target: EffectsTarget,\n effectData: EffectData\n ): gdjs.PixiFiltersTools.Filter {\n if (typeof THREE === 'undefined') {\n return new gdjs.PixiFiltersTools.EmptyFilter();\n }\n return new (class implements gdjs.PixiFiltersTools.Filter {\n private _light: THREE.DirectionalLight;\n private _isEnabled: boolean = false;\n private _top: string = 'Y-';\n private _elevation: float = 45;\n private _rotation: float = 0;\n\n private _shadowMapDirty = true;\n private _shadowMapSize: float = 1024;\n private _minimumShadowBias: float = 0;\n\n private _shadowCameraDirty = true;\n private _distanceFromCamera: float = 1500;\n private _frustumSize: float = 4000;\n private _shadowCameraHelper: THREE.CameraHelper | null;\n\n constructor() {\n this._light = new THREE.DirectionalLight();\n\n if (shadowHelper) {\n this._shadowCameraHelper = new THREE.CameraHelper(\n this._light.shadow.camera\n );\n } else {\n this._shadowCameraHelper = null;\n }\n\n this._light.shadow.camera.updateProjectionMatrix();\n }\n\n private _updateShadowCamera(): void {\n if (!this._shadowCameraDirty) {\n return;\n }\n this._shadowCameraDirty = false;\n\n this._light.shadow.camera.near = 1;\n this._light.shadow.camera.far = this._distanceFromCamera + 10000;\n this._light.shadow.camera.right = this._frustumSize / 2;\n this._light.shadow.camera.left = -this._frustumSize / 2;\n this._light.shadow.camera.top = this._frustumSize / 2;\n this._light.shadow.camera.bottom = -this._frustumSize / 2;\n }\n\n private _updateShadowMapSize(): void {\n if (!this._shadowMapDirty) {\n return;\n }\n this._shadowMapDirty = false;\n\n this._light.shadow.mapSize.set(\n this._shadowMapSize,\n this._shadowMapSize\n );\n\n // Force the recreation of the shadow map texture:\n this._light.shadow.map?.dispose();\n this._light.shadow.map = null;\n this._light.shadow.needsUpdate = true;\n }\n\n isEnabled(target: EffectsTarget): boolean {\n return this._isEnabled;\n }\n setEnabled(target: EffectsTarget, enabled: boolean): boolean {\n if (this._isEnabled === enabled) {\n return true;\n }\n if (enabled) {\n return this.applyEffect(target);\n } else {\n return this.removeEffect(target);\n }\n }\n applyEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.add(this._light);\n scene.add(this._light.target);\n if (this._shadowCameraHelper) {\n scene.add(this._shadowCameraHelper);\n }\n\n this._isEnabled = true;\n return true;\n }\n removeEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.remove(this._light);\n scene.remove(this._light.target);\n if (this._shadowCameraHelper) {\n scene.remove(this._shadowCameraHelper);\n }\n this._isEnabled = false;\n return true;\n }\n updatePreRender(target: gdjs.EffectsTarget): any {\n // Apply any update to the camera or shadow map size.\n this._updateShadowCamera();\n this._updateShadowMapSize();\n\n // Avoid shadow acne due to depth buffer precision.\n const biasMultiplier =\n this._shadowMapSize < 1024\n ? 2\n : this._shadowMapSize < 2048\n ? 1.25\n : 1;\n this._light.shadow.bias = -this._minimumShadowBias * biasMultiplier;\n\n // Apply update to the light position and its target.\n // By doing this, the shadows are \"following\" the GDevelop camera.\n if (!target.getRuntimeLayer) {\n return;\n }\n const layer = target.getRuntimeLayer();\n const x = layer.getCameraX();\n const y = layer.getCameraY();\n const z = layer.getCameraZ(layer.getInitialCamera3DFieldOfView());\n\n const roundedX = Math.floor(x / 100) * 100;\n const roundedY = Math.floor(y / 100) * 100;\n const roundedZ = Math.floor(z / 100) * 100;\n if (this._top === 'Y-') {\n const posLightX =\n roundedX +\n this._distanceFromCamera *\n Math.cos(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightY =\n roundedY -\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._elevation));\n const posLightZ =\n roundedZ +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation));\n this._light.position.set(posLightX, posLightY, posLightZ);\n this._light.target.position.set(roundedX, roundedY, roundedZ);\n } else {\n const posLightX =\n roundedX +\n this._distanceFromCamera *\n Math.cos(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightY =\n roundedY +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightZ =\n roundedZ +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._elevation));\n\n this._light.position.set(posLightX, posLightY, posLightZ);\n this._light.target.position.set(roundedX, roundedY, roundedZ);\n }\n }\n updateDoubleParameter(parameterName: string, value: number): void {\n if (parameterName === 'intensity') {\n this._light.intensity = value;\n } else if (parameterName === 'elevation') {\n this._elevation = value;\n } else if (parameterName === 'rotation') {\n this._rotation = value;\n } else if (parameterName === 'distanceFromCamera') {\n this._distanceFromCamera = value;\n } else if (parameterName === 'frustumSize') {\n this._frustumSize = value;\n } else if (parameterName === 'minimumShadowBias') {\n this._minimumShadowBias = value;\n }\n }\n getDoubleParameter(parameterName: string): number {\n if (parameterName === 'intensity') {\n return this._light.intensity;\n } else if (parameterName === 'elevation') {\n return this._elevation;\n } else if (parameterName === 'rotation') {\n return this._rotation;\n } else if (parameterName === 'distanceFromCamera') {\n return this._distanceFromCamera;\n } else if (parameterName === 'frustumSize') {\n return this._frustumSize;\n } else if (parameterName === 'minimumShadowBias') {\n return this._minimumShadowBias;\n }\n return 0;\n }\n updateStringParameter(parameterName: string, value: string): void {\n if (parameterName === 'color') {\n this._light.color = new THREE.Color(\n gdjs.rgbOrHexStringToNumber(value)\n );\n }\n if (parameterName === 'top') {\n this._top = value;\n }\n if (parameterName === 'shadowQuality') {\n if (value === 'low' && this._shadowMapSize !== 512) {\n this._shadowMapSize = 512;\n this._shadowMapDirty = true;\n }\n if (value === 'medium' && this._shadowMapSize !== 1024) {\n this._shadowMapSize = 1024;\n this._shadowMapDirty = true;\n }\n if (value === 'high' && this._shadowMapSize !== 2048) {\n this._shadowMapSize = 2048;\n this._shadowMapDirty = true;\n }\n }\n }\n updateColorParameter(parameterName: string, value: number): void {\n if (parameterName === 'color') {\n this._light.color.setHex(value);\n }\n }\n getColorParameter(parameterName: string): number {\n if (parameterName === 'color') {\n return this._light.color.getHex();\n }\n return 0;\n }\n updateBooleanParameter(parameterName: string, value: boolean): void {\n if (parameterName === 'isCastingShadow') {\n this._light.castShadow = value;\n }\n }\n getNetworkSyncData(): DirectionalLightFilterNetworkSyncData {\n return {\n i: this._light.intensity,\n c: this._light.color.getHex(),\n e: this._elevation,\n r: this._rotation,\n t: this._top,\n };\n }\n updateFromNetworkSyncData(syncData: any): void {\n this._light.intensity = syncData.i;\n this._light.color.setHex(syncData.c);\n this._elevation = syncData.e;\n this._rotation = syncData.r;\n this._top = syncData.t;\n }\n })();\n }\n })()\n );\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAQE,KAAM,GAAe,GACrB,EAAK,iBAAiB,sBACpB,4BACA,GAAK,MAAqD,CACxD,WACE,EACA,EAC8B,CAC9B,MAAI,OAAO,QAAU,YACZ,GAAI,GAAK,iBAAiB,YAE5B,GAAK,MAA8C,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n interface DirectionalLightFilterNetworkSyncData {\n i: number;\n c: number;\n e: number;\n r: number;\n t: string;\n }\n const shadowHelper = false;\n gdjs.PixiFiltersTools.registerFilterCreator(\n 'Scene3D::DirectionalLight',\n new (class implements gdjs.PixiFiltersTools.FilterCreator {\n makeFilter(\n target: EffectsTarget,\n effectData: EffectData\n ): gdjs.PixiFiltersTools.Filter {\n if (typeof THREE === 'undefined') {\n return new gdjs.PixiFiltersTools.EmptyFilter();\n }\n return new (class implements gdjs.PixiFiltersTools.Filter {\n private _top: string = 'Z+';\n private _elevation: float = 45;\n private _rotation: float = 0;\n private _shadowMapSize: float = 1024;\n private _minimumShadowBias: float = 0;\n private _distanceFromCamera: float = 1500;\n private _frustumSize: float = 4000;\n\n private _isEnabled: boolean = false;\n private _light: THREE.DirectionalLight;\n private _shadowMapDirty = true;\n private _shadowCameraDirty = true;\n private _shadowCameraHelper: THREE.CameraHelper | null;\n\n constructor() {\n this._light = new THREE.DirectionalLight();\n\n if (shadowHelper) {\n this._shadowCameraHelper = new THREE.CameraHelper(\n this._light.shadow.camera\n );\n } else {\n this._shadowCameraHelper = null;\n }\n\n this._light.shadow.camera.updateProjectionMatrix();\n }\n\n private _updateShadowCamera(): void {\n if (!this._shadowCameraDirty) {\n return;\n }\n this._shadowCameraDirty = false;\n\n this._light.shadow.camera.near = 1;\n this._light.shadow.camera.far = this._distanceFromCamera + 10000;\n this._light.shadow.camera.right = this._frustumSize / 2;\n this._light.shadow.camera.left = -this._frustumSize / 2;\n this._light.shadow.camera.top = this._frustumSize / 2;\n this._light.shadow.camera.bottom = -this._frustumSize / 2;\n }\n\n private _updateShadowMapSize(): void {\n if (!this._shadowMapDirty) {\n return;\n }\n this._shadowMapDirty = false;\n\n this._light.shadow.mapSize.set(\n this._shadowMapSize,\n this._shadowMapSize\n );\n\n // Force the recreation of the shadow map texture:\n this._light.shadow.map?.dispose();\n this._light.shadow.map = null;\n this._light.shadow.needsUpdate = true;\n }\n\n isEnabled(target: EffectsTarget): boolean {\n return this._isEnabled;\n }\n setEnabled(target: EffectsTarget, enabled: boolean): boolean {\n if (this._isEnabled === enabled) {\n return true;\n }\n if (enabled) {\n return this.applyEffect(target);\n } else {\n return this.removeEffect(target);\n }\n }\n applyEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.add(this._light);\n scene.add(this._light.target);\n if (this._shadowCameraHelper) {\n scene.add(this._shadowCameraHelper);\n }\n\n this._isEnabled = true;\n return true;\n }\n removeEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.remove(this._light);\n scene.remove(this._light.target);\n if (this._shadowCameraHelper) {\n scene.remove(this._shadowCameraHelper);\n }\n this._isEnabled = false;\n return true;\n }\n updatePreRender(target: gdjs.EffectsTarget): any {\n // Apply any update to the camera or shadow map size.\n this._updateShadowCamera();\n this._updateShadowMapSize();\n\n // Avoid shadow acne due to depth buffer precision.\n const biasMultiplier =\n this._shadowMapSize < 1024\n ? 2\n : this._shadowMapSize < 2048\n ? 1.25\n : 1;\n this._light.shadow.bias = -this._minimumShadowBias * biasMultiplier;\n\n // Apply update to the light position and its target.\n // By doing this, the shadows are \"following\" the GDevelop camera.\n if (!target.getRuntimeLayer) {\n return;\n }\n const layer = target.getRuntimeLayer();\n const x = layer.getCameraX();\n const y = layer.getCameraY();\n const z = layer.getCameraZ(layer.getInitialCamera3DFieldOfView());\n\n const roundedX = Math.floor(x / 100) * 100;\n const roundedY = Math.floor(y / 100) * 100;\n const roundedZ = Math.floor(z / 100) * 100;\n if (this._top === 'Y-') {\n const posLightX =\n roundedX +\n this._distanceFromCamera *\n Math.cos(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightY =\n roundedY -\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._elevation));\n const posLightZ =\n roundedZ +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation));\n this._light.position.set(posLightX, posLightY, posLightZ);\n this._light.target.position.set(roundedX, roundedY, roundedZ);\n } else {\n const posLightX =\n roundedX +\n this._distanceFromCamera *\n Math.cos(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightY =\n roundedY +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation));\n const posLightZ =\n roundedZ +\n this._distanceFromCamera *\n Math.sin(gdjs.toRad(this._elevation));\n\n this._light.position.set(posLightX, posLightY, posLightZ);\n this._light.target.position.set(roundedX, roundedY, roundedZ);\n }\n }\n updateDoubleParameter(parameterName: string, value: number): void {\n if (parameterName === 'intensity') {\n this._light.intensity = value;\n } else if (parameterName === 'elevation') {\n this._elevation = value;\n } else if (parameterName === 'rotation') {\n this._rotation = value;\n } else if (parameterName === 'distanceFromCamera') {\n this._distanceFromCamera = value;\n } else if (parameterName === 'frustumSize') {\n this._frustumSize = value;\n } else if (parameterName === 'minimumShadowBias') {\n this._minimumShadowBias = value;\n }\n }\n getDoubleParameter(parameterName: string): number {\n if (parameterName === 'intensity') {\n return this._light.intensity;\n } else if (parameterName === 'elevation') {\n return this._elevation;\n } else if (parameterName === 'rotation') {\n return this._rotation;\n } else if (parameterName === 'distanceFromCamera') {\n return this._distanceFromCamera;\n } else if (parameterName === 'frustumSize') {\n return this._frustumSize;\n } else if (parameterName === 'minimumShadowBias') {\n return this._minimumShadowBias;\n }\n return 0;\n }\n updateStringParameter(parameterName: string, value: string): void {\n if (parameterName === 'color') {\n this._light.color = new THREE.Color(\n gdjs.rgbOrHexStringToNumber(value)\n );\n }\n if (parameterName === 'top') {\n this._top = value;\n }\n if (parameterName === 'shadowQuality') {\n if (value === 'low' && this._shadowMapSize !== 512) {\n this._shadowMapSize = 512;\n this._shadowMapDirty = true;\n }\n if (value === 'medium' && this._shadowMapSize !== 1024) {\n this._shadowMapSize = 1024;\n this._shadowMapDirty = true;\n }\n if (value === 'high' && this._shadowMapSize !== 2048) {\n this._shadowMapSize = 2048;\n this._shadowMapDirty = true;\n }\n }\n }\n updateColorParameter(parameterName: string, value: number): void {\n if (parameterName === 'color') {\n this._light.color.setHex(value);\n }\n }\n getColorParameter(parameterName: string): number {\n if (parameterName === 'color') {\n return this._light.color.getHex();\n }\n return 0;\n }\n updateBooleanParameter(parameterName: string, value: boolean): void {\n if (parameterName === 'isCastingShadow') {\n this._light.castShadow = value;\n }\n }\n getNetworkSyncData(): DirectionalLightFilterNetworkSyncData {\n return {\n i: this._light.intensity,\n c: this._light.color.getHex(),\n e: this._elevation,\n r: this._rotation,\n t: this._top,\n };\n }\n updateFromNetworkSyncData(syncData: any): void {\n this._light.intensity = syncData.i;\n this._light.color.setHex(syncData.c);\n this._elevation = syncData.e;\n this._rotation = syncData.r;\n this._top = syncData.t;\n }\n })();\n }\n })()\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAQE,KAAM,GAAe,GACrB,EAAK,iBAAiB,sBACpB,4BACA,GAAK,MAAqD,CACxD,WACE,EACA,EAC8B,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AAO,UACf,EAAG,KAAK,OAAO,MAAM,SACrB,EAAG,KAAK,WACR,EAAG,KAAK,UACR,EAAG,KAAK,MAGZ,0BAA0B,EAAqB,CAC7C,KAAK,OAAO,UAAY,EAAS,EACjC,KAAK,OAAO,MAAM,OAAO,EAAS,GAClC,KAAK,WAAa,EAAS,EAC3B,KAAK,UAAY,EAAS,EAC1B,KAAK,KAAO,EAAS,SAlRvB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(i){i.PixiFiltersTools.registerFilterCreator("Scene3D::HemisphereLight",new class{makeFilter(o,r){return typeof THREE=="undefined"?new i.PixiFiltersTools.EmptyFilter:new class{constructor(){this.
|
|
1
|
+
var gdjs;(function(i){i.PixiFiltersTools.registerFilterCreator("Scene3D::HemisphereLight",new class{makeFilter(o,r){return typeof THREE=="undefined"?new i.PixiFiltersTools.EmptyFilter:new class{constructor(){this._top="Z+";this._elevation=90;this._rotation=0;this._isEnabled=!1;this._light=new THREE.HemisphereLight,this.updateRotation()}isEnabled(t){return this._isEnabled}setEnabled(t,e){return this._isEnabled===e?!0:e?this.applyEffect(t):this.removeEffect(t)}applyEffect(t){const e=t.get3DRendererObject();return e?(e.add(this._light),this._isEnabled=!0,!0):!1}removeEffect(t){const e=t.get3DRendererObject();return e?(e.remove(this._light),this._isEnabled=!1,!0):!1}updatePreRender(t){}updateDoubleParameter(t,e){t==="intensity"?this._light.intensity=e:t==="elevation"?(this._elevation=e,this.updateRotation()):t==="rotation"&&(this._rotation=e,this.updateRotation())}getDoubleParameter(t){return t==="intensity"?this._light.intensity:t==="elevation"?this._elevation:t==="rotation"?this._rotation:0}updateStringParameter(t,e){t==="skyColor"&&(this._light.color=new THREE.Color(i.rgbOrHexStringToNumber(e))),t==="groundColor"&&(this._light.groundColor=new THREE.Color(i.rgbOrHexStringToNumber(e))),t==="top"&&(this._top=e,this.updateRotation())}updateColorParameter(t,e){t==="skyColor"&&this._light.color.setHex(e),t==="groundColor"&&this._light.groundColor.setHex(e)}getColorParameter(t){return t==="skyColor"?this._light.color.getHex():t==="groundColor"?this._light.groundColor.getHex():0}updateBooleanParameter(t,e){}updateRotation(){this._top==="Y-"?this._light.position.set(Math.cos(i.toRad(-this._rotation+90))*Math.cos(i.toRad(this._elevation)),-Math.sin(i.toRad(this._elevation)),Math.sin(i.toRad(-this._rotation+90))*Math.cos(i.toRad(this._elevation))):this._light.position.set(Math.cos(i.toRad(this._rotation))*Math.cos(i.toRad(this._elevation)),Math.sin(i.toRad(this._rotation))*Math.cos(i.toRad(this._elevation)),Math.sin(i.toRad(this._elevation)))}getNetworkSyncData(){return{i:this._light.intensity,sc:this._light.color.getHex(),gc:this._light.groundColor.getHex(),e:this._elevation,r:this._rotation,t:this._top}}updateFromNetworkSyncData(t){this._light.intensity=t.i,this._light.color.setHex(t.sc),this._light.groundColor.setHex(t.gc),this._elevation=t.e,this._rotation=t.r,this._top=t.t,this.updateRotation()}}}})})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=HemisphereLight.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/3D/HemisphereLight.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n interface HemisphereLightFilterNetworkSyncData {\n i: number;\n sc: number;\n gc: number;\n e: number;\n r: number;\n t: string;\n }\n gdjs.PixiFiltersTools.registerFilterCreator(\n 'Scene3D::HemisphereLight',\n new (class implements gdjs.PixiFiltersTools.FilterCreator {\n makeFilter(\n target: EffectsTarget,\n effectData: EffectData\n ): gdjs.PixiFiltersTools.Filter {\n if (typeof THREE === 'undefined') {\n return new gdjs.PixiFiltersTools.EmptyFilter();\n }\n return new (class implements gdjs.PixiFiltersTools.Filter {\n
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CASE,EAAK,iBAAiB,sBACpB,2BACA,GAAK,MAAqD,CACxD,WACE,EACA,EAC8B,CAC9B,MAAI,OAAO,QAAU,YACZ,GAAI,GAAK,iBAAiB,YAE5B,GAAK,MAA8C,CAQxD,aAAc,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n interface HemisphereLightFilterNetworkSyncData {\n i: number;\n sc: number;\n gc: number;\n e: number;\n r: number;\n t: string;\n }\n gdjs.PixiFiltersTools.registerFilterCreator(\n 'Scene3D::HemisphereLight',\n new (class implements gdjs.PixiFiltersTools.FilterCreator {\n makeFilter(\n target: EffectsTarget,\n effectData: EffectData\n ): gdjs.PixiFiltersTools.Filter {\n if (typeof THREE === 'undefined') {\n return new gdjs.PixiFiltersTools.EmptyFilter();\n }\n return new (class implements gdjs.PixiFiltersTools.Filter {\n _top: string = 'Z+';\n _elevation: float = 90;\n _rotation: float = 0;\n\n _isEnabled: boolean = false;\n _light: THREE.HemisphereLight;\n\n constructor() {\n this._light = new THREE.HemisphereLight();\n this.updateRotation();\n }\n\n isEnabled(target: EffectsTarget): boolean {\n return this._isEnabled;\n }\n setEnabled(target: EffectsTarget, enabled: boolean): boolean {\n if (this._isEnabled === enabled) {\n return true;\n }\n if (enabled) {\n return this.applyEffect(target);\n } else {\n return this.removeEffect(target);\n }\n }\n applyEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.add(this._light);\n this._isEnabled = true;\n return true;\n }\n removeEffect(target: EffectsTarget): boolean {\n const scene = target.get3DRendererObject() as\n | THREE.Scene\n | null\n | undefined;\n if (!scene) {\n return false;\n }\n scene.remove(this._light);\n this._isEnabled = false;\n return true;\n }\n updatePreRender(target: gdjs.EffectsTarget): any {}\n updateDoubleParameter(parameterName: string, value: number): void {\n if (parameterName === 'intensity') {\n this._light.intensity = value;\n } else if (parameterName === 'elevation') {\n this._elevation = value;\n this.updateRotation();\n } else if (parameterName === 'rotation') {\n this._rotation = value;\n this.updateRotation();\n }\n }\n getDoubleParameter(parameterName: string): number {\n if (parameterName === 'intensity') {\n return this._light.intensity;\n } else if (parameterName === 'elevation') {\n return this._elevation;\n } else if (parameterName === 'rotation') {\n return this._rotation;\n }\n return 0;\n }\n updateStringParameter(parameterName: string, value: string): void {\n if (parameterName === 'skyColor') {\n this._light.color = new THREE.Color(\n gdjs.rgbOrHexStringToNumber(value)\n );\n }\n if (parameterName === 'groundColor') {\n this._light.groundColor = new THREE.Color(\n gdjs.rgbOrHexStringToNumber(value)\n );\n }\n if (parameterName === 'top') {\n this._top = value;\n this.updateRotation();\n }\n }\n updateColorParameter(parameterName: string, value: number): void {\n if (parameterName === 'skyColor') {\n this._light.color.setHex(value);\n }\n if (parameterName === 'groundColor') {\n this._light.groundColor.setHex(value);\n }\n }\n getColorParameter(parameterName: string): number {\n if (parameterName === 'skyColor') {\n return this._light.color.getHex();\n }\n if (parameterName === 'groundColor') {\n return this._light.groundColor.getHex();\n }\n return 0;\n }\n updateBooleanParameter(parameterName: string, value: boolean): void {}\n updateRotation() {\n if (this._top === 'Y-') {\n // `rotation` at 0\u00B0 becomes a light from Z+.\n this._light.position.set(\n Math.cos(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation)),\n -Math.sin(gdjs.toRad(this._elevation)),\n Math.sin(gdjs.toRad(-this._rotation + 90)) *\n Math.cos(gdjs.toRad(this._elevation))\n );\n } else {\n // `rotation` at 0\u00B0 is a light from the right of the screen.\n this._light.position.set(\n Math.cos(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation)),\n Math.sin(gdjs.toRad(this._rotation)) *\n Math.cos(gdjs.toRad(this._elevation)),\n Math.sin(gdjs.toRad(this._elevation))\n );\n }\n }\n getNetworkSyncData(): HemisphereLightFilterNetworkSyncData {\n return {\n i: this._light.intensity,\n sc: this._light.color.getHex(),\n gc: this._light.groundColor.getHex(),\n e: this._elevation,\n r: this._rotation,\n t: this._top,\n };\n }\n updateFromNetworkSyncData(\n syncData: HemisphereLightFilterNetworkSyncData\n ): void {\n this._light.intensity = syncData.i;\n this._light.color.setHex(syncData.sc);\n this._light.groundColor.setHex(syncData.gc);\n this._elevation = syncData.e;\n this._rotation = syncData.r;\n this._top = syncData.t;\n this.updateRotation();\n }\n })();\n }\n })()\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CASE,EAAK,iBAAiB,sBACpB,2BACA,GAAK,MAAqD,CACxD,WACE,EACA,EAC8B,CAC9B,MAAI,OAAO,QAAU,YACZ,GAAI,GAAK,iBAAiB,YAE5B,GAAK,MAA8C,CAQxD,aAAc,CAPd,UAAe,KACf,gBAAoB,GACpB,eAAmB,EAEnB,gBAAsB,GAIpB,KAAK,OAAS,GAAI,OAAM,gBACxB,KAAK,iBAGP,UAAU,EAAgC,CACxC,MAAO,MAAK,WAEd,WAAW,EAAuB,EAA2B,CAC3D,MAAI,MAAK,aAAe,EACf,GAEL,EACK,KAAK,YAAY,GAEjB,KAAK,aAAa,GAG7B,YAAY,EAAgC,CAC1C,KAAM,GAAQ,EAAO,sBAIrB,MAAK,GAGL,GAAM,IAAI,KAAK,QACf,KAAK,WAAa,GACX,IAJE,GAMX,aAAa,EAAgC,CAC3C,KAAM,GAAQ,EAAO,sBAIrB,MAAK,GAGL,GAAM,OAAO,KAAK,QAClB,KAAK,WAAa,GACX,IAJE,GAMX,gBAAgB,EAAiC,EACjD,sBAAsB,EAAuB,EAAqB,CAChE,AAAI,IAAkB,YACpB,KAAK,OAAO,UAAY,EACnB,AAAI,IAAkB,YAC3B,MAAK,WAAa,EAClB,KAAK,kBACI,IAAkB,YAC3B,MAAK,UAAY,EACjB,KAAK,kBAGT,mBAAmB,EAA+B,CAChD,MAAI,KAAkB,YACb,KAAK,OAAO,UACV,IAAkB,YACpB,KAAK,WACH,IAAkB,WACpB,KAAK,UAEP,EAET,sBAAsB,EAAuB,EAAqB,CAChE,AAAI,IAAkB,YACpB,MAAK,OAAO,MAAQ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1B,KAAK,KAAO,EAAS,EACrB,KAAK,wBArKP",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1916,11 +1916,11 @@ module.exports = {
|
|
|
1916
1916
|
.setType('number');
|
|
1917
1917
|
properties
|
|
1918
1918
|
.getOrCreate('top')
|
|
1919
|
-
.setValue('
|
|
1919
|
+
.setValue('Z+')
|
|
1920
1920
|
.setLabel(_('3D world top'))
|
|
1921
1921
|
.setType('choice')
|
|
1922
|
-
.addExtraInfo('Y-')
|
|
1923
1922
|
.addExtraInfo('Z+')
|
|
1923
|
+
.addExtraInfo('Y-')
|
|
1924
1924
|
.setGroup(_('Orientation'));
|
|
1925
1925
|
properties
|
|
1926
1926
|
.getOrCreate('elevation')
|
|
@@ -1974,6 +1974,7 @@ module.exports = {
|
|
|
1974
1974
|
.setValue('1500')
|
|
1975
1975
|
.setLabel(_("Distance from layer's camera"))
|
|
1976
1976
|
.setType('number')
|
|
1977
|
+
.setGroup(_('Shadows'))
|
|
1977
1978
|
.setAdvanced(true);
|
|
1978
1979
|
}
|
|
1979
1980
|
{
|
|
@@ -2006,11 +2007,11 @@ module.exports = {
|
|
|
2006
2007
|
.setType('number');
|
|
2007
2008
|
properties
|
|
2008
2009
|
.getOrCreate('top')
|
|
2009
|
-
.setValue('
|
|
2010
|
+
.setValue('Z+')
|
|
2010
2011
|
.setLabel(_('3D world top'))
|
|
2011
2012
|
.setType('choice')
|
|
2012
|
-
.addExtraInfo('Y-')
|
|
2013
2013
|
.addExtraInfo('Z+')
|
|
2014
|
+
.addExtraInfo('Y-')
|
|
2014
2015
|
.setGroup(_('Orientation'));
|
|
2015
2016
|
properties
|
|
2016
2017
|
.getOrCreate('elevation')
|
|
@@ -31,6 +31,73 @@ module.exports = {
|
|
|
31
31
|
.addInstructionOrExpressionGroupMetadata(_('Multiplayer'))
|
|
32
32
|
.setIcon('JsPlatform/Extensions/multiplayer.svg');
|
|
33
33
|
|
|
34
|
+
extension
|
|
35
|
+
.addStrExpression(
|
|
36
|
+
'CurrentLobbyID',
|
|
37
|
+
_('Current lobby ID'),
|
|
38
|
+
_('Returns current lobby ID.'),
|
|
39
|
+
_('Lobbies'),
|
|
40
|
+
'JsPlatform/Extensions/multiplayer.svg'
|
|
41
|
+
)
|
|
42
|
+
.getCodeExtraInformation()
|
|
43
|
+
.setIncludeFile('Extensions/Multiplayer/peer.js')
|
|
44
|
+
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
|
|
45
|
+
.addIncludeFile(
|
|
46
|
+
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
|
|
47
|
+
)
|
|
48
|
+
.addIncludeFile(
|
|
49
|
+
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
|
|
50
|
+
)
|
|
51
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
|
|
52
|
+
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
|
|
53
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
|
|
54
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
|
|
55
|
+
.setFunctionName('gdjs.multiplayer.getLobbyID');
|
|
56
|
+
|
|
57
|
+
extension
|
|
58
|
+
.addAction(
|
|
59
|
+
'QuickJoinWithLobbyID',
|
|
60
|
+
_('Join a specific lobby by its ID'),
|
|
61
|
+
_(
|
|
62
|
+
'Join a specific lobby. The player will join the game instantly if this is possible.'
|
|
63
|
+
),
|
|
64
|
+
_('Join a specific lobby by its ID _PARAM1_'),
|
|
65
|
+
_('Lobbies'),
|
|
66
|
+
'JsPlatform/Extensions/multiplayer.svg',
|
|
67
|
+
'JsPlatform/Extensions/multiplayer.svg'
|
|
68
|
+
)
|
|
69
|
+
.addCodeOnlyParameter('currentScene', '')
|
|
70
|
+
.addParameter('string', _('Lobby ID'), '', false)
|
|
71
|
+
.addParameter(
|
|
72
|
+
'yesorno',
|
|
73
|
+
_('Display loader while joining a lobby.'),
|
|
74
|
+
'',
|
|
75
|
+
true
|
|
76
|
+
)
|
|
77
|
+
.setDefaultValue('yes')
|
|
78
|
+
.addParameter(
|
|
79
|
+
'yesorno',
|
|
80
|
+
_('Display game lobbies if unable to join a specific one.'),
|
|
81
|
+
'',
|
|
82
|
+
true
|
|
83
|
+
)
|
|
84
|
+
.setDefaultValue('yes')
|
|
85
|
+
.setHelpPath('/all-features/multiplayer')
|
|
86
|
+
.getCodeExtraInformation()
|
|
87
|
+
.setIncludeFile('Extensions/Multiplayer/peer.js')
|
|
88
|
+
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
|
|
89
|
+
.addIncludeFile(
|
|
90
|
+
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
|
|
91
|
+
)
|
|
92
|
+
.addIncludeFile(
|
|
93
|
+
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
|
|
94
|
+
)
|
|
95
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
|
|
96
|
+
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
|
|
97
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
|
|
98
|
+
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
|
|
99
|
+
.setFunctionName('gdjs.multiplayer.authenticateAndQuickJoinWithLobbyID');
|
|
100
|
+
|
|
34
101
|
extension
|
|
35
102
|
.addAction(
|
|
36
103
|
'QuickJoinLobby',
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(a){const d=new a.Logger("Multiplayer"),m=new a.Logger("Multiplayer - Debug"),f=window.performance&&typeof window.performance.now=="function"?window.performance.now.bind(window.performance):Date.now;class g extends a.RuntimeBehavior{constructor(t,n,e){super(t,n,e);this.playerNumber=0;this._lastObjectSyncTimestamp=0;this._lastBasicObjectSyncTimestamp=0;this._objectBasicInfoSyncRate=5;this._numberOfForcedBasicObjectUpdates=0;this._lastVariablesSyncTimestamp=0;this._variablesSyncRate=1;this._numberOfForcedVariablesUpdates=0;this._lastEffectsSyncTimestamp=0;this._effectsSyncRate=1;this._numberOfForcedEffectsUpdates=0;this._lastLogTimestamp=0;this._logSyncRate=1;this._clock=0;this._destroyInstanceTimeoutId=null;this._timeBeforeDestroyingObjectWithoutNetworkIdInMs=500;this._sendDataToPeersWithIncreasedClock=async(t,n)=>{this._clock++,n._clock=this._clock;const e=a.multiplayerPeerJsHelper.getAllPeers();await a.multiplayerMessageManager.sendDataTo(e,t,n)};this.playerNumber=n.playerNumber==="Host"?0:parseInt(n.playerNumber,10),this.actionOnPlayerDisconnect=n.actionOnPlayerDisconnect,this._destroyInstanceTimeoutId=setTimeout(()=>{const r=this.owner.getRuntimeScene().networkId;!e.networkId&&a.multiplayer.isLobbyGameRunning()&&r&&(m.info(`Lobby game is running on a synced scene and object ${e.getName()} has not been assigned a networkId after a short delay, destroying it.`),e.deleteFromScene())},this._timeBeforeDestroyingObjectWithoutNetworkIdInMs)}_isOwnerAsPlayerOrHost(){const t=a.multiplayer.getCurrentPlayerNumber(),n=a.multiplayer.isCurrentPlayerHost();return t===this.playerNumber||n&&this.playerNumber===0}_hasObjectBeenSyncedWithinMaxRate(){const t=a.multiplayer.getObjectsSynchronizationRate();return f()-this._lastObjectSyncTimestamp<1e3/t}_hasObjectBasicInfoBeenSyncedRecently(){return f()-this._lastBasicObjectSyncTimestamp<1e3/this._objectBasicInfoSyncRate}_haveVariablesBeenSyncedRecently(){return f()-this._lastVariablesSyncTimestamp<1e3/this._variablesSyncRate}_haveEffectsBeenSyncedRecently(){return f()-this._lastEffectsSyncTimestamp<1e3/this._effectsSyncRate}_getOrCreateInstanceNetworkId(){if(!this.owner.networkId){const t=a.makeUuid().substring(0,8);this.owner.networkId=t}return this.owner.networkId}_isBasicObjectNetworkSyncDataDifferentFromLastSync(t){return this._lastSentBasicObjectSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentBasicObjectSyncData):!0}_areVariablesDifferentFromLastSync(t){return this._lastSentVariableSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentVariableSyncData):!0}_areEffectsDifferentFromLastSync(t){if(!this._lastSentEffectSyncData)return!0;for(const n in t){if(!t.hasOwnProperty(n))continue;const e=t[n],r=e.ena,i=e.fc,c=this._lastSentEffectSyncData[n];if(!c||c.ena!==r)return!0;for(const s in i){if(!i.hasOwnProperty(s))continue;const o=i[s];if(c.fc[s]!==o)return!0}}return!1}doStepPostEvents(){if(!a.multiplayer.isLobbyGameRunning())return;if(this.actionOnPlayerDisconnect!=="DoNothing"&&this.playerNumber!==0&&!a.multiplayerMessageManager.isPlayerConnected(this.playerNumber)){m.info(`Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`),this.owner.deleteFromScene();return}if(!this._isOwnerAsPlayerOrHost()||this._hasObjectBeenSyncedWithinMaxRate())return;const t=this._getOrCreateInstanceNetworkId(),n=this.owner.getName(),e=this.owner.getNetworkSyncData(),r=this._isBasicObjectNetworkSyncDataDifferentFromLastSync({x:e.x,y:e.y,z:e.z,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy}),i=!this._hasObjectBasicInfoBeenSyncedRecently()||r||this._numberOfForcedBasicObjectUpdates>0;if(r&&(this._numberOfForcedBasicObjectUpdates=3),!i)return;const c=e.var&&this._areVariablesDifferentFromLastSync(e.var),s=!this._haveVariablesBeenSyncedRecently()||c||this._numberOfForcedVariablesUpdates>0;c&&(this._numberOfForcedVariablesUpdates=3),s||delete e.var;const o=e.eff&&this._areEffectsDifferentFromLastSync(e.eff),l=!this._haveEffectsBeenSyncedRecently()||o||this._numberOfForcedEffectsUpdates>0;o&&(this._numberOfForcedEffectsUpdates=3),l||delete e.eff;const y=this.owner.getRuntimeScene().networkId;if(!y)return;const{messageName:h,messageData:b}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:e,sceneNetworkId:y});this._sendDataToPeersWithIncreasedClock(h,b);const u=f();this._lastObjectSyncTimestamp=u,i&&(this._lastBasicObjectSyncTimestamp=u,this._lastSentBasicObjectSyncData={x:e.x,y:e.y,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy},this._numberOfForcedBasicObjectUpdates=Math.max(this._numberOfForcedBasicObjectUpdates-1,0)),s&&(this._lastVariablesSyncTimestamp=u,this._lastSentVariableSyncData=e.var,this._numberOfForcedVariablesUpdates=Math.max(this._numberOfForcedVariablesUpdates-1,0)),l&&(this._lastEffectsSyncTimestamp=u,this._lastSentEffectSyncData=e.eff,this._numberOfForcedEffectsUpdates=Math.max(this._numberOfForcedEffectsUpdates-1,0))}onDestroy(){if(this._destroyInstanceTimeoutId&&(clearTimeout(this._destroyInstanceTimeoutId),this._destroyInstanceTimeoutId=null),!a.multiplayer.isLobbyGameRunning()||!this._isOwnerAsPlayerOrHost()&&!a.multiplayer.isCurrentPlayerHost())return;const t=this.owner.networkId,n=this.owner.getName();if(!t){m.info(`Destroying object ${n} without networkId, no need to send a message.`);return}const e=this.owner.getRuntimeScene().networkId;if(!e)return;const{messageName:r,messageData:i}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:this.owner.getNetworkSyncData(),sceneNetworkId:e});this._sendDataToPeersWithIncreasedClock(r,i);const c=a.multiplayerPeerJsHelper.getAllPeers(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createDestroyInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,sceneNetworkId:e}),l=a.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:l,otherPeerIds:c,shouldCancelMessageIfTimesOut:!1}),this._sendDataToPeersWithIncreasedClock(s,o)}setPlayerObjectOwnership(t){if(m.info(`Setting ownership of object ${this.owner.getName()} (networkId: ${this.owner.networkId} to player ${t}.`),t<0){d.error("Invalid player number ("+t+") when setting ownership of an object.");return}const n=this.playerNumber;this.playerNumber=t;const e=a.multiplayer.getCurrentPlayerNumber();if(!a.multiplayer.isLobbyGameRunning())return;let r=this.owner.networkId;if(!r){if(m.info("Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner."),t!==e)return;m.info("We are the new owner, creating a networkId for the object."),r=this._getOrCreateInstanceNetworkId()}const i=this.owner.getRuntimeScene().networkId;if(!i)return;const c=this.owner.getName(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createChangeInstanceOwnerMessage({objectOwner:n,objectName:c,instanceNetworkId:r,newObjectOwner:t,instanceX:this.owner.getX(),instanceY:this.owner.getY(),sceneNetworkId:i});if(t===e){const l=a.multiplayerPeerJsHelper.getAllPeers(),y=a.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:y,otherPeerIds:l,shouldCancelMessageIfTimesOut:!a.multiplayer.isCurrentPlayerHost()})}if(m.info("Sending change owner message",s),this._sendDataToPeersWithIncreasedClock(s,o),t===e){m.info("Sending update message to move the object immediately.");const l=this.owner.getNetworkSyncData(),{messageName:y,messageData:h}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:c,instanceNetworkId:r,objectNetworkSyncData:l,sceneNetworkId:i});this._sendDataToPeersWithIncreasedClock(y,h)}}getPlayerObjectOwnership(){return this.playerNumber}isObjectOwnedByCurrentPlayer(){return this._isOwnerAsPlayerOrHost()}removeObjectOwnership(){this.setPlayerObjectOwnership(0)}takeObjectOwnership(){this.setPlayerObjectOwnership(a.multiplayer.getCurrentPlayerNumber())}getActionOnPlayerDisconnect(){return this.actionOnPlayerDisconnect}enableBehaviorSynchronization(t,n){const e=this.owner.getBehavior(t);if(!e){d.error(`Behavior ${t} does not exist on object ${this.owner.getName()}.`);return}e.enableSynchronization(n)}}a.MultiplayerObjectRuntimeBehavior=g,a.registerBehavior("Multiplayer::MultiplayerObjectBehavior",a.MultiplayerObjectRuntimeBehavior)})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(a){const d=new a.Logger("Multiplayer"),m=new a.Logger("Multiplayer - Debug"),f=window.performance&&typeof window.performance.now=="function"?window.performance.now.bind(window.performance):Date.now;class g extends a.RuntimeBehavior{constructor(t,n,e){super(t,n,e);this.playerNumber=0;this._lastObjectSyncTimestamp=0;this._lastBasicObjectSyncTimestamp=0;this._objectBasicInfoSyncRate=5;this._numberOfForcedBasicObjectUpdates=0;this._lastVariablesSyncTimestamp=0;this._variablesSyncRate=1;this._numberOfForcedVariablesUpdates=0;this._lastEffectsSyncTimestamp=0;this._effectsSyncRate=1;this._numberOfForcedEffectsUpdates=0;this._lastLogTimestamp=0;this._logSyncRate=1;this._clock=0;this._destroyInstanceTimeoutId=null;this._timeBeforeDestroyingObjectWithoutNetworkIdInMs=500;this._sendDataToPeersWithIncreasedClock=async(t,n)=>{this._clock++,n._clock=this._clock;const e=a.multiplayerPeerJsHelper.getAllPeers();await a.multiplayerMessageManager.sendDataTo(e,t,n)};this.playerNumber=n.playerNumber==="Host"?0:parseInt(n.playerNumber,10),this.actionOnPlayerDisconnect=n.actionOnPlayerDisconnect,this._destroyInstanceTimeoutId=setTimeout(()=>{const r=this.owner.getRuntimeScene().networkId;!e.networkId&&a.multiplayer.isLobbyGameRunning()&&r&&(m.info(`Lobby game is running on a synced scene and object ${e.getName()} has not been assigned a networkId after a short delay, destroying it.`),e.deleteFromScene())},this._timeBeforeDestroyingObjectWithoutNetworkIdInMs)}_isOwnerAsPlayerOrHost(){const t=a.multiplayer.getCurrentPlayerNumber(),n=a.multiplayer.isCurrentPlayerHost();return t===this.playerNumber||n&&this.playerNumber===0}_hasObjectBeenSyncedWithinMaxRate(){const t=a.multiplayer.getObjectsSynchronizationRate();return f()-this._lastObjectSyncTimestamp<1e3/t}_hasObjectBasicInfoBeenSyncedRecently(){return f()-this._lastBasicObjectSyncTimestamp<1e3/this._objectBasicInfoSyncRate}_haveVariablesBeenSyncedRecently(){return f()-this._lastVariablesSyncTimestamp<1e3/this._variablesSyncRate}_haveEffectsBeenSyncedRecently(){return f()-this._lastEffectsSyncTimestamp<1e3/this._effectsSyncRate}_getOrCreateInstanceNetworkId(){if(!this.owner.networkId){const t=a.makeUuid().substring(0,8);this.owner.networkId=t}return this.owner.networkId}_isBasicObjectNetworkSyncDataDifferentFromLastSync(t){return this._lastSentBasicObjectSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentBasicObjectSyncData):!0}_areVariablesDifferentFromLastSync(t){return this._lastSentVariableSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentVariableSyncData):!0}_areEffectsDifferentFromLastSync(t){if(!this._lastSentEffectSyncData)return!0;for(const n in t){if(!t.hasOwnProperty(n))continue;const e=t[n],r=e.ena,i=e.fc,c=this._lastSentEffectSyncData[n];if(!c||c.ena!==r)return!0;for(const s in i){if(!i.hasOwnProperty(s))continue;const o=i[s];if(c.fc[s]!==o)return!0}}return!1}doStepPostEvents(){if(!a.multiplayer.isLobbyGameRunning())return;if(this.actionOnPlayerDisconnect!=="DoNothing"&&this.playerNumber!==0&&!a.multiplayerMessageManager.isPlayerConnected(this.playerNumber)){m.info(`Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`),this.owner.deleteFromScene();return}if(!this._isOwnerAsPlayerOrHost()||this._hasObjectBeenSyncedWithinMaxRate())return;const t=this._getOrCreateInstanceNetworkId(),n=this.owner.getName(),e=this.owner.getNetworkSyncData(),r=this._isBasicObjectNetworkSyncDataDifferentFromLastSync({x:e.x,y:e.y,z:e.z,w:e.w,h:e.h,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy}),i=!this._hasObjectBasicInfoBeenSyncedRecently()||r||this._numberOfForcedBasicObjectUpdates>0;if(r&&(this._numberOfForcedBasicObjectUpdates=3),!i)return;const c=e.var&&this._areVariablesDifferentFromLastSync(e.var),s=!this._haveVariablesBeenSyncedRecently()||c||this._numberOfForcedVariablesUpdates>0;c&&(this._numberOfForcedVariablesUpdates=3),s||delete e.var;const o=e.eff&&this._areEffectsDifferentFromLastSync(e.eff),l=!this._haveEffectsBeenSyncedRecently()||o||this._numberOfForcedEffectsUpdates>0;o&&(this._numberOfForcedEffectsUpdates=3),l||delete e.eff;const y=this.owner.getRuntimeScene().networkId;if(!y)return;const{messageName:h,messageData:b}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:e,sceneNetworkId:y});this._sendDataToPeersWithIncreasedClock(h,b);const u=f();this._lastObjectSyncTimestamp=u,i&&(this._lastBasicObjectSyncTimestamp=u,this._lastSentBasicObjectSyncData={x:e.x,y:e.y,z:e.z,w:e.w,h:e.h,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy},this._numberOfForcedBasicObjectUpdates=Math.max(this._numberOfForcedBasicObjectUpdates-1,0)),s&&(this._lastVariablesSyncTimestamp=u,this._lastSentVariableSyncData=e.var,this._numberOfForcedVariablesUpdates=Math.max(this._numberOfForcedVariablesUpdates-1,0)),l&&(this._lastEffectsSyncTimestamp=u,this._lastSentEffectSyncData=e.eff,this._numberOfForcedEffectsUpdates=Math.max(this._numberOfForcedEffectsUpdates-1,0))}onDestroy(){if(this._destroyInstanceTimeoutId&&(clearTimeout(this._destroyInstanceTimeoutId),this._destroyInstanceTimeoutId=null),!a.multiplayer.isLobbyGameRunning()||!this._isOwnerAsPlayerOrHost()&&!a.multiplayer.isCurrentPlayerHost())return;const t=this.owner.networkId,n=this.owner.getName();if(!t){m.info(`Destroying object ${n} without networkId, no need to send a message.`);return}const e=this.owner.getRuntimeScene().networkId;if(!e)return;const{messageName:r,messageData:i}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:this.owner.getNetworkSyncData(),sceneNetworkId:e});this._sendDataToPeersWithIncreasedClock(r,i);const c=a.multiplayerPeerJsHelper.getAllPeers(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createDestroyInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,sceneNetworkId:e}),l=a.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:l,otherPeerIds:c,shouldCancelMessageIfTimesOut:!1}),this._sendDataToPeersWithIncreasedClock(s,o)}setPlayerObjectOwnership(t){if(m.info(`Setting ownership of object ${this.owner.getName()} (networkId: ${this.owner.networkId} to player ${t}.`),t<0){d.error("Invalid player number ("+t+") when setting ownership of an object.");return}const n=this.playerNumber;this.playerNumber=t;const e=a.multiplayer.getCurrentPlayerNumber();if(!a.multiplayer.isLobbyGameRunning())return;let r=this.owner.networkId;if(!r){if(m.info("Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner."),t!==e)return;m.info("We are the new owner, creating a networkId for the object."),r=this._getOrCreateInstanceNetworkId()}const i=this.owner.getRuntimeScene().networkId;if(!i)return;const c=this.owner.getName(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createChangeInstanceOwnerMessage({objectOwner:n,objectName:c,instanceNetworkId:r,newObjectOwner:t,instanceX:this.owner.getX(),instanceY:this.owner.getY(),sceneNetworkId:i});if(t===e){const l=a.multiplayerPeerJsHelper.getAllPeers(),y=a.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:y,otherPeerIds:l,shouldCancelMessageIfTimesOut:!a.multiplayer.isCurrentPlayerHost()})}if(m.info("Sending change owner message",s),this._sendDataToPeersWithIncreasedClock(s,o),t===e){m.info("Sending update message to move the object immediately.");const l=this.owner.getNetworkSyncData(),{messageName:y,messageData:h}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:c,instanceNetworkId:r,objectNetworkSyncData:l,sceneNetworkId:i});this._sendDataToPeersWithIncreasedClock(y,h)}}getPlayerObjectOwnership(){return this.playerNumber}isObjectOwnedByCurrentPlayer(){return this._isOwnerAsPlayerOrHost()}removeObjectOwnership(){this.setPlayerObjectOwnership(0)}takeObjectOwnership(){this.setPlayerObjectOwnership(a.multiplayer.getCurrentPlayerNumber())}getActionOnPlayerDisconnect(){return this.actionOnPlayerDisconnect}enableBehaviorSynchronization(t,n){const e=this.owner.getBehavior(t);if(!e){d.error(`Behavior ${t} does not exist on object ${this.owner.getName()}.`);return}e.enableSynchronization(n)}}a.MultiplayerObjectRuntimeBehavior=g,a.registerBehavior("Multiplayer::MultiplayerObjectBehavior",a.MultiplayerObjectRuntimeBehavior)})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=multiplayerobjectruntimebehavior.js.map
|