gdcore-tools 2.0.0-gd-v5.5.232-autobuild → 2.0.0-gd-v5.5.234-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/Extensions/3D/Cube3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObject.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/DirectionalLight.js +1 -1
- package/dist/Runtime/Extensions/3D/DirectionalLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/JsExtension.js +60 -9
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js.map +2 -2
- package/dist/Runtime/Extensions/BBText/JsExtension.js +6 -6
- package/dist/Runtime/Extensions/BitmapText/JsExtension.js +6 -6
- package/dist/Runtime/Extensions/Physics2Behavior/JsExtension.js +10 -10
- package/dist/Runtime/Extensions/Physics3DBehavior/JsExtension.js +20 -7
- 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/PlatformBehavior/platformerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/JsExtension.js +11 -11
- package/dist/Runtime/Extensions/TileMap/JsExtension.js +3 -3
- package/dist/Runtime/Model3DManager.js +1 -1
- package/dist/Runtime/Model3DManager.js.map +2 -2
- package/dist/Runtime/ResourceLoader.js +1 -1
- package/dist/Runtime/ResourceLoader.js.map +2 -2
- package/dist/Runtime/RuntimeLayer.js +1 -1
- package/dist/Runtime/RuntimeLayer.js.map +2 -2
- package/dist/Runtime/events-tools/objecttools.js +1 -1
- package/dist/Runtime/events-tools/objecttools.js.map +2 -2
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js +1 -1
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/jsonmanager.js +1 -1
- package/dist/Runtime/jsonmanager.js.map +2 -2
- package/dist/Runtime/logger.js +1 -1
- package/dist/Runtime/logger.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-effects-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimescene.js +1 -1
- package/dist/Runtime/runtimescene.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/types/project-data.d.ts +6 -1
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +21 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/3D/Model3DRuntimeObject.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n type Model3DAnimation = { name: string; source: string; loop: boolean };\n\n type Model3DObjectNetworkSyncDataType = {\n mt: number;\n op: FloatPoint3D | null;\n cp: FloatPoint3D | null;\n anis: Model3DAnimation[];\n ai: integer;\n ass: float;\n ap: boolean;\n cfd: float;\n };\n\n type Model3DObjectNetworkSyncData = Object3DNetworkSyncData &\n Model3DObjectNetworkSyncDataType;\n\n /** Base parameters for {@link gdjs.Cube3DRuntimeObject} */\n export interface Model3DObjectData extends Object3DData {\n /** The base parameters of the Model3D object */\n content: Object3DDataContent & {\n modelResourceName: string;\n rotationX: number;\n rotationY: number;\n rotationZ: number;\n keepAspectRatio: boolean;\n materialType: 'Basic' | 'StandardWithoutMetalness' | 'KeepOriginal';\n originLocation:\n | 'ModelOrigin'\n | 'ObjectCenter'\n | 'BottomCenterZ'\n | 'BottomCenterY'\n | 'TopLeft';\n centerLocation:\n | 'ModelOrigin'\n | 'ObjectCenter'\n | 'BottomCenterZ'\n | 'BottomCenterY';\n animations: Model3DAnimation[];\n crossfadeDuration: float;\n };\n }\n\n type FloatPoint3D = [float, float, float];\n\n const getPointForLocation = (location: string): FloatPoint3D | null => {\n switch (location) {\n case 'ModelOrigin':\n return null;\n case 'ObjectCenter':\n return [0.5, 0.5, 0.5];\n case 'BottomCenterZ':\n return [0.5, 0.5, 0];\n case 'BottomCenterY':\n return [0.5, 1, 0.5];\n case 'TopLeft':\n return [0, 0, 0];\n default:\n return null;\n }\n };\n\n /**\n * A 3D object which displays a 3D model.\n */\n export class Model3DRuntimeObject\n extends gdjs.RuntimeObject3D\n implements gdjs.Animatable\n {\n _renderer: gdjs.Model3DRuntimeObjectRenderer;\n\n _modelResourceName: string;\n _materialType: gdjs.Model3DRuntimeObject.MaterialType =\n gdjs.Model3DRuntimeObject.MaterialType.Basic;\n\n /**\n * The local point of the model that will be at the object position.\n *\n * Coordinates are between 0 and 1.\n *\n * Its value is `null` when the point is configured to `\"ModelOrigin\"`\n * because the model origin needs to be evaluated according to the object\n * configuration.\n * @see gdjs.Model3DRuntimeObject3DRenderer.getOriginPoint\n */\n _originPoint: FloatPoint3D | null;\n /**\n * The local point of the model that is used as rotation center.\n *\n * Coordinates are between 0 and 1.\n *\n * Its value is `null` when the point is configured to `\"ModelOrigin\"`\n * because the model origin needs to be evaluated according to the object\n * configuration.\n * @see gdjs.Model3DRuntimeObject3DRenderer.getCenterPoint\n */\n _centerPoint: FloatPoint3D | null;\n\n _animations: Model3DAnimation[];\n _currentAnimationIndex: integer = 0;\n _animationSpeedScale: float = 1;\n _animationPaused: boolean = false;\n _crossfadeDuration: float = 0;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n objectData: Model3DObjectData\n ) {\n super(instanceContainer, objectData);\n this._modelResourceName = objectData.content.modelResourceName;\n this._animations = objectData.content.animations;\n this._originPoint = getPointForLocation(\n objectData.content.originLocation\n );\n this._centerPoint = getPointForLocation(\n objectData.content.centerLocation\n );\n this._renderer = new gdjs.Model3DRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n this._materialType = this._convertMaterialType(\n objectData.content.materialType\n );\n\n this.onModelChanged(objectData);\n\n this._crossfadeDuration = objectData.content.crossfadeDuration || 0;\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n /**\n * To be called after the renderer loaded a Model resource:\n * - After the renderer was instantiated\n * - After reloading the model\n */\n private onModelChanged(objectData) {\n this._updateModel(objectData);\n if (this._animations.length > 0) {\n this._renderer.playAnimation(\n this._animations[0].source,\n this._animations[0].loop\n );\n }\n }\n\n updateFromObjectData(\n oldObjectData: Model3DObjectData,\n newObjectData: Model3DObjectData\n ): boolean {\n super.updateFromObjectData(oldObjectData, newObjectData);\n\n if (\n oldObjectData.content.materialType !==\n newObjectData.content.materialType\n ) {\n this._materialType = this._convertMaterialType(\n newObjectData.content.materialType\n );\n }\n if (\n oldObjectData.content.modelResourceName !==\n newObjectData.content.modelResourceName\n ) {\n this._reloadModel(newObjectData);\n } else if (\n oldObjectData.content.width !== newObjectData.content.width ||\n oldObjectData.content.height !== newObjectData.content.height ||\n oldObjectData.content.depth !== newObjectData.content.depth ||\n oldObjectData.content.rotationX !== newObjectData.content.rotationX ||\n oldObjectData.content.rotationY !== newObjectData.content.rotationY ||\n oldObjectData.content.rotationZ !== newObjectData.content.rotationZ ||\n oldObjectData.content.keepAspectRatio !==\n newObjectData.content.keepAspectRatio ||\n oldObjectData.content.materialType !==\n newObjectData.content.materialType\n ) {\n this._updateModel(newObjectData);\n }\n if (\n oldObjectData.content.originLocation !==\n newObjectData.content.originLocation\n ) {\n this._originPoint = getPointForLocation(\n newObjectData.content.originLocation\n );\n }\n if (\n oldObjectData.content.centerLocation !==\n newObjectData.content.centerLocation\n ) {\n this._centerPoint = getPointForLocation(\n newObjectData.content.centerLocation\n );\n }\n return true;\n }\n\n getNetworkSyncData(): Model3DObjectNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n mt: this._materialType,\n op: this._originPoint,\n cp: this._centerPoint,\n anis: this._animations,\n ai: this._currentAnimationIndex,\n ass: this._animationSpeedScale,\n ap: this._animationPaused,\n cfd: this._crossfadeDuration,\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: Model3DObjectNetworkSyncData\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n\n if (networkSyncData.mt !== undefined) {\n this._materialType = networkSyncData.mt;\n }\n if (networkSyncData.op !== undefined) {\n this._originPoint = networkSyncData.op;\n }\n if (networkSyncData.cp !== undefined) {\n this._centerPoint = networkSyncData.cp;\n }\n if (networkSyncData.anis !== undefined) {\n this._animations = networkSyncData.anis;\n }\n if (networkSyncData.ai !== undefined) {\n this.setAnimationIndex(networkSyncData.ai);\n }\n if (networkSyncData.ass !== undefined) {\n this.setAnimationSpeedScale(networkSyncData.ass);\n }\n if (networkSyncData.ap !== undefined) {\n if (networkSyncData.ap !== this.isAnimationPaused()) {\n networkSyncData.ap ? this.pauseAnimation() : this.resumeAnimation();\n }\n }\n if (networkSyncData.cfd !== undefined) {\n this._crossfadeDuration = networkSyncData.cfd;\n }\n }\n\n _reloadModel(objectData: Model3DObjectData) {\n this._modelResourceName = objectData.content.modelResourceName;\n this._renderer._reloadModel(this, this._runtimeScene);\n this.onModelChanged(objectData);\n }\n\n _updateModel(objectData: Model3DObjectData) {\n const rotationX = objectData.content.rotationX || 0;\n const rotationY = objectData.content.rotationY || 0;\n const rotationZ = objectData.content.rotationZ || 0;\n const keepAspectRatio = objectData.content.keepAspectRatio;\n this._renderer._updateModel(\n rotationX,\n rotationY,\n rotationZ,\n this._getOriginalWidth(),\n this._getOriginalHeight(),\n this._getOriginalDepth(),\n keepAspectRatio\n );\n }\n\n getRenderer(): RuntimeObject3DRenderer {\n return this._renderer;\n }\n\n _convertMaterialType(\n materialTypeString: string\n ): gdjs.Model3DRuntimeObject.MaterialType {\n if (materialTypeString === 'KeepOriginal') {\n return gdjs.Model3DRuntimeObject.MaterialType.KeepOriginal;\n } else if (materialTypeString === 'StandardWithoutMetalness') {\n return gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness;\n } else {\n return gdjs.Model3DRuntimeObject.MaterialType.Basic;\n }\n }\n\n update(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n const elapsedTime = this.getElapsedTime() / 1000;\n this._renderer.updateAnimation(elapsedTime);\n }\n\n /**\n * Get the index of the animation being played.\n * @return The index of the new animation being played\n */\n getAnimationIndex(): number {\n return this._currentAnimationIndex;\n }\n\n /**\n * Change the animation being played.\n * @param animationIndex The index of the new animation to be played\n */\n setAnimationIndex(animationIndex: number): void {\n animationIndex = animationIndex | 0;\n if (\n animationIndex < this._animations.length &&\n this._currentAnimationIndex !== animationIndex &&\n animationIndex >= 0\n ) {\n const animation = this._animations[animationIndex];\n this._currentAnimationIndex = animationIndex;\n this._renderer.playAnimation(animation.source, animation.loop);\n if (this._animationPaused) {\n this._renderer.pauseAnimation();\n }\n }\n }\n\n /**\n * Get the name of the animation being played.\n * @return The name of the new animation being played\n */\n getAnimationName(): string {\n if (this._currentAnimationIndex >= this._animations.length) {\n return '';\n }\n return this._animations[this._currentAnimationIndex].name;\n }\n\n /**\n * Change the animation being played.\n * @param newAnimationName The name of the new animation to be played\n */\n setAnimationName(newAnimationName: string): void {\n if (!newAnimationName) {\n return;\n }\n const animationIndex = this._animations.findIndex(\n (animation) => animation.name === newAnimationName\n );\n if (animationIndex >= 0) {\n this.setAnimationIndex(animationIndex);\n }\n }\n\n isCurrentAnimationName(name: string): boolean {\n return this.getAnimationName() === name;\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n return this._renderer.hasAnimationEnded();\n }\n\n setCrossfadeDuration(duration: number): void {\n if (this._crossfadeDuration === duration) return;\n this._crossfadeDuration = duration;\n }\n\n isAnimationPaused() {\n return this._animationPaused;\n }\n\n pauseAnimation() {\n this._animationPaused = true;\n this._renderer.pauseAnimation();\n }\n\n resumeAnimation() {\n this._animationPaused = false;\n this._renderer.resumeAnimation();\n }\n\n getAnimationSpeedScale() {\n return this._animationSpeedScale;\n }\n\n setAnimationSpeedScale(ratio: float): void {\n this._animationSpeedScale = ratio;\n this._renderer.setAnimationTimeScale(ratio);\n }\n\n getAnimationElapsedTime(): float {\n return this._renderer.getAnimationElapsedTime();\n }\n\n setAnimationElapsedTime(time: float): void {\n this._renderer.setAnimationElapsedTime(time);\n if (!this._animationPaused) {\n this._renderer.resumeAnimation();\n }\n }\n\n getAnimationDuration(): float {\n return this._renderer.getAnimationDuration(\n this._animations[this._currentAnimationIndex].source\n );\n }\n\n getCenterX(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getWidth() * centerPoint[0];\n }\n\n getCenterY(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getHeight() * centerPoint[1];\n }\n\n getCenterZ(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getDepth() * centerPoint[2];\n }\n\n getDrawableX(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getX() - this.getWidth() * originPoint[0];\n }\n\n getDrawableY(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getY() - this.getHeight() * originPoint[1];\n }\n\n getDrawableZ(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getZ() - this.getDepth() * originPoint[2];\n }\n }\n\n export namespace Model3DRuntimeObject {\n export enum MaterialType {\n Basic,\n StandardWithoutMetalness,\n KeepOriginal,\n }\n }\n gdjs.registerObject('Scene3D::Model3DObject', gdjs.Model3DRuntimeObject);\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n type Model3DAnimation = { name: string; source: string; loop: boolean };\n\n type Model3DObjectNetworkSyncDataType = {\n mt: number;\n op: FloatPoint3D | null;\n cp: FloatPoint3D | null;\n anis: Model3DAnimation[];\n ai: integer;\n ass: float;\n ap: boolean;\n cfd: float;\n };\n\n type Model3DObjectNetworkSyncData = Object3DNetworkSyncData &\n Model3DObjectNetworkSyncDataType;\n\n /** Base parameters for {@link gdjs.Cube3DRuntimeObject} */\n export interface Model3DObjectData extends Object3DData {\n /** The base parameters of the Model3D object */\n content: Object3DDataContent & {\n modelResourceName: string;\n rotationX: number;\n rotationY: number;\n rotationZ: number;\n keepAspectRatio: boolean;\n materialType: 'Basic' | 'StandardWithoutMetalness' | 'KeepOriginal';\n originLocation:\n | 'ModelOrigin'\n | 'ObjectCenter'\n | 'BottomCenterZ'\n | 'BottomCenterY'\n | 'TopLeft';\n centerLocation:\n | 'ModelOrigin'\n | 'ObjectCenter'\n | 'BottomCenterZ'\n | 'BottomCenterY';\n animations: Model3DAnimation[];\n crossfadeDuration: float;\n isCastingShadow: boolean;\n isReceivingShadow: boolean;\n };\n }\n\n type FloatPoint3D = [float, float, float];\n\n const getPointForLocation = (location: string): FloatPoint3D | null => {\n switch (location) {\n case 'ModelOrigin':\n return null;\n case 'ObjectCenter':\n return [0.5, 0.5, 0.5];\n case 'BottomCenterZ':\n return [0.5, 0.5, 0];\n case 'BottomCenterY':\n return [0.5, 1, 0.5];\n case 'TopLeft':\n return [0, 0, 0];\n default:\n return null;\n }\n };\n\n /**\n * A 3D object which displays a 3D model.\n */\n export class Model3DRuntimeObject\n extends gdjs.RuntimeObject3D\n implements gdjs.Animatable\n {\n _renderer: gdjs.Model3DRuntimeObjectRenderer;\n\n _modelResourceName: string;\n _materialType: gdjs.Model3DRuntimeObject.MaterialType =\n gdjs.Model3DRuntimeObject.MaterialType.Basic;\n\n /**\n * The local point of the model that will be at the object position.\n *\n * Coordinates are between 0 and 1.\n *\n * Its value is `null` when the point is configured to `\"ModelOrigin\"`\n * because the model origin needs to be evaluated according to the object\n * configuration.\n * @see gdjs.Model3DRuntimeObject3DRenderer.getOriginPoint\n */\n _originPoint: FloatPoint3D | null;\n /**\n * The local point of the model that is used as rotation center.\n *\n * Coordinates are between 0 and 1.\n *\n * Its value is `null` when the point is configured to `\"ModelOrigin\"`\n * because the model origin needs to be evaluated according to the object\n * configuration.\n * @see gdjs.Model3DRuntimeObject3DRenderer.getCenterPoint\n */\n _centerPoint: FloatPoint3D | null;\n\n _animations: Model3DAnimation[];\n _currentAnimationIndex: integer = 0;\n _animationSpeedScale: float = 1;\n _animationPaused: boolean = false;\n _crossfadeDuration: float = 0;\n _isCastingShadow: boolean = true;\n _isReceivingShadow: boolean = true;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n objectData: Model3DObjectData\n ) {\n super(instanceContainer, objectData);\n this._modelResourceName = objectData.content.modelResourceName;\n this._animations = objectData.content.animations;\n this._originPoint = getPointForLocation(\n objectData.content.originLocation\n );\n this._centerPoint = getPointForLocation(\n objectData.content.centerLocation\n );\n this._renderer = new gdjs.Model3DRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n this._materialType = this._convertMaterialType(\n objectData.content.materialType\n );\n\n this.setIsCastingShadow(objectData.content.isCastingShadow);\n this.setIsReceivingShadow(objectData.content.isReceivingShadow);\n this.onModelChanged(objectData);\n\n this._crossfadeDuration = objectData.content.crossfadeDuration || 0;\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n /**\n * To be called after the renderer loaded a Model resource:\n * - After the renderer was instantiated\n * - After reloading the model\n */\n private onModelChanged(objectData) {\n this._updateModel(objectData);\n if (this._animations.length > 0) {\n this._renderer.playAnimation(\n this._animations[0].source,\n this._animations[0].loop\n );\n }\n }\n\n updateFromObjectData(\n oldObjectData: Model3DObjectData,\n newObjectData: Model3DObjectData\n ): boolean {\n super.updateFromObjectData(oldObjectData, newObjectData);\n\n if (\n oldObjectData.content.materialType !==\n newObjectData.content.materialType\n ) {\n this._materialType = this._convertMaterialType(\n newObjectData.content.materialType\n );\n }\n if (\n oldObjectData.content.modelResourceName !==\n newObjectData.content.modelResourceName\n ) {\n this._reloadModel(newObjectData);\n } else if (\n oldObjectData.content.width !== newObjectData.content.width ||\n oldObjectData.content.height !== newObjectData.content.height ||\n oldObjectData.content.depth !== newObjectData.content.depth ||\n oldObjectData.content.rotationX !== newObjectData.content.rotationX ||\n oldObjectData.content.rotationY !== newObjectData.content.rotationY ||\n oldObjectData.content.rotationZ !== newObjectData.content.rotationZ ||\n oldObjectData.content.keepAspectRatio !==\n newObjectData.content.keepAspectRatio ||\n oldObjectData.content.materialType !==\n newObjectData.content.materialType\n ) {\n this._updateModel(newObjectData);\n }\n if (\n oldObjectData.content.originLocation !==\n newObjectData.content.originLocation\n ) {\n this._originPoint = getPointForLocation(\n newObjectData.content.originLocation\n );\n }\n if (\n oldObjectData.content.centerLocation !==\n newObjectData.content.centerLocation\n ) {\n this._centerPoint = getPointForLocation(\n newObjectData.content.centerLocation\n );\n }\n if (\n oldObjectData.content.isCastingShadow !==\n newObjectData.content.isCastingShadow\n ) {\n this.setIsCastingShadow(newObjectData.content.isCastingShadow);\n }\n if (\n oldObjectData.content.isReceivingShadow !==\n newObjectData.content.isReceivingShadow\n ) {\n this.setIsReceivingShadow(newObjectData.content.isReceivingShadow);\n }\n return true;\n }\n\n getNetworkSyncData(): Model3DObjectNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n mt: this._materialType,\n op: this._originPoint,\n cp: this._centerPoint,\n anis: this._animations,\n ai: this._currentAnimationIndex,\n ass: this._animationSpeedScale,\n ap: this._animationPaused,\n cfd: this._crossfadeDuration,\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: Model3DObjectNetworkSyncData\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n\n if (networkSyncData.mt !== undefined) {\n this._materialType = networkSyncData.mt;\n }\n if (networkSyncData.op !== undefined) {\n this._originPoint = networkSyncData.op;\n }\n if (networkSyncData.cp !== undefined) {\n this._centerPoint = networkSyncData.cp;\n }\n if (networkSyncData.anis !== undefined) {\n this._animations = networkSyncData.anis;\n }\n if (networkSyncData.ai !== undefined) {\n this.setAnimationIndex(networkSyncData.ai);\n }\n if (networkSyncData.ass !== undefined) {\n this.setAnimationSpeedScale(networkSyncData.ass);\n }\n if (networkSyncData.ap !== undefined) {\n if (networkSyncData.ap !== this.isAnimationPaused()) {\n networkSyncData.ap ? this.pauseAnimation() : this.resumeAnimation();\n }\n }\n if (networkSyncData.cfd !== undefined) {\n this._crossfadeDuration = networkSyncData.cfd;\n }\n }\n\n _reloadModel(objectData: Model3DObjectData) {\n this._modelResourceName = objectData.content.modelResourceName;\n this._renderer._reloadModel(this, this._runtimeScene);\n this.onModelChanged(objectData);\n }\n\n _updateModel(objectData: Model3DObjectData) {\n const rotationX = objectData.content.rotationX || 0;\n const rotationY = objectData.content.rotationY || 0;\n const rotationZ = objectData.content.rotationZ || 0;\n const keepAspectRatio = objectData.content.keepAspectRatio;\n this._renderer._updateModel(\n rotationX,\n rotationY,\n rotationZ,\n this._getOriginalWidth(),\n this._getOriginalHeight(),\n this._getOriginalDepth(),\n keepAspectRatio\n );\n }\n\n getRenderer(): RuntimeObject3DRenderer {\n return this._renderer;\n }\n\n _convertMaterialType(\n materialTypeString: string\n ): gdjs.Model3DRuntimeObject.MaterialType {\n if (materialTypeString === 'KeepOriginal') {\n return gdjs.Model3DRuntimeObject.MaterialType.KeepOriginal;\n } else if (materialTypeString === 'StandardWithoutMetalness') {\n return gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness;\n } else {\n return gdjs.Model3DRuntimeObject.MaterialType.Basic;\n }\n }\n\n update(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n const elapsedTime = this.getElapsedTime() / 1000;\n this._renderer.updateAnimation(elapsedTime);\n }\n\n /**\n * Get the index of the animation being played.\n * @return The index of the new animation being played\n */\n getAnimationIndex(): number {\n return this._currentAnimationIndex;\n }\n\n /**\n * Change the animation being played.\n * @param animationIndex The index of the new animation to be played\n */\n setAnimationIndex(animationIndex: number): void {\n animationIndex = animationIndex | 0;\n if (\n animationIndex < this._animations.length &&\n this._currentAnimationIndex !== animationIndex &&\n animationIndex >= 0\n ) {\n const animation = this._animations[animationIndex];\n this._currentAnimationIndex = animationIndex;\n this._renderer.playAnimation(animation.source, animation.loop);\n if (this._animationPaused) {\n this._renderer.pauseAnimation();\n }\n }\n }\n\n /**\n * Get the name of the animation being played.\n * @return The name of the new animation being played\n */\n getAnimationName(): string {\n if (this._currentAnimationIndex >= this._animations.length) {\n return '';\n }\n return this._animations[this._currentAnimationIndex].name;\n }\n\n /**\n * Change the animation being played.\n * @param newAnimationName The name of the new animation to be played\n */\n setAnimationName(newAnimationName: string): void {\n if (!newAnimationName) {\n return;\n }\n const animationIndex = this._animations.findIndex(\n (animation) => animation.name === newAnimationName\n );\n if (animationIndex >= 0) {\n this.setAnimationIndex(animationIndex);\n }\n }\n\n isCurrentAnimationName(name: string): boolean {\n return this.getAnimationName() === name;\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n return this._renderer.hasAnimationEnded();\n }\n\n setIsCastingShadow(value: boolean): void {\n this._isCastingShadow = value;\n this._renderer._updateShadow();\n }\n\n setIsReceivingShadow(value: boolean): void {\n this._isReceivingShadow = value;\n this._renderer._updateShadow();\n }\n\n setCrossfadeDuration(duration: number): void {\n if (this._crossfadeDuration === duration) return;\n this._crossfadeDuration = duration;\n }\n\n isAnimationPaused() {\n return this._animationPaused;\n }\n\n pauseAnimation() {\n this._animationPaused = true;\n this._renderer.pauseAnimation();\n }\n\n resumeAnimation() {\n this._animationPaused = false;\n this._renderer.resumeAnimation();\n }\n\n getAnimationSpeedScale() {\n return this._animationSpeedScale;\n }\n\n setAnimationSpeedScale(ratio: float): void {\n this._animationSpeedScale = ratio;\n this._renderer.setAnimationTimeScale(ratio);\n }\n\n getAnimationElapsedTime(): float {\n return this._renderer.getAnimationElapsedTime();\n }\n\n setAnimationElapsedTime(time: float): void {\n this._renderer.setAnimationElapsedTime(time);\n if (!this._animationPaused) {\n this._renderer.resumeAnimation();\n }\n }\n\n getAnimationDuration(): float {\n return this._renderer.getAnimationDuration(\n this._animations[this._currentAnimationIndex].source\n );\n }\n\n getCenterX(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getWidth() * centerPoint[0];\n }\n\n getCenterY(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getHeight() * centerPoint[1];\n }\n\n getCenterZ(): float {\n const centerPoint = this._renderer.getCenterPoint();\n return this.getDepth() * centerPoint[2];\n }\n\n getDrawableX(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getX() - this.getWidth() * originPoint[0];\n }\n\n getDrawableY(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getY() - this.getHeight() * originPoint[1];\n }\n\n getDrawableZ(): float {\n const originPoint = this._renderer.getOriginPoint();\n return this.getZ() - this.getDepth() * originPoint[2];\n }\n }\n\n export namespace Model3DRuntimeObject {\n export enum MaterialType {\n Basic,\n StandardWithoutMetalness,\n KeepOriginal,\n }\n }\n gdjs.registerObject('Scene3D::Model3DObject', gdjs.Model3DRuntimeObject);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CA+CE,KAAM,GAAsB,AAAC,GAA0C,CACrE,OAAQ,OACD,cACH,MAAO,UACJ,eACH,MAAO,CAAC,GAAK,GAAK,QACf,gBACH,MAAO,CAAC,GAAK,GAAK,OACf,gBACH,MAAO,CAAC,GAAK,EAAG,QACb,UACH,MAAO,CAAC,EAAG,EAAG,WAEd,MAAO,QAON,eACG,GAAK,eAEf,CAsCE,YACE,EACA,EACA,CACA,MAAM,EAAmB,GAtC3B,mBACE,EAAK,qBAAqB,aAAa,MA0BzC,4BAAkC,EAClC,0BAA8B,EAC9B,sBAA4B,GAC5B,wBAA4B,EAC5B,sBAA4B,GAC5B,wBAA8B,GAO5B,KAAK,mBAAqB,EAAW,QAAQ,kBAC7C,KAAK,YAAc,EAAW,QAAQ,WACtC,KAAK,aAAe,EAClB,EAAW,QAAQ,gBAErB,KAAK,aAAe,EAClB,EAAW,QAAQ,gBAErB,KAAK,UAAY,GAAI,GAAK,6BACxB,KACA,GAEF,KAAK,cAAgB,KAAK,qBACxB,EAAW,QAAQ,cAGrB,KAAK,mBAAmB,EAAW,QAAQ,iBAC3C,KAAK,qBAAqB,EAAW,QAAQ,mBAC7C,KAAK,eAAe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c,KAAK,UAAU,iBACnC,MAAO,MAAK,WAAa,EAAY,GAGvC,cAAsB,CACpB,KAAM,GAAc,KAAK,UAAU,iBACnC,MAAO,MAAK,OAAS,KAAK,WAAa,EAAY,GAGrD,cAAsB,CACpB,KAAM,GAAc,KAAK,UAAU,iBACnC,MAAO,MAAK,OAAS,KAAK,YAAc,EAAY,GAGtD,cAAsB,CACpB,KAAM,GAAc,KAAK,UAAU,iBACnC,MAAO,MAAK,OAAS,KAAK,WAAa,EAAY,IAzYhD,EAAM,uBA6YN,SAAU,EAAV,CACE,GAAK,GAAL,UAAK,EAAL,CACL,qBACA,2DACA,qCAHU,wCADG,uDAOjB,EAAK,eAAe,yBAA0B,EAAK,wBAvd3C",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(a){const s=1/(1<<16),g=i=>{i.metalness&&(i.metalness=0)},
|
|
1
|
+
var gdjs;(function(a){const s=1/(1<<16),g=i=>{i.metalness&&(i.metalness=0)},f=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)g(t.material[e]);else g(t.material)},b=i=>i.traverse(f),M=i=>{const t=new THREE.MeshBasicMaterial;return i.color&&(t.color=i.color),i.map&&(t.map=i.map),t},D=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)t.material[e]=M(t.material[e]);else t.material=M(t.material)},T=i=>i.traverse(D);class j extends a.RuntimeObject3DRenderer{constructor(t,e){const r=e.getGame().getModel3DManager().getModel(t._modelResourceName),n=new THREE.Group,h=new THREE.Group;h.rotation.order="ZYX",h.add(n);super(t,e,h);this._model3DRuntimeObject=t,this._threeObject=n,this._originalModel=r,this._modelOriginPoint=[0,0,0],this.updateSize(),this.updatePosition(),this.updateRotation(),this._animationMixer=new THREE.AnimationMixer(n),this._action=null}updateAnimation(t){this._animationMixer.update(t)}updatePosition(){const t=this.getOriginPoint(),e=this.getCenterPoint();this.get3DRendererObject().position.set(this._object.getX()-this._object.getWidth()*(t[0]-e[0]),this._object.getY()-this._object.getHeight()*(t[1]-e[1]),this._object.getZ()-this._object.getDepth()*(t[2]-e[2]))}getOriginPoint(){return this._model3DRuntimeObject._originPoint||this._modelOriginPoint}getCenterPoint(){return this._model3DRuntimeObject._centerPoint||this._modelOriginPoint}_updateDefaultTransformation(t,e,r,n,h,R,p,l){t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(n)),t.updateMatrixWorld(!0);const o=new THREE.Box3().setFromObject(t);!this._model3DRuntimeObject._originPoint&&o.expandByPoint(new THREE.Vector3(0,0,0));const m=o.max.x-o.min.x,c=o.max.y-o.min.y,d=o.max.z-o.min.z;this._modelOriginPoint[0]=m<s?0:-o.min.x/m,this._modelOriginPoint[1]=c<s?0:-o.min.y/c,this._modelOriginPoint[2]=d<s?0:-o.min.z/d,this._modelOriginPoint[1]=1-this._modelOriginPoint[1];const u=this._model3DRuntimeObject._centerPoint;u&&t.position.set(-(o.min.x+m*u[0]),-(o.min.y+c*(1-u[1])),-(o.min.z+d*u[2])),t.scale.set(1,1,1),t.rotation.set(a.toRad(e),a.toRad(r),a.toRad(n));const A=m<s?1:1/m,H=c<s?1:1/c,P=d<s?1:1/d,O=new THREE.Matrix4;if(O.makeScale(A,-H,P),t.updateMatrix(),t.applyMatrix4(O),l){const x=m<s?Number.POSITIVE_INFINITY:h/m,v=c<s?Number.POSITIVE_INFINITY:R/c,I=d<s?Number.POSITIVE_INFINITY:p/d;let _=Math.min(x,v,I);Number.isFinite(_)||(_=1),this._object._setOriginalWidth(_*m),this._object._setOriginalHeight(_*c),this._object._setOriginalDepth(_*d)}}_reloadModel(t,e){this._originalModel=e.getGame().getModel3DManager().getModel(t._modelResourceName)}_updateModel(t,e,r,n,h,R,p){const l=new THREE.Group;l.rotation.order="ZYX";const o=THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);l.add(o),this._replaceMaterials(l),this._updateDefaultTransformation(l,t,e,r,n,h,R,p),this.get3DRendererObject().remove(this._threeObject),this.get3DRendererObject().add(l),this._threeObject=l,this._updateShadow(),this._animationMixer=new THREE.AnimationMixer(o);const E=this._model3DRuntimeObject.isAnimationPaused();this._model3DRuntimeObject.setAnimationIndex(this._model3DRuntimeObject.getAnimationIndex()),E&&this.pauseAnimation()}_replaceMaterials(t){this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness?b(t):this._model3DRuntimeObject._materialType===a.Model3DRuntimeObject.MaterialType.Basic&&T(t)}getAnimationCount(){return this._originalModel.animations.length}getAnimationName(t){return this._originalModel.animations[t].name}_updateShadow(){this._threeObject.traverse(t=>{t.castShadow=this._model3DRuntimeObject._isCastingShadow,t.receiveShadow=this._model3DRuntimeObject._isReceivingShadow})}hasAnimationEnded(){return this._action?!this._action.isRunning():!0}animationPaused(){if(!!this._action)return this._action.paused}pauseAnimation(){!this._action||(this._action.paused=!0)}resumeAnimation(){!this._action||(this._action.paused=!1)}playAnimation(t,e){const r=THREE.AnimationClip.findByName(this._originalModel.animations,t);if(!r){console.error(`The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${t}`);return}const n=this._action;this._action=this._animationMixer.clipAction(r),this._action.reset(),this._action.setLoop(e?THREE.LoopRepeat:THREE.LoopOnce,Number.POSITIVE_INFINITY),this._action.clampWhenFinished=!0,this._action.timeScale=this._model3DRuntimeObject.getAnimationSpeedScale(),n&&n!==this._action&&this._action.crossFadeFrom(n,this._model3DRuntimeObject._crossfadeDuration,!1),this._action.play(),this._animationMixer.update(0)}getAnimationElapsedTime(){return this._action?this._action.time:0}setAnimationElapsedTime(t){this._action&&(this._action.time=t)}setAnimationTimeScale(t){this._action&&(this._action.timeScale=t)}getAnimationDuration(t){const e=THREE.AnimationClip.findByName(this._originalModel.animations,t);return e?e.duration:0}}a.Model3DRuntimeObjectRenderer=j})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=Model3DRuntimeObject3DRenderer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/3D/Model3DRuntimeObject3DRenderer.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n type FloatPoint3D = [float, float, float];\n\n const epsilon = 1 / (1 << 16);\n\n const removeMetalness = (material: THREE.Material): void => {\n //@ts-ignore\n if (material.metalness) {\n //@ts-ignore\n material.metalness = 0;\n }\n };\n\n const removeMetalnessFromMesh = (node: THREE.Object3D) => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n removeMetalness(mesh.material[index]);\n }\n } else {\n removeMetalness(mesh.material);\n }\n };\n\n const traverseToRemoveMetalnessFromMeshes = (node: THREE.Object3D) =>\n node.traverse(removeMetalnessFromMesh);\n\n const convertToBasicMaterial = (\n material: THREE.Material\n ): THREE.MeshBasicMaterial => {\n const basicMaterial = new THREE.MeshBasicMaterial();\n //@ts-ignore\n if (material.color) {\n //@ts-ignore\n basicMaterial.color = material.color;\n }\n //@ts-ignore\n if (material.map) {\n //@ts-ignore\n basicMaterial.map = material.map;\n }\n return basicMaterial;\n };\n\n const setBasicMaterialTo = (node: THREE.Object3D): void => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n mesh.material[index] = convertToBasicMaterial(mesh.material[index]);\n }\n } else {\n mesh.material = convertToBasicMaterial(mesh.material);\n }\n };\n\n const traverseToSetBasicMaterialFromMeshes = (node: THREE.Object3D) =>\n node.traverse(setBasicMaterialTo);\n\n class Model3DRuntimeObject3DRenderer extends gdjs.RuntimeObject3DRenderer {\n private _model3DRuntimeObject: gdjs.Model3DRuntimeObject;\n /**\n * The 3D model stretched in a 1x1x1 cube.\n */\n private _threeObject: THREE.Object3D;\n private _originalModel: THREE_ADDONS.GLTF;\n private _animationMixer: THREE.AnimationMixer;\n private _action: THREE.AnimationAction | null;\n\n /**\n * The model origin evaluated according to the object configuration.\n *\n * Coordinates are between 0 and 1.\n */\n private _modelOriginPoint: FloatPoint3D;\n\n constructor(\n runtimeObject: gdjs.Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n // GLB files with skeleton must not have any transformation to work properly.\n const originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n // _updateModel will actually add a clone of the model.\n const model = new THREE.Group();\n\n // Create a group to transform the object according to\n // position, angle and dimensions.\n const group = new THREE.Group();\n group.rotation.order = 'ZYX';\n group.add(model);\n super(runtimeObject, instanceContainer, group);\n\n this._model3DRuntimeObject = runtimeObject;\n this._threeObject = model;\n this._originalModel = originalModel;\n this._modelOriginPoint = [0, 0, 0];\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n\n this._animationMixer = new THREE.AnimationMixer(model);\n this._action = null;\n }\n\n updateAnimation(timeDelta: float) {\n this._animationMixer.update(timeDelta);\n }\n\n updatePosition() {\n const originPoint = this.getOriginPoint();\n const centerPoint = this.getCenterPoint();\n this.get3DRendererObject().position.set(\n this._object.getX() -\n this._object.getWidth() * (originPoint[0] - centerPoint[0]),\n this._object.getY() -\n this._object.getHeight() * (originPoint[1] - centerPoint[1]),\n this._object.getZ() -\n this._object.getDepth() * (originPoint[2] - centerPoint[2])\n );\n }\n\n getOriginPoint() {\n return this._model3DRuntimeObject._originPoint || this._modelOriginPoint;\n }\n\n getCenterPoint() {\n return this._model3DRuntimeObject._centerPoint || this._modelOriginPoint;\n }\n\n private _updateDefaultTransformation(\n threeObject: THREE.Object3D,\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // These formulas are also used in:\n // - Model3DEditor.modelSize\n // - Model3DRendered2DInstance\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n threeObject.updateMatrixWorld(true);\n const boundingBox = new THREE.Box3().setFromObject(threeObject);\n\n const shouldKeepModelOrigin = !this._model3DRuntimeObject._originPoint;\n if (shouldKeepModelOrigin) {\n // Keep the origin as part of the model.\n // For instance, a model can be 1 face of a cube and we want to keep the\n // inside as part of the object even if it's just void.\n // It also avoids to have the origin outside of the object box.\n boundingBox.expandByPoint(new THREE.Vector3(0, 0, 0));\n }\n\n const modelWidth = boundingBox.max.x - boundingBox.min.x;\n const modelHeight = boundingBox.max.y - boundingBox.min.y;\n const modelDepth = boundingBox.max.z - boundingBox.min.z;\n this._modelOriginPoint[0] =\n modelWidth < epsilon ? 0 : -boundingBox.min.x / modelWidth;\n this._modelOriginPoint[1] =\n modelHeight < epsilon ? 0 : -boundingBox.min.y / modelHeight;\n this._modelOriginPoint[2] =\n modelDepth < epsilon ? 0 : -boundingBox.min.z / modelDepth;\n\n // The model is flipped on Y axis.\n this._modelOriginPoint[1] = 1 - this._modelOriginPoint[1];\n\n // Center the model.\n const centerPoint = this._model3DRuntimeObject._centerPoint;\n if (centerPoint) {\n threeObject.position.set(\n -(boundingBox.min.x + modelWidth * centerPoint[0]),\n // The model is flipped on Y axis.\n -(boundingBox.min.y + modelHeight * (1 - centerPoint[1])),\n -(boundingBox.min.z + modelDepth * centerPoint[2])\n );\n }\n\n // Rotate the model.\n threeObject.scale.set(1, 1, 1);\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n\n // Stretch the model in a 1x1x1 cube.\n const scaleX = modelWidth < epsilon ? 1 : 1 / modelWidth;\n const scaleY = modelHeight < epsilon ? 1 : 1 / modelHeight;\n const scaleZ = modelDepth < epsilon ? 1 : 1 / modelDepth;\n\n const scaleMatrix = new THREE.Matrix4();\n // Flip on Y because the Y axis is on the opposite side of direct basis.\n // It avoids models to be like a mirror refection.\n scaleMatrix.makeScale(scaleX, -scaleY, scaleZ);\n threeObject.updateMatrix();\n threeObject.applyMatrix4(scaleMatrix);\n\n if (keepAspectRatio) {\n // Reduce the object dimensions to keep aspect ratio.\n const widthRatio =\n modelWidth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalWidth / modelWidth;\n const heightRatio =\n modelHeight < epsilon\n ? Number.POSITIVE_INFINITY\n : originalHeight / modelHeight;\n const depthRatio =\n modelDepth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalDepth / modelDepth;\n let scaleRatio = Math.min(widthRatio, heightRatio, depthRatio);\n if (!Number.isFinite(scaleRatio)) {\n scaleRatio = 1;\n }\n\n this._object._setOriginalWidth(scaleRatio * modelWidth);\n this._object._setOriginalHeight(scaleRatio * modelHeight);\n this._object._setOriginalDepth(scaleRatio * modelDepth);\n }\n }\n\n /**\n * `_updateModel` should always be called after this method.\n * Ideally, use `Model3DRuntimeObject#_reloadModel` instead.\n */\n _reloadModel(\n runtimeObject: Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n }\n\n _updateModel(\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // Start from the original model because:\n // - _replaceMaterials is destructive\n // - _updateDefaultTransformation may need to work with meshes in local space\n\n // This group hold the rotation defined by properties.\n const threeObject = new THREE.Group();\n threeObject.rotation.order = 'ZYX';\n const root = THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);\n threeObject.add(root);\n\n this._replaceMaterials(threeObject);\n\n this._updateDefaultTransformation(\n threeObject,\n rotationX,\n rotationY,\n rotationZ,\n originalWidth,\n originalHeight,\n originalDepth,\n keepAspectRatio\n );\n\n // Replace the 3D object.\n this.get3DRendererObject().remove(this._threeObject);\n this.get3DRendererObject().add(threeObject);\n this._threeObject = threeObject;\n\n // Start the current animation on the new 3D object.\n this._animationMixer = new THREE.AnimationMixer(root);\n const isAnimationPaused = this._model3DRuntimeObject.isAnimationPaused();\n this._model3DRuntimeObject.setAnimationIndex(\n this._model3DRuntimeObject.getAnimationIndex()\n );\n if (isAnimationPaused) {\n this.pauseAnimation();\n }\n }\n\n /**\n * Replace materials to better work with lights (or no light).\n */\n private _replaceMaterials(threeObject: THREE.Object3D) {\n if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness\n ) {\n traverseToRemoveMetalnessFromMeshes(threeObject);\n } else if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.Basic\n ) {\n traverseToSetBasicMaterialFromMeshes(threeObject);\n }\n }\n\n getAnimationCount() {\n return this._originalModel.animations.length;\n }\n\n getAnimationName(animationIndex: integer) {\n return this._originalModel.animations[animationIndex].name;\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n if (!this._action) {\n return true;\n }\n return !this._action.isRunning();\n }\n\n animationPaused() {\n if (!this._action) {\n return;\n }\n return this._action.paused;\n }\n\n pauseAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = true;\n }\n\n resumeAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = false;\n }\n\n playAnimation(animationName: string, shouldLoop: boolean) {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n if (!clip) {\n console.error(\n `The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${animationName}`\n );\n return;\n }\n const previousAction = this._action;\n this._action = this._animationMixer.clipAction(clip);\n // Reset the animation and play it from the start.\n // `clipAction` always gives back the same action for a given animation\n // and its likely to be in a finished or at least started state.\n this._action.reset();\n this._action.setLoop(\n shouldLoop ? THREE.LoopRepeat : THREE.LoopOnce,\n Number.POSITIVE_INFINITY\n );\n this._action.clampWhenFinished = true;\n this._action.timeScale =\n this._model3DRuntimeObject.getAnimationSpeedScale();\n\n if (previousAction && previousAction !== this._action) {\n this._action.crossFadeFrom(\n previousAction,\n this._model3DRuntimeObject._crossfadeDuration,\n false\n );\n }\n this._action.play();\n // Make sure the first frame is displayed.\n this._animationMixer.update(0);\n }\n\n getAnimationElapsedTime(): float {\n return this._action ? this._action.time : 0;\n }\n\n setAnimationElapsedTime(time: float): void {\n if (this._action) {\n this._action.time = time;\n }\n }\n\n setAnimationTimeScale(timeScale: float): void {\n if (this._action) {\n this._action.timeScale = timeScale;\n }\n }\n\n getAnimationDuration(animationName: string): float {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n return clip ? clip.duration : 0;\n }\n }\n\n export const Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n export type Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAGE,KAAM,GAAU,EAAK,IAAK,IAEpB,EAAkB,AAAC,GAAmC,CAE1D,AAAI,EAAS,WAEX,GAAS,UAAY,IAInB,EAA0B,AAAC,GAAyB,CACxD,KAAM,GAAO,EACb,GAAI,EAAC,EAAK,SAGV,GAAI,MAAM,QAAQ,EAAK,UACrB,OAAS,GAAQ,EAAG,EAAQ,EAAK,SAAS,OAAQ,IAChD,EAAgB,EAAK,SAAS,QAGhC,GAAgB,EAAK,WAInB,EAAsC,AAAC,GAC3C,EAAK,SAAS,GAEV,EAAyB,AAC7B,GAC4B,CAC5B,KAAM,GAAgB,GAAI,OAAM,kBAEhC,MAAI,GAAS,OAEX,GAAc,MAAQ,EAAS,OAG7B,EAAS,KAEX,GAAc,IAAM,EAAS,KAExB,GAGH,EAAqB,AAAC,GAA+B,CACzD,KAAM,GAAO,EACb,GAAI,EAAC,EAAK,SAIV,GAAI,MAAM,QA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,GAC5C,KAAK,QAAQ,mBAAmB,EAAa,GAC7C,KAAK,QAAQ,kBAAkB,EAAa,IAQhD,aACE,EACA,EACA,CACA,KAAK,eAAiB,EACnB,UACA,oBACA,SAAS,EAAc,oBAG5B,aACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,CAMA,KAAM,GAAc,GAAI,OAAM,MAC9B,EAAY,SAAS,MAAQ,MAC7B,KAAM,GAAO,aAAa,cAAc,MAAM,KAAK,eAAe,OAClE,EAAY,IAAI,GAEhB,KAAK,kBAAkB,GAEvB,KAAK,6BACH,EACA,EACA,EACA,EACA,EACA,EACA,EACA,GAIF,KAAK,sBAAsB,OAAO,KAAK,cACvC,KAAK,sBAAsB,IAAI,GAC/B,KAAK,aAAe,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n type FloatPoint3D = [float, float, float];\n\n const epsilon = 1 / (1 << 16);\n\n const removeMetalness = (material: THREE.Material): void => {\n //@ts-ignore\n if (material.metalness) {\n //@ts-ignore\n material.metalness = 0;\n }\n };\n\n const removeMetalnessFromMesh = (node: THREE.Object3D) => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n removeMetalness(mesh.material[index]);\n }\n } else {\n removeMetalness(mesh.material);\n }\n };\n\n const traverseToRemoveMetalnessFromMeshes = (node: THREE.Object3D) =>\n node.traverse(removeMetalnessFromMesh);\n\n const convertToBasicMaterial = (\n material: THREE.Material\n ): THREE.MeshBasicMaterial => {\n const basicMaterial = new THREE.MeshBasicMaterial();\n //@ts-ignore\n if (material.color) {\n //@ts-ignore\n basicMaterial.color = material.color;\n }\n //@ts-ignore\n if (material.map) {\n //@ts-ignore\n basicMaterial.map = material.map;\n }\n return basicMaterial;\n };\n\n const setBasicMaterialTo = (node: THREE.Object3D): void => {\n const mesh = node as THREE.Mesh;\n if (!mesh.material) {\n return;\n }\n\n if (Array.isArray(mesh.material)) {\n for (let index = 0; index < mesh.material.length; index++) {\n mesh.material[index] = convertToBasicMaterial(mesh.material[index]);\n }\n } else {\n mesh.material = convertToBasicMaterial(mesh.material);\n }\n };\n\n const traverseToSetBasicMaterialFromMeshes = (node: THREE.Object3D) =>\n node.traverse(setBasicMaterialTo);\n\n class Model3DRuntimeObject3DRenderer extends gdjs.RuntimeObject3DRenderer {\n private _model3DRuntimeObject: gdjs.Model3DRuntimeObject;\n /**\n * The 3D model stretched in a 1x1x1 cube.\n */\n private _threeObject: THREE.Object3D;\n private _originalModel: THREE_ADDONS.GLTF;\n private _animationMixer: THREE.AnimationMixer;\n private _action: THREE.AnimationAction | null;\n\n /**\n * The model origin evaluated according to the object configuration.\n *\n * Coordinates are between 0 and 1.\n */\n private _modelOriginPoint: FloatPoint3D;\n\n constructor(\n runtimeObject: gdjs.Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n // GLB files with skeleton must not have any transformation to work properly.\n const originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n // _updateModel will actually add a clone of the model.\n const model = new THREE.Group();\n\n // Create a group to transform the object according to\n // position, angle and dimensions.\n const group = new THREE.Group();\n group.rotation.order = 'ZYX';\n group.add(model);\n super(runtimeObject, instanceContainer, group);\n\n this._model3DRuntimeObject = runtimeObject;\n this._threeObject = model;\n this._originalModel = originalModel;\n this._modelOriginPoint = [0, 0, 0];\n\n this.updateSize();\n this.updatePosition();\n this.updateRotation();\n\n this._animationMixer = new THREE.AnimationMixer(model);\n this._action = null;\n }\n\n updateAnimation(timeDelta: float) {\n this._animationMixer.update(timeDelta);\n }\n\n updatePosition() {\n const originPoint = this.getOriginPoint();\n const centerPoint = this.getCenterPoint();\n this.get3DRendererObject().position.set(\n this._object.getX() -\n this._object.getWidth() * (originPoint[0] - centerPoint[0]),\n this._object.getY() -\n this._object.getHeight() * (originPoint[1] - centerPoint[1]),\n this._object.getZ() -\n this._object.getDepth() * (originPoint[2] - centerPoint[2])\n );\n }\n\n getOriginPoint() {\n return this._model3DRuntimeObject._originPoint || this._modelOriginPoint;\n }\n\n getCenterPoint() {\n return this._model3DRuntimeObject._centerPoint || this._modelOriginPoint;\n }\n\n private _updateDefaultTransformation(\n threeObject: THREE.Object3D,\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // These formulas are also used in:\n // - Model3DEditor.modelSize\n // - Model3DRendered2DInstance\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n threeObject.updateMatrixWorld(true);\n const boundingBox = new THREE.Box3().setFromObject(threeObject);\n\n const shouldKeepModelOrigin = !this._model3DRuntimeObject._originPoint;\n if (shouldKeepModelOrigin) {\n // Keep the origin as part of the model.\n // For instance, a model can be 1 face of a cube and we want to keep the\n // inside as part of the object even if it's just void.\n // It also avoids to have the origin outside of the object box.\n boundingBox.expandByPoint(new THREE.Vector3(0, 0, 0));\n }\n\n const modelWidth = boundingBox.max.x - boundingBox.min.x;\n const modelHeight = boundingBox.max.y - boundingBox.min.y;\n const modelDepth = boundingBox.max.z - boundingBox.min.z;\n this._modelOriginPoint[0] =\n modelWidth < epsilon ? 0 : -boundingBox.min.x / modelWidth;\n this._modelOriginPoint[1] =\n modelHeight < epsilon ? 0 : -boundingBox.min.y / modelHeight;\n this._modelOriginPoint[2] =\n modelDepth < epsilon ? 0 : -boundingBox.min.z / modelDepth;\n\n // The model is flipped on Y axis.\n this._modelOriginPoint[1] = 1 - this._modelOriginPoint[1];\n\n // Center the model.\n const centerPoint = this._model3DRuntimeObject._centerPoint;\n if (centerPoint) {\n threeObject.position.set(\n -(boundingBox.min.x + modelWidth * centerPoint[0]),\n // The model is flipped on Y axis.\n -(boundingBox.min.y + modelHeight * (1 - centerPoint[1])),\n -(boundingBox.min.z + modelDepth * centerPoint[2])\n );\n }\n\n // Rotate the model.\n threeObject.scale.set(1, 1, 1);\n threeObject.rotation.set(\n gdjs.toRad(rotationX),\n gdjs.toRad(rotationY),\n gdjs.toRad(rotationZ)\n );\n\n // Stretch the model in a 1x1x1 cube.\n const scaleX = modelWidth < epsilon ? 1 : 1 / modelWidth;\n const scaleY = modelHeight < epsilon ? 1 : 1 / modelHeight;\n const scaleZ = modelDepth < epsilon ? 1 : 1 / modelDepth;\n\n const scaleMatrix = new THREE.Matrix4();\n // Flip on Y because the Y axis is on the opposite side of direct basis.\n // It avoids models to be like a mirror refection.\n scaleMatrix.makeScale(scaleX, -scaleY, scaleZ);\n threeObject.updateMatrix();\n threeObject.applyMatrix4(scaleMatrix);\n\n if (keepAspectRatio) {\n // Reduce the object dimensions to keep aspect ratio.\n const widthRatio =\n modelWidth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalWidth / modelWidth;\n const heightRatio =\n modelHeight < epsilon\n ? Number.POSITIVE_INFINITY\n : originalHeight / modelHeight;\n const depthRatio =\n modelDepth < epsilon\n ? Number.POSITIVE_INFINITY\n : originalDepth / modelDepth;\n let scaleRatio = Math.min(widthRatio, heightRatio, depthRatio);\n if (!Number.isFinite(scaleRatio)) {\n scaleRatio = 1;\n }\n\n this._object._setOriginalWidth(scaleRatio * modelWidth);\n this._object._setOriginalHeight(scaleRatio * modelHeight);\n this._object._setOriginalDepth(scaleRatio * modelDepth);\n }\n }\n\n /**\n * `_updateModel` should always be called after this method.\n * Ideally, use `Model3DRuntimeObject#_reloadModel` instead.\n */\n _reloadModel(\n runtimeObject: Model3DRuntimeObject,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._originalModel = instanceContainer\n .getGame()\n .getModel3DManager()\n .getModel(runtimeObject._modelResourceName);\n }\n\n _updateModel(\n rotationX: float,\n rotationY: float,\n rotationZ: float,\n originalWidth: float,\n originalHeight: float,\n originalDepth: float,\n keepAspectRatio: boolean\n ) {\n // Start from the original model because:\n // - _replaceMaterials is destructive\n // - _updateDefaultTransformation may need to work with meshes in local space\n\n // This group hold the rotation defined by properties.\n const threeObject = new THREE.Group();\n threeObject.rotation.order = 'ZYX';\n const root = THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);\n threeObject.add(root);\n\n this._replaceMaterials(threeObject);\n\n this._updateDefaultTransformation(\n threeObject,\n rotationX,\n rotationY,\n rotationZ,\n originalWidth,\n originalHeight,\n originalDepth,\n keepAspectRatio\n );\n\n // Replace the 3D object.\n this.get3DRendererObject().remove(this._threeObject);\n this.get3DRendererObject().add(threeObject);\n this._threeObject = threeObject;\n this._updateShadow();\n\n // Start the current animation on the new 3D object.\n this._animationMixer = new THREE.AnimationMixer(root);\n const isAnimationPaused = this._model3DRuntimeObject.isAnimationPaused();\n this._model3DRuntimeObject.setAnimationIndex(\n this._model3DRuntimeObject.getAnimationIndex()\n );\n if (isAnimationPaused) {\n this.pauseAnimation();\n }\n }\n\n /**\n * Replace materials to better work with lights (or no light).\n */\n private _replaceMaterials(threeObject: THREE.Object3D) {\n if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness\n ) {\n traverseToRemoveMetalnessFromMeshes(threeObject);\n } else if (\n this._model3DRuntimeObject._materialType ===\n gdjs.Model3DRuntimeObject.MaterialType.Basic\n ) {\n traverseToSetBasicMaterialFromMeshes(threeObject);\n }\n }\n\n getAnimationCount() {\n return this._originalModel.animations.length;\n }\n\n getAnimationName(animationIndex: integer) {\n return this._originalModel.animations[animationIndex].name;\n }\n\n _updateShadow() {\n this._threeObject.traverse((child) => {\n child.castShadow = this._model3DRuntimeObject._isCastingShadow;\n child.receiveShadow = this._model3DRuntimeObject._isReceivingShadow;\n });\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n */\n hasAnimationEnded(): boolean {\n if (!this._action) {\n return true;\n }\n return !this._action.isRunning();\n }\n\n animationPaused() {\n if (!this._action) {\n return;\n }\n return this._action.paused;\n }\n\n pauseAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = true;\n }\n\n resumeAnimation() {\n if (!this._action) {\n return;\n }\n this._action.paused = false;\n }\n\n playAnimation(animationName: string, shouldLoop: boolean) {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n if (!clip) {\n console.error(\n `The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${animationName}`\n );\n return;\n }\n const previousAction = this._action;\n this._action = this._animationMixer.clipAction(clip);\n // Reset the animation and play it from the start.\n // `clipAction` always gives back the same action for a given animation\n // and its likely to be in a finished or at least started state.\n this._action.reset();\n this._action.setLoop(\n shouldLoop ? THREE.LoopRepeat : THREE.LoopOnce,\n Number.POSITIVE_INFINITY\n );\n this._action.clampWhenFinished = true;\n this._action.timeScale =\n this._model3DRuntimeObject.getAnimationSpeedScale();\n\n if (previousAction && previousAction !== this._action) {\n this._action.crossFadeFrom(\n previousAction,\n this._model3DRuntimeObject._crossfadeDuration,\n false\n );\n }\n this._action.play();\n // Make sure the first frame is displayed.\n this._animationMixer.update(0);\n }\n\n getAnimationElapsedTime(): float {\n return this._action ? this._action.time : 0;\n }\n\n setAnimationElapsedTime(time: float): void {\n if (this._action) {\n this._action.time = time;\n }\n }\n\n setAnimationTimeScale(timeScale: float): void {\n if (this._action) {\n this._action.timeScale = timeScale;\n }\n }\n\n getAnimationDuration(animationName: string): float {\n const clip = THREE.AnimationClip.findByName(\n this._originalModel.animations,\n animationName\n );\n return clip ? clip.duration : 0;\n }\n }\n\n export const Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n export type Model3DRuntimeObjectRenderer = Model3DRuntimeObject3DRenderer;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CAGE,KAAM,GAAU,EAAK,IAAK,IAEpB,EAAkB,AAAC,GAAmC,CAE1D,AAAI,EAAS,WAEX,GAAS,UAAY,IAInB,EAA0B,AAAC,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,eAAe,WACpB,GAEF,MAAO,GAAO,EAAK,SAAW,GAI3B,AAAM,+BAA+B,IA9apC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -75,9 +75,9 @@ module.exports = {
|
|
|
75
75
|
.getOrCreate('align')
|
|
76
76
|
.setValue(objectContent.align)
|
|
77
77
|
.setType('choice')
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
.
|
|
78
|
+
.addChoice('left', _('Left'))
|
|
79
|
+
.addChoice('center', _('Center'))
|
|
80
|
+
.addChoice('right', _('Right'))
|
|
81
81
|
.setLabel(_('Base alignment'))
|
|
82
82
|
.setGroup(_('Appearance'));
|
|
83
83
|
|
|
@@ -88,9 +88,9 @@ module.exports = {
|
|
|
88
88
|
.getOrCreate('verticalTextAlignment')
|
|
89
89
|
.setValue(objectContent.verticalTextAlignment)
|
|
90
90
|
.setType('choice')
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
.
|
|
91
|
+
.addChoice('top', _('Top'))
|
|
92
|
+
.addChoice('center', _('Center'))
|
|
93
|
+
.addChoice('bottom', _('Bottom'))
|
|
94
94
|
.setLabel(_('Vertical alignment'))
|
|
95
95
|
.setGroup(_('Appearance'));
|
|
96
96
|
|
|
@@ -61,9 +61,9 @@ module.exports = {
|
|
|
61
61
|
.getOrCreate('align')
|
|
62
62
|
.setValue(objectContent.align)
|
|
63
63
|
.setType('choice')
|
|
64
|
-
.
|
|
65
|
-
.
|
|
66
|
-
.
|
|
64
|
+
.addChoice('left', _('Left'))
|
|
65
|
+
.addChoice('center', _('Center'))
|
|
66
|
+
.addChoice('right', _('Right'))
|
|
67
67
|
.setLabel(_('Alignment'))
|
|
68
68
|
.setGroup(_('Appearance'));
|
|
69
69
|
|
|
@@ -74,9 +74,9 @@ module.exports = {
|
|
|
74
74
|
.getOrCreate('verticalTextAlignment')
|
|
75
75
|
.setValue(objectContent.verticalTextAlignment)
|
|
76
76
|
.setType('choice')
|
|
77
|
-
.
|
|
78
|
-
.
|
|
79
|
-
.
|
|
77
|
+
.addChoice('top', _('Top'))
|
|
78
|
+
.addChoice('center', _('Center'))
|
|
79
|
+
.addChoice('bottom', _('Bottom'))
|
|
80
80
|
.setLabel(_('Vertical alignment'))
|
|
81
81
|
.setGroup(_('Appearance'));
|
|
82
82
|
|
|
@@ -818,7 +818,7 @@ module.exports = {
|
|
|
818
818
|
)
|
|
819
819
|
.addParameter('object', _('Object'), '', false)
|
|
820
820
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
821
|
-
.addParameter('yesorno', _('Treat as bullet
|
|
821
|
+
.addParameter('yesorno', _('Treat as bullet'), '', false)
|
|
822
822
|
.setDefaultValue('false')
|
|
823
823
|
.getCodeExtraInformation()
|
|
824
824
|
.setFunctionName('setBullet');
|
|
@@ -852,7 +852,7 @@ module.exports = {
|
|
|
852
852
|
)
|
|
853
853
|
.addParameter('object', _('Object'), '', false)
|
|
854
854
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
855
|
-
.addParameter('yesorno', _('Fixed rotation
|
|
855
|
+
.addParameter('yesorno', _('Fixed rotation'), '', false)
|
|
856
856
|
.setDefaultValue('false')
|
|
857
857
|
.getCodeExtraInformation()
|
|
858
858
|
.setFunctionName('setFixedRotation');
|
|
@@ -886,7 +886,7 @@ module.exports = {
|
|
|
886
886
|
)
|
|
887
887
|
.addParameter('object', _('Object'), '', false)
|
|
888
888
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
889
|
-
.addParameter('yesorno', _('Can sleep
|
|
889
|
+
.addParameter('yesorno', _('Can sleep'), '', false)
|
|
890
890
|
.setDefaultValue('true')
|
|
891
891
|
.getCodeExtraInformation()
|
|
892
892
|
.setFunctionName('setSleepingAllowed');
|
|
@@ -1296,7 +1296,7 @@ module.exports = {
|
|
|
1296
1296
|
.addParameter('object', _('Object'), '', false)
|
|
1297
1297
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
1298
1298
|
.addParameter('expression', _('Layer (1 - 16)'))
|
|
1299
|
-
.addParameter('yesorno', _('Enable
|
|
1299
|
+
.addParameter('yesorno', _('Enable'), '', false)
|
|
1300
1300
|
.setDefaultValue('true')
|
|
1301
1301
|
.getCodeExtraInformation()
|
|
1302
1302
|
.setFunctionName('enableLayer');
|
|
@@ -1332,7 +1332,7 @@ module.exports = {
|
|
|
1332
1332
|
.addParameter('object', _('Object'), '', false)
|
|
1333
1333
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
1334
1334
|
.addParameter('expression', _('Mask (1 - 16)'))
|
|
1335
|
-
.addParameter('yesorno', _('Enable
|
|
1335
|
+
.addParameter('yesorno', _('Enable'), '', false)
|
|
1336
1336
|
.setDefaultValue('true')
|
|
1337
1337
|
.getCodeExtraInformation()
|
|
1338
1338
|
.setFunctionName('enableMask');
|
|
@@ -2409,7 +2409,7 @@ module.exports = {
|
|
|
2409
2409
|
.addParameter('object', _('Object'), '', false)
|
|
2410
2410
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
2411
2411
|
.addParameter('expression', _('Joint ID'))
|
|
2412
|
-
.addParameter('yesorno', _('Enable
|
|
2412
|
+
.addParameter('yesorno', _('Enable'))
|
|
2413
2413
|
.getCodeExtraInformation()
|
|
2414
2414
|
.setFunctionName('enableRevoluteJointLimits');
|
|
2415
2415
|
|
|
@@ -2488,7 +2488,7 @@ module.exports = {
|
|
|
2488
2488
|
.addParameter('object', _('Object'), '', false)
|
|
2489
2489
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
2490
2490
|
.addParameter('expression', _('Joint ID'))
|
|
2491
|
-
.addParameter('yesorno', _('Enable
|
|
2491
|
+
.addParameter('yesorno', _('Enable'))
|
|
2492
2492
|
.getCodeExtraInformation()
|
|
2493
2493
|
.setFunctionName('enableRevoluteJointMotor');
|
|
2494
2494
|
|
|
@@ -2727,7 +2727,7 @@ module.exports = {
|
|
|
2727
2727
|
.addParameter('object', _('Object'), '', false)
|
|
2728
2728
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
2729
2729
|
.addParameter('expression', _('Joint ID'))
|
|
2730
|
-
.addParameter('yesorno', _('Enable
|
|
2730
|
+
.addParameter('yesorno', _('Enable'))
|
|
2731
2731
|
.getCodeExtraInformation()
|
|
2732
2732
|
.setFunctionName('enablePrismaticJointLimits');
|
|
2733
2733
|
|
|
@@ -2806,7 +2806,7 @@ module.exports = {
|
|
|
2806
2806
|
.addParameter('object', _('Object'), '', false)
|
|
2807
2807
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
2808
2808
|
.addParameter('expression', _('Joint ID'))
|
|
2809
|
-
.addParameter('yesorno', _('Enable
|
|
2809
|
+
.addParameter('yesorno', _('Enable'))
|
|
2810
2810
|
.getCodeExtraInformation()
|
|
2811
2811
|
.setFunctionName('enablePrismaticJointMotor');
|
|
2812
2812
|
|
|
@@ -3486,7 +3486,7 @@ module.exports = {
|
|
|
3486
3486
|
.addParameter('object', _('Object'), '', false)
|
|
3487
3487
|
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
|
|
3488
3488
|
.addParameter('expression', _('Joint ID'))
|
|
3489
|
-
.addParameter('yesorno', _('Enable
|
|
3489
|
+
.addParameter('yesorno', _('Enable'))
|
|
3490
3490
|
.getCodeExtraInformation()
|
|
3491
3491
|
.setFunctionName('enableWheelJointMotor');
|
|
3492
3492
|
|
|
@@ -274,7 +274,7 @@ module.exports = {
|
|
|
274
274
|
.setLabel('Fixed Rotation')
|
|
275
275
|
.setDescription(
|
|
276
276
|
_(
|
|
277
|
-
"If enabled, the object won't rotate and will stay at the same angle.
|
|
277
|
+
"If enabled, the object won't rotate and will stay at the same angle."
|
|
278
278
|
)
|
|
279
279
|
)
|
|
280
280
|
.setGroup(_('Movement'));
|
|
@@ -845,7 +845,7 @@ module.exports = {
|
|
|
845
845
|
)
|
|
846
846
|
.addParameter('object', _('Object'), '', false)
|
|
847
847
|
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
848
|
-
.addParameter('yesorno', _('Treat as bullet
|
|
848
|
+
.addParameter('yesorno', _('Treat as bullet'), '', false)
|
|
849
849
|
.setDefaultValue('false')
|
|
850
850
|
.getCodeExtraInformation()
|
|
851
851
|
.setFunctionName('setBullet');
|
|
@@ -870,7 +870,7 @@ module.exports = {
|
|
|
870
870
|
'SetFixedRotation',
|
|
871
871
|
_('Fixed rotation'),
|
|
872
872
|
_(
|
|
873
|
-
"Enable or disable an object fixed rotation. If enabled the object won't be able to rotate."
|
|
873
|
+
"Enable or disable an object fixed rotation. If enabled the object won't be able to rotate. This action has no effect on characters."
|
|
874
874
|
),
|
|
875
875
|
_('Set _PARAM0_ fixed rotation: _PARAM2_'),
|
|
876
876
|
_('Dynamics'),
|
|
@@ -879,7 +879,7 @@ module.exports = {
|
|
|
879
879
|
)
|
|
880
880
|
.addParameter('object', _('Object'), '', false)
|
|
881
881
|
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
882
|
-
.addParameter('yesorno', _('Fixed rotation
|
|
882
|
+
.addParameter('yesorno', _('Fixed rotation'), '', false)
|
|
883
883
|
.setDefaultValue('false')
|
|
884
884
|
.getCodeExtraInformation()
|
|
885
885
|
.setFunctionName('setFixedRotation');
|
|
@@ -1054,7 +1054,7 @@ module.exports = {
|
|
|
1054
1054
|
.addParameter('object', _('Object'), '', false)
|
|
1055
1055
|
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
1056
1056
|
.addParameter('expression', _('Layer (1 - 8)'))
|
|
1057
|
-
.addParameter('yesorno', _('Enable
|
|
1057
|
+
.addParameter('yesorno', _('Enable'), '', false)
|
|
1058
1058
|
.setDefaultValue('true')
|
|
1059
1059
|
.getCodeExtraInformation()
|
|
1060
1060
|
.setFunctionName('enableLayer');
|
|
@@ -1090,7 +1090,7 @@ module.exports = {
|
|
|
1090
1090
|
.addParameter('object', _('Object'), '', false)
|
|
1091
1091
|
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
1092
1092
|
.addParameter('expression', _('Mask (1 - 8)'))
|
|
1093
|
-
.addParameter('yesorno', _('Enable
|
|
1093
|
+
.addParameter('yesorno', _('Enable'), '', false)
|
|
1094
1094
|
.setDefaultValue('true')
|
|
1095
1095
|
.getCodeExtraInformation()
|
|
1096
1096
|
.setFunctionName('enableMask');
|
|
@@ -1270,7 +1270,7 @@ module.exports = {
|
|
|
1270
1270
|
.addParameter('expression', _('Application point on Z axis'))
|
|
1271
1271
|
.setParameterLongDescription(
|
|
1272
1272
|
_(
|
|
1273
|
-
'Use `MassCenterX` and `
|
|
1273
|
+
'Use `MassCenterX`, `MassCenterY` and `MassCenterZ` expressions to avoid any rotation.'
|
|
1274
1274
|
)
|
|
1275
1275
|
)
|
|
1276
1276
|
.getCodeExtraInformation()
|
|
@@ -1544,6 +1544,19 @@ module.exports = {
|
|
|
1544
1544
|
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
1545
1545
|
.getCodeExtraInformation()
|
|
1546
1546
|
.setFunctionName('getMassCenterY');
|
|
1547
|
+
|
|
1548
|
+
aut
|
|
1549
|
+
.addExpression(
|
|
1550
|
+
'MassCenterZ',
|
|
1551
|
+
_('Mass center Z'),
|
|
1552
|
+
_('Mass center Z'),
|
|
1553
|
+
'',
|
|
1554
|
+
'JsPlatform/Extensions/physics3d.svg'
|
|
1555
|
+
)
|
|
1556
|
+
.addParameter('object', _('Object'), '', false)
|
|
1557
|
+
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
|
|
1558
|
+
.getCodeExtraInformation()
|
|
1559
|
+
.setFunctionName('getMassCenterZ');
|
|
1547
1560
|
}
|
|
1548
1561
|
// Collision
|
|
1549
1562
|
extension
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(n){const g=async()=>{try{const t=(await import("./jolt-physics.wasm.js")).default;if(!t)throw new Error("No default export found in Jolt.");const e=await t();window.Jolt=e}catch(f){throw console.error("Unable to load Jolt physics library.",f),f}};n.registerAsynchronouslyLoadingLibraryPromise(g());class p{constructor(t,e){this._tempVec3=new Jolt.Vec3;this._tempRVec3=new Jolt.RVec3;this._tempQuat=new Jolt.Quat;this.stepped=!1;this._physics3DHooks=[];this._registeredBehaviors=new Set,this.gravityX=e.gravityX,this.gravityY=e.gravityY,this.gravityZ=e.gravityZ,this.worldScale=e.worldScale,this.worldInvScale=1/this.worldScale;const s=new Jolt.JoltSettings;n.Physics3DSharedData.setupCollisionFiltering(s),this.jolt=new Jolt.JoltInterface(s),Jolt.destroy(s),this.physicsSystem=this.jolt.GetPhysicsSystem(),this.physicsSystem.SetGravity(this.getVec3(this.gravityX,this.gravityY,this.gravityZ)),this.bodyInterface=this.physicsSystem.GetBodyInterface(),this.contactListener=new Jolt.ContactListenerJS,this.physicsSystem.SetContactListener(this.contactListener),this.contactListener.OnContactAdded=(i,o,a,r)=>{const l=Jolt.wrapPointer(i,Jolt.Body),c=Jolt.wrapPointer(o,Jolt.Body),d=l.gdjsAssociatedBehavior,h=c.gdjsAssociatedBehavior;!d||!h||(d.onContactBegin(h),h.onContactBegin(d))},this.contactListener.OnContactRemoved=i=>{const o=Jolt.wrapPointer(i,Jolt.SubShapeIDPair),a=this.physicsSystem.GetBodyLockInterface(),r=a.TryGetBody(o.GetBody1ID()),l=a.TryGetBody(o.GetBody2ID()),c=r.gdjsAssociatedBehavior,d=l.gdjsAssociatedBehavior;!c||!d||(c.onContactEnd(d),d.onContactEnd(c))},this.contactListener.OnContactPersisted=(i,o,a,r)=>{},this.contactListener.OnContactValidate=(i,o,a,r)=>Jolt.ValidateResult_AcceptAllContactsForThisBodyPair}getVec3(t,e,s){const i=this._tempVec3;return i.Set(t,e,s),i}getRVec3(t,e,s){const i=this._tempRVec3;return i.Set(t,e,s),i}getQuat(t,e,s,i){const o=this._tempQuat;return o.Set(t,e,s,i),o}static getSharedData(t,e){if(!t.physics3DSharedData){const s=t.getInitialSharedDataForBehavior(e);t.physics3DSharedData=new n.Physics3DSharedData(t,s)}return t.physics3DSharedData}static setupCollisionFiltering(t){const e=new Jolt.ObjectLayerPairFilterMask,s=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.staticBroadPhaseLayerIndex),i=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.dynamicBroadPhaseLayerIndex),o=new Jolt.BroadPhaseLayerInterfaceMask(2);o.ConfigureLayer(s,n.Physics3DSharedData.staticLayersMask,0),o.ConfigureLayer(i,n.Physics3DSharedData.dynamicLayersMask,0),Jolt.destroy(s),Jolt.destroy(i),t.mObjectLayerPairFilter=e,t.mBroadPhaseLayerInterface=o,t.mObjectVsBroadPhaseLayerFilter=new Jolt.ObjectVsBroadPhaseLayerFilterMask(o)}addToBehaviorsList(t){this._registeredBehaviors.add(t)}removeFromBehaviorsList(t){this._registeredBehaviors.delete(t)}step(t){for(const s of this._registeredBehaviors)s._contactsStartedThisFrame.length=0,s._contactsEndedThisFrame.length=0;for(const s of this._registeredBehaviors)s.updateBodyFromObject();for(const s of this._physics3DHooks)s.doBeforePhysicsStep(t);const e=t>1/55?2:1;this.jolt.Step(t,e),this.stepped=!0;for(const s of this._registeredBehaviors)s.updateObjectFromBody()}registerHook(t){this._physics3DHooks.push(t)}}p.staticLayersMask=15,p.dynamicLayersMask=240,p.allLayersMask=255,p.staticBroadPhaseLayerIndex=1,p.dynamicBroadPhaseLayerIndex=1,n.Physics3DSharedData=p,n.registerRuntimeSceneUnloadedCallback(function(f){const t=f.physics3DSharedData;t&&(Jolt.destroy(t.contactListener),Jolt.destroy(t._tempVec3),Jolt.destroy(t._tempRVec3),Jolt.destroy(t._tempQuat),Jolt.destroy(t.jolt),f.physics3DSharedData=null)});class _ extends n.RuntimeBehavior{constructor(t,e,s){super(t,e,s);this.shapeScale=1;this._contactsStartedThisFrame=[];this._contactsEndedThisFrame=[];this._currentContacts=[];this._destroyedDuringFrameLogic=!1;this._body=null;this._needToRecreateBody=!1;this._needToRecreateShape=!1;this._shapeHalfWidth=0;this._shapeHalfHeight=0;this._shapeHalfDepth=0;this._objectOldX=0;this._objectOldY=0;this._objectOldZ=0;this._objectOldRotationX=0;this._objectOldRotationY=0;this._objectOldRotationZ=0;this._objectOldWidth=0;this._objectOldHeight=0;this._objectOldDepth=0;this.bodyUpdater=new n.Physics3DRuntimeBehavior.DefaultBodyUpdater(this),this.collisionChecker=new n.Physics3DRuntimeBehavior.DefaultCollisionChecker(this),this.owner3D=s,this.bodyType=e.bodyType,this.bullet=e.bullet,this.fixedRotation=e.fixedRotation,this.shape=e.shape,this.shapeOrientation=e.shape==="Box"?"Z":e.shapeOrientation,this.shapeDimensionA=e.shapeDimensionA,this.shapeDimensionB=e.shapeDimensionB,this.shapeDimensionC=e.shapeDimensionC,this.shapeOffsetX=e.shapeOffsetX||0,this.shapeOffsetY=e.shapeOffsetY||0,this.shapeOffsetZ=e.shapeOffsetZ||0,this.massCenterOffsetX=e.massCenterOffsetX||0,this.massCenterOffsetY=e.massCenterOffsetY||0,this.massCenterOffsetZ=e.massCenterOffsetZ||0,this.density=e.density,this.massOverride=e.massOverride||0,this.friction=e.friction,this.restitution=e.restitution,this.linearDamping=Math.max(0,e.linearDamping),this.angularDamping=Math.max(0,e.angularDamping),this.gravityScale=e.gravityScale,this.layers=e.layers,this.masks=e.masks,this._sharedData=p.getSharedData(t.getScene(),e.name),this._sharedData.addToBehaviorsList(this)}getVec3(t,e,s){const i=this._sharedData._tempVec3;return i.Set(t,e,s),i}getRVec3(t,e,s){const i=this._sharedData._tempRVec3;return i.Set(t,e,s),i}getQuat(t,e,s,i){const o=this._sharedData._tempQuat;return o.Set(t,e,s,i),o}updateFromBehaviorData(t,e){return t.bullet!==e.bullet&&this.setBullet(e.bullet),t.fixedRotation!==e.fixedRotation&&this.setFixedRotation(e.fixedRotation),t.shapeDimensionA!==e.shapeDimensionA&&(this.shapeDimensionA=e.shapeDimensionA,this._needToRecreateShape=!0),t.shapeDimensionB!==e.shapeDimensionB&&(this.shapeDimensionB=e.shapeDimensionB,this._needToRecreateShape=!0),t.density!==e.density&&this.setDensity(e.density),t.friction!==e.friction&&this.setFriction(e.friction),t.restitution!==e.restitution&&this.setRestitution(e.restitution),t.linearDamping!==e.linearDamping&&this.setLinearDamping(e.linearDamping),t.angularDamping!==e.angularDamping&&this.setAngularDamping(e.angularDamping),t.gravityScale!==e.gravityScale&&this.setGravityScale(e.gravityScale),!(t.layers!==e.layers||t.masks!==e.masks||t.vertices!==e.vertices||t.bodyType!==e.bodyType||t.shape!==e.shape)}getNetworkSyncData(){let t;if(this._body){const e=this._body.GetPosition(),s=this._body.GetRotation(),i=this._body.GetLinearVelocity(),o=this._body.GetAngularVelocity();t={px:e.GetX(),py:e.GetY(),pz:e.GetZ(),rx:s.GetX(),ry:s.GetY(),rz:s.GetZ(),rw:s.GetW(),lvx:i.GetX(),lvy:i.GetY(),lvz:i.GetZ(),avx:o.GetX(),avy:o.GetY(),avz:o.GetZ(),aw:this._body.IsActive()}}else t={px:void 0,py:void 0,pz:void 0,rx:void 0,ry:void 0,rz:void 0,rw:void 0,lvx:void 0,lvy:void 0,lvz:void 0,avx:void 0,avy:void 0,avz:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...t,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t);const e=t.props;e.px!==void 0&&e.py!==void 0&&e.pz!==void 0&&this._body&&this._sharedData.bodyInterface.SetPosition(this._body.GetID(),this.getRVec3(e.px,e.py,e.pz),Jolt.EActivation_DontActivate),e.rx!==void 0&&e.ry!==void 0&&e.rz!==void 0&&e.rw!==void 0&&this._body&&this._sharedData.bodyInterface.SetRotation(this._body.GetID(),this.getQuat(e.rx,e.ry,e.rz,e.rw),Jolt.EActivation_DontActivate),e.lvx!==void 0&&e.lvy!==void 0&&e.lvz!==void 0&&this._body&&this._sharedData.bodyInterface.SetLinearVelocity(this._body.GetID(),this.getVec3(e.lvx,e.lvy,e.lvz)),e.avx!==void 0&&e.avy!==void 0&&e.avz!==void 0&&this._body&&this._sharedData.bodyInterface.SetAngularVelocity(this._body.GetID(),this.getVec3(e.avx,e.avy,e.avz)),e.layers!==void 0&&(this.layers=e.layers),e.masks!==void 0&&(this.masks=e.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this.bodyUpdater.destroyBody(),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this._destroyedDuringFrameLogic=!0,this.onDeActivate()}createShape(){if(this.massCenterOffsetX===0&&this.massCenterOffsetY===0&&this.massCenterOffsetZ===0)return this.createShapeWithoutMassCenterOffset();const t=this._createNewShapeSettingsWithoutMassCenterOffset(),e=this.shapeScale*this._sharedData.worldInvScale,s=new Jolt.OffsetCenterOfMassShapeSettings(this.getVec3(this.massCenterOffsetX*e,this.massCenterOffsetY*e,this.massCenterOffsetZ*e),t),i=s.Create().Get();return Jolt.destroy(s),i}createShapeWithoutMassCenterOffset(){const t=this._createNewShapeSettingsWithoutMassCenterOffset(),e=t.Create().Get();return Jolt.destroy(t),e}_createNewShapeSettingsWithoutMassCenterOffset(){let t=this.owner3D.getWidth()*this._sharedData.worldInvScale,e=this.owner3D.getHeight()*this._sharedData.worldInvScale,s=this.owner3D.getDepth()*this._sharedData.worldInvScale;if(this.shapeOrientation==="X"){const h=s;s=t,t=h}else if(this.shapeOrientation==="Y"){const h=s;s=e,e=h}const i=this.shapeScale*this._sharedData.worldInvScale,o=this.shapeDimensionA*i,a=this.shapeDimensionB*i,r=this.shapeDimensionC*i,l=this._sharedData.worldInvScale;let c,d;if(this.shape==="Box"){const h=o>0?o:t>0?t:l,y=a>0?a:e>0?e:l,u=r>0?r:s>0?s:l,b=Math.min(l,Math.min(h,y,u)/4);c=new Jolt.BoxShapeSettings(this.getVec3(h/2,y/2,u/2),b),d=this.getQuat(0,0,0,1),this._shapeHalfWidth=h/2,this._shapeHalfHeight=y/2,this._shapeHalfDepth=u/2}else if(this.shape==="Capsule"){const h=o>0?o:t>0?Math.sqrt(t*e)/2:l,y=a>0?a:s>0?s:l;c=new Jolt.CapsuleShapeSettings(Math.max(0,y/2-h),h),d=this._getShapeOrientationQuat(),this._shapeHalfWidth=this.shapeOrientation==="X"?y/2:h,this._shapeHalfHeight=this.shapeOrientation==="Y"?y/2:h,this._shapeHalfDepth=this.shapeOrientation==="Z"?y/2:h}else if(this.shape==="Cylinder"){const h=o>0?o:t>0?Math.sqrt(t*e)/2:l,y=a>0?a:s>0?s:l,u=Math.min(l,Math.min(y,h)/4);c=new Jolt.CylinderShapeSettings(y/2,h,u),d=this._getShapeOrientationQuat(),this._shapeHalfWidth=this.shapeOrientation==="X"?y/2:h,this._shapeHalfHeight=this.shapeOrientation==="Y"?y/2:h,this._shapeHalfDepth=this.shapeOrientation==="Z"?y/2:h}else{const h=o>0?o:t>0?Math.pow(t*e*s,1/3)/2:l;c=new Jolt.SphereShapeSettings(h),d=this.getQuat(0,0,0,1),this._shapeHalfWidth=h,this._shapeHalfHeight=h,this._shapeHalfDepth=h}return c.mDensity=this.density,new Jolt.RotatedTranslatedShapeSettings(this.getVec3(this.shapeOffsetX*i,this.shapeOffsetY*i,this.shapeOffsetZ*i),d,c)}_getShapeOrientationQuat(){return this.shapeOrientation==="X"?this.getQuat(0,0,Math.sqrt(2)/2,-Math.sqrt(2)/2):this.shapeOrientation==="Y"?this.getQuat(0,0,0,1):this.getQuat(Math.sqrt(2)/2,0,0,Math.sqrt(2)/2)}_recreateShape(){this.bodyUpdater.recreateShape(),this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth()}getShapeScale(){return this.shapeScale}setShapeScale(t){t!==this.shapeScale&&t>0&&(this.shapeScale=t,this._needToRecreateShape=!0)}getBody(){return this._body===null&&this._createBody(),this._body}_createBody(){return this._needToRecreateBody=!1,this._needToRecreateShape=!1,!this.activated()||this._destroyedDuringFrameLogic||(this._body=this.bodyUpdater.createAndAddBody(),!this._body)?!1:(this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth(),!0)}getBodyLayer(){return Jolt.ObjectLayerPairFilterMask.prototype.sGetObjectLayer(this.getLayersAccordingToBodyType(),this.getMasksAccordingToBodyType())}getLayersAccordingToBodyType(){return this.isStatic()?this.layers&n.Physics3DSharedData.staticLayersMask:this.layers&n.Physics3DSharedData.dynamicLayersMask}getMasksAccordingToBodyType(){return this.isStatic()?n.Physics3DSharedData.allLayersMask:this.masks}doStepPreEvents(t){!this._sharedData.stepped&&!t.getScene().getTimeManager().isFirstFrame()&&this._sharedData.step(t.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(t){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}recreateBody(){if(!this._body){this._createBody();return}const t=this._sharedData.bodyInterface,e=this._body.GetLinearVelocity(),s=e.GetX(),i=e.GetY(),o=e.GetZ(),a=this._body.GetAngularVelocity(),r=a.GetX(),l=a.GetY(),c=a.GetZ();let d=this._body.GetID();t.RemoveBody(d),t.DestroyBody(d),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this._createBody(),!!this._body&&(d=this._body.GetID(),t.SetLinearVelocity(d,this.getVec3(s,i,o)),t.SetAngularVelocity(d,this.getVec3(r,l,c)))}updateObjectFromBody(){this.bodyUpdater.updateObjectFromBody(),this._objectOldX=this.owner3D.getX(),this._objectOldY=this.owner3D.getY(),this._objectOldZ=this.owner3D.getZ(),this._objectOldRotationX=this.owner3D.getRotationX(),this._objectOldRotationY=this.owner3D.getRotationY(),this._objectOldRotationZ=this.owner3D.getAngle()}updateBodyFromObject(){this._body===null&&!this._createBody()||(this._needToRecreateBody&&this.recreateBody(),(this._needToRecreateShape||!this.hasCustomShapeDimension()&&(this._objectOldWidth!==this.owner3D.getWidth()||this._objectOldHeight!==this.owner3D.getHeight()||this._objectOldDepth!==this.owner3D.getDepth()))&&(this._needToRecreateShape=!1,this._recreateShape()),this.bodyUpdater.updateBodyFromObject())}hasCustomShapeDimension(){return this.shapeDimensionA>0||this.shapeDimensionB>0||this.shapeDimensionC>0}_getPhysicsPosition(t){return t.Set(this.owner3D.getCenterXInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterYInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterZInScene()*this._sharedData.worldInvScale),t}_getPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();return t.Set(e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w),t}_moveObjectToPhysicsPosition(t){this.owner3D.setCenterXInScene(t.GetX()*this._sharedData.worldScale),this.owner3D.setCenterYInScene(t.GetY()*this._sharedData.worldScale),this.owner3D.setCenterZInScene(t.GetZ()*this._sharedData.worldScale)}_moveObjectToPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();e.quaternion.x=t.GetX(),e.quaternion.y=t.GetY(),e.quaternion.z=t.GetZ(),e.quaternion.w=t.GetW();const s=new THREE.Euler(0,0,0,"ZYX");s.setFromQuaternion(e.quaternion),this.owner3D.setRotationX(n.toDegrees(s.x)),this.owner3D.setRotationY(n.toDegrees(s.y)),this.owner3D.setAngle(n.toDegrees(s.z))}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}getGravityZ(){return this._sharedData.gravityZ}setGravityX(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityY(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityZ(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityZ=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}isDynamic(){return this.bodyType==="Dynamic"}isStatic(){return this.bodyType==="Static"}isKinematic(){return this.bodyType==="Kinematic"}isBullet(){return this.bullet}setBullet(t){if(this.bullet===t||(this.bullet=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetMotionQuality(e.GetID(),this.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(t){this.fixedRotation!==t&&(this.fixedRotation=t,this._needToRecreateBody=!0)}getDensity(){return this.density}setDensity(t){t<0&&(t=0),this.density!==t&&(this.density=t,this._needToRecreateShape=!0)}getMassOverride(){return this.massOverride}setMassOverride(t){this.massOverride!==t&&(this.massOverride=t,this._needToRecreateBody=!0)}getFriction(){return this.friction}setFriction(t){if(t<0&&(t=0),this.friction===t||(this.friction=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetFriction(e.GetID(),t)}getRestitution(){return this.restitution}setRestitution(t){if(t<0&&(t=0),this.restitution===t||(this.restitution=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetRestitution(e.GetID(),t)}getLinearDamping(){return this.linearDamping}setLinearDamping(t){if(t<0&&(t=0),this.linearDamping===t||(this.linearDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetLinearDamping(t)}getAngularDamping(){return this.angularDamping}setAngularDamping(t){if(t<0&&(t=0),this.angularDamping===t||(this.angularDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetAngularDamping(t)}getGravityScale(){return this.gravityScale}setGravityScale(t){if(this.gravityScale===t||(this.gravityScale=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetGravityFactor(t)}layerEnabled(t){return t=Math.floor(t),t<1||t>8?!1:!!(this.layers&1<<t-1)}enableLayer(t,e){t=Math.floor(t),!(t<1||t>8)&&(e?this.layers|=1<<t-1:this.layers&=~(1<<t-1),this._needToRecreateBody=!0)}maskEnabled(t){return t=Math.floor(t),t<1||t>16?!1:!!(this.masks&1<<t-1)}enableMask(t,e){t=Math.floor(t),!(t<1||t>16)&&(e?this.masks|=1<<t-1:this.masks&=~(1<<t-1),this._needToRecreateBody=!0)}getLinearVelocityX(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetX()*this._sharedData.worldScale}setLinearVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetY(),e.GetLinearVelocity().GetZ()))}getLinearVelocityY(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetY()*this._sharedData.worldScale}setLinearVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetZ()))}getLinearVelocityZ(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetZ()*this._sharedData.worldScale}setLinearVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),e.GetLinearVelocity().GetY(),t*this._sharedData.worldInvScale))}getLinearVelocityLength(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().Length()*this._sharedData.worldScale}getAngularVelocityX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetX())}setAngularVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(n.toRad(t),e.GetAngularVelocity().GetY(),e.GetAngularVelocity().GetZ()))}getAngularVelocityY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetY())}setAngularVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),n.toRad(t),e.GetAngularVelocity().GetZ()))}getAngularVelocityZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetZ())}setAngularVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),e.GetAngularVelocity().GetY(),n.toRad(t)))}applyForce(t,e,s,i,o,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddForce(r.GetID(),this.getVec3(t,e,s),this.getRVec3(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale),Jolt.EActivation_Activate)}applyForceAtCenter(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddForce(i.GetID(),this.getVec3(t,e,s),Jolt.EActivation_Activate)}applyForceTowardPosition(t,e,s,i){if(this._body===null&&!this._createBody())return;const o=this._body,a=e-o.GetPosition().GetX(),r=s-o.GetPosition().GetY(),l=i-o.GetPosition().GetZ(),c=a*a+r*r+l*l;if(c===0)return;const d=t/Math.sqrt(c);this._sharedData.bodyInterface.AddForce(o.GetID(),this.getVec3(a*d,r*d,l*d),Jolt.EActivation_Activate)}applyImpulse(t,e,s,i,o,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddImpulse(r.GetID(),this.getVec3(t,e,s),this.getRVec3(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale))}applyImpulseAtCenter(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddImpulse(i.GetID(),this.getVec3(t,e,s))}applyImpulseTowardPosition(t,e,s,i,o,a,r){if(this._body===null&&!this._createBody())return;const l=this._body,c=e-o,d=s-a,h=i-r,y=c*c+d*d+h*h;if(y===0)return;const u=t/Math.sqrt(y);this._sharedData.bodyInterface.AddImpulse(l.GetID(),this.getVec3(c*u,d*u,h*u),this.getRVec3(o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale,r*this._sharedData.worldInvScale))}applyTorque(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddTorque(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(s)),Jolt.EActivation_Activate)}applyAngularImpulse(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddAngularImpulse(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(s)))}getMass(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseMass()}getInertiaAroundX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetX()}getInertiaAroundY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetY()}getInertiaAroundZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetZ()}getMassCenterX(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetX()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetY()*this._sharedData.worldScale}getMassCenterZ(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetZ()*this._sharedData.worldScale}onContactBegin(t){this._currentContacts.push(t);let e=this._contactsEndedThisFrame.indexOf(t);e!==-1?this._contactsEndedThisFrame.splice(e,1):this._contactsStartedThisFrame.push(t)}onContactEnd(t){this._contactsEndedThisFrame.push(t);const e=this._currentContacts.indexOf(t);e!==-1&&this._currentContacts.splice(e,1)}canCollideAgainst(t){return(this.getMasksAccordingToBodyType()&t.getLayersAccordingToBodyType())!=0}static areObjectsColliding(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.isColliding(e):!1}static hasCollisionStartedBetween(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.hasCollisionStartedWith(e):!1}static hasCollisionStoppedBetween(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.hasCollisionStoppedWith(e):!1}}n.Physics3DRuntimeBehavior=_,n.registerBehavior("Physics3D::Physics3DBehavior",n.Physics3DRuntimeBehavior),function(e){class f{constructor(i){this.behavior=i}createAndAddBody(){const{behavior:i}=this,{_sharedData:o}=i,a=i.createShape(),r=new Jolt.BodyCreationSettings(a,i._getPhysicsPosition(o.getRVec3(0,0,0)),i._getPhysicsRotation(o.getQuat(0,0,0,1)),i.bodyType==="Static"?Jolt.EMotionType_Static:i.bodyType==="Kinematic"?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic,i.getBodyLayer());r.mMotionQuality=i.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete,r.mAllowedDOFs=i.fixedRotation?Jolt.EAllowedDOFs_TranslationX|Jolt.EAllowedDOFs_TranslationY|Jolt.EAllowedDOFs_TranslationZ:Jolt.EAllowedDOFs_All,r.mFriction=i.friction,r.mRestitution=i.restitution,r.mLinearDamping=i.linearDamping,r.mAngularDamping=i.angularDamping,r.mGravityFactor=i.gravityScale,i.massOverride>0&&(r.mOverrideMassProperties=Jolt.EOverrideMassProperties_CalculateInertia,r.mMassPropertiesOverride.mMass=i.massOverride);const l=o.bodyInterface,c=l.CreateBody(r);return Jolt.destroy(r),l.AddBody(c.GetID(),Jolt.EActivation_Activate),c}updateObjectFromBody(){const{behavior:i}=this,{_body:o}=i;o!==null&&o.IsActive()&&(i._moveObjectToPhysicsPosition(o.GetPosition()),i._moveObjectToPhysicsRotation(o.GetRotation()))}updateBodyFromObject(){const{behavior:i}=this,{owner3D:o,_sharedData:a}=i;if(i._body===null&&!i._createBody())return;const r=i._body;(this.behavior._objectOldX!==o.getX()||this.behavior._objectOldY!==o.getY()||this.behavior._objectOldZ!==o.getZ()||this.behavior._objectOldRotationX!==o.getRotationX()||this.behavior._objectOldRotationY!==o.getRotationY()||this.behavior._objectOldRotationZ!==o.getAngle())&&a.bodyInterface.SetPositionAndRotationWhenChanged(r.GetID(),this.behavior._getPhysicsPosition(a.getRVec3(0,0,0)),this.behavior._getPhysicsRotation(a.getQuat(0,0,0,1)),Jolt.EActivation_Activate)}recreateShape(){const{behavior:i}=this,{_sharedData:o}=i;if(i._body===null&&!i._createBody())return;const a=i._body;o.bodyInterface.SetShape(a.GetID(),i.createShape(),!0,Jolt.EActivation_Activate)}destroyBody(){const{behavior:i}=this,{_sharedData:o}=i;i._body!==null&&(o.bodyInterface.RemoveBody(i._body.GetID()),o.bodyInterface.DestroyBody(i._body.GetID()),i._body=null)}}e.DefaultBodyUpdater=f;class t{constructor(i){this.behavior=i}isColliding(i){return this.behavior._currentContacts.some(o=>o.owner===i)?!0:this.behavior._contactsStartedThisFrame.some(o=>o.owner===i)}hasCollisionStartedWith(i){return this.behavior._contactsStartedThisFrame.some(o=>o.owner===i)}hasCollisionStoppedWith(i){return this.behavior._contactsEndedThisFrame.some(o=>o.owner===i)}}e.DefaultCollisionChecker=t}(_=n.Physics3DRuntimeBehavior||(n.Physics3DRuntimeBehavior={}))})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(n){const g=async()=>{try{const t=(await import("./jolt-physics.wasm.js")).default;if(!t)throw new Error("No default export found in Jolt.");const e=await t();window.Jolt=e}catch(f){throw console.error("Unable to load Jolt physics library.",f),f}};n.registerAsynchronouslyLoadingLibraryPromise(g());class p{constructor(t,e){this._tempVec3=new Jolt.Vec3;this._tempRVec3=new Jolt.RVec3;this._tempQuat=new Jolt.Quat;this.stepped=!1;this._physics3DHooks=[];this._registeredBehaviors=new Set,this.gravityX=e.gravityX,this.gravityY=e.gravityY,this.gravityZ=e.gravityZ,this.worldScale=e.worldScale,this.worldInvScale=1/this.worldScale;const s=new Jolt.JoltSettings;n.Physics3DSharedData.setupCollisionFiltering(s),this.jolt=new Jolt.JoltInterface(s),Jolt.destroy(s),this.physicsSystem=this.jolt.GetPhysicsSystem(),this.physicsSystem.SetGravity(this.getVec3(this.gravityX,this.gravityY,this.gravityZ)),this.bodyInterface=this.physicsSystem.GetBodyInterface(),this.contactListener=new Jolt.ContactListenerJS,this.physicsSystem.SetContactListener(this.contactListener),this.contactListener.OnContactAdded=(i,o,a,r)=>{const d=Jolt.wrapPointer(i,Jolt.Body),l=Jolt.wrapPointer(o,Jolt.Body),c=d.gdjsAssociatedBehavior,h=l.gdjsAssociatedBehavior;!c||!h||(c.onContactBegin(h),h.onContactBegin(c))},this.contactListener.OnContactRemoved=i=>{const o=Jolt.wrapPointer(i,Jolt.SubShapeIDPair),a=this.physicsSystem.GetBodyLockInterface(),r=a.TryGetBody(o.GetBody1ID()),d=a.TryGetBody(o.GetBody2ID()),l=r.gdjsAssociatedBehavior,c=d.gdjsAssociatedBehavior;!l||!c||(l.onContactEnd(c),c.onContactEnd(l))},this.contactListener.OnContactPersisted=(i,o,a,r)=>{},this.contactListener.OnContactValidate=(i,o,a,r)=>Jolt.ValidateResult_AcceptAllContactsForThisBodyPair}getVec3(t,e,s){const i=this._tempVec3;return i.Set(t,e,s),i}getRVec3(t,e,s){const i=this._tempRVec3;return i.Set(t,e,s),i}getQuat(t,e,s,i){const o=this._tempQuat;return o.Set(t,e,s,i),o}static getSharedData(t,e){if(!t.physics3DSharedData){const s=t.getInitialSharedDataForBehavior(e);t.physics3DSharedData=new n.Physics3DSharedData(t,s)}return t.physics3DSharedData}static setupCollisionFiltering(t){const e=new Jolt.ObjectLayerPairFilterMask,s=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.staticBroadPhaseLayerIndex),i=new Jolt.BroadPhaseLayer(n.Physics3DSharedData.dynamicBroadPhaseLayerIndex),o=new Jolt.BroadPhaseLayerInterfaceMask(2);o.ConfigureLayer(s,n.Physics3DSharedData.staticLayersMask,0),o.ConfigureLayer(i,n.Physics3DSharedData.dynamicLayersMask,0),Jolt.destroy(s),Jolt.destroy(i),t.mObjectLayerPairFilter=e,t.mBroadPhaseLayerInterface=o,t.mObjectVsBroadPhaseLayerFilter=new Jolt.ObjectVsBroadPhaseLayerFilterMask(o)}addToBehaviorsList(t){this._registeredBehaviors.add(t)}removeFromBehaviorsList(t){this._registeredBehaviors.delete(t)}step(t){for(const s of this._registeredBehaviors)s._contactsStartedThisFrame.length=0,s._contactsEndedThisFrame.length=0;for(const s of this._registeredBehaviors)s.updateBodyFromObject();for(const s of this._physics3DHooks)s.doBeforePhysicsStep(t);const e=t>1/55?2:1;this.jolt.Step(t,e),this.stepped=!0;for(const s of this._registeredBehaviors)s.updateObjectFromBody()}registerHook(t){this._physics3DHooks.push(t)}}p.staticLayersMask=15,p.dynamicLayersMask=240,p.allLayersMask=255,p.staticBroadPhaseLayerIndex=1,p.dynamicBroadPhaseLayerIndex=1,n.Physics3DSharedData=p,n.registerRuntimeSceneUnloadedCallback(function(f){const t=f.physics3DSharedData;t&&(Jolt.destroy(t.contactListener),Jolt.destroy(t._tempVec3),Jolt.destroy(t._tempRVec3),Jolt.destroy(t._tempQuat),Jolt.destroy(t.jolt),f.physics3DSharedData=null)});class _ extends n.RuntimeBehavior{constructor(t,e,s){super(t,e,s);this.shapeScale=1;this._contactsStartedThisFrame=[];this._contactsEndedThisFrame=[];this._currentContacts=[];this._destroyedDuringFrameLogic=!1;this._body=null;this._needToRecreateBody=!1;this._needToRecreateShape=!1;this._shapeHalfWidth=0;this._shapeHalfHeight=0;this._shapeHalfDepth=0;this._objectOldX=0;this._objectOldY=0;this._objectOldZ=0;this._objectOldRotationX=0;this._objectOldRotationY=0;this._objectOldRotationZ=0;this._objectOldWidth=0;this._objectOldHeight=0;this._objectOldDepth=0;this.bodyUpdater=new n.Physics3DRuntimeBehavior.DefaultBodyUpdater(this),this.collisionChecker=new n.Physics3DRuntimeBehavior.DefaultCollisionChecker(this),this.owner3D=s,this.bodyType=e.bodyType,this.bullet=e.bullet,this.fixedRotation=e.fixedRotation,this.shape=e.shape,this.shapeOrientation=e.shape==="Box"?"Z":e.shapeOrientation,this.shapeDimensionA=e.shapeDimensionA,this.shapeDimensionB=e.shapeDimensionB,this.shapeDimensionC=e.shapeDimensionC,this.shapeOffsetX=e.shapeOffsetX||0,this.shapeOffsetY=e.shapeOffsetY||0,this.shapeOffsetZ=e.shapeOffsetZ||0,this.massCenterOffsetX=e.massCenterOffsetX||0,this.massCenterOffsetY=e.massCenterOffsetY||0,this.massCenterOffsetZ=e.massCenterOffsetZ||0,this.density=e.density,this.massOverride=e.massOverride||0,this.friction=e.friction,this.restitution=e.restitution,this.linearDamping=Math.max(0,e.linearDamping),this.angularDamping=Math.max(0,e.angularDamping),this.gravityScale=e.gravityScale,this.layers=e.layers,this.masks=e.masks,this._sharedData=p.getSharedData(t.getScene(),e.name),this._sharedData.addToBehaviorsList(this)}getVec3(t,e,s){const i=this._sharedData._tempVec3;return i.Set(t,e,s),i}getRVec3(t,e,s){const i=this._sharedData._tempRVec3;return i.Set(t,e,s),i}getQuat(t,e,s,i){const o=this._sharedData._tempQuat;return o.Set(t,e,s,i),o}updateFromBehaviorData(t,e){return t.bullet!==e.bullet&&this.setBullet(e.bullet),t.fixedRotation!==e.fixedRotation&&this.setFixedRotation(e.fixedRotation),t.shapeDimensionA!==e.shapeDimensionA&&(this.shapeDimensionA=e.shapeDimensionA,this._needToRecreateShape=!0),t.shapeDimensionB!==e.shapeDimensionB&&(this.shapeDimensionB=e.shapeDimensionB,this._needToRecreateShape=!0),t.density!==e.density&&this.setDensity(e.density),t.friction!==e.friction&&this.setFriction(e.friction),t.restitution!==e.restitution&&this.setRestitution(e.restitution),t.linearDamping!==e.linearDamping&&this.setLinearDamping(e.linearDamping),t.angularDamping!==e.angularDamping&&this.setAngularDamping(e.angularDamping),t.gravityScale!==e.gravityScale&&this.setGravityScale(e.gravityScale),!(t.layers!==e.layers||t.masks!==e.masks||t.vertices!==e.vertices||t.bodyType!==e.bodyType||t.shape!==e.shape)}getNetworkSyncData(){let t;if(this._body){const e=this._body.GetPosition(),s=this._body.GetRotation(),i=this._body.GetLinearVelocity(),o=this._body.GetAngularVelocity();t={px:e.GetX(),py:e.GetY(),pz:e.GetZ(),rx:s.GetX(),ry:s.GetY(),rz:s.GetZ(),rw:s.GetW(),lvx:i.GetX(),lvy:i.GetY(),lvz:i.GetZ(),avx:o.GetX(),avy:o.GetY(),avz:o.GetZ(),aw:this._body.IsActive()}}else t={px:void 0,py:void 0,pz:void 0,rx:void 0,ry:void 0,rz:void 0,rw:void 0,lvx:void 0,lvy:void 0,lvz:void 0,avx:void 0,avy:void 0,avz:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...t,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t);const e=t.props;e.px!==void 0&&e.py!==void 0&&e.pz!==void 0&&this._body&&this._sharedData.bodyInterface.SetPosition(this._body.GetID(),this.getRVec3(e.px,e.py,e.pz),Jolt.EActivation_DontActivate),e.rx!==void 0&&e.ry!==void 0&&e.rz!==void 0&&e.rw!==void 0&&this._body&&this._sharedData.bodyInterface.SetRotation(this._body.GetID(),this.getQuat(e.rx,e.ry,e.rz,e.rw),Jolt.EActivation_DontActivate),e.lvx!==void 0&&e.lvy!==void 0&&e.lvz!==void 0&&this._body&&this._sharedData.bodyInterface.SetLinearVelocity(this._body.GetID(),this.getVec3(e.lvx,e.lvy,e.lvz)),e.avx!==void 0&&e.avy!==void 0&&e.avz!==void 0&&this._body&&this._sharedData.bodyInterface.SetAngularVelocity(this._body.GetID(),this.getVec3(e.avx,e.avy,e.avz)),e.layers!==void 0&&(this.layers=e.layers),e.masks!==void 0&&(this.masks=e.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this.bodyUpdater.destroyBody(),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this._destroyedDuringFrameLogic=!0,this.onDeActivate()}createShape(){if(this.massCenterOffsetX===0&&this.massCenterOffsetY===0&&this.massCenterOffsetZ===0)return this.createShapeWithoutMassCenterOffset();const t=this._createNewShapeSettingsWithoutMassCenterOffset(),e=this.shapeScale*this._sharedData.worldInvScale,s=new Jolt.OffsetCenterOfMassShapeSettings(this.getVec3(this.massCenterOffsetX*e,this.massCenterOffsetY*e,this.massCenterOffsetZ*e),t),i=s.Create().Get();return Jolt.destroy(s),i}createShapeWithoutMassCenterOffset(){const t=this._createNewShapeSettingsWithoutMassCenterOffset(),e=t.Create().Get();return Jolt.destroy(t),e}_createNewShapeSettingsWithoutMassCenterOffset(){let t=this.owner3D.getWidth()*this._sharedData.worldInvScale,e=this.owner3D.getHeight()*this._sharedData.worldInvScale,s=this.owner3D.getDepth()*this._sharedData.worldInvScale;if(this.shapeOrientation==="X"){const h=s;s=t,t=h}else if(this.shapeOrientation==="Y"){const h=s;s=e,e=h}const i=this.shapeScale*this._sharedData.worldInvScale,o=this.shapeDimensionA*i,a=this.shapeDimensionB*i,r=this.shapeDimensionC*i,d=this._sharedData.worldInvScale;let l,c;if(this.shape==="Box"){const h=o>0?o:t>0?t:d,y=a>0?a:e>0?e:d,u=r>0?r:s>0?s:d,b=Math.min(d,Math.min(h,y,u)/4);l=new Jolt.BoxShapeSettings(this.getVec3(h/2,y/2,u/2),b),c=this.getQuat(0,0,0,1),this._shapeHalfWidth=h/2,this._shapeHalfHeight=y/2,this._shapeHalfDepth=u/2}else if(this.shape==="Capsule"){const h=o>0?o:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:s>0?s:d;l=new Jolt.CapsuleShapeSettings(Math.max(0,y/2-h),h),c=this._getShapeOrientationQuat(),this._shapeHalfWidth=this.shapeOrientation==="X"?y/2:h,this._shapeHalfHeight=this.shapeOrientation==="Y"?y/2:h,this._shapeHalfDepth=this.shapeOrientation==="Z"?y/2:h}else if(this.shape==="Cylinder"){const h=o>0?o:t>0?Math.sqrt(t*e)/2:d,y=a>0?a:s>0?s:d,u=Math.min(d,Math.min(y,h)/4);l=new Jolt.CylinderShapeSettings(y/2,h,u),c=this._getShapeOrientationQuat(),this._shapeHalfWidth=this.shapeOrientation==="X"?y/2:h,this._shapeHalfHeight=this.shapeOrientation==="Y"?y/2:h,this._shapeHalfDepth=this.shapeOrientation==="Z"?y/2:h}else{const h=o>0?o:t>0?Math.pow(t*e*s,1/3)/2:d;l=new Jolt.SphereShapeSettings(h),c=this.getQuat(0,0,0,1),this._shapeHalfWidth=h,this._shapeHalfHeight=h,this._shapeHalfDepth=h}return l.mDensity=this.density,new Jolt.RotatedTranslatedShapeSettings(this.getVec3(this.shapeOffsetX*i,this.shapeOffsetY*i,this.shapeOffsetZ*i),c,l)}_getShapeOrientationQuat(){return this.shapeOrientation==="X"?this.getQuat(0,0,Math.sqrt(2)/2,-Math.sqrt(2)/2):this.shapeOrientation==="Y"?this.getQuat(0,0,0,1):this.getQuat(Math.sqrt(2)/2,0,0,Math.sqrt(2)/2)}_recreateShape(){this.bodyUpdater.recreateShape(),this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth()}getShapeScale(){return this.shapeScale}setShapeScale(t){t!==this.shapeScale&&t>0&&(this.shapeScale=t,this._needToRecreateShape=!0)}getBody(){return this._body===null&&this._createBody(),this._body}_createBody(){return this._needToRecreateBody=!1,this._needToRecreateShape=!1,!this.activated()||this._destroyedDuringFrameLogic||(this._body=this.bodyUpdater.createAndAddBody(),!this._body)?!1:(this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner3D.getWidth(),this._objectOldHeight=this.owner3D.getHeight(),this._objectOldDepth=this.owner3D.getDepth(),!0)}getBodyLayer(){return Jolt.ObjectLayerPairFilterMask.prototype.sGetObjectLayer(this.getLayersAccordingToBodyType(),this.getMasksAccordingToBodyType())}getLayersAccordingToBodyType(){return this.isStatic()?this.layers&n.Physics3DSharedData.staticLayersMask:this.layers&n.Physics3DSharedData.dynamicLayersMask}getMasksAccordingToBodyType(){return this.isStatic()?n.Physics3DSharedData.allLayersMask:this.masks}doStepPreEvents(t){!this._sharedData.stepped&&!t.getScene().getTimeManager().isFirstFrame()&&this._sharedData.step(t.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(t){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}recreateBody(){if(!this._body){this._createBody();return}const t=this._sharedData.bodyInterface,e=this._body.GetLinearVelocity(),s=e.GetX(),i=e.GetY(),o=e.GetZ(),a=this._body.GetAngularVelocity(),r=a.GetX(),d=a.GetY(),l=a.GetZ();if(this.bodyUpdater.destroyBody(),this._contactsEndedThisFrame.length=0,this._contactsStartedThisFrame.length=0,this._currentContacts.length=0,this._createBody(),!this._body)return;const c=this._body.GetID();t.SetLinearVelocity(c,this.getVec3(s,i,o)),t.SetAngularVelocity(c,this.getVec3(r,d,l))}updateObjectFromBody(){this.bodyUpdater.updateObjectFromBody(),this._objectOldX=this.owner3D.getX(),this._objectOldY=this.owner3D.getY(),this._objectOldZ=this.owner3D.getZ(),this._objectOldRotationX=this.owner3D.getRotationX(),this._objectOldRotationY=this.owner3D.getRotationY(),this._objectOldRotationZ=this.owner3D.getAngle()}updateBodyFromObject(){this._body===null&&!this._createBody()||(this._needToRecreateBody&&this.recreateBody(),(this._needToRecreateShape||!this.hasCustomShapeDimension()&&(this._objectOldWidth!==this.owner3D.getWidth()||this._objectOldHeight!==this.owner3D.getHeight()||this._objectOldDepth!==this.owner3D.getDepth()))&&(this._needToRecreateShape=!1,this._recreateShape()),this.bodyUpdater.updateBodyFromObject())}hasCustomShapeDimension(){return this.shapeDimensionA>0||this.shapeDimensionB>0||this.shapeDimensionC>0}_getPhysicsPosition(t){return t.Set(this.owner3D.getCenterXInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterYInScene()*this._sharedData.worldInvScale,this.owner3D.getCenterZInScene()*this._sharedData.worldInvScale),t}_getPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();return t.Set(e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w),t}_moveObjectToPhysicsPosition(t){this.owner3D.setCenterXInScene(t.GetX()*this._sharedData.worldScale),this.owner3D.setCenterYInScene(t.GetY()*this._sharedData.worldScale),this.owner3D.setCenterZInScene(t.GetZ()*this._sharedData.worldScale)}_moveObjectToPhysicsRotation(t){const e=this.owner3D.get3DRendererObject();e.quaternion.x=t.GetX(),e.quaternion.y=t.GetY(),e.quaternion.z=t.GetZ(),e.quaternion.w=t.GetW();const s=new THREE.Euler(0,0,0,"ZYX");s.setFromQuaternion(e.quaternion),this.owner3D.setRotationX(n.toDegrees(s.x)),this.owner3D.setRotationY(n.toDegrees(s.y)),this.owner3D.setAngle(n.toDegrees(s.z))}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}getGravityZ(){return this._sharedData.gravityZ}setGravityX(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityY(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityX=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}setGravityZ(t){this._sharedData.gravityX!==t&&(this._sharedData.gravityZ=t,this._sharedData.physicsSystem.SetGravity(this.getVec3(this._sharedData.gravityX,this._sharedData.gravityY,this._sharedData.gravityZ)))}isDynamic(){return this.bodyType==="Dynamic"}isStatic(){return this.bodyType==="Static"}isKinematic(){return this.bodyType==="Kinematic"}isBullet(){return this.bullet}setBullet(t){if(this.bullet===t||(this.bullet=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetMotionQuality(e.GetID(),this.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(t){this.fixedRotation!==t&&(this.fixedRotation=t,this._needToRecreateBody=!0)}getDensity(){return this.density}setDensity(t){t<0&&(t=0),this.density!==t&&(this.density=t,this._needToRecreateShape=!0)}getMassOverride(){return this.massOverride}setMassOverride(t){this.massOverride!==t&&(this.massOverride=t,this._needToRecreateBody=!0)}getFriction(){return this.friction}setFriction(t){if(t<0&&(t=0),this.friction===t||(this.friction=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetFriction(e.GetID(),t)}getRestitution(){return this.restitution}setRestitution(t){if(t<0&&(t=0),this.restitution===t||(this.restitution=t,this._body===null&&!this._createBody()))return;const e=this._body;this._sharedData.bodyInterface.SetRestitution(e.GetID(),t)}getLinearDamping(){return this.linearDamping}setLinearDamping(t){if(t<0&&(t=0),this.linearDamping===t||(this.linearDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetLinearDamping(t)}getAngularDamping(){return this.angularDamping}setAngularDamping(t){if(t<0&&(t=0),this.angularDamping===t||(this.angularDamping=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetAngularDamping(t)}getGravityScale(){return this.gravityScale}setGravityScale(t){if(this.gravityScale===t||(this.gravityScale=t,this._body===null&&!this._createBody()))return;this._body.GetMotionProperties().SetGravityFactor(t)}layerEnabled(t){return t=Math.floor(t),t<1||t>8?!1:!!(this.layers&1<<t-1)}enableLayer(t,e){t=Math.floor(t),!(t<1||t>8)&&(e?this.layers|=1<<t-1:this.layers&=~(1<<t-1),this._needToRecreateBody=!0)}maskEnabled(t){return t=Math.floor(t),t<1||t>16?!1:!!(this.masks&1<<t-1)}enableMask(t,e){t=Math.floor(t),!(t<1||t>16)&&(e?this.masks|=1<<t-1:this.masks&=~(1<<t-1),this._needToRecreateBody=!0)}getLinearVelocityX(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetX()*this._sharedData.worldScale}setLinearVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetY(),e.GetLinearVelocity().GetZ()))}getLinearVelocityY(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetY()*this._sharedData.worldScale}setLinearVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),t*this._sharedData.worldInvScale,e.GetLinearVelocity().GetZ()))}getLinearVelocityZ(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().GetZ()*this._sharedData.worldScale}setLinearVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetLinearVelocity(e.GetID(),this.getVec3(e.GetLinearVelocity().GetX(),e.GetLinearVelocity().GetY(),t*this._sharedData.worldInvScale))}getLinearVelocityLength(){return this._body===null&&!this._createBody()?0:this._body.GetLinearVelocity().Length()*this._sharedData.worldScale}getAngularVelocityX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetX())}setAngularVelocityX(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(n.toRad(t),e.GetAngularVelocity().GetY(),e.GetAngularVelocity().GetZ()))}getAngularVelocityY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetY())}setAngularVelocityY(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),n.toRad(t),e.GetAngularVelocity().GetZ()))}getAngularVelocityZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return n.toDegrees(t.GetAngularVelocity().GetZ())}setAngularVelocityZ(t){if(this._body===null&&!this._createBody())return;const e=this._body;this._sharedData.bodyInterface.SetAngularVelocity(e.GetID(),this.getVec3(e.GetAngularVelocity().GetX(),e.GetAngularVelocity().GetY(),n.toRad(t)))}applyForce(t,e,s,i,o,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddForce(r.GetID(),this.getVec3(t,e,s),this.getRVec3(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale),Jolt.EActivation_Activate)}applyForceAtCenter(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddForce(i.GetID(),this.getVec3(t,e,s),Jolt.EActivation_Activate)}applyForceTowardPosition(t,e,s,i){if(this._body===null&&!this._createBody())return;const o=this._body,a=e-o.GetPosition().GetX(),r=s-o.GetPosition().GetY(),d=i-o.GetPosition().GetZ(),l=a*a+r*r+d*d;if(l===0)return;const c=t/Math.sqrt(l);this._sharedData.bodyInterface.AddForce(o.GetID(),this.getVec3(a*c,r*c,d*c),Jolt.EActivation_Activate)}applyImpulse(t,e,s,i,o,a){if(this._body===null&&!this._createBody())return;const r=this._body;this._sharedData.bodyInterface.AddImpulse(r.GetID(),this.getVec3(t,e,s),this.getRVec3(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale))}applyImpulseAtCenter(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddImpulse(i.GetID(),this.getVec3(t,e,s))}applyImpulseTowardPosition(t,e,s,i,o,a,r){if(this._body===null&&!this._createBody())return;const d=this._body,l=e-o,c=s-a,h=i-r,y=l*l+c*c+h*h;if(y===0)return;const u=t/Math.sqrt(y);this._sharedData.bodyInterface.AddImpulse(d.GetID(),this.getVec3(l*u,c*u,h*u),this.getRVec3(o*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale,r*this._sharedData.worldInvScale))}applyTorque(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddTorque(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(s)),Jolt.EActivation_Activate)}applyAngularImpulse(t,e,s){if(this._body===null&&!this._createBody())return;const i=this._body;this._sharedData.bodyInterface.AddAngularImpulse(i.GetID(),this.getVec3(n.toRad(t),n.toRad(e),n.toRad(s)))}getMass(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseMass()}getInertiaAroundX(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetX()}getInertiaAroundY(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetY()}getInertiaAroundZ(){if(this._body===null&&!this._createBody())return 0;const t=this._body;return 1/t.GetMotionProperties().GetInverseInertiaDiagonal().GetZ()}getMassCenterX(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetX()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetY()*this._sharedData.worldScale}getMassCenterZ(){return this._body===null&&!this._createBody()?0:this._body.GetCenterOfMassPosition().GetZ()*this._sharedData.worldScale}onContactBegin(t){this._currentContacts.push(t);let e=this._contactsEndedThisFrame.indexOf(t);e!==-1?this._contactsEndedThisFrame.splice(e,1):this._contactsStartedThisFrame.push(t)}onContactEnd(t){this._contactsEndedThisFrame.push(t);const e=this._currentContacts.indexOf(t);e!==-1&&this._currentContacts.splice(e,1)}canCollideAgainst(t){return(this.getMasksAccordingToBodyType()&t.getLayersAccordingToBodyType())!=0}static areObjectsColliding(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.isColliding(e):!1}static hasCollisionStartedBetween(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.hasCollisionStartedWith(e):!1}static hasCollisionStoppedBetween(t,e,s){const i=t.getBehavior(s);return i?i.collisionChecker.hasCollisionStoppedWith(e):!1}}n.Physics3DRuntimeBehavior=_,n.registerBehavior("Physics3D::Physics3DBehavior",n.Physics3DRuntimeBehavior),function(e){class f{constructor(i){this.behavior=i}createAndAddBody(){const{behavior:i}=this,{_sharedData:o}=i,a=i.createShape(),r=new Jolt.BodyCreationSettings(a,i._getPhysicsPosition(o.getRVec3(0,0,0)),i._getPhysicsRotation(o.getQuat(0,0,0,1)),i.bodyType==="Static"?Jolt.EMotionType_Static:i.bodyType==="Kinematic"?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic,i.getBodyLayer());r.mMotionQuality=i.bullet?Jolt.EMotionQuality_LinearCast:Jolt.EMotionQuality_Discrete,r.mAllowedDOFs=i.fixedRotation?Jolt.EAllowedDOFs_TranslationX|Jolt.EAllowedDOFs_TranslationY|Jolt.EAllowedDOFs_TranslationZ:Jolt.EAllowedDOFs_All,r.mFriction=i.friction,r.mRestitution=i.restitution,r.mLinearDamping=i.linearDamping,r.mAngularDamping=i.angularDamping,r.mGravityFactor=i.gravityScale,i.massOverride>0&&(r.mOverrideMassProperties=Jolt.EOverrideMassProperties_CalculateInertia,r.mMassPropertiesOverride.mMass=i.massOverride);const d=o.bodyInterface,l=d.CreateBody(r);return Jolt.destroy(r),d.AddBody(l.GetID(),Jolt.EActivation_Activate),l}updateObjectFromBody(){const{behavior:i}=this,{_body:o}=i;o!==null&&o.IsActive()&&(i._moveObjectToPhysicsPosition(o.GetPosition()),i._moveObjectToPhysicsRotation(o.GetRotation()))}updateBodyFromObject(){const{behavior:i}=this,{owner3D:o,_sharedData:a}=i;if(i._body===null&&!i._createBody())return;const r=i._body;(this.behavior._objectOldX!==o.getX()||this.behavior._objectOldY!==o.getY()||this.behavior._objectOldZ!==o.getZ()||this.behavior._objectOldRotationX!==o.getRotationX()||this.behavior._objectOldRotationY!==o.getRotationY()||this.behavior._objectOldRotationZ!==o.getAngle())&&a.bodyInterface.SetPositionAndRotationWhenChanged(r.GetID(),this.behavior._getPhysicsPosition(a.getRVec3(0,0,0)),this.behavior._getPhysicsRotation(a.getQuat(0,0,0,1)),Jolt.EActivation_Activate)}recreateShape(){const{behavior:i}=this,{_sharedData:o}=i;if(i._body===null&&!i._createBody())return;const a=i._body;o.bodyInterface.SetShape(a.GetID(),i.createShape(),!0,Jolt.EActivation_Activate)}destroyBody(){const{behavior:i}=this,{_sharedData:o}=i;i._body!==null&&(o.bodyInterface.RemoveBody(i._body.GetID()),o.bodyInterface.DestroyBody(i._body.GetID()),i._body=null)}}e.DefaultBodyUpdater=f;class t{constructor(i){this.behavior=i}isColliding(i){return this.behavior._currentContacts.some(o=>o.owner===i)?!0:this.behavior._contactsStartedThisFrame.some(o=>o.owner===i)}hasCollisionStartedWith(i){return this.behavior._contactsStartedThisFrame.some(o=>o.owner===i)}hasCollisionStoppedWith(i){return this.behavior._contactsEndedThisFrame.some(o=>o.owner===i)}}e.DefaultCollisionChecker=t}(_=n.Physics3DRuntimeBehavior||(n.Physics3DRuntimeBehavior={}))})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=Physics3DRuntimeBehavior.js.map
|