pacem 0.53.0-pascal → 0.53.0-peano
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/pacem-dark-content.min.css +1 -1
- package/dist/css/pacem-dark-shell.min.css +1 -1
- package/dist/css/pacem-dark.min.css +1 -1
- package/dist/css/pacem-light-content.min.css +1 -1
- package/dist/css/pacem-light-shell.min.css +1 -1
- package/dist/css/pacem-light.min.css +1 -1
- package/dist/css/pacem-phousys-content.min.css +1 -1
- package/dist/css/pacem-phousys-shell.min.css +1 -1
- package/dist/css/pacem-phousys.min.css +1 -1
- package/dist/js/azure-maps.d.ts +1 -1
- package/dist/js/pacem-2d.d.ts +1 -1
- package/dist/js/pacem-2d.js +1 -1
- package/dist/js/pacem-2d.min.js +1 -1
- package/dist/js/pacem-3d.d.ts +1 -1
- package/dist/js/pacem-3d.js +10 -1
- package/dist/js/pacem-3d.min.js +2 -2
- package/dist/js/pacem-charts.d.ts +1 -1
- package/dist/js/pacem-charts.js +1 -1
- package/dist/js/pacem-charts.min.js +1 -1
- package/dist/js/pacem-cms.d.ts +1 -1
- package/dist/js/pacem-cms.js +1 -1
- package/dist/js/pacem-cms.min.js +1 -1
- package/dist/js/pacem-core.d.ts +1 -1
- package/dist/js/pacem-core.js +1 -1
- package/dist/js/pacem-core.min.js +1 -1
- package/dist/js/pacem-foundation.d.ts +1 -1
- package/dist/js/pacem-foundation.js +1 -1
- package/dist/js/pacem-foundation.min.js +1 -1
- package/dist/js/pacem-fx.d.ts +1 -1
- package/dist/js/pacem-fx.js +1 -1
- package/dist/js/pacem-fx.min.js +1 -1
- package/dist/js/pacem-logging.d.ts +1 -1
- package/dist/js/pacem-logging.js +1 -1
- package/dist/js/pacem-logging.min.js +1 -1
- package/dist/js/pacem-maps.d.ts +1 -1
- package/dist/js/pacem-maps.js +1 -1
- package/dist/js/pacem-maps.min.js +1 -1
- package/dist/js/pacem-media.d.ts +1 -1
- package/dist/js/pacem-media.js +1 -1
- package/dist/js/pacem-media.min.js +1 -1
- package/dist/js/pacem-networking.d.ts +1 -1
- package/dist/js/pacem-networking.js +1 -1
- package/dist/js/pacem-networking.min.js +1 -1
- package/dist/js/pacem-numerical.d.ts +1 -1
- package/dist/js/pacem-numerical.js +1 -1
- package/dist/js/pacem-numerical.min.js +1 -1
- package/dist/js/pacem-plus.d.ts +1 -1
- package/dist/js/pacem-plus.js +1 -1
- package/dist/js/pacem-plus.min.js +1 -1
- package/dist/js/pacem-scaffolding.d.ts +1 -1
- package/dist/js/pacem-scaffolding.js +1 -1
- package/dist/js/pacem-scaffolding.min.js +1 -1
- package/dist/js/pacem-ui.d.ts +1 -1
- package/dist/js/pacem-ui.js +1 -1
- package/dist/js/pacem-ui.min.js +1 -1
- package/dist/js/swagger-types.d.ts +1 -1
- package/package.json +1 -1
package/dist/js/pacem-3d.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pacem v0.53.0-
|
|
2
|
+
* pacem v0.53.0-peano (https://js.pacem.it)
|
|
3
3
|
* Copyright 2026 Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
var Pacem,__decorate=this&&this.__decorate||function(e,t,r,i){var n,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,r,s):n(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s};!function(e){!function(t){t.Point3DConverter={convert:t=>e.Geometry.LinearAlgebra.Vector3D.parse(t),convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0}`},t.Point3DOrNumberConverter={convert:t=>{const r=e.parseAsNumericalArray(t),i=()=>{throw new Error(`Cannot parse "${t}" as a valid Vector3D.`)};if(e.Utils.isNullOrEmpty(r)&&i(),3===r.length)return e.Geometry.LinearAlgebra.Vector3D.from(...r);if(1===r.length){const t=r[0];return e.Geometry.LinearAlgebra.Vector3D.from(t,t,t)}i()},convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0}`},t.QuaternionConverter={convert:t=>e.Geometry.LinearAlgebra.Quaternion.parse(t),convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0} ${e.w||0}`},t.BooleanOrNumberConverter={convert:t=>"true"===t||"false"!==t&&e.parseAsNumericalArray(t)[0],convertBack:e=>e.toString()}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){t.NotifyChange=function(t){return(r,i,n)=>{const o=`_${i}_${e.Utils.uniqueCode()}_backingField`;function s(){return this[o]}function a(e){if(e!==this[o]){const r=this[o];this[o]=e,t.call(this,i,r,e)}}Object.defineProperty(r,i,{get:function(){return s.call(this)},set:function(e){a.call(this,e)},enumerable:!0,configurable:!1})}}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.Pacem3DDetector=class Pacem3DDetector{constructor(){this._detected={supported:!1,info:{}};let e,t=document.createElement("canvas"),r=["webgl","experimental-webgl","moz-webgl","webkit-3d"],i=function(t){if(t)return e.getParameter(t)},n=(e,t,r)=>{let i=this._detected;(i.info[e]=i.info[e]||{})[t=(t=t.replace(/[^\w]+/g,"")).substring(0,1).toLowerCase()+t.substring(1)]=r};if(navigator.userAgent.indexOf("MSIE")>=0)try{e=window.WebGLHelper.CreateGLContext(t,"canvas")}catch(e){}else for(var o=0;o<r.length;o++)try{if(e=t.getContext(r[o]),e){n("main","Context Name",r[o]);break}}catch(e){}this._detected.supported=!!e,n("main","Platform",navigator.platform),n("main","Agent",navigator.userAgent),e&&(n("main","Vendor",i(e.VENDOR)),n("main","Version",i(e.VERSION)),n("main","Renderer",i(e.RENDERER)),n("main","Shading Language Version",i(e.SHADING_LANGUAGE_VERSION)),n("bits","Rgba Bits",i(e.RED_BITS)+", "+i(e.GREEN_BITS)+", "+i(e.BLUE_BITS)+", "+i(e.ALPHA_BITS)),n("bits","Depth Bits",i(e.DEPTH_BITS)),n("shader","Max Vertex Attribs",i(e.MAX_VERTEX_ATTRIBS)),n("shader","Max Vertex Texture Image Units",i(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS)),n("shader","Max Varying Vectors",i(e.MAX_VARYING_VECTORS)),n("shader","Max Uniform Vectors",i(e.MAX_VERTEX_UNIFORM_VECTORS)),n("tex","Max Combined Texture Image Units",i(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS)),n("tex","Max Texture Size",i(e.MAX_TEXTURE_SIZE)),n("tex","Max Cube Map Texture Size",i(e.MAX_CUBE_MAP_TEXTURE_SIZE)),n("tex","Num. Compressed Texture Formats",i(e.COMPRESSED_TEXTURE_FORMATS)),n("misc","Max Render Buffer Size",i(e.MAX_RENDERBUFFER_SIZE)),n("misc","Max Viewport Dimensions",i(e.MAX_VIEWPORT_DIMS)),n("misc","Aliased Line Width Range",i(e.ALIASED_LINE_WIDTH_RANGE)),n("misc","Aliased Point Size Range",i(e.ALIASED_POINT_SIZE_RANGE)),n("misc","Supported Extensions",e.getSupportedExtensions()||[]))}get info(){return this._detected.info}get supported(){return this._detected.supported}}}(e.Drawing3D||(e.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){class NodeGeometry{constructor(e=[]){this.positions=e}static barycenter(t){var r={x:0,y:0,z:0};if(!e.Utils.isNullOrEmpty(t)){for(var i=t.length,n=0;n<t.length;n++){var o=t[n];r.x+=o.x,r.y+=o.y,r.z+=o.z}var s=1*i;r.x/=s,r.y/=s,r.z/=s}return r}static boundingBox(t){const r={minX:1/0,minY:1/0,minZ:1/0,maxX:-1/0,maxY:-1/0,maxZ:-1/0};if(!e.Utils.isNullOrEmpty(t))for(var i=0;i<t.length;i++){var n=t[i];r.minX=Math.min(r.minX,n.x),r.minY=Math.min(r.minY,n.y),r.minZ=Math.min(r.minZ,n.z),r.maxX=Math.max(r.maxX,n.x),r.maxY=Math.max(r.maxY,n.y),r.maxZ=Math.max(r.maxZ,n.z)}return r}setAsDirty(){r.call(this)}}function r(){this.flags=[t.StalePropertyFlag.Geometry]}t.NodeGeometry=NodeGeometry;class LineGeometry extends NodeGeometry{}__decorate([t.NotifyChange(r)],LineGeometry.prototype,"positions",void 0),t.LineGeometry=LineGeometry;class MeshGeometry extends NodeGeometry{#e;#t;#r;get barycenter(){return this.#r??=NodeGeometry.barycenter(this.positions)}set barycenter(e){this.#r=e}get boundingBox(){return this.#e??=NodeGeometry.boundingBox(this.positions)}set boundingBox(e){this.#e=e}get boundingSphere(){return this.#t}set boundingSphere(e){this.#t=e}constructor(e,t,r=[],i=[]){super(e),this.triangleIndices=t,this.textureCoordinates=r,this.normals=i}}__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"positions",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"triangleIndices",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"textureCoordinates",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"normals",void 0),t.MeshGeometry=MeshGeometry}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){function r(t){return!e.Utils.isNull(t)&&"render"in t&&"function"==typeof t.render}function i(e){return r(e?.stage)}function n(e){return"transformMatrix"in e&&i(e)}function o(e){return"type"in e&&"up"in e&&"lookAt"in e&&i(e)}function s(t){return"positions"in t&&e.Utils.isArray(t.positions)}function a(t,r,i){const n=e.Geometry.LinearAlgebra.Vector3D.subtract(t,r),o=e.Geometry.LinearAlgebra.Vector3D.subtract(t,i),s=e.Geometry.LinearAlgebra.Vector3D.cross(n,o);return e.Geometry.LinearAlgebra.Vector3D.unit(s)}t.isStage=r,t.isRenderable=i,t.isUi3DObject=n,t.isCamera=o,t.isPerspectiveCamera=function(e){return o(e)&&"type"in e&&"perspective"===e.type},t.isOrthographicCamera=function(e){return o(e)&&"type"in e&&"orthographic"===e.type},t.isLight=function(e){return"type"in e&&("ambient"===e.type||"omni"===e.type||"direction"===e.type||"spot"==e.type)&&i(e)},t.isMesh=function(e){return"geometry"in e&&n(e)},t.isGeometry=s,t.isMeshGeometry=function(t){return("triangleIndices"in t&&e.Utils.isArray(t.triangleIndices)||"normals"in t&&e.Utils.isArray(t.normals)||"textureCoordinates"in t&&e.Utils.isArray(t.textureCoordinates))&&s(t)},t.isGroup=function(t){return"childRenderables"in t&&e.Utils.isArray(t.childRenderables)&&n(t)},t.computeSharpVertexNormals=function(t){const r=[];if(!e.Utils.isNullOrEmpty(t)){const e=t.triangleIndices;if(e.length%3!=0)throw new RangeError(`Invalid mesh geometry: ${e.length} is not multiple of 3.`);for(let i=2;i<e.length;i+=3){const n=e[i-2],o=e[i-1],s=e[i],l=a(t.positions[n],t.positions[o],t.positions[s]);r.push(l,l,l)}}t.normals=r},t.computePlaneNormal=a;class UI3DEvent extends e.CustomUIEvent{constructor(e,t,r,i){super(e,t,r),this.#i=i}#i;get point(){return this.#i}}t.UI3DEvent=UI3DEvent;t.DragEvent=class DragEvent extends UI3DEvent{};let l;t.RenderableEvent=class RenderableEvent extends UI3DEvent{constructor(e,t,r,i){super(e,{detail:t,bubbles:!0,cancelable:!0},r,i)}},function(e){e.Position="position",e.Transform="transform",e.Geometry="geometry",e.Children="children",e.Material="material",e.Light="light",e.Camera="camera",e.Visibility="visibility"}(l=t.StalePropertyFlag||(t.StalePropertyFlag={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){r.TAG_MIDDLE_NAME="3d",r.DEG2RAD=Math.PI/180;const i={OBJECT_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-object",LIGHT_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-light",PERSPECTIVE_CAMERA_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-perspective-camera",ORTHO_CAMERA_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-orthographic-camera",LINE_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-line",MESH_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-mesh",GROUP_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-group",DEFAULT_COORDS:{x:0,y:0,z:0}},n=e.Drawing3D.StalePropertyFlag;class RenderableElement extends t.PacemCrossItemsContainerElement{constructor(){super(...arguments),this.position=i.DEFAULT_COORDS,this.#n=[]}validate(e){return!1}findContainer(){return this.parent||this.stage}get stage(){return this._scene=this._scene||e.CustomElementUtils.findAncestorOfType(this,r.Pacem3DElement)}get parent(){return this._drawableParent=this._drawableParent||e.CustomElementUtils.findAncestor(this,e=>e instanceof RenderableElement)}disconnectedCallback(){delete this._scene,delete this._drawableParent,super.disconnectedCallback()}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"hide":this.setAsDirty(n.Visibility);break;case"items":this.setAsDirty(n.Children);break;case"position":this.setAsDirty(n.Position)}}#n;get flags(){return this.#n}setAsDirty(...e){for(let t of e)this.flags.includes(t)||this.flags.push(t);this.stage?.render(this)}}__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],RenderableElement.prototype,"position",void 0),__decorate([e.Watch({emit:!1,reflectBack:!0,converter:e.PropertyConverters.String})],RenderableElement.prototype,"tag",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],RenderableElement.prototype,"inert",void 0),r.RenderableElement=RenderableElement;class Ui3DElement extends RenderableElement{propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"transformMatrix":this.setAsDirty(n.Transform);break;case"translateZ":case"translateX":case"translateY":this.offset={x:this.translateX,y:this.translateY,z:this.translateZ};break;case"scaleX":case"scaleY":case"scaleZ":this.scale={x:this.scaleX,y:this.scaleY,z:this.scaleZ};break;case"scale":case"offset":case"rotate":this._computeTransformMatrix()}}_computeTransformMatrix(){const t=e.Geometry.LinearAlgebra.Matrix3D,r=e.Geometry.LinearAlgebra.Vector3D,i=e.Geometry.LinearAlgebra.Quaternion,n=this.scale??r.from(1,1,1);let o=t.scale(t.identity(),n);if(!e.Utils.isNull(this.rotate)){const e=i.toRotationMatrix(this.rotate);o=t.multiply(o,e)}const s=this.offset??r.from(0,0,0);o=t.translate(o,s),this.transformMatrix=o}}__decorate([e.Watch({emit:!1,converter:e.Drawing3D.QuaternionConverter})],Ui3DElement.prototype,"rotate",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DOrNumberConverter})],Ui3DElement.prototype,"scale",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DOrNumberConverter})],Ui3DElement.prototype,"offset",void 0),__decorate([e.Watch({emit:!1})],Ui3DElement.prototype,"transformMatrix",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleX",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleY",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleZ",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateX",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateY",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateZ",void 0),r.Ui3DElement=Ui3DElement;let o=class Pacem3DGroupElement extends Ui3DElement{validate(e){return e instanceof RenderableElement}#o=[];get childRenderables(){return this.#o}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"items":case"datasource":this.#o=r||[],this.setAsDirty(n.Children)}}};__decorate([e.Watch({emit:!1})],o.prototype,"datasource",void 0),o=__decorate([e.CustomElement({tagName:i.GROUP_SELECTOR})],o),r.Pacem3DGroupElement=o;let s=class Pacem3DMeshElement extends Ui3DElement{propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"geometry":this.setAsDirty(n.Geometry);break;case"material":case"backMaterial":this.setAsDirty(n.Material)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"geometry",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"material",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"backMaterial",void 0),s=__decorate([e.CustomElement({tagName:i.MESH_SELECTOR})],s),r.Pacem3DMeshElement=s;let a=class Pacem3DObjectElement extends Ui3DElement{propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"content"!==e&&"type"!==e||this.setAsDirty(n.Geometry,n.Material)}};__decorate([e.Watch({emit:!1})],a.prototype,"content",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],a.prototype,"type",void 0),a=__decorate([e.CustomElement({tagName:i.OBJECT_SELECTOR})],a),r.Pacem3DObjectElement=a;let l=class Pacem3DLightElement extends RenderableElement{constructor(){super(...arguments),this.intensity=.85,this.target=i.DEFAULT_COORDS,this.color="#fff",this.type="omni"}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"type":case"color":case"intensity":case"target":this.setAsDirty(n.Light)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],l.prototype,"intensity",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],l.prototype,"target",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],l.prototype,"color",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],l.prototype,"type",void 0),l=__decorate([e.CustomElement({tagName:i.LIGHT_SELECTOR})],l),r.Pacem3DLightElement=l;class Pacem3DCameraElement extends RenderableElement{constructor(){super(...arguments),this.near=.1,this.far=1e3,this.up=e.Geometry.LinearAlgebra.Vector3D.j(),this.lookAt=i.DEFAULT_COORDS}#s;_resetBoundingSphere(){const t=this.#s,r=this.position,i=this.lookAt,n=e.Utils.isNullOrEmpty(r)||e.Utils.isNullOrEmpty(i)?0:e.Geometry.LinearAlgebra.Vector3D.mag(e.Geometry.LinearAlgebra.Vector3D.subtract(r,i)),o=this.#s={center:i,radius:n};this.dispatchEvent(new e.PropertyChangeEvent({currentValue:o,propertyName:"boundingSphere",oldValue:t}))}get boundingSphere(){return this.#s}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"lookAt":case"position":this._resetBoundingSphere();case"near":case"far":case"up":this.setAsDirty(n.Camera)}}}__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Pacem3DCameraElement.prototype,"near",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Pacem3DCameraElement.prototype,"far",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],Pacem3DCameraElement.prototype,"up",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],Pacem3DCameraElement.prototype,"lookAt",void 0),r.Pacem3DCameraElement=Pacem3DCameraElement;let c=class Pacem3DPerspectiveCameraElement extends Pacem3DCameraElement{constructor(){super(...arguments),this.fov=45,this.aspect=1}get type(){return"perspective"}get aspectRatio(){return this.aspect}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"fov":case"aspect":this.setAsDirty(n.Camera)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],c.prototype,"fov",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],c.prototype,"aspect",void 0),c=__decorate([e.CustomElement({tagName:i.PERSPECTIVE_CAMERA_SELECTOR})],c),r.Pacem3DPerspectiveCameraElement=c;let u=class Pacem3DOrthographicCameraElement extends Pacem3DCameraElement{constructor(){super(...arguments),this.top=1,this.left=-1,this.bottom=-1,this.right=1}get type(){return"orthographic"}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"top":case"left":case"bottom":case"right":this.setAsDirty(n.Camera)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"top",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"left",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"bottom",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"right",void 0),u=__decorate([e.CustomElement({tagName:i.ORTHO_CAMERA_SELECTOR})],u),r.Pacem3DOrthographicCameraElement=u;class Pacem3DAdapterElement extends t.PacemEventTarget{}r.Pacem3DAdapterElement=Pacem3DAdapterElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){let i=class Pacem3DElement extends t.PacemItemsContainerElement{constructor(){super(...arguments),this._itemPropertyChangeHandler=e=>{const t=e.target;this.adapter&&this.adapter.updateItem(this,t),t.flags.splice(0)},this._clickHandler=t=>{let r=this;if(!r.interactive||e.Utils.isNull(r._lastHitResult))return;const i=t.type.replace(/^mouse/,""),n=r._lastHitResult,o=n.object,s=n.point;this._itemDispatch(o,s,i,t)},this._hitTestCallback=(t,r)=>{const i=this;if(t!=i._lastHitResult){if(t?.object!=i._lastHitResult?.object){const n=t?.object,o=i._lastHitResult?.object,s=t?.point;e.Utils.isNull(o)||this._itemDispatch(o,s,"out",r),e.Utils.isNull(n)||this._itemDispatch(n,s,"over",r)}i._lastHitResult=t}},this._moveHandler=e=>{let t=this;if(!t.adapter||!t.interactive)return;const r=t._resizer.currentSize,i="mousemove"===e.type?{x:e.pageX-r.left,y:e.pageY-r.top}:{x:-1,y:-1};t.adapter.raycast(this,i,r,r=>t._hitTestCallback(r,e))},this._resizeHandler=r=>{const i=this.#a,n=r.detail;if(!e.Utils.isNull(i)&&i.height===n.height&&i.width===n.width)return;this.#a=n;const o=this.adapter;e.Utils.isNull(o)||(this.adapter.invalidateSize(this,n),this.dispatchEvent(new t.ResizeEvent(n)))}}validate(e){return e instanceof r.RenderableElement}get stage(){return this._container}get scene(){return this.adapter&&this.adapter.getScene(this)}register(t){const r=super.register(t);return r&&(this._add(t),t.addEventListener(e.PropertyChangeEventName,this._itemPropertyChangeHandler,!1)),r}unregister(t){const r=super.unregister(t);return r&&(t.removeEventListener(e.PropertyChangeEventName,this._itemPropertyChangeHandler,!1),this._erase(t)),r}_refreshDatasource(e=this.datasource){this.adapter?.updateItem(this,void 0)}_buildUpDatasourceFromDOM(t=this.items){e.Utils.isNullOrEmpty(t)||(this.datasource=t.slice())}_add(e){this.adapter&&this.adapter.addItem(this,e)}_erase(e){this.adapter&&this.adapter.removeItem(this,e)}_initializeAdapter(t,r){return new Promise((i,n)=>{const o=this.datasource||[];e.Utils.isNull(t)||o.forEach(e=>t.removeItem(this,e)),e.Utils.isNull(this._container)||e.Utils.isNull(r)?i():r.initialize(this).then(e=>{(o||[]).forEach(e=>this._add(e)),i()},t=>{this.log(e.Logging.LogLevel.Error,t?.toString()),n(t)})})}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"adapter":this._initializeAdapter(t,r);break;case"items":this._buildUpDatasourceFromDOM(r);break;case"transparent":this.adapter?.invalidateSize(this,this.size);break;case"datasource":this._refreshDatasource(r);case"disabled":case"background":this.render()}}viewActivatedCallback(){super.viewActivatedCallback();const e=this._container,t=this._resizer;t.addEventListener("resize",this._resizeHandler,!1),t.target=e,this._initializeAdapter(null,this.adapter).then(t=>{e.addEventListener("mousemove",this._moveHandler,!1),e.addEventListener("click",this._clickHandler,!1),e.addEventListener("mouseup",this._clickHandler,!1),e.addEventListener("mousedown",this._clickHandler,!1),e.addEventListener("mouseout",this._moveHandler,!1),this._buildUpDatasourceFromDOM(),this.render()})}_itemDispatch(t,r,i,n){if(!e.Utils.isNull(t)){var o,s,a;n instanceof Event?s=n:o={item:t,offset:n},"string"==typeof i?a=i:(a=i.type,s=i.originalEvent);const c=r,u=()=>n instanceof Event?new e.Drawing3D.RenderableEvent(a,t,s,c):new e.Drawing3D.DragEvent(a,{detail:o,cancelable:a===e.UI.DragDropEventType.Init||a===e.UI.DragDropEventType.Drag},s,c),d=n instanceof Event?new e.Drawing3D.RenderableEvent("item"+a,t,s,c):new e.Drawing3D.DragEvent("item"+a,{detail:o,cancelable:a===e.UI.DragDropEventType.Init||a===e.UI.DragDropEventType.Drag},s,c);var l=!1;if(t instanceof EventTarget){const e=u();t.dispatchEvent(e),l=e.defaultPrevented}return t.stage.dispatchEvent(d),l||d.defaultPrevented}return!1}disconnectedCallback(){this.#l?.stop();const t=this._resizer,r=this._container;e.Utils.isNull(r)||(r.removeEventListener("click",this._clickHandler,!1),r.removeEventListener("mouseup",this._clickHandler,!1),r.removeEventListener("mousedown",this._clickHandler,!1),r.removeEventListener("mousemove",this._moveHandler,!1),r.removeEventListener("mouseout",this._moveHandler,!1)),e.Utils.isNull(t)||t.removeEventListener("resize",this._resizeHandler,!1),super.disconnectedCallback()}#a;get size(){return this.#a}render(t,r,i=performance.now()){if(e.Utils.isNull(t))this.#l?.stop(),this.#l=e.Animations.Timer.run(e=>this._doRender());else{const r=this.adapter;e.Utils.isNull(r)||r.updateItem(this,t)}}#l;_doRender(){if(!this.disabled&&!e.Utils.isNull(this.adapter)){const e=this.adapter.getScene(this);let t=new CustomEvent("prerender",{detail:{scene:e},cancelable:!0});this.dispatchEvent(t),t.defaultPrevented||(this.adapter.render(this),this.dispatchEvent(new CustomEvent("render",{detail:{scene:e}})))}}};__decorate([e.ViewChild(`.${e.PCSS}-3d`)],i.prototype,"_container",void 0),__decorate([e.ViewChild(e.P+"-resize")],i.prototype,"_resizer",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"interactive",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"transparent",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],i.prototype,"background",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Element})],i.prototype,"adapter",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],i.prototype,"datasource",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"orbit",void 0),i=__decorate([e.CustomElement({tagName:e.P+"-"+r.TAG_MIDDLE_NAME,shadow:e.Defaults.USE_SHADOW_ROOT,template:`<${e.P}-resize watch-position="true"></${e.P}-resize><div class="${e.PCSS}-3d"></div><${e.P}-content></${e.P}-content>`})],i),r.Pacem3DElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){class AdapterUtils{static isMeshGeometry(t){return"positions"in t&&e.Utils.isArray(t.positions)&&"triangleIndices"in t&&e.Utils.isArray(t.triangleIndices)}static isVector3D(e){return"x"in e&&"number"==typeof e.x&&"y"in e&&"number"==typeof e.y&&"z"in e&&"number"==typeof e.z}static isRgba(e){return"r"in e&&"number"==typeof e.r&&"g"in e&&"number"==typeof e.g&&"b"in e&&"number"==typeof e.b}static flattenVectorArray(e){const t=[];for(let r of e)AdapterUtils.isVector3D(r)?t.push(r.x,r.y,r.z):AdapterUtils.isRgba(r)?t.push(r.r,r.g,r.b,r.a??1):t.push(r.x,r.y);return t}static findCamera(t){return(t||[]).find(t=>e.Drawing3D.isCamera(t)&&!t.hide)}clipPixel(t,r){return r instanceof HTMLElement&&(r=e.Utils.offsetRect(r)),function(t,r){let i,n;if(e.Point.isPoint(t))i=t.x,n=t.y;else{const{page:o}=e.CustomEventUtils.getEventCoordinates(t),s={x:o.x-r.x,y:o.y-r.y};i=s.x,n=s.y}return{x:i/r.width*2-1,y:n/r.height*-2+1}}(t,r)}}t.AdapterUtils=AdapterUtils}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(e){let t;function r(e){return"shader"in e}!function(e){e.Basic="basic",e.Lambert="lambert",e.Phong="phong",e.Standard="standard",e.Line="line",e.Custom="custom"}(t=e.KnownShader||(e.KnownShader={})),e.isMaterial=r,e.isBasicMaterial=function(e){return r(e)&&e.shader===t.Basic},e.isLineMaterial=function(e){return r(e)&&e.shader===t.Line},e.isLambertMaterial=function(e){return r(e)&&e.shader===t.Lambert},e.isPhongMaterial=function(e){return r(e)&&e.shader===t.Phong},e.isStandardMaterial=function(e){return r(e)&&e.shader===t.Standard},e.isShaderMaterial=function(e){return r(e)&&e.shader===t.Custom}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){class MaterialElement extends t.PacemEventTarget{constructor(e){super(),this.#c=e}#c;get shader(){return this.#c}async _loadMap(t,r=this.material?.texture){if(e.Utils.isNull(r)||r.close(),e.Utils.isNullOrEmpty(t))return null;const i=await e.Imaging.loadImage(t);return e.Utils.isNull(i)?null:await createImageBitmap(i)}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"map":case"opacity":case"wireframe":case"color":case"hide":this.updateMaterial()}}viewActivatedCallback(){super.viewActivatedCallback(),this.updateMaterial()}updateMaterial(){this.createMaterial().then(t=>{this.material=e.Utils.extend(t,{flags:[e.Drawing3D.StalePropertyFlag.Material]})})}async createMaterial(){return{opacity:this.opacity??1,wireframe:this.wireframe??!1,color:this.color||e.Utils.Css.getVariableValue(`--${e.PCSS}-color-primary`),visible:!this.hide,map:this.map,texture:await this._loadMap(this.map),shader:this.shader,flags:[]}}}__decorate([e.Watch()],MaterialElement.prototype,"material",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],MaterialElement.prototype,"opacity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],MaterialElement.prototype,"wireframe",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],MaterialElement.prototype,"color",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],MaterialElement.prototype,"hide",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],MaterialElement.prototype,"map",void 0),r.MaterialElement=MaterialElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){function r(e){return t.AdapterUtils.flattenVectorArray(e)}const i="0.152.2",n={VERSION:i,API_URI:`https://unpkg.com/three@${i}/build/three.min.js`,ORBIT_URI:"https://unpkg.com/three@0.147.0/examples/js/controls/OrbitControls.js",LOADERS:[],DEFAULT_MATERIAL:function(){return new THREE.MeshStandardMaterial({color:"#069",flatShading:!0})}};function o(t){if(e.Utils.isNull(t))return null;const r={color:"string"==typeof t.color?t.color:e.Colors.stringify(t.color),opacity:t.opacity??1,transparent:!0,wireframe:t.wireframe??!1,visible:t.visible??!0},i=e.Utils.extend({},r,{wireframe:t.wireframe??!1}),n=e=>(t.map&&(e.map=(new THREE.TextureLoader).load(t.map,t=>{e.needsUpdate=!0})),e);if(e.Drawing3D.isStandardMaterial(t)){return n(new THREE.MeshStandardMaterial(e.Utils.extend(i,{roughness:t.roughness,metalness:t.metalness,emissive:t.emissiveColor,flatShading:t.flatShading,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isPhongMaterial(t)){return n(new THREE.MeshPhongMaterial(e.Utils.extend(i,{shininess:t.shininess,emissive:t.emissiveColor,flatShading:t.flatShading,specular:t.specularColor,reflectivity:t.reflectivity,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isLambertMaterial(t)){return n(new THREE.MeshLambertMaterial(e.Utils.extend(i,{emissive:t.emissiveColor,reflectivity:t.reflectivity,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isLineMaterial(t)){const i=t.dashArray&&t.dashArray[0]||null,n=t.dashArray&&t.dashArray.length>1&&t.dashArray[1]||i,o=e.Utils.extend(r,{linecap:t.lineCap??"round",linejoin:t.lineJoin??"round",linewidth:t.lineWidth??1});return e.Utils.isNullOrEmpty(t.dashArray)?new THREE.LineBasicMaterial(o):new THREE.LineDashedMaterial(e.Utils.extend({dashSize:i,gapSize:n},o))}if(e.Drawing3D.isMaterial(t)){return n(new THREE.MeshBasicMaterial(i))}return null}function s(t){if(e.Utils.isNullOrEmpty(t.content))throw new Error("Missing content.");{const e=t.type?.toLowerCase();if("obj"===e){return(new THREE.OBJLoader).parse(t.content)}return(new THREE.ObjectLoader).parse(t.content)}}function a(t){if(e.Utils.isNullOrEmpty(t.geometry))return null;return new(t.geometry instanceof e.Drawing3D.LineGeometry?THREE.Line:THREE.Mesh)}function l(){return"THREE"in window}let c=class Pacem3DThreeAdapterElement extends t.Pacem3DAdapterElement{constructor(){super(...arguments),this._renderer=null,this._camera=null,this._scene=null,this._orbitCtrls=null,this._objects=new WeakMap,this._dict={},this._orbitControlsDelegate=e=>{},this._ensureAndRefresh=(i,l,c)=>{if(l.matrixAutoUpdate=!1,l.visible=!i.hide){if(e.Drawing3D.isMesh(i)){let t=l;if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Geometry)>=0){t.geometry.dispose();const n=a(i);n.constructor.name!==t.constructor.name&&(c.remove(l),delete this._dict[l.id],l=t=n),t.geometry=function(t){const i=new THREE.BufferGeometry,n=r(t.positions);if(i.setAttribute("position",new THREE.Float32BufferAttribute(n,3)),t instanceof e.Drawing3D.MeshGeometry){e.Utils.isNullOrEmpty(t.triangleIndices)||i.setIndex(t.triangleIndices);const n=r(t.positions);i.setAttribute("position",new THREE.Float32BufferAttribute(n,3));const o=r(t.textureCoordinates);if(i.setAttribute("uv",new THREE.Float32BufferAttribute(o,2)),e.Utils.isNullOrEmpty(t.normals))i.computeVertexNormals();else{const e=r(t.normals);i.setAttribute("normal",new THREE.Float32BufferAttribute(e,3))}}return i}(i.geometry)}if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Material)>=0){if(e.Utils.isArray(t.material))for(let e of t.material)e.dispose();else t.material.dispose();t.material=function(t,r,i){const n=i,s=[],a=o(t);if(e.Utils.isNull(a)||(a.side=THREE.FrontSide,s.push(a)),!e.Utils.isNull(r))if(r==t)a.side=THREE.DoubleSide;else{const t=o(r);e.Utils.isNull(t)||(t.side=THREE.BackSide,s.push(t))}return n&&s.length>1?s:a}(i.material)||n.DEFAULT_MATERIAL()}}else if(i instanceof t.Pacem3DObjectElement&&(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Material)>=0||i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Geometry)>=0))l.parent&&l.parent.remove(l),l=s(i);else if(i instanceof t.Pacem3DGroupElement){if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Children)>=0){for(let e=l.children.length-1;e>=0;e--){const t=l.children[e];l.remove(t)}for(let e of i.items)this._addOrUpdateItem(e,l)}}else if(i instanceof t.Pacem3DLightElement){const t=l;i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Light)>=0&&(t.color=new THREE.Color(i.color),t.intensity=i.intensity)}let d=i.position;if(e.Drawing3D.isUi3DObject(i)&&!e.Utils.isNull(i.transformMatrix)&&(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Position)>=0||i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Transform)>=0)){const t=e.Geometry.LinearAlgebra.Matrix3D.from(1,0,0,0,0,1,0,0,0,0,1,0,d.x,d.y,d.z,1),r=e.Geometry.LinearAlgebra.Matrix3D.multiply(i.transformMatrix,t);THREE.Matrix4.prototype.set.apply(l.matrix,[(u=r).m11,u.m21,u.m31,u.offsetX,u.m12,u.m22,u.m32,u.offsetY,u.m13,u.m23,u.m33,u.offsetZ,u.m14,u.m24,u.m34,u.m44])}else i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Position)>=0&&(l.position.set(d.x,d.y,d.z),l.updateMatrix())}var u;return l.userData=i.tag,e.Utils.isNull(c.getObjectById(l.id))&&(c.add(l),this._dict[l.id]=i),i.flags.splice(0),l}}_assertMonoStage(t){if(t!=this._3d&&!e.Utils.isNull(this._3d))throw new Error("Stage mismatch.")}dispose(e){}snapshot(t,r,i,n){if(t!=this._3d)return Promise.resolve(null);const o=!e.Utils.isNullOrEmpty(r),s=i??(o?"image/jpeg":null),a=n??(o?.9:null);return new Promise((t,i)=>{this.render(),e.Utils.snapshotElement(this._stage,r,s,a).then(t)})}project(t,r){if(this._assertMonoStage(t),e.Utils.isNull(this._camera)||e.Utils.isNull(this._stage))return null;const i=this._stage,n=new THREE.Vector3(r.x,r.y,r.z),o=i.width/2,s=i.height/2,a=n.project(this._camera);return{x:a.x*o+o,y:-a.y*s+s}}zoomFit(t,...r){return this._assertMonoStage(t),new Promise((t,i)=>{const n=this._camera,o=this._objects,s=r.filter(e=>o.has(e)).map(e=>o.get(e));(e.Utils.isNull(n)||e.Utils.isNullOrEmpty(s))&&t(),function(t,r,i,n=1.333){const o=new THREE.Box3;for(const e of i)o.expandByObject(e);const s=o.getSize(new THREE.Vector3),a=o.getCenter(new THREE.Vector3),l=Math.max(s.x,s.y,s.z)/(2*Math.atan(Math.PI*t.fov/360)),c=l/t.aspect,u=n*Math.max(l,c),d=!e.Utils.isNull(r);var h;d&&(h=r.target.clone().sub(t.position).normalize().multiplyScalar(u),r.maxDistance=10*u,r.target.copy(a)),t.near=u/100,t.far=100*u,t.updateProjectionMatrix(),d&&(t.position.copy(r.target).sub(h),r.update())}(n,this._orbitCtrls,s),t()})}getScene(e){return this._assertMonoStage(e),this._scene}raycast(t,r,i,n){if(this._assertMonoStage(t),l()&&!e.Utils.isNull(this._camera)){const e=this._camera,t=new THREE.Vector2(r.x/i.width*2-1,-r.y/i.height*2+1),o=new THREE.Raycaster;o.setFromCamera(t,e);const s=o.intersectObjects(this._scene.children,!0);let a,l,c=0;for(;s.length>c&&(l=s[c++])&&(a=l.object);){if(this._dict[a.id].inert)continue;const e=l.point,t={x:e.x,y:e.y,z:e.z};return void n({object:this._dict[a.id],point:t})}}n(null)}async initialize(t){if(!e.Utils.isNull(this._stage))return this._stage;this._3d=t;const r=t.stage,i=this._stage=document.createElement("canvas");r.innerHTML="",r.appendChild(i),l()||(await e.CustomElementUtils.importjs(n.API_URI),await async function(...e){const t=Date.now();var r=!1;do{r=l();for(let t of e)r&&=t();r||await new Promise(e=>setTimeout(e,500))}while(!r&&Date.now()-t<3e4);if(!r)throw new Error("The wait for THREE adapter initialization timed out.")}(),await Promise.all([e.CustomElementUtils.importjs(n.ORBIT_URI)].concat(n.LOADERS.map(t=>e.CustomElementUtils.importjs(t))))),this._scene=new THREE.Scene,this.invalidateSize(t);let o=this._stage.width,s=this._stage.height,a={canvas:i,antialias:!0,stencil:!1,alpha:t.transparent??!0};if(this._renderer=new THREE.WebGLRenderer(a),this._renderer.setSize(o,s),t.background&&!t.transparent){let r=t.background;"string"==typeof r&&(r=e.Colors.parse(r));const i=new THREE.Color(r.r,r.g,r.b);this._renderer.setClearColor(i,r.a)}return this.orbit=t.orbit,i}_setCamera(e){this._camera=e,this.invalidateSize(this._3d),this._disposeOrbitControls(),this.orbit&&this._initOrbitControls()}propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"orbit"===e&&(!0===r?this._initOrbitControls():this._disposeOrbitControls())}_initOrbitControls(){const t=this._camera;if(e.Utils.isNull(this._3d)||e.Utils.isNull(t))return;(this._orbitCtrls=new THREE.OrbitControls(t,this._3d.stage)).addEventListener("change",this._orbitControlsDelegate)}_disposeOrbitControls(){const t=this._orbitCtrls;e.Utils.isNull(t)||(t.removeEventListener("change",this._orbitControlsDelegate),t.dispose())}_updateRenderer(t,r=this._renderer){if(t.transparent)r.setClearAlpha(0);else if(t.background){let i=t.background;"string"==typeof i&&(i=e.Colors.parse(i));const n=new THREE.Color(i.r,i.g,i.b);r.setClearColor(n,i.a)}else r.setClearColor(null)}invalidateSize(t,r=t.size){if(this._assertMonoStage(t),!l()||e.Utils.isNull(r))return;let i=r.width,n=r.height;this._stage.width=i,this._stage.height=n;let o=this._camera;o instanceof THREE.PerspectiveCamera&&(o.aspect=i/n,o.updateProjectionMatrix()),this._renderer&&(this._renderer.setSize(i,n),this._updateRenderer(t))}removeItem(t,r){this._assertMonoStage(t);const i=this._objects,n=i.get(r);e.Utils.isNull(n)||(this._scene.remove(n),delete this._dict[n.id],i.delete(r))}updateItem(t,r){this._assertMonoStage(t);const i=this._objects;if(!e.Utils.isNull(r.parent)&&i.has(r.parent)){const e=i.get(r.parent);this._addOrUpdateItem(r,e)}else this._addOrUpdateItem(r)}addItem(e,t){this._assertMonoStage(e),this._addOrUpdateItem(t)}_addOrUpdateItem(r,i=this._scene){if(l()&&!e.Utils.isNull(i))if(r instanceof t.Pacem3DCameraElement)if(r instanceof t.Pacem3DPerspectiveCameraElement){if(this._camera instanceof THREE.PerspectiveCamera)var n=this._camera;else n=new THREE.PerspectiveCamera;const t=new THREE.Vector3(r.lookAt.x,r.lookAt.y,r.lookAt.z);n.lookAt(t),n.position.set(r.position.x,r.position.y,r.position.z),n.fov=r.fov,n.aspect=r.aspect,n.near=r.near,n.far=r.far,this._setCamera(n);const i=this._orbitCtrls;e.Utils.isNull(i)||i.object!==n||(i.target=t,i.update())}else{if(!(r instanceof t.Pacem3DOrthographicCameraElement))throw new Error(`Camera ${r} not supported.`);{if(this._camera instanceof THREE.OrthographicCamera)var o=this._camera;else o=new THREE.OrthographicCamera;const t=new THREE.Vector3(r.lookAt.x,r.lookAt.y,r.lookAt.z);o.lookAt(t),o.position.set(r.position.x,r.position.y,r.position.z),o.left=r.left,o.right=r.right,o.top=r.top,o.bottom=r.bottom,o.near=r.near,o.far=r.far,this._setCamera(o);const i=this._orbitCtrls;e.Utils.isNull(i)||i.object!==o||(i.target=t,i.update())}}else if(this._objects.has(r)){const e=this._objects.get(r),t=this._ensureAndRefresh(r,e,i);t!=e&&this._objects.set(r,t)}else{const e=e=>{e&&(e=this._ensureAndRefresh(r,e,i),this._objects.set(r,e))};if(r instanceof t.Pacem3DObjectElement){e(s(r))}else if(r instanceof t.Pacem3DMeshElement){e(a(r))}else if(r instanceof t.Pacem3DLightElement){const t=function(e){var t;if("spot"===e.type){const r=new THREE.SpotLight;r.target.position.set(e.target.x,e.target.y,e.target.z),t=r}else t=new THREE.PointLight;return t}(r);e(t)}else if(r instanceof t.Pacem3DGroupElement){e(new THREE.Group)}}}render(){this._camera&&this._renderer.render(this._scene,this._camera)}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],c.prototype,"orbit",void 0),c=__decorate([e.CustomElement({tagName:e.P+"-3d-three-adapter"})],c),t.Pacem3DThreeAdapterElement=c}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){let t;!function(e){e.Mesh="mesh",e.Camera="camera",e.Texture="texture",e.Light="light"}(t=e.WGSLBindingType||(e.WGSLBindingType={}))}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.Buffers=class Buffers{static create(e,t,r=""){const i=e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});return new Float32Array(i.getMappedRange()).set(t),i.unmap(),i}static createUniform(e,t,r=""){return e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST})}static createStorage(e,t,r=""){return e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST})}static createIndexed(e,t,r=""){const i=e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});return new Uint16Array(i.getMappedRange()).set(t),i.unmap(),i}};e.BufferLayouts=class BufferLayouts{static createVertex(e=0,t=3,...r){const i=[];let n=0,o=0;for(let s of[t].concat(r))i.push({shaderLocation:e+o,offset:n*Float32Array.BYTES_PER_ELEMENT,format:`float32x${s}`}),n+=s,o++;return{arrayStride:n*Float32Array.BYTES_PER_ELEMENT,attributes:i,stepMode:"vertex"}}}}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){const i=e.Geometry.LinearAlgebra.Vector3D,n=e.Geometry.LinearAlgebra.Matrix3D,o={width:1,height:1};function s(e,t,r){const o=i.subtract(t,e),s=i.cross(r,o),a=i.cross(o,s);i.normalize(s),i.normalize(o),i.normalize(a);const l=-i.dot(s,e),c=-i.dot(a,e),u=-i.dot(o,e);return n.from(s.x,a.x,o.x,0,s.y,a.y,o.y,0,s.z,a.z,o.z,0,l,c,u,1)}function a(e,t){if(e<=0)throw new RangeError("Near plane distance must be positive.");if(t<=e)throw new RangeError("Far plane distance must be greater than near plane distance.")}r.Camera=class Camera{static create(e){if(t.isPerspectiveCamera(e))return new PerspectiveCamera(e);if(t.isOrthographicCamera(e))return new OrthographicCamera(e);throw new TypeError(`Camera type '${e.type}' not supported.`)}};class OrthographicCamera{constructor(e){this._camera=e}static view(e){return s(e.position,e.lookAt,e.up)}static projection(e,t=o){const r=e.position,s=e.lookAt,l=i.subtract(s,r);i.normalize(l);const c=i.dot(l,r),{height:u,width:d}=t,h=.5*c,p=h*(d/u),m=h,f=e.top*m,g=e.bottom*m,_=e.right*p;return function(e,t,r,i,o=.1,s=1e3){return a(o,s),n.from(2/(t-e),0,0,0,0,2/(r-i),0,0,0,0,1/(o-s),0,(e+t)/(e-t),(r+i)/(i-r),o/(o-s),1)}(e.left*p,_,f,g,e.near,e.far)}view(){return OrthographicCamera.view(this._camera)}projection(e){return OrthographicCamera.projection(this._camera,e)}}r.OrthographicCamera=OrthographicCamera;class PerspectiveCamera{constructor(e){this._camera=e}static view(e){return s(e.position,e.lookAt,e.up)}static projection(e,t=o){const r=t.width/t.height/e.aspectRatio;return function(e=120,t=1,r=.1,i=1e3){a(r,i);const o=Math.tan(.5*Math.PI*(1-e/180)),s=o/t,l=Number.isFinite(i),c=l?i/(r-i):-1,u=l?i*r/(r-i):-r;return n.from(s,0,0,0,0,o,0,0,0,0,c,-1,0,0,u,0)}(e.fov,r,e.near,e.far)}view(){return PerspectiveCamera.view(this._camera)}projection(e){return PerspectiveCamera.projection(this._camera,e)}}r.PerspectiveCamera=PerspectiveCamera}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.LABEL_PREFIX="pacem-3d-",e.U32_MAX=4294967295,e.VERTEX_BUFFER_INDEX_MESH_POSITION=0,e.VERTEX_BUFFER_INDEX_MESH_NORMAL=1,e.VERTEX_BUFFER_INDEX_MESH_UV=2,e.VERTEX_OUTPUT_LOCATION_NORMAL=0,e.VERTEX_OUTPUT_LOCATION_VERTEX=1,e.VERTEX_OUTPUT_LOCATION_UV=2,e.VERTEX_OUTPUT_LOCATION_INDEX=3,e.VERTEX_OUTPUT_LOCATION_RAY=4,e.UNIFORM_GROUP_INDEX_TRANSFORM=0,e.UNIFORM_GROUP_INDEX_CAMERA=1,e.STORAGE_GROUP_INDEX_LINE=2,e.UNIFORM_GROUP_INDEX_COLORPICKING=2,e.UNIFORM_BINDING_INDEX_TRANSFORM=0,e.UNIFORM_BINDING_INDEX_CAMERA=0,e.MATERIAL_GROUP_INDEX=2,e.UNIFORM_GROUP_INDEX_LIGHTING=e.MATERIAL_GROUP_INDEX+1,e.STORAGE_MATERIAL_INDEX=0,e.SAMPLER_BINDING_INDEX=1,e.TEXTURE_BINDING_INDEX=2,e.MATERIAL_REFERENCE="material",e.VERTEX_COLOR_REFERENCE="color",e.AMBIENT_COLOR_REFERENCE="ambient",e.LIGHTING_COLOR_REFERENCE="lighting"}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayIndexLocation:t.VERTEX_OUTPUT_LOCATION_RAY,storageMaterialGroupIndex:t.MATERIAL_GROUP_INDEX,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getBasicMaterialFragmentWgsl=function(n={},o=r){const s=e.Utils.extend({},r,o),a=i(n.definitions),l=i(n.bindings),c=function(e=[]){let r="";for(let i of e){const e=i.trim();e.endsWith(";")?r+=e+"\r\n\t":r+=`${t.VERTEX_COLOR_REFERENCE} = ${e};\r\n\t`}return r}(n.modifiers),u=t.VERTEX_COLOR_REFERENCE,d=t.LIGHTING_COLOR_REFERENCE,h=t.AMBIENT_COLOR_REFERENCE;return`// definitions\n\n${a}\n\n// bindings\n@group(${o.storageMaterialGroupIndex}) @binding(${o.storageMaterialBindingIndex}) var<storage, read> diffuseColor: vec4f;\n${l}\n\nconst empty = vec4f(0,0,0,0);\nconst white = vec4f(1,1,1,1);\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${s.outputNormalLocation}) normal: vec3f, // world-space normal\n @location(${s.outputVertexLocation}) vertex: vec3f, // world-space position\n @location(${s.outputUvLocation}) uv: vec2f, \n @location(${s.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index, \n @location(${s.outputRayIndexLocation}) ray: vec3f // ray (eye-to-vertex) vector\n) -> @location(0) vec4f {\n var ${u} = diffuseColor;\n var ${h}: vec4f = empty;\n var ${d}: vec4f = empty;\n\n // modifiers\n ${c}\n\n ${d} = select(white, ${d}, ${d}.a > 0);\n return ${u} * ${d} + ${h};\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputInstanceIndexLocation:0,outputVertexIndexLocation:1,storageMaterialGroupIndex:t.STORAGE_GROUP_INDEX_LINE+1,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getLineMaterialFragmentWgsl=function(t={},n=r){const o=e.Utils.extend({},r,n),s=i(t.definitions),a=i(t.bindings),l=function(e=[]){let t="";for(let r of e){const e=r.trim();e.endsWith(";")?t+=e+"\r\n":t+=`output = ${e};\r\n`}return t}(t.modifiers);return`// definitions\n${s}\n\n// bindings\n@group(${n.storageMaterialGroupIndex}) @binding(${n.storageMaterialBindingIndex}) var<storage, read> vertexColors: array<vec4f>;\n${a}\n\nfn getVertexColor(index: u32) -> vec4f {\n let numColors = arrayLength(&vertexColors);\n let vertexColorIndex = index % numColors;\n return vertexColors[vertexColorIndex];\n}\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${o.outputInstanceIndexLocation}) @interpolate(flat) instance: u32, // instance index\n @location(${o.outputVertexIndexLocation}) @interpolate(flat) index: u32 // vertex index\n) -> @location(0) vec4f {\n var output = getVertexColor(index);\n\n // modifiers\n ${l}\n\n return output;\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){r.Material=class Material{static create(e){if(t.isBasicMaterial(e))return new BasicMaterial(e);if(t.isLineMaterial(e))return new LineMaterial(e);throw new TypeError(`Material type '${e.shader}' not supported.`)}};const i={};class MaterialBase{constructor(t){if(e.Utils.isNull(this.#u=t))throw new ReferenceError("Null material provided.")}#u;get material(){return this.#u}get wgsl(){return i}buffer({device:e},t=r.LABEL_PREFIX+"material-"+this.shader+"-buffer"){const{r:i,g:n,b:o,a:s}=this._diffuseColor(),a=new Float32Array([i,n,o,s]);return{buffer:r.Buffers.createStorage(e,a,t),value:a,version:performance.now()}}_diffuseColor(){const{visible:t,opacity:r,color:i}=this.material;if(!(t??1))return{r:0,g:0,b:0,a:0};const n="string"==typeof i?e.Colors.parse(i):i??{r:1,g:1,b:1,a:1};return r>=0&&r<=1?e.Utils.extend(n,{a:n.a*r}):n}}class BasicMaterial extends MaterialBase{get shader(){return t.KnownShader.Basic}constructor(e){if(super(e),e.shader!=this.shader)throw new TypeError("Basic material expected.")}texture({device:t},r="texture"){const i=this.material;if("texture"===r&&!e.Utils.isNull(i.texture)){const e=i.texture;return{texture:t.createTexture({format:"rgba8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_DST,size:[e.width,e.height]}),source:e}}return null}static{this.fragment=r.getBasicMaterialFragmentWgsl}}r.BasicMaterial=BasicMaterial;class LineMaterial extends MaterialBase{get shader(){return t.KnownShader.Line}constructor(e){if(super(e),e.shader!=this.shader)throw new TypeError("Line material expected.")}buffer(e,t){if("line"===t){const{device:t,canvas:i}=e,n=this.material,o=new Float32Array([i.clientWidth,i.clientHeight,n.lineWidth/2]);return{buffer:r.Buffers.createUniform(t,o,r.LABEL_PREFIX+"line-"+this.shader+"-buffer"),value:o,version:performance.now()}}return super.buffer(e)}texture(e){return null}static{this.fragment=r.getLineMaterialFragmentWgsl}}r.LineMaterial=LineMaterial}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={uv:"uv"};t.textureMap=function(i=r,n,o=t.SAMPLER_BINDING_INDEX){const s=e.Utils.uniqueCode(),a=`sampler_${s}`,l=`tex_${s}`,c=e.Utils.extend({},r,i),u=c.inputColor,d=c.outputColors;if(e.Utils.isNullOrEmpty(u))throw new Error("Must provide either input and output vertex color parameter names.");const h=d?d.map((e,t)=>0===t?`${e} = textureSample(${l}, ${a}, ${c.uv}) * ${u};`:`${e} = ${d[0]};`):[`textureSample(${l}, ${a}, ${c.uv}) * ${u}`];return{bindings:[`@group(${n}) @binding(${o}) var ${a}: sampler;`,`@group(${n}) @binding(${o+1}) var ${l}: texture_2d<f32>;`],modifiers:h}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayLocation:t.VERTEX_OUTPUT_LOCATION_RAY,inputPositionLocation:t.VERTEX_BUFFER_INDEX_MESH_POSITION,inputNormalLocation:t.VERTEX_BUFFER_INDEX_MESH_NORMAL,inputUvLocation:t.VERTEX_BUFFER_INDEX_MESH_UV,uniformViewBindingIndex:t.UNIFORM_BINDING_INDEX_CAMERA,uniformViewGroupIndex:t.UNIFORM_GROUP_INDEX_CAMERA,uniformWorldBindingIndex:t.UNIFORM_BINDING_INDEX_TRANSFORM,uniformWorldGroupIndex:t.UNIFORM_GROUP_INDEX_TRANSFORM};t.getMeshVertexWgsl=function(t=r){const i=e.Utils.extend({},r,t);return`struct VertexOutput {\n @builtin(position) position : vec4f, // clip space position\n @location(${i.outputNormalLocation}) normal: vec3f, // world space normal\n @location(${i.outputVertexLocation}) vertex : vec3f, // world space position\n @location(${i.outputUvLocation}) uv : vec2f, // texture coordinates\n @location(${i.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index\n @location(${i.outputRayLocation}) ray : vec3f, // eye-to-point\n}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\n@group(${i.uniformWorldGroupIndex}) @binding(${i.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${i.uniformViewGroupIndex}) @binding(${i.uniformViewBindingIndex}) var<uniform> camera: Camera;\n\n@vertex fn main(@location(${i.inputPositionLocation}) position: vec3f,\n @location(${i.inputNormalLocation}) normal: vec3f,\n @location(${i.inputUvLocation}) uv: vec2f,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n let position4 = vec4f(position, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n let worldPosition = (worldTransform * position4).xyz;\n return VertexOutput(\n worldViewProjectionTransform * position4,\n transforms.normal * normal,\n worldPosition,\n uv,\n index,\n normalize(worldPosition - camera.position)\n );\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={inputPositionLocation:t.VERTEX_BUFFER_INDEX_MESH_POSITION,outputInstanceIndexLocation:0,outputVertexIndexLocation:1,storagePositionsGroupIndex:t.STORAGE_GROUP_INDEX_LINE,storagePositionsBindingIndex:0,uniformDimensionsGroupIndex:t.STORAGE_GROUP_INDEX_LINE,uniformDimensionsBindingIndex:1,uniformViewGroupIndex:t.UNIFORM_GROUP_INDEX_CAMERA,uniformViewBindingIndex:t.UNIFORM_BINDING_INDEX_CAMERA,uniformWorldGroupIndex:t.UNIFORM_GROUP_INDEX_TRANSFORM,uniformWorldBindingIndex:t.UNIFORM_BINDING_INDEX_TRANSFORM};function i(e){return`struct VertexOutput {\n @builtin(position) position : vec4f, // clip space position\n @location(${e.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index\n @location(${e.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index\n}`}t.getDefaultLineVertexWgsl=function(t=r){const n=e.Utils.extend({},r,t);return`${i(n)}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\n@group(${n.uniformWorldGroupIndex}) @binding(${n.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${n.uniformViewGroupIndex}) @binding(${n.uniformViewBindingIndex}) var<uniform> camera: Camera;\n@group(${n.storagePositionsGroupIndex}) @binding(${n.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;\n\n@vertex fn main(@builtin(instance_index) instance: u32,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n \n let x = positions[3u * index + 0u];\n let y = positions[3u * index + 1u];\n let z = positions[3u * index + 2u];\n let position4 = vec4f(x, y, z, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n let worldPosition = (worldTransform * position4).xyz;\n return VertexOutput(\n worldViewProjectionTransform * position4,\n instance,\n index);\n}`},t.getFatLineVertexWgsl=function(t=r){const n=e.Utils.extend({},r,t);return`${i(n)}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\nstruct Pixels {\n viewportWidth: f32,\n viewportHeight: f32,\n halfLineWidth: f32\n}\n\n@group(${n.uniformWorldGroupIndex}) @binding(${n.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${n.uniformViewGroupIndex}) @binding(${n.uniformViewBindingIndex}) var<uniform> camera: Camera;\n@group(${n.storagePositionsGroupIndex}) @binding(${n.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;\n@group(${n.uniformDimensionsGroupIndex}) @binding(${n.uniformDimensionsBindingIndex}) var<uniform> dimensions: Pixels;\n\nfn computeClipPosition(index: u32) -> vec4f {\n let x = positions[3u * index + 0u];\n let y = positions[3u * index + 1u];\n let z = positions[3u * index + 2u];\n let position4 = vec4f(x, y, z, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n return worldViewProjectionTransform * position4;\n}\n\nfn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {\n\n let viewportSize = vec2f(dimensions.viewportWidth, dimensions.viewportHeight);\n let normalizedSize = normalize(viewportSize);\n let halfThickness = dimensions.halfLineWidth / dimensions.viewportWidth;\n let p0ndc = p0.xyz / p0.w;\n let p1ndc = p1.xyz / p1.w;\n let dir = normalize((p1ndc - p0ndc).xy);\n let offsetX = halfThickness * 2.0 / normalizedSize.x;\n let offsetY = halfThickness * 2.0 / normalizedSize.y;\n\n // perp\n let perp0 = vec2f(-dir.y * offsetX, dir.x * offsetY);\n let perp1 = perp0;\n\n /*\n \n position0-0 -----*----- position0-1\n |\\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\|\n position1-0 -----*----- position1-1\n\n indexes:\n ------------\n p0-0 -> 0, 3\n p0-1 -> 5\n p1-0 -> 1\n p1-1 -> 2, 4\n */\n\n var outPos: vec2f;\n var w = p0.w;\n var z = p0.z;\n if (index == 0 || index == 3){\n outPos = p0ndc.xy - perp0;\n }\n else if (index == 1){\n outPos = p1ndc.xy - perp1;\n w = p1.w;\n z = p1.z;\n }\n else if (index == 5){\n outPos = p0ndc.xy + perp0;\n }\n else { //if (index == 2 || index == 4)\n outPos = p1ndc.xy + perp1;\n w = p1.w;\n z = p1.z;\n }\n\n // return vec4f(outPos , 0, 1.0);\n return vec4f(outPos * w, z, w);\n}\n\n@vertex fn main(@builtin(instance_index) instance: u32,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n \n // vertex index starting at 1\n let position0 = computeClipPosition(instance);\n let position1 = computeClipPosition(instance + 1);\n\n // apply offset\n let position = computeOffsetPosition(position0, position1, index);\n\n return VertexOutput(\n position,\n instance,\n index\n );\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){const i=r.LABEL_PREFIX,n={multisample:!0,packedVertices:!0,primitive:{topology:"triangle-list",frontFace:"ccw",cullMode:"back"}},o=e=>{};class RenderPipeline{static{this._memoizer=new WeakMap}static dispose(t){const r=this._memoizer,i=r.get(t);e.Utils.isNull(i)||(i.clear(),r.delete(t))}static createColorPicking(e,t){const r=RenderPipeline.create(e,t);return r instanceof MeshRenderPipelineClass||r instanceof LineRenderPipelineClass?{frame:r.raycast}:null}static create(r,[i,n,...o],s){const a=RenderPipeline._memoizer;let l=a.get(r);if(e.Utils.isNull(l)&&a.set(r,l=new Map),e.Utils.isNull(i))throw new Error("Pipeline not implemented, given the provided arguments.");if(t.isMesh(i.item)){const a=t.isMeshGeometry(i.item.geometry),c=!a&&t.isLineMaterial(i.item.material);if(!a&&!c)throw new Error("Pipeline not implemented, given the provided mesh argument.");const u=a?new MeshWGSLBuilder(i,n,...o):new LineWGSLBuilder(i,n),d=u.key,h=l.get(d);if(h)return h;const p=a?new MeshRenderPipelineClass(r,u):new LineRenderPipelineClass(r,u);p.build(s);const m=p;return e.Utils.extend(m,{id:d+"-"+r.canvas.width+"x"+r.canvas.height+"-"+e.Utils.Dates.now().toISOString()}),l.set(d,m),m}throw new ReferenceError("Pipeline not implemented, given thst the first argument is not a mesh.")}}r.RenderPipeline=RenderPipeline;class RenderPipelineCache{constructor(){this.#d=new Map}#d;ensureBindGroup({device:t},r,i,n,o,s,a=()=>{}){const l=this.#d,c="string"==typeof r?r:r.key;let u=l.get(c);if(e.Utils.isNull(u)&&l.set(c,u=new Map),n||!u.has(s)){const e=i.map((e,t)=>({binding:t,resource:{buffer:e}})),r={label:s,layout:o,entries:e};a(r);const n=t.createBindGroup(r);return u.set(s,n),n}return u.get(s)}}class MeshWGSLBuilder{#h=[];#p;#m;#f=new Map;#g={shader:"basic",lights:""};constructor(...e){this.add(...e)}reset(){this.#h.splice(0),this.#p=null,this.#f.clear(),this.#g={shader:"basic",lights:""}}add(...r){for(let i of r??[])if(t.isMesh(i.item)){if(!e.Utils.isNull(this.#p))throw new Error("Mesh already added.");{this.#p=i;const e=i.item.material??{shader:t.KnownShader.Basic};this.#g.shader=e.shader+"-"+(e.map?"map":"nomap")}}else if(t.isLight(i.item)){this.#h.push(i),this.#g.lights+="-"+i.item.type}else{if(!t.isCamera(i.item))throw new Error("Unknown object type.");this.#m??=i}}build(){const e=this._computeBasicData(),t=this.key;return{vertex:this.vertex(),fragment:this.fragment(e),key:t,bindings:(...e)=>MeshWGSLBuilder.prototype.bindgroup.apply(this,e),metadata:{lightCount:this.#h.length,mapCount:this.#p.item.material?.map?1:0}}}get key(){const{shader:e,lights:t}=this.#g;return"mesh-"+e+t}bindgroup(t,r,i){const n=this.#f.get(t);if(e.Utils.isNull(n))return null;if(e.Utils.isNullOrEmpty(r))return n;const o=n.filter(e=>e.key===r);return isNaN(i)?o:i>=0&&i<n.length?o[i]:o}vertex(){return r.getMeshVertexWgsl()}_computeBasicData(){const i=this.#p.item,n=this.#h,o=i.material;return{hasTexture:!e.Utils.isNull(o?.texture),hasLighting:!e.Utils.isNullOrEmpty(n),shader:e.Utils.isNull(i)?t.KnownShader.Basic:i.material?.shader??t.KnownShader.Basic,materialBindGroupIndex:r.MATERIAL_GROUP_INDEX,lightingBindGroupIndex:r.UNIFORM_GROUP_INDEX_LIGHTING}}_computeBindGroupsAndReferences(e=this._computeBasicData()){const{hasTexture:t,materialBindGroupIndex:i,lightingBindGroupIndex:n}=e,o=this.#f,s=this.#h,a={key:"objectWorldTransform",group:r.UNIFORM_GROUP_INDEX_TRANSFORM,binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,type:"buffer"},l={key:"material",group:i,binding:r.STORAGE_MATERIAL_INDEX,type:"buffer"};t?o.set(r.WGSLBindingType.Mesh,[a,l,{key:"texture",group:i,type:"texture"}]):o.set(r.WGSLBindingType.Mesh,[a,l]),o.set(r.WGSLBindingType.Camera,[{key:"cameraViewTransform",group:r.UNIFORM_GROUP_INDEX_CAMERA,binding:r.UNIFORM_BINDING_INDEX_CAMERA,type:"buffer"}]);const c=s.map((e,t)=>({key:"light",group:n,binding:t,type:"buffer"}));c.push(...c)}fragment(i=this._computeBasicData()){this._computeBindGroupsAndReferences(i);const n={definitions:[],bindings:[],modifiers:[]},o=t=>{for(let e of t.definitions??[])-1===n.definitions.indexOf(e)&&n.definitions.push(e);e.Utils.isNullOrEmpty(t.bindings)||n.bindings.push(...t.bindings),e.Utils.isNullOrEmpty(t.modifiers)||n.modifiers.push(...t.modifiers)};if(i.shader===t.KnownShader.Basic){if(i.hasTexture){const e=i.materialBindGroupIndex;o(r.textureMap({inputColor:r.VERTEX_COLOR_REFERENCE,outputColors:[r.VERTEX_COLOR_REFERENCE],uv:"uv"},e))}let e=0;const t=this.#h;for(let n of t){switch(n.item.type){case"direction":o(r.directionalLight({outputColor:r.LIGHTING_COLOR_REFERENCE,normal:"normal"},i.lightingBindGroupIndex,e));break;case"omni":o(r.omniLight({outputColor:r.LIGHTING_COLOR_REFERENCE,normal:"normal",position:"vertex"},i.lightingBindGroupIndex,e));break;case"ambient":o(r.ambientLight({inputColor:r.VERTEX_COLOR_REFERENCE,outputColor:r.AMBIENT_COLOR_REFERENCE},i.lightingBindGroupIndex,e))}e++}return r.BasicMaterial.fragment(n)}}}const s=(e,t)=>{t.fresh&&e.queue.writeBuffer(t.buffer,0,t.value)};class MeshRenderPipelineClass{constructor(e,t,n=new RenderPipelineCache){this._context=e,this._builder=t,this._cache=n,this._ensureU32idBindGroup=(e,t,r)=>this._cache.ensureBindGroup(this._context,e,[t],r,this._pickBindGroupLayout,i+"mesh-colorpick-bind-group"),this._ensureMaterialBindGroup=(e,t,n,o,s=r.MATERIAL_GROUP_INDEX)=>{const a=this._bindGroupLayouts[s],l=i+"material-bind-group";if(a.label!==i+"material-bind-group-layout")throw new Error("BindGroupLayout mismatch!");return this._cache.ensureBindGroup(this._context,e,[t],o,a,l,e=>{const{device:t}=this.context,i=e.entries;n&&i.push({binding:r.SAMPLER_BINDING_INDEX,resource:t.createSampler({addressModeU:"repeat",addressModeV:"repeat",magFilter:"linear",minFilter:"linear"})},{binding:r.TEXTURE_BINDING_INDEX,resource:n.createView()})})},this._ensureWorldTransformBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_TRANSFORM,s=!1)=>{const a=this._bindGroupLayouts[o];if(a.label!==i+"mesh-transforms-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const l=e.key+"-"+(s?1:0),c=`${i}${s?"colorpick":"mesh"}-transforms-bind-group`;return this._cache.ensureBindGroup(this._context,l,[t],n,a,c)},this._ensureCameraProjectionBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_CAMERA,s=!1)=>{const a=this._bindGroupLayouts[o],l=e.key+"-"+(s?1:0),c=`${i}${s?"colorpick":"mesh"}-view-bind-group`;return this._cache.ensureBindGroup(this._context,l,[t],n,a,c)},this._ensureLightingBindGroup=(e,t,n=r.UNIFORM_GROUP_INDEX_LIGHTING)=>{const o=this._bindGroupLayouts[n],s=e.map(e=>e.id).join(":"),a=e.map(e=>e.buffer.buffer);return this._cache.ensureBindGroup(this._context,s,a,t,o,i+"mesh-lighting-bind-group")},this._bindGroupLayouts=[],this._bindVertex=o,this._bindPicker=o,this._bindWorldTransform=o,this._bindRaycastWorldTransform=o,this._bindCameraProjection=o,this._bindRaycastCameraProjection=o,this._bindLighting=o,this._bindMaterial=o,this.set=e=>{throw new Error("Deprecated.")},this.bind=(e,...t)=>{throw new Error("Deprecated.")},this.draw=(e,...t)=>{throw new Error("Deprecated.")},this.frame=(e,t,r,...i)=>{e.setPipeline(this._pipeline);try{this._bindVertex(e,t),this._bindWorldTransform(e,t),this._bindMaterial(e,t),this._bindCameraProjection(e,r),this._bindLighting(e,...i);const n=t.item.geometry;e.draw(n.triangleIndices?.length||n.positions.length)}catch(e){console.error("Pacem.Drawing3D.FrameException",e)}},this.raycast=(e,t,r)=>{e.setPipeline(this._pickPipeline);try{this._bindVertex(e,t),this._bindRaycastWorldTransform(e,t),this._bindRaycastCameraProjection(e,r),this._bindPicker(e,t);const i=t.item.geometry;e.draw(i.triangleIndices.length)}catch(e){}},this._key=t.key}get context(){return this._context}get key(){return this._key}build(t){const o=e.Utils.extend({},n,t??{}),a=this._builder.build(),l=this._context,c=l.device,u={module:c.createShaderModule({code:a.vertex}),buffers:o.packedVertices?[r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_POSITION,3,3,2)]:[r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_POSITION,3),r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_NORMAL,3),r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_UV,2)]},d=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"mesh-transforms-bind-group-layout"}),h=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_CAMERA,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"mesh-view-bind-group-layout"}),p=[d,h],m={module:c.createShaderModule({code:a.fragment}),targets:[{format:l.format,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{}}}]},f=p.length,g=[{binding:r.STORAGE_MATERIAL_INDEX,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}}],{mapCount:_}=a.metadata,y=_>0;y&&g.push({visibility:GPUShaderStage.FRAGMENT,binding:r.SAMPLER_BINDING_INDEX,sampler:{}},...Array(_).keys().map(e=>({visibility:GPUShaderStage.FRAGMENT,binding:r.SAMPLER_BINDING_INDEX+1+e,texture:{}})));const E={label:i+"material-bind-group-layout",entries:g},b=c.createBindGroupLayout(E);p.push(b);const v=p.length,{lightCount:P}=a.metadata,x=P>0;if(x){const e=c.createBindGroupLayout({entries:[...Array(P).keys()].map((e,t)=>({visibility:GPUShaderStage.FRAGMENT,binding:t,buffer:{type:"uniform"}})),label:i+"lighting-bind-group-layout"});p.push(e)}const C={label:i+"mesh-render-pipeline",vertex:u,fragment:m,layout:c.createPipelineLayout({label:i+"mesh-render-pipeline-layout",bindGroupLayouts:this._bindGroupLayouts=p}),primitive:o.primitive};o.multisample&&(C.multisample={count:4},C.depthStencil={depthCompare:"less",format:"depth24plus",depthWriteEnabled:!0}),this._pipeline=c.createRenderPipeline(C);const w=this._pickBindGroupLayout=c.createBindGroupLayout({label:i+"mesh-colorpick-bind-group-layout",entries:[{visibility:GPUShaderStage.FRAGMENT,binding:0,buffer:{type:"uniform"}}]}),D={label:i+"mesh-colorpick-pipeline",vertex:u,fragment:{module:c.createShaderModule({code:r.getColorPickingFragmentWgsl(r.UNIFORM_GROUP_INDEX_COLORPICKING)}),targets:[{format:"r32uint"}]},layout:c.createPipelineLayout({label:i+"mesh-colorpick-pipeline-layout",bindGroupLayouts:[d,h,w]}),primitive:o.primitive,depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}};this._pickPipeline=c.createRenderPipeline(D);this._bindVertex=o.packedVertices?(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided.`);const{buffer:o}=n.buffer(l,"geometry");t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_POSITION,o)}:(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided.`);const{buffer:o}=n.buffer(l,"geometryPositions"),{buffer:s}=n.buffer(l,"geometryNormals"),{buffer:a}=n.buffer(l,"geometryTexCoords");t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_POSITION,o),t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_NORMAL,s),t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_UV,a)};const R=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=i.buffer(l,"objectWorldTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Mesh,"objectWorldTransform",0),h=this._ensureWorldTransformBindGroup(i.item,u,o.fresh,d,n);t.setBindGroup(d,h)};this._bindWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!1)},this._bindRaycastWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!0)};const N=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing view projection buffers was provided.`);const o=i.buffer(l,"cameraViewTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Camera,"cameraViewTransform",0),h=this._ensureCameraProjectionBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!1)},this._bindRaycastCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!0)},this._bindMaterial=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex colors was provided.`);const o=n.buffer(l,"material"),a=o.buffer;s(c,o);let u=n.texture(l);const d=u?.texture,h=this._ensureMaterialBindGroup(n.item,a,d,o.fresh,f);t.setBindGroup(f,h),y&&c.queue.copyExternalImageToTexture({source:u.source,flipY:!0},{texture:d},{width:d.width,height:d.height})},this._bindLighting=(e,...t)=>{if(x){const r=Array.from(t),i=r.map(e=>({buffer:e.buffer(l,"light"),id:e.item.key})),n=this._ensureLightingBindGroup(i,r.some(e=>e.item.flags.length>0),v);for(let e of i)s(c,e.buffer);e.setBindGroup(v,n)}},this._bindPicker=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=n.buffer(l,"u32id"),a=o.buffer;s(c,o);const u=r.UNIFORM_GROUP_INDEX_COLORPICKING,d=this._ensureU32idBindGroup(n.item,a,!1);t.setBindGroup(u,d)}}}class LineWGSLBuilder{#_;#m;#f=new Map;constructor(...e){this.add(...e)}reset(){this.#_=null,this.#f.clear()}add(...r){for(let i of r??[])if(t.isMesh(i.item)){if(!e.Utils.isNull(this.#_))throw new Error("Line already added.");this.#_=i}else if(t.isCamera(i.item))this.#m??=i;else if(!t.isLight(i.item))throw new Error("Unknown object type.")}build(){const e=this._computeBasicData(),t=this.key;return{vertex:this.vertex(e),fragment:this.fragment(e),key:t,bindings:(...e)=>LineWGSLBuilder.prototype.bindgroup.apply(this,e),metadata:{thickness:e.thickness,dashPattern:e.dashPattern}}}get key(){const e=(this.#_?.item).material?.lineWidth>1;return t.KnownShader.Line+(e?"-fat":"")}bindgroup(t,r,i){const n=this.#f.get(t);if(e.Utils.isNull(n))return null;if(e.Utils.isNullOrEmpty(r))return n;const o=n.filter(e=>e.key===r);return isNaN(i)?o:i>=0&&i<n.length?o[i]:o}vertex(e=this._computeBasicData()){return e.thickness>1?r.getFatLineVertexWgsl():r.getDefaultLineVertexWgsl()}_computeBasicData(){const r=this.#_.item,i=e.Utils.isNull(r)?t.KnownShader.Line:r.material?.shader??t.KnownShader.Line,n=r.material,o=n?.lineWidth??1,s=n?.dashArray;return{shader:i,thickness:o,dashPattern:s}}_computeBindGroupsAndReferences(e=this._computeBasicData()){const t=this.#f,i={key:"objectWorldTransform",group:r.UNIFORM_GROUP_INDEX_TRANSFORM,binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,type:"buffer"},n={key:"material",group:r.STORAGE_GROUP_INDEX_LINE+1,binding:r.STORAGE_MATERIAL_INDEX,type:"buffer"},o={key:"geometryPositions",group:r.STORAGE_GROUP_INDEX_LINE,binding:0,type:"buffer"},s={key:"line",group:r.STORAGE_GROUP_INDEX_LINE,binding:1,type:"buffer"};t.set(r.WGSLBindingType.Mesh,[i,n,o,s]),t.set(r.WGSLBindingType.Camera,[{key:"cameraViewTransform",group:r.UNIFORM_GROUP_INDEX_CAMERA,binding:r.UNIFORM_BINDING_INDEX_CAMERA,type:"buffer"}])}fragment(e=this._computeBasicData()){this._computeBindGroupsAndReferences(e);const i={definitions:[],bindings:[],modifiers:[]};if(e.shader===t.KnownShader.Line)return r.LineMaterial.fragment(i)}}class LineRenderPipelineClass{#y;constructor(e,t,n=new RenderPipelineCache){this._lineBuilder=t,this._cache=n,this._ensureLineU32idBindGroup=(e,t,r)=>{const n=this.context;return this._cache.ensureBindGroup(n,e,[t],r,this._pickLineBindGroupLayout,i+"line-colorpick-bind-group")},this._ensureLineMaterialBindGroup=(e,t,n,o=r.MATERIAL_GROUP_INDEX)=>{const s=this._bindLineGroupLayouts[o];if(s.label!==i+"line-material-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const a=this.context;return this._cache.ensureBindGroup(a,e,[t],n,s,i+"line-material-bind-group")},this._ensureLinePositionsBindGroup=(e,t,r,n)=>{const o=this._bindLineGroupLayouts[n];if(o.label!==i+"line-positions-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const s=this.context;return this._cache.ensureBindGroup(s,e,t,r,o,i+"line-positions-bind-group")},this._ensureLineWorldTransformBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_TRANSFORM,s=!1)=>{const a=this._bindLineGroupLayouts[o];if(a.label!==i+"line-transforms-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const l=e.key+"-line-"+(s?1:0),c=`${i}${s?"colorpick":""}-line-transforms-bind-group`,u=this.context;return this._cache.ensureBindGroup(u,l,[t],n,a,c)},this._ensureLineCameraProjectionBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_CAMERA,s=!1)=>{const a=this._bindLineGroupLayouts[o],l=e.key+"-line-"+(s?1:0),c=`${i}${s?"colorpick":""}-line-view-bind-group`,u=this.context;return this._cache.ensureBindGroup(u,l,[t],n,a,c)},this._bindLineGroupLayouts=[],this._bindLinePositions=o,this._bindLinePicker=o,this._bindLineWorldTransform=o,this._bindLineRaycastWorldTransform=o,this._bindLineCameraProjection=o,this._bindLineRaycastCameraProjection=o,this._bindLineMaterial=o,this._drawLine=o,this.set=e=>{throw new Error("Deprecated.")},this.bind=(e,...t)=>{throw new Error("Deprecated.")},this.draw=(e,...t)=>{throw new Error("Deprecated.")},this.frame=(e,t,r)=>{e.setPipeline(this._linePipeline);try{this._bindLineWorldTransform(e,t),this._bindLineCameraProjection(e,r),this._bindLinePositions(e,t),this._bindLineMaterial(e,t),this._drawLine(e,t)}catch(e){console.error("Pacem.Drawing3D.FrameException",e)}},this.raycast=(e,t,r)=>{e.setPipeline(this._pickLinePipeline);try{this._bindLineRaycastWorldTransform(e,t),this._bindLineRaycastCameraProjection(e,r),this._bindLinePositions(e,t),this._bindLinePicker(e,t),this._drawLine(e,t)}catch(e){}},this.#y=e,this._lineKey=t.key}get context(){return this.#y}get key(){return this._lineKey}build(t){const o=e.Utils.extend({},n,t??{}),a=this._lineBuilder.build(),l=this.context,c=l.device,u=a.metadata.thickness>1,d={module:c.createShaderModule({code:a.vertex}),buffers:[]},h=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"line-transforms-bind-group-layout"}),p=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_CAMERA,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"line-view-bind-group-layout"}),m=[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}];u&&m.push({binding:1,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}});const f=[h,p,c.createBindGroupLayout({entries:m,label:i+"line-positions-bind-group-layout"})],g=f.length,_=f.slice(),y={module:c.createShaderModule({code:a.fragment}),targets:[{format:l.format,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{}}}]},E=_.length,b=[{binding:r.STORAGE_MATERIAL_INDEX,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}}],v={label:i+"line-material-bind-group-layout",entries:b},P=c.createBindGroupLayout(v);_.push(P);const x=u?o.primitive.topology:"line-list",C={label:i+"line-render-pipeline",vertex:d,fragment:y,layout:c.createPipelineLayout({label:i+"line-render-pipeline-layout",bindGroupLayouts:this._bindLineGroupLayouts=_}),primitive:e.Utils.extend({},o.primitive,{topology:x})};o.multisample&&(C.multisample={count:4},C.depthStencil={depthCompare:"less",format:"depth24plus",depthWriteEnabled:!0}),this._linePipeline=c.createRenderPipeline(C);const w=this._pickLineBindGroupLayout=c.createBindGroupLayout({label:i+"line-colorpick-bind-group-layout",entries:[{visibility:GPUShaderStage.FRAGMENT,binding:0,buffer:{type:"uniform"}}]}),D={label:i+"line-colorpick-pipeline",vertex:d,fragment:{module:c.createShaderModule({code:r.getColorPickingFragmentWgsl(g)}),targets:[{format:"r32uint"}]},layout:c.createPipelineLayout({label:i+"line-colorpick-pipeline-layout",bindGroupLayouts:f.concat(w)}),primitive:e.Utils.extend({},o.primitive,{topology:x}),depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}};this._pickLinePipeline=c.createRenderPipeline(D);const R=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=i.buffer(l,"objectWorldTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Mesh,"objectWorldTransform",0),h=this._ensureLineWorldTransformBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindLineWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!1)},this._bindLineRaycastWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!0)};const N=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing view projection buffers was provided.`);const o=i.buffer(l,"cameraViewTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Camera,"cameraViewTransform",0),h=this._ensureLineCameraProjectionBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindLineCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!1)},this._bindLineRaycastCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!0)},this._bindLinePositions=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided as index 0.`);const o=n.buffer(l,"geometryPositions"),d=o.buffer;let h=o.fresh;const p=[d];if(s(c,o),u){const e=n.buffer(l,"line"),t=e.buffer;h||=e.fresh,p.push(t),s(c,e)}const{group:m}=a.bindings(r.WGSLBindingType.Mesh,"line",0),f=this._ensureLinePositionsBindGroup(n.item,p,h,m);t.setBindGroup(m,f)},this._bindLineMaterial=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex colors was provided.`);const o=n.buffer(l,"material"),a=o.buffer;s(c,o);const u=this._ensureLineMaterialBindGroup(n.item,a,o.fresh,E);t.setBindGroup(E,u)},this._bindLinePicker=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=n.buffer(l,"u32id"),a=o.buffer;o.value;s(c,o);const u=this._ensureLineU32idBindGroup(n.item,a,!1);t.setBindGroup(g,u)},this._drawLine=(e,...t)=>{const r=t.at(0).item.geometry;u?e.draw(6,r.positions.length-1,0,0):e.draw(r.positions.length)}}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){e.Geometry.LinearAlgebra.Matrix3D;class Raycaster{static{this._memoizer=new WeakMap}static dispose(e){const t=this._memoizer;if(t.has(e)){const r=t.get(e);for(let e of r.values())e.destroy();r.clear(),t.delete(e)}}static createColorPicking(e){const t=this._memoizer;t.has(e)||t.set(e,new Map);const r=t.get(e),i="colorpick";if(r.has(i))return r.get(i);const n=new ColorPickingRaycaster(e);return r.set(i,n),n}}t.Raycaster=Raycaster;class ColorPickingRaycaster{constructor(r){this._context=r,this._objects=new Map,this.frame=(...r)=>{if(e.Utils.isNull(this._encoder))throw new Error("Null encoder. Maybe you missed to call the 'begin' method first.");const i=Array.from(r),n=t.RenderPipeline.createColorPicking(this._context,i);n?.frame(this._pass,...r);for(let e of i){e.item.inert||this._objects.set(e.id,e)}},this.end=t=>{if(!e.Utils.isNull(this._handle))return this._handle;const r=this._pass,i=this._encoder,{device:n}=this._context,{render:o}=this._textures,s=o.texture,a=this._ensureBuffer();r.end(),i.copyTextureToBuffer({texture:s,origin:{x:t.x,y:t.y}},{buffer:a,bytesPerRow:66304,rowsPerImage:1},{width:1}),n.queue.submit([i.finish()]),this._encoder=null;const l=this,c=l._objects;return this._handle=new Promise((e,t)=>{a.mapAsync(GPUMapMode.READ,0,4).then(t=>{const r=new Uint32Array(a.getMappedRange(0,4))[0];a.unmap(),l._handle=null;const i=c.get(r);e(i?[i.item]:[])})})}}_createTexture(e){const{device:t,canvas:r}=this._context,i=Math.min(t.limits.maxTextureDimension2D,r.clientWidth),n=Math.min(t.limits.maxTextureDimension2D,r.clientHeight);return t.createTexture({size:[i,n,1],format:e,usage:GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT})}_ensureBuffer(){const r=this._buffer;if(!e.Utils.isNull(r))return r;const{device:i}=this._context;return this._buffer=i.createBuffer({label:t.LABEL_PREFIX+"colorpick-output-buffer",size:4,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST})}_ensureTextures(){const t=this._textures;if(!e.Utils.isNull(t))return t;const r=this._createTexture("r32uint"),i=this._createTexture("depth24plus"),n={texture:r,view:r.createView()},o={texture:i,view:i.createView()};return this._textures={render:n,depth:o}}_destroyTexture(t){e.Utils.isNull(t)||t.texture?.destroy()}destroy(){const t=this._textures,r=this._buffer;if(!e.Utils.isNullOrEmpty(t)){const{render:e,depth:r}=t;this._destroyTexture(e),this._destroyTexture(r),this._textures=null}e.Utils.isNull(r)||(r.destroy(),this._buffer=null)}begin(){const{device:e}=this._context;this._encoder=e.createCommandEncoder({label:t.LABEL_PREFIX+"colorpick-raycaster"});const{render:r,depth:i}=this._ensureTextures(),n={label:t.LABEL_PREFIX+"colorpick-raycaster-pass",colorAttachments:[{view:r.view,clearValue:{r:0,g:0,b:0,a:0},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:i.view,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}};this._pass=this._encoder.beginRenderPass(n),this._objects.clear()}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){function i(e,t){throw"function"==typeof t&&(t=t.name),new RangeError(`Buffer '${e}' not available for ${t}.`)}function n(r,i,...n){if(r.stage??=i?.item.stage,t.isGroup(r))return r.key??="group_"+e.Utils.uniqueCode(),new RenderableGroupBuffer(r,i,...n);if(t.isMesh(r))return r.key??="mesh_"+e.Utils.uniqueCode(),new RenderableMeshBuffer(r,i,...n);if(t.isCamera(r))return r.key??="camera_"+e.Utils.uniqueCode(),new RenderableCameraBuffer(r);if(t.isLight(r))return r.key??="light_"+r.type+"_"+e.Utils.uniqueCode(),new RenderableLightBuffer(r);throw new Error("Renderable is not supported.")}r.RenderLooper=class RenderLooper{constructor(e){this._set=e}get items(){return this._set}loop(e){const{meshes:t,cameras:r,groups:i,lights:n}=this._set,o=r[0];let s=!1,a=!1;for(let r of t){if(r.disposed)continue;e(r,o,n)&&(RenderableBuffer.clearFlags(r),s||(RenderableBuffer.clearFlags(o),s=!0),a||(n.forEach(e=>RenderableBuffer.clearFlags(e)),a=!0))}for(let e of i)RenderableBuffer.clearFlags(e)}};r.ManagedBuffer=class ManagedBuffer{static create(r){if(t.isGeometry(r))return r.key??="geometry_"+e.Utils.uniqueCode(),new GeometryBuffer(r);if(t.isMaterial(r))return new MaterialBuffer(r);throw new Error("Object is not supported.")}};class RenderableBuffer{static create(e,...t){return n(e,null,...t)}static clearFlags(t,r=!1){if(t.item.flags.splice(0),r){const r=t;e.Utils.isNull(r.parent)||RenderableBuffer.clearFlags(r.parent,!0)}}static allFlags(t){const r=t,i=r.parent,n=e.Utils.isNull(i)?[]:RenderableBuffer.allFlags(i);return r.item.flags.union(n)}}r.RenderableBuffer=RenderableBuffer;class ManagedBufferBase{#E;constructor(e){this.#E=e}get item(){return this.#E}#b=!1;lock(){this.#b=!0}unlock(){this.#b=!1;const e=this.#v;for(;e.length>0;){const t=e.shift();this._destroyUnsafe(t)}}#v=[];_destroyUnsafe(e){"texture"in e?e.texture.destroy():"buffer"in e&&e.buffer.destroy()}destroySafely(...e){for(let t of Array.from(e).concat(...this.#v.splice(0)))t&&(this.#b?this.#v.push(t):this._destroyUnsafe(t))}#P=!1;destroy(){this.dispose(),this.#P=!0}get disposed(){return this.#P}}class RenderableBufferBase extends ManagedBufferBase{constructor(t,i){super(t),this.#x=i,this.#C=e.Utils.uniqueId()%r.U32_MAX}#C;#x;#w;get parent(){return this.#x}get id(){return this.#C}allFlags(){const e=this.parent;return this.item.flags.union(e?.allFlags()??[])}buildParentWorldTransform(){let t=s.identity(),r=this;for(;!e.Utils.isNull(r.parent);){const e=r.parent.item,i=s.translate(e.transformMatrix??s.identity(),e.position??a.zero());t=s.multiply(t,i),r=r.parent}return t}buildWorldTransform(){const e=s.translate(this.item.transformMatrix??s.identity(),this.item.position??a.zero()),t=this.buildParentWorldTransform();return s.multiply(e,t)}#D=new Map;version(e){return this.#D.get(e)??0}buffer(t,i){if("u32id"===i){const i=this.#w;if(!e.Utils.isNull(i))return e.Utils.extend({fresh:!1},i);const n=new Uint32Array([this.id]),o=r.Buffers.createUniform(t.device,n,r.LABEL_PREFIX+"u32id-buffer");return e.Utils.extend(this.#w={buffer:o,value:n,version:performance.now()},{fresh:!0})}const n=this.specificBuffer(t,i);return this.#D.set(i,n.version),n}}const o=e.Components.Drawing3D.AdapterUtils,s=e.Geometry.LinearAlgebra.Matrix3D,a=e.Geometry.LinearAlgebra.Vector3D,l={shader:t.KnownShader.Basic,color:"#c0c0c0",flags:[]};class RenderableGroupBuffer extends RenderableBufferBase{#o;constructor(e,t,...r){super(e,t),this.#o=e.childRenderables.map(e=>n(e,this,...r))}get children(){return this.#o}specificBuffer(e,t){return null}texture(e){throw new Error("Method not implemented.")}dispose(){this.#o.forEach(e=>e.destroy())}}class RenderableCameraBuffer extends RenderableBufferBase{#R;constructor(e){super(e)}texture(e){throw new Error("Method not implemented.")}specificBuffer(t,r){this.item;const n=e.Utils.isNull(this.#R)||this.allFlags().length>0;if(n&&this._rebuildMatrices(t),RenderableBuffer.clearFlags(this),"cameraViewTransform"===r)return e.Utils.extend(this.#R,{fresh:n});i(r,RenderableCameraBuffer)}_rebuildMatrices({device:t,canvas:i}){const n=this.item,o=r.Camera.create(n),{x:a,y:l,z:c}=n.position,u=o.view(),d=o.projection(i),h=s.multiply(u,d),p=new Float32Array(36);if(p.set(s.toArray(u),0),p.set(s.toArray(h),16),p.set([a,l,c],32),e.Utils.isNull(this.#R)){const e=r.Buffers.createUniform(t,p,r.LABEL_PREFIX+"view-buffer");this.#R={buffer:e,value:p,version:performance.now().roundoff()}}else this.#R.value=p,this.#R.version=performance.now().roundoff()}_destroyView(){const e=this.#R;this.#R=null,this.destroySafely(e)}dispose(){this._destroyView()}}class GeometryBuffer extends ManagedBufferBase{#N={positions:!0,normals:!0,uv:!0,packed:!0};#M;constructor(e){super(e),e.flags??=[]}buffer(r,n){const o=this.item.flags??[];(e.Utils.isNull(this.#M)||o.includes(t.StalePropertyFlag.Geometry))&&(o.splice(0),this._rebuildGeometryBuffers(r));const s=this.#N,a=this.#M;switch(n){case"geometryPositions":const{positions:t}=a,r=s.positions;return s.positions=!1,e.Utils.extend(t,{fresh:r});case"geometryNormals":const{normals:o}=a,l=s.normals;return s.normals=!1,e.Utils.extend(o,{fresh:l});case"geometryTexCoords":const{uv:c}=a,u=s.uv;return s.uv=!1,e.Utils.extend({fresh:u},c);case"geometry":const{packed:d}=a,h=s.packed;return s.packed=!1,e.Utils.extend(d,{fresh:h});default:i(n,GeometryBuffer)}}texture(e){throw new Error("Method not implemented.")}_rebuildGeometryBuffers({device:i}){this._destroyBuffers();const n=performance.now(),s=this.item,a=s.key;if(t.isMeshGeometry(s)){const t=s,o=!e.Utils.isNullOrEmpty(t.triangleIndices)?t.triangleIndices.map(e=>t.positions[e]):t.positions,l=2*o.length,c=l+o.length,u=new Float32Array(c),d=new Float32Array(c),h=new Float32Array(l),p=new Float32Array(2*c+l);for(let e=0;e<o.length;e++){const r=2*e,i=3*e,{x:n,y:s,z:a}=o[e],{x:l,y:c,z:m}=t.normals[e],{x:f,y:g}=t.textureCoordinates[e];u.set([n,s,a],i),d.set([l,c,m],i),h.set([f,g],r),p.set([n,s,a,l,c,m,f,g],2*i+r)}const m=r.Buffers.create(i,u,r.LABEL_PREFIX+"meshgeometry-"+a+"-positions-buffer"),f=r.Buffers.create(i,d,r.LABEL_PREFIX+"meshgeometry-"+a+"-normals-buffer"),g=r.Buffers.create(i,h,r.LABEL_PREFIX+"meshgeometry-"+a+"-uvmap-buffer"),_=r.Buffers.create(i,p,r.LABEL_PREFIX+"meshgeometry-"+a+"-buffer");this.#M={packed:{buffer:_,value:p,version:n},positions:{buffer:m,value:u,version:n},normals:{buffer:f,value:d,version:n},uv:{buffer:g,value:h,version:n}},this.#N={positions:!0,normals:!0,uv:!0,packed:!0}}else{const e=new Float32Array(o.flattenVectorArray(s.positions)),t=r.Buffers.createStorage(i,e,r.LABEL_PREFIX+"nodegeometry-"+a+"-positions-buffer");this.#M={positions:{buffer:t,value:e,version:n},packed:{buffer:t,value:e,version:n}},this.#N={positions:!0,packed:!0}}}_destroyBuffers(){const t=this.#M;e.Utils.isNull(t)||this.destroySafely(t.positions,t.normals,t.uv)}dispose(){this._destroyBuffers()}}class MaterialBuffer extends ManagedBufferBase{#U;#L=new Map;#T=new Map;constructor(e){super(e),e.flags??=[],-1===e.flags.indexOf(t.StalePropertyFlag.Material)&&e.flags.push(t.StalePropertyFlag.Material)}buffer(r,n){const o=this.item.flags??[];let s=e.Utils.isNull(this.#U);switch(o.includes(t.StalePropertyFlag.Material)&&(o.splice(0),s=!0,this.#T.clear(),this._resetMaterialBuffers()),n){case"material":case"line":const t=this._ensureMaterialBuffer(r,n);return t?e.Utils.extend(t,{fresh:s}):null;default:i(n,MaterialBuffer)}}_ensureMaterialBuffer(e,t="material"){const r=this.#L;let i=r.get(t);return i||(r.has(t)?null:(i=this.#U?.buffer(e,t),i&&r.set(t,i),i))}_resetMaterialBuffers(){this.#U=r.Material.create(this.item),this._destroyBuffers()}texture(t,r="texture"){const i=this.#T;let n=i.get(r),o=!1;if(!n){if(n=this.#U?.texture(t,r),!n)return null;i.set(r,n),o=!0}return e.Utils.extend(n,{fresh:o})}dispose(){this._destroyBuffers()}_destroyBuffers(){const e=this.#L.values();this.#L.clear(),this.destroySafely(...e);const t=this.#T.values();this.#T.clear(),t.forEach(e=>e.texture.destroy())}}class RenderableMeshBuffer extends RenderableBufferBase{#M;#G;#A;#I;#B;#N={geometry:!0,material:!0,transform:!0};constructor(e,r,i,n){super(e,r),e.flags??=[],-1===e.flags.indexOf(t.StalePropertyFlag.Geometry)&&e.flags.push(t.StalePropertyFlag.Geometry),-1===e.flags.indexOf(t.StalePropertyFlag.Material)&&e.flags.push(t.StalePropertyFlag.Material),-1===e.flags.indexOf(t.StalePropertyFlag.Position)&&-1===e.flags.indexOf(t.StalePropertyFlag.Transform)&&e.flags.push(t.StalePropertyFlag.Transform),this.#M=i,this.#A=n}texture(e,t){const r=this.#I;return r?.texture(e,t)}specificBuffer(r,n){const o=this.#N,s=this.allFlags();(e.Utils.isNull(this.#B)||s.includes(t.StalePropertyFlag.Position)||s.includes(t.StalePropertyFlag.Transform))&&(o.transform=!0,this._rebuildWorldMatrices(r)),(e.Utils.isNull(this.#G)||s.includes(t.StalePropertyFlag.Geometry))&&(o.geometry=!0,this._ensureGeometryBuffer()),(e.Utils.isNull(this.#I)||s.includes(t.StalePropertyFlag.Material))&&(o.material=!0,this._ensureMaterialBuffer()),RenderableBuffer.clearFlags(this);const a=this.#G,l=this.#I;switch(n){case"geometryPositions":case"geometryNormals":case"geometryTexCoords":case"geometry":return a.buffer(r,n);case"material":case"line":return l.buffer(r,n);case"objectWorldTransform":const t=this.#B,s=o.transform;return o.transform=!1,e.Utils.extend(t,{fresh:s});default:i(n,RenderableMeshBuffer)}}_ensureGeometryBuffer(){const t=this.#G,r=this.#M,i=this.item.geometry;if(e.Utils.isNull(r))t?.destroy(),this.#G=new GeometryBuffer(i);else{let e=r?.get(i);!1!==e?.disposed&&(e=new GeometryBuffer(i),r.set(i,e)),this.#G=e}}_ensureMaterialBuffer(){const t=this.#I,r=this.#A,i=this.item.material??l;if(e.Utils.isNull(r))t?.destroy(),this.#I=new MaterialBuffer(i);else{let e=r?.get(i);!1!==e?.disposed&&(e=new MaterialBuffer(i),r.set(i,e)),this.#I=e}}_rebuildWorldMatrices({device:t}){const i=this.item,n=this.buildWorldTransform(),o=s.transpose(s.invert(n)),a=new Float32Array(28);if(a.set(s.toArray(n),0),a.set([o.m11,o.m12,o.m13,0,o.m21,o.m22,o.m23,0,o.m31,o.m32,o.m33,0],16),e.Utils.isNull(this.#B)){const e=r.Buffers.createUniform(t,a,r.LABEL_PREFIX+"mesh-"+i.key+"-worldmatrix-buffer");this.#B={buffer:e,value:a,version:performance.now().roundoff()}}else this.#B.value=a,this.#B.version=performance.now().roundoff()}dispose(){const e=this.#B;this.#B=null,this.destroySafely(e);const t=this.#I;this.#I=null,t?.destroy();const r=this.#G;this.#G=null,r?.destroy()}}class RenderableLightBuffer extends RenderableBufferBase{#O;constructor(e){super(e),e.flags.push(t.StalePropertyFlag.Light)}_rebuildAmbientLightBuffer({device:t}){const i=this.item,n=new Float32Array(24),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"ambient-light-buffer"),version:performance.now()}}_rebuildDirectionalLightBuffer({device:t}){const i=this.item,n=new Float32Array(8),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],7);const c=e.Geometry.LinearAlgebra.Vector3D.subtract(i.position,i.target);n.set([c.x,c.y,c.z],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"directional-light-buffer"),version:performance.now()}}_rebuildOmniLightBuffer({device:t}){const i=this.item,n=new Float32Array(8),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],7),n.set([i.position.x,i.position.y,i.position.z],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"omni-light-buffer"),version:performance.now()}}_rebuildLight(e){this.destroySafely(this.#O);const t=this.item;switch(t.type){case"direction":this._rebuildDirectionalLightBuffer(e);break;case"omni":this._rebuildOmniLightBuffer(e);break;case"ambient":this._rebuildAmbientLightBuffer(e);break;default:throw new Error(`Light '${t.type}' is not supported.`)}}texture(e){throw new Error("Method not implemented.")}specificBuffer(t,r){const n=e.Utils.isNull(this.#O)||this.allFlags().length>0;if(n&&this._rebuildLight(t),RenderableBuffer.clearFlags(this),"light"===r)return e.Utils.extend(this.#O,{fresh:n});i(r,RenderableLightBuffer)}dispose(){const e=this.#O;this.#O=null,this.destroySafely(e)}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){let i;!function(e){e[e.NotSupported=0]="NotSupported",e[e.Disabled=1]="Disabled"}(i=r.WebGPUIssueCause||(r.WebGPUIssueCause={}));r.Renderer=class Renderer{static create(e,t){return new Promise((r,n)=>{if(navigator.gpu){const o=new RendererClass(e);o.init(t).then(e=>r(o),e=>{const t={message:"string"==typeof e?e:e.message,cause:i.Disabled};n(t)})}else{const e={message:"WebGPU not supported.",cause:i.NotSupported};n(e)}})}};const n=e.Geometry.LinearAlgebra.Vector3D;class RendererClass{#S;#k;#y;#W;#F;#V;#$;#T;#X;#z;constructor(t){this.#W=new WeakMap,this.#F=new WeakMap,this.#V=new WeakMap,this.#X={enableValidation:!1},this.#z=!1,this._logError=t=>{const r=this.#S.logger;if(!e.Utils.isNull(r)){const i="error"in t?t.error:t;r.log(e.Logging.LogLevel.Error,i.message,"WebGPU")}},this.#H=!0;const r=(this.#S=t).stage,i=document.createElement("canvas");i.id=e.P+"_3d_stage_"+e.Utils.uniqueCode(),r.innerHTML="",r.appendChild(this.#k=i)}_buildPassDescriptor({multisample:t,format:i}){const{context:n,device:o}=this.#y,s=n.getCurrentTexture();let a=this.#T;if(e.Utils.isNull(a)){if(a={},t){const e=o.createTexture({label:r.LABEL_PREFIX+"render-texture",format:i??s.format,usage:GPUTextureUsage.RENDER_ATTACHMENT,size:[s.width,s.height],sampleCount:4});a.render={texture:e,view:e.createView({label:r.LABEL_PREFIX+"render-texture-view"})};const t=o.createTexture({label:r.LABEL_PREFIX+"depth-texture",format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT,size:[s.width,s.height],sampleCount:4});a.depth={texture:t,view:t.createView({label:r.LABEL_PREFIX+"depth-texture-view"})}}this.#T=a}const{transparent:l,background:c}=this.#S,u=l?{r:0,g:0,b:0,a:0}:c?"string"==typeof c?e.Colors.parse(c):c:{r:0,g:0,b:0,a:1},d=e.Components.Drawing3D.AdapterUtils.flattenVectorArray([u]),h=s.createView({label:r.LABEL_PREFIX+"canvas-texture-view"}),p={view:h,clearValue:d,loadOp:"clear",storeOp:"store"},m={colorAttachments:[p]};if(t){const e=a.render.view,t=a.depth.view;m.depthStencilAttachment={view:t,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store",stencilClearValue:0,stencilReadOnly:!0},p.view=e,p.resolveTarget=h}return m}_buildContext(e=this.#k,t=this.#S.size){t??=e;let r=t.width,i=t.height;e.width=1*r,e.height=1*i;return{context:e.getContext("webgpu"),textureFormat:navigator.gpu.getPreferredCanvasFormat()}}_buildUpContext(e,t,r,i){const{transparent:n}=this.#S;r.configure({alphaMode:n?"premultiplied":"opaque",device:e,format:i}),this.#y={device:e,adapter:t,canvas:this.#k,context:r,format:i},this.#H=!1}async init(t){this.#X=t;const r=await navigator.gpu.requestAdapter();if(e.Utils.isNull(r))throw new Error("WebGPU adapter unavalable or disabled.");const i=await r.requestDevice();if(e.Utils.isNull(r))throw new Error("WebGPU device unavalable or disabled.");i.addEventListener("uncapturederror",this._logError);const{context:n,textureFormat:o}=this._buildContext();this._buildUpContext(i,r,n,o)}#H;render(){if(this.#H||e.Utils.isNull(this.#$))return;const t=this.#y,i=t.device,n=this.#$,o=this.#X?.enableValidation??!1,s=this._buildPassDescriptor({multisample:!0}),a=i.createCommandEncoder({label:r.LABEL_PREFIX+"renderer"}),l=a.beginRenderPass(s);n.loop((e,n,s)=>{if(e.item.hide)return!1;o&&i.pushErrorScope("validation");const a=[e,n,...s];return r.RenderPipeline.create(t,a,{multisample:!0}).frame(l,...a),o&&i.popErrorScope().then(e=>{e&&this._logError(e)}),!0}),l.end(),i.queue.submit([a.finish()])}set disabled(e){this.#z=e}get disabled(){return this.#z}raycast(t){if(this.#H||e.Utils.isNull(this.#$))return Promise.resolve([]);const i=this.#y,n=i.device,o=this.#$,s=this.#X?.enableValidation??!1,a=r.Raycaster.createColorPicking(i);return a.begin(),o.loop((e,t)=>!e.item.hide&&(s&&n.pushErrorScope("validation"),a.frame(e,t),s&&n.popErrorScope().then(e=>{e&&this._logError(e)}),!0)),a.end(t)}_createOrYieldRenderable(t,i=this.#F,n=this.#V){t.stage??=this.#S;const o=this.#W;let s=o.get(t);return e.Utils.isNull(s)&&o.set(t,s=r.RenderableBuffer.create(t,i)),s}_createOrYieldGeometry(t){const i=this.#F;let n=i.get(t);return e.Utils.isNull(n)&&i.set(t,n=r.ManagedBuffer.create(t)),n}_createOrYieldMaterial(t){const i=this.#V;let n=i.get(t);return e.Utils.isNull(n)&&i.set(t,n=r.ManagedBuffer.create(t)),n}_unwrapBuffers(e,r){r??={meshes:[],lights:[],cameras:[],groups:[]};for(let i of e.children)i.item.stage??=this.#S,t.isMesh(i.item)&&r.meshes.push(i),t.isCamera(i.item)&&r.cameras.push(i),t.isLight(i.item)&&r.lights.push(i),t.isGroup(i.item)&&(r.groups.push(i),this._unwrapBuffers(i,r));return r}_update(i){const o=[],s=[],a=[],l=e=>this._createOrYieldRenderable(e);let c;for(let r of i)if(!r.hide){if(r.stage??=this.#S,t.isGroup(r)){const e=r;e.flags.includes(t.StalePropertyFlag.Children)&&this.#W.delete(e),o.push(l(e))}t.isMesh(r)&&r.geometry&&(this._createOrYieldGeometry(r.geometry),e.Utils.isNull(r.material)||this._createOrYieldMaterial(r.material),s.push(l(r))),t.isLight(r)&&a.push(l(r)),t.isCamera(r)&&(c??=r)}var u;c??=(u=this.#S,{bottom:-1,top:1,left:-1,right:1,near:.1,far:200,lookAt:n.from(0,0,0),up:n.j(),position:n.from(0,0,1),type:"orthographic",flags:[],stage:u});const d=l(c);let h={meshes:s,lights:a,cameras:[d],groups:o};for(let e of o)h=this._unwrapBuffers(e,h);this.#$?.items.meshes.forEach(e=>{s.includes(e)||e.destroy()}),this.#$=new r.RenderLooper(h)}update(...e){this._update(Array.from(e))}dispose(){if(this._disposeContext()){const{device:e}=this.#y;e.removeEventListener("uncapturederror",this._logError),e.destroy}}_disposeContext(){const t=this.#y;if(e.Utils.isNull(t))return!1;r.Raycaster.dispose(t),r.RenderPipeline.dispose(t);const i=this.#T;if(this.#T=null,!e.Utils.isNull(i)){const{render:e,depth:t}=i;!function(...e){for(let t of e||[])t?.destroy()}(e?.texture,t?.texture)}return t.context.unconfigure(),!0}resize(e){if(this.#H=!0,this._disposeContext()){const{device:t,adapter:r}=this.#y,{context:i,textureFormat:n}=this._buildContext(this.canvas,e);this._buildUpContext(t,r,i,n)}}get canvas(){return this.#k}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r="WebGPURaycastCallback",i="WebGPURaycastPixel",n=e.CustomElementUtils.getAttachedPropertyValue,o=e.CustomElementUtils.setAttachedPropertyValue,s=e.CustomElementUtils.deleteAttachedPropertyValue;let a=class Pacem3DWebgpuAdapterElement extends t.Pacem3DAdapterElement{invalidateSize(e,t=e.size){const r=this._ensureRenderer(e);r?.resize(t)}#j=new Map;#Y=!0;#K=!0;get supported(){return this.#Y}get active(){return this.#K}_webGPUNotSupported(t){this.#Y&&t.cause===e.Drawing3D.WebGPU.WebGPUIssueCause.NotSupported&&(this.#Y=!1,this.dispatchEvent(new e.PropertyChangeEvent({propertyName:"supported",oldValue:null,currentValue:!1}))),this.#K&&(this.#K=!1,this.dispatchEvent(new e.PropertyChangeEvent({propertyName:"active",oldValue:null,currentValue:!1})))}initialize(t){const r=this.#j;return e.Drawing3D.WebGPU.Renderer.create(t,{enableValidation:this.enableValidation??!1}).then(e=>(r.set(t,e),e.canvas),t=>(this.log(e.Logging.LogLevel.Error,t.message),this._webGPUNotSupported(t),null))}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i&&"enableValidation"===e){const e=this.#j;for(let t of e.keys()){const r=e.get(t);e.delete(t),r.dispose(),this.initialize(t)}}}disconnectedCallback(){const e=this.#j;for(let[t,r]of e)r.dispose();e.clear(),super.disconnectedCallback()}dispose(e){const t=this.#j;t.has(e)&&(t.get(e).dispose(),t.delete(e))}_ensureRenderer(e){return this.#j.get(e)}_updatePipeline(e){const t=this._ensureRenderer(e);t?.update(...e.datasource)}#Z=new WeakMap;render(t){const o=this._ensureRenderer(t);if(e.Utils.isNull(o))return;if(this.#Z.has(t)&&(this.#Z.delete(t),this._itemsChangedExec(t)),o.render(),!t.interactive)return;const s=n(t,r);if(e.Utils.isNullOrEmpty(s))return;const a=n(t,i);e.Utils.isNullOrEmpty(a)?s(null):o.raycast(a).then(t=>{if(e.Utils.isNullOrEmpty(t))s(null);else{const e={object:t[0],point:null};s(e)}})}snapshot(t,r,i,n){const o=this.#j;if(!o.has(t))return Promise.resolve(null);const{canvas:s}=o.get(t),a=!e.Utils.isNullOrEmpty(r),l=i??(a?"image/jpeg":null),c=n??(a?.9:null);return new Promise((i,n)=>{this.render(t),e.Utils.snapshotElement(s,r,l,c).then(i)})}raycast(e,t,n,a){o(e,r,a),t.x<0||t.y<0||t.x>=n.width||t.y>=n.height?s(e,i):o(e,i,t)}_itemsChangedExec(e){this._updatePipeline(e)}_itemsChanged(e,t){this.#Z.set(e,!0)}addItem(e,t){this._itemsChanged(e,t)}removeItem(e,t){this._itemsChanged(e,t)}updateItem(t,r){(e.Utils.isNull(r)||r.flags.indexOf(e.Drawing3D.StalePropertyFlag.Visibility)>=0||r.flags.indexOf(e.Drawing3D.StalePropertyFlag.Children)>=0)&&this._itemsChanged(t,r)}zoomFit(e,...t){return Promise.resolve()}project(e,t){return{x:0,y:0}}getScene(e){return e}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],a.prototype,"enableValidation",void 0),a=__decorate([e.CustomElement({tagName:e.P+"-3d-webgpu-adapter"})],a),t.Pacem3DWebgpuAdapterElement=a}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r=.001,i=e.Geometry.LinearAlgebra.Matrix3D,n=e.Geometry.LinearAlgebra.Vector3D,o=e.Geometry.LinearAlgebra.Quaternion,s=(e.Geometry.LinearAlgebra.Spherical,{maxAzimuth:180,minAzimuth:-180,inertia:!1,maxPolar:1/0,minPolar:-1/0,zoom:{enabled:!0},pan:{enabled:!0,button:2},rotation:{enabled:!0,button:0}});class OrbitCameraBehavior{constructor(t,r){this._config=r,this._input={rho:0,theta:0,phi:0,x:0,y:0},this._progress={rho:0,theta:0,phi:0,x:0,y:0},this._startHandler=t=>{const{rotation:r,pan:i}=this._config,o="mouse"===t.pointerType,s=r.enabled&&o&&t.button===r.button&&e.CustomEventUtils.matchModifiers(t,r.modifiers),a=i.enabled&&o&&t.button===i.button&&e.CustomEventUtils.matchModifiers(t,i.modifiers);(s||a)&&(this.#q=s,(this.#J=a)&&(this._currentState=OrbitCameraBehavior._buildState(this._camera),e.Utils.extend(this._input,n.zero()),this._progress.x=this._progress.y=0),e.avoidHandler(t),window.addEventListener("pointerup",this._endHandler,!1),window.addEventListener("pointermove",this._moveHandler,!1),window.addEventListener("contextmenu",this._avoidHandler,!1))},this._avoidHandler=t=>e.avoidHandler(t),this._endHandler=t=>{e.avoidHandler(t),window.setTimeout(()=>{window.removeEventListener("pointerup",this._endHandler),window.removeEventListener("pointermove",this._moveHandler),window.removeEventListener("contextmenu",this._avoidHandler)},20)},this._zoomHandler=t=>{const{zoom:r}=this._config;if(!(r.enabled&&e.CustomEventUtils.matchModifiers(t,r.modifiers)))return;e.avoidHandler(t);this._input.rho-=Math.sign(t.deltaY)},this._moveHandler=t=>{e.avoidHandler(t);const{height:r,width:i}=this._scene.size,n=this._input,o=Math.min(r,i);if(this.#q){const e=-360/o,{phi:r,theta:i}=n,{maxPolar:s,minPolar:a,maxAzimuth:l,minAzimuth:c}=this._config;n.phi=(r+t.movementX*e).clamp(a,s),n.theta=(i+t.movementY*e).clamp(c,l)}else if(this.#J){const e=this._currentState.radius/o;n.x+=-t.movementX*e,n.y+=t.movementY*e}},this._renderHandler=e=>{this._update()};const i=this._scene=(this._camera=t).stage;this._initialState=this._currentState=OrbitCameraBehavior._buildState(t);const o=this._canvas=i.stage;o.addEventListener("pointerdown",this._startHandler,!1),o.addEventListener("wheel",this._zoomHandler,{passive:!1}),i.addEventListener("render",this._renderHandler,!1)}static _buildState(e){const t=n.subtract(e.position,e.lookAt),r=n.mag(t);return{target:e.lookAt,versor:n.unit(t),up:e.up,radius:r,position:e.position}}static tryAttach(t,r){r??=s;const i=function(t){return e.Drawing3D.isCamera(t)?t.stage:null}(t)?.stage;if(e.Utils.isNull(i))return null;{const{position:i,lookAt:o}=t;return e.Utils.isNull(i)||e.Utils.isNull(o)||n.areClose(i,o)?null:new OrbitCameraBehavior(t,r)}}get configuration(){return this._config}set configuration(e){this._config=e}#J;#q;_getSafeAzimuth({theta:e}){return OrbitCameraBehavior._modAngle(e)}_getSafePolar({phi:e}){return OrbitCameraBehavior._modAngle(e)}static _modAngle(e){for(;e<0;)e+=360;return e%360}static _getViewXYZ(e){const{versor:t,up:r}=e,i=n.cross(t,r),o=n.cross(i,t);return n.normalize(i),n.normalize(o),{right:i,up:o,versor:t}}#Q;_update(){if(this.#Q)return;this.#Q=!0;const t=this._camera,{radius:s,versor:a,target:l,up:c}=this._initialState,{target:u}=this._currentState,{theta:d,phi:h,rho:p,x:m,y:f}=this._input,g=this._progress,{theta:_,phi:y,rho:E,x:b,y:v}=g,P=Math.abs(y-h)>r||Math.abs(_-d)>r,x=Math.abs(E-p)>r,C=Math.abs(m-b)>r||Math.abs(f-v)>r;if(x||P||C){const r="boolean"==typeof this._config.inertia?this._config.inertia?.05:0:this._config.inertia,P=r>0&&r<1,{right:x,up:C}=OrbitCameraBehavior._getViewXYZ(this._initialState);let w=l,D=c,R=u,N=E;P?N+=(p-E)*r:N=p,g.rho=N;const M=Math.pow(.95,1*N),U=n.scale(a,-M*s);w=n.add(w,U);let L=y,T=_;P?(L+=(h-y)*r,T+=(d-_)*r):(L=h,T=d);const G=this._getSafePolar({phi:g.phi=L}),A=this._getSafeAzimuth({theta:g.theta=T}),I=n.negate(l);let B=i.translate(i.identity(),I);const O=o.fromAxisAngle(C,G),S=o.fromAxisAngle(x,A),k=i.multiply(o.toRotationMatrix(S),o.toRotationMatrix(O));B=i.multiply(B,k),B=i.translate(B,n.negate(I)),w=i.transform(w,B),D=i.transform(D,i.clone(B,e=>{e.offsetX=e.offsetY=e.offsetZ=0}));let W=b,F=v;P?(W+=(m-b)*r,F+=(f-v)*r):(W=m,F=f),g.x=W,g.y=F;const{right:V,up:$}=OrbitCameraBehavior._getViewXYZ(this._currentState),X=n.scale(V,W),z=n.scale($,F),H=n.add(X,z);R=n.add(u,H),t.lookAt=R,t.position=w,t.up=D,t.flags.push(e.Drawing3D.StalePropertyFlag.Camera)}this.#Q=!1}dispose(){const t=this._canvas,r=this._scene;e.Utils.isNull(t)||(t.removeEventListener("pointerdown",this._startHandler),t.removeEventListener("wheel",this._zoomHandler)),r.removeEventListener("render",this._renderHandler,!1)}}t.OrbitCameraBehavior=OrbitCameraBehavior;let a=class PacemOrbitCameraBehaviorElement extends e.Behaviors.PacemBehavior{constructor(){super(...arguments),this.#ee=new Map,this._readyHandler=t=>{if("isReady"===t.detail.propertyName&&!0===t.detail.currentValue){const r=t.currentTarget;r.removeEventListener(e.PropertyChangeEventName,this._readyHandler),this._decorateCore(r)}}}#ee;propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"maxAzimuth":case"minAzimuth":case"inertia":case"zoomControl":case"panControl":case"rotationControl":const e=this._buildConfig(),t=this.#ee;for(let r of t.values())r.configuration=e}}disconnectedCallback(){const e=this.#ee;for(let t of e.values())t.dispose();e.clear(),super.disconnectedCallback()}_buildConfig(){return e.Utils.extend({},s,{maxAzimuth:this.maxAzimuth??1/0,minAzimuth:this.minAzimuth??-1/0,minPolar:this.minPolar??-1/0,maxPolar:this.maxPolar??1/0,inertia:this.inertia??!1,zoom:this.zoomControl??s.zoom,pan:this.panControl??s.pan,rotation:this.rotationControl??s.rotation})}_decorateCore(t){const r=OrbitCameraBehavior.tryAttach(t,this._buildConfig());e.Utils.isNull(r)||this.#ee.set(t,r)}decorate(t){t.isConnected?this._decorateCore(t):t.addEventListener(e.PropertyChangeEventName,this._readyHandler,!1)}undecorate(e){const t=this.#ee;t.has(e)&&(t.get(e).dispose(),t.delete(e))}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"maxAzimuth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"maxPolar",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"minAzimuth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"minPolar",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"zoomControl",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"rotationControl",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"panControl",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.BooleanOrNumberConverter})],a.prototype,"inertia",void 0),a=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-orbit-camera"})],a),t.PacemOrbitCameraBehaviorElement=a}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){t.ambientLight=function(t,r,i){const n=`ambient_${e.Utils.uniqueCode()}`,o=t.inputColor,s=t.outputColor;if(e.Utils.isNullOrEmpty(o)||e.Utils.isNullOrEmpty(s))throw new Error("Must provide either input and output vertex color parameter names.");return{definitions:["struct AmbientLight {\n color: vec4f,\n intensity: f32\n}","fn computeAmbient(color: vec4f, light: AmbientLight) -> vec4f {\n return vec4f(light.intensity * color.rgb * light.color.rgb, color.a);\n}"],bindings:[`@group(${r}) @binding(${i}) var<uniform> ${n}: AmbientLight;`],modifiers:[`${s} = computeAmbient(${o}, ${n});`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={normal:"normal",inputColor:"white"};t.directionalLight=function(t,i,n){const o=`directional_${e.Utils.uniqueCode()}`,s=e.Utils.extend({},r,t),a=s.inputColor,l=s.outputColor,c=s.normal??"normal";if(e.Utils.isNullOrEmpty(a))throw new Error("Must provide input vertex color parameter name.");return{definitions:["struct DirectionalLight {\n color: vec4f,\n direction: vec3f,\n intensity: f32\n}","fn computeDirectional(normal: vec3f, color: vec4f, light: DirectionalLight) -> vec4f {\n let n = normalize(normal);\n let d = normalize(light.direction);\n let factor = light.intensity * .5 * (1.0 + dot(n, -d));\n let output = color.rgb * light.color.rgb * factor;\n return vec4f(output, color.a);\n}"],bindings:[`@group(${i}) @binding(${n}) var<uniform> ${o}: DirectionalLight;`],modifiers:l?[`${l} += computeDirectional(${c}, ${a}, ${o});`]:[`computeDirectional(${c}, ${a}, ${o})`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.getColorPickingFragmentWgsl=function(t=e.UNIFORM_GROUP_INDEX_COLORPICKING){return`struct ColorPicker {\n id: u32,\n };\n\n @group(${t}) @binding(0) var<uniform> colorPicker: ColorPicker;\n\n @fragment\n fn main(@builtin(position) position: vec4f) -> @location(0) u32 {\n return colorPicker.id;\n }\n `}}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={normal:"normal",position:"vertex",ray:"ray",inputColor:"white",specularColor:"empty",shininess:"0"};t.omniLight=function(t,i,n){const o=`omni_${e.Utils.uniqueCode()}`,s=e.Utils.extend({},r,t),a=s.inputColor,l=s.outputColor,c=s.normal,u=s.ray,d=s.position,h=s.shininess,p=s.specularColor;if(e.Utils.isNullOrEmpty(a))throw new Error("Must provide input vertex color parameter name.");return{definitions:["struct OmniLight {\n color: vec4f,\n position: vec3f,\n intensity: f32\n}","fn computeOmni(position: vec3f, normal: vec3f, ray: vec3f, color: vec4f, specularColor: vec4f, shininess: f32, light: OmniLight) -> vec4f {\n\n // color\n let n = normalize(normal);\n let d = normalize(position - light.position);\n let factor = light.intensity * .5 * (1.0 + dot(n, -d));\n\n // specular\n let r = normalize(ray);\n let halfVector = normalize(d + r);\n let specular = specularColor.rgb * shininess * dot(n, -halfVector);\n\n let output = color.rgb * light.color.rgb * factor + specular;\n return vec4f(output, color.a);\n}"],bindings:[`@group(${i}) @binding(${n}) var<uniform> ${o}: OmniLight;`],modifiers:l?[`${l} += computeOmni(${d}, ${c}, ${u}, ${a}, ${p}, ${h}, ${o});`]:[`computeOmni(${d}, ${c}, ${u}, ${a}, ${p}, ${h}, ${o})`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayIndexLocation:t.VERTEX_OUTPUT_LOCATION_RAY,storageMaterialGroupIndex:t.MATERIAL_GROUP_INDEX,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getStandardMaterialFragmentWgsl=function(n={},o=r){const s=e.Utils.extend({},r,o),a=i(n.definitions),l=i(n.bindings),c=function(e=[]){let r="";for(let i of e){const e=i.trim();e.endsWith(";")?r+=e+"\r\n\t":r+=`${t.VERTEX_COLOR_REFERENCE} = ${e};\r\n\t`}return r}(n.modifiers),u=t.VERTEX_COLOR_REFERENCE,d=t.LIGHTING_COLOR_REFERENCE,h=t.AMBIENT_COLOR_REFERENCE,p=t.MATERIAL_REFERENCE;return`// definitions\nstruct Material{\n specularColor: vec4f,\n shininess: vec4f,\n diffuseColor: vec4f,\n}\n\n${a}\n\n// bindings\n@group(${o.storageMaterialGroupIndex}) @binding(${o.storageMaterialBindingIndex}) var<storage, read> ${p}: Material;\n${l}\n\nconst empty = vec4f(0,0,0,0);\nconst white = vec4f(1,1,1,1);\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${s.outputNormalLocation}) normal: vec3f, // world-space normal\n @location(${s.outputVertexLocation}) vertex: vec3f, // world-space position\n @location(${s.outputUvLocation}) uv: vec2f, \n @location(${s.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index, \n @location(${s.outputRayIndexLocation}) ray: vec3f // ray (eye-to-vertex) vector\n) -> @location(0) vec4f {\n var ${u} = ${p}.diffuseColor;\n var ${h}: vec4f = empty;\n var ${d}: vec4f = empty;\n\n // modifiers\n ${c}\n\n ${d} = select(white, ${d}, ${d}.a > 0);\n return ${u} * ${d} + ${h};\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class BasicMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Basic)}};r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-basic`})],r),t.BasicMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class LambertMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Lambert)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",reflectivity:this.reflectivity??0,refractionRatio:this.refractionRatio??0},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"reflectivity":case"refractionRatio":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"reflectivity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-lambert`})],r),t.LambertMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class LineMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Line)}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"lineWidth":case"lineJoin":case"lineCap":case"dashArray":this.updateMaterial()}}async createMaterial(){return e.Utils.extend({lineWidth:this.lineWidth??1,lineJoin:this.lineJoin??"round",lineCap:this.lineCap??"round",dashArray:this.dashArray},await super.createMaterial())}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"lineWidth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"lineJoin",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"lineCap",void 0),__decorate([e.Watch({emit:!1,converter:{convert:e=>e?.split(",").map(e=>parseInt(e)).filter(e=>!Number.isNaN(e)),convertBack:e=>e?.join(",")}})],r.prototype,"dashArray",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-line`})],r),t.LineMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class PhongMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Phong)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",reflectivity:this.reflectivity??0,refractionRatio:this.refractionRatio??0,specularColor:this.specularColor||"#000",shininess:this.shininess??0,flatShading:this.flatShading??!0},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"reflectivity":case"refractionRatio":case"specularColor":case"shininess":case"flatShading":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"reflectivity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"specularColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"shininess",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],r.prototype,"flatShading",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-phong`})],r),t.PhongMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class StandardMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Standard)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",refractionRatio:this.refractionRatio??0,metalness:this.metalness??0,roughness:this.roughness??0,flatShading:this.flatShading??!1},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"roughness":case"metalness":case"refractionRatio":case"flatShading":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"roughness",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"metalness",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],r.prototype,"flatShading",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-standard`})],r),t.StandardMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){class OBJParser{static parse(r){const i=[],n=/^v((\s+-?[\d\.]+){3})/gm;let o=n.exec(r);for(;o&&o.length;)i.push(t.Point3DConverter.convert(o[1])),o=n.exec(r);const s=[],a=/^vt((\s+-?[\d\.]+){2})/gm;for(o=a.exec(r);o&&o.length;)s.push(e.Point.parse(o[1])),o=a.exec(r);const l=[],c=/^vn((\s+-?[\d\.]+){3})/gm;for(o=c.exec(r);o&&o.length;)l.push(t.Point3DConverter.convert(o[1])),o=c.exec(r);const u=[],d=[],h=[],p=/^f((\s+([\d]+\/[\d]+\/[\d]+)){3,})/gm;for(o=p.exec(r);o&&o.length;){const e=/([\d]+)\/([\d]+)\/([\d]+)/g,t=o[1];let i=e.exec(t),n=0;for(var m,f,g,_,y,E;i&&i.length;)n>2&&(h.push(m),d.push(s[f]),u.push(l[g]),h.push(_),d.push(s[y]),u.push(l[E])),_=parseInt(i[1])-1,y=parseInt(i[2])-1,E=parseInt(i[3])-1,h.push(_),d.push(s[y]),u.push(l[E]),0===n&&(m=_,f=y,g=E),n++,i=e.exec(t);o=p.exec(r)}return new t.MeshGeometry(i,h,d,u)}}__decorate([e.Transformer("parse3D")],class Parser3D{static parseGeometry(e,t){if("obj"===t.toLowerCase())return OBJParser.parse(e);throw new Error(`Type '${t}' is not supported.`)}},"parseGeometry",null)}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){class Pacem3DPrimitiveElement extends t.PacemEventTarget{viewActivatedCallback(){super.viewActivatedCallback(),e.Utils.isNull(this.geometry)&&(this.geometry=this.createDefaultGeometry())}}__decorate([e.Watch({converter:e.PropertyConverters.Json})],Pacem3DPrimitiveElement.prototype,"geometry",void 0),r.Pacem3DPrimitiveElement=Pacem3DPrimitiveElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemBoxElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(t,r,i,n,o,s){const a=t||1,l=r||1,c=i||1,u=n||1,d=o||1,h=s||1,p=[],m=[],f=[];for(var g=0;g<=d;g++)for(var _=l/2-l*(1*g)/(1*d),y=0;y<=h;y++)for(var E=-c/2+c*(1*y)/(1*h),b=0;b<=u;b++){var v=-a/2+a*(1*b)/(1*u);0!=b&&b!=u&&0!=y&&y!=h&&0!=g&&g!=d||p.push({x:v,y:_,z:E})}var P=function(e,t,r){for(var i=1e-5,n=0;n<p.length;n++){var o=p[n];if(Math.abs(o.x-e)<i&&Math.abs(o.y-t)<i&&Math.abs(o.z-r)<i)return n}return-1},x=function(e,t,r,i,n,o,s,a){f.push(e),f.push(t),f.push(r),f.push(e),f.push(r),f.push(i),m.push({x:n,y:a}),m.push({x:s,y:a}),m.push({x:s,y:o}),m.push({x:n,y:a}),m.push({x:s,y:o}),m.push({x:n,y:o})};for(y=0;y<h;y++){_=l/2,E=-c/2+c*(1*y)/(1*h);var C=-c/2+c*(1*(y+1))/(1*h);for(b=0;b<u;b++){var w=-a/2+1*(b+1)*a/(1*u);x(P(v=-a/2+1*b*a/(1*u),_,C),P(w,_,C),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*y/(1*h),1*(b+1)/(1*u),1-1*(y+1)/(1*h))}}for(g=0;g<d;g++){_=l/2-1*g*l/(1*d);var D=l/2-(g+1)*l/(1*d);for(E=-c/2,b=0;b<u;b++){w=a/2-(b+1)*a/(1*u);x(P(v=a/2-1*b*a/(1*u),D,E),P(w,D,E),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*g/(1*d),(b+1)/(1*u),1-(g+1)/(1*d))}}for(g=0;g<d;g++)for(_=l/2-1*g*l/(1*d),D=l/2-(g+1)*l/(1*d),v=-a/2,y=0;y<h;y++){C=-c/2+(y+1)*c/(1*h);x(P(v,D,E=-c/2+y*c/(1*h)),P(v,D,C),P(v,_,C),P(v,_,E),1*y/(1*h),1-g/(1*d),(y+1)/(1*h),1-(g+1)/(1*d))}for(g=0;g<d;g++)for(_=l/2-g*l/(1*d),D=l/2-(g+1)*l/(1*d),E=c/2,b=0;b<u;b++){w=-a/2+(b+1)*a/(1*u);x(P(v=-a/2+b*a/(1*u),D,E),P(w,D,E),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*g/(1*d),(b+1)/(1*u),1-(g+1)/(1*d))}for(g=0;g<d;g++)for(_=l/2-g*l/(1*d),D=l/2-(g+1)*l/(1*d),v=a/2,y=0;y<h;y++){C=c/2-(y+1)*c/(1*h);x(P(v,D,E=c/2-y*c/(1*h)),P(v,D,C),P(v,_,C),P(v,_,E),1*y/(1*h),1-1*g/(1*d),(y+1)/(1*h),1-(g+1)/(1*d))}for(y=0;y<h;y++)for(_=-l/2,E=c/2-c*y/(1*h),C=c/2-c*(y+1)/(1*h),b=0;b<u;b++){w=-a/2+(b+1)*a/(1*u);x(P(v=-a/2+b*a/(1*u),_,C),P(w,_,C),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*y/(1*h),(b+1)/(1*u),1-(y+1)/(1*h))}const R=new e.Drawing3D.MeshGeometry(p,f,m);R.key=`box_${t}x${r}x${i}_w${n}_h${o}_d${s}`,e.Drawing3D.computeSharpVertexNormals(R);const N={x:0,y:0,z:0},M=t/2,U=r/2,L=i/2;return R.barycenter=N,R.boundingBox={maxX:M,maxY:U,maxZ:L,minX:-M,minY:-U,minZ:-L},R.boundingSphere={center:N,radius:Math.sqrt(Math.pow(M,2)+Math.pow(U,2)+Math.pow(L,2))},R}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"width":case"height":case"depth":case"widthSegments":case"heightSegments":case"depthSegments":this.geometry=r.createMeshGeometry(this.width,this.height,this.depth,this.widthSegments,this.heightSegments,this.depthSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"width",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"depth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"widthSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"depthSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-box"})],i),t.PacemBoxElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemConeElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=1,n=18,o=5,s=1){const a=r,l=[],c=[],u=[],d=t.DEG2RAD*(360/n),h=a/i,p=i/o,m=1/n;l.push({x:0,y:i,z:0});for(let e=1;e<=o;e++){const t=i-p*e,r=t/i,o=(i-t)*h,s=(t+p)/i;for(let i=0;i<n;i++){const a=d*i,h=Math.cos(a)*o,p=-Math.sin(a)*o;l.push({x:h,y:t,z:p});const f=1+n*(e-1)+i,g=0==i?f+n-1:f-1,_=i*m,y=0==i?1-m:m*(i-1);if(1==e){u.push(0,g,f),c.push({x:_,y:1},{x:y,y:r},{x:_,y:r});continue}const E=1+n*(e-2)+i,b=0==i?E+n-1:E-1,v=g,P=f,x=E;u.push(P,b,v),u.push(P,x,b);const C={x:y,y:s},w={x:y,y:r},D={x:_,y:r},R={x:_,y:s};c.push(D,C,w),c.push(D,R,C)}}const f=1+(o-1)*n;l.push({x:0,y:0,z:0});const g=f+n;for(let e=1;e<=s;e++){const t=e/s,i=r*t,o=(e-1)/s;for(let r=0;r<n;r++){const a=d*r,h=Math.cos(a),p=Math.sin(a),m=a-d,_=Math.cos(m),y=Math.sin(m),E=.5*(1+h*t),b=.5*(1+p*t),v=.5*(1+_*t),P=.5*(1+y*t);let x,C;if(e!=s){const t=Math.cos(a)*i,o=-Math.sin(a)*i;l.push({x:t,y:0,z:o}),x=g+1+(e-1)*n+r,C=0==r?x+n-1:x-1}else x=f+r,C=0==r?f+n-1:x-1;if(1==e){u.push(g,x,C),c.push({x:.5,y:.5},{x:E,y:b},{x:v,y:P});continue}const w=.5*(1+h*o),D=.5*(1+p*o),R=.5*(1+_*o),N=.5*(1+y*o),M=g+1+(e-2)*n+r,U=0==r?M+n-1:M-1,L=C,T=x,G=M;u.push(U,G,L),u.push(L,G,T);const A={x:R,y:N},I={x:v,y:P},B={x:E,y:b},O={x:w,y:D};c.push(A,O,I),c.push(I,O,B)}}const _=new e.Drawing3D.MeshGeometry(l,u,c);return _.key=`cone_${r}x${i}_s${n}_h${o}_c${s}`,e.Drawing3D.computeSharpVertexNormals(_),_}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"height":case"sides":case"heightSegments":case"capSegments":this.geometry=r.createMeshGeometry(this.radius,this.height,this.sides,this.heightSegments,this.capSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"capSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-cone"})],i),t.PacemConeElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemCylinderElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=1,n=18,o=5,s=1){const a=r,l=[],c=[],u=[],d=t.DEG2RAD*(360/n);l.push({x:0,y:i,z:0}),l.push({x:0,y:0,z:0});const h=a/s;for(let e=1;e<=s;e++)for(var p=h*e,m=0;m<n;m++){const t=2+2*n*(e-1),r=0==m?t+2*(n-1):t+2*(m-1),o=t+2*m,h=Math.cos(d*m),f=-Math.sin(d*m),g=Math.cos(d*(m-1)),_=-Math.sin(d*(m-1)),y=p*h,E=p*f,b={x:y,y:i,z:E},v={x:y,y:0,z:E};l.push(b),l.push(v);const P=.5*p/a,x=h*P,C=f*P,w=g*P,D=_*P;if(1==e){const e=[0,r,o],t=[1,o+1,r+1],i=[{x:.5,y:.5},{x:.5+w,y:.5-D},{x:.5+x,y:.5-C}],n=[{x:.5,y:.5},{x:.5+x,y:.5+C},{x:.5+w,y:.5+D}];u.push(...e),u.push(...t);for(let e=0;e<i.length;e++)c.push(i[e]);for(let e=0;e<n.length;e++)c.push(n[e])}else{const t=2+2*n*(e-2),i=0==m?t+2*(n-1):t+2*(m-1),a=t+2*m,l=(e-1)/s*.5,d=h*l,p=f*l,y=g*l,E=_*l,b={x:.5+w,y:.5-D},v={x:.5+x,y:.5-C},P={x:.5+d,y:.5-p},R={x:.5+y,y:.5-E},N={x:.5+w,y:.5+D},M={x:.5+x,y:.5+C},U={x:.5+d,y:.5+p},L={x:.5+y,y:.5+E};u.push(r),u.push(o),u.push(i),u.push(i),u.push(o),u.push(a),u.push(a+1),u.push(o+1),u.push(r+1),u.push(a+1),u.push(r+1),u.push(i+1),c.push(b),c.push(v),c.push(R),c.push(R),c.push(v),c.push(P),c.push(U),c.push(M),c.push(N),c.push(U),c.push(N),c.push(L)}}const f=2+2*n*s,g=2+2*n*(s-1),_=1/n,y=1/o;for(let e=1;e<=o;e++)for(let t=0;t<n;t++){if(e!=o){var E=a*Math.cos(d*t),b=-a*Math.sin(d*t),v=i*e/o;l.push({x:E,y:v,z:b})}const r=0==t?n-1:t-1,s=1==e?g+2*r+1:f+n*(e-2)+r,h=1==e?g+2*t+1:f+n*(e-2)+t,p=e==o?g+2*t:f+n*(e-1)+t,m=e==o?g+2*r:f+n*(e-1)+r,P=r*_,x=(e-1)*y,C=0==t?1:t*_,w=e*y,D={x:P,y:x},R={x:C,y:x},N={x:C,y:w},M={x:P,y:w};u.push(s),u.push(h),u.push(p),u.push(s),u.push(p),u.push(m),c.push(D),c.push(R),c.push(N),c.push(D),c.push(N),c.push(M)}const P=new e.Drawing3D.MeshGeometry(l,u,c);return P.key=`cylinder_${r}x${i}_s${n}_h${o}_c${s}`,e.Drawing3D.computeSharpVertexNormals(P),P}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"height":case"sides":case"heightSegments":case"capSegments":this.geometry=r.createMeshGeometry(this.radius,this.height,this.sides,this.heightSegments,this.capSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"capSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-cylinder"})],i),t.PacemCylinderElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;const i=[{x:0,y:0,z:0},{x:0,y:1,z:0}];let n=r=class PacemLineElement extends t.Pacem3DPrimitiveElement{static createLineGeometry(t){return new e.Drawing3D.LineGeometry(t||i)}createDefaultGeometry(){return r.createLineGeometry()}propertyChangedCallback(e,t,i,n){if(super.propertyChangedCallback(e,t,i,n),"positions"===e)this.geometry=r.createLineGeometry(i)}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],n.prototype,"positions",void 0),n=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-line"})],n),t.PacemLineElement=n}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemPlaneElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(t,r,i,n){t||=1,r||=1,i||=4,n||=4;const o=.5*t,s=.5*r,a=[],l=[],c=[],u=[],d=e.Geometry.LinearAlgebra.Vector3D.from(0,0,1);for(let e=0;e<=n;e++)for(let h=0;h<=i;h++){const p=h*t/(1*i)-o,m=0,f=e*r/(1*n)-s;if(a.push({x:p,y:m,z:f}),e<n&&h<i){const t=i+1,r=(h+1)/(1*i),o=1*h/(1*i),s=1-(e+1)/(1*n),a=1-1*e/(1*n);c.push((e+1)*t+h),c.push((e+1)*t+h+1),c.push(e*t+h+1),c.push((e+1)*t+h),c.push(e*t+h+1),c.push(e*t+h),l.push({x:o,y:s}),l.push({x:r,y:s}),l.push({x:r,y:a}),l.push({x:o,y:s}),l.push({x:r,y:a}),l.push({x:o,y:a}),u.push(d,d,d,d,d,d)}}const h=new e.Drawing3D.MeshGeometry(a,c,l,u);return h.key=`plane_${t}x${r}_w${i}_l${n}`,h}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"width":case"length":case"widthSegments":case"lengthSegments":this.geometry=r.createMeshGeometry(this.width,this.length,this.widthSegments,this.lengthSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"width",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"length",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"widthSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"lengthSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-plane"})],i),t.PacemPlaneElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r,i,n,o,s;const a=function(e){const t=/([\d.-]+)/i;var r=t.exec(e);const i=[];for(;null!=r;){const n=r[0],o=parseFloat(n);i.push(o),e=e.replace(n,""),r=t.exec(e)}return i},l=e.Geometry.LinearAlgebra.Vector3D;class PolyhedronElement extends t.Pacem3DPrimitiveElement{propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"radius"===e&&this._assignMeshGeometry(r)}_assignMeshGeometry(e){this.geometry=this.createMeshGeometry(e>0?e:1)}createDefaultGeometry(){return this.createMeshGeometry(1)}}__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],PolyhedronElement.prototype,"radius",void 0),t.PolyhedronElement=PolyhedronElement;let c=r=class PacemTetrahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r="0 0.5774 -0.8165, 0 0.5774 0.8165, 0.8165 -0.5774 0, -0.8165 -0.5774 0".split(","),i=[];for(let e=0;e<r.length;e++){const n=r[e],o=a(n);i.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const n="0.5 0.9995, 0.5 0.0004995, 0.0004995 0.5, 0.9995 0.5, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995".split(","),o=[4,5,6,7,8,9,10,11,0,3,2,1],s=[];for(let e=0;e<o.length;e++){const t=a(n[o[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(i,[1,2,0,2,3,0,3,1,0,3,2,1],s);return c.key=`tetrahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return r.createMeshGeometry(e)}};c=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-tetrahedron"})],c),t.PacemTetrahedronElement=c;let u=i=class PacemOctahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[6,7,8,9,10,11,12,13,14,15,16,0,17,18,19,20,21,1,2,22,23,4,3,5],i="0 0.7071 -0.7071, 0 0.7071 0.7071, 1 0 0, 0 -0.7071 -0.7071, -1 0 0, 0 -0.7071 0.7071".split(","),n=[];for(let e=0;e<i.length;e++){const r=i[e],o=a(r);n.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const o="0.5 0.9995, 0.5 0.9995, 0.0004995 0.5, 0.5 0.9995, 0.9995 0.5, 0.5 0.0004995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995, 0.5 0.9995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995, 0.0004995 0.5, 0.5 0.0004995, 0.5 0.9995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.0004995, 0.5 0.9995".split(","),s=[];for(let e=0;e<r.length;e++){const t=a(o[r[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(n,[1,2,0,2,3,0,3,4,0,4,1,0,4,5,1,5,2,1,2,5,3,4,3,5],s);return c.key=`octahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return i.createMeshGeometry(e)}};u=i=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-octahedron"})],u),t.PacemOctahedronElement=u;let d=n=class PacemHexahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=2*t*(1/Math.sqrt(3)),i=e.Components.Drawing3D.PacemBoxElement.createMeshGeometry(r,r,r);return i.key=`hexahedron_${t}`,i}createMeshGeometry(e=this.radius){return n.createMeshGeometry(e)}};d=n=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-hexahedron"})],d),t.PacemHexahedronElement=d;let h=o=class PacemIcosahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,26,27,28,29,30,31,32,33,1,34,35,36,2,37,38,39,40,41,42,43,7,44,45,46,8,47,48,49,50,51,52,53,9,54,55,3,10,56,57,6,58,59,5,4,11],i="0 0.850651 -0.525731, 0 0.850651 0.525731, 0.850651 0.525731 0, 0.525731 0 -0.850651, -0.525731 0 -0.850651, -0.850651 0.525731 0, -0.525731 0 0.850651, 0.525731 0 0.850651, 0.850651 -0.525731 0, 0 -0.850651 0.525731, 0 -0.850651 -0.525731, -0.850651 -0.525731 0".split(","),n=[];for(let e=0;e<i.length;e++){const r=i[e],o=a(r);n.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const o="0.5 0.808708, 0.5 0.999501, 0.5 0.808708, 0.191292 0.5, 0.000499547 0.5, 0.5 0.808708, 0.9995 0.5, 0.808708 0.5,0.000499487 0.5, 0.5 0.191292, 0.5 0.000499487, 0.5 0.191292,0.5 0.191292, 0.999501 0.5, 0.5 0.808708, 0.5 0.808708,0.9995 0.5, 0.808708 0.999501, 0.191292 0.5, 0.808708 0.5,0.5 0.999501, 0.808708 0.5, 0.999501 0.808708, 0.5 0.999501,0.000499487 0.5, 0.5 0.191292, 0.5 0.808708, 0.9995 0.5,0.808708 0.999501, 0.191292 0.5, 0.808708 0.5, 0.5 0.999501,0.808708 0.5, 0.999501 0.808708, 0.5 0.808708, 0.5 0.191292,0.9995 0.5, 0.000499547 0.5, 0.5 0.191292, 0.191292 0.5,0.5 0.000499487, 0.808708 0.5, 0.5 0.000499487, 0.999501 0.191292,0.5 0.191292, 0.808708 0.000499487, 0.9995 0.5, 0.5 0.191292,0.5 0.808708, 0.9995 0.5, 0.5 0.191292, 0.808708 0.000499487,0.999501 0.5, 0.5 0.808708, 0.5 0.000499487, 0.808708 0.5,0.999501 0.191292, 0.808708 0.5, 0.5 0.808708, 0.5 0.191292".split(","),s=[];for(let e=0;e<r.length;e++){const t=a(o[r[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(n,[1,2,0,2,3,0,3,4,0,4,5,0,5,1,0,5,6,1,6,7,1,7,2,1,2,8,3,2,7,8,6,9,7,9,8,7,8,10,3,8,9,10,6,11,9,11,10,9,10,4,3,10,11,4,6,5,11,5,4,11],s);return c.key=`icosahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return o.createMeshGeometry(e)}};h=o=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-icosahedron"})],h),t.PacemIcosahedronElement=h;let p=s=class PacemDodecahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[l.from(.356822*t,.934172*t,0*t),l.from(-.356822*t,.934172*t,0*t),l.from(.57735*t,.57735*t,-.57735*t),l.from(0*t,.356822*t,-.934172*t),l.from(-.57735*t,.57735*t,-.57735*t),l.from(-.57735*t,.57735*t,.57735*t),l.from(0*t,.356822*t,.934172*t),l.from(.57735*t,.57735*t,.57735*t),l.from(.934172*t,0*t,-.356822*t),l.from(.934172*t,0*t,.356822*t),l.from(0*t,-.356822*t,.934172*t),l.from(.57735*t,-.57735*t,.57735*t),l.from(.57735*t,-.57735*t,-.57735*t),l.from(.356822*t,-.934172*t,0*t),l.from(-.57735*t,-.57735*t,.57735*t),l.from(-.356822*t,-.934172*t,0*t),l.from(0*t,-.356822*t,-.934172*t),l.from(-.57735*t,-.57735*t,-.57735*t),l.from(-.934172*t,0*t,.356822*t),l.from(-.934172*t,0*t,-.356822*t)],i=[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,0,46,47,48,49,50,51,7,52,53,54,55,56,57,58,59,60,61,9,62,63,64,65,66,67,11,68,69,70,71,72,73,74,75,76,77,13,78,79,80,81,82,83,15,84,85,86,87,88,89,90,91,92,93,17,94,95,96,97,98,99,19,1,4,100,14,101,102,10,103,18,6,5,104,2,105,106,8,107,3,12,16],n="0.5 0.999501, 0.5 0.999501, 0.191292 0.808708, 0.5 0.690792,\n 0.191292 0.808708, 0.191292 0.808708, 0.5 0.690792, \n 0.808708 0.808708, 0.000499517 0.5, 0.309208 0.5, 0.5 0.309208, \n 0.191292 0.191292, 0.191292 0.191292, 0.309208 0.5, \n 0.191292 0.191292, 0.5 0.000499517, 0.5 0.309208, 0.808708 0.191292, \n 0.000499517 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708, \n 0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.309208 0.5, \n 0.191292 0.191292, 0.5 0.000499517, 0.309208 0.5, 0.5 0.000499517, \n 0.808708 0.191292, 0.309208 0.5, 0.808708 0.191292, \n 0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.690792 0.5, \n 0.191292 0.808708, 0.690792 0.5, 0.808708 0.808708, \n 0.191292 0.808708, 0.808708 0.808708, 0.808708 0.808708, \n 0.5 0.690792, 0.5 0.309208, 0.808708 0.808708, 0.5 0.309208, \n 0.808708 0.191292, 0.808708 0.191292, 0.9995 0.5, 0.191292 0.191292, \n 0.5 0.000499517, 0.808708 0.191292, 0.191292 0.191292, \n 0.808708 0.191292, 0.690792 0.5, 0.191292 0.191292, \n 0.690792 0.5, 0.191292 0.191292, 0.5 0.000499517, 0.808708 0.191292, \n 0.191292 0.191292, 0.808708 0.191292, 0.690792 0.5, \n 0.690792 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708, \n 0.690792 0.5, 0.191292 0.808708, 0.5 0.000499517, 0.808708 0.191292, \n 0.690792 0.5, 0.5 0.000499517, 0.690792 0.5, 0.309208 0.5, \n 0.309208 0.5, 0.191292 0.191292, 0.9995 0.5, 0.808708 0.808708, \n 0.5 0.690792, 0.9995 0.5, 0.5 0.690792, 0.5 0.309208, \n 0.9995 0.5, 0.5 0.309208, 0.309208 0.5, 0.690792 0.5, \n 0.808708 0.808708, 0.309208 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.000499517 0.5, 0.5 0.309208, 0.000499517 0.5, \n 0.5 0.690792, 0.5 0.690792, 0.000499517 0.5, 0.5 0.690792, \n 0.191292 0.191292".split(","),o=[];for(let e=0;e<i.length;e++){const t=a(n[i[e]]);o.push({x:t[0],y:t[1]})}const s=new e.Drawing3D.MeshGeometry(r,[0,2,3,0,3,4,0,4,1,1,5,6,1,6,7,1,7,0,7,9,8,7,8,2,7,2,0,7,6,10,7,10,11,7,11,9,11,13,12,11,12,8,11,8,9,11,10,14,11,14,15,11,15,13,15,17,16,15,16,12,15,12,13,15,14,18,15,18,19,15,19,17,19,4,3,19,3,16,19,16,17,19,18,5,19,5,1,19,1,4,18,14,10,18,10,6,18,6,5,3,2,8,3,8,12,3,12,16],o);return s.key=`dodecahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(s),s.boundingSphere={center:l.zero(),radius:t},s}createMeshGeometry(e=this.radius){return s.createMeshGeometry(e)}};p=s=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-dodecahedron"})],p),t.PacemDodecahedronElement=p}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemSphereElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=8){const n=[],o=[],s=[],a=r,l=i,c=t.DEG2RAD*(360/l),u=l%2==0?l/2:(l-1)/2;n.push({x:0,y:a,z:0});for(let e=1;e<u;e++){const t=c*e,r=Math.cos(t),i=Math.sin(t),d=1-1*e/u;for(let t=0;t<l;t++){const h=c*t-Math.PI/2,p=a*i*Math.cos(h),m=a*r,f=a*i*Math.sin(h);n.push({x:p,y:m,z:f});const g=0==t?l-1:t-1,_=0==t?0:1-1*t/l,y=1-1*g/l;if(1==e)s.push(1+t),s.push(1+g),s.push(0),o.push({x:_,y:d}),o.push({x:y,y:d}),o.push({x:.5,y:1});else{s.push((e-1)*l+t+1),s.push((e-1)*l+g+1),s.push((e-2)*l+g+1),s.push((e-1)*l+t+1),s.push((e-2)*l+g+1),s.push((e-2)*l+t+1);const r=1-(e-1)/u;o.push({x:_,y:d}),o.push({x:y,y:d}),o.push({x:y,y:r}),o.push({x:_,y:d}),o.push({x:y,y:r}),o.push({x:_,y:r})}}}n.push({x:0,y:-a,z:0});const d=n.length-1;for(let e=0;e<l;e++){const t=u-2,r=0==e?l-1:e-1,i=0==e?0:1-1*e/l,n=1-1*r/l,a=1-(t+1)/u;s.push(d),s.push(t*l+1+r),s.push(t*l+1+e),o.push({x:.5,y:0}),o.push({x:n,y:a}),o.push({x:i,y:a})}const h=new e.Drawing3D.MeshGeometry(n,s,o);return h.key=`sphere_${r}_s${i}`,e.Drawing3D.computeSharpVertexNormals(h),h}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"segments":this.geometry=r.createMeshGeometry(this.radius,this.segments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"segments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-sphere"})],i),t.PacemSphereElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemTorusElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=.25,n=24,o=12){const s=[],a=[],l=[],c=t.DEG2RAD*(360/n),u=t.DEG2RAD*(360/o),d=r,h=i;for(let e=0;e<n;e++){const t=c*e-Math.PI/2,r=Math.sin(t),i=Math.cos(t);for(let t=0;t<o;t++){const c=u*t+Math.PI,p=Math.cos(c),m=d*i+h*p*i,f=h*Math.sin(c),g=d*r+h*p*r;s.push({x:m,y:f,z:g});const _=e>0?e-1:n-1,y=t>0?t-1:o-1,E=0==e?0:1-1*e/n,b=t>0?1*t/o:1,v=e>0?1-(e-1)/n:1/n,P=t>0?(t-1)/o:1-1/o;l.push(e*o+y),l.push(_*o+y),l.push(_*o+t),l.push(e*o+y),l.push(_*o+t),l.push(e*o+t),a.push({x:E,y:P}),a.push({x:v,y:P}),a.push({x:v,y:b}),a.push({x:E,y:P}),a.push({x:v,y:b}),a.push({x:E,y:b})}}const p=new e.Drawing3D.MeshGeometry(s,l,a);return p.key=`torus_${r}x${i}_t${n}_s${o}`,e.Drawing3D.computeSharpVertexNormals(p),p}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"innerRadius":case"segments":case"sides":this.geometry=r.createMeshGeometry(this.radius,this.innerRadius,this.segments,this.sides)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"innerRadius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"segments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-torus"})],i),t.PacemTorusElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={}));
|
|
6
|
+
var Pacem,__decorate=this&&this.__decorate||function(e,t,r,i){var n,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,r,s):n(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s};!function(e){!function(t){t.Point3DConverter={convert:t=>e.Geometry.LinearAlgebra.Vector3D.parse(t),convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0}`},t.Point3DOrNumberConverter={convert:t=>{const r=e.parseAsNumericalArray(t),i=()=>{throw new Error(`Cannot parse "${t}" as a valid Vector3D.`)};if(e.Utils.isNullOrEmpty(r)&&i(),3===r.length)return e.Geometry.LinearAlgebra.Vector3D.from(...r);if(1===r.length){const t=r[0];return e.Geometry.LinearAlgebra.Vector3D.from(t,t,t)}i()},convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0}`},t.QuaternionConverter={convert:t=>e.Geometry.LinearAlgebra.Quaternion.parse(t),convertBack:e=>`${e.x||0} ${e.y||0} ${e.z||0} ${e.w||0}`},t.BooleanOrNumberConverter={convert:t=>"true"===t||"false"!==t&&e.parseAsNumericalArray(t)[0],convertBack:e=>e.toString()}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){t.NotifyChange=function(t){return(r,i,n)=>{const o=`_${i}_${e.Utils.uniqueCode()}_backingField`;function s(){return this[o]}function a(e){if(e!==this[o]){const r=this[o];this[o]=e,t.call(this,i,r,e)}}Object.defineProperty(r,i,{get:function(){return s.call(this)},set:function(e){a.call(this,e)},enumerable:!0,configurable:!1})}}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.Pacem3DDetector=class Pacem3DDetector{constructor(){this._detected={supported:!1,info:{}};let e,t=document.createElement("canvas"),r=["webgl","experimental-webgl","moz-webgl","webkit-3d"],i=function(t){if(t)return e.getParameter(t)},n=(e,t,r)=>{let i=this._detected;(i.info[e]=i.info[e]||{})[t=(t=t.replace(/[^\w]+/g,"")).substring(0,1).toLowerCase()+t.substring(1)]=r};if(navigator.userAgent.indexOf("MSIE")>=0)try{e=window.WebGLHelper.CreateGLContext(t,"canvas")}catch(e){}else for(var o=0;o<r.length;o++)try{if(e=t.getContext(r[o]),e){n("main","Context Name",r[o]);break}}catch(e){}this._detected.supported=!!e,n("main","Platform",navigator.platform),n("main","Agent",navigator.userAgent),e&&(n("main","Vendor",i(e.VENDOR)),n("main","Version",i(e.VERSION)),n("main","Renderer",i(e.RENDERER)),n("main","Shading Language Version",i(e.SHADING_LANGUAGE_VERSION)),n("bits","Rgba Bits",i(e.RED_BITS)+", "+i(e.GREEN_BITS)+", "+i(e.BLUE_BITS)+", "+i(e.ALPHA_BITS)),n("bits","Depth Bits",i(e.DEPTH_BITS)),n("shader","Max Vertex Attribs",i(e.MAX_VERTEX_ATTRIBS)),n("shader","Max Vertex Texture Image Units",i(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS)),n("shader","Max Varying Vectors",i(e.MAX_VARYING_VECTORS)),n("shader","Max Uniform Vectors",i(e.MAX_VERTEX_UNIFORM_VECTORS)),n("tex","Max Combined Texture Image Units",i(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS)),n("tex","Max Texture Size",i(e.MAX_TEXTURE_SIZE)),n("tex","Max Cube Map Texture Size",i(e.MAX_CUBE_MAP_TEXTURE_SIZE)),n("tex","Num. Compressed Texture Formats",i(e.COMPRESSED_TEXTURE_FORMATS)),n("misc","Max Render Buffer Size",i(e.MAX_RENDERBUFFER_SIZE)),n("misc","Max Viewport Dimensions",i(e.MAX_VIEWPORT_DIMS)),n("misc","Aliased Line Width Range",i(e.ALIASED_LINE_WIDTH_RANGE)),n("misc","Aliased Point Size Range",i(e.ALIASED_POINT_SIZE_RANGE)),n("misc","Supported Extensions",e.getSupportedExtensions()||[]))}get info(){return this._detected.info}get supported(){return this._detected.supported}}}(e.Drawing3D||(e.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){class NodeGeometry{constructor(e=[]){this.positions=e}static barycenter(t){var r={x:0,y:0,z:0};if(!e.Utils.isNullOrEmpty(t)){for(var i=t.length,n=0;n<t.length;n++){var o=t[n];r.x+=o.x,r.y+=o.y,r.z+=o.z}var s=1*i;r.x/=s,r.y/=s,r.z/=s}return r}static boundingBox(t){const r={minX:1/0,minY:1/0,minZ:1/0,maxX:-1/0,maxY:-1/0,maxZ:-1/0};if(!e.Utils.isNullOrEmpty(t))for(var i=0;i<t.length;i++){var n=t[i];r.minX=Math.min(r.minX,n.x),r.minY=Math.min(r.minY,n.y),r.minZ=Math.min(r.minZ,n.z),r.maxX=Math.max(r.maxX,n.x),r.maxY=Math.max(r.maxY,n.y),r.maxZ=Math.max(r.maxZ,n.z)}return r}setAsDirty(){r.call(this)}}function r(){this.flags=[t.StalePropertyFlag.Geometry]}t.NodeGeometry=NodeGeometry;class LineGeometry extends NodeGeometry{}__decorate([t.NotifyChange(r)],LineGeometry.prototype,"positions",void 0),t.LineGeometry=LineGeometry;class MeshGeometry extends NodeGeometry{#e;#t;#r;get barycenter(){return this.#r??=NodeGeometry.barycenter(this.positions)}set barycenter(e){this.#r=e}get boundingBox(){return this.#e??=NodeGeometry.boundingBox(this.positions)}set boundingBox(e){this.#e=e}get boundingSphere(){return this.#t}set boundingSphere(e){this.#t=e}constructor(e,t,r=[],i=[]){super(e),this.triangleIndices=t,this.textureCoordinates=r,this.normals=i}}__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"positions",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"triangleIndices",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"textureCoordinates",void 0),__decorate([t.NotifyChange(r)],MeshGeometry.prototype,"normals",void 0),t.MeshGeometry=MeshGeometry}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){function r(t){return!e.Utils.isNull(t)&&"render"in t&&"function"==typeof t.render}function i(e){return r(e?.stage)}function n(e){return"transformMatrix"in e&&i(e)}function o(e){return"type"in e&&"up"in e&&"lookAt"in e&&i(e)}function s(t){return"positions"in t&&e.Utils.isArray(t.positions)}function a(t,r,i){const n=e.Geometry.LinearAlgebra.Vector3D.subtract(t,r),o=e.Geometry.LinearAlgebra.Vector3D.subtract(t,i),s=e.Geometry.LinearAlgebra.Vector3D.cross(n,o);return e.Geometry.LinearAlgebra.Vector3D.unit(s)}t.isStage=r,t.isRenderable=i,t.isUi3DObject=n,t.isCamera=o,t.isPerspectiveCamera=function(e){return o(e)&&"type"in e&&"perspective"===e.type},t.isOrthographicCamera=function(e){return o(e)&&"type"in e&&"orthographic"===e.type},t.isLight=function(e){return"type"in e&&("ambient"===e.type||"omni"===e.type||"direction"===e.type||"spot"==e.type)&&i(e)},t.isMesh=function(e){return"geometry"in e&&n(e)},t.isGeometry=s,t.isMeshGeometry=function(t){return("triangleIndices"in t&&e.Utils.isArray(t.triangleIndices)||"normals"in t&&e.Utils.isArray(t.normals)||"textureCoordinates"in t&&e.Utils.isArray(t.textureCoordinates))&&s(t)},t.isGroup=function(t){return"childRenderables"in t&&e.Utils.isArray(t.childRenderables)&&n(t)},t.computeSharpVertexNormals=function(t){const r=[];if(!e.Utils.isNullOrEmpty(t)){const e=t.triangleIndices;if(e.length%3!=0)throw new RangeError(`Invalid mesh geometry: ${e.length} is not multiple of 3.`);for(let i=2;i<e.length;i+=3){const n=e[i-2],o=e[i-1],s=e[i],l=a(t.positions[n],t.positions[o],t.positions[s]);r.push(l,l,l)}}t.normals=r},t.computePlaneNormal=a;class UI3DEvent extends e.CustomUIEvent{constructor(e,t,r,i){super(e,t,r),this.#i=i}#i;get point(){return this.#i}}t.UI3DEvent=UI3DEvent;t.DragEvent=class DragEvent extends UI3DEvent{};let l;t.RenderableEvent=class RenderableEvent extends UI3DEvent{constructor(e,t,r,i){super(e,{detail:t,bubbles:!0,cancelable:!0},r,i)}},function(e){e.Position="position",e.Transform="transform",e.Geometry="geometry",e.Children="children",e.Material="material",e.Light="light",e.Camera="camera",e.Visibility="visibility"}(l=t.StalePropertyFlag||(t.StalePropertyFlag={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){r.TAG_MIDDLE_NAME="3d",r.DEG2RAD=Math.PI/180;const i={OBJECT_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-object",LIGHT_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-light",PERSPECTIVE_CAMERA_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-perspective-camera",ORTHO_CAMERA_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-orthographic-camera",LINE_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-line",MESH_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-mesh",GROUP_SELECTOR:e.P+"-"+r.TAG_MIDDLE_NAME+"-group",DEFAULT_COORDS:{x:0,y:0,z:0}},n=e.Drawing3D.StalePropertyFlag;class RenderableElement extends t.PacemCrossItemsContainerElement{constructor(){super(...arguments),this.position=i.DEFAULT_COORDS,this.#n=[]}validate(e){return!1}findContainer(){return this.parent||this.stage}get stage(){return this._scene=this._scene||e.CustomElementUtils.findAncestorOfType(this,r.Pacem3DElement)}get parent(){return this._drawableParent=this._drawableParent||e.CustomElementUtils.findAncestor(this,e=>e instanceof RenderableElement)}disconnectedCallback(){delete this._scene,delete this._drawableParent,super.disconnectedCallback()}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"hide":this.setAsDirty(n.Visibility);break;case"items":this.setAsDirty(n.Children);break;case"position":this.setAsDirty(n.Position)}}#n;get flags(){return this.#n}setAsDirty(...e){for(let t of e)this.flags.includes(t)||this.flags.push(t);this.stage?.render(this)}}__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],RenderableElement.prototype,"position",void 0),__decorate([e.Watch({emit:!1,reflectBack:!0,converter:e.PropertyConverters.String})],RenderableElement.prototype,"tag",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],RenderableElement.prototype,"inert",void 0),r.RenderableElement=RenderableElement;class Ui3DElement extends RenderableElement{propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"transformMatrix":this.setAsDirty(n.Transform);break;case"translateZ":case"translateX":case"translateY":this.offset={x:this.translateX,y:this.translateY,z:this.translateZ};break;case"scaleX":case"scaleY":case"scaleZ":this.scale={x:this.scaleX,y:this.scaleY,z:this.scaleZ};break;case"scale":case"offset":case"rotate":this._computeTransformMatrix()}}_computeTransformMatrix(){const t=e.Geometry.LinearAlgebra.Matrix3D,r=e.Geometry.LinearAlgebra.Vector3D,i=e.Geometry.LinearAlgebra.Quaternion,n=this.scale??r.from(1,1,1);let o=t.scale(t.identity(),n);if(!e.Utils.isNull(this.rotate)){const e=i.toRotationMatrix(this.rotate);o=t.multiply(o,e)}const s=this.offset??r.from(0,0,0);o=t.translate(o,s),this.transformMatrix=o}}__decorate([e.Watch({emit:!1,converter:e.Drawing3D.QuaternionConverter})],Ui3DElement.prototype,"rotate",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DOrNumberConverter})],Ui3DElement.prototype,"scale",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DOrNumberConverter})],Ui3DElement.prototype,"offset",void 0),__decorate([e.Watch({emit:!1})],Ui3DElement.prototype,"transformMatrix",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleX",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleY",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"scaleZ",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateX",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateY",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Ui3DElement.prototype,"translateZ",void 0),r.Ui3DElement=Ui3DElement;let o=class Pacem3DGroupElement extends Ui3DElement{validate(e){return e instanceof RenderableElement}#o=[];get childRenderables(){return this.#o}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"items":case"datasource":this.#o=r||[],this.setAsDirty(n.Children)}}};__decorate([e.Watch({emit:!1})],o.prototype,"datasource",void 0),o=__decorate([e.CustomElement({tagName:i.GROUP_SELECTOR})],o),r.Pacem3DGroupElement=o;let s=class Pacem3DMeshElement extends Ui3DElement{propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"geometry":this.setAsDirty(n.Geometry);break;case"material":case"backMaterial":this.setAsDirty(n.Material)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"geometry",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"material",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],s.prototype,"backMaterial",void 0),s=__decorate([e.CustomElement({tagName:i.MESH_SELECTOR})],s),r.Pacem3DMeshElement=s;let a=class Pacem3DObjectElement extends Ui3DElement{propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"content"!==e&&"type"!==e||this.setAsDirty(n.Geometry,n.Material)}};__decorate([e.Watch({emit:!1})],a.prototype,"content",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],a.prototype,"type",void 0),a=__decorate([e.CustomElement({tagName:i.OBJECT_SELECTOR})],a),r.Pacem3DObjectElement=a;let l=class Pacem3DLightElement extends RenderableElement{constructor(){super(...arguments),this.intensity=.85,this.target=i.DEFAULT_COORDS,this.color="#fff",this.type="omni"}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"type":case"color":case"intensity":case"target":this.setAsDirty(n.Light)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],l.prototype,"intensity",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],l.prototype,"target",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],l.prototype,"color",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],l.prototype,"type",void 0),l=__decorate([e.CustomElement({tagName:i.LIGHT_SELECTOR})],l),r.Pacem3DLightElement=l;class Pacem3DCameraElement extends RenderableElement{constructor(){super(...arguments),this.near=.1,this.far=1e3,this.up=e.Geometry.LinearAlgebra.Vector3D.j(),this.lookAt=i.DEFAULT_COORDS}#s;_resetBoundingSphere(){const t=this.#s,r=this.position,i=this.lookAt,n=e.Utils.isNullOrEmpty(r)||e.Utils.isNullOrEmpty(i)?0:e.Geometry.LinearAlgebra.Vector3D.mag(e.Geometry.LinearAlgebra.Vector3D.subtract(r,i)),o=this.#s={center:i,radius:n};this.dispatchEvent(new e.PropertyChangeEvent({currentValue:o,propertyName:"boundingSphere",oldValue:t}))}get boundingSphere(){return this.#s}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"lookAt":case"position":this._resetBoundingSphere();case"near":case"far":case"up":this.setAsDirty(n.Camera)}}}__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Pacem3DCameraElement.prototype,"near",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],Pacem3DCameraElement.prototype,"far",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],Pacem3DCameraElement.prototype,"up",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.Point3DConverter})],Pacem3DCameraElement.prototype,"lookAt",void 0),r.Pacem3DCameraElement=Pacem3DCameraElement;let c=class Pacem3DPerspectiveCameraElement extends Pacem3DCameraElement{constructor(){super(...arguments),this.fov=45,this.aspect=1}get type(){return"perspective"}get aspectRatio(){return this.aspect}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"fov":case"aspect":this.setAsDirty(n.Camera)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],c.prototype,"fov",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],c.prototype,"aspect",void 0),c=__decorate([e.CustomElement({tagName:i.PERSPECTIVE_CAMERA_SELECTOR})],c),r.Pacem3DPerspectiveCameraElement=c;let u=class Pacem3DOrthographicCameraElement extends Pacem3DCameraElement{constructor(){super(...arguments),this.top=1,this.left=-1,this.bottom=-1,this.right=1}get type(){return"orthographic"}propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"top":case"left":case"bottom":case"right":this.setAsDirty(n.Camera)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"top",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"left",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"bottom",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],u.prototype,"right",void 0),u=__decorate([e.CustomElement({tagName:i.ORTHO_CAMERA_SELECTOR})],u),r.Pacem3DOrthographicCameraElement=u;class Pacem3DAdapterElement extends t.PacemEventTarget{}r.Pacem3DAdapterElement=Pacem3DAdapterElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){let i=class Pacem3DElement extends t.PacemItemsContainerElement{constructor(){super(...arguments),this._itemPropertyChangeHandler=e=>{const t=e.target;this.adapter&&this.adapter.updateItem(this,t),t.flags.splice(0)},this._clickHandler=t=>{let r=this;if(!r.interactive||e.Utils.isNull(r._lastHitResult))return;const i=t.type.replace(/^mouse/,""),n=r._lastHitResult,o=n.object,s=n.point;this._itemDispatch(o,s,i,t)},this._hitTestCallback=(t,r)=>{const i=this;if(t!=i._lastHitResult){if(t?.object!=i._lastHitResult?.object){const n=t?.object,o=i._lastHitResult?.object,s=t?.point;e.Utils.isNull(o)||this._itemDispatch(o,s,"out",r),e.Utils.isNull(n)||this._itemDispatch(n,s,"over",r)}i._lastHitResult=t}},this._moveHandler=e=>{let t=this;if(!t.adapter||!t.interactive)return;const r=t._resizer.currentSize,i="mousemove"===e.type?{x:e.pageX-r.left,y:e.pageY-r.top}:{x:-1,y:-1};t.adapter.raycast(this,i,r,r=>t._hitTestCallback(r,e))},this._resizeHandler=r=>{const i=this.#a,n=r.detail;if(!e.Utils.isNull(i)&&i.height===n.height&&i.width===n.width)return;this.#a=n;const o=this.adapter;e.Utils.isNull(o)||(this.adapter.invalidateSize(this,n),this.dispatchEvent(new t.ResizeEvent(n)))}}validate(e){return e instanceof r.RenderableElement}get stage(){return this._container}get scene(){return this.adapter&&this.adapter.getScene(this)}register(t){const r=super.register(t);return r&&(this._add(t),t.addEventListener(e.PropertyChangeEventName,this._itemPropertyChangeHandler,!1)),r}unregister(t){const r=super.unregister(t);return r&&(t.removeEventListener(e.PropertyChangeEventName,this._itemPropertyChangeHandler,!1),this._erase(t)),r}_refreshDatasource(e=this.datasource){this.adapter?.updateItem(this,void 0)}_buildUpDatasourceFromDOM(t=this.items){e.Utils.isNullOrEmpty(t)||(this.datasource=t.slice())}_add(e){this.adapter&&this.adapter.addItem(this,e)}_erase(e){this.adapter&&this.adapter.removeItem(this,e)}_initializeAdapter(t,r){return new Promise((i,n)=>{const o=this.datasource||[];e.Utils.isNull(t)||o.forEach(e=>t.removeItem(this,e)),e.Utils.isNull(this._container)||e.Utils.isNull(r)?i():r.initialize(this).then(e=>{(o||[]).forEach(e=>this._add(e)),i()},t=>{this.log(e.Logging.LogLevel.Error,t?.toString()),n(t)})})}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"adapter":this._initializeAdapter(t,r);break;case"items":this._buildUpDatasourceFromDOM(r);break;case"transparent":this.adapter?.invalidateSize(this,this.size);break;case"datasource":this._refreshDatasource(r);case"disabled":case"background":this.render()}}viewActivatedCallback(){super.viewActivatedCallback();const e=this._container,t=this._resizer;t.addEventListener("resize",this._resizeHandler,!1),t.target=e,this._initializeAdapter(null,this.adapter).then(t=>{e.addEventListener("mousemove",this._moveHandler,!1),e.addEventListener("click",this._clickHandler,!1),e.addEventListener("mouseup",this._clickHandler,!1),e.addEventListener("mousedown",this._clickHandler,!1),e.addEventListener("mouseout",this._moveHandler,!1),this._buildUpDatasourceFromDOM(),this.render()})}_itemDispatch(t,r,i,n){if(!e.Utils.isNull(t)){var o,s,a;n instanceof Event?s=n:o={item:t,offset:n},"string"==typeof i?a=i:(a=i.type,s=i.originalEvent);const c=r,u=()=>n instanceof Event?new e.Drawing3D.RenderableEvent(a,t,s,c):new e.Drawing3D.DragEvent(a,{detail:o,cancelable:a===e.UI.DragDropEventType.Init||a===e.UI.DragDropEventType.Drag},s,c),d=n instanceof Event?new e.Drawing3D.RenderableEvent("item"+a,t,s,c):new e.Drawing3D.DragEvent("item"+a,{detail:o,cancelable:a===e.UI.DragDropEventType.Init||a===e.UI.DragDropEventType.Drag},s,c);var l=!1;if(t instanceof EventTarget){const e=u();t.dispatchEvent(e),l=e.defaultPrevented}return t.stage.dispatchEvent(d),l||d.defaultPrevented}return!1}disconnectedCallback(){this.#l?.stop();const t=this._resizer,r=this._container;e.Utils.isNull(r)||(r.removeEventListener("click",this._clickHandler,!1),r.removeEventListener("mouseup",this._clickHandler,!1),r.removeEventListener("mousedown",this._clickHandler,!1),r.removeEventListener("mousemove",this._moveHandler,!1),r.removeEventListener("mouseout",this._moveHandler,!1)),e.Utils.isNull(t)||t.removeEventListener("resize",this._resizeHandler,!1),super.disconnectedCallback()}#a;get size(){return this.#a}render(t,r,i=performance.now()){if(e.Utils.isNull(t))this.#l?.stop(),this.#l=e.Animations.Timer.run(e=>this._doRender());else{const r=this.adapter;e.Utils.isNull(r)||r.updateItem(this,t)}}#l;_doRender(){if(!this.disabled&&!e.Utils.isNull(this.adapter)){const e=this.adapter.getScene(this);let t=new CustomEvent("prerender",{detail:{scene:e},cancelable:!0});this.dispatchEvent(t),t.defaultPrevented||(this.adapter.render(this),this.dispatchEvent(new CustomEvent("render",{detail:{scene:e}})))}}};__decorate([e.ViewChild(`.${e.PCSS}-3d`)],i.prototype,"_container",void 0),__decorate([e.ViewChild(e.P+"-resize")],i.prototype,"_resizer",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"interactive",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"transparent",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],i.prototype,"background",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Element})],i.prototype,"adapter",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],i.prototype,"datasource",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],i.prototype,"orbit",void 0),i=__decorate([e.CustomElement({tagName:e.P+"-"+r.TAG_MIDDLE_NAME,shadow:e.Defaults.USE_SHADOW_ROOT,template:`<${e.P}-resize watch-position="true"></${e.P}-resize><div class="${e.PCSS}-3d"></div><${e.P}-content></${e.P}-content>`})],i),r.Pacem3DElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){class AdapterUtils{static isMeshGeometry(t){return"positions"in t&&e.Utils.isArray(t.positions)&&"triangleIndices"in t&&e.Utils.isArray(t.triangleIndices)}static isVector3D(e){return"x"in e&&"number"==typeof e.x&&"y"in e&&"number"==typeof e.y&&"z"in e&&"number"==typeof e.z}static isRgba(e){return"r"in e&&"number"==typeof e.r&&"g"in e&&"number"==typeof e.g&&"b"in e&&"number"==typeof e.b}static flattenVectorArray(e){const t=[];for(let r of e)AdapterUtils.isVector3D(r)?t.push(r.x,r.y,r.z):AdapterUtils.isRgba(r)?t.push(r.r,r.g,r.b,r.a??1):t.push(r.x,r.y);return t}static findCamera(t){return(t||[]).find(t=>e.Drawing3D.isCamera(t)&&!t.hide)}clipPixel(t,r){return r instanceof HTMLElement&&(r=e.Utils.offsetRect(r)),function(t,r){let i,n;if(e.Point.isPoint(t))i=t.x,n=t.y;else{const{page:o}=e.CustomEventUtils.getEventCoordinates(t),s={x:o.x-r.x,y:o.y-r.y};i=s.x,n=s.y}return{x:i/r.width*2-1,y:n/r.height*-2+1}}(t,r)}}t.AdapterUtils=AdapterUtils}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(e){let t;function r(e){return"shader"in e}!function(e){e.Basic="basic",e.Lambert="lambert",e.Phong="phong",e.Standard="standard",e.Line="line",e.Custom="custom"}(t=e.KnownShader||(e.KnownShader={})),e.isMaterial=r,e.isBasicMaterial=function(e){return r(e)&&e.shader===t.Basic},e.isLineMaterial=function(e){return r(e)&&e.shader===t.Line},e.isLambertMaterial=function(e){return r(e)&&e.shader===t.Lambert},e.isPhongMaterial=function(e){return r(e)&&e.shader===t.Phong},e.isStandardMaterial=function(e){return r(e)&&e.shader===t.Standard},e.isShaderMaterial=function(e){return r(e)&&e.shader===t.Custom}}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){class MaterialElement extends t.PacemEventTarget{constructor(e){super(),this.#c=e}#c;get shader(){return this.#c}async _loadMap(t,r=this.material?.texture){if(e.Utils.isNull(r)||r.close(),e.Utils.isNullOrEmpty(t))return null;const i=await e.Imaging.loadImage(t);return e.Utils.isNull(i)?null:await createImageBitmap(i)}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"map":case"opacity":case"wireframe":case"color":case"hide":this.updateMaterial()}}viewActivatedCallback(){super.viewActivatedCallback(),this.updateMaterial()}updateMaterial(){this.createMaterial().then(t=>{this.material=e.Utils.extend(t,{flags:[e.Drawing3D.StalePropertyFlag.Material]})})}async createMaterial(){return{opacity:this.opacity??1,wireframe:this.wireframe??!1,color:this.color||e.Utils.Css.getVariableValue(`--${e.PCSS}-color-primary`),visible:!this.hide,map:this.map,texture:await this._loadMap(this.map),shader:this.shader,flags:[]}}}__decorate([e.Watch()],MaterialElement.prototype,"material",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],MaterialElement.prototype,"opacity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],MaterialElement.prototype,"wireframe",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],MaterialElement.prototype,"color",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],MaterialElement.prototype,"hide",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],MaterialElement.prototype,"map",void 0),r.MaterialElement=MaterialElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){function r(e){return t.AdapterUtils.flattenVectorArray(e)}const i="0.152.2",n={VERSION:i,API_URI:`https://unpkg.com/three@${i}/build/three.min.js`,ORBIT_URI:"https://unpkg.com/three@0.147.0/examples/js/controls/OrbitControls.js",LOADERS:[],DEFAULT_MATERIAL:function(){return new THREE.MeshStandardMaterial({color:"#069",flatShading:!0})}};function o(t){if(e.Utils.isNull(t))return null;const r={color:"string"==typeof t.color?t.color:e.Colors.stringify(t.color),opacity:t.opacity??1,transparent:!0,wireframe:t.wireframe??!1,visible:t.visible??!0},i=e.Utils.extend({},r,{wireframe:t.wireframe??!1}),n=e=>(t.map&&(e.map=(new THREE.TextureLoader).load(t.map,t=>{e.needsUpdate=!0})),e);if(e.Drawing3D.isStandardMaterial(t)){return n(new THREE.MeshStandardMaterial(e.Utils.extend(i,{roughness:t.roughness,metalness:t.metalness,emissive:t.emissiveColor,flatShading:t.flatShading,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isPhongMaterial(t)){return n(new THREE.MeshPhongMaterial(e.Utils.extend(i,{shininess:t.shininess,emissive:t.emissiveColor,flatShading:t.flatShading,specular:t.specularColor,reflectivity:t.reflectivity,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isLambertMaterial(t)){return n(new THREE.MeshLambertMaterial(e.Utils.extend(i,{emissive:t.emissiveColor,reflectivity:t.reflectivity,refractionRatio:t.refractionRatio})))}if(e.Drawing3D.isLineMaterial(t)){const i=t.dashArray&&t.dashArray[0]||null,n=t.dashArray&&t.dashArray.length>1&&t.dashArray[1]||i,o=e.Utils.extend(r,{linecap:t.lineCap??"round",linejoin:t.lineJoin??"round",linewidth:t.lineWidth??1});return e.Utils.isNullOrEmpty(t.dashArray)?new THREE.LineBasicMaterial(o):new THREE.LineDashedMaterial(e.Utils.extend({dashSize:i,gapSize:n},o))}if(e.Drawing3D.isMaterial(t)){return n(new THREE.MeshBasicMaterial(i))}return null}function s(t){if(e.Utils.isNullOrEmpty(t.content))throw new Error("Missing content.");{const e=t.type?.toLowerCase();if("obj"===e){return(new THREE.OBJLoader).parse(t.content)}return(new THREE.ObjectLoader).parse(t.content)}}function a(t){if(e.Utils.isNullOrEmpty(t.geometry))return null;return new(t.geometry instanceof e.Drawing3D.LineGeometry?THREE.Line:THREE.Mesh)}function l(){return"THREE"in window}let c=class Pacem3DThreeAdapterElement extends t.Pacem3DAdapterElement{constructor(){super(...arguments),this._renderer=null,this._camera=null,this._scene=null,this._orbitCtrls=null,this._objects=new WeakMap,this._dict={},this._orbitControlsDelegate=e=>{},this._ensureAndRefresh=(i,l,c)=>{if(l.matrixAutoUpdate=!1,l.visible=!i.hide){if(e.Drawing3D.isMesh(i)){let t=l;if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Geometry)>=0){t.geometry.dispose();const n=a(i);n.constructor.name!==t.constructor.name&&(c.remove(l),delete this._dict[l.id],l=t=n),t.geometry=function(t){const i=new THREE.BufferGeometry,n=r(t.positions);if(i.setAttribute("position",new THREE.Float32BufferAttribute(n,3)),t instanceof e.Drawing3D.MeshGeometry){e.Utils.isNullOrEmpty(t.triangleIndices)||i.setIndex(t.triangleIndices);const n=r(t.positions);i.setAttribute("position",new THREE.Float32BufferAttribute(n,3));const o=r(t.textureCoordinates);if(i.setAttribute("uv",new THREE.Float32BufferAttribute(o,2)),e.Utils.isNullOrEmpty(t.normals))i.computeVertexNormals();else{const e=r(t.normals);i.setAttribute("normal",new THREE.Float32BufferAttribute(e,3))}}return i}(i.geometry)}if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Material)>=0){if(e.Utils.isArray(t.material))for(let e of t.material)e.dispose();else t.material.dispose();t.material=function(t,r,i){const n=i,s=[],a=o(t);if(e.Utils.isNull(a)||(a.side=THREE.FrontSide,s.push(a)),!e.Utils.isNull(r))if(r==t)a.side=THREE.DoubleSide;else{const t=o(r);e.Utils.isNull(t)||(t.side=THREE.BackSide,s.push(t))}return n&&s.length>1?s:a}(i.material)||n.DEFAULT_MATERIAL()}}else if(i instanceof t.Pacem3DObjectElement&&(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Material)>=0||i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Geometry)>=0))l.parent&&l.parent.remove(l),l=s(i);else if(i instanceof t.Pacem3DGroupElement){if(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Children)>=0){for(let e=l.children.length-1;e>=0;e--){const t=l.children[e];l.remove(t)}for(let e of i.items)this._addOrUpdateItem(e,l)}}else if(i instanceof t.Pacem3DLightElement){const t=l;i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Light)>=0&&(t.color=new THREE.Color(i.color),t.intensity=i.intensity)}let d=i.position;if(e.Drawing3D.isUi3DObject(i)&&!e.Utils.isNull(i.transformMatrix)&&(i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Position)>=0||i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Transform)>=0)){const t=e.Geometry.LinearAlgebra.Matrix3D.from(1,0,0,0,0,1,0,0,0,0,1,0,d.x,d.y,d.z,1),r=e.Geometry.LinearAlgebra.Matrix3D.multiply(i.transformMatrix,t);THREE.Matrix4.prototype.set.apply(l.matrix,[(u=r).m11,u.m21,u.m31,u.offsetX,u.m12,u.m22,u.m32,u.offsetY,u.m13,u.m23,u.m33,u.offsetZ,u.m14,u.m24,u.m34,u.m44])}else i.flags.indexOf(e.Drawing3D.StalePropertyFlag.Position)>=0&&(l.position.set(d.x,d.y,d.z),l.updateMatrix())}var u;return l.userData=i.tag,e.Utils.isNull(c.getObjectById(l.id))&&(c.add(l),this._dict[l.id]=i),i.flags.splice(0),l}}_assertMonoStage(t){if(t!=this._3d&&!e.Utils.isNull(this._3d))throw new Error("Stage mismatch.")}dispose(e){}snapshot(t,r,i,n){if(t!=this._3d)return Promise.resolve(null);const o=!e.Utils.isNullOrEmpty(r),s=i??(o?"image/jpeg":null),a=n??(o?.9:null);return new Promise((t,i)=>{this.render(),e.Utils.snapshotElement(this._stage,r,s,a).then(t)})}project(t,r){if(this._assertMonoStage(t),e.Utils.isNull(this._camera)||e.Utils.isNull(this._stage))return null;const i=this._stage,n=new THREE.Vector3(r.x,r.y,r.z),o=i.width/2,s=i.height/2,a=n.project(this._camera);return{x:a.x*o+o,y:-a.y*s+s}}zoomFit(t,...r){return this._assertMonoStage(t),new Promise((t,i)=>{const n=this._camera,o=this._objects,s=r.filter(e=>o.has(e)).map(e=>o.get(e));(e.Utils.isNull(n)||e.Utils.isNullOrEmpty(s))&&t(),function(t,r,i,n=1.333){const o=new THREE.Box3;for(const e of i)o.expandByObject(e);const s=o.getSize(new THREE.Vector3),a=o.getCenter(new THREE.Vector3),l=Math.max(s.x,s.y,s.z)/(2*Math.atan(Math.PI*t.fov/360)),c=l/t.aspect,u=n*Math.max(l,c),d=!e.Utils.isNull(r);var h;d&&(h=r.target.clone().sub(t.position).normalize().multiplyScalar(u),r.maxDistance=10*u,r.target.copy(a)),t.near=u/100,t.far=100*u,t.updateProjectionMatrix(),d&&(t.position.copy(r.target).sub(h),r.update())}(n,this._orbitCtrls,s),t()})}getScene(e){return this._assertMonoStage(e),this._scene}raycast(t,r,i,n){if(this._assertMonoStage(t),l()&&!e.Utils.isNull(this._camera)){const e=this._camera,t=new THREE.Vector2(r.x/i.width*2-1,-r.y/i.height*2+1),o=new THREE.Raycaster;o.setFromCamera(t,e);const s=o.intersectObjects(this._scene.children,!0);let a,l,c=0;for(;s.length>c&&(l=s[c++])&&(a=l.object);){if(this._dict[a.id].inert)continue;const e=l.point,t={x:e.x,y:e.y,z:e.z};return void n({object:this._dict[a.id],point:t})}}n(null)}async initialize(t){if(!e.Utils.isNull(this._stage))return this._stage;this._3d=t;const r=t.stage,i=this._stage=document.createElement("canvas");r.innerHTML="",r.appendChild(i),l()||(await e.CustomElementUtils.importjs(n.API_URI),await async function(...e){const t=Date.now();var r=!1;do{r=l();for(let t of e)r&&=t();r||await new Promise(e=>setTimeout(e,500))}while(!r&&Date.now()-t<3e4);if(!r)throw new Error("The wait for THREE adapter initialization timed out.")}(),await Promise.all([e.CustomElementUtils.importjs(n.ORBIT_URI)].concat(n.LOADERS.map(t=>e.CustomElementUtils.importjs(t))))),this._scene=new THREE.Scene,this.invalidateSize(t);let o=this._stage.width,s=this._stage.height,a={canvas:i,antialias:!0,stencil:!1,alpha:t.transparent??!0};if(this._renderer=new THREE.WebGLRenderer(a),this._renderer.setSize(o,s),t.background&&!t.transparent){let r=t.background;"string"==typeof r&&(r=e.Colors.parse(r));const i=new THREE.Color(r.r,r.g,r.b);this._renderer.setClearColor(i,r.a)}return this.orbit=t.orbit,i}_setCamera(e){this._camera=e,this.invalidateSize(this._3d),this._disposeOrbitControls(),this.orbit&&this._initOrbitControls()}propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"orbit"===e&&(!0===r?this._initOrbitControls():this._disposeOrbitControls())}_initOrbitControls(){const t=this._camera;if(e.Utils.isNull(this._3d)||e.Utils.isNull(t))return;(this._orbitCtrls=new THREE.OrbitControls(t,this._3d.stage)).addEventListener("change",this._orbitControlsDelegate)}_disposeOrbitControls(){const t=this._orbitCtrls;e.Utils.isNull(t)||(t.removeEventListener("change",this._orbitControlsDelegate),t.dispose())}_updateRenderer(t,r=this._renderer){if(t.transparent)r.setClearAlpha(0);else if(t.background){let i=t.background;"string"==typeof i&&(i=e.Colors.parse(i));const n=new THREE.Color(i.r,i.g,i.b);r.setClearColor(n,i.a)}else r.setClearColor(null)}invalidateSize(t,r=t.size){if(this._assertMonoStage(t),!l()||e.Utils.isNull(r))return;let i=r.width,n=r.height;this._stage.width=i,this._stage.height=n;let o=this._camera;o instanceof THREE.PerspectiveCamera&&(o.aspect=i/n,o.updateProjectionMatrix()),this._renderer&&(this._renderer.setSize(i,n),this._updateRenderer(t))}removeItem(t,r){this._assertMonoStage(t);const i=this._objects,n=i.get(r);e.Utils.isNull(n)||(this._scene.remove(n),delete this._dict[n.id],i.delete(r))}updateItem(t,r){this._assertMonoStage(t);const i=this._objects;if(!e.Utils.isNull(r.parent)&&i.has(r.parent)){const e=i.get(r.parent);this._addOrUpdateItem(r,e)}else this._addOrUpdateItem(r)}addItem(e,t){this._assertMonoStage(e),this._addOrUpdateItem(t)}_addOrUpdateItem(r,i=this._scene){if(l()&&!e.Utils.isNull(i))if(r instanceof t.Pacem3DCameraElement)if(r instanceof t.Pacem3DPerspectiveCameraElement){if(this._camera instanceof THREE.PerspectiveCamera)var n=this._camera;else n=new THREE.PerspectiveCamera;const t=new THREE.Vector3(r.lookAt.x,r.lookAt.y,r.lookAt.z);n.lookAt(t),n.position.set(r.position.x,r.position.y,r.position.z),n.fov=r.fov,n.aspect=r.aspect,n.near=r.near,n.far=r.far,this._setCamera(n);const i=this._orbitCtrls;e.Utils.isNull(i)||i.object!==n||(i.target=t,i.update())}else{if(!(r instanceof t.Pacem3DOrthographicCameraElement))throw new Error(`Camera ${r} not supported.`);{if(this._camera instanceof THREE.OrthographicCamera)var o=this._camera;else o=new THREE.OrthographicCamera;const t=new THREE.Vector3(r.lookAt.x,r.lookAt.y,r.lookAt.z);o.lookAt(t),o.position.set(r.position.x,r.position.y,r.position.z),o.left=r.left,o.right=r.right,o.top=r.top,o.bottom=r.bottom,o.near=r.near,o.far=r.far,this._setCamera(o);const i=this._orbitCtrls;e.Utils.isNull(i)||i.object!==o||(i.target=t,i.update())}}else if(this._objects.has(r)){const e=this._objects.get(r),t=this._ensureAndRefresh(r,e,i);t!=e&&this._objects.set(r,t)}else{const e=e=>{e&&(e=this._ensureAndRefresh(r,e,i),this._objects.set(r,e))};if(r instanceof t.Pacem3DObjectElement){e(s(r))}else if(r instanceof t.Pacem3DMeshElement){e(a(r))}else if(r instanceof t.Pacem3DLightElement){const t=function(e){var t;if("spot"===e.type){const r=new THREE.SpotLight;r.target.position.set(e.target.x,e.target.y,e.target.z),t=r}else t=new THREE.PointLight;return t}(r);e(t)}else if(r instanceof t.Pacem3DGroupElement){e(new THREE.Group)}}}render(){this._camera&&this._renderer.render(this._scene,this._camera)}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],c.prototype,"orbit",void 0),c=__decorate([e.CustomElement({tagName:e.P+"-3d-three-adapter"})],c),t.Pacem3DThreeAdapterElement=c}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){let t;!function(e){e.Mesh="mesh",e.Camera="camera",e.Texture="texture",e.Light="light"}(t=e.WGSLBindingType||(e.WGSLBindingType={}))}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.Buffers=class Buffers{static create(e,t,r=""){const i=e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});return new Float32Array(i.getMappedRange()).set(t),i.unmap(),i}static createUniform(e,t,r=""){return e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST})}static createStorage(e,t,r=""){return e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST})}static createIndexed(e,t,r=""){const i=e.createBuffer({size:t.byteLength,label:r,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0});return new Uint16Array(i.getMappedRange()).set(t),i.unmap(),i}};e.BufferLayouts=class BufferLayouts{static createVertex(e=0,t=3,...r){const i=[];let n=0,o=0;for(let s of[t].concat(r))i.push({shaderLocation:e+o,offset:n*Float32Array.BYTES_PER_ELEMENT,format:`float32x${s}`}),n+=s,o++;return{arrayStride:n*Float32Array.BYTES_PER_ELEMENT,attributes:i,stepMode:"vertex"}}}}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){const i=e.Geometry.LinearAlgebra.Vector3D,n=e.Geometry.LinearAlgebra.Matrix3D,o={width:1,height:1};function s(e,t,r){const o=i.subtract(t,e),s=i.cross(r,o),a=i.cross(o,s);i.normalize(s),i.normalize(o),i.normalize(a);const l=-i.dot(s,e),c=-i.dot(a,e),u=-i.dot(o,e);return n.from(s.x,a.x,o.x,0,s.y,a.y,o.y,0,s.z,a.z,o.z,0,l,c,u,1)}function a(e,t){if(e<=0)throw new RangeError("Near plane distance must be positive.");if(t<=e)throw new RangeError("Far plane distance must be greater than near plane distance.")}r.Camera=class Camera{static create(e){if(t.isPerspectiveCamera(e))return new PerspectiveCamera(e);if(t.isOrthographicCamera(e))return new OrthographicCamera(e);throw new TypeError(`Camera type '${e.type}' not supported.`)}};class OrthographicCamera{constructor(e){this._camera=e}static view(e){return s(e.position,e.lookAt,e.up)}static projection(e,t=o){const r=e.position,s=e.lookAt,l=i.subtract(s,r);i.normalize(l);const c=i.dot(l,r),{height:u,width:d}=t,h=.5*c,p=h*(d/u),m=h,f=e.top*m,g=e.bottom*m,_=e.right*p;return function(e,t,r,i,o=.1,s=1e3){return a(o,s),n.from(2/(t-e),0,0,0,0,2/(r-i),0,0,0,0,1/(o-s),0,(e+t)/(e-t),(r+i)/(i-r),o/(o-s),1)}(e.left*p,_,f,g,e.near,e.far)}view(){return OrthographicCamera.view(this._camera)}projection(e){return OrthographicCamera.projection(this._camera,e)}}r.OrthographicCamera=OrthographicCamera;class PerspectiveCamera{constructor(e){this._camera=e}static view(e){return s(e.position,e.lookAt,e.up)}static projection(e,t=o){const r=t.width/t.height/e.aspectRatio;return function(e=120,t=1,r=.1,i=1e3){a(r,i);const o=Math.tan(.5*Math.PI*(1-e/180)),s=o/t,l=Number.isFinite(i),c=l?i/(r-i):-1,u=l?i*r/(r-i):-r;return n.from(s,0,0,0,0,o,0,0,0,0,c,-1,0,0,u,0)}(e.fov,r,e.near,e.far)}view(){return PerspectiveCamera.view(this._camera)}projection(e){return PerspectiveCamera.projection(this._camera,e)}}r.PerspectiveCamera=PerspectiveCamera}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.LABEL_PREFIX="pacem-3d-",e.U32_MAX=4294967295,e.VERTEX_BUFFER_INDEX_MESH_POSITION=0,e.VERTEX_BUFFER_INDEX_MESH_NORMAL=1,e.VERTEX_BUFFER_INDEX_MESH_UV=2,e.VERTEX_OUTPUT_LOCATION_NORMAL=0,e.VERTEX_OUTPUT_LOCATION_VERTEX=1,e.VERTEX_OUTPUT_LOCATION_UV=2,e.VERTEX_OUTPUT_LOCATION_INDEX=3,e.VERTEX_OUTPUT_LOCATION_RAY=4,e.UNIFORM_GROUP_INDEX_TRANSFORM=0,e.UNIFORM_GROUP_INDEX_CAMERA=1,e.STORAGE_GROUP_INDEX_LINE=2,e.UNIFORM_GROUP_INDEX_COLORPICKING=2,e.UNIFORM_BINDING_INDEX_TRANSFORM=0,e.UNIFORM_BINDING_INDEX_CAMERA=0,e.MATERIAL_GROUP_INDEX=2,e.UNIFORM_GROUP_INDEX_LIGHTING=e.MATERIAL_GROUP_INDEX+1,e.STORAGE_MATERIAL_INDEX=0,e.SAMPLER_BINDING_INDEX=1,e.TEXTURE_BINDING_INDEX=2,e.MATERIAL_REFERENCE="material",e.VERTEX_COLOR_REFERENCE="color",e.AMBIENT_COLOR_REFERENCE="ambient",e.LIGHTING_COLOR_REFERENCE="lighting"}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayIndexLocation:t.VERTEX_OUTPUT_LOCATION_RAY,storageMaterialGroupIndex:t.MATERIAL_GROUP_INDEX,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getBasicMaterialFragmentWgsl=function(n={},o=r){const s=e.Utils.extend({},r,o),a=i(n.definitions),l=i(n.bindings),c=function(e=[]){let r="";for(let i of e){const e=i.trim();e.endsWith(";")?r+=e+"\r\n\t":r+=`${t.VERTEX_COLOR_REFERENCE} = ${e};\r\n\t`}return r}(n.modifiers),u=t.VERTEX_COLOR_REFERENCE,d=t.LIGHTING_COLOR_REFERENCE,h=t.AMBIENT_COLOR_REFERENCE;return`// definitions\n\n${a}\n\n// bindings\n@group(${o.storageMaterialGroupIndex}) @binding(${o.storageMaterialBindingIndex}) var<storage, read> diffuseColor: vec4f;\n${l}\n\nconst empty = vec4f(0,0,0,0);\nconst white = vec4f(1,1,1,1);\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${s.outputNormalLocation}) normal: vec3f, // world-space normal\n @location(${s.outputVertexLocation}) vertex: vec3f, // world-space position\n @location(${s.outputUvLocation}) uv: vec2f, \n @location(${s.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index, \n @location(${s.outputRayIndexLocation}) ray: vec3f // ray (eye-to-vertex) vector\n) -> @location(0) vec4f {\n var ${u} = diffuseColor;\n var ${h}: vec4f = empty;\n var ${d}: vec4f = empty;\n\n // modifiers\n ${c}\n\n ${d} = select(white, ${d}, ${d}.a > 0);\n return ${u} * ${d} + ${h};\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputInstanceIndexLocation:0,outputVertexIndexLocation:1,storageMaterialGroupIndex:t.STORAGE_GROUP_INDEX_LINE+1,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getLineMaterialFragmentWgsl=function(t={},n=r){const o=e.Utils.extend({},r,n),s=i(t.definitions),a=i(t.bindings),l=function(e=[]){let t="";for(let r of e){const e=r.trim();e.endsWith(";")?t+=e+"\r\n":t+=`output = ${e};\r\n`}return t}(t.modifiers);return`// definitions\n${s}\n\n// bindings\n@group(${n.storageMaterialGroupIndex}) @binding(${n.storageMaterialBindingIndex}) var<storage, read> vertexColors: array<vec4f>;\n${a}\n\nfn getVertexColor(index: u32) -> vec4f {\n let numColors = arrayLength(&vertexColors);\n let vertexColorIndex = index % numColors;\n return vertexColors[vertexColorIndex];\n}\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${o.outputInstanceIndexLocation}) @interpolate(flat) instance: u32, // instance index\n @location(${o.outputVertexIndexLocation}) @interpolate(flat) index: u32 // vertex index\n) -> @location(0) vec4f {\n var output = getVertexColor(index);\n\n // modifiers\n ${l}\n\n return output;\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){r.Material=class Material{static create(e){if(t.isBasicMaterial(e))return new BasicMaterial(e);if(t.isLineMaterial(e))return new LineMaterial(e);throw new TypeError(`Material type '${e.shader}' not supported.`)}};const i={};class MaterialBase{constructor(t){if(e.Utils.isNull(this.#u=t))throw new ReferenceError("Null material provided.")}#u;get material(){return this.#u}get wgsl(){return i}buffer({device:e},t=r.LABEL_PREFIX+"material-"+this.shader+"-buffer"){const{r:i,g:n,b:o,a:s}=this._diffuseColor(),a=new Float32Array([i,n,o,s]);return{buffer:r.Buffers.createStorage(e,a,t),value:a,version:performance.now()}}_diffuseColor(){const{visible:t,opacity:r,color:i}=this.material;if(!(t??1))return{r:0,g:0,b:0,a:0};const n="string"==typeof i?e.Colors.parse(i):i??{r:1,g:1,b:1,a:1};return r>=0&&r<=1?e.Utils.extend(n,{a:n.a*r}):n}}class BasicMaterial extends MaterialBase{get shader(){return t.KnownShader.Basic}constructor(e){if(super(e),e.shader!=this.shader)throw new TypeError("Basic material expected.")}texture({device:t},r="texture"){const i=this.material;if("texture"===r&&!e.Utils.isNull(i.texture)){const e=i.texture;return{texture:t.createTexture({format:"rgba8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_DST,size:[e.width,e.height]}),source:e}}return null}static{this.fragment=r.getBasicMaterialFragmentWgsl}}r.BasicMaterial=BasicMaterial;class LineMaterial extends MaterialBase{get shader(){return t.KnownShader.Line}constructor(e){if(super(e),e.shader!=this.shader)throw new TypeError("Line material expected.")}buffer(e,t){if("line"===t){const{device:t,canvas:i}=e,n=this.material,o=new Float32Array([i.clientWidth,i.clientHeight,n.lineWidth/2]);return{buffer:r.Buffers.createUniform(t,o,r.LABEL_PREFIX+"line-"+this.shader+"-buffer"),value:o,version:performance.now()}}return super.buffer(e)}texture(e){return null}static{this.fragment=r.getLineMaterialFragmentWgsl}}r.LineMaterial=LineMaterial}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={uv:"uv"};t.textureMap=function(i=r,n,o=t.SAMPLER_BINDING_INDEX){const s=e.Utils.uniqueCode(),a=`sampler_${s}`,l=`tex_${s}`,c=e.Utils.extend({},r,i),u=c.inputColor,d=c.outputColors;if(e.Utils.isNullOrEmpty(u))throw new Error("Must provide either input and output vertex color parameter names.");const h=d?d.map((e,t)=>0===t?`${e} = textureSample(${l}, ${a}, ${c.uv}) * ${u};`:`${e} = ${d[0]};`):[`textureSample(${l}, ${a}, ${c.uv}) * ${u}`];return{bindings:[`@group(${n}) @binding(${o}) var ${a}: sampler;`,`@group(${n}) @binding(${o+1}) var ${l}: texture_2d<f32>;`],modifiers:h}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayLocation:t.VERTEX_OUTPUT_LOCATION_RAY,inputPositionLocation:t.VERTEX_BUFFER_INDEX_MESH_POSITION,inputNormalLocation:t.VERTEX_BUFFER_INDEX_MESH_NORMAL,inputUvLocation:t.VERTEX_BUFFER_INDEX_MESH_UV,uniformViewBindingIndex:t.UNIFORM_BINDING_INDEX_CAMERA,uniformViewGroupIndex:t.UNIFORM_GROUP_INDEX_CAMERA,uniformWorldBindingIndex:t.UNIFORM_BINDING_INDEX_TRANSFORM,uniformWorldGroupIndex:t.UNIFORM_GROUP_INDEX_TRANSFORM};t.getMeshVertexWgsl=function(t=r){const i=e.Utils.extend({},r,t);return`struct VertexOutput {\n @builtin(position) position : vec4f, // clip space position\n @location(${i.outputNormalLocation}) normal: vec3f, // world space normal\n @location(${i.outputVertexLocation}) vertex : vec3f, // world space position\n @location(${i.outputUvLocation}) uv : vec2f, // texture coordinates\n @location(${i.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index\n @location(${i.outputRayLocation}) ray : vec3f, // eye-to-point\n}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\n@group(${i.uniformWorldGroupIndex}) @binding(${i.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${i.uniformViewGroupIndex}) @binding(${i.uniformViewBindingIndex}) var<uniform> camera: Camera;\n\n@vertex fn main(@location(${i.inputPositionLocation}) position: vec3f,\n @location(${i.inputNormalLocation}) normal: vec3f,\n @location(${i.inputUvLocation}) uv: vec2f,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n let position4 = vec4f(position, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n let worldPosition = (worldTransform * position4).xyz;\n return VertexOutput(\n worldViewProjectionTransform * position4,\n transforms.normal * normal,\n worldPosition,\n uv,\n index,\n normalize(worldPosition - camera.position)\n );\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={inputPositionLocation:t.VERTEX_BUFFER_INDEX_MESH_POSITION,outputInstanceIndexLocation:0,outputVertexIndexLocation:1,storagePositionsGroupIndex:t.STORAGE_GROUP_INDEX_LINE,storagePositionsBindingIndex:0,uniformDimensionsGroupIndex:t.STORAGE_GROUP_INDEX_LINE,uniformDimensionsBindingIndex:1,uniformViewGroupIndex:t.UNIFORM_GROUP_INDEX_CAMERA,uniformViewBindingIndex:t.UNIFORM_BINDING_INDEX_CAMERA,uniformWorldGroupIndex:t.UNIFORM_GROUP_INDEX_TRANSFORM,uniformWorldBindingIndex:t.UNIFORM_BINDING_INDEX_TRANSFORM};function i(e){return`struct VertexOutput {\n @builtin(position) position : vec4f, // clip space position\n @location(${e.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index\n @location(${e.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index\n}`}t.getDefaultLineVertexWgsl=function(t=r){const n=e.Utils.extend({},r,t);return`${i(n)}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\n@group(${n.uniformWorldGroupIndex}) @binding(${n.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${n.uniformViewGroupIndex}) @binding(${n.uniformViewBindingIndex}) var<uniform> camera: Camera;\n@group(${n.storagePositionsGroupIndex}) @binding(${n.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;\n\n@vertex fn main(@builtin(instance_index) instance: u32,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n \n let x = positions[3u * index + 0u];\n let y = positions[3u * index + 1u];\n let z = positions[3u * index + 2u];\n let position4 = vec4f(x, y, z, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n let worldPosition = (worldTransform * position4).xyz;\n return VertexOutput(\n worldViewProjectionTransform * position4,\n instance,\n index);\n}`},t.getFatLineVertexWgsl=function(t=r){const n=e.Utils.extend({},r,t);return`${i(n)}\n\nstruct Transforms {\n world: mat4x4f,\n normal: mat3x3f,\n}\n\nstruct Camera {\n view: mat4x4f,\n projection: mat4x4f,\n position: vec3f\n}\n\nstruct Pixels {\n viewportWidth: f32,\n viewportHeight: f32,\n halfLineWidth: f32\n}\n\n@group(${n.uniformWorldGroupIndex}) @binding(${n.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;\n@group(${n.uniformViewGroupIndex}) @binding(${n.uniformViewBindingIndex}) var<uniform> camera: Camera;\n@group(${n.storagePositionsGroupIndex}) @binding(${n.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;\n@group(${n.uniformDimensionsGroupIndex}) @binding(${n.uniformDimensionsBindingIndex}) var<uniform> dimensions: Pixels;\n\nfn computeClipPosition(index: u32) -> vec4f {\n let x = positions[3u * index + 0u];\n let y = positions[3u * index + 1u];\n let z = positions[3u * index + 2u];\n let position4 = vec4f(x, y, z, 1.0);\n let worldTransform = transforms.world;\n let viewProjectionTransform = camera.projection;\n let worldViewProjectionTransform = viewProjectionTransform * worldTransform;\n return worldViewProjectionTransform * position4;\n}\n\nfn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {\n\n let viewportSize = vec2f(dimensions.viewportWidth, dimensions.viewportHeight);\n let normalizedSize = normalize(viewportSize);\n let halfThickness = dimensions.halfLineWidth / dimensions.viewportWidth;\n let p0ndc = p0.xyz / p0.w;\n let p1ndc = p1.xyz / p1.w;\n let dir = normalize((p1ndc - p0ndc).xy);\n let offsetX = halfThickness * 2.0 / normalizedSize.x;\n let offsetY = halfThickness * 2.0 / normalizedSize.y;\n\n // perp\n let perp0 = vec2f(-dir.y * offsetX, dir.x * offsetY);\n let perp1 = perp0;\n\n /*\n \n position0-0 -----*----- position0-1\n |\\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\ |\n | \\|\n position1-0 -----*----- position1-1\n\n indexes:\n ------------\n p0-0 -> 0, 3\n p0-1 -> 5\n p1-0 -> 1\n p1-1 -> 2, 4\n */\n\n var outPos: vec2f;\n var w = p0.w;\n var z = p0.z;\n if (index == 0 || index == 3){\n outPos = p0ndc.xy - perp0;\n }\n else if (index == 1){\n outPos = p1ndc.xy - perp1;\n w = p1.w;\n z = p1.z;\n }\n else if (index == 5){\n outPos = p0ndc.xy + perp0;\n }\n else { //if (index == 2 || index == 4)\n outPos = p1ndc.xy + perp1;\n w = p1.w;\n z = p1.z;\n }\n\n // return vec4f(outPos , 0, 1.0);\n return vec4f(outPos * w, z, w);\n}\n\n@vertex fn main(@builtin(instance_index) instance: u32,\n @builtin(vertex_index) index: u32) -> VertexOutput {\n \n // vertex index starting at 1\n let position0 = computeClipPosition(instance);\n let position1 = computeClipPosition(instance + 1);\n\n // apply offset\n let position = computeOffsetPosition(position0, position1, index);\n\n return VertexOutput(\n position,\n instance,\n index\n );\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){const i=r.LABEL_PREFIX,n={multisample:!0,packedVertices:!0,primitive:{topology:"triangle-list",frontFace:"ccw",cullMode:"back"}},o=e=>{};class RenderPipeline{static{this._memoizer=new WeakMap}static dispose(t){const r=this._memoizer,i=r.get(t);e.Utils.isNull(i)||(i.clear(),r.delete(t))}static createColorPicking(e,t){const r=RenderPipeline.create(e,t);return r instanceof MeshRenderPipelineClass||r instanceof LineRenderPipelineClass?{frame:r.raycast}:null}static create(r,[i,n,...o],s){const a=RenderPipeline._memoizer;let l=a.get(r);if(e.Utils.isNull(l)&&a.set(r,l=new Map),e.Utils.isNull(i))throw new Error("Pipeline not implemented, given the provided arguments.");if(t.isMesh(i.item)){const a=t.isMeshGeometry(i.item.geometry),c=!a&&t.isLineMaterial(i.item.material);if(!a&&!c)throw new Error("Pipeline not implemented, given the provided mesh argument.");const u=a?new MeshWGSLBuilder(i,n,...o):new LineWGSLBuilder(i,n),d=u.key,h=l.get(d);if(h)return h;const p=a?new MeshRenderPipelineClass(r,u):new LineRenderPipelineClass(r,u);p.build(s);const m=p;return e.Utils.extend(m,{id:d+"-"+r.canvas.width+"x"+r.canvas.height+"-"+e.Utils.Dates.now().toISOString()}),l.set(d,m),m}throw new ReferenceError("Pipeline not implemented, given thst the first argument is not a mesh.")}}r.RenderPipeline=RenderPipeline;class RenderPipelineCache{constructor(){this.#d=new Map}#d;ensureBindGroup({device:t},r,i,n,o,s,a=()=>{}){const l=this.#d,c="string"==typeof r?r:r.key;let u=l.get(c);if(e.Utils.isNull(u)&&l.set(c,u=new Map),n||!u.has(s)){const e=i.map((e,t)=>({binding:t,resource:{buffer:e}})),r={label:s,layout:o,entries:e};a(r);const n=t.createBindGroup(r);return u.set(s,n),n}return u.get(s)}}class MeshWGSLBuilder{#h=[];#p;#m;#f=new Map;#g={shader:"basic",lights:""};constructor(...e){this.add(...e)}reset(){this.#h.splice(0),this.#p=null,this.#f.clear(),this.#g={shader:"basic",lights:""}}add(...r){for(let i of r??[])if(t.isMesh(i.item)){if(!e.Utils.isNull(this.#p))throw new Error("Mesh already added.");{this.#p=i;const e=i.item.material??{shader:t.KnownShader.Basic};this.#g.shader=e.shader+"-"+(e.map?"map":"nomap")}}else if(t.isLight(i.item)){this.#h.push(i),this.#g.lights+="-"+i.item.type}else{if(!t.isCamera(i.item))throw new Error("Unknown object type.");this.#m??=i}}build(){const e=this._computeBasicData(),t=this.key;return{vertex:this.vertex(),fragment:this.fragment(e),key:t,bindings:(...e)=>MeshWGSLBuilder.prototype.bindgroup.apply(this,e),metadata:{lightCount:this.#h.length,mapCount:this.#p.item.material?.map?1:0}}}get key(){const{shader:e,lights:t}=this.#g;return"mesh-"+e+t}bindgroup(t,r,i){const n=this.#f.get(t);if(e.Utils.isNull(n))return null;if(e.Utils.isNullOrEmpty(r))return n;const o=n.filter(e=>e.key===r);return isNaN(i)?o:i>=0&&i<n.length?o[i]:o}vertex(){return r.getMeshVertexWgsl()}_computeBasicData(){const i=this.#p.item,n=this.#h,o=i.material;return{hasTexture:!e.Utils.isNull(o?.texture),hasLighting:!e.Utils.isNullOrEmpty(n),shader:e.Utils.isNull(i)?t.KnownShader.Basic:i.material?.shader??t.KnownShader.Basic,materialBindGroupIndex:r.MATERIAL_GROUP_INDEX,lightingBindGroupIndex:r.UNIFORM_GROUP_INDEX_LIGHTING}}_computeBindGroupsAndReferences(e=this._computeBasicData()){const{hasTexture:t,materialBindGroupIndex:i,lightingBindGroupIndex:n}=e,o=this.#f,s=this.#h,a={key:"objectWorldTransform",group:r.UNIFORM_GROUP_INDEX_TRANSFORM,binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,type:"buffer"},l={key:"material",group:i,binding:r.STORAGE_MATERIAL_INDEX,type:"buffer"};t?o.set(r.WGSLBindingType.Mesh,[a,l,{key:"texture",group:i,type:"texture"}]):o.set(r.WGSLBindingType.Mesh,[a,l]),o.set(r.WGSLBindingType.Camera,[{key:"cameraViewTransform",group:r.UNIFORM_GROUP_INDEX_CAMERA,binding:r.UNIFORM_BINDING_INDEX_CAMERA,type:"buffer"}]);const c=s.map((e,t)=>({key:"light",group:n,binding:t,type:"buffer"}));c.push(...c)}fragment(i=this._computeBasicData()){this._computeBindGroupsAndReferences(i);const n={definitions:[],bindings:[],modifiers:[]},o=t=>{for(let e of t.definitions??[])-1===n.definitions.indexOf(e)&&n.definitions.push(e);e.Utils.isNullOrEmpty(t.bindings)||n.bindings.push(...t.bindings),e.Utils.isNullOrEmpty(t.modifiers)||n.modifiers.push(...t.modifiers)};if(i.shader===t.KnownShader.Basic){if(i.hasTexture){const e=i.materialBindGroupIndex;o(r.textureMap({inputColor:r.VERTEX_COLOR_REFERENCE,outputColors:[r.VERTEX_COLOR_REFERENCE],uv:"uv"},e))}let e=0;const t=this.#h;for(let n of t){switch(n.item.type){case"direction":o(r.directionalLight({outputColor:r.LIGHTING_COLOR_REFERENCE,normal:"normal"},i.lightingBindGroupIndex,e));break;case"omni":o(r.omniLight({outputColor:r.LIGHTING_COLOR_REFERENCE,normal:"normal",position:"vertex"},i.lightingBindGroupIndex,e));break;case"ambient":o(r.ambientLight({inputColor:r.VERTEX_COLOR_REFERENCE,outputColor:r.AMBIENT_COLOR_REFERENCE},i.lightingBindGroupIndex,e))}e++}return r.BasicMaterial.fragment(n)}}}const s=(e,t)=>{t.fresh&&e.queue.writeBuffer(t.buffer,0,t.value)};class MeshRenderPipelineClass{constructor(e,t,n=new RenderPipelineCache){this._context=e,this._builder=t,this._cache=n,this._ensureU32idBindGroup=(e,t,r)=>this._cache.ensureBindGroup(this._context,e,[t],r,this._pickBindGroupLayout,i+"mesh-colorpick-bind-group"),this._ensureMaterialBindGroup=(e,t,n,o,s=r.MATERIAL_GROUP_INDEX)=>{const a=this._bindGroupLayouts[s],l=i+"material-bind-group";if(a.label!==i+"material-bind-group-layout")throw new Error("BindGroupLayout mismatch!");return this._cache.ensureBindGroup(this._context,e,[t],o,a,l,e=>{const{device:t}=this.context,i=e.entries;n&&i.push({binding:r.SAMPLER_BINDING_INDEX,resource:t.createSampler({addressModeU:"repeat",addressModeV:"repeat",magFilter:"linear",minFilter:"linear"})},{binding:r.TEXTURE_BINDING_INDEX,resource:n.createView()})})},this._ensureWorldTransformBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_TRANSFORM,s=!1)=>{const a=this._bindGroupLayouts[o];if(a.label!==i+"mesh-transforms-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const l=e.key+"-"+(s?1:0),c=`${i}${s?"colorpick":"mesh"}-transforms-bind-group`;return this._cache.ensureBindGroup(this._context,l,[t],n,a,c)},this._ensureCameraProjectionBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_CAMERA,s=!1)=>{const a=this._bindGroupLayouts[o],l=e.key+"-"+(s?1:0),c=`${i}${s?"colorpick":"mesh"}-view-bind-group`;return this._cache.ensureBindGroup(this._context,l,[t],n,a,c)},this._ensureLightingBindGroup=(e,t,n=r.UNIFORM_GROUP_INDEX_LIGHTING)=>{const o=this._bindGroupLayouts[n],s=e.map(e=>e.id).join(":"),a=e.map(e=>e.buffer.buffer);return this._cache.ensureBindGroup(this._context,s,a,t,o,i+"mesh-lighting-bind-group")},this._bindGroupLayouts=[],this._bindVertex=o,this._bindPicker=o,this._bindWorldTransform=o,this._bindRaycastWorldTransform=o,this._bindCameraProjection=o,this._bindRaycastCameraProjection=o,this._bindLighting=o,this._bindMaterial=o,this.set=e=>{throw new Error("Deprecated.")},this.bind=(e,...t)=>{throw new Error("Deprecated.")},this.draw=(e,...t)=>{throw new Error("Deprecated.")},this.frame=(e,t,r,...i)=>{e.setPipeline(this._pipeline);try{this._bindVertex(e,t),this._bindWorldTransform(e,t),this._bindMaterial(e,t),this._bindCameraProjection(e,r),this._bindLighting(e,...i);const n=t.item.geometry;e.draw(n.triangleIndices?.length||n.positions.length)}catch(e){console.error("Pacem.Drawing3D.FrameException",e)}},this.raycast=(e,t,r)=>{e.setPipeline(this._pickPipeline);try{this._bindVertex(e,t),this._bindRaycastWorldTransform(e,t),this._bindRaycastCameraProjection(e,r),this._bindPicker(e,t);const i=t.item.geometry;e.draw(i.triangleIndices.length)}catch(e){}},this._key=t.key}get context(){return this._context}get key(){return this._key}build(t){const o=e.Utils.extend({},n,t??{}),a=this._builder.build(),l=this._context,c=l.device,u={module:c.createShaderModule({code:a.vertex}),buffers:o.packedVertices?[r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_POSITION,3,3,2)]:[r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_POSITION,3),r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_NORMAL,3),r.BufferLayouts.createVertex(r.VERTEX_BUFFER_INDEX_MESH_UV,2)]},d=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"mesh-transforms-bind-group-layout"}),h=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_CAMERA,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"mesh-view-bind-group-layout"}),p=[d,h],m={module:c.createShaderModule({code:a.fragment}),targets:[{format:l.format,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{}}}]},f=p.length,g=[{binding:r.STORAGE_MATERIAL_INDEX,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}}],{mapCount:_}=a.metadata,y=_>0;y&&g.push({visibility:GPUShaderStage.FRAGMENT,binding:r.SAMPLER_BINDING_INDEX,sampler:{}},...Array(_).keys().map(e=>({visibility:GPUShaderStage.FRAGMENT,binding:r.SAMPLER_BINDING_INDEX+1+e,texture:{}})));const E={label:i+"material-bind-group-layout",entries:g},b=c.createBindGroupLayout(E);p.push(b);const v=p.length,{lightCount:P}=a.metadata,x=P>0;if(x){const e=c.createBindGroupLayout({entries:[...Array(P).keys()].map((e,t)=>({visibility:GPUShaderStage.FRAGMENT,binding:t,buffer:{type:"uniform"}})),label:i+"lighting-bind-group-layout"});p.push(e)}const C={label:i+"mesh-render-pipeline",vertex:u,fragment:m,layout:c.createPipelineLayout({label:i+"mesh-render-pipeline-layout",bindGroupLayouts:this._bindGroupLayouts=p}),primitive:o.primitive};o.multisample&&(C.multisample={count:4},C.depthStencil={depthCompare:"less",format:"depth24plus",depthWriteEnabled:!0}),this._pipeline=c.createRenderPipeline(C);const w=this._pickBindGroupLayout=c.createBindGroupLayout({label:i+"mesh-colorpick-bind-group-layout",entries:[{visibility:GPUShaderStage.FRAGMENT,binding:0,buffer:{type:"uniform"}}]}),D={label:i+"mesh-colorpick-pipeline",vertex:u,fragment:{module:c.createShaderModule({code:r.getColorPickingFragmentWgsl(r.UNIFORM_GROUP_INDEX_COLORPICKING)}),targets:[{format:"r32uint"}]},layout:c.createPipelineLayout({label:i+"mesh-colorpick-pipeline-layout",bindGroupLayouts:[d,h,w]}),primitive:o.primitive,depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}};this._pickPipeline=c.createRenderPipeline(D);this._bindVertex=o.packedVertices?(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided.`);const{buffer:o}=n.buffer(l,"geometry");t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_POSITION,o)}:(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided.`);const{buffer:o}=n.buffer(l,"geometryPositions"),{buffer:s}=n.buffer(l,"geometryNormals"),{buffer:a}=n.buffer(l,"geometryTexCoords");t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_POSITION,o),t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_NORMAL,s),t.setVertexBuffer(r.VERTEX_BUFFER_INDEX_MESH_UV,a)};const R=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=i.buffer(l,"objectWorldTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Mesh,"objectWorldTransform",0),h=this._ensureWorldTransformBindGroup(i.item,u,o.fresh,d,n);t.setBindGroup(d,h)};this._bindWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!1)},this._bindRaycastWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!0)};const N=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing view projection buffers was provided.`);const o=i.buffer(l,"cameraViewTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Camera,"cameraViewTransform",0),h=this._ensureCameraProjectionBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!1)},this._bindRaycastCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!0)},this._bindMaterial=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex colors was provided.`);const o=n.buffer(l,"material"),a=o.buffer;s(c,o);let u=n.texture(l);const d=u?.texture,h=this._ensureMaterialBindGroup(n.item,a,d,o.fresh,f);t.setBindGroup(f,h),y&&c.queue.copyExternalImageToTexture({source:u.source,flipY:!0},{texture:d},{width:d.width,height:d.height})},this._bindLighting=(e,...t)=>{if(x){const r=Array.from(t),i=r.map(e=>({buffer:e.buffer(l,"light"),id:e.item.key})),n=this._ensureLightingBindGroup(i,r.some(e=>e.item.flags.length>0),v);for(let e of i)s(c,e.buffer);e.setBindGroup(v,n)}},this._bindPicker=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=n.buffer(l,"u32id"),a=o.buffer;s(c,o);const u=r.UNIFORM_GROUP_INDEX_COLORPICKING,d=this._ensureU32idBindGroup(n.item,a,!1);t.setBindGroup(u,d)}}}class LineWGSLBuilder{#_;#m;#f=new Map;constructor(...e){this.add(...e)}reset(){this.#_=null,this.#f.clear()}add(...r){for(let i of r??[])if(t.isMesh(i.item)){if(!e.Utils.isNull(this.#_))throw new Error("Line already added.");this.#_=i}else if(t.isCamera(i.item))this.#m??=i;else if(!t.isLight(i.item))throw new Error("Unknown object type.")}build(){const e=this._computeBasicData(),t=this.key;return{vertex:this.vertex(e),fragment:this.fragment(e),key:t,bindings:(...e)=>LineWGSLBuilder.prototype.bindgroup.apply(this,e),metadata:{thickness:e.thickness,dashPattern:e.dashPattern}}}get key(){const e=(this.#_?.item).material?.lineWidth>1;return t.KnownShader.Line+(e?"-fat":"")}bindgroup(t,r,i){const n=this.#f.get(t);if(e.Utils.isNull(n))return null;if(e.Utils.isNullOrEmpty(r))return n;const o=n.filter(e=>e.key===r);return isNaN(i)?o:i>=0&&i<n.length?o[i]:o}vertex(e=this._computeBasicData()){return e.thickness>1?r.getFatLineVertexWgsl():r.getDefaultLineVertexWgsl()}_computeBasicData(){const r=this.#_.item,i=e.Utils.isNull(r)?t.KnownShader.Line:r.material?.shader??t.KnownShader.Line,n=r.material,o=n?.lineWidth??1,s=n?.dashArray;return{shader:i,thickness:o,dashPattern:s}}_computeBindGroupsAndReferences(e=this._computeBasicData()){const t=this.#f,i={key:"objectWorldTransform",group:r.UNIFORM_GROUP_INDEX_TRANSFORM,binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,type:"buffer"},n={key:"material",group:r.STORAGE_GROUP_INDEX_LINE+1,binding:r.STORAGE_MATERIAL_INDEX,type:"buffer"},o={key:"geometryPositions",group:r.STORAGE_GROUP_INDEX_LINE,binding:0,type:"buffer"},s={key:"line",group:r.STORAGE_GROUP_INDEX_LINE,binding:1,type:"buffer"};t.set(r.WGSLBindingType.Mesh,[i,n,o,s]),t.set(r.WGSLBindingType.Camera,[{key:"cameraViewTransform",group:r.UNIFORM_GROUP_INDEX_CAMERA,binding:r.UNIFORM_BINDING_INDEX_CAMERA,type:"buffer"}])}fragment(e=this._computeBasicData()){this._computeBindGroupsAndReferences(e);const i={definitions:[],bindings:[],modifiers:[]};if(e.shader===t.KnownShader.Line)return r.LineMaterial.fragment(i)}}class LineRenderPipelineClass{#y;constructor(e,t,n=new RenderPipelineCache){this._lineBuilder=t,this._cache=n,this._ensureLineU32idBindGroup=(e,t,r)=>{const n=this.context;return this._cache.ensureBindGroup(n,e,[t],r,this._pickLineBindGroupLayout,i+"line-colorpick-bind-group")},this._ensureLineMaterialBindGroup=(e,t,n,o=r.MATERIAL_GROUP_INDEX)=>{const s=this._bindLineGroupLayouts[o];if(s.label!==i+"line-material-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const a=this.context;return this._cache.ensureBindGroup(a,e,[t],n,s,i+"line-material-bind-group")},this._ensureLinePositionsBindGroup=(e,t,r,n)=>{const o=this._bindLineGroupLayouts[n];if(o.label!==i+"line-positions-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const s=this.context;return this._cache.ensureBindGroup(s,e,t,r,o,i+"line-positions-bind-group")},this._ensureLineWorldTransformBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_TRANSFORM,s=!1)=>{const a=this._bindLineGroupLayouts[o];if(a.label!==i+"line-transforms-bind-group-layout")throw new Error("BindGroupLayout mismatch!");const l=e.key+"-line-"+(s?1:0),c=`${i}${s?"colorpick":""}-line-transforms-bind-group`,u=this.context;return this._cache.ensureBindGroup(u,l,[t],n,a,c)},this._ensureLineCameraProjectionBindGroup=(e,t,n,o=r.UNIFORM_GROUP_INDEX_CAMERA,s=!1)=>{const a=this._bindLineGroupLayouts[o],l=e.key+"-line-"+(s?1:0),c=`${i}${s?"colorpick":""}-line-view-bind-group`,u=this.context;return this._cache.ensureBindGroup(u,l,[t],n,a,c)},this._bindLineGroupLayouts=[],this._bindLinePositions=o,this._bindLinePicker=o,this._bindLineWorldTransform=o,this._bindLineRaycastWorldTransform=o,this._bindLineCameraProjection=o,this._bindLineRaycastCameraProjection=o,this._bindLineMaterial=o,this._drawLine=o,this.set=e=>{throw new Error("Deprecated.")},this.bind=(e,...t)=>{throw new Error("Deprecated.")},this.draw=(e,...t)=>{throw new Error("Deprecated.")},this.frame=(e,t,r)=>{e.setPipeline(this._linePipeline);try{this._bindLineWorldTransform(e,t),this._bindLineCameraProjection(e,r),this._bindLinePositions(e,t),this._bindLineMaterial(e,t),this._drawLine(e,t)}catch(e){console.error("Pacem.Drawing3D.FrameException",e)}},this.raycast=(e,t,r)=>{e.setPipeline(this._pickLinePipeline);try{this._bindLineRaycastWorldTransform(e,t),this._bindLineRaycastCameraProjection(e,r),this._bindLinePositions(e,t),this._bindLinePicker(e,t),this._drawLine(e,t)}catch(e){}},this.#y=e,this._lineKey=t.key}get context(){return this.#y}get key(){return this._lineKey}build(t){const o=e.Utils.extend({},n,t??{}),a=this._lineBuilder.build(),l=this.context,c=l.device,u=a.metadata.thickness>1,d={module:c.createShaderModule({code:a.vertex}),buffers:[]},h=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_TRANSFORM,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"line-transforms-bind-group-layout"}),p=c.createBindGroupLayout({entries:[{binding:r.UNIFORM_BINDING_INDEX_CAMERA,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}}],label:i+"line-view-bind-group-layout"}),m=[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}];u&&m.push({binding:1,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}});const f=[h,p,c.createBindGroupLayout({entries:m,label:i+"line-positions-bind-group-layout"})],g=f.length,_=f.slice(),y={module:c.createShaderModule({code:a.fragment}),targets:[{format:l.format,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{}}}]},E=_.length,b=[{binding:r.STORAGE_MATERIAL_INDEX,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"read-only-storage"}}],v={label:i+"line-material-bind-group-layout",entries:b},P=c.createBindGroupLayout(v);_.push(P);const x=u?o.primitive.topology:"line-list",C={label:i+"line-render-pipeline",vertex:d,fragment:y,layout:c.createPipelineLayout({label:i+"line-render-pipeline-layout",bindGroupLayouts:this._bindLineGroupLayouts=_}),primitive:e.Utils.extend({},o.primitive,{topology:x})};o.multisample&&(C.multisample={count:4},C.depthStencil={depthCompare:"less",format:"depth24plus",depthWriteEnabled:!0}),this._linePipeline=c.createRenderPipeline(C);const w=this._pickLineBindGroupLayout=c.createBindGroupLayout({label:i+"line-colorpick-bind-group-layout",entries:[{visibility:GPUShaderStage.FRAGMENT,binding:0,buffer:{type:"uniform"}}]}),D={label:i+"line-colorpick-pipeline",vertex:d,fragment:{module:c.createShaderModule({code:r.getColorPickingFragmentWgsl(g)}),targets:[{format:"r32uint"}]},layout:c.createPipelineLayout({label:i+"line-colorpick-pipeline-layout",bindGroupLayouts:f.concat(w)}),primitive:e.Utils.extend({},o.primitive,{topology:x}),depthStencil:{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}};this._pickLinePipeline=c.createRenderPipeline(D);const R=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=i.buffer(l,"objectWorldTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Mesh,"objectWorldTransform",0),h=this._ensureLineWorldTransformBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindLineWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!1)},this._bindLineRaycastWorldTransform=(e,...t)=>{const r=t.at(0);R(e,r,!0)};const N=(t,i,n)=>{if(e.Utils.isNull(i))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing view projection buffers was provided.`);const o=i.buffer(l,"cameraViewTransform"),u=o.buffer;s(c,o);const{group:d}=a.bindings(r.WGSLBindingType.Camera,"cameraViewTransform",0),h=this._ensureLineCameraProjectionBindGroup(i.item,u,!1,d,n);t.setBindGroup(d,h)};this._bindLineCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!1)},this._bindLineRaycastCameraProjection=(e,...t)=>{const r=t.at(0);N(e,r,!0)},this._bindLinePositions=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex buffers was provided as index 0.`);const o=n.buffer(l,"geometryPositions"),d=o.buffer;let h=o.fresh;const p=[d];if(s(c,o),u){const e=n.buffer(l,"line"),t=e.buffer;h||=e.fresh,p.push(t),s(c,e)}const{group:m}=a.bindings(r.WGSLBindingType.Mesh,"line",0),f=this._ensureLinePositionsBindGroup(n.item,p,h,m);t.setBindGroup(m,f)},this._bindLineMaterial=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing vertex colors was provided.`);const o=n.buffer(l,"material"),a=o.buffer;s(c,o);const u=this._ensureLineMaterialBindGroup(n.item,a,o.fresh,E);t.setBindGroup(E,u)},this._bindLinePicker=(t,...i)=>{const n=i.at(0);if(e.Utils.isNull(n))throw new ReferenceError(`Null ${r.RenderableBuffer.name} bringing world transform buffer was provided.`);const o=n.buffer(l,"u32id"),a=o.buffer;o.value;s(c,o);const u=this._ensureLineU32idBindGroup(n.item,a,!1);t.setBindGroup(g,u)},this._drawLine=(e,...t)=>{const r=t.at(0).item.geometry;u?e.draw(6,r.positions.length-1,0,0):e.draw(r.positions.length)}}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){e.Geometry.LinearAlgebra.Matrix3D;class Raycaster{static{this._memoizer=new WeakMap}static dispose(e){const t=this._memoizer;if(t.has(e)){const r=t.get(e);for(let e of r.values())e.destroy();r.clear(),t.delete(e)}}static createColorPicking(e){const t=this._memoizer;t.has(e)||t.set(e,new Map);const r=t.get(e),i="colorpick";if(r.has(i))return r.get(i);const n=new ColorPickingRaycaster(e);return r.set(i,n),n}}t.Raycaster=Raycaster;class ColorPickingRaycaster{constructor(r){this._context=r,this._objects=new Map,this.frame=(...r)=>{if(e.Utils.isNull(this._encoder))throw new Error("Null encoder. Maybe you missed to call the 'begin' method first.");const i=Array.from(r),n=t.RenderPipeline.createColorPicking(this._context,i);n?.frame(this._pass,...r);for(let e of i){e.item.inert||this._objects.set(e.id,e)}},this.end=t=>{if(!e.Utils.isNull(this._handle))return this._handle;const r=this._pass,i=this._encoder,{device:n}=this._context,{render:o}=this._textures,s=o.texture,a=this._ensureBuffer();r.end(),i.copyTextureToBuffer({texture:s,origin:{x:t.x,y:t.y}},{buffer:a,bytesPerRow:66304,rowsPerImage:1},{width:1}),n.queue.submit([i.finish()]),this._encoder=null;const l=this,c=l._objects;return this._handle=new Promise((e,t)=>{a.mapAsync(GPUMapMode.READ,0,4).then(t=>{const r=new Uint32Array(a.getMappedRange(0,4))[0];a.unmap(),l._handle=null;const i=c.get(r);e(i?[i.item]:[])})})}}_createTexture(e){const{device:t,canvas:r}=this._context,i=Math.min(t.limits.maxTextureDimension2D,r.clientWidth),n=Math.min(t.limits.maxTextureDimension2D,r.clientHeight);return t.createTexture({size:[i,n,1],format:e,usage:GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT})}_ensureBuffer(){const r=this._buffer;if(!e.Utils.isNull(r))return r;const{device:i}=this._context;return this._buffer=i.createBuffer({label:t.LABEL_PREFIX+"colorpick-output-buffer",size:4,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST})}_ensureTextures(){const t=this._textures;if(!e.Utils.isNull(t))return t;const r=this._createTexture("r32uint"),i=this._createTexture("depth24plus"),n={texture:r,view:r.createView()},o={texture:i,view:i.createView()};return this._textures={render:n,depth:o}}_destroyTexture(t){e.Utils.isNull(t)||t.texture?.destroy()}destroy(){const t=this._textures,r=this._buffer;if(!e.Utils.isNullOrEmpty(t)){const{render:e,depth:r}=t;this._destroyTexture(e),this._destroyTexture(r),this._textures=null}e.Utils.isNull(r)||(r.destroy(),this._buffer=null)}begin(){const{device:e}=this._context;this._encoder=e.createCommandEncoder({label:t.LABEL_PREFIX+"colorpick-raycaster"});const{render:r,depth:i}=this._ensureTextures(),n={label:t.LABEL_PREFIX+"colorpick-raycaster-pass",colorAttachments:[{view:r.view,clearValue:{r:0,g:0,b:0,a:0},loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:i.view,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}};this._pass=this._encoder.beginRenderPass(n),this._objects.clear()}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){function i(e,t){throw"function"==typeof t&&(t=t.name),new RangeError(`Buffer '${e}' not available for ${t}.`)}function n(r,i,...n){if(r.stage??=i?.item.stage,t.isGroup(r))return r.key??="group_"+e.Utils.uniqueCode(),new RenderableGroupBuffer(r,i,...n);if(t.isMesh(r))return r.key??="mesh_"+e.Utils.uniqueCode(),new RenderableMeshBuffer(r,i,...n);if(t.isCamera(r))return r.key??="camera_"+e.Utils.uniqueCode(),new RenderableCameraBuffer(r);if(t.isLight(r))return r.key??="light_"+r.type+"_"+e.Utils.uniqueCode(),new RenderableLightBuffer(r);throw new Error("Renderable is not supported.")}r.RenderLooper=class RenderLooper{constructor(e){this._set=e}get items(){return this._set}loop(e){const{meshes:t,cameras:r,groups:i,lights:n}=this._set,o=r[0];let s=!1,a=!1;for(let r of t){if(r.disposed)continue;e(r,o,n)&&(RenderableBuffer.clearFlags(r),s||(RenderableBuffer.clearFlags(o),s=!0),a||(n.forEach(e=>RenderableBuffer.clearFlags(e)),a=!0))}for(let e of i)RenderableBuffer.clearFlags(e)}};r.ManagedBuffer=class ManagedBuffer{static create(r){if(t.isGeometry(r))return r.key??="geometry_"+e.Utils.uniqueCode(),new GeometryBuffer(r);if(t.isMaterial(r))return new MaterialBuffer(r);throw new Error("Object is not supported.")}};class RenderableBuffer{static create(e,...t){return n(e,null,...t)}static clearFlags(t,r=!1){if(t.item.flags.splice(0),r){const r=t;e.Utils.isNull(r.parent)||RenderableBuffer.clearFlags(r.parent,!0)}}static allFlags(t){const r=t,i=r.parent,n=e.Utils.isNull(i)?[]:RenderableBuffer.allFlags(i);return r.item.flags.union(n)}}r.RenderableBuffer=RenderableBuffer;class ManagedBufferBase{#E;constructor(e){this.#E=e}get item(){return this.#E}#b=!1;lock(){this.#b=!0}unlock(){this.#b=!1;const e=this.#v;for(;e.length>0;){const t=e.shift();this._destroyUnsafe(t)}}#v=[];_destroyUnsafe(e){"texture"in e?e.texture.destroy():"buffer"in e&&e.buffer.destroy()}destroySafely(...e){for(let t of Array.from(e).concat(...this.#v.splice(0)))t&&(this.#b?this.#v.push(t):this._destroyUnsafe(t))}#P=!1;destroy(){this.dispose(),this.#P=!0}get disposed(){return this.#P}}class RenderableBufferBase extends ManagedBufferBase{constructor(t,i){super(t),this.#x=i,this.#C=e.Utils.uniqueId()%r.U32_MAX}#C;#x;#w;get parent(){return this.#x}get id(){return this.#C}allFlags(){const e=this.parent;return this.item.flags.union(e?.allFlags()??[])}buildParentWorldTransform(){let t=s.identity(),r=this;for(;!e.Utils.isNull(r.parent);){const e=r.parent.item,i=s.translate(e.transformMatrix??s.identity(),e.position??a.zero());t=s.multiply(t,i),r=r.parent}return t}buildWorldTransform(){const e=s.translate(this.item.transformMatrix??s.identity(),this.item.position??a.zero()),t=this.buildParentWorldTransform();return s.multiply(e,t)}#D=new Map;version(e){return this.#D.get(e)??0}buffer(t,i){if("u32id"===i){const i=this.#w;if(!e.Utils.isNull(i))return e.Utils.extend({fresh:!1},i);const n=new Uint32Array([this.id]),o=r.Buffers.createUniform(t.device,n,r.LABEL_PREFIX+"u32id-buffer");return e.Utils.extend(this.#w={buffer:o,value:n,version:performance.now()},{fresh:!0})}const n=this.specificBuffer(t,i);return this.#D.set(i,n.version),n}}const o=e.Components.Drawing3D.AdapterUtils,s=e.Geometry.LinearAlgebra.Matrix3D,a=e.Geometry.LinearAlgebra.Vector3D,l={shader:t.KnownShader.Basic,color:"#c0c0c0",flags:[]};class RenderableGroupBuffer extends RenderableBufferBase{#o;constructor(e,t,...r){super(e,t),this.#o=e.childRenderables.map(e=>n(e,this,...r))}get children(){return this.#o}specificBuffer(e,t){return null}texture(e){throw new Error("Method not implemented.")}dispose(){this.#o.forEach(e=>e.destroy())}}class RenderableCameraBuffer extends RenderableBufferBase{#R;constructor(e){super(e)}texture(e){throw new Error("Method not implemented.")}specificBuffer(t,r){this.item;const n=e.Utils.isNull(this.#R)||this.allFlags().length>0;if(n&&this._rebuildMatrices(t),RenderableBuffer.clearFlags(this),"cameraViewTransform"===r)return e.Utils.extend(this.#R,{fresh:n});i(r,RenderableCameraBuffer)}_rebuildMatrices({device:t,canvas:i}){const n=this.item,o=r.Camera.create(n),{x:a,y:l,z:c}=n.position,u=o.view(),d=o.projection(i),h=s.multiply(u,d),p=new Float32Array(36);if(p.set(s.toArray(u),0),p.set(s.toArray(h),16),p.set([a,l,c],32),e.Utils.isNull(this.#R)){const e=r.Buffers.createUniform(t,p,r.LABEL_PREFIX+"view-buffer");this.#R={buffer:e,value:p,version:performance.now().roundoff()}}else this.#R.value=p,this.#R.version=performance.now().roundoff()}_destroyView(){const e=this.#R;this.#R=null,this.destroySafely(e)}dispose(){this._destroyView()}}class GeometryBuffer extends ManagedBufferBase{#N={positions:!0,normals:!0,uv:!0,packed:!0};#M;constructor(e){super(e),e.flags??=[]}buffer(r,n){const o=this.item.flags??[];(e.Utils.isNull(this.#M)||o.includes(t.StalePropertyFlag.Geometry))&&(o.splice(0),this._rebuildGeometryBuffers(r));const s=this.#N,a=this.#M;switch(n){case"geometryPositions":const{positions:t}=a,r=s.positions;return s.positions=!1,e.Utils.extend(t,{fresh:r});case"geometryNormals":const{normals:o}=a,l=s.normals;return s.normals=!1,e.Utils.extend(o,{fresh:l});case"geometryTexCoords":const{uv:c}=a,u=s.uv;return s.uv=!1,e.Utils.extend({fresh:u},c);case"geometry":const{packed:d}=a,h=s.packed;return s.packed=!1,e.Utils.extend(d,{fresh:h});default:i(n,GeometryBuffer)}}texture(e){throw new Error("Method not implemented.")}_rebuildGeometryBuffers({device:i}){this._destroyBuffers();const n=performance.now(),s=this.item,a=s.key;if(t.isMeshGeometry(s)){const t=s,o=!e.Utils.isNullOrEmpty(t.triangleIndices)?t.triangleIndices.map(e=>t.positions[e]):t.positions,l=2*o.length,c=l+o.length,u=new Float32Array(c),d=new Float32Array(c),h=new Float32Array(l),p=new Float32Array(2*c+l);for(let e=0;e<o.length;e++){const r=2*e,i=3*e,{x:n,y:s,z:a}=o[e],{x:l,y:c,z:m}=t.normals[e],{x:f,y:g}=t.textureCoordinates[e];u.set([n,s,a],i),d.set([l,c,m],i),h.set([f,g],r),p.set([n,s,a,l,c,m,f,g],2*i+r)}const m=r.Buffers.create(i,u,r.LABEL_PREFIX+"meshgeometry-"+a+"-positions-buffer"),f=r.Buffers.create(i,d,r.LABEL_PREFIX+"meshgeometry-"+a+"-normals-buffer"),g=r.Buffers.create(i,h,r.LABEL_PREFIX+"meshgeometry-"+a+"-uvmap-buffer"),_=r.Buffers.create(i,p,r.LABEL_PREFIX+"meshgeometry-"+a+"-buffer");this.#M={packed:{buffer:_,value:p,version:n},positions:{buffer:m,value:u,version:n},normals:{buffer:f,value:d,version:n},uv:{buffer:g,value:h,version:n}},this.#N={positions:!0,normals:!0,uv:!0,packed:!0}}else{const e=new Float32Array(o.flattenVectorArray(s.positions)),t=r.Buffers.createStorage(i,e,r.LABEL_PREFIX+"nodegeometry-"+a+"-positions-buffer");this.#M={positions:{buffer:t,value:e,version:n},packed:{buffer:t,value:e,version:n}},this.#N={positions:!0,packed:!0}}}_destroyBuffers(){const t=this.#M;e.Utils.isNull(t)||this.destroySafely(t.positions,t.normals,t.uv)}dispose(){this._destroyBuffers()}}class MaterialBuffer extends ManagedBufferBase{#U;#L=new Map;#T=new Map;constructor(e){super(e),e.flags??=[],-1===e.flags.indexOf(t.StalePropertyFlag.Material)&&e.flags.push(t.StalePropertyFlag.Material)}buffer(r,n){const o=this.item.flags??[];let s=e.Utils.isNull(this.#U);switch(o.includes(t.StalePropertyFlag.Material)&&(o.splice(0),s=!0,this.#T.clear(),this._resetMaterialBuffers()),n){case"material":case"line":const t=this._ensureMaterialBuffer(r,n);return t?e.Utils.extend(t,{fresh:s}):null;default:i(n,MaterialBuffer)}}_ensureMaterialBuffer(e,t="material"){const r=this.#L;let i=r.get(t);return i||(r.has(t)?null:(i=this.#U?.buffer(e,t),i&&r.set(t,i),i))}_resetMaterialBuffers(){this.#U=r.Material.create(this.item),this._destroyBuffers()}texture(t,r="texture"){const i=this.#T;let n=i.get(r),o=!1;if(!n){if(n=this.#U?.texture(t,r),!n)return null;i.set(r,n),o=!0}return e.Utils.extend(n,{fresh:o})}dispose(){this._destroyBuffers()}_destroyBuffers(){const e=this.#L.values();this.#L.clear(),this.destroySafely(...e);const t=this.#T.values();this.#T.clear(),t.forEach(e=>e.texture.destroy())}}class RenderableMeshBuffer extends RenderableBufferBase{#M;#G;#A;#I;#B;#N={geometry:!0,material:!0,transform:!0};constructor(e,r,i,n){super(e,r),e.flags??=[],-1===e.flags.indexOf(t.StalePropertyFlag.Geometry)&&e.flags.push(t.StalePropertyFlag.Geometry),-1===e.flags.indexOf(t.StalePropertyFlag.Material)&&e.flags.push(t.StalePropertyFlag.Material),-1===e.flags.indexOf(t.StalePropertyFlag.Position)&&-1===e.flags.indexOf(t.StalePropertyFlag.Transform)&&e.flags.push(t.StalePropertyFlag.Transform),this.#M=i,this.#A=n}texture(e,t){const r=this.#I;return r?.texture(e,t)}specificBuffer(r,n){const o=this.#N,s=this.allFlags();(e.Utils.isNull(this.#B)||s.includes(t.StalePropertyFlag.Position)||s.includes(t.StalePropertyFlag.Transform))&&(o.transform=!0,this._rebuildWorldMatrices(r)),(e.Utils.isNull(this.#G)||s.includes(t.StalePropertyFlag.Geometry))&&(o.geometry=!0,this._ensureGeometryBuffer()),(e.Utils.isNull(this.#I)||s.includes(t.StalePropertyFlag.Material))&&(o.material=!0,this._ensureMaterialBuffer()),RenderableBuffer.clearFlags(this);const a=this.#G,l=this.#I;switch(n){case"geometryPositions":case"geometryNormals":case"geometryTexCoords":case"geometry":return a.buffer(r,n);case"material":case"line":return l.buffer(r,n);case"objectWorldTransform":const t=this.#B,s=o.transform;return o.transform=!1,e.Utils.extend(t,{fresh:s});default:i(n,RenderableMeshBuffer)}}_ensureGeometryBuffer(){const t=this.#G,r=this.#M,i=this.item.geometry;if(e.Utils.isNull(r))t?.destroy(),this.#G=new GeometryBuffer(i);else{let e=r?.get(i);!1!==e?.disposed&&(e=new GeometryBuffer(i),r.set(i,e)),this.#G=e}}_ensureMaterialBuffer(){const t=this.#I,r=this.#A,i=this.item.material??l;if(e.Utils.isNull(r))t?.destroy(),this.#I=new MaterialBuffer(i);else{let e=r?.get(i);!1!==e?.disposed&&(e=new MaterialBuffer(i),r.set(i,e)),this.#I=e}}_rebuildWorldMatrices({device:t}){const i=this.item,n=this.buildWorldTransform(),o=s.transpose(s.invert(n)),a=new Float32Array(28);if(a.set(s.toArray(n),0),a.set([o.m11,o.m12,o.m13,0,o.m21,o.m22,o.m23,0,o.m31,o.m32,o.m33,0],16),e.Utils.isNull(this.#B)){const e=r.Buffers.createUniform(t,a,r.LABEL_PREFIX+"mesh-"+i.key+"-worldmatrix-buffer");this.#B={buffer:e,value:a,version:performance.now().roundoff()}}else this.#B.value=a,this.#B.version=performance.now().roundoff()}dispose(){const e=this.#B;this.#B=null,this.destroySafely(e);const t=this.#I;this.#I=null,t?.destroy();const r=this.#G;this.#G=null,r?.destroy()}}class RenderableLightBuffer extends RenderableBufferBase{#O;constructor(e){super(e),e.flags.push(t.StalePropertyFlag.Light)}_rebuildAmbientLightBuffer({device:t}){const i=this.item,n=new Float32Array(24),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"ambient-light-buffer"),version:performance.now()}}_rebuildDirectionalLightBuffer({device:t}){const i=this.item,n=new Float32Array(8),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],7);const c=e.Geometry.LinearAlgebra.Vector3D.subtract(i.position,i.target);n.set([c.x,c.y,c.z],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"directional-light-buffer"),version:performance.now()}}_rebuildOmniLightBuffer({device:t}){const i=this.item,n=new Float32Array(8),{r:o,g:s,b:a,a:l}=e.Colors.parse(i.color??"#fff");n.set([o,s,a,l],0),n.set([i.intensity],7),n.set([i.position.x,i.position.y,i.position.z],4),this.#O={value:n,buffer:r.Buffers.createUniform(t,n,r.LABEL_PREFIX+"omni-light-buffer"),version:performance.now()}}_rebuildLight(e){this.destroySafely(this.#O);const t=this.item;switch(t.type){case"direction":this._rebuildDirectionalLightBuffer(e);break;case"omni":this._rebuildOmniLightBuffer(e);break;case"ambient":this._rebuildAmbientLightBuffer(e);break;default:throw new Error(`Light '${t.type}' is not supported.`)}}texture(e){throw new Error("Method not implemented.")}specificBuffer(t,r){const n=e.Utils.isNull(this.#O)||this.allFlags().length>0;if(n&&this._rebuildLight(t),RenderableBuffer.clearFlags(this),"light"===r)return e.Utils.extend(this.#O,{fresh:n});i(r,RenderableLightBuffer)}dispose(){const e=this.#O;this.#O=null,this.destroySafely(e)}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){let i;!function(e){e[e.NotSupported=0]="NotSupported",e[e.Disabled=1]="Disabled"}(i=r.WebGPUIssueCause||(r.WebGPUIssueCause={}));r.Renderer=class Renderer{static create(e,t){return new Promise((r,n)=>{if(navigator.gpu){const o=new RendererClass(e);o.init(t).then(e=>r(o),e=>{const t={message:"string"==typeof e?e:e.message,cause:i.Disabled};n(t)})}else{const e={message:"WebGPU not supported.",cause:i.NotSupported};n(e)}})}};const n=e.Geometry.LinearAlgebra.Vector3D;class RendererClass{#S;#k;#y;#W;#F;#V;#$;#T;#X;#z;constructor(t){this.#W=new WeakMap,this.#F=new WeakMap,this.#V=new WeakMap,this.#X={enableValidation:!1},this.#z=!1,this._logError=t=>{const r=this.#S.logger;if(!e.Utils.isNull(r)){const i="error"in t?t.error:t;r.log(e.Logging.LogLevel.Error,i.message,"WebGPU")}},this.#H=!0;const r=(this.#S=t).stage,i=document.createElement("canvas");i.id=e.P+"_3d_stage_"+e.Utils.uniqueCode(),r.innerHTML="",r.appendChild(this.#k=i)}_buildPassDescriptor({multisample:t,format:i}){const{context:n,device:o}=this.#y,s=n.getCurrentTexture();let a=this.#T;if(e.Utils.isNull(a)){if(a={},t){const e=o.createTexture({label:r.LABEL_PREFIX+"render-texture",format:i??s.format,usage:GPUTextureUsage.RENDER_ATTACHMENT,size:[s.width,s.height],sampleCount:4});a.render={texture:e,view:e.createView({label:r.LABEL_PREFIX+"render-texture-view"})};const t=o.createTexture({label:r.LABEL_PREFIX+"depth-texture",format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT,size:[s.width,s.height],sampleCount:4});a.depth={texture:t,view:t.createView({label:r.LABEL_PREFIX+"depth-texture-view"})}}this.#T=a}const{transparent:l,background:c}=this.#S,u=l?{r:0,g:0,b:0,a:0}:c?"string"==typeof c?e.Colors.parse(c):c:{r:0,g:0,b:0,a:1},d=e.Components.Drawing3D.AdapterUtils.flattenVectorArray([u]),h=s.createView({label:r.LABEL_PREFIX+"canvas-texture-view"}),p={view:h,clearValue:d,loadOp:"clear",storeOp:"store"},m={colorAttachments:[p]};if(t){const e=a.render.view,t=a.depth.view;m.depthStencilAttachment={view:t,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store",stencilClearValue:0,stencilReadOnly:!0},p.view=e,p.resolveTarget=h}return m}_buildContext(e=this.#k,t=this.#S.size){t??=e;let r=t.width,i=t.height;e.width=1*r,e.height=1*i;return{context:e.getContext("webgpu"),textureFormat:navigator.gpu.getPreferredCanvasFormat()}}_buildUpContext(e,t,r,i){const{transparent:n}=this.#S;r.configure({alphaMode:n?"premultiplied":"opaque",device:e,format:i}),this.#y={device:e,adapter:t,canvas:this.#k,context:r,format:i},this.#H=!1}async init(t){this.#X=t;const r=await navigator.gpu.requestAdapter();if(e.Utils.isNull(r))throw new Error("WebGPU adapter unavalable or disabled.");const i=await r.requestDevice();if(e.Utils.isNull(r))throw new Error("WebGPU device unavalable or disabled.");i.addEventListener("uncapturederror",this._logError);const{context:n,textureFormat:o}=this._buildContext();this._buildUpContext(i,r,n,o)}#H;render(){if(this.#H||e.Utils.isNull(this.#$))return;const t=this.#y,i=t.device,n=this.#$,o=this.#X?.enableValidation??!1,s=this._buildPassDescriptor({multisample:!0}),a=i.createCommandEncoder({label:r.LABEL_PREFIX+"renderer"}),l=a.beginRenderPass(s);n.loop((e,n,s)=>{if(e.item.hide)return!1;o&&i.pushErrorScope("validation");const a=[e,n,...s];return r.RenderPipeline.create(t,a,{multisample:!0}).frame(l,...a),o&&i.popErrorScope().then(e=>{e&&this._logError(e)}),!0}),l.end(),i.queue.submit([a.finish()])}set disabled(e){this.#z=e}get disabled(){return this.#z}raycast(t){if(this.#H||e.Utils.isNull(this.#$))return Promise.resolve([]);const i=this.#y,n=i.device,o=this.#$,s=this.#X?.enableValidation??!1,a=r.Raycaster.createColorPicking(i);return a.begin(),o.loop((e,t)=>!e.item.hide&&(s&&n.pushErrorScope("validation"),a.frame(e,t),s&&n.popErrorScope().then(e=>{e&&this._logError(e)}),!0)),a.end(t)}_disposeRenderableJustInCase(e){const t=this.#W;t.has(e)&&(t.get(e)?.destroy(),t.delete(e))}_createOrYieldRenderable(t,i=this.#F,n=this.#V){t.stage??=this.#S;const o=this.#W;let s=o.get(t);return e.Utils.isNull(s)&&o.set(t,s=r.RenderableBuffer.create(t,i)),s}_createOrYieldGeometry(t){const i=this.#F;let n=i.get(t);return e.Utils.isNull(n)&&i.set(t,n=r.ManagedBuffer.create(t)),n}_createOrYieldMaterial(t){const i=this.#V;let n=i.get(t);return e.Utils.isNull(n)&&i.set(t,n=r.ManagedBuffer.create(t)),n}_unwrapBuffers(e,r){r??={meshes:[],lights:[],cameras:[],groups:[]};for(let i of e.children)i.item.stage??=this.#S,t.isMesh(i.item)&&r.meshes.push(i),t.isCamera(i.item)&&r.cameras.push(i),t.isLight(i.item)&&r.lights.push(i),t.isGroup(i.item)&&(r.groups.push(i),this._unwrapBuffers(i,r));return r}_update(i){const o=[],s=[],a=[],l=e=>this._createOrYieldRenderable(e);let c;for(let r of i)if(r.hide)this._disposeRenderableJustInCase(r);else{if(r.stage??=this.#S,t.isGroup(r)){const e=r;e.flags.includes(t.StalePropertyFlag.Children)&&this.#W.delete(e),o.push(l(e))}t.isMesh(r)&&r.geometry&&(this._createOrYieldGeometry(r.geometry),e.Utils.isNull(r.material)||this._createOrYieldMaterial(r.material),s.push(l(r))),t.isLight(r)&&a.push(l(r)),t.isCamera(r)&&(c??=r)}var u;c??=(u=this.#S,{bottom:-1,top:1,left:-1,right:1,near:.1,far:200,lookAt:n.from(0,0,0),up:n.j(),position:n.from(0,0,1),type:"orthographic",flags:[],stage:u});const d=l(c);let h={meshes:s,lights:a,cameras:[d],groups:o};for(let e of o)h=this._unwrapBuffers(e,h);this.#$?.items.meshes.forEach(e=>{s.includes(e)||e.destroy()}),this.#$=new r.RenderLooper(h)}update(...e){this._update(Array.from(e))}dispose(){if(this._disposeContext()){const{device:e}=this.#y;e.removeEventListener("uncapturederror",this._logError),e.destroy}}_disposeContext(){const t=this.#y;if(e.Utils.isNull(t))return!1;r.Raycaster.dispose(t),r.RenderPipeline.dispose(t);const i=this.#T;if(this.#T=null,!e.Utils.isNull(i)){const{render:e,depth:t}=i;!function(...e){for(let t of e||[])t?.destroy()}(e?.texture,t?.texture)}return t.context.unconfigure(),!0}resize(e){if(this.#H=!0,this._disposeContext()){const{device:t,adapter:r}=this.#y,{context:i,textureFormat:n}=this._buildContext(this.canvas,e);this._buildUpContext(t,r,i,n)}}get canvas(){return this.#k}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r="WebGPURaycastCallback",i="WebGPURaycastPixel",n=e.CustomElementUtils.getAttachedPropertyValue,o=e.CustomElementUtils.setAttachedPropertyValue,s=e.CustomElementUtils.deleteAttachedPropertyValue;let a=class Pacem3DWebgpuAdapterElement extends t.Pacem3DAdapterElement{invalidateSize(e,t=e.size){const r=this._ensureRenderer(e);r?.resize(t)}#j=new Map;#Y=!0;#K=!0;get supported(){return this.#Y}get active(){return this.#K}_webGPUNotSupported(t){this.#Y&&t.cause===e.Drawing3D.WebGPU.WebGPUIssueCause.NotSupported&&(this.#Y=!1,this.dispatchEvent(new e.PropertyChangeEvent({propertyName:"supported",oldValue:null,currentValue:!1}))),this.#K&&(this.#K=!1,this.dispatchEvent(new e.PropertyChangeEvent({propertyName:"active",oldValue:null,currentValue:!1})))}initialize(t){const r=this.#j;return e.Drawing3D.WebGPU.Renderer.create(t,{enableValidation:this.enableValidation??!1}).then(e=>(r.set(t,e),e.canvas),t=>(this.log(e.Logging.LogLevel.Error,t.message),this._webGPUNotSupported(t),null))}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i&&"enableValidation"===e){const e=this.#j;for(let t of e.keys()){const r=e.get(t);e.delete(t),r.dispose(),this.initialize(t)}}}disconnectedCallback(){const e=this.#j;for(let[t,r]of e)r.dispose();e.clear(),super.disconnectedCallback()}dispose(e){const t=this.#j;t.has(e)&&(t.get(e).dispose(),t.delete(e))}_ensureRenderer(e){return this.#j.get(e)}_updatePipeline(e){const t=this._ensureRenderer(e);t?.update(...e.datasource)}#Z=new WeakMap;render(t){const o=this._ensureRenderer(t);if(e.Utils.isNull(o))return;if(this.#Z.has(t)&&(this.#Z.delete(t),this._itemsChangedExec(t)),o.render(),!t.interactive)return;const s=n(t,r);if(e.Utils.isNullOrEmpty(s))return;const a=n(t,i);e.Utils.isNullOrEmpty(a)?s(null):o.raycast(a).then(t=>{if(e.Utils.isNullOrEmpty(t))s(null);else{const e={object:t[0],point:null};s(e)}})}snapshot(t,r,i,n){const o=this.#j;if(!o.has(t))return Promise.resolve(null);const{canvas:s}=o.get(t),a=!e.Utils.isNullOrEmpty(r),l=i??(a?"image/jpeg":null),c=n??(a?.9:null);return new Promise((i,n)=>{this.render(t),e.Utils.snapshotElement(s,r,l,c).then(i)})}raycast(e,t,n,a){o(e,r,a),t.x<0||t.y<0||t.x>=n.width||t.y>=n.height?s(e,i):o(e,i,t)}_itemsChangedExec(e){this._updatePipeline(e)}_itemsChanged(e,t){this.#Z.set(e,!0)}addItem(e,t){this._itemsChanged(e,t)}removeItem(e,t){this._itemsChanged(e,t)}updateItem(t,r){(e.Utils.isNull(r)||r.flags.indexOf(e.Drawing3D.StalePropertyFlag.Visibility)>=0||r.flags.indexOf(e.Drawing3D.StalePropertyFlag.Children)>=0)&&this._itemsChanged(t,r)}zoomFit(e,...t){return Promise.resolve()}project(e,t){return{x:0,y:0}}getScene(e){return e}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],a.prototype,"enableValidation",void 0),a=__decorate([e.CustomElement({tagName:e.P+"-3d-webgpu-adapter"})],a),t.Pacem3DWebgpuAdapterElement=a}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r=.001,i=e.Geometry.LinearAlgebra.Matrix3D,n=e.Geometry.LinearAlgebra.Vector3D,o=e.Geometry.LinearAlgebra.Quaternion,s=(e.Geometry.LinearAlgebra.Spherical,{maxAzimuth:180,minAzimuth:-180,inertia:!1,maxPolar:1/0,minPolar:-1/0,zoom:{enabled:!0},pan:{enabled:!0,button:2},rotation:{enabled:!0,button:0}});class OrbitCameraBehavior{constructor(t,r){this._config=r,this._input={rho:0,theta:0,phi:0,x:0,y:0},this._progress={rho:0,theta:0,phi:0,x:0,y:0},this._startHandler=t=>{const{rotation:r,pan:i}=this._config,o="mouse"===t.pointerType,s=r.enabled&&o&&t.button===r.button&&e.CustomEventUtils.matchModifiers(t,r.modifiers),a=i.enabled&&o&&t.button===i.button&&e.CustomEventUtils.matchModifiers(t,i.modifiers);(s||a)&&(this.#q=s,(this.#J=a)&&(this._currentState=OrbitCameraBehavior._buildState(this._camera),e.Utils.extend(this._input,n.zero()),this._progress.x=this._progress.y=0),e.avoidHandler(t),window.addEventListener("pointerup",this._endHandler,!1),window.addEventListener("pointermove",this._moveHandler,!1),window.addEventListener("contextmenu",this._avoidHandler,!1))},this._avoidHandler=t=>e.avoidHandler(t),this._endHandler=t=>{e.avoidHandler(t),window.setTimeout(()=>{window.removeEventListener("pointerup",this._endHandler),window.removeEventListener("pointermove",this._moveHandler),window.removeEventListener("contextmenu",this._avoidHandler)},20)},this._zoomHandler=t=>{const{zoom:r}=this._config;if(!(r.enabled&&e.CustomEventUtils.matchModifiers(t,r.modifiers)))return;e.avoidHandler(t);this._input.rho-=Math.sign(t.deltaY)},this._moveHandler=t=>{e.avoidHandler(t);const{height:r,width:i}=this._scene.size,n=this._input,o=Math.min(r,i);if(this.#q){const e=-360/o,{phi:r,theta:i}=n,{maxPolar:s,minPolar:a,maxAzimuth:l,minAzimuth:c}=this._config;n.phi=(r+t.movementX*e).clamp(a,s),n.theta=(i+t.movementY*e).clamp(c,l)}else if(this.#J){const e=this._currentState.radius/o;n.x+=-t.movementX*e,n.y+=t.movementY*e}},this._renderHandler=e=>{this._update()};const i=this._scene=(this._camera=t).stage;this._initialState=this._currentState=OrbitCameraBehavior._buildState(t);const o=this._canvas=i.stage;o.addEventListener("pointerdown",this._startHandler,!1),o.addEventListener("wheel",this._zoomHandler,{passive:!1}),i.addEventListener("render",this._renderHandler,!1)}static _buildState(e){const t=n.subtract(e.position,e.lookAt),r=n.mag(t);return{target:e.lookAt,versor:n.unit(t),up:e.up,radius:r,position:e.position}}static tryAttach(t,r){r??=s;const i=function(t){return e.Drawing3D.isCamera(t)?t.stage:null}(t)?.stage;if(e.Utils.isNull(i))return null;{const{position:i,lookAt:o}=t;return e.Utils.isNull(i)||e.Utils.isNull(o)||n.areClose(i,o)?null:new OrbitCameraBehavior(t,r)}}get configuration(){return this._config}set configuration(e){this._config=e}#J;#q;_getSafeAzimuth({theta:e}){return OrbitCameraBehavior._modAngle(e)}_getSafePolar({phi:e}){return OrbitCameraBehavior._modAngle(e)}static _modAngle(e){for(;e<0;)e+=360;return e%360}static _getViewXYZ(e){const{versor:t,up:r}=e,i=n.cross(t,r),o=n.cross(i,t);return n.normalize(i),n.normalize(o),{right:i,up:o,versor:t}}#Q;_update(){if(this.#Q)return;this.#Q=!0;const t=this._camera,{radius:s,versor:a,target:l,up:c}=this._initialState,{target:u}=this._currentState,{theta:d,phi:h,rho:p,x:m,y:f}=this._input,g=this._progress,{theta:_,phi:y,rho:E,x:b,y:v}=g,P=Math.abs(y-h)>r||Math.abs(_-d)>r,x=Math.abs(E-p)>r,C=Math.abs(m-b)>r||Math.abs(f-v)>r;if(x||P||C){const r="boolean"==typeof this._config.inertia?this._config.inertia?.05:0:this._config.inertia,P=r>0&&r<1,{right:x,up:C}=OrbitCameraBehavior._getViewXYZ(this._initialState);let w=l,D=c,R=u,N=E;P?N+=(p-E)*r:N=p,g.rho=N;const M=Math.pow(.95,1*N),U=n.scale(a,-M*s);w=n.add(w,U);let L=y,T=_;P?(L+=(h-y)*r,T+=(d-_)*r):(L=h,T=d);const G=this._getSafePolar({phi:g.phi=L}),A=this._getSafeAzimuth({theta:g.theta=T}),I=n.negate(l);let B=i.translate(i.identity(),I);const O=o.fromAxisAngle(C,G),S=o.fromAxisAngle(x,A),k=i.multiply(o.toRotationMatrix(S),o.toRotationMatrix(O));B=i.multiply(B,k),B=i.translate(B,n.negate(I)),w=i.transform(w,B),D=i.transform(D,i.clone(B,e=>{e.offsetX=e.offsetY=e.offsetZ=0}));let W=b,F=v;P?(W+=(m-b)*r,F+=(f-v)*r):(W=m,F=f),g.x=W,g.y=F;const{right:V,up:$}=OrbitCameraBehavior._getViewXYZ(this._currentState),X=n.scale(V,W),z=n.scale($,F),H=n.add(X,z);R=n.add(u,H),t.lookAt=R,t.position=w,t.up=D,t.flags.push(e.Drawing3D.StalePropertyFlag.Camera)}this.#Q=!1}dispose(){const t=this._canvas,r=this._scene;e.Utils.isNull(t)||(t.removeEventListener("pointerdown",this._startHandler),t.removeEventListener("wheel",this._zoomHandler)),r.removeEventListener("render",this._renderHandler,!1)}}t.OrbitCameraBehavior=OrbitCameraBehavior;let a=class PacemOrbitCameraBehaviorElement extends e.Behaviors.PacemBehavior{constructor(){super(...arguments),this.#ee=new Map,this._readyHandler=t=>{if("isReady"===t.detail.propertyName&&!0===t.detail.currentValue){const r=t.currentTarget;r.removeEventListener(e.PropertyChangeEventName,this._readyHandler),this._decorateCore(r)}}}#ee;propertyChangedCallback(e,t,r,i){switch(super.propertyChangedCallback(e,t,r,i),e){case"maxAzimuth":case"minAzimuth":case"inertia":case"zoomControl":case"panControl":case"rotationControl":const e=this._buildConfig(),t=this.#ee;for(let r of t.values())r.configuration=e}}disconnectedCallback(){const e=this.#ee;for(let t of e.values())t.dispose();e.clear(),super.disconnectedCallback()}_buildConfig(){return e.Utils.extend({},s,{maxAzimuth:this.maxAzimuth??1/0,minAzimuth:this.minAzimuth??-1/0,minPolar:this.minPolar??-1/0,maxPolar:this.maxPolar??1/0,inertia:this.inertia??!1,zoom:this.zoomControl??s.zoom,pan:this.panControl??s.pan,rotation:this.rotationControl??s.rotation})}_decorateCore(t){const r=OrbitCameraBehavior.tryAttach(t,this._buildConfig());e.Utils.isNull(r)||this.#ee.set(t,r)}decorate(t){t.isConnected?this._decorateCore(t):t.addEventListener(e.PropertyChangeEventName,this._readyHandler,!1)}undecorate(e){const t=this.#ee;t.has(e)&&(t.get(e).dispose(),t.delete(e))}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"maxAzimuth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"maxPolar",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"minAzimuth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"minPolar",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"zoomControl",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"rotationControl",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],a.prototype,"panControl",void 0),__decorate([e.Watch({emit:!1,converter:e.Drawing3D.BooleanOrNumberConverter})],a.prototype,"inertia",void 0),a=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-orbit-camera"})],a),t.PacemOrbitCameraBehaviorElement=a}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){t.ambientLight=function(t,r,i){const n=`ambient_${e.Utils.uniqueCode()}`,o=t.inputColor,s=t.outputColor;if(e.Utils.isNullOrEmpty(o)||e.Utils.isNullOrEmpty(s))throw new Error("Must provide either input and output vertex color parameter names.");return{definitions:["struct AmbientLight {\n color: vec4f,\n intensity: f32\n}","fn computeAmbient(color: vec4f, light: AmbientLight) -> vec4f {\n return vec4f(light.intensity * color.rgb * light.color.rgb, color.a);\n}"],bindings:[`@group(${r}) @binding(${i}) var<uniform> ${n}: AmbientLight;`],modifiers:[`${s} = computeAmbient(${o}, ${n});`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={normal:"normal",inputColor:"white"};t.directionalLight=function(t,i,n){const o=`directional_${e.Utils.uniqueCode()}`,s=e.Utils.extend({},r,t),a=s.inputColor,l=s.outputColor,c=s.normal??"normal";if(e.Utils.isNullOrEmpty(a))throw new Error("Must provide input vertex color parameter name.");return{definitions:["struct DirectionalLight {\n color: vec4f,\n direction: vec3f,\n intensity: f32\n}","fn computeDirectional(normal: vec3f, color: vec4f, light: DirectionalLight) -> vec4f {\n let n = normalize(normal);\n let d = normalize(light.direction);\n let factor = light.intensity * .5 * (1.0 + dot(n, -d));\n let output = color.rgb * light.color.rgb * factor;\n return vec4f(output, color.a);\n}"],bindings:[`@group(${i}) @binding(${n}) var<uniform> ${o}: DirectionalLight;`],modifiers:l?[`${l} += computeDirectional(${c}, ${a}, ${o});`]:[`computeDirectional(${c}, ${a}, ${o})`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(e){!function(e){e.getColorPickingFragmentWgsl=function(t=e.UNIFORM_GROUP_INDEX_COLORPICKING){return`struct ColorPicker {\n id: u32,\n };\n\n @group(${t}) @binding(0) var<uniform> colorPicker: ColorPicker;\n\n @fragment\n fn main(@builtin(position) position: vec4f) -> @location(0) u32 {\n return colorPicker.id;\n }\n `}}(e.WebGPU||(e.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={normal:"normal",position:"vertex",ray:"ray",inputColor:"white",specularColor:"empty",shininess:"0"};t.omniLight=function(t,i,n){const o=`omni_${e.Utils.uniqueCode()}`,s=e.Utils.extend({},r,t),a=s.inputColor,l=s.outputColor,c=s.normal,u=s.ray,d=s.position,h=s.shininess,p=s.specularColor;if(e.Utils.isNullOrEmpty(a))throw new Error("Must provide input vertex color parameter name.");return{definitions:["struct OmniLight {\n color: vec4f,\n position: vec3f,\n intensity: f32\n}","fn computeOmni(position: vec3f, normal: vec3f, ray: vec3f, color: vec4f, specularColor: vec4f, shininess: f32, light: OmniLight) -> vec4f {\n\n // color\n let n = normalize(normal);\n let d = normalize(position - light.position);\n let factor = light.intensity * .5 * (1.0 + dot(n, -d));\n\n // specular\n let r = normalize(ray);\n let halfVector = normalize(d + r);\n let specular = specularColor.rgb * shininess * dot(n, -halfVector);\n\n let output = color.rgb * light.color.rgb * factor + specular;\n return vec4f(output, color.a);\n}"],bindings:[`@group(${i}) @binding(${n}) var<uniform> ${o}: OmniLight;`],modifiers:l?[`${l} += computeOmni(${d}, ${c}, ${u}, ${a}, ${p}, ${h}, ${o});`]:[`computeOmni(${d}, ${c}, ${u}, ${a}, ${p}, ${h}, ${o})`]}}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){const r={outputNormalLocation:t.VERTEX_OUTPUT_LOCATION_NORMAL,outputVertexLocation:t.VERTEX_OUTPUT_LOCATION_VERTEX,outputUvLocation:t.VERTEX_OUTPUT_LOCATION_UV,outputVertexIndexLocation:t.VERTEX_OUTPUT_LOCATION_INDEX,outputRayIndexLocation:t.VERTEX_OUTPUT_LOCATION_RAY,storageMaterialGroupIndex:t.MATERIAL_GROUP_INDEX,storageMaterialBindingIndex:t.STORAGE_MATERIAL_INDEX};function i(e=[]){return e.join("\r\n")}t.getStandardMaterialFragmentWgsl=function(n={},o=r){const s=e.Utils.extend({},r,o),a=i(n.definitions),l=i(n.bindings),c=function(e=[]){let r="";for(let i of e){const e=i.trim();e.endsWith(";")?r+=e+"\r\n\t":r+=`${t.VERTEX_COLOR_REFERENCE} = ${e};\r\n\t`}return r}(n.modifiers),u=t.VERTEX_COLOR_REFERENCE,d=t.LIGHTING_COLOR_REFERENCE,h=t.AMBIENT_COLOR_REFERENCE,p=t.MATERIAL_REFERENCE;return`// definitions\nstruct Material{\n specularColor: vec4f,\n shininess: vec4f,\n diffuseColor: vec4f,\n}\n\n${a}\n\n// bindings\n@group(${o.storageMaterialGroupIndex}) @binding(${o.storageMaterialBindingIndex}) var<storage, read> ${p}: Material;\n${l}\n\nconst empty = vec4f(0,0,0,0);\nconst white = vec4f(1,1,1,1);\n\n@fragment fn main (\n @builtin(position) position: vec4f, // clip-space position\n @location(${s.outputNormalLocation}) normal: vec3f, // world-space normal\n @location(${s.outputVertexLocation}) vertex: vec3f, // world-space position\n @location(${s.outputUvLocation}) uv: vec2f, \n @location(${s.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index, \n @location(${s.outputRayIndexLocation}) ray: vec3f // ray (eye-to-vertex) vector\n) -> @location(0) vec4f {\n var ${u} = ${p}.diffuseColor;\n var ${h}: vec4f = empty;\n var ${d}: vec4f = empty;\n\n // modifiers\n ${c}\n\n ${d} = select(white, ${d}, ${d}.a > 0);\n return ${u} * ${d} + ${h};\n}`}}(t.WebGPU||(t.WebGPU={}))}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class BasicMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Basic)}};r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-basic`})],r),t.BasicMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class LambertMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Lambert)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",reflectivity:this.reflectivity??0,refractionRatio:this.refractionRatio??0},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"reflectivity":case"refractionRatio":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"reflectivity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-lambert`})],r),t.LambertMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class LineMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Line)}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"lineWidth":case"lineJoin":case"lineCap":case"dashArray":this.updateMaterial()}}async createMaterial(){return e.Utils.extend({lineWidth:this.lineWidth??1,lineJoin:this.lineJoin??"round",lineCap:this.lineCap??"round",dashArray:this.dashArray},await super.createMaterial())}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"lineWidth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"lineJoin",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"lineCap",void 0),__decorate([e.Watch({emit:!1,converter:{convert:e=>e?.split(",").map(e=>parseInt(e)).filter(e=>!Number.isNaN(e)),convertBack:e=>e?.join(",")}})],r.prototype,"dashArray",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-line`})],r),t.LineMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class PhongMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Phong)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",reflectivity:this.reflectivity??0,refractionRatio:this.refractionRatio??0,specularColor:this.specularColor||"#000",shininess:this.shininess??0,flatShading:this.flatShading??!0},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"reflectivity":case"refractionRatio":case"specularColor":case"shininess":case"flatShading":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"reflectivity",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"specularColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"shininess",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],r.prototype,"flatShading",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-phong`})],r),t.PhongMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){let r=class StandardMaterialElement extends t.MaterialElement{constructor(){super(e.Drawing3D.KnownShader.Standard)}async createMaterial(){return e.Utils.extend({emissiveColor:this.emissiveColor||"#000",refractionRatio:this.refractionRatio??0,metalness:this.metalness??0,roughness:this.roughness??0,flatShading:this.flatShading??!1},await super.createMaterial())}propertyChangedCallback(e,t,r,i){if(super.propertyChangedCallback(e,t,r,i),!i)switch(e){case"emissiveColor":case"roughness":case"metalness":case"refractionRatio":case"flatShading":this.updateMaterial()}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.String})],r.prototype,"emissiveColor",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"refractionRatio",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"roughness",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],r.prototype,"metalness",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Boolean})],r.prototype,"flatShading",void 0),r=__decorate([e.CustomElement({tagName:`${e.P}-${t.TAG_MIDDLE_NAME}-material-standard`})],r),t.StandardMaterialElement=r}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){class OBJParser{static parse(r){const i=[],n=/^v((\s+-?[\d\.]+){3})/gm;let o=n.exec(r);for(;o&&o.length;)i.push(t.Point3DConverter.convert(o[1])),o=n.exec(r);const s=[],a=/^vt((\s+-?[\d\.]+){2})/gm;for(o=a.exec(r);o&&o.length;)s.push(e.Point.parse(o[1])),o=a.exec(r);const l=[],c=/^vn((\s+-?[\d\.]+){3})/gm;for(o=c.exec(r);o&&o.length;)l.push(t.Point3DConverter.convert(o[1])),o=c.exec(r);const u=[],d=[],h=[],p=/^f((\s+([\d]+\/[\d]+\/[\d]+)){3,})/gm;for(o=p.exec(r);o&&o.length;){const e=/([\d]+)\/([\d]+)\/([\d]+)/g,t=o[1];let i=e.exec(t),n=0;for(var m,f,g,_,y,E;i&&i.length;)n>2&&(h.push(m),d.push(s[f]),u.push(l[g]),h.push(_),d.push(s[y]),u.push(l[E])),_=parseInt(i[1])-1,y=parseInt(i[2])-1,E=parseInt(i[3])-1,h.push(_),d.push(s[y]),u.push(l[E]),0===n&&(m=_,f=y,g=E),n++,i=e.exec(t);o=p.exec(r)}return new t.MeshGeometry(i,h,d,u)}}__decorate([e.Transformer("parse3D")],class Parser3D{static parseGeometry(e,t){if("obj"===t.toLowerCase())return OBJParser.parse(e);throw new Error(`Type '${t}' is not supported.`)}},"parseGeometry",null)}(e.Drawing3D||(e.Drawing3D={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(r){class Pacem3DPrimitiveElement extends t.PacemEventTarget{viewActivatedCallback(){super.viewActivatedCallback(),e.Utils.isNull(this.geometry)&&(this.geometry=this.createDefaultGeometry())}}__decorate([e.Watch({converter:e.PropertyConverters.Json})],Pacem3DPrimitiveElement.prototype,"geometry",void 0),r.Pacem3DPrimitiveElement=Pacem3DPrimitiveElement}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemBoxElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(t,r,i,n,o,s){const a=t||1,l=r||1,c=i||1,u=n||1,d=o||1,h=s||1,p=[],m=[],f=[];for(var g=0;g<=d;g++)for(var _=l/2-l*(1*g)/(1*d),y=0;y<=h;y++)for(var E=-c/2+c*(1*y)/(1*h),b=0;b<=u;b++){var v=-a/2+a*(1*b)/(1*u);0!=b&&b!=u&&0!=y&&y!=h&&0!=g&&g!=d||p.push({x:v,y:_,z:E})}var P=function(e,t,r){for(var i=1e-5,n=0;n<p.length;n++){var o=p[n];if(Math.abs(o.x-e)<i&&Math.abs(o.y-t)<i&&Math.abs(o.z-r)<i)return n}return-1},x=function(e,t,r,i,n,o,s,a){f.push(e),f.push(t),f.push(r),f.push(e),f.push(r),f.push(i),m.push({x:n,y:a}),m.push({x:s,y:a}),m.push({x:s,y:o}),m.push({x:n,y:a}),m.push({x:s,y:o}),m.push({x:n,y:o})};for(y=0;y<h;y++){_=l/2,E=-c/2+c*(1*y)/(1*h);var C=-c/2+c*(1*(y+1))/(1*h);for(b=0;b<u;b++){var w=-a/2+1*(b+1)*a/(1*u);x(P(v=-a/2+1*b*a/(1*u),_,C),P(w,_,C),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*y/(1*h),1*(b+1)/(1*u),1-1*(y+1)/(1*h))}}for(g=0;g<d;g++){_=l/2-1*g*l/(1*d);var D=l/2-(g+1)*l/(1*d);for(E=-c/2,b=0;b<u;b++){w=a/2-(b+1)*a/(1*u);x(P(v=a/2-1*b*a/(1*u),D,E),P(w,D,E),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*g/(1*d),(b+1)/(1*u),1-(g+1)/(1*d))}}for(g=0;g<d;g++)for(_=l/2-1*g*l/(1*d),D=l/2-(g+1)*l/(1*d),v=-a/2,y=0;y<h;y++){C=-c/2+(y+1)*c/(1*h);x(P(v,D,E=-c/2+y*c/(1*h)),P(v,D,C),P(v,_,C),P(v,_,E),1*y/(1*h),1-g/(1*d),(y+1)/(1*h),1-(g+1)/(1*d))}for(g=0;g<d;g++)for(_=l/2-g*l/(1*d),D=l/2-(g+1)*l/(1*d),E=c/2,b=0;b<u;b++){w=-a/2+(b+1)*a/(1*u);x(P(v=-a/2+b*a/(1*u),D,E),P(w,D,E),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*g/(1*d),(b+1)/(1*u),1-(g+1)/(1*d))}for(g=0;g<d;g++)for(_=l/2-g*l/(1*d),D=l/2-(g+1)*l/(1*d),v=a/2,y=0;y<h;y++){C=c/2-(y+1)*c/(1*h);x(P(v,D,E=c/2-y*c/(1*h)),P(v,D,C),P(v,_,C),P(v,_,E),1*y/(1*h),1-1*g/(1*d),(y+1)/(1*h),1-(g+1)/(1*d))}for(y=0;y<h;y++)for(_=-l/2,E=c/2-c*y/(1*h),C=c/2-c*(y+1)/(1*h),b=0;b<u;b++){w=-a/2+(b+1)*a/(1*u);x(P(v=-a/2+b*a/(1*u),_,C),P(w,_,C),P(w,_,E),P(v,_,E),1*b/(1*u),1-1*y/(1*h),(b+1)/(1*u),1-(y+1)/(1*h))}const R=new e.Drawing3D.MeshGeometry(p,f,m);R.key=`box_${t}x${r}x${i}_w${n}_h${o}_d${s}`,e.Drawing3D.computeSharpVertexNormals(R);const N={x:0,y:0,z:0},M=t/2,U=r/2,L=i/2;return R.barycenter=N,R.boundingBox={maxX:M,maxY:U,maxZ:L,minX:-M,minY:-U,minZ:-L},R.boundingSphere={center:N,radius:Math.sqrt(Math.pow(M,2)+Math.pow(U,2)+Math.pow(L,2))},R}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"width":case"height":case"depth":case"widthSegments":case"heightSegments":case"depthSegments":this.geometry=r.createMeshGeometry(this.width,this.height,this.depth,this.widthSegments,this.heightSegments,this.depthSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"width",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"depth",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"widthSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"depthSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-box"})],i),t.PacemBoxElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemConeElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=1,n=18,o=5,s=1){const a=r,l=[],c=[],u=[],d=t.DEG2RAD*(360/n),h=a/i,p=i/o,m=1/n;l.push({x:0,y:i,z:0});for(let e=1;e<=o;e++){const t=i-p*e,r=t/i,o=(i-t)*h,s=(t+p)/i;for(let i=0;i<n;i++){const a=d*i,h=Math.cos(a)*o,p=-Math.sin(a)*o;l.push({x:h,y:t,z:p});const f=1+n*(e-1)+i,g=0==i?f+n-1:f-1,_=i*m,y=0==i?1-m:m*(i-1);if(1==e){u.push(0,g,f),c.push({x:_,y:1},{x:y,y:r},{x:_,y:r});continue}const E=1+n*(e-2)+i,b=0==i?E+n-1:E-1,v=g,P=f,x=E;u.push(P,b,v),u.push(P,x,b);const C={x:y,y:s},w={x:y,y:r},D={x:_,y:r},R={x:_,y:s};c.push(D,C,w),c.push(D,R,C)}}const f=1+(o-1)*n;l.push({x:0,y:0,z:0});const g=f+n;for(let e=1;e<=s;e++){const t=e/s,i=r*t,o=(e-1)/s;for(let r=0;r<n;r++){const a=d*r,h=Math.cos(a),p=Math.sin(a),m=a-d,_=Math.cos(m),y=Math.sin(m),E=.5*(1+h*t),b=.5*(1+p*t),v=.5*(1+_*t),P=.5*(1+y*t);let x,C;if(e!=s){const t=Math.cos(a)*i,o=-Math.sin(a)*i;l.push({x:t,y:0,z:o}),x=g+1+(e-1)*n+r,C=0==r?x+n-1:x-1}else x=f+r,C=0==r?f+n-1:x-1;if(1==e){u.push(g,x,C),c.push({x:.5,y:.5},{x:E,y:b},{x:v,y:P});continue}const w=.5*(1+h*o),D=.5*(1+p*o),R=.5*(1+_*o),N=.5*(1+y*o),M=g+1+(e-2)*n+r,U=0==r?M+n-1:M-1,L=C,T=x,G=M;u.push(U,G,L),u.push(L,G,T);const A={x:R,y:N},I={x:v,y:P},B={x:E,y:b},O={x:w,y:D};c.push(A,O,I),c.push(I,O,B)}}const _=new e.Drawing3D.MeshGeometry(l,u,c);return _.key=`cone_${r}x${i}_s${n}_h${o}_c${s}`,e.Drawing3D.computeSharpVertexNormals(_),_}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"height":case"sides":case"heightSegments":case"capSegments":this.geometry=r.createMeshGeometry(this.radius,this.height,this.sides,this.heightSegments,this.capSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"capSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-cone"})],i),t.PacemConeElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemCylinderElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=1,n=18,o=5,s=1){const a=r,l=[],c=[],u=[],d=t.DEG2RAD*(360/n);l.push({x:0,y:i,z:0}),l.push({x:0,y:0,z:0});const h=a/s;for(let e=1;e<=s;e++)for(var p=h*e,m=0;m<n;m++){const t=2+2*n*(e-1),r=0==m?t+2*(n-1):t+2*(m-1),o=t+2*m,h=Math.cos(d*m),f=-Math.sin(d*m),g=Math.cos(d*(m-1)),_=-Math.sin(d*(m-1)),y=p*h,E=p*f,b={x:y,y:i,z:E},v={x:y,y:0,z:E};l.push(b),l.push(v);const P=.5*p/a,x=h*P,C=f*P,w=g*P,D=_*P;if(1==e){const e=[0,r,o],t=[1,o+1,r+1],i=[{x:.5,y:.5},{x:.5+w,y:.5-D},{x:.5+x,y:.5-C}],n=[{x:.5,y:.5},{x:.5+x,y:.5+C},{x:.5+w,y:.5+D}];u.push(...e),u.push(...t);for(let e=0;e<i.length;e++)c.push(i[e]);for(let e=0;e<n.length;e++)c.push(n[e])}else{const t=2+2*n*(e-2),i=0==m?t+2*(n-1):t+2*(m-1),a=t+2*m,l=(e-1)/s*.5,d=h*l,p=f*l,y=g*l,E=_*l,b={x:.5+w,y:.5-D},v={x:.5+x,y:.5-C},P={x:.5+d,y:.5-p},R={x:.5+y,y:.5-E},N={x:.5+w,y:.5+D},M={x:.5+x,y:.5+C},U={x:.5+d,y:.5+p},L={x:.5+y,y:.5+E};u.push(r),u.push(o),u.push(i),u.push(i),u.push(o),u.push(a),u.push(a+1),u.push(o+1),u.push(r+1),u.push(a+1),u.push(r+1),u.push(i+1),c.push(b),c.push(v),c.push(R),c.push(R),c.push(v),c.push(P),c.push(U),c.push(M),c.push(N),c.push(U),c.push(N),c.push(L)}}const f=2+2*n*s,g=2+2*n*(s-1),_=1/n,y=1/o;for(let e=1;e<=o;e++)for(let t=0;t<n;t++){if(e!=o){var E=a*Math.cos(d*t),b=-a*Math.sin(d*t),v=i*e/o;l.push({x:E,y:v,z:b})}const r=0==t?n-1:t-1,s=1==e?g+2*r+1:f+n*(e-2)+r,h=1==e?g+2*t+1:f+n*(e-2)+t,p=e==o?g+2*t:f+n*(e-1)+t,m=e==o?g+2*r:f+n*(e-1)+r,P=r*_,x=(e-1)*y,C=0==t?1:t*_,w=e*y,D={x:P,y:x},R={x:C,y:x},N={x:C,y:w},M={x:P,y:w};u.push(s),u.push(h),u.push(p),u.push(s),u.push(p),u.push(m),c.push(D),c.push(R),c.push(N),c.push(D),c.push(N),c.push(M)}const P=new e.Drawing3D.MeshGeometry(l,u,c);return P.key=`cylinder_${r}x${i}_s${n}_h${o}_c${s}`,e.Drawing3D.computeSharpVertexNormals(P),P}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"height":case"sides":case"heightSegments":case"capSegments":this.geometry=r.createMeshGeometry(this.radius,this.height,this.sides,this.heightSegments,this.capSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"height",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"heightSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"capSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-cylinder"})],i),t.PacemCylinderElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;const i=[{x:0,y:0,z:0},{x:0,y:1,z:0}];let n=r=class PacemLineElement extends t.Pacem3DPrimitiveElement{static createLineGeometry(t){return new e.Drawing3D.LineGeometry(t||i)}createDefaultGeometry(){return r.createLineGeometry()}propertyChangedCallback(e,t,i,n){if(super.propertyChangedCallback(e,t,i,n),"positions"===e)this.geometry=r.createLineGeometry(i)}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Json})],n.prototype,"positions",void 0),n=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-line"})],n),t.PacemLineElement=n}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemPlaneElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(t,r,i,n){t||=1,r||=1,i||=4,n||=4;const o=.5*t,s=.5*r,a=[],l=[],c=[],u=[],d=e.Geometry.LinearAlgebra.Vector3D.from(0,0,1);for(let e=0;e<=n;e++)for(let h=0;h<=i;h++){const p=h*t/(1*i)-o,m=0,f=e*r/(1*n)-s;if(a.push({x:p,y:m,z:f}),e<n&&h<i){const t=i+1,r=(h+1)/(1*i),o=1*h/(1*i),s=1-(e+1)/(1*n),a=1-1*e/(1*n);c.push((e+1)*t+h),c.push((e+1)*t+h+1),c.push(e*t+h+1),c.push((e+1)*t+h),c.push(e*t+h+1),c.push(e*t+h),l.push({x:o,y:s}),l.push({x:r,y:s}),l.push({x:r,y:a}),l.push({x:o,y:s}),l.push({x:r,y:a}),l.push({x:o,y:a}),u.push(d,d,d,d,d,d)}}const h=new e.Drawing3D.MeshGeometry(a,c,l,u);return h.key=`plane_${t}x${r}_w${i}_l${n}`,h}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"width":case"length":case"widthSegments":case"lengthSegments":this.geometry=r.createMeshGeometry(this.width,this.length,this.widthSegments,this.lengthSegments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"width",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"length",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"widthSegments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"lengthSegments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-plane"})],i),t.PacemPlaneElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r,i,n,o,s;const a=function(e){const t=/([\d.-]+)/i;var r=t.exec(e);const i=[];for(;null!=r;){const n=r[0],o=parseFloat(n);i.push(o),e=e.replace(n,""),r=t.exec(e)}return i},l=e.Geometry.LinearAlgebra.Vector3D;class PolyhedronElement extends t.Pacem3DPrimitiveElement{propertyChangedCallback(e,t,r,i){super.propertyChangedCallback(e,t,r,i),"radius"===e&&this._assignMeshGeometry(r)}_assignMeshGeometry(e){this.geometry=this.createMeshGeometry(e>0?e:1)}createDefaultGeometry(){return this.createMeshGeometry(1)}}__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],PolyhedronElement.prototype,"radius",void 0),t.PolyhedronElement=PolyhedronElement;let c=r=class PacemTetrahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r="0 0.5774 -0.8165, 0 0.5774 0.8165, 0.8165 -0.5774 0, -0.8165 -0.5774 0".split(","),i=[];for(let e=0;e<r.length;e++){const n=r[e],o=a(n);i.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const n="0.5 0.9995, 0.5 0.0004995, 0.0004995 0.5, 0.9995 0.5, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995".split(","),o=[4,5,6,7,8,9,10,11,0,3,2,1],s=[];for(let e=0;e<o.length;e++){const t=a(n[o[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(i,[1,2,0,2,3,0,3,1,0,3,2,1],s);return c.key=`tetrahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return r.createMeshGeometry(e)}};c=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-tetrahedron"})],c),t.PacemTetrahedronElement=c;let u=i=class PacemOctahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[6,7,8,9,10,11,12,13,14,15,16,0,17,18,19,20,21,1,2,22,23,4,3,5],i="0 0.7071 -0.7071, 0 0.7071 0.7071, 1 0 0, 0 -0.7071 -0.7071, -1 0 0, 0 -0.7071 0.7071".split(","),n=[];for(let e=0;e<i.length;e++){const r=i[e],o=a(r);n.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const o="0.5 0.9995, 0.5 0.9995, 0.0004995 0.5, 0.5 0.9995, 0.9995 0.5, 0.5 0.0004995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995, 0.5 0.9995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.9995, 0.0004995 0.5, 0.5 0.0004995, 0.0004995 0.5, 0.5 0.0004995, 0.5 0.9995, 0.5 0.0004995, 0.9995 0.5, 0.5 0.0004995, 0.5 0.9995".split(","),s=[];for(let e=0;e<r.length;e++){const t=a(o[r[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(n,[1,2,0,2,3,0,3,4,0,4,1,0,4,5,1,5,2,1,2,5,3,4,3,5],s);return c.key=`octahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return i.createMeshGeometry(e)}};u=i=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-octahedron"})],u),t.PacemOctahedronElement=u;let d=n=class PacemHexahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=2*t*(1/Math.sqrt(3)),i=e.Components.Drawing3D.PacemBoxElement.createMeshGeometry(r,r,r);return i.key=`hexahedron_${t}`,i}createMeshGeometry(e=this.radius){return n.createMeshGeometry(e)}};d=n=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-hexahedron"})],d),t.PacemHexahedronElement=d;let h=o=class PacemIcosahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,26,27,28,29,30,31,32,33,1,34,35,36,2,37,38,39,40,41,42,43,7,44,45,46,8,47,48,49,50,51,52,53,9,54,55,3,10,56,57,6,58,59,5,4,11],i="0 0.850651 -0.525731, 0 0.850651 0.525731, 0.850651 0.525731 0, 0.525731 0 -0.850651, -0.525731 0 -0.850651, -0.850651 0.525731 0, -0.525731 0 0.850651, 0.525731 0 0.850651, 0.850651 -0.525731 0, 0 -0.850651 0.525731, 0 -0.850651 -0.525731, -0.850651 -0.525731 0".split(","),n=[];for(let e=0;e<i.length;e++){const r=i[e],o=a(r);n.push({x:o[0]*t,y:o[1]*t,z:o[2]*t})}const o="0.5 0.808708, 0.5 0.999501, 0.5 0.808708, 0.191292 0.5, 0.000499547 0.5, 0.5 0.808708, 0.9995 0.5, 0.808708 0.5,0.000499487 0.5, 0.5 0.191292, 0.5 0.000499487, 0.5 0.191292,0.5 0.191292, 0.999501 0.5, 0.5 0.808708, 0.5 0.808708,0.9995 0.5, 0.808708 0.999501, 0.191292 0.5, 0.808708 0.5,0.5 0.999501, 0.808708 0.5, 0.999501 0.808708, 0.5 0.999501,0.000499487 0.5, 0.5 0.191292, 0.5 0.808708, 0.9995 0.5,0.808708 0.999501, 0.191292 0.5, 0.808708 0.5, 0.5 0.999501,0.808708 0.5, 0.999501 0.808708, 0.5 0.808708, 0.5 0.191292,0.9995 0.5, 0.000499547 0.5, 0.5 0.191292, 0.191292 0.5,0.5 0.000499487, 0.808708 0.5, 0.5 0.000499487, 0.999501 0.191292,0.5 0.191292, 0.808708 0.000499487, 0.9995 0.5, 0.5 0.191292,0.5 0.808708, 0.9995 0.5, 0.5 0.191292, 0.808708 0.000499487,0.999501 0.5, 0.5 0.808708, 0.5 0.000499487, 0.808708 0.5,0.999501 0.191292, 0.808708 0.5, 0.5 0.808708, 0.5 0.191292".split(","),s=[];for(let e=0;e<r.length;e++){const t=a(o[r[e]]);s.push({x:t[0],y:t[1]})}const c=new e.Drawing3D.MeshGeometry(n,[1,2,0,2,3,0,3,4,0,4,5,0,5,1,0,5,6,1,6,7,1,7,2,1,2,8,3,2,7,8,6,9,7,9,8,7,8,10,3,8,9,10,6,11,9,11,10,9,10,4,3,10,11,4,6,5,11,5,4,11],s);return c.key=`icosahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(c),c.boundingSphere={center:l.zero(),radius:t},c}createMeshGeometry(e=this.radius){return o.createMeshGeometry(e)}};h=o=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-icosahedron"})],h),t.PacemIcosahedronElement=h;let p=s=class PacemDodecahedronElement extends PolyhedronElement{static createMeshGeometry(t){t||=1;const r=[l.from(.356822*t,.934172*t,0*t),l.from(-.356822*t,.934172*t,0*t),l.from(.57735*t,.57735*t,-.57735*t),l.from(0*t,.356822*t,-.934172*t),l.from(-.57735*t,.57735*t,-.57735*t),l.from(-.57735*t,.57735*t,.57735*t),l.from(0*t,.356822*t,.934172*t),l.from(.57735*t,.57735*t,.57735*t),l.from(.934172*t,0*t,-.356822*t),l.from(.934172*t,0*t,.356822*t),l.from(0*t,-.356822*t,.934172*t),l.from(.57735*t,-.57735*t,.57735*t),l.from(.57735*t,-.57735*t,-.57735*t),l.from(.356822*t,-.934172*t,0*t),l.from(-.57735*t,-.57735*t,.57735*t),l.from(-.356822*t,-.934172*t,0*t),l.from(0*t,-.356822*t,-.934172*t),l.from(-.57735*t,-.57735*t,-.57735*t),l.from(-.934172*t,0*t,.356822*t),l.from(-.934172*t,0*t,-.356822*t)],i=[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,0,46,47,48,49,50,51,7,52,53,54,55,56,57,58,59,60,61,9,62,63,64,65,66,67,11,68,69,70,71,72,73,74,75,76,77,13,78,79,80,81,82,83,15,84,85,86,87,88,89,90,91,92,93,17,94,95,96,97,98,99,19,1,4,100,14,101,102,10,103,18,6,5,104,2,105,106,8,107,3,12,16],n="0.5 0.999501, 0.5 0.999501, 0.191292 0.808708, 0.5 0.690792,\n 0.191292 0.808708, 0.191292 0.808708, 0.5 0.690792, \n 0.808708 0.808708, 0.000499517 0.5, 0.309208 0.5, 0.5 0.309208, \n 0.191292 0.191292, 0.191292 0.191292, 0.309208 0.5, \n 0.191292 0.191292, 0.5 0.000499517, 0.5 0.309208, 0.808708 0.191292, \n 0.000499517 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708, \n 0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.309208 0.5, \n 0.191292 0.191292, 0.5 0.000499517, 0.309208 0.5, 0.5 0.000499517, \n 0.808708 0.191292, 0.309208 0.5, 0.808708 0.191292, \n 0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.690792 0.5, \n 0.191292 0.808708, 0.690792 0.5, 0.808708 0.808708, \n 0.191292 0.808708, 0.808708 0.808708, 0.808708 0.808708, \n 0.5 0.690792, 0.5 0.309208, 0.808708 0.808708, 0.5 0.309208, \n 0.808708 0.191292, 0.808708 0.191292, 0.9995 0.5, 0.191292 0.191292, \n 0.5 0.000499517, 0.808708 0.191292, 0.191292 0.191292, \n 0.808708 0.191292, 0.690792 0.5, 0.191292 0.191292, \n 0.690792 0.5, 0.191292 0.191292, 0.5 0.000499517, 0.808708 0.191292, \n 0.191292 0.191292, 0.808708 0.191292, 0.690792 0.5, \n 0.690792 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708, \n 0.690792 0.5, 0.191292 0.808708, 0.5 0.000499517, 0.808708 0.191292, \n 0.690792 0.5, 0.5 0.000499517, 0.690792 0.5, 0.309208 0.5, \n 0.309208 0.5, 0.191292 0.191292, 0.9995 0.5, 0.808708 0.808708, \n 0.5 0.690792, 0.9995 0.5, 0.5 0.690792, 0.5 0.309208, \n 0.9995 0.5, 0.5 0.309208, 0.309208 0.5, 0.690792 0.5, \n 0.808708 0.808708, 0.309208 0.5, 0.808708 0.808708, \n 0.5 0.999501, 0.000499517 0.5, 0.5 0.309208, 0.000499517 0.5, \n 0.5 0.690792, 0.5 0.690792, 0.000499517 0.5, 0.5 0.690792, \n 0.191292 0.191292".split(","),o=[];for(let e=0;e<i.length;e++){const t=a(n[i[e]]);o.push({x:t[0],y:t[1]})}const s=new e.Drawing3D.MeshGeometry(r,[0,2,3,0,3,4,0,4,1,1,5,6,1,6,7,1,7,0,7,9,8,7,8,2,7,2,0,7,6,10,7,10,11,7,11,9,11,13,12,11,12,8,11,8,9,11,10,14,11,14,15,11,15,13,15,17,16,15,16,12,15,12,13,15,14,18,15,18,19,15,19,17,19,4,3,19,3,16,19,16,17,19,18,5,19,5,1,19,1,4,18,14,10,18,10,6,18,6,5,3,2,8,3,8,12,3,12,16],o);return s.key=`dodecahedron_${t}`,e.Drawing3D.computeSharpVertexNormals(s),s.boundingSphere={center:l.zero(),radius:t},s}createMeshGeometry(e=this.radius){return s.createMeshGeometry(e)}};p=s=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-dodecahedron"})],p),t.PacemDodecahedronElement=p}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemSphereElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=8){const n=[],o=[],s=[],a=r,l=i,c=t.DEG2RAD*(360/l),u=l%2==0?l/2:(l-1)/2;n.push({x:0,y:a,z:0});for(let e=1;e<u;e++){const t=c*e,r=Math.cos(t),i=Math.sin(t),d=1-1*e/u;for(let t=0;t<l;t++){const h=c*t-Math.PI/2,p=a*i*Math.cos(h),m=a*r,f=a*i*Math.sin(h);n.push({x:p,y:m,z:f});const g=0==t?l-1:t-1,_=0==t?0:1-1*t/l,y=1-1*g/l;if(1==e)s.push(1+t),s.push(1+g),s.push(0),o.push({x:_,y:d}),o.push({x:y,y:d}),o.push({x:.5,y:1});else{s.push((e-1)*l+t+1),s.push((e-1)*l+g+1),s.push((e-2)*l+g+1),s.push((e-1)*l+t+1),s.push((e-2)*l+g+1),s.push((e-2)*l+t+1);const r=1-(e-1)/u;o.push({x:_,y:d}),o.push({x:y,y:d}),o.push({x:y,y:r}),o.push({x:_,y:d}),o.push({x:y,y:r}),o.push({x:_,y:r})}}}n.push({x:0,y:-a,z:0});const d=n.length-1;for(let e=0;e<l;e++){const t=u-2,r=0==e?l-1:e-1,i=0==e?0:1-1*e/l,n=1-1*r/l,a=1-(t+1)/u;s.push(d),s.push(t*l+1+r),s.push(t*l+1+e),o.push({x:.5,y:0}),o.push({x:n,y:a}),o.push({x:i,y:a})}const h=new e.Drawing3D.MeshGeometry(n,s,o);return h.key=`sphere_${r}_s${i}`,e.Drawing3D.computeSharpVertexNormals(h),h}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"segments":this.geometry=r.createMeshGeometry(this.radius,this.segments)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"segments",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-sphere"})],i),t.PacemSphereElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={})),function(e){!function(t){!function(t){var r;let i=r=class PacemTorusElement extends t.Pacem3DPrimitiveElement{static createMeshGeometry(r=1,i=.25,n=24,o=12){const s=[],a=[],l=[],c=t.DEG2RAD*(360/n),u=t.DEG2RAD*(360/o),d=r,h=i;for(let e=0;e<n;e++){const t=c*e-Math.PI/2,r=Math.sin(t),i=Math.cos(t);for(let t=0;t<o;t++){const c=u*t+Math.PI,p=Math.cos(c),m=d*i+h*p*i,f=h*Math.sin(c),g=d*r+h*p*r;s.push({x:m,y:f,z:g});const _=e>0?e-1:n-1,y=t>0?t-1:o-1,E=0==e?0:1-1*e/n,b=t>0?1*t/o:1,v=e>0?1-(e-1)/n:1/n,P=t>0?(t-1)/o:1-1/o;l.push(e*o+y),l.push(_*o+y),l.push(_*o+t),l.push(e*o+y),l.push(_*o+t),l.push(e*o+t),a.push({x:E,y:P}),a.push({x:v,y:P}),a.push({x:v,y:b}),a.push({x:E,y:P}),a.push({x:v,y:b}),a.push({x:E,y:b})}}const p=new e.Drawing3D.MeshGeometry(s,l,a);return p.key=`torus_${r}x${i}_t${n}_s${o}`,e.Drawing3D.computeSharpVertexNormals(p),p}createDefaultGeometry(){return r.createMeshGeometry()}propertyChangedCallback(e,t,i,n){switch(super.propertyChangedCallback(e,t,i,n),e){case"radius":case"innerRadius":case"segments":case"sides":this.geometry=r.createMeshGeometry(this.radius,this.innerRadius,this.segments,this.sides)}}};__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"radius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"innerRadius",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"segments",void 0),__decorate([e.Watch({emit:!1,converter:e.PropertyConverters.Number})],i.prototype,"sides",void 0),i=r=__decorate([e.CustomElement({tagName:e.P+"-"+t.TAG_MIDDLE_NAME+"-primitive-torus"})],i),t.PacemTorusElement=i}(t.Drawing3D||(t.Drawing3D={}))}(e.Components||(e.Components={}))}(Pacem||(Pacem={}));
|