@combos-fun/plugin-renderer-3d 0.1.24 → 0.1.26
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/plugin-renderer-3d.cjs.js +51 -2
- package/dist/plugin-renderer-3d.cjs.js.map +1 -1
- package/dist/plugin-renderer-3d.cjs.prod.js +1 -1
- package/dist/plugin-renderer-3d.d.ts +1 -0
- package/dist/plugin-renderer-3d.esm.js +52 -3
- package/dist/plugin-renderer-3d.esm.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("@combos-fun/engine"),o=require("three"),r=require("@combos-fun/inspector-decorator"),s=require("three/addons/loaders/KTX2Loader.js");const i="combosGameObjectId",n="combosTransform3D";function a(e){return!!e?.userData?.[n]}function c(e,t){e.traverse(e=>{e.userData[i]=t})}function p(e){let t=e;for(;t;){const e=t.userData?.[i];if("number"==typeof e)return e;t=t.parent}}function d(e){if(!e)return!0;const t=e.parent;return!t||t===e.scene}function h(e){return{positionX:e.positionX??0,positionY:e.positionY??0,positionZ:e.positionZ??0,rotationX:e.rotationX??0,rotationY:e.rotationY??0,rotationZ:e.rotationZ??0,scaleX:e.scaleX??1,scaleY:e.scaleY??1,scaleZ:e.scaleZ??1}}function l(e){const t=h(e);return[t.positionX,t.positionY,t.positionZ,t.rotationX,t.rotationY,t.rotationZ,t.scaleX,t.scaleY,t.scaleZ].join(",")}function m(e,t){const o=h(e);t.positionX=o.positionX,t.positionY=o.positionY,t.positionZ=o.positionZ,t.rotationX=o.rotationX,t.rotationY=o.rotationY,t.rotationZ=o.rotationZ,t.scaleX=o.scaleX,t.scaleY=o.scaleY,t.scaleZ=o.scaleZ}function u(e){const t=h(e);return 0===t.positionX&&0===t.positionY&&0===t.positionZ&&0===t.rotationX&&0===t.rotationY&&0===t.rotationZ&&1===t.scaleX&&1===t.scaleY&&1===t.scaleZ}function g(e,t){u(t)&&!u(e)&&m(e,t)}const f={none:o.NoToneMapping,aces:o.ACESFilmicToneMapping,linear:o.LinearToneMapping,reinhard:o.ReinhardToneMapping,cineon:o.CineonToneMapping},y=new o.Vector3,b=new o.Euler;class C{constructor(e){this.mixers=new Map,this.models=new Map,this.nodes=new Map,this.defaultLights=[];const{canvas:t,container:r,width:s,height:i,antialias:n=!0,backgroundColor:a=0,backgroundAlpha:c=1}=e;this.scene=new o.Scene,this.shadows=!!e.shadows,this.camera=new o.PerspectiveCamera(75,s/i,.1,1e3),this.camera.position.z=5,this.fallbackCamera=this.camera;const p=e.pixelRatio??1;this.width=s,this.height=i,this.pixelRatio=p;const d={antialias:n,powerPreference:e.powerPreference??"high-performance"};t&&(d.canvas=t),c<1&&(d.alpha=!0),this.renderer=new o.WebGLRenderer(d),this.renderer.setPixelRatio(1),this.renderer.setSize(Math.max(1,Math.round(s*p)),Math.max(1,Math.round(i*p)),!1),this.renderer.domElement.style.width="",this.renderer.domElement.style.height="",this.renderer.setClearColor(a,c),this.renderer.toneMapping=f[e.toneMapping??"aces"]??o.ACESFilmicToneMapping,this.renderer.toneMappingExposure=e.toneMappingExposure??1,this.anisotropy=function(e){const t=e.capabilities,o=t?.getMaxAnisotropy?.()??0;return o>1?Math.min(8,o):1}(this.renderer);const h=e.softShadows??p<2,l=e.shadowMapSize??(h?1024:512);this.shadows&&(this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=h?o.PCFSoftShadowMap:o.PCFShadowMap),!t&&r&&r.appendChild(this.renderer.domElement);const m=new o.AmbientLight(16777215,e.ambientIntensity??.6);this.scene.add(m),this.defaultLights.push(m);const u=new o.DirectionalLight(16777215,e.directionalIntensity??.8);if(u.position.set(5,10,7.5),this.shadows&&(u.castShadow=!0,u.shadow.mapSize.set(l,l)),this.scene.add(u),this.defaultLights.push(u),!1!==e.hemisphereLight){const t="object"==typeof e.hemisphereLight?e.hemisphereLight:{},r=new o.HemisphereLight(t.skyColor??16777215,t.groundColor??4473924,t.intensity??.35);this.scene.add(r),this.defaultLights.push(r)}if(e.fog){const t="object"==typeof e.fog?e.fog:{};this.scene.fog=new o.Fog(t.color??a,t.near??8,t.far??40)}this.clock=new o.Clock}update(e){const t=this.clock.getDelta();if(!e?.skipDraw){for(const e of this.mixers.values())e.update(t);this.renderer.render(this.scene,this.camera)}}setPixelRatio(e){e>0&&e!==this.pixelRatio&&(this.pixelRatio=e)}presentBuffer(e,t){if(!(e>=1&&t>=1))return;this.renderer.setDrawingBufferSize(e,t,1);const o=this.renderer.domElement;o.width===e&&o.height===t||(o.width=e,o.height=t),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.fallbackCamera!==this.camera&&(this.fallbackCamera.aspect=e/t,this.fallbackCamera.updateProjectionMatrix())}configureTexture(e){!e?.isTexture||this.anisotropy<=1||e.anisotropy!==this.anisotropy&&(e.anisotropy=this.anisotropy,e.needsUpdate=!0)}configureObject(e){!e||this.anisotropy<=1||e.traverse(e=>{const t=e;if(!t.isMesh||!t.material)return;const o=Array.isArray(t.material)?t.material:[t.material];for(const e of o)v(e,e=>this.configureTexture(e))})}hasTransform3DRoot(e){return a(this.nodes.get(e))}applyModelShadows(e){this.shadows&&e.traverse(e=>{const t=e;t.isMesh&&(t.castShadow=!0,t.receiveShadow=!0)})}attachParsedModel(e,t,r,s){if(c(t,e),this.applyModelShadows(t),this.models.set(e,t),this.attachVisual(e,t,s),r&&r.length>0){const s=new o.AnimationMixer(t);this.mixers.set(e,s),t.userData.animations=r}return t}object3DFor(e){return this.nodes.get(e)}attachObject3D(e,t,o){const r=this.nodes.get(e);r&&r!==t&&(this.rehomeRegisteredChildren(r),r.parent?.remove(r)),this.nodes.set(e,t);const s=this.findParentNode(o);t.parent!==s&&s.add(t),o&&this.adoptChildGameObjects(o,t)}attachVisual(e,t,o){c(t,e),this.configureObject(t);const r=this.nodes.get(e);a(r)&&r!==t?t.parent!==r&&r.add(t):this.attachObject3D(e,t,o)}detachVisual(e,t){const o=this.nodes.get(e);return a(o)&&o!==t?(t.parent?.remove(t),t):o===t?this.detachObject3D(e):(t.parent?.remove(t),t)}detachObject3D(e){const t=this.nodes.get(e);if(t)return this.rehomeRegisteredChildren(t),t.parent?.remove(t),this.nodes.delete(e),t}reparentGameObject(e){const t=this.nodes.get(e.id);if(!t)return;const o=this.findParentNode(e);t.parent!==o&&o.add(t)}findParentNode(e){if(!e||d(e))return this.scene;let t=e.parent;for(;t&&t!==e.scene;){const e=this.nodes.get(t.id);if(e)return e;t=t.parent}return this.scene}adoptChildGameObjects(e,t){const o=e.children;if(o)for(const e of o){if(!e)continue;const o=this.nodes.get(e.id);o&&o.parent!==t&&t.add(o)}}ensureTransformRoot(e,t){const r=this.nodes.get(e.id);if(a(r))return this.applyTransformPose(r,t),r;const s=new o.Group;if(s.name=e.name,s.userData[n]=!0,c(s,e.id),r&&r!==s){(function(e){const t=h(e);return 0===t.positionX&&0===t.positionY&&0===t.positionZ&&0===t.rotationX&&0===t.rotationY&&0===t.rotationZ&&1===t.scaleX&&1===t.scaleY&&1===t.scaleZ})(t)&&(t.positionX=r.position.x,t.positionY=r.position.y,t.positionZ=r.position.z,t.rotationX=r.rotation.x,t.rotationY=r.rotation.y,t.rotationZ=r.rotation.z,t.scaleX=r.scale.x,t.scaleY=r.scale.y,t.scaleZ=r.scale.z);(r.parent||this.scene).add(s),s.add(r),r.position.set(0,0,0),r.rotation.set(0,0,0),r.scale.set(1,1,1),this.nodes.set(e.id,s),this.adoptChildGameObjects(e,s)}else this.attachObject3D(e.id,s,e);return this.applyTransformPose(s,t),s}applyTransform3D(e,t){const o=this.ensureTransformRoot(e,t);return this.applyTransformPose(o,t),o.updateWorldMatrix(!0,!1),o.getWorldPosition(y),t.worldPositionX=y.x,t.worldPositionY=y.y,t.worldPositionZ=y.z,b.setFromRotationMatrix(o.matrixWorld),t.worldRotationX=b.x,t.worldRotationY=b.y,t.worldRotationZ=b.z,o}applyTransformPose(e,t){const o=h(t);e.position.set(o.positionX,o.positionY,o.positionZ),e.rotation.set(o.rotationX,o.rotationY,o.rotationZ),e.scale.set(o.scaleX,o.scaleY,o.scaleZ)}removeDefaultLights(){if(this.defaultLights.length){for(const e of this.defaultLights)e.parent?.remove(e),e.dispose?.();this.defaultLights=[]}}setActiveCamera(e){const t=this.camera;this.camera=e,t&&(e.aspect=t.aspect),e.updateProjectionMatrix()}restoreFallbackCamera(){this.camera!==this.fallbackCamera&&this.setActiveCamera(this.fallbackCamera)}rehomeRegisteredChildren(e){for(const t of[...e.children]){const e=t.userData?.[i];"number"==typeof e&&this.nodes.get(e)===t&&this.scene.add(t)}}playAnimation(e,t,o){const r=this.mixers.get(e),s=this.models.get(e);if(!r||!s)return;r.stopAllAction();const i=s.userData.animations;if(i&&i[t]){const e=r.clipAction(i[t]);e.timeScale=o,e.play()}}stopAnimation(e){const t=this.mixers.get(e);t&&t.stopAllAction()}removeModel(e){const t=this.models.get(e);t&&(this.detachVisual(e,t),t.traverse(e=>{const t=e;if(t.geometry&&t.geometry.dispose(),t.material){(Array.isArray(t.material)?t.material:[t.material]).forEach(e=>e.dispose())}}),this.models.delete(e));const o=this.mixers.get(e);o&&(o.stopAllAction(),this.mixers.delete(e))}resize(e,t){this.width=e,this.height=t,this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.fallbackCamera!==this.camera&&(this.fallbackCamera.aspect=e/t,this.fallbackCamera.updateProjectionMatrix()),this.renderer.setSize(e,t,!1)}destroy(){for(const e of this.models.keys())this.removeModel(e);this.removeDefaultLights(),this.renderer.dispose(),this.renderer.domElement.remove(),this.nodes.clear(),this.scene=null,this.camera=null,this.fallbackCamera=null,this.renderer=null,this.clock=null}}const x=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap"];function v(e,t){const o=e;for(const e of x){const r=o[e];r?.isTexture&&t(r)}}class D{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this,t.threeContext=this.rendererSystem.threeContext,this.renderers.push(t)}componentChanged(e){for(const o of e)for(const e of this.renderers){const r=e.observerInfo[o.componentName];if(!r)continue;if(o.type===t.OBSERVER_TYPE.ADD||o.type===t.OBSERVER_TYPE.REMOVE){try{e.componentChanged(o)}catch(e){console.error(`gameObject: ${o.gameObject.name}, ${o.componentName} error.`,o,e)}continue}if(r.findIndex(e=>"string"==typeof e&&"string"==typeof o.prop?e===o.prop:JSON.stringify(e)===JSON.stringify(o.prop))>-1)try{e.componentChanged(o)}catch(e){console.error(`gameObject: ${o.gameObject?.name}, ${o.componentName} componentChanged error.`,o,e)}}}update(e){for(const t of e.components)for(const o of this.renderers){if(o.observerInfo[t.name])try{o.rendererUpdate(e)}catch(o){console.info(`gameObject: ${e.name}, ${t.name} update error`,o)}}}}class w extends t.Component{constructor(){super(...arguments),this.positionX=0,this.positionY=0,this.positionZ=0,this.rotationX=0,this.rotationY=0,this.rotationZ=0,this.scaleX=1,this.scaleY=1,this.scaleZ=1,this.worldPositionX=0,this.worldPositionY=0,this.worldPositionZ=0,this.worldRotationX=0,this.worldRotationY=0,this.worldRotationZ=0}static{this.componentName="Transform3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"positionX",description:"Local X position.",editor:"number-stepper"})],w.prototype,"positionX",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"positionY",description:"Local Y position.",editor:"number-stepper"})],w.prototype,"positionY",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"positionZ",description:"Local Z position.",editor:"number-stepper"})],w.prototype,"positionZ",void 0),e.__decorate([r.Field({type:"number",step:.01,group:"Transform3D",label:"rotationX",description:"Rotation around X in radians.",editor:"number-stepper"})],w.prototype,"rotationX",void 0),e.__decorate([r.Field({type:"number",step:.01,group:"Transform3D",label:"rotationY",description:"Rotation around Y in radians.",editor:"number-stepper"})],w.prototype,"rotationY",void 0),e.__decorate([r.Field({type:"number",step:.01,group:"Transform3D",label:"rotationZ",description:"Rotation around Z in radians.",editor:"number-stepper"})],w.prototype,"rotationZ",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"scaleX",description:"Scale on X.",editor:"number-stepper"})],w.prototype,"scaleX",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"scaleY",description:"Scale on Y.",editor:"number-stepper"})],w.prototype,"scaleY",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Transform3D",label:"scaleZ",description:"Scale on Z.",editor:"number-stepper"})],w.prototype,"scaleZ",void 0);let R=class extends t.System{constructor(){super(...arguments),this.name="Renderer3DSystem",this.adaptive=null,this.pauseWhenHidden=!0,this.resolution=1,this.resizeObserver=null}static{this.systemName="Renderer3DSystem"}init(e){const o=e||{},r=o.width||750,s=o.height||1334,i=t.resolveRenderQuality(o,{adaptivePixelRatio:!1});this.resolution=i.pixelRatio,this.pauseWhenHidden=i.pauseWhenHidden,this.adaptive=new t.AdaptivePixelRatio({pixelRatio:i.pixelRatio,ceiling:i.pixelRatioCeiling,enabled:i.adaptivePixelRatio}),this.threeContext=new C({canvas:o.canvas,container:o.container,width:r,height:s,antialias:i.antialias,pixelRatio:i.pixelRatio,powerPreference:i.powerPreference,softShadows:o.softShadows,shadowMapSize:o.shadowMapSize,backgroundColor:o.backgroundColor,backgroundAlpha:o.backgroundAlpha,fog:o.fog,hemisphereLight:o.hemisphereLight,shadows:o.shadows,toneMapping:o.toneMapping,toneMappingExposure:o.toneMappingExposure,ambientIntensity:o.ambientIntensity,directionalIntensity:o.directionalIntensity}),this.game.canvas=this.threeContext.renderer.domElement,this.observeCanvas(this.game.canvas),this.rendererManager=new D({game:this.game,rendererSystem:this})}update(e){const t=this.componentObserver.clear();for(const e of t)this.handleHierarchyChange(e);for(const e of this.game.gameObjects){const t=e.getComponent(w);t&&this.threeContext.applyTransform3D(e,t),this.rendererManager.update(e)}}handleHierarchyChange(e){"GameObject"===e.componentName&&(e.type!==t.OBSERVER_TYPE.CHANGE&&e.type!==t.OBSERVER_TYPE.ADD||(this.ensureTransform3D(e.gameObject),e.gameObject.parent&&this.ensureTransform3D(e.gameObject.parent),this.threeContext?.reparentGameObject(e.gameObject)))}ensureTransform3D(e){if(!e||e.destroyed||e===e.scene)return;let t=e.getComponent(w);(t||(t=new w,e.addComponent(t)))&&this.threeContext?.ensureTransformRoot(e,t)}lateUpdate(e){if(!this.threeContext)return;if(t.shouldPauseRendering(this.pauseWhenHidden))return void this.threeContext.update({skipDraw:!0});const o=this.adaptive?.sample(e?.deltaTime??0);null!=o&&(this.resolution=o,this.threeContext.pixelRatio=o,this.applyDisplay()),this.threeContext.update()}resize(e,t){this.applyDisplay()}observeCanvas(e){this.resizeObserver?.disconnect(),"undefined"!=typeof ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.applyDisplay()),this.resizeObserver.observe(e)),this.applyDisplay()}applyDisplay(){const e=this.threeContext?.renderer?.domElement;if(!e||"function"!=typeof e.getBoundingClientRect)return;const o=e.getBoundingClientRect(),r=t.displayBufferSize(o,this.resolution);if(!r)return;const s=e.width,i=e.height;if(s===r.bufferWidth&&i===r.bufferHeight){const e=r.bufferWidth/r.bufferHeight;if(Math.abs(this.threeContext.camera.aspect-e)<1e-6)return}this.threeContext.presentBuffer(r.bufferWidth,r.bufferHeight)}onDestroy(){this.resizeObserver?.disconnect(),this.resizeObserver=null,this.threeContext?.destroy(),this.threeContext=null}};R=e.__decorate([t.decorators.componentObserver({GameObject:["parent"]})],R);var O=R;Object.assign(O,{packageName:"@combos-fun/plugin-renderer-3d",packageVersion:"0.1.24"});class _ extends t.System{constructor(e){super(e),this.asyncIdMap={};const t=this.constructor;this.observerInfo=t.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}const S=new Set(["positionX","positionY","positionZ","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"]);let M=class extends _{constructor(){super(...arguments),this.name="Transform3DSystem"}static{this.systemName="Transform3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("GameObject"===e.componentName)return this.ensureOn(e.gameObject),e.gameObject.parent&&this.ensureOn(e.gameObject.parent),void this.threeContext.reparentGameObject(e.gameObject);"Transform3D"===e.componentName&&(e.type===t.OBSERVER_TYPE.ADD?this.threeContext.ensureTransformRoot(e.gameObject,e.component):e.type===t.OBSERVER_TYPE.REMOVE?this.threeContext.detachObject3D(e.gameObject.id):S.has(e.prop?.prop?.[0])&&this.threeContext.applyTransform3D(e.gameObject,e.component))}rendererUpdate(e){const t=e.getComponent(w);t&&this.threeContext.applyTransform3D(e,t)}ensureOn(e){if(!e||e.destroyed||e===e.scene)return;let t=e.getComponent(w);(t||(t=new w,e.addComponent(t)))&&this.threeContext.ensureTransformRoot(e,t)}};M=e.__decorate([t.decorators.componentObserver({Transform3D:["positionX","positionY","positionZ","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"],GameObject:["parent"]})],M);var T=M;class E extends t.Component{constructor(){super(...arguments),this.visible=!0,this.opacity=1,this.renderOrder=0,this.sortableChildren=!1}static{this.componentName="Render3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([r.Field({type:"boolean",group:"Render3D",label:"visible",description:"Whether this object is drawn.",editor:"toggle"})],E.prototype,"visible",void 0),e.__decorate([r.Field({type:"number",step:.01,min:0,max:1,group:"Render3D",label:"opacity",description:"Opacity from 0 to 1.",editor:"number-slider"})],E.prototype,"opacity",void 0),e.__decorate([r.Field({type:"number",step:1,group:"Render3D",label:"renderOrder",description:"Draw order; higher values render on top.",editor:"number-stepper"})],E.prototype,"renderOrder",void 0),e.__decorate([r.Field({type:"boolean",group:"Render3D",label:"sortableChildren",description:"When on, children are sorted by their render order before drawing.",editor:"toggle"})],E.prototype,"sortableChildren",void 0);let j=class extends _{constructor(){super(...arguments),this.name="Render3DSystem"}static{this.systemName="Render3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Render3D"===e.componentName){if(e.type===t.OBSERVER_TYPE.REMOVE){const t=this.threeContext.object3DFor(e.gameObject.id);return void(t&&this.apply(t,{visible:!0,opacity:1,renderOrder:0,sortableChildren:!1}))}this.applyTo(e.gameObject,e.component)}}rendererUpdate(e){const t=e.getComponent(E);t&&this.applyTo(e,t)}applyTo(e,t){const o=this.threeContext.object3DFor(e.id);o&&(this.apply(o,t),t.sortableChildren&&this.sortChildren(e,o))}apply(e,t){e.visible=t.visible,e.traverse(e=>{e.renderOrder=t.renderOrder;const o=e;if(!o.isMesh||!o.material)return;const r=Array.isArray(o.material)?o.material:[o.material];for(const e of r){const o=e;"number"==typeof o.opacity&&(o.opacity=t.opacity,o.transparent=t.opacity<1)}})}sortChildren(e,t){const o=e.children?.map(e=>{if(!e)return null;const o=this.threeContext.object3DFor(e.id);if(!o||o.parent!==t)return null;const r=e.getComponent(E);return{node:o,order:r?.renderOrder??0}}).filter(e=>!!e).sort((e,t)=>e.order-t.order);if(o?.length)for(const e of o)t.add(e.node)}};j=e.__decorate([t.decorators.componentObserver({Render3D:["visible","opacity","renderOrder","sortableChildren"]})],j);var A=j;class Y extends t.Component{constructor(){super(...arguments),this.fov=75,this.near=.1,this.far=1e3,this.active=!0,this.lookAt=!1,this.lookAtX=0,this.lookAtY=0,this.lookAtZ=0}static{this.componentName="Camera3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([r.Field({type:"number",step:1,group:"Camera3D",label:"fov",description:"Vertical field of view in degrees.",editor:"number-stepper"})],Y.prototype,"fov",void 0),e.__decorate([r.Field({type:"number",step:.01,group:"Camera3D",label:"near",description:"Near clipping plane.",editor:"number-stepper"})],Y.prototype,"near",void 0),e.__decorate([r.Field({type:"number",step:1,group:"Camera3D",label:"far",description:"Far clipping plane.",editor:"number-stepper"})],Y.prototype,"far",void 0),e.__decorate([r.Field({type:"boolean",group:"Camera3D",label:"active",description:"Use this camera for rendering.",editor:"toggle"})],Y.prototype,"active",void 0),e.__decorate([r.Field({type:"boolean",group:"Camera3D",label:"lookAt",description:"Point the camera at lookAtX/Y/Z each frame.",editor:"toggle"})],Y.prototype,"lookAt",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtX",description:"World-space look-at target on X.",editor:"number-stepper"})],Y.prototype,"lookAtX",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtY",description:"World-space look-at target on Y.",editor:"number-stepper"})],Y.prototype,"lookAtY",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtZ",description:"World-space look-at target on Z.",editor:"number-stepper"})],Y.prototype,"lookAtZ",void 0);let L=class extends _{constructor(){super(...arguments),this.name="Camera3DSystem",this.cameras=new Map}static{this.systemName="Camera3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Camera3D"!==e.componentName)return;const o=e.component;e.type===t.OBSERVER_TYPE.ADD?this.mount(e.gameObject,o):e.type===t.OBSERVER_TYPE.REMOVE?this.unmount(e.gameObject.id):this.sync(e.gameObject,o)}rendererUpdate(e){const t=e.getComponent(Y),o=this.cameras.get(e.id);t&&o&&t.lookAt&&o.lookAt(t.lookAtX,t.lookAtY,t.lookAtZ)}mount(e,t){this.ensureTransform(e);const r=new o.PerspectiveCamera(t.fov,this.threeContext.camera.aspect,t.near,t.far);this.threeContext.attachVisual(e.id,r,e),this.cameras.set(e.id,r),this.sync(e,t)}sync(e,t){const o=this.cameras.get(e.id);o&&(o.fov=t.fov,o.near=t.near,o.far=t.far,o.updateProjectionMatrix(),t.active?this.threeContext.setActiveCamera(o):this.threeContext.camera===o&&this.activateAnother(e.id))}unmount(e){const t=this.cameras.get(e);t&&(this.threeContext.detachVisual(e,t),this.cameras.delete(e),this.threeContext.camera===t&&this.activateAnother(e))}activateAnother(e){for(const[t,o]of this.cameras){if(t===e)continue;const r=this.game.gameObjects.find(e=>e.id===t),s=r?.getComponent(Y);if(s?.active)return void this.threeContext.setActiveCamera(o)}this.threeContext.restoreFallbackCamera()}ensureTransform(e){if(!e||e.destroyed)return;let t=e.getComponent(w);if(!t)return t=new w,t.positionZ=5,void e.addComponent(t);u(t)&&(t.positionZ=5)}onDestroy(){for(const[e]of this.cameras)this.unmount(e);this.cameras.clear()}};L=e.__decorate([t.decorators.componentObserver({Camera3D:["fov","near","far","active","lookAt","lookAtX","lookAtY","lookAtZ"]})],L);var k=L;class P extends t.Component{constructor(){super(...arguments),this.type="directional",this.color=16777215,this.intensity=1,this.castShadow=!1,this.skyColor=16777215,this.groundColor=4473924,this.distance=0,this.decay=2,this.angle=Math.PI/3,this.penumbra=0}static{this.componentName="Light3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([r.Field({type:"string",group:"Light3D",label:"type",description:"Light kind.",editor:"enum",enumOptions:["ambient","directional","hemisphere","point","spot"]})],P.prototype,"type",void 0),e.__decorate([r.Field({type:"number",group:"Light3D",label:"color",description:"Light color (hex).",editor:"number-stepper"})],P.prototype,"color",void 0),e.__decorate([r.Field({type:"number",step:.05,group:"Light3D",label:"intensity",description:"Light intensity.",editor:"number-stepper"})],P.prototype,"intensity",void 0),e.__decorate([r.Field({type:"boolean",group:"Light3D",label:"castShadow",description:"Whether this light casts shadows.",editor:"toggle"})],P.prototype,"castShadow",void 0),e.__decorate([r.Field({type:"number",group:"Light3D",label:"skyColor",description:"Hemisphere sky color (hex).",editor:"number-stepper"})],P.prototype,"skyColor",void 0),e.__decorate([r.Field({type:"number",group:"Light3D",label:"groundColor",description:"Hemisphere ground color (hex).",editor:"number-stepper"})],P.prototype,"groundColor",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Light3D",label:"distance",description:"Range for point and spot lights. 0 means no limit.",editor:"number-stepper"})],P.prototype,"distance",void 0),e.__decorate([r.Field({type:"number",step:.1,group:"Light3D",label:"decay",description:"Intensity falloff for point and spot lights.",editor:"number-stepper"})],P.prototype,"decay",void 0),e.__decorate([r.Field({type:"number",step:.01,group:"Light3D",label:"angle",description:"Spot light cone angle in radians.",editor:"number-stepper"})],P.prototype,"angle",void 0),e.__decorate([r.Field({type:"number",step:.01,min:0,max:1,group:"Light3D",label:"penumbra",description:"Spot light soft edge (0–1).",editor:"number-slider"})],P.prototype,"penumbra",void 0);let X=class extends _{constructor(){super(...arguments),this.name="Light3DSystem",this.lights=new Map}static{this.systemName="Light3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Light3D"!==e.componentName)return;const o=e.component;e.type===t.OBSERVER_TYPE.ADD?this.mount(e.gameObject,o):e.type===t.OBSERVER_TYPE.REMOVE?this.unmount(e.gameObject.id):"type"===e.prop?.prop?.[0]?(this.unmount(e.gameObject.id),this.mount(e.gameObject,o)):this.sync(e.gameObject.id,o)}rendererUpdate(e){}mount(e,t){this.ensureTransform(e),0===this.lights.size&&this.threeContext.removeDefaultLights();const o=this.createLight(t);this.threeContext.attachVisual(e.id,o,e),this.lights.set(e.id,o),this.sync(e.id,t)}createLight(e){switch(e.type){case"ambient":return new o.AmbientLight(e.color,e.intensity);case"hemisphere":return new o.HemisphereLight(e.skyColor,e.groundColor,e.intensity);case"point":return new o.PointLight(e.color,e.intensity,e.distance,e.decay);case"spot":return new o.SpotLight(e.color,e.intensity,e.distance,e.angle,e.penumbra,e.decay);default:return new o.DirectionalLight(e.color,e.intensity)}}sync(e,t){const r=this.lights.get(e);r&&("color"in r&&r.color&&r.color.set(t.color),r.intensity=t.intensity,r instanceof o.HemisphereLight&&(r.color.set(t.skyColor),r.groundColor.set(t.groundColor)),(r instanceof o.PointLight||r instanceof o.SpotLight)&&(r.distance=t.distance,r.decay=t.decay),r instanceof o.SpotLight&&(r.angle=t.angle,r.penumbra=t.penumbra),"castShadow"in r&&(r.castShadow=!(!t.castShadow||!this.threeContext.shadows)))}unmount(e){const t=this.lights.get(e);t&&(this.threeContext.detachVisual(e,t),t.dispose?.(),this.lights.delete(e))}ensureTransform(e){e&&!e.destroyed&&(e.getComponent(w)||e.addComponent(new w))}onDestroy(){for(const[e]of this.lights)this.unmount(e);this.lights.clear()}};X=e.__decorate([t.decorators.componentObserver({Light3D:["type","color","intensity","castShadow","skyColor","groundColor","distance","decay","angle","penumbra"]})],X);var Z=X;const F=["WEBGL_compressed_texture_astc","EXT_texture_compression_bptc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_etc"];let I=null,B=null;function V(e){return F.some(t=>e.extensions.has(t))}function N(e){return I||(I=new s.KTX2Loader,I.setTranscoderPath("https://unpkg.com/three@0.172.0/examples/jsm/libs/basis/")),e&&B!==e&&(I.detectSupport(e),B=e),I}async function z(e,t){if(!V(t))return null;try{const r=await N(t).loadAsync(e),s=r;return s?.isCompressedTexture&&s.format!==o.RGBAFormat?r:(r?.dispose(),null)}catch{return null}}async function G(e){const o=String(e??"").trim();if(!o)throw new Error("resource name is required; register it with resource.addResource");const r=await t.resource.getResource(o);if(!r||!r.name)throw new Error(`Unknown resource "${o}"; register it with resource.addResource first`);return r}function U(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?e:null}async function W(e){let t=e;if("function"==typeof createImageBitmap)try{t=await createImageBitmap(e)}catch{t=e}const r=new o.Texture(t);if(r.colorSpace=o.SRGBColorSpace,r.needsUpdate=!0,"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=t,o=r.dispose.bind(r);r.dispose=()=>{o();try{e.close()}catch{}}}return r}async function H(e,o){if(!o)return null;const r=function(e){if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e)){const t=e;return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}return null}(e.data?.image);if(!r)return null;const s=t.compressedTextureUrl(e.src?.image),i=URL.createObjectURL(new Blob([r]));try{const e=await z(i,o);if(e)return e}finally{URL.revokeObjectURL(i)}return s?z(s,o):null}async function $(e,o){const r=await H(e,o);if(r)return r;const s=U(e.data?.image);if(s)return W(s);const i=t.imageFallbackUrl(e.src?.image);if(i)try{return W(await(n=i,new Promise((e,t)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>e(o),o.onerror=()=>t(new Error(`Failed to load image ${n}`)),o.src=n})))}catch{}var n;throw new Error(`Resource "${e.name}" has no image data; use RESOURCE_TYPE.IMAGE with src.image.url`)}exports.COMBOS_GAME_OBJECT_ID=i,exports.COMBOS_TRANSFORM3D=n,exports.Camera3D=Y,exports.Camera3DSystem=k,exports.Light3D=P,exports.Light3DSystem=Z,exports.Render3D=E,exports.Render3DSystem=A,exports.Renderer3D=_,exports.Renderer3DManager=D,exports.Renderer3DSystem=O,exports.ThreeContext=C,exports.Transform3D=w,exports.Transform3DSystem=T,exports.VisualPoseBridge=class{constructor(){this.lastVisual="",this.lastRoot=""}sync(e,t){if(!t)return!0;if(""===this.lastVisual&&""===this.lastRoot)return g(e,t),this.lastVisual=l(e),this.lastRoot=l(t),!1;const o=l(e),r=l(t);return o!==this.lastVisual&&r===this.lastRoot&&m(e,t),this.lastVisual=l(e),this.lastRoot=l(t),!1}},exports.copyPose=m,exports.ensureKtx2Loader=N,exports.gameObjectIdFromIntersection=function(e){return p(e?.object)},exports.gameObjectIdFromObject3D=p,exports.has3DChildGameObjects=function(e){return(e?.children?.length??0)>0},exports.is3DSceneParent=d,exports.isIdentityPose=u,exports.isTransform3DRoot=a,exports.loadThreeKtx2=z,exports.poseKeyOf=l,exports.readPose=h,exports.rendererSupportsCompressedTexture=V,exports.requireNamedResource=G,exports.seedTransform3D=g,exports.tagObject3D=c,exports.textureFromNamedImage=async function(e,t){return $(await G(e),t)},exports.textureFromResourceImage=function(e){const t=U(e.data?.image);if(!t)throw new Error(`Resource "${e.name}" has no image data; use RESOURCE_TYPE.IMAGE with src.image.url`);const r=new o.Texture(t);return r.colorSpace=o.SRGBColorSpace,r.needsUpdate=!0,r},exports.textureFromResourceImageAsync=$;
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("@combos-fun/engine"),r=require("three"),o=require("@combos-fun/inspector-decorator"),s=require("three/addons/loaders/KTX2Loader.js");const i="combosGameObjectId",n="combosTransform3D";function a(e){return!!e?.userData?.[n]}function c(e,t){e.traverse(e=>{e.userData[i]=t})}function p(e){let t=e;for(;t;){const e=t.userData?.[i];if("number"==typeof e)return e;t=t.parent}}function d(e){if(!e)return!0;const t=e.parent;return!t||t===e.scene}function h(e){return{positionX:e.positionX??0,positionY:e.positionY??0,positionZ:e.positionZ??0,rotationX:e.rotationX??0,rotationY:e.rotationY??0,rotationZ:e.rotationZ??0,scaleX:e.scaleX??1,scaleY:e.scaleY??1,scaleZ:e.scaleZ??1}}function l(e){const t=h(e);return[t.positionX,t.positionY,t.positionZ,t.rotationX,t.rotationY,t.rotationZ,t.scaleX,t.scaleY,t.scaleZ].join(",")}function m(e,t){const r=h(e);t.positionX=r.positionX,t.positionY=r.positionY,t.positionZ=r.positionZ,t.rotationX=r.rotationX,t.rotationY=r.rotationY,t.rotationZ=r.rotationZ,t.scaleX=r.scaleX,t.scaleY=r.scaleY,t.scaleZ=r.scaleZ}function u(e){const t=h(e);return 0===t.positionX&&0===t.positionY&&0===t.positionZ&&0===t.rotationX&&0===t.rotationY&&0===t.rotationZ&&1===t.scaleX&&1===t.scaleY&&1===t.scaleZ}function g(e,t){u(t)&&!u(e)&&m(e,t)}const f={none:r.NoToneMapping,aces:r.ACESFilmicToneMapping,linear:r.LinearToneMapping,reinhard:r.ReinhardToneMapping,cineon:r.CineonToneMapping},y=new r.Vector3,b=new r.Euler;class C{constructor(e){this.mixers=new Map,this.models=new Map,this.nodes=new Map,this.defaultLights=[];const{canvas:t,container:o,width:s,height:i,antialias:n=!0,backgroundColor:a=0,backgroundAlpha:c=1}=e;this.scene=new r.Scene,this.shadows=!!e.shadows,this.camera=new r.PerspectiveCamera(75,s/i,.1,1e3),this.camera.position.z=5,this.fallbackCamera=this.camera;const p=e.pixelRatio??1;this.width=s,this.height=i,this.pixelRatio=p;const d={antialias:n,powerPreference:e.powerPreference??"high-performance"};t&&(d.canvas=t),c<1&&(d.alpha=!0),this.renderer=new r.WebGLRenderer(d),this.renderer.setPixelRatio(1),this.renderer.setSize(Math.max(1,Math.round(s*p)),Math.max(1,Math.round(i*p)),!1),this.renderer.domElement.style.width="",this.renderer.domElement.style.height="",this.renderer.setClearColor(a,c),this.renderer.toneMapping=f[e.toneMapping??"aces"]??r.ACESFilmicToneMapping,this.renderer.toneMappingExposure=e.toneMappingExposure??1,this.anisotropy=function(e){const t=e.capabilities,r=t?.getMaxAnisotropy?.()??0;return r>1?Math.min(8,r):1}(this.renderer);const h=e.softShadows??p<2,l=e.shadowMapSize??(h?1024:512);this.shadows&&(this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=h?r.PCFSoftShadowMap:r.PCFShadowMap),!t&&o&&o.appendChild(this.renderer.domElement);const m=new r.AmbientLight(16777215,e.ambientIntensity??.6);this.scene.add(m),this.defaultLights.push(m);const u=new r.DirectionalLight(16777215,e.directionalIntensity??.8);if(u.position.set(5,10,7.5),this.shadows&&(u.castShadow=!0,u.shadow.mapSize.set(l,l)),this.scene.add(u),this.defaultLights.push(u),!1!==e.hemisphereLight){const t="object"==typeof e.hemisphereLight?e.hemisphereLight:{},o=new r.HemisphereLight(t.skyColor??16777215,t.groundColor??4473924,t.intensity??.35);this.scene.add(o),this.defaultLights.push(o)}if(e.fog){const t="object"==typeof e.fog?e.fog:{};this.scene.fog=new r.Fog(t.color??a,t.near??8,t.far??40)}this.clock=new r.Clock}update(e){const t=this.clock.getDelta();if(!e?.skipDraw){for(const e of this.mixers.values())e.update(t);this.renderer.render(this.scene,this.camera)}}setPixelRatio(e){e>0&&e!==this.pixelRatio&&(this.pixelRatio=e)}presentBuffer(e,t){if(!(e>=1&&t>=1))return;this.renderer.setDrawingBufferSize(e,t,1);const r=this.renderer.domElement;r.width===e&&r.height===t||(r.width=e,r.height=t),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.fallbackCamera!==this.camera&&(this.fallbackCamera.aspect=e/t,this.fallbackCamera.updateProjectionMatrix())}configureTexture(e){!e?.isTexture||this.anisotropy<=1||e.anisotropy!==this.anisotropy&&(e.anisotropy=this.anisotropy,e.needsUpdate=!0)}configureObject(e){!e||this.anisotropy<=1||e.traverse(e=>{const t=e;if(!t.isMesh||!t.material)return;const r=Array.isArray(t.material)?t.material:[t.material];for(const e of r)v(e,e=>this.configureTexture(e))})}hasTransform3DRoot(e){return a(this.nodes.get(e))}applyModelShadows(e){this.shadows&&e.traverse(e=>{const t=e;t.isMesh&&(t.castShadow=!0,t.receiveShadow=!0)})}attachParsedModel(e,t,o,s){if(c(t,e),this.applyModelShadows(t),this.models.set(e,t),this.attachVisual(e,t,s),o&&o.length>0){const s=new r.AnimationMixer(t);this.mixers.set(e,s),t.userData.animations=o}return t}object3DFor(e){return this.nodes.get(e)}attachObject3D(e,t,r){const o=this.nodes.get(e);o&&o!==t&&(this.rehomeRegisteredChildren(o),o.parent?.remove(o)),this.nodes.set(e,t);const s=this.findParentNode(r);t.parent!==s&&s.add(t),r&&this.adoptChildGameObjects(r,t)}attachVisual(e,t,r){c(t,e),this.configureObject(t);const o=this.nodes.get(e);a(o)&&o!==t?t.parent!==o&&o.add(t):this.attachObject3D(e,t,r)}detachVisual(e,t){const r=this.nodes.get(e);return a(r)&&r!==t?(t.parent?.remove(t),t):r===t?this.detachObject3D(e):(t.parent?.remove(t),t)}detachObject3D(e){const t=this.nodes.get(e);if(t)return this.rehomeRegisteredChildren(t),t.parent?.remove(t),this.nodes.delete(e),t}reparentGameObject(e){const t=this.nodes.get(e.id);if(!t)return;const r=this.findParentNode(e);t.parent!==r&&r.add(t)}findParentNode(e){if(!e||d(e))return this.scene;let t=e.parent;for(;t&&t!==e.scene;){const e=this.nodes.get(t.id);if(e)return e;t=t.parent}return this.scene}adoptChildGameObjects(e,t){const r=e.children;if(r)for(const e of r){if(!e)continue;const r=this.nodes.get(e.id);r&&r.parent!==t&&t.add(r)}}ensureTransformRoot(e,t){const o=this.nodes.get(e.id);if(a(o))return this.applyTransformPose(o,t),o;const s=new r.Group;if(s.name=e.name,s.userData[n]=!0,c(s,e.id),o&&o!==s){(function(e){const t=h(e);return 0===t.positionX&&0===t.positionY&&0===t.positionZ&&0===t.rotationX&&0===t.rotationY&&0===t.rotationZ&&1===t.scaleX&&1===t.scaleY&&1===t.scaleZ})(t)&&(t.positionX=o.position.x,t.positionY=o.position.y,t.positionZ=o.position.z,t.rotationX=o.rotation.x,t.rotationY=o.rotation.y,t.rotationZ=o.rotation.z,t.scaleX=o.scale.x,t.scaleY=o.scale.y,t.scaleZ=o.scale.z);(o.parent||this.scene).add(s),s.add(o),o.position.set(0,0,0),o.rotation.set(0,0,0),o.scale.set(1,1,1),this.nodes.set(e.id,s),this.adoptChildGameObjects(e,s)}else this.attachObject3D(e.id,s,e);return this.applyTransformPose(s,t),s}applyTransform3D(e,t){const r=this.ensureTransformRoot(e,t);return this.applyTransformPose(r,t),r.updateWorldMatrix(!0,!1),r.getWorldPosition(y),t.worldPositionX=y.x,t.worldPositionY=y.y,t.worldPositionZ=y.z,b.setFromRotationMatrix(r.matrixWorld),t.worldRotationX=b.x,t.worldRotationY=b.y,t.worldRotationZ=b.z,r}applyTransformPose(e,t){const r=h(t);e.position.set(r.positionX,r.positionY,r.positionZ),e.rotation.set(r.rotationX,r.rotationY,r.rotationZ),e.scale.set(r.scaleX,r.scaleY,r.scaleZ)}removeDefaultLights(){if(this.defaultLights.length){for(const e of this.defaultLights)e.parent?.remove(e),e.dispose?.();this.defaultLights=[]}}setActiveCamera(e){const t=this.camera;this.camera=e,t&&(e.aspect=t.aspect),e.updateProjectionMatrix()}restoreFallbackCamera(){this.camera!==this.fallbackCamera&&this.setActiveCamera(this.fallbackCamera)}rehomeRegisteredChildren(e){for(const t of[...e.children]){const e=t.userData?.[i];"number"==typeof e&&this.nodes.get(e)===t&&this.scene.add(t)}}playAnimation(e,t,r){const o=this.mixers.get(e),s=this.models.get(e);if(!o||!s)return;o.stopAllAction();const i=s.userData.animations;if(i&&i[t]){const e=o.clipAction(i[t]);e.timeScale=r,e.play()}}stopAnimation(e){const t=this.mixers.get(e);t&&t.stopAllAction()}removeModel(e){const t=this.models.get(e);t&&(this.detachVisual(e,t),t.traverse(e=>{const t=e;if(t.geometry&&t.geometry.dispose(),t.material){(Array.isArray(t.material)?t.material:[t.material]).forEach(e=>e.dispose())}}),this.models.delete(e));const r=this.mixers.get(e);r&&(r.stopAllAction(),this.mixers.delete(e))}resize(e,t){this.width=e,this.height=t,this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.fallbackCamera!==this.camera&&(this.fallbackCamera.aspect=e/t,this.fallbackCamera.updateProjectionMatrix()),this.renderer.setSize(e,t,!1)}destroy(){for(const e of this.models.keys())this.removeModel(e);this.removeDefaultLights(),this.renderer.dispose(),this.renderer.domElement.remove(),this.nodes.clear(),this.scene=null,this.camera=null,this.fallbackCamera=null,this.renderer=null,this.clock=null}}const x=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap"];function v(e,t){const r=e;for(const e of x){const o=r[e];o?.isTexture&&t(o)}}class w{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this,t.threeContext=this.rendererSystem.threeContext,this.renderers.push(t)}componentChanged(e){for(const r of e)for(const e of this.renderers){const o=e.observerInfo[r.componentName];if(!o)continue;if(r.type===t.OBSERVER_TYPE.ADD||r.type===t.OBSERVER_TYPE.REMOVE){try{e.componentChanged(r)}catch(e){console.error(`gameObject: ${r.gameObject.name}, ${r.componentName} error.`,r,e)}continue}if(o.findIndex(e=>"string"==typeof e&&"string"==typeof r.prop?e===r.prop:JSON.stringify(e)===JSON.stringify(r.prop))>-1)try{e.componentChanged(r)}catch(e){console.error(`gameObject: ${r.gameObject?.name}, ${r.componentName} componentChanged error.`,r,e)}}}update(e){for(const t of e.components)for(const r of this.renderers){if(r.observerInfo[t.name])try{r.rendererUpdate(e)}catch(r){console.info(`gameObject: ${e.name}, ${t.name} update error`,r)}}}}class D extends t.Component{constructor(){super(...arguments),this.positionX=0,this.positionY=0,this.positionZ=0,this.rotationX=0,this.rotationY=0,this.rotationZ=0,this.scaleX=1,this.scaleY=1,this.scaleZ=1,this.worldPositionX=0,this.worldPositionY=0,this.worldPositionZ=0,this.worldRotationX=0,this.worldRotationY=0,this.worldRotationZ=0}static{this.componentName="Transform3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"positionX",description:"Local X position.",editor:"number-stepper"})],D.prototype,"positionX",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"positionY",description:"Local Y position.",editor:"number-stepper"})],D.prototype,"positionY",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"positionZ",description:"Local Z position.",editor:"number-stepper"})],D.prototype,"positionZ",void 0),e.__decorate([o.Field({type:"number",step:.01,group:"Transform3D",label:"rotationX",description:"Rotation around X in radians.",editor:"number-stepper"})],D.prototype,"rotationX",void 0),e.__decorate([o.Field({type:"number",step:.01,group:"Transform3D",label:"rotationY",description:"Rotation around Y in radians.",editor:"number-stepper"})],D.prototype,"rotationY",void 0),e.__decorate([o.Field({type:"number",step:.01,group:"Transform3D",label:"rotationZ",description:"Rotation around Z in radians.",editor:"number-stepper"})],D.prototype,"rotationZ",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"scaleX",description:"Scale on X.",editor:"number-stepper"})],D.prototype,"scaleX",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"scaleY",description:"Scale on Y.",editor:"number-stepper"})],D.prototype,"scaleY",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Transform3D",label:"scaleZ",description:"Scale on Z.",editor:"number-stepper"})],D.prototype,"scaleZ",void 0);let R=class extends t.System{constructor(){super(...arguments),this.name="Renderer3DSystem",this.adaptive=null,this.pauseWhenHidden=!0,this.resolution=1,this.resizeObserver=null}static{this.systemName="Renderer3DSystem"}init(e){const r=e||{},o=r.width||750,s=r.height||1334,i=t.resolveRenderQuality(r,{adaptivePixelRatio:!1});this.resolution=i.pixelRatio,this.pauseWhenHidden=i.pauseWhenHidden,this.adaptive=new t.AdaptivePixelRatio({pixelRatio:i.pixelRatio,ceiling:i.pixelRatioCeiling,enabled:i.adaptivePixelRatio}),this.threeContext=new C({canvas:r.canvas,container:r.container,width:o,height:s,antialias:i.antialias,pixelRatio:i.pixelRatio,powerPreference:i.powerPreference,softShadows:r.softShadows,shadowMapSize:r.shadowMapSize,backgroundColor:r.backgroundColor,backgroundAlpha:r.backgroundAlpha,fog:r.fog,hemisphereLight:r.hemisphereLight,shadows:r.shadows,toneMapping:r.toneMapping,toneMappingExposure:r.toneMappingExposure,ambientIntensity:r.ambientIntensity,directionalIntensity:r.directionalIntensity}),this.game.canvas=this.threeContext.renderer.domElement,this.unregisterMetrics=this.game.diagnostics.register(function(e,r){let o=null,s=!0,i=!1,n={calls:0,triangles:0};const a={drawCalls:{supported:!0,coverage:"all passes including shadows within renderer.render"},canvasDrawOps:{supported:!1,reason:"backend-not-applicable"},triangles:{supported:!0},textures:{supported:!0},geometries:{supported:!0},programs:{supported:!0},gpuMs:{supported:!1,reason:"timer-query-unavailable"}};return{id:r,dimension:"3d",backend:"webgl",canvas:e.domElement,capabilities:a,start(r={}){i||(i=!0,o=r.gpuTiming?new t.WebGLGpuTimer(e.getContext()):null,a.gpuMs={supported:!!o?.supported,reason:o?.supported?void 0:r.gpuTiming?"timer-query-unavailable":"disabled-by-config"})},stop(){o?.clear(),o=null,i=!1},beginFrame(){s=e.info.autoReset,s&&e.info.reset(),e.info.autoReset=!1,n={calls:e.info.render.calls,triangles:e.info.render.triangles},o?.begin()},endFrame:()=>(e.info.autoReset=s,{drawCalls:e.info.render.calls-n.calls,triangles:e.info.render.triangles-n.triangles,canvasDrawOps:null,gpuMs:o?.end()??null}),resources:()=>({textures:e.info.memory.textures,geometries:e.info.memory.geometries,programs:e.info.programs?.length??0,bufferWidth:e.domElement.width,bufferHeight:e.domElement.height})}}(this.threeContext.renderer,"three-0")),this.observeCanvas(this.game.canvas),this.rendererManager=new w({game:this.game,rendererSystem:this})}update(e){const t=this.componentObserver.clear();for(const e of t)this.handleHierarchyChange(e);for(const e of this.game.gameObjects){const t=e.getComponent(D);t&&this.threeContext.applyTransform3D(e,t),this.rendererManager.update(e)}}handleHierarchyChange(e){"GameObject"===e.componentName&&(e.type!==t.OBSERVER_TYPE.CHANGE&&e.type!==t.OBSERVER_TYPE.ADD||(this.ensureTransform3D(e.gameObject),e.gameObject.parent&&this.ensureTransform3D(e.gameObject.parent),this.threeContext?.reparentGameObject(e.gameObject)))}ensureTransform3D(e){if(!e||e.destroyed||e===e.scene)return;let t=e.getComponent(D);(t||(t=new D,e.addComponent(t)))&&this.threeContext?.ensureTransformRoot(e,t)}lateUpdate(e){if(!this.threeContext)return;if(t.shouldPauseRendering(this.pauseWhenHidden))return void this.threeContext.update({skipDraw:!0});const r=this.adaptive?.sample(e?.deltaTime??0);null!=r&&(this.resolution=r,this.threeContext.pixelRatio=r,this.applyDisplay()),this.game.diagnostics.measureRender("three-0",()=>this.threeContext.update())}resize(e,t){this.applyDisplay()}observeCanvas(e){this.resizeObserver?.disconnect(),"undefined"!=typeof ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>this.applyDisplay()),this.resizeObserver.observe(e)),this.applyDisplay()}applyDisplay(){const e=this.threeContext?.renderer?.domElement;if(!e||"function"!=typeof e.getBoundingClientRect)return;const r=e.getBoundingClientRect(),o=t.displayBufferSize(r,this.resolution);if(!o)return;const s=e.width,i=e.height;if(s===o.bufferWidth&&i===o.bufferHeight){const e=o.bufferWidth/o.bufferHeight;if(Math.abs(this.threeContext.camera.aspect-e)<1e-6)return}this.threeContext.presentBuffer(o.bufferWidth,o.bufferHeight)}onDestroy(){this.unregisterMetrics?.(),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.threeContext?.destroy(),this.threeContext=null}};R=e.__decorate([t.decorators.componentObserver({GameObject:["parent"]})],R);var O=R;Object.assign(O,{packageName:"@combos-fun/plugin-renderer-3d",packageVersion:"0.1.26"});class _ extends t.System{constructor(e){super(e),this.asyncIdMap={};const t=this.constructor;this.observerInfo=t.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}const S=new Set(["positionX","positionY","positionZ","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"]);let M=class extends _{constructor(){super(...arguments),this.name="Transform3DSystem"}static{this.systemName="Transform3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("GameObject"===e.componentName)return this.ensureOn(e.gameObject),e.gameObject.parent&&this.ensureOn(e.gameObject.parent),void this.threeContext.reparentGameObject(e.gameObject);"Transform3D"===e.componentName&&(e.type===t.OBSERVER_TYPE.ADD?this.threeContext.ensureTransformRoot(e.gameObject,e.component):e.type===t.OBSERVER_TYPE.REMOVE?this.threeContext.detachObject3D(e.gameObject.id):S.has(e.prop?.prop?.[0])&&this.threeContext.applyTransform3D(e.gameObject,e.component))}rendererUpdate(e){const t=e.getComponent(D);t&&this.threeContext.applyTransform3D(e,t)}ensureOn(e){if(!e||e.destroyed||e===e.scene)return;let t=e.getComponent(D);(t||(t=new D,e.addComponent(t)))&&this.threeContext.ensureTransformRoot(e,t)}};M=e.__decorate([t.decorators.componentObserver({Transform3D:["positionX","positionY","positionZ","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"],GameObject:["parent"]})],M);var T=M;class E extends t.Component{constructor(){super(...arguments),this.visible=!0,this.opacity=1,this.renderOrder=0,this.sortableChildren=!1}static{this.componentName="Render3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([o.Field({type:"boolean",group:"Render3D",label:"visible",description:"Whether this object is drawn.",editor:"toggle"})],E.prototype,"visible",void 0),e.__decorate([o.Field({type:"number",step:.01,min:0,max:1,group:"Render3D",label:"opacity",description:"Opacity from 0 to 1.",editor:"number-slider"})],E.prototype,"opacity",void 0),e.__decorate([o.Field({type:"number",step:1,group:"Render3D",label:"renderOrder",description:"Draw order; higher values render on top.",editor:"number-stepper"})],E.prototype,"renderOrder",void 0),e.__decorate([o.Field({type:"boolean",group:"Render3D",label:"sortableChildren",description:"When on, children are sorted by their render order before drawing.",editor:"toggle"})],E.prototype,"sortableChildren",void 0);let j=class extends _{constructor(){super(...arguments),this.name="Render3DSystem"}static{this.systemName="Render3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Render3D"===e.componentName){if(e.type===t.OBSERVER_TYPE.REMOVE){const t=this.threeContext.object3DFor(e.gameObject.id);return void(t&&this.apply(t,{visible:!0,opacity:1,renderOrder:0,sortableChildren:!1}))}this.applyTo(e.gameObject,e.component)}}rendererUpdate(e){const t=e.getComponent(E);t&&this.applyTo(e,t)}applyTo(e,t){const r=this.threeContext.object3DFor(e.id);r&&(this.apply(r,t),t.sortableChildren&&this.sortChildren(e,r))}apply(e,t){e.visible=t.visible,e.traverse(e=>{e.renderOrder=t.renderOrder;const r=e;if(!r.isMesh||!r.material)return;const o=Array.isArray(r.material)?r.material:[r.material];for(const e of o){const r=e;"number"==typeof r.opacity&&(r.opacity=t.opacity,r.transparent=t.opacity<1)}})}sortChildren(e,t){const r=e.children?.map(e=>{if(!e)return null;const r=this.threeContext.object3DFor(e.id);if(!r||r.parent!==t)return null;const o=e.getComponent(E);return{node:r,order:o?.renderOrder??0}}).filter(e=>!!e).sort((e,t)=>e.order-t.order);if(r?.length)for(const e of r)t.add(e.node)}};j=e.__decorate([t.decorators.componentObserver({Render3D:["visible","opacity","renderOrder","sortableChildren"]})],j);var A=j;class Y extends t.Component{constructor(){super(...arguments),this.fov=75,this.near=.1,this.far=1e3,this.active=!0,this.lookAt=!1,this.lookAtX=0,this.lookAtY=0,this.lookAtZ=0}static{this.componentName="Camera3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([o.Field({type:"number",step:1,group:"Camera3D",label:"fov",description:"Vertical field of view in degrees.",editor:"number-stepper"})],Y.prototype,"fov",void 0),e.__decorate([o.Field({type:"number",step:.01,group:"Camera3D",label:"near",description:"Near clipping plane.",editor:"number-stepper"})],Y.prototype,"near",void 0),e.__decorate([o.Field({type:"number",step:1,group:"Camera3D",label:"far",description:"Far clipping plane.",editor:"number-stepper"})],Y.prototype,"far",void 0),e.__decorate([o.Field({type:"boolean",group:"Camera3D",label:"active",description:"Use this camera for rendering.",editor:"toggle"})],Y.prototype,"active",void 0),e.__decorate([o.Field({type:"boolean",group:"Camera3D",label:"lookAt",description:"Point the camera at lookAtX/Y/Z each frame.",editor:"toggle"})],Y.prototype,"lookAt",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtX",description:"World-space look-at target on X.",editor:"number-stepper"})],Y.prototype,"lookAtX",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtY",description:"World-space look-at target on Y.",editor:"number-stepper"})],Y.prototype,"lookAtY",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Camera3D",label:"lookAtZ",description:"World-space look-at target on Z.",editor:"number-stepper"})],Y.prototype,"lookAtZ",void 0);let L=class extends _{constructor(){super(...arguments),this.name="Camera3DSystem",this.cameras=new Map}static{this.systemName="Camera3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Camera3D"!==e.componentName)return;const r=e.component;e.type===t.OBSERVER_TYPE.ADD?this.mount(e.gameObject,r):e.type===t.OBSERVER_TYPE.REMOVE?this.unmount(e.gameObject.id):this.sync(e.gameObject,r)}rendererUpdate(e){const t=e.getComponent(Y),r=this.cameras.get(e.id);t&&r&&t.lookAt&&r.lookAt(t.lookAtX,t.lookAtY,t.lookAtZ)}mount(e,t){this.ensureTransform(e);const o=new r.PerspectiveCamera(t.fov,this.threeContext.camera.aspect,t.near,t.far);this.threeContext.attachVisual(e.id,o,e),this.cameras.set(e.id,o),this.sync(e,t)}sync(e,t){const r=this.cameras.get(e.id);r&&(r.fov=t.fov,r.near=t.near,r.far=t.far,r.updateProjectionMatrix(),t.active?this.threeContext.setActiveCamera(r):this.threeContext.camera===r&&this.activateAnother(e.id))}unmount(e){const t=this.cameras.get(e);t&&(this.threeContext.detachVisual(e,t),this.cameras.delete(e),this.threeContext.camera===t&&this.activateAnother(e))}activateAnother(e){for(const[t,r]of this.cameras){if(t===e)continue;const o=this.game.gameObjects.find(e=>e.id===t),s=o?.getComponent(Y);if(s?.active)return void this.threeContext.setActiveCamera(r)}this.threeContext.restoreFallbackCamera()}ensureTransform(e){if(!e||e.destroyed)return;let t=e.getComponent(D);if(!t)return t=new D,t.positionZ=5,void e.addComponent(t);u(t)&&(t.positionZ=5)}onDestroy(){for(const[e]of this.cameras)this.unmount(e);this.cameras.clear()}};L=e.__decorate([t.decorators.componentObserver({Camera3D:["fov","near","far","active","lookAt","lookAtX","lookAtY","lookAtZ"]})],L);var k=L;class P extends t.Component{constructor(){super(...arguments),this.type="directional",this.color=16777215,this.intensity=1,this.castShadow=!1,this.skyColor=16777215,this.groundColor=4473924,this.distance=0,this.decay=2,this.angle=Math.PI/3,this.penumbra=0}static{this.componentName="Light3D"}init(e){e&&Object.assign(this,e)}}e.__decorate([o.Field({type:"string",group:"Light3D",label:"type",description:"Light kind.",editor:"enum",enumOptions:["ambient","directional","hemisphere","point","spot"]})],P.prototype,"type",void 0),e.__decorate([o.Field({type:"number",group:"Light3D",label:"color",description:"Light color (hex).",editor:"number-stepper"})],P.prototype,"color",void 0),e.__decorate([o.Field({type:"number",step:.05,group:"Light3D",label:"intensity",description:"Light intensity.",editor:"number-stepper"})],P.prototype,"intensity",void 0),e.__decorate([o.Field({type:"boolean",group:"Light3D",label:"castShadow",description:"Whether this light casts shadows.",editor:"toggle"})],P.prototype,"castShadow",void 0),e.__decorate([o.Field({type:"number",group:"Light3D",label:"skyColor",description:"Hemisphere sky color (hex).",editor:"number-stepper"})],P.prototype,"skyColor",void 0),e.__decorate([o.Field({type:"number",group:"Light3D",label:"groundColor",description:"Hemisphere ground color (hex).",editor:"number-stepper"})],P.prototype,"groundColor",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Light3D",label:"distance",description:"Range for point and spot lights. 0 means no limit.",editor:"number-stepper"})],P.prototype,"distance",void 0),e.__decorate([o.Field({type:"number",step:.1,group:"Light3D",label:"decay",description:"Intensity falloff for point and spot lights.",editor:"number-stepper"})],P.prototype,"decay",void 0),e.__decorate([o.Field({type:"number",step:.01,group:"Light3D",label:"angle",description:"Spot light cone angle in radians.",editor:"number-stepper"})],P.prototype,"angle",void 0),e.__decorate([o.Field({type:"number",step:.01,min:0,max:1,group:"Light3D",label:"penumbra",description:"Spot light soft edge (0–1).",editor:"number-slider"})],P.prototype,"penumbra",void 0);let X=class extends _{constructor(){super(...arguments),this.name="Light3DSystem",this.lights=new Map}static{this.systemName="Light3DSystem"}init(){this.game.getSystem("Renderer3DSystem").rendererManager.register(this)}componentChanged(e){if("Light3D"!==e.componentName)return;const r=e.component;e.type===t.OBSERVER_TYPE.ADD?this.mount(e.gameObject,r):e.type===t.OBSERVER_TYPE.REMOVE?this.unmount(e.gameObject.id):"type"===e.prop?.prop?.[0]?(this.unmount(e.gameObject.id),this.mount(e.gameObject,r)):this.sync(e.gameObject.id,r)}rendererUpdate(e){}mount(e,t){this.ensureTransform(e),0===this.lights.size&&this.threeContext.removeDefaultLights();const r=this.createLight(t);this.threeContext.attachVisual(e.id,r,e),this.lights.set(e.id,r),this.sync(e.id,t)}createLight(e){switch(e.type){case"ambient":return new r.AmbientLight(e.color,e.intensity);case"hemisphere":return new r.HemisphereLight(e.skyColor,e.groundColor,e.intensity);case"point":return new r.PointLight(e.color,e.intensity,e.distance,e.decay);case"spot":return new r.SpotLight(e.color,e.intensity,e.distance,e.angle,e.penumbra,e.decay);default:return new r.DirectionalLight(e.color,e.intensity)}}sync(e,t){const o=this.lights.get(e);o&&("color"in o&&o.color&&o.color.set(t.color),o.intensity=t.intensity,o instanceof r.HemisphereLight&&(o.color.set(t.skyColor),o.groundColor.set(t.groundColor)),(o instanceof r.PointLight||o instanceof r.SpotLight)&&(o.distance=t.distance,o.decay=t.decay),o instanceof r.SpotLight&&(o.angle=t.angle,o.penumbra=t.penumbra),"castShadow"in o&&(o.castShadow=!(!t.castShadow||!this.threeContext.shadows)))}unmount(e){const t=this.lights.get(e);t&&(this.threeContext.detachVisual(e,t),t.dispose?.(),this.lights.delete(e))}ensureTransform(e){e&&!e.destroyed&&(e.getComponent(D)||e.addComponent(new D))}onDestroy(){for(const[e]of this.lights)this.unmount(e);this.lights.clear()}};X=e.__decorate([t.decorators.componentObserver({Light3D:["type","color","intensity","castShadow","skyColor","groundColor","distance","decay","angle","penumbra"]})],X);var Z=X;const F=["WEBGL_compressed_texture_astc","EXT_texture_compression_bptc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_etc"];let I=null,B=null;function V(e){return F.some(t=>e.extensions.has(t))}function N(e){return I||(I=new s.KTX2Loader,I.setTranscoderPath("https://unpkg.com/three@0.172.0/examples/jsm/libs/basis/")),e&&B!==e&&(I.detectSupport(e),B=e),I}async function G(e,t){if(!V(t))return null;try{const o=await N(t).loadAsync(e),s=o;return s?.isCompressedTexture&&s.format!==r.RGBAFormat?o:(o?.dispose(),null)}catch{return null}}async function z(e){const r=String(e??"").trim();if(!r)throw new Error("resource name is required; register it with resource.addResource");const o=await t.resource.getResource(r);if(!o||!o.name)throw new Error(`Unknown resource "${r}"; register it with resource.addResource first`);return o}function W(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?e:null}async function U(e){let t=e;if("function"==typeof createImageBitmap)try{t=await createImageBitmap(e)}catch{t=e}const o=new r.Texture(t);if(o.colorSpace=r.SRGBColorSpace,o.needsUpdate=!0,"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=t,r=o.dispose.bind(o);o.dispose=()=>{r();try{e.close()}catch{}}}return o}async function H(e,r){if(!r)return null;const o=function(e){if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e)){const t=e;return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}return null}(e.data?.image);if(!o)return null;const s=t.compressedTextureUrl(e.src?.image),i=URL.createObjectURL(new Blob([o]));try{const e=await G(i,r);if(e)return e}finally{URL.revokeObjectURL(i)}return s?G(s,r):null}async function $(e,r){const o=await H(e,r);if(o)return o;const s=W(e.data?.image);if(s)return U(s);const i=t.imageFallbackUrl(e.src?.image);if(i)try{return U(await(n=i,new Promise((e,t)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>e(r),r.onerror=()=>t(new Error(`Failed to load image ${n}`)),r.src=n})))}catch{}var n;throw new Error(`Resource "${e.name}" has no image data; use RESOURCE_TYPE.IMAGE with src.image.url`)}exports.COMBOS_GAME_OBJECT_ID=i,exports.COMBOS_TRANSFORM3D=n,exports.Camera3D=Y,exports.Camera3DSystem=k,exports.Light3D=P,exports.Light3DSystem=Z,exports.Render3D=E,exports.Render3DSystem=A,exports.Renderer3D=_,exports.Renderer3DManager=w,exports.Renderer3DSystem=O,exports.ThreeContext=C,exports.Transform3D=D,exports.Transform3DSystem=T,exports.VisualPoseBridge=class{constructor(){this.lastVisual="",this.lastRoot=""}sync(e,t){if(!t)return!0;if(""===this.lastVisual&&""===this.lastRoot)return g(e,t),this.lastVisual=l(e),this.lastRoot=l(t),!1;const r=l(e),o=l(t);return r!==this.lastVisual&&o===this.lastRoot&&m(e,t),this.lastVisual=l(e),this.lastRoot=l(t),!1}},exports.copyPose=m,exports.ensureKtx2Loader=N,exports.gameObjectIdFromIntersection=function(e){return p(e?.object)},exports.gameObjectIdFromObject3D=p,exports.has3DChildGameObjects=function(e){return(e?.children?.length??0)>0},exports.is3DSceneParent=d,exports.isIdentityPose=u,exports.isTransform3DRoot=a,exports.loadThreeKtx2=G,exports.poseKeyOf=l,exports.readPose=h,exports.rendererSupportsCompressedTexture=V,exports.requireNamedResource=z,exports.seedTransform3D=g,exports.tagObject3D=c,exports.textureFromNamedImage=async function(e,t){return $(await z(e),t)},exports.textureFromResourceImage=function(e){const t=W(e.data?.image);if(!t)throw new Error(`Resource "${e.name}" has no image data; use RESOURCE_TYPE.IMAGE with src.image.url`);const o=new r.Texture(t);return o.colorSpace=r.SRGBColorSpace,o.needsUpdate=!0,o},exports.textureFromResourceImageAsync=$;
|
|
@@ -182,6 +182,7 @@ declare class Renderer3DSystem extends System<Renderer3DSystemParams> {
|
|
|
182
182
|
private pauseWhenHidden;
|
|
183
183
|
private resolution;
|
|
184
184
|
private resizeObserver;
|
|
185
|
+
private unregisterMetrics?;
|
|
185
186
|
init(params?: Renderer3DSystemParams): void;
|
|
186
187
|
update(e?: UpdateParams): void;
|
|
187
188
|
private handleHierarchyChange;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import { OBSERVER_TYPE, Component, System, resolveRenderQuality, AdaptivePixelRatio, shouldPauseRendering, displayBufferSize, decorators, resource, imageFallbackUrl, compressedTextureUrl } from '@combos-fun/engine';
|
|
2
|
+
import { OBSERVER_TYPE, Component, WebGLGpuTimer, System, resolveRenderQuality, AdaptivePixelRatio, shouldPauseRendering, displayBufferSize, decorators, resource, imageFallbackUrl, compressedTextureUrl } from '@combos-fun/engine';
|
|
3
3
|
import { Vector3, Euler, Scene, PerspectiveCamera, WebGLRenderer, CineonToneMapping, ReinhardToneMapping, LinearToneMapping, ACESFilmicToneMapping, NoToneMapping, PCFSoftShadowMap, PCFShadowMap, AmbientLight, DirectionalLight, HemisphereLight, Fog, Clock, AnimationMixer, Group, SpotLight, PointLight, RGBAFormat, Texture, SRGBColorSpace } from 'three';
|
|
4
4
|
import { Field } from '@combos-fun/inspector-decorator';
|
|
5
5
|
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
|
|
@@ -733,6 +733,53 @@ __decorate([
|
|
|
733
733
|
})
|
|
734
734
|
], Transform3D.prototype, "scaleZ", void 0);
|
|
735
735
|
|
|
736
|
+
function createThreeMetricsProvider(renderer, id) {
|
|
737
|
+
let timer = null;
|
|
738
|
+
let autoReset = true, started = false;
|
|
739
|
+
let previous = { calls: 0, triangles: 0 };
|
|
740
|
+
const capabilities = {
|
|
741
|
+
drawCalls: { supported: true, coverage: 'all passes including shadows within renderer.render' },
|
|
742
|
+
canvasDrawOps: { supported: false, reason: 'backend-not-applicable' },
|
|
743
|
+
triangles: { supported: true }, textures: { supported: true },
|
|
744
|
+
geometries: { supported: true }, programs: { supported: true },
|
|
745
|
+
gpuMs: { supported: false, reason: 'timer-query-unavailable' },
|
|
746
|
+
};
|
|
747
|
+
return {
|
|
748
|
+
id, dimension: '3d', backend: 'webgl', canvas: renderer.domElement, capabilities,
|
|
749
|
+
start(options = {}) {
|
|
750
|
+
if (started)
|
|
751
|
+
return;
|
|
752
|
+
started = true;
|
|
753
|
+
timer = options.gpuTiming ? new WebGLGpuTimer(renderer.getContext()) : null;
|
|
754
|
+
capabilities.gpuMs = { supported: !!timer?.supported, reason: timer?.supported ? undefined : options.gpuTiming ? 'timer-query-unavailable' : 'disabled-by-config' };
|
|
755
|
+
},
|
|
756
|
+
stop() { timer?.clear(); timer = null; started = false; },
|
|
757
|
+
beginFrame() {
|
|
758
|
+
autoReset = renderer.info.autoReset;
|
|
759
|
+
if (autoReset)
|
|
760
|
+
renderer.info.reset();
|
|
761
|
+
renderer.info.autoReset = false;
|
|
762
|
+
previous = { calls: renderer.info.render.calls, triangles: renderer.info.render.triangles };
|
|
763
|
+
timer?.begin();
|
|
764
|
+
},
|
|
765
|
+
endFrame() {
|
|
766
|
+
renderer.info.autoReset = autoReset;
|
|
767
|
+
return {
|
|
768
|
+
drawCalls: renderer.info.render.calls - previous.calls,
|
|
769
|
+
triangles: renderer.info.render.triangles - previous.triangles,
|
|
770
|
+
canvasDrawOps: null, gpuMs: timer?.end() ?? null,
|
|
771
|
+
};
|
|
772
|
+
},
|
|
773
|
+
resources() {
|
|
774
|
+
return {
|
|
775
|
+
textures: renderer.info.memory.textures, geometries: renderer.info.memory.geometries,
|
|
776
|
+
programs: renderer.info.programs?.length ?? 0,
|
|
777
|
+
bufferWidth: renderer.domElement.width, bufferHeight: renderer.domElement.height,
|
|
778
|
+
};
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
|
|
736
783
|
let Renderer3DSystem = class Renderer3DSystem extends System {
|
|
737
784
|
constructor() {
|
|
738
785
|
super(...arguments);
|
|
@@ -776,6 +823,7 @@ let Renderer3DSystem = class Renderer3DSystem extends System {
|
|
|
776
823
|
directionalIntensity: opts.directionalIntensity,
|
|
777
824
|
});
|
|
778
825
|
this.game.canvas = this.threeContext.renderer.domElement;
|
|
826
|
+
this.unregisterMetrics = this.game.diagnostics.register(createThreeMetricsProvider(this.threeContext.renderer, 'three-0'));
|
|
779
827
|
this.observeCanvas(this.game.canvas);
|
|
780
828
|
this.rendererManager = new Renderer3DManager({
|
|
781
829
|
game: this.game,
|
|
@@ -829,7 +877,7 @@ let Renderer3DSystem = class Renderer3DSystem extends System {
|
|
|
829
877
|
this.threeContext.pixelRatio = next;
|
|
830
878
|
this.applyDisplay();
|
|
831
879
|
}
|
|
832
|
-
this.threeContext.update();
|
|
880
|
+
this.game.diagnostics.measureRender('three-0', () => this.threeContext.update());
|
|
833
881
|
}
|
|
834
882
|
resize(_width, _height) {
|
|
835
883
|
this.applyDisplay();
|
|
@@ -860,6 +908,7 @@ let Renderer3DSystem = class Renderer3DSystem extends System {
|
|
|
860
908
|
this.threeContext.presentBuffer(buffer.bufferWidth, buffer.bufferHeight);
|
|
861
909
|
}
|
|
862
910
|
onDestroy() {
|
|
911
|
+
this.unregisterMetrics?.();
|
|
863
912
|
this.resizeObserver?.disconnect();
|
|
864
913
|
this.resizeObserver = null;
|
|
865
914
|
this.threeContext?.destroy();
|
|
@@ -876,7 +925,7 @@ var Renderer3DSystem$1 = Renderer3DSystem;
|
|
|
876
925
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
877
926
|
Object.assign(Renderer3DSystem$1, {
|
|
878
927
|
packageName: "@combos-fun/plugin-renderer-3d",
|
|
879
|
-
packageVersion: "0.1.
|
|
928
|
+
packageVersion: "0.1.26",
|
|
880
929
|
});
|
|
881
930
|
|
|
882
931
|
class Renderer3D extends System {
|