@thatopen/components 2.3.9 → 2.4.0-alpha.2
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/core/Components/index.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/namespace.d.ts +4159 -4159
- package/package.json +4 -4
|
@@ -6,7 +6,7 @@ export declare class Components implements Disposable {
|
|
|
6
6
|
/**
|
|
7
7
|
* The version of the @thatopen/components library.
|
|
8
8
|
*/
|
|
9
|
-
static readonly release = "2.
|
|
9
|
+
static readonly release = "2.4.0-alpha.1";
|
|
10
10
|
/** {@link Disposable.onDisposed} */
|
|
11
11
|
readonly onDisposed: Event<void>;
|
|
12
12
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.
|
|
4
4
|
|
|
5
|
-
- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};C(Lt,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),C(Lt,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let Kt=Lt;class ic extends mt{constructor(t,e){super(t);C(this,"onDisposed",new q);C(this,"onVertexFound",new q);C(this,"onVertexLost",new q);C(this,"onEnabled",new q);C(this,"components");C(this,"workingPlane",null);C(this,"_pickedPoint",null);C(this,"_config");C(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...e},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const n=this.components.get(ve).get(t).castRay();if(!n)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const r=this.getClosestVertex(n);return r?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(r))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(r))&&(this._pickedPoint=r.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let e=new b.Vector3,s=!1,n=Number.MAX_SAFE_INTEGER;const r=this.getVertices(t);if(r===null)return null;for(const o of r){if(!o)continue;const a=t.point.distanceTo(o);a>n||a>this._config.snapDistance||(s=!0,e=o,n=t.point.distanceTo(o))}return s?e:this.config.showOnlyVertex?null:t.point}getVertices(t){const e=t.object;if(!t.face||!e)return null;const s=e.geometry,n=new b.Matrix4,{instanceId:r}=t,o=r!==void 0,a=e instanceof b.InstancedMesh;return a&&o&&e.getMatrixAt(r,n),[this.getVertex(t.face.a,s),this.getVertex(t.face.b,s),this.getVertex(t.face.c,s)].map(l=>(l&&(a&&o&&l.applyMatrix4(n),l.applyMatrix4(e.matrixWorld)),l))}getVertex(t,e){if(t===void 0)return null;const s=e.attributes.position;return new b.Vector3(s.getX(t),s.getY(t),s.getZ(t))}}const Rs=class Rs{constructor(){C(this,"onDisposed",new q);C(this,"list",new Map);C(this,"enabled",!1);C(this,"_clock");C(this,"onInit",new q);C(this,"update",()=>{if(!this.enabled)return;const i=this._clock.getDelta();for(const[t,e]of this.list)e.enabled&&e.isUpdateable()&&e.update(i);requestAnimationFrame(this.update)});this._clock=new b.Clock,Rs.setupBVH()}add(i,t){if(this.list.has(i))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");Kt.validate(i),this.list.set(i,t)}get(i){const t=i.uuid;if(!this.list.has(t)){const e=new i(this);return this.list.has(t)||this.add(t,e),e}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update(),this.onInit.trigger()}dispose(){this.enabled=!1;for(const[i,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){b.BufferGeometry.prototype.computeBoundsTree=Ha,b.BufferGeometry.prototype.disposeBoundsTree=Wa,b.Mesh.prototype.raycast=ka}};C(Rs,"release","2.3.9");let Li=Rs;class Hr extends Vs{constructor(){super(...arguments);C(this,"meshes",new Set);C(this,"onAfterUpdate",new q);C(this,"onBeforeUpdate",new q);C(this,"onDisposed",new q);C(this,"isDisposing",!1);C(this,"enabled",!0);C(this,"uuid",Kt.create());C(this,"name");C(this,"_scene");C(this,"_camera");C(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const s=this.components.get(Ce);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const n of this.meshes)s.destroy(n);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.components.get(Pi).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class ye{constructor(i,t,e,s){C(this,"_component");C(this,"name");C(this,"uuid");this._component=i,this.name=e,this.uuid=s??Kt.create(),t.get(Ne).list.set(this.uuid,this)}get controls(){const i={};for(const t in this._config){const e=this._config[t];i[t]=this.copyEntry(e)}return i}copyEntry(i){if(i.type==="Boolean"){const t=i;return{type:t.type,value:t.value}}if(i.type==="Color"){const t=i;return{type:t.type,value:t.value.clone()}}if(i.type==="Text"){const t=i;return{type:t.type,value:t.value}}if(i.type==="Number"){const t=i;return{type:t.type,value:t.value,min:t.min,max:t.max,interpolable:t.interpolable}}if(i.type==="Select"){const t=i;return{type:t.type,value:t.value,multiple:t.multiple,options:new Set(t.options)}}if(i.type==="Vector3"){const t=i;return{type:t.type,value:t.value.clone()}}if(i.type==="TextSet"){const t=i;return{type:t.type,value:new Set(t.value)}}if(i.type==="None"){const t=i;return{type:t.type,value:t.value}}throw new Error("Invalid entry!")}}const gs=class gs extends mt{constructor(t){super(t);C(this,"list",new Qt);C(this,"enabled",!0);t.add(gs.uuid,this)}};C(gs,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let Ne=gs;class sc{constructor(i,t){C(this,"_list");C(this,"_scene");this._list=i,this._scene=t}get color(){return this._list.directionalLight.color.value}set color(i){this._list.directionalLight.color.value=i;for(const[,t]of this._scene.directionalLights)t.color.copy(i)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(i){this._list.directionalLight.intensity.value=i;for(const[,t]of this._scene.directionalLights)t.intensity=i}get position(){return this._list.directionalLight.position.value.clone()}set position(i){this._list.directionalLight.position.value=i;for(const[,t]of this._scene.directionalLights)t.position.copy(i)}}class nc{constructor(i,t){C(this,"_list");C(this,"_scene");this._list=i,this._scene=t}get color(){return this._list.ambientLight.color.value}set color(i){this._list.ambientLight.color.value=i;for(const[,t]of this._scene.ambientLights)t.color.copy(i)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(i){this._list.ambientLight.intensity.value=i;for(const[,t]of this._scene.ambientLights)t.intensity=i}}class Wr extends ye{constructor(){super(...arguments);C(this,"_config",{backgroundColor:{value:new b.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new b.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new b.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new b.Vector3}}});C(this,"ambientLight",new nc(this._config,this._component));C(this,"directionalLight",new sc(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class Xr extends zr{constructor(t){super(t);C(this,"onSetup",new q);C(this,"isSetup",!1);C(this,"three");C(this,"config",new Wr(this,this.components,"Scene"));C(this,"_defaultConfig",{backgroundColor:new b.Color(2107698),directionalLight:{color:new b.Color("white"),intensity:1.5,position:new b.Vector3(5,10,3)},ambientLight:{color:new b.Color("white"),intensity:1}});this.three=new b.Scene,this.three.background=new b.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const s=e.ambientLight;this.config.ambientLight.color=s.color,this.config.ambientLight.intensity=s.intensity;const n=e.directionalLight;this.config.directionalLight.color=n.color,this.config.directionalLight.intensity=n.intensity,this.config.directionalLight.position=n.position,this.deleteAllLights();const{color:r,intensity:o}=this.config.directionalLight,a=new b.DirectionalLight(r,o);a.position.copy(n.position);const{color:l,intensity:h}=this.config.directionalLight,f=new b.AmbientLight(l,h);this.three.add(a,f),this.directionalLights.set(a.uuid,a),this.ambientLights.set(f.uuid,f),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose(),this.components.get(Ne).list.delete(this.config.uuid)}}class rc extends Gr{constructor(t,e,s){super(t);C(this,"enabled",!0);C(this,"container");C(this,"three");C(this,"_canvas");C(this,"_parameters");C(this,"_resizeObserver",null);C(this,"onContainerUpdated",new q);C(this,"_resizing",!1);C(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,s=t?t.y:this.container.clientHeight;this.three.setSize(e,s),this.onResize.trigger(new b.Vector2(e,s)),this._resizing=!1});C(this,"resizeEvent",()=>{this.resize()});C(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});C(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new b.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=e,this._parameters=s,this.three=new b.WebGLRenderer({antialias:!0,alpha:!0,...s}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const n=this.three.getContext(),{canvas:r}=n;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,e=this.currentWorld.camera.three;this.three.render(t,e),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new b.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
|
|
5
|
+
- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};C(Lt,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),C(Lt,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let Kt=Lt;class ic extends mt{constructor(t,e){super(t);C(this,"onDisposed",new q);C(this,"onVertexFound",new q);C(this,"onVertexLost",new q);C(this,"onEnabled",new q);C(this,"components");C(this,"workingPlane",null);C(this,"_pickedPoint",null);C(this,"_config");C(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...e},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const n=this.components.get(ve).get(t).castRay();if(!n)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const r=this.getClosestVertex(n);return r?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(r))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(r))&&(this._pickedPoint=r.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let e=new b.Vector3,s=!1,n=Number.MAX_SAFE_INTEGER;const r=this.getVertices(t);if(r===null)return null;for(const o of r){if(!o)continue;const a=t.point.distanceTo(o);a>n||a>this._config.snapDistance||(s=!0,e=o,n=t.point.distanceTo(o))}return s?e:this.config.showOnlyVertex?null:t.point}getVertices(t){const e=t.object;if(!t.face||!e)return null;const s=e.geometry,n=new b.Matrix4,{instanceId:r}=t,o=r!==void 0,a=e instanceof b.InstancedMesh;return a&&o&&e.getMatrixAt(r,n),[this.getVertex(t.face.a,s),this.getVertex(t.face.b,s),this.getVertex(t.face.c,s)].map(l=>(l&&(a&&o&&l.applyMatrix4(n),l.applyMatrix4(e.matrixWorld)),l))}getVertex(t,e){if(t===void 0)return null;const s=e.attributes.position;return new b.Vector3(s.getX(t),s.getY(t),s.getZ(t))}}const Rs=class Rs{constructor(){C(this,"onDisposed",new q);C(this,"list",new Map);C(this,"enabled",!1);C(this,"_clock");C(this,"onInit",new q);C(this,"update",()=>{if(!this.enabled)return;const i=this._clock.getDelta();for(const[t,e]of this.list)e.enabled&&e.isUpdateable()&&e.update(i);requestAnimationFrame(this.update)});this._clock=new b.Clock,Rs.setupBVH()}add(i,t){if(this.list.has(i))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");Kt.validate(i),this.list.set(i,t)}get(i){const t=i.uuid;if(!this.list.has(t)){const e=new i(this);return this.list.has(t)||this.add(t,e),e}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update(),this.onInit.trigger()}dispose(){this.enabled=!1;for(const[i,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){b.BufferGeometry.prototype.computeBoundsTree=Ha,b.BufferGeometry.prototype.disposeBoundsTree=Wa,b.Mesh.prototype.raycast=ka}};C(Rs,"release","2.4.0-alpha.1");let Li=Rs;class Hr extends Vs{constructor(){super(...arguments);C(this,"meshes",new Set);C(this,"onAfterUpdate",new q);C(this,"onBeforeUpdate",new q);C(this,"onDisposed",new q);C(this,"isDisposing",!1);C(this,"enabled",!0);C(this,"uuid",Kt.create());C(this,"name");C(this,"_scene");C(this,"_camera");C(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const s=this.components.get(Ce);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const n of this.meshes)s.destroy(n);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.components.get(Pi).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class ye{constructor(i,t,e,s){C(this,"_component");C(this,"name");C(this,"uuid");this._component=i,this.name=e,this.uuid=s??Kt.create(),t.get(Ne).list.set(this.uuid,this)}get controls(){const i={};for(const t in this._config){const e=this._config[t];i[t]=this.copyEntry(e)}return i}copyEntry(i){if(i.type==="Boolean"){const t=i;return{type:t.type,value:t.value}}if(i.type==="Color"){const t=i;return{type:t.type,value:t.value.clone()}}if(i.type==="Text"){const t=i;return{type:t.type,value:t.value}}if(i.type==="Number"){const t=i;return{type:t.type,value:t.value,min:t.min,max:t.max,interpolable:t.interpolable}}if(i.type==="Select"){const t=i;return{type:t.type,value:t.value,multiple:t.multiple,options:new Set(t.options)}}if(i.type==="Vector3"){const t=i;return{type:t.type,value:t.value.clone()}}if(i.type==="TextSet"){const t=i;return{type:t.type,value:new Set(t.value)}}if(i.type==="None"){const t=i;return{type:t.type,value:t.value}}throw new Error("Invalid entry!")}}const gs=class gs extends mt{constructor(t){super(t);C(this,"list",new Qt);C(this,"enabled",!0);t.add(gs.uuid,this)}};C(gs,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let Ne=gs;class sc{constructor(i,t){C(this,"_list");C(this,"_scene");this._list=i,this._scene=t}get color(){return this._list.directionalLight.color.value}set color(i){this._list.directionalLight.color.value=i;for(const[,t]of this._scene.directionalLights)t.color.copy(i)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(i){this._list.directionalLight.intensity.value=i;for(const[,t]of this._scene.directionalLights)t.intensity=i}get position(){return this._list.directionalLight.position.value.clone()}set position(i){this._list.directionalLight.position.value=i;for(const[,t]of this._scene.directionalLights)t.position.copy(i)}}class nc{constructor(i,t){C(this,"_list");C(this,"_scene");this._list=i,this._scene=t}get color(){return this._list.ambientLight.color.value}set color(i){this._list.ambientLight.color.value=i;for(const[,t]of this._scene.ambientLights)t.color.copy(i)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(i){this._list.ambientLight.intensity.value=i;for(const[,t]of this._scene.ambientLights)t.intensity=i}}class Wr extends ye{constructor(){super(...arguments);C(this,"_config",{backgroundColor:{value:new b.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new b.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new b.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new b.Vector3}}});C(this,"ambientLight",new nc(this._config,this._component));C(this,"directionalLight",new sc(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(t){this._config.backgroundColor.value=t,this._component.three.background=t}}class Xr extends zr{constructor(t){super(t);C(this,"onSetup",new q);C(this,"isSetup",!1);C(this,"three");C(this,"config",new Wr(this,this.components,"Scene"));C(this,"_defaultConfig",{backgroundColor:new b.Color(2107698),directionalLight:{color:new b.Color("white"),intensity:1.5,position:new b.Vector3(5,10,3)},ambientLight:{color:new b.Color("white"),intensity:1}});this.three=new b.Scene,this.three.background=new b.Color(2107698)}setup(t){const e={...this._defaultConfig,...t};this.config.backgroundColor=e.backgroundColor;const s=e.ambientLight;this.config.ambientLight.color=s.color,this.config.ambientLight.intensity=s.intensity;const n=e.directionalLight;this.config.directionalLight.color=n.color,this.config.directionalLight.intensity=n.intensity,this.config.directionalLight.position=n.position,this.deleteAllLights();const{color:r,intensity:o}=this.config.directionalLight,a=new b.DirectionalLight(r,o);a.position.copy(n.position);const{color:l,intensity:h}=this.config.directionalLight,f=new b.AmbientLight(l,h);this.three.add(a,f),this.directionalLights.set(a.uuid,a),this.ambientLights.set(f.uuid,f),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose(),this.components.get(Ne).list.delete(this.config.uuid)}}class rc extends Gr{constructor(t,e,s){super(t);C(this,"enabled",!0);C(this,"container");C(this,"three");C(this,"_canvas");C(this,"_parameters");C(this,"_resizeObserver",null);C(this,"onContainerUpdated",new q);C(this,"_resizing",!1);C(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,s=t?t.y:this.container.clientHeight;this.three.setSize(e,s),this.onResize.trigger(new b.Vector2(e,s)),this._resizing=!1});C(this,"resizeEvent",()=>{this.resize()});C(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});C(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new b.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=e,this._parameters=s,this.three=new b.WebGLRenderer({antialias:!0,alpha:!0,...s}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const n=this.three.getContext(),{canvas:r}=n;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,e=this.currentWorld.camera.three;this.three.render(t,e),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new b.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
|
|
6
6
|
* camera-controls
|
|
7
7
|
* https://github.com/yomotsu/camera-controls
|
|
8
8
|
* (c) 2017 @yomotsu
|
package/dist/index.mjs
CHANGED