Skip to content

Commit

Permalink
Merge pull request #170 from BarthPaleologue/FixSphericalTankWarning
Browse files Browse the repository at this point in the history
Fix spherical tank warning
  • Loading branch information
BarthPaleologue authored Nov 4, 2024
2 parents 44cd6bf + ce808bb commit 0d46b7e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Binary file modified src/asset/SpaceStationParts/sphericalTank.glb
Binary file not shown.
11 changes: 9 additions & 2 deletions src/ts/assets/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
};

Expand Down
3 changes: 2 additions & 1 deletion src/ts/assets/procedural/spaceStation/landingBayMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class LandingBayMaterial extends ShaderMaterial {
width: textureResolution * aspectRatio,
height: textureResolution
},
scene
scene,
true
);

const font_size = 128;
Expand Down
25 changes: 14 additions & 11 deletions src/ts/assets/procedural/spaceStation/utilitySection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion src/ts/assets/textures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export class Textures {
width: padNumberTextureResolution,
height: padNumberTextureResolution * Settings.LANDING_PAD_ASPECT_RATIO
},
scene
scene,
true
);

//Add text to dynamic texture
Expand Down

0 comments on commit 0d46b7e

Please sign in to comment.