-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from BarthPaleologue/WIP
Bug fix
- Loading branch information
Showing
16 changed files
with
505 additions
and
249 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { TransformNode } from "@babylonjs/core/Meshes"; | ||
import { Assets } from "../assets"; | ||
import { PhysicsAggregate } from "@babylonjs/core/Physics/v2/physicsAggregate"; | ||
import { PhysicsShapeType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; | ||
import { PhysicsShapeConvexHull } from "@babylonjs/core/Physics/v2/physicsShape"; | ||
import { Mesh } from "@babylonjs/core/Meshes/mesh"; | ||
import { CollisionMask } from "../settings"; | ||
import { Scene } from "@babylonjs/core/scene"; | ||
import { Vector3 } from "@babylonjs/core/Maths/math"; | ||
import { Transformable } from "../architecture/transformable"; | ||
|
||
export class LandingPad implements Transformable { | ||
readonly instanceRoot: TransformNode; | ||
readonly aggregate: PhysicsAggregate; | ||
|
||
constructor(scene: Scene) { | ||
this.instanceRoot = Assets.CreateLandingPadInstance(); | ||
|
||
this.aggregate = new PhysicsAggregate( | ||
this.instanceRoot, | ||
PhysicsShapeType.CONTAINER, | ||
{ | ||
mass: 0, | ||
restitution: 0.2 | ||
}, | ||
scene | ||
); | ||
|
||
this.aggregate.body.setMassProperties({ inertia: Vector3.Zero(), mass: 0 }); | ||
|
||
for (const child of this.instanceRoot.getChildMeshes()) { | ||
const childShape = new PhysicsShapeConvexHull(child as Mesh, scene); | ||
childShape.filterMembershipMask = CollisionMask.LANDING_PADS; | ||
this.aggregate.shape.addChildFromParent(this.instanceRoot, childShape, child); | ||
} | ||
this.aggregate.body.disablePreStep = false; | ||
} | ||
|
||
getTransform(): TransformNode { | ||
return this.aggregate.transformNode; | ||
} | ||
|
||
dispose() { | ||
this.aggregate.dispose(); | ||
this.instanceRoot.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import "../styles/index.scss"; | ||
|
||
import { Engine } from "@babylonjs/core/Engines/engine"; | ||
import HavokPhysics from "@babylonjs/havok"; | ||
import { HavokPlugin } from "@babylonjs/core/Physics/v2/Plugins/havokPlugin"; | ||
import { setMaxLinVel } from "./utils/havok"; | ||
import { UberScene } from "./uberCore/uberScene"; | ||
import { Vector3 } from "@babylonjs/core/Maths/math.vector"; | ||
import { Assets } from "./assets"; | ||
import { roll, translate } from "./uberCore/transforms/basicTransform"; | ||
import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight"; | ||
import { Color4 } from "@babylonjs/core/Maths/math.color"; | ||
import "@babylonjs/core/Physics/physicsEngineComponent"; | ||
import { Keyboard } from "./inputs/keyboard"; | ||
import { LandingPad } from "./landingPad/landingPad"; | ||
import { PhysicsViewer } from "@babylonjs/core/Debug/physicsViewer"; | ||
import { DefaultControls } from "./defaultController/defaultControls"; | ||
import { Spaceship } from "./spaceship/spaceship"; | ||
import "@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent"; | ||
import { ShadowGenerator } from "@babylonjs/core/Lights/Shadows/shadowGenerator"; | ||
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder"; | ||
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight"; | ||
import { PointLight } from "@babylonjs/core/Lights/pointLight"; | ||
|
||
const canvas = document.getElementById("renderer") as HTMLCanvasElement; | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
|
||
const engine = new Engine(canvas, true); | ||
engine.useReverseDepthBuffer = true; | ||
|
||
// Init Havok physics engine | ||
const havokInstance = await HavokPhysics(); | ||
const havokPlugin = new HavokPlugin(true, havokInstance); | ||
setMaxLinVel(havokPlugin, 10000, 10000); | ||
console.log(`Havok initialized`); | ||
|
||
const scene = new UberScene(engine); | ||
scene.useRightHandedSystem = true; | ||
scene.enablePhysics(Vector3.Zero(), havokPlugin); | ||
scene.clearColor = new Color4(0.2, 0.2, 0.6, 1); | ||
|
||
const hemi = new HemisphericLight("hemi", new Vector3(0, 1, 0), scene); | ||
const light = new DirectionalLight("light", new Vector3(-2, -5, 1).normalize(), scene); | ||
const pointLight = new PointLight("pointLight", new Vector3(0, 0, 0), scene); | ||
pointLight.intensity = 0; | ||
const shadowGenerator = new ShadowGenerator(2048, light); | ||
|
||
await Assets.Init(scene); | ||
|
||
const spaceship = new Spaceship(scene); | ||
shadowGenerator.addShadowCaster(spaceship.instanceRoot, true); | ||
spaceship.getTransform().position = new Vector3(0, 0, -10); | ||
roll(spaceship.getTransform(), Math.random() * 6.28); | ||
|
||
const landingPad = new LandingPad(scene); | ||
landingPad.getTransform().position = new Vector3(0, -20, 0); | ||
landingPad.instanceRoot.getChildMeshes().forEach((mesh) => { | ||
mesh.receiveShadows = true; | ||
}); | ||
|
||
/*const ground = MeshBuilder.CreateGround("ground", { width: 50, height: 50 }); | ||
ground.position.y = -40; | ||
ground.receiveShadows = true;*/ | ||
|
||
/*const physicsViewer = new PhysicsViewer(); | ||
physicsViewer.showBody(spaceship.aggregate.body); | ||
physicsViewer.showBody(landingPad.aggregate.body);*/ | ||
|
||
const defaultControls = new DefaultControls(scene); | ||
defaultControls.speed *= 15; | ||
defaultControls.addInput(new Keyboard()); | ||
scene.setActiveController(defaultControls); | ||
|
||
translate(defaultControls.getTransform(), new Vector3(50, 0, 0)); | ||
|
||
defaultControls.getTransform().lookAt(Vector3.Lerp(spaceship.getTransform().position, landingPad.getTransform().position, 0.5)); | ||
|
||
scene.onBeforeRenderObservable.add(() => { | ||
const deltaTime = scene.deltaTime / 1000; | ||
scene.getActiveController().update(deltaTime); | ||
spaceship.update(deltaTime); | ||
}); | ||
|
||
scene.executeWhenReady(() => { | ||
engine.runRenderLoop(() => { | ||
scene.render(); | ||
}); | ||
}); | ||
|
||
document.addEventListener("keydown", (event) => { | ||
if (event.key === "o") { | ||
spaceship.engageLanding(landingPad); | ||
} | ||
}); | ||
|
||
window.addEventListener("resize", () => { | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
engine.resize(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.