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.

65 lines 2.55 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { BoxHelper, Color } from "three"; import * as params from "../engine/engine_default_parameters.js"; import * as Gizmos from "../engine/engine_gizmos.js"; import { serializable } from "../engine/engine_serialization_decorator.js"; import { FrameEvent } from "../engine/engine_setup.js"; import { Behaviour } from "./Component.js"; /** * BoxGizmo is a component that displays a box around the object in the scene. It can optionally expand to the object's bounds. * @category Helpers * @group Components */ export class BoxGizmo extends Behaviour { objectBounds = false; color; isGizmo = true; _gizmoObject = null; _boxHelper = null; onEnable() { if (this.isGizmo && !params.showGizmos) return; if (!this._gizmoObject) { if (this.objectBounds) { this._gizmoObject = new BoxHelper(this.gameObject, this.color ?? 0xffff00); } else { this.objectBounds = false; this._gizmoObject = Gizmos.CreateWireCube(this.color ?? 0xffff00); } } if (this.objectBounds) { this.scene.add(this._gizmoObject); this._boxHelper = this._gizmoObject; this.startCoroutine(this.syncObjectBounds(), FrameEvent.OnBeforeRender); } else this.gameObject.add(this._gizmoObject); } onDisable() { if (this._gizmoObject) { this.gameObject.remove(this._gizmoObject); } } *syncObjectBounds() { while (this._boxHelper) { this._boxHelper?.update(); yield; } } } __decorate([ serializable() ], BoxGizmo.prototype, "objectBounds", void 0); __decorate([ serializable(Color) ], BoxGizmo.prototype, "color", void 0); __decorate([ serializable() ], BoxGizmo.prototype, "isGizmo", void 0); //# sourceMappingURL=Gizmos.js.map