@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
68 lines • 2.3 kB
JavaScript
import { foreachComponent } from "../../engine/engine_gameobject.js";
import { $shadowDomOwner } from "./Symbols.js";
export class UIRaycastUtils {
/** returns the real object when dealing with shadow UI */
static getObject(obj) {
const shadowOwner = obj[$shadowDomOwner];
if (shadowOwner) {
if (shadowOwner.isComponent === true)
obj = shadowOwner.gameObject;
else
obj = shadowOwner;
}
return obj;
}
;
static isInteractable(obj, out) {
// reset state
if (out) {
out.canvasGroup = undefined;
out.graphic = undefined;
}
if (obj === null || obj === undefined || !obj.visible)
return false;
obj = this.getObject(obj);
if (!obj.visible)
return false;
const canvasGroup = this.tryFindCanvasGroup(obj);
if (canvasGroup?.isCanvasGroup === true) {
if (out)
out.canvasGroup = canvasGroup;
if (canvasGroup.blocksRaycasts === false)
return false;
if (canvasGroup.interactable === false)
return false;
}
// handle Graphic Raycast target
const graphic = foreachComponent(obj, c => {
if (c.isGraphic === true)
return c;
return undefined;
}, false);
// console.log(obj, graphic?.raycastTarget);
if (out) {
if (graphic?.isGraphic === true)
out.graphic = graphic;
}
if (graphic?.raycastTarget === false)
return false;
if (graphic?.layer === 2)
return false;
return true;
}
static tryFindCanvasGroup(obj) {
if (!obj)
return null;
// test for canvas groups
const res = foreachComponent(obj, c => {
const gr = c;
if (gr.blocksRaycasts !== undefined && gr.interactable !== undefined)
return gr;
return undefined;
}, false);
if (res !== undefined)
return res;
return this.tryFindCanvasGroup(obj.parent);
}
}
//# sourceMappingURL=RaycastUtils.js.map