Skip to content

Commit

Permalink
Correctly handle scene physics
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jul 6, 2023
1 parent 31373a2 commit 8001c99
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,5 @@ export const LinearScale = defineComponent({
targetZ: Types.f32
});
export const Quack = defineComponent();
export const TrimeshTag = defineComponent();
export const HeightFieldTag = defineComponent();
8 changes: 6 additions & 2 deletions src/bit-systems/scene-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { Mesh } from "three";
import { HubsWorld } from "../app";
import {
EnvironmentSettings,
HeightFieldTag,
NavMesh,
Networked,
PhysicsShape,
SceneLoader,
ScenePreviewCamera,
SceneRoot,
Skybox
Skybox,
TrimeshTag
} from "../bit-components";
import Sky from "../components/skybox";
import { Fit, inflatePhysicsShape, Shape } from "../inflators/physics-shape";
Expand Down Expand Up @@ -104,7 +106,9 @@ function* loadScene(
}
});

if (!findChildWithComponent(world, PhysicsShape, scene)) {
if (findChildWithComponent(world, TrimeshTag, scene) || findChildWithComponent(world, HeightFieldTag, scene)) {
console.log("heightfield or trimesh found on scene");
} else {
let navMeshEid;
if (isHighDensity) {
navMeshEid = findChildWithComponent(world, NavMesh, scene);
Expand Down
3 changes: 3 additions & 0 deletions src/inflators/heightfield.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { addComponent } from "bitecs";
import { HubsWorld } from "../app";
import { Fit, inflatePhysicsShape, Shape } from "./physics-shape";
import { HeightFieldTag } from "../bit-components";

export type HeightFieldParams = {
distance: number;
Expand All @@ -16,4 +18,5 @@ export function inflateHeightField(world: HubsWorld, eid: number, params: Height
heightfieldDistance: params.distance,
heightfieldData: params.data
});
addComponent(world, HeightFieldTag, eid);
}
3 changes: 3 additions & 0 deletions src/inflators/trimesh.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { addComponent } from "bitecs";
import { HubsWorld } from "../app";
import { Fit, inflatePhysicsShape, Shape } from "./physics-shape";
import { TrimeshTag } from "../bit-components";

export function inflateTrimesh(world: HubsWorld, eid: number) {
inflatePhysicsShape(world, eid, {
Expand All @@ -8,4 +10,5 @@ export function inflateTrimesh(world: HubsWorld, eid: number) {
includeInvisible: true,
margin: 0.01
});
addComponent(world, TrimeshTag, eid);
}

0 comments on commit 8001c99

Please sign in to comment.