Skip to content

Commit

Permalink
Fix spawned media sliding
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jan 25, 2024
1 parent 14c3e35 commit 6b94772
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/bit-systems/media-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
ObjectMenuTarget,
Rigidbody,
MediaLoaderOffset,
MediaVideo
MediaVideo,
NetworkedTransform
} from "../bit-components";
import { inflatePhysicsShape, Shape } from "../inflators/physics-shape";
import { ErrorObject } from "../prefabs/error-object";
Expand Down Expand Up @@ -341,6 +342,9 @@ const mediaRefreshQuery = defineQuery([MediaRefresh]);
const mediaRefreshEnterQuery = enterQuery(mediaRefreshQuery);
export function mediaLoadingSystem(world: HubsWorld) {
mediaLoadingEnterQuery(world).forEach(function (eid) {
const mediaLoaderObj = world.eid2obj.get(eid)!;
mediaLoaderObj.visible = false;

const mediaLoaderEids = findAncestorsWithComponent(world, MediaLoader, eid);
mediaLoaderEids.forEach(mediaLoaderEid => {
MediaLoader.count[mediaLoaderEid]++;
Expand All @@ -366,6 +370,9 @@ export function mediaLoadingSystem(world: HubsWorld) {
MediaVideoLoaderData.delete(eid);
}

const mediaLoaderObj = world.eid2obj.get(eid)!;
mediaLoaderObj.visible = true;

const mediaLoaderEids = findAncestorsWithComponent(world, MediaLoader, eid);
for (let i = 0; i < mediaLoaderEids.length; i++) {
const mediaLoaderEid = mediaLoaderEids[i];
Expand Down Expand Up @@ -399,6 +406,14 @@ export function mediaLoadingSystem(world: HubsWorld) {
}
});

mediaLoadingQuery(world).forEach(eid => {
const mediaLoaderObj = world.eid2obj.get(eid)!;
transformPosition.fromArray(NetworkedTransform.position[eid]);
if (mediaLoaderObj.position.near(transformPosition, 0.001)) {
mediaLoaderObj.visible = true;
}
});

mediaLoadedEnterQuery(world).forEach(() => APP.scene?.emit("listed_media_changed"));
mediaLoadedExitQuery(world).forEach(() => APP.scene?.emit("listed_media_changed"));

Expand Down
4 changes: 4 additions & 0 deletions types/three.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ declare module "three" {
interface Mesh {
reflectionProbeMode: "static" | "dynamic" | false;
}

interface Vector3 {
near: Function;
}
}

0 comments on commit 6b94772

Please sign in to comment.