UNPKG

@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.

40 lines (31 loc) 1.23 kB
import { Camera, Object3D } from "three"; import type { ICameraController } from "./engine_types.js"; const $cameraController = "needle:cameraController"; /** Get the camera controller for the given camera (if any) */ export function getCameraController(cam: Camera): ICameraController | null { return cam[$cameraController]; } /** Set the camera controller for the given camera */ export function setCameraController(cam: Camera, cameraController: ICameraController, active: boolean) { if (active) cam[$cameraController] = cameraController; else { if (cam[$cameraController] === cameraController) cam[$cameraController] = null; } } const autofit = "needle:autofit"; /** @internal */ export function useForAutoFit(obj: Object3D): boolean { // if autofit is not defined we assume it may be included if (obj[autofit] === undefined) return true; // otherwise if anything is set except false we assume it should be included return obj[autofit] !== false; } /** * Enable or disable autofitting for the given object */ export function setAutoFitEnabled(obj: Object3D, enabled: boolean): void { obj[autofit] = enabled; }