From f9f7905303550d29d9215f99699ac5a02402dbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:10:29 +0100 Subject: [PATCH 1/2] fix spherical tank warning share physics shape sphere between all tanks to avoid the warning and avoid generating the shape everytime --- src/asset/SpaceStationParts/sphericalTank.glb | Bin 152808 -> 152808 bytes src/ts/assets/objects.ts | 11 ++++++-- .../procedural/spaceStation/utilitySection.ts | 25 ++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/asset/SpaceStationParts/sphericalTank.glb b/src/asset/SpaceStationParts/sphericalTank.glb index 7c8c8cef05d75d367767d35fd7f17ae1fb14e380..f71a229291a71973949990698fbf1b218d9eeb3b 100644 GIT binary patch delta 23 fcmaE{lJmt%&I#@;MtbH3joz)^j9a~#=7sb1q diff --git a/src/ts/assets/objects.ts b/src/ts/assets/objects.ts index 56829e540..1a82462e1 100644 --- a/src/ts/assets/objects.ts +++ b/src/ts/assets/objects.ts @@ -41,8 +41,9 @@ import sphericalTank from "../../asset/SpaceStationParts/sphericalTank.glb"; import stationEngine from "../../asset/SpaceStationParts/engine.glb"; import { CollisionMask } from "../settings"; -import { PhysicsShape, PhysicsShapeMesh } from "@babylonjs/core/Physics/v2/physicsShape"; +import { PhysicsShape, PhysicsShapeMesh, PhysicsShapeSphere } from "@babylonjs/core/Physics/v2/physicsShape"; import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder"; +import { Vector3 } from "@babylonjs/core/Maths/math"; export class Objects { private static WANDERER: Mesh; @@ -60,6 +61,7 @@ export class Objects { public static GRASS_BLADES: Mesh[] = []; public static SPHERICAL_TANK: Mesh; + public static SPHERICAL_TANK_PHYSICS_SHAPE: PhysicsShape; public static STATION_ENGINE: Mesh; public static CRATE: Mesh; @@ -189,9 +191,14 @@ export class Objects { const boundingBox = Objects.SPHERICAL_TANK.getBoundingInfo().boundingBox; const maxDimension = Math.max(boundingBox.extendSize.x, boundingBox.extendSize.y, boundingBox.extendSize.z); - Objects.SPHERICAL_TANK.scalingDeterminant = 20 / maxDimension; + const targetDimension = 20; + + Objects.SPHERICAL_TANK.scaling.scaleInPlace(targetDimension / maxDimension); Objects.SPHERICAL_TANK.bakeCurrentTransformIntoVertices(); + //FIXME: the scaling of the radius is caused by an issue with the mesh + Objects.SPHERICAL_TANK_PHYSICS_SHAPE = new PhysicsShapeSphere(Vector3.Zero(), targetDimension * 2.5, scene) + console.log("SphericalTank loaded"); }; diff --git a/src/ts/assets/procedural/spaceStation/utilitySection.ts b/src/ts/assets/procedural/spaceStation/utilitySection.ts index b46eb7b40..0de264c56 100644 --- a/src/ts/assets/procedural/spaceStation/utilitySection.ts +++ b/src/ts/assets/procedural/spaceStation/utilitySection.ts @@ -27,8 +27,9 @@ import { Mesh } from "@babylonjs/core/Meshes/mesh"; import { CollisionMask } from "../../../settings"; import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh"; import { PhysicsAggregate } from "@babylonjs/core/Physics/v2/physicsAggregate"; -import { PhysicsShapeType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; +import { PhysicsMotionType, PhysicsShapeType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; import { getRngFromSeed } from "../../../utils/getRngFromSeed"; +import { PhysicsBody } from "@babylonjs/core/Physics/v2/physicsBody"; export class UtilitySection implements Transformable { private readonly attachment: Mesh; @@ -40,7 +41,7 @@ export class UtilitySection implements Transformable { private readonly metalSectionMaterial: MetalSectionMaterial; private readonly tanks: AbstractMesh[] = []; - private readonly tankAggregates: PhysicsAggregate[] = []; + private readonly tankBodies: PhysicsBody[] = []; constructor(seed: number, scene: Scene) { this.metalSectionMaterial = new MetalSectionMaterial(scene); @@ -95,19 +96,21 @@ export class UtilitySection implements Transformable { this.attachmentAggregate.shape.filterCollideMask = CollisionMask.DYNAMIC_OBJECTS; this.tanks.forEach((tank) => { - const tankAggregate = new PhysicsAggregate(tank, PhysicsShapeType.SPHERE, { mass: 0 }); - tankAggregate.body.disablePreStep = false; - tankAggregate.shape.filterMembershipMask = CollisionMask.ENVIRONMENT; - tankAggregate.shape.filterCollideMask = CollisionMask.DYNAMIC_OBJECTS; - - this.tankAggregates.push(tankAggregate); + const tankBody = new PhysicsBody(tank, PhysicsMotionType.STATIC, false, this.getTransform().getScene()); + tankBody.setMassProperties({ mass: 0 }); + tankBody.disablePreStep = false; + tankBody.shape = Objects.SPHERICAL_TANK_PHYSICS_SHAPE; + tankBody.shape.filterMembershipMask = CollisionMask.ENVIRONMENT; + tankBody.shape.filterCollideMask = CollisionMask.DYNAMIC_OBJECTS; + + this.tankBodies.push(tankBody); }); } else if (distanceToCamera > 360e3 && this.attachmentAggregate !== null) { this.attachmentAggregate?.dispose(); this.attachmentAggregate = null; - this.tankAggregates.forEach((tankAggregate) => tankAggregate.dispose()); - this.tankAggregates.length = 0; + this.tankBodies.forEach((tankBody) => tankBody.dispose()); + this.tankBodies.length = 0; } } @@ -120,6 +123,6 @@ export class UtilitySection implements Transformable { this.attachmentAggregate?.dispose(); this.metalSectionMaterial.dispose(); this.tanks.forEach((tank) => tank.dispose()); - this.tankAggregates.forEach((tankAggregate) => tankAggregate.dispose()); + this.tankBodies.forEach((tankAggregate) => tankAggregate.dispose()); } } From ce808bb4cfa5ec47d0581f048596e066d6d9def0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:10:52 +0100 Subject: [PATCH 2/2] add mipmaps to station dynamics textures it looks better from afar --- src/ts/assets/procedural/spaceStation/landingBayMaterial.ts | 3 ++- src/ts/assets/textures.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ts/assets/procedural/spaceStation/landingBayMaterial.ts b/src/ts/assets/procedural/spaceStation/landingBayMaterial.ts index 87c0c7b7d..5b4006741 100644 --- a/src/ts/assets/procedural/spaceStation/landingBayMaterial.ts +++ b/src/ts/assets/procedural/spaceStation/landingBayMaterial.ts @@ -75,7 +75,8 @@ export class LandingBayMaterial extends ShaderMaterial { width: textureResolution * aspectRatio, height: textureResolution }, - scene + scene, + true ); const font_size = 128; diff --git a/src/ts/assets/textures.ts b/src/ts/assets/textures.ts index e8ab4d18e..44b4a6884 100644 --- a/src/ts/assets/textures.ts +++ b/src/ts/assets/textures.ts @@ -191,7 +191,8 @@ export class Textures { width: padNumberTextureResolution, height: padNumberTextureResolution * Settings.LANDING_PAD_ASPECT_RATIO }, - scene + scene, + true ); //Add text to dynamic texture