UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

38 lines 1.36 kB
import { forceGetInstance } from "@lincode/utils"; import { HitEvent } from "../interface/IVisible"; import { getAppendablesById } from "../collections/idCollections"; import createInternalSystem from "./utils/createInternalSystem"; const getAppendables = (val) => { if (!val) return []; if (typeof val === "string") return getAppendablesById(val); const result = []; for (const id of val) for (const appendable of getAppendablesById(id)) result.push(appendable); return result; }; const hitCache = new WeakMap(); export const hitTestSystem = createInternalSystem("hitTestSystem", { update: (self) => { for (const target of getAppendables(self.hitTarget)) { if (!("object3d" in target)) return; const cache = forceGetInstance(hitCache, self, WeakSet); if (self.hitTest(target)) { if (!cache.has(target)) { cache.add(target); self.onHitStart?.(new HitEvent(target)); } self.onHit?.(new HitEvent(target)); continue; } if (!cache.has(target)) continue; cache.delete(target); self.onHitEnd?.(new HitEvent(target)); } } }); //# sourceMappingURL=hitTestSystem.js.map