UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.83 kB
import{isSome as e,isNone as s}from"../../../../core/maybe.js";import{c as r}from"../../../../chunks/mat4.js";import{c as t}from"../../../../chunks/mat4f64.js";import{VisualElement as o}from"./VisualElement.js";import{Object3D as i}from"../../webgl-engine/lib/Object3D.js";import{UpdatePolicy as a}from"../../webgl-engine/lib/UpdatePolicy.js";import{WebGLLayer as c}from"../../webgl-engine/lib/WebGLLayer.js";class n extends o{constructor(e){super(e.view),this._resources=null,this._transform=t()}get object(){return e(this._resources)?this._resources.object:null}get transform(){return this._transform}set transform(s){r(this._transform,s),e(this._resources)&&(this._resources.object.transformation=this._transform)}recreate(){this.attached&&this.createResources()}recreateGeometry(){if(s(this._resources))return;const e=this._resources.object,r=this.view._stage;r.removeMany(e.geometries),e.removeAllGeometries(),this.createGeometries(e),e.visible=this.visible,r.addMany(e.geometries)}createResources(){this.destroyResources();const e=this.view._stage;if(!e)return;const s=new c({pickable:!1,updatePolicy:a.SYNC});e.add(s);const r=new i({castShadow:!1});r.transformation=this._transform,this.createExternalResources(),this.createGeometries(r),e.addMany(r.geometries),this.forEachExternalMaterial((s=>e.add(s))),e.add(r),s.add(r),r.visible=this.visible,this._resources={layer:s,object:r}}destroyResources(){const e=this.view._stage;!s(this._resources)&&e&&(e.remove(this._resources.object),e.remove(this._resources.layer),this.forEachExternalMaterial((s=>{e.remove(s),s.dispose()})),e.removeMany(this._resources.object.geometries),this._resources.object.dispose(),this.destroyExternalResources(),this._resources=null)}updateVisibility(e){s(this._resources)||(this._resources.object.visible=e)}}export{n as Object3DVisualElement};