-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description - Move out of the core the `Physics` helper - Register it in the dependency container - Add debug module - Implement physics debug - Add new turbo env to the dev process - use vite `import.meta.env?.DEV` env as debug mode checker
- Loading branch information
1 parent
8a915ea
commit 288962c
Showing
14 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import "reflect-metadata"; | ||
|
||
import { singleton } from "tsyringe"; | ||
import { RapierPhysics } from "@chess-d/rapier-physics"; | ||
|
||
@singleton() | ||
export class CoreComponent { | ||
public physics!: Awaited<ReturnType<typeof RapierPhysics>>; | ||
|
||
constructor() {} | ||
|
||
public async init() { | ||
this.physics = await RapierPhysics(); | ||
} | ||
|
||
public 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 |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import "reflect-metadata"; | ||
import { Subject } from "rxjs"; | ||
|
||
import { Subject } from "rxjs"; | ||
import { singleton } from "tsyringe"; | ||
|
||
@singleton() | ||
export class CoreController { | ||
public readonly gui$$ = new Subject<any>(); | ||
|
||
constructor() {} | ||
|
||
public init() {} | ||
|
||
public 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
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { container } from "tsyringe"; | ||
import { isObject } from "@quick-threejs/utils"; | ||
import { AppModule } from "@quick-threejs/reactive"; | ||
import { Physics, RapierPhysics } from "@chess-d/rapier-physics"; | ||
|
||
import { CoreModule } from "./core.module"; | ||
|
||
export const setupCoreModule = (app: AppModule) => { | ||
export const setupCoreModule = async (app: AppModule) => { | ||
if (!isObject(app)) | ||
throw new Error("Unable to retrieve the application context."); | ||
|
||
container.register(AppModule, { useValue: app }); | ||
container.register(Physics, { useValue: await RapierPhysics() }); | ||
|
||
return container.resolve<CoreModule>(CoreModule); | ||
}; |
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,10 @@ | ||
import { BufferGeometry, LineSegments, MeshBasicMaterial } from "three"; | ||
import { singleton } from "tsyringe"; | ||
|
||
@singleton() | ||
export class DebugComponent { | ||
public readonly lines = new LineSegments( | ||
new BufferGeometry(), | ||
new MeshBasicMaterial({ color: 0xff40f0 }) | ||
); | ||
} |
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,24 @@ | ||
import { inject, singleton } from "tsyringe"; | ||
import { filter, map, Observable } from "rxjs"; | ||
import { AppModule } from "@quick-threejs/reactive"; | ||
import { Physics } from "@chess-d/rapier-physics"; | ||
|
||
import { DebugComponent } from "./debug.component"; | ||
|
||
@singleton() | ||
export class DebugController { | ||
public readonly physicsDebugRender$: Observable< | ||
InstanceType<Physics["rapier"]["DebugRenderBuffers"]> | ||
>; | ||
|
||
constructor( | ||
@inject(AppModule) private readonly appModule: AppModule, | ||
@inject(DebugComponent) private readonly component: DebugComponent, | ||
@inject(Physics) private readonly _physics: Physics | ||
) { | ||
this.physicsDebugRender$ = this.appModule.timer.step$().pipe( | ||
filter(() => !!this.appModule?.debug?.enabled), | ||
map(() => this._physics.world.debugRender()) | ||
); | ||
} | ||
} |
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,37 @@ | ||
import { inject, singleton } from "tsyringe"; | ||
import { BufferAttribute } from "three"; | ||
import { AppModule, Module } from "@quick-threejs/reactive"; | ||
|
||
import { DebugComponent } from "./debug.component"; | ||
import { DebugController } from "./debug.controller"; | ||
|
||
@singleton() | ||
export class DebugModule implements Module { | ||
constructor( | ||
@inject(DebugComponent) private readonly component: DebugComponent, | ||
@inject(DebugController) private readonly controller: DebugController, | ||
@inject(AppModule) private readonly appModule: AppModule | ||
) { | ||
if (this.appModule.debug.enabled()) | ||
appModule.world.scene().add(this.component.lines); | ||
|
||
this.controller.physicsDebugRender$.subscribe({ | ||
next: (buffers) => { | ||
this.component.lines.geometry.setAttribute( | ||
"position", | ||
new BufferAttribute(buffers.vertices, 3) | ||
); | ||
this.component.lines.geometry.setAttribute( | ||
"color", | ||
new BufferAttribute(buffers.colors, 4) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
init(): void {} | ||
|
||
dispose(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"$schema": "https://turborepo.org/schema.json", | ||
"extends": ["//"], | ||
"tasks": { | ||
"dev": { | ||
"env": ["DEV"] | ||
} | ||
} | ||
} |