UNPKG

threepipe

Version:

A modern 3D viewer framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.

76 lines 2.94 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 { Object3D } from 'three'; import { generateUiFolder, uiToggle } from 'uiconfig.js'; import { iObjectCommons } from '../../core'; import { onChange2 } from 'ts-browser-helpers'; export class AHelperWidget extends Object3D { constructor(object) { super(); this.modelObject = this; this.isWidget = true; this.assetType = 'widget'; this.visible = true; this.uiConfig = generateUiFolder('Widget', this); this.object = object; this.object.updateMatrixWorld(); if (this.object.updateProjectionMatrix) this.object.updateProjectionMatrix(); this.matrix = object.matrixWorld; this.matrixAutoUpdate = false; this.dispose = this.dispose.bind(this); this._objectUpdate = this._objectUpdate.bind(this); this.attach(object); this.traverse(o => { o.userData.__keepShadowDef = true; o.castShadow = false; o.receiveShadow = false; }); } dispose() { this.detach(); } update() { iObjectCommons.setDirty.call(this); } _objectUpdate() { if (this.object) this.update(); } attach(object) { if (this.object) this.detach(); this.object = object; if (this.object) { this.update(); this.object.addEventListener('objectUpdate', this._objectUpdate); this.object.addEventListener('dispose', this.dispose); this.uiConfig && this.object.uiConfig?.children?.push(this.uiConfig); this.visible = true; } return this; } detach() { if (this.object) { this.object.removeEventListener('objectUpdate', this._objectUpdate); this.object.removeEventListener('dispose', this.dispose); if (this.uiConfig) { const i = this.object.uiConfig?.children?.indexOf(this.uiConfig); if (i !== undefined && i >= 0) this.object.uiConfig?.children?.splice(i, 1); } this.object = undefined; this.visible = false; } return this; } } __decorate([ uiToggle(), onChange2(AHelperWidget.prototype.update) ], AHelperWidget.prototype, "visible", void 0); //# sourceMappingURL=AHelperWidget.js.map