@eva/plugin-renderer-scene-capture 2.1.0-beta.14 → 2.1.0-beta.15

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.
@@ -1,9 +1,10 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ var globalThis = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : Function('return this')();
2
3
  globalThis.EVA = globalThis.EVA || {};
3
4
  globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
5
  globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
6
  globalThis.EVA.plugin.renderer.scene = globalThis.EVA.plugin.renderer.scene || {};
6
- var _EVA_IIFE_capture = function (exports, eva_js, pluginRenderer, pixi_js) {
7
+ var _EVA_IIFE_capture = function (exports, eva_js, inspectorDecorator, pluginRenderer, pixi_js) {
7
8
  'use strict';
8
9
  function __decorate(decorators, target, key, desc) {
9
10
  var c = arguments.length,
@@ -15,106 +16,6 @@ var _EVA_IIFE_capture = function (exports, eva_js, pluginRenderer, pixi_js) {
15
16
  function __metadata(metadataKey, metadataValue) {
16
17
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
17
18
  }
18
- function __rest(s, e) {
19
- var t = {};
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
21
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
23
- }
24
- return t;
25
- }
26
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
27
- var e = new Error(message);
28
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
- };
30
- class SymbolKeysNotSupportedError extends Error {
31
- constructor() {
32
- super('Symbol keys are not supported yet!');
33
- Object.setPrototypeOf(this, new.target.prototype);
34
- }
35
- }
36
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
37
- function transformBasicType(type) {
38
- if (type === String) {
39
- return 'string';
40
- }
41
- if (type === Number) {
42
- return 'number';
43
- }
44
- if (type === Boolean) {
45
- return 'boolean';
46
- }
47
- return 'unknown';
48
- }
49
- function defineLegacyIDEProp(target, propertyKey, patch) {
50
- const constructor = target.constructor;
51
- const current = constructor.IDEProps || {};
52
- current[propertyKey] = _extends(_extends({
53
- key: propertyKey
54
- }, current[propertyKey]), patch);
55
- constructor.IDEProps = current;
56
- }
57
- function defineTypes(target, key, options, returnTypeFunction) {
58
- let type = Reflect.getMetadata('design:type', target, key);
59
- let isArray = type === Array;
60
- const str = transformBasicType(type);
61
- if (str !== 'unknown') {
62
- type = str;
63
- }
64
- if (returnTypeFunction) {
65
- const returnType = returnTypeFunction();
66
- if (Array.isArray(returnType)) {
67
- isArray = true;
68
- type = returnType[0];
69
- } else {
70
- type = returnType;
71
- }
72
- }
73
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
74
- const current = properties[key] || {};
75
- const property = _extends(_extends(_extends({}, current), {
76
- type,
77
- isArray: isArray
78
- }), options);
79
- properties[key] = property;
80
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
81
- const legacyProperty = __rest(property, ["isArray"]);
82
- defineLegacyIDEProp(target, key, legacyProperty);
83
- }
84
- function type(type) {
85
- return Field({
86
- type
87
- });
88
- }
89
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
90
- if (typeof returnTypeFuncOrOptions === 'function') {
91
- return {
92
- returnTypeFunc: returnTypeFuncOrOptions,
93
- options: maybeOptions || {}
94
- };
95
- }
96
- return {
97
- options: returnTypeFuncOrOptions || {}
98
- };
99
- }
100
- function Field(returnTypeFunction, maybeOptions) {
101
- return (target, propertyKey) => {
102
- if (typeof propertyKey === 'symbol') {
103
- throw new SymbolKeysNotSupportedError();
104
- }
105
- const {
106
- options,
107
- returnTypeFunc
108
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
109
- defineTypes(target, propertyKey, options, returnTypeFunc);
110
- };
111
- }
112
- var ExecuteMode;
113
- (function (ExecuteMode) {
114
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
115
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
116
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
117
- })(ExecuteMode || (ExecuteMode = {}));
118
19
  const finitePositive$1 = (value, fallback) => {
119
20
  const numberValue = Number(value);
120
21
  return Number.isFinite(numberValue) && numberValue > 0 ? numberValue : fallback;
@@ -161,16 +62,16 @@ var _EVA_IIFE_capture = function (exports, eva_js, pluginRenderer, pixi_js) {
161
62
  }
162
63
  }
163
64
  SceneCapture.componentName = 'SceneCapture';
164
- __decorate([type('array'), __metadata("design:type", Array)], SceneCapture.prototype, "sourceNames", void 0);
165
- __decorate([type('string'), __metadata("design:type", String)], SceneCapture.prototype, "output", void 0);
166
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "width", void 0);
167
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "height", void 0);
168
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "resolutionScale", void 0);
169
- __decorate([type('string'), __metadata("design:type", String)], SceneCapture.prototype, "updateMode", void 0);
170
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "clearColor", void 0);
171
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "clearAlpha", void 0);
172
- __decorate([type('boolean'), __metadata("design:type", Boolean)], SceneCapture.prototype, "enabled", void 0);
173
- __decorate([type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "captureRevision", void 0);
65
+ __decorate([inspectorDecorator.type('array'), __metadata("design:type", Array)], SceneCapture.prototype, "sourceNames", void 0);
66
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], SceneCapture.prototype, "output", void 0);
67
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "width", void 0);
68
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "height", void 0);
69
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "resolutionScale", void 0);
70
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], SceneCapture.prototype, "updateMode", void 0);
71
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "clearColor", void 0);
72
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "clearAlpha", void 0);
73
+ __decorate([inspectorDecorator.type('boolean'), __metadata("design:type", Boolean)], SceneCapture.prototype, "enabled", void 0);
74
+ __decorate([inspectorDecorator.type('number'), __metadata("design:type", Number)], SceneCapture.prototype, "captureRevision", void 0);
174
75
  class SceneCaptureTextureRegistry {
175
76
  constructor() {
176
77
  this.entries = new Map();
@@ -257,8 +158,8 @@ var _EVA_IIFE_capture = function (exports, eva_js, pluginRenderer, pixi_js) {
257
158
  return;
258
159
  }
259
160
  if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
260
- const record = this.records.get(gameObjectId);
261
- if (record) this.disposeRecord(record);
161
+ const _record = this.records.get(gameObjectId);
162
+ if (_record) this.disposeRecord(_record);
262
163
  return;
263
164
  }
264
165
  const record = this.records.get(gameObjectId);
@@ -514,5 +415,5 @@ var _EVA_IIFE_capture = function (exports, eva_js, pluginRenderer, pixi_js) {
514
415
  value: true
515
416
  });
516
417
  return exports;
517
- }({}, EVA, EVA.plugin.renderer, PIXI);
418
+ }({}, EVA, inspectorDecorator, EVA.plugin.renderer, PIXI);
518
419
  globalThis.EVA.plugin.renderer.scene.capture = globalThis.EVA.plugin.renderer.scene.capture || _EVA_IIFE_capture;
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{},globalThis.EVA.plugin.renderer.scene=globalThis.EVA.plugin.renderer.scene||{};var _EVA_IIFE_capture=function(e,t,r,n){"use strict";function o(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class s extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const a="IDE_PROPERTY_METADATA";function u(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),n){const e=n();Array.isArray(e)?(i=!0,o=e[0]):o=e}const u=Reflect.getMetadata(a,e.constructor)||{},p=_extends(_extends(_extends({},u[t]||{}),{type:o,isArray:i}),r);u[t]=p,Reflect.defineMetadata(a,u,e.constructor);!function(e,t,r){const n=e.constructor,o=n.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),r),n.IDEProps=o}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(p,["isArray"]))}function p(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new s;const{options:o,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);u(e,n,o,i)};var t,r}var c;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(c||(c={}));const d=(e,t)=>{const r=Number(e);return Number.isFinite(r)&&r>0?r:t};class l extends t.Component{constructor(){super(...arguments),this.sourceNames=[],this.output="",this.width=256,this.height=256,this.resolutionScale=1,this.updateMode="always",this.clearColor=0,this.clearAlpha=0,this.enabled=!0,this.captureRevision=0}init(e){e&&_extends(this,e),this.sourceNames=Array.isArray(this.sourceNames)?this.sourceNames.filter(e=>"string"==typeof e&&e.trim().length>0):[],this.output="string"==typeof this.output?this.output.trim():"",this.width=d(this.width,256),this.height=d(this.height,256),this.resolutionScale=d(this.resolutionScale,1),this.updateMode=this.normalizeUpdateMode(this.updateMode),this.clearColor=Math.max(0,Math.min(16777215,Number(this.clearColor)||0))>>>0,this.clearAlpha=((e,t,r,n)=>{const o=Number(e);return Number.isFinite(o)?Math.min(r,Math.max(t,o)):n})(this.clearAlpha,0,1,0),this.enabled=!1!==this.enabled}requestCapture(){this.captureRevision++,this.emit("captureRequested",{revision:this.captureRevision})}normalizeUpdateMode(e){return"onDirty"===e||"manual"===e?e:"always"}}l.componentName="SceneCapture",o([p("array"),i("design:type",Array)],l.prototype,"sourceNames",void 0),o([p("string"),i("design:type",String)],l.prototype,"output",void 0),o([p("number"),i("design:type",Number)],l.prototype,"width",void 0),o([p("number"),i("design:type",Number)],l.prototype,"height",void 0),o([p("number"),i("design:type",Number)],l.prototype,"resolutionScale",void 0),o([p("string"),i("design:type",String)],l.prototype,"updateMode",void 0),o([p("number"),i("design:type",Number)],l.prototype,"clearColor",void 0),o([p("number"),i("design:type",Number)],l.prototype,"clearAlpha",void 0),o([p("boolean"),i("design:type",Boolean)],l.prototype,"enabled",void 0),o([p("number"),i("design:type",Number)],l.prototype,"captureRevision",void 0);class h{constructor(){this.entries=new Map}get(e){var t;return null===(t=this.entries.get(this.normalize(e)))||void 0===t?void 0:t.texture}getEntry(e){return this.entries.get(this.normalize(e))}has(e){return this.entries.has(this.normalize(e))}set(e,t,r){const n=this.normalize(e);n&&t&&r&&this.entries.set(n,Object.freeze({output:n,owner:t,texture:r}))}delete(e,t){const r=this.normalize(e),n=this.entries.get(r);return!(!n||t&&n.owner!==t)&&this.entries.delete(r)}normalize(e){return"string"==typeof e?e.trim():""}}const y=new h;let m=0;const f=(e,t)=>{const r=Number(e);return Number.isFinite(r)&&r>0?r:t},g=e=>{const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0},b=e=>"string"==typeof e?e.trim():"";let v=class extends r.Renderer{constructor(){super(...arguments),this.name="SceneCapture",this.presentationAddFlushEnabled=!0,this.records=new Map,this.outputs=new Map,this.emptyCaptureRoot=new n.Container,this.participantId="scene-capture:"+ ++m,this.destroyed=!1}init(){if(this.renderSystem=this.game.getSystem(r.RendererSystem),!this.renderSystem)throw new Error("[SceneCapture] RendererSystem must be registered before SceneCaptureSystem.");this.renderSystem.rendererManager.register(this),this.ensurePresentationParticipant()}update(e){super.update(e),this.ensurePresentationParticipant()}lateUpdate(){var e;if(this.hasLivePresentationParticipant())return;const t=null===(e=this.renderSystem)||void 0===e?void 0:e.application;t&&this.captureForApplication(t)}componentChanged(e){if("SceneCapture"!==e.componentName)return;const r=e.component,n=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD)return void this.addRecord(n,r);if(e.type===t.OBSERVER_TYPE.REMOVE){const e=this.records.get(n);return void(e&&this.disposeRecord(e))}const o=this.records.get(n);o&&(o.component=r,this.resizeRecord(o),this.updateOutput(o),"manual"!==r.updateMode&&(o.dirty=!0),r.captureRevision!==o.lastCaptureRevision&&(o.dirty=!0))}getTexture(e){var t;return null===(t=this.outputs.get(b(e)))||void 0===t?void 0:t.texture}onDestroy(){var e;this.destroyed=!0,null===(e=this.presentationHandle)||void 0===e||e.dispose(),this.presentationHandle=void 0;for(const e of Array.from(this.records.values()))this.disposeRecord(e);try{this.emptyCaptureRoot.destroy({children:!1})}catch(e){}}addRecord(e,t){const r=this.records.get(e);r&&this.disposeRecord(r);const n={};_extends(n,{owner:n,gameObjectId:e,component:t,texture:this.createTexture(t),output:b(t.output),width:this.widthOf(t),height:this.heightOf(t),resolutionScale:this.resolutionOf(t),dirty:"manual"!==t.updateMode||t.captureRevision>0,lastCaptureRevision:0,disposed:!1,onCaptureRequested:()=>{n.disposed||(n.dirty=!0)}}),t.on("captureRequested",n.onCaptureRequested),this.records.set(e,n),this.bindOutput(n)}createTexture(e){return n.RenderTexture.create({width:this.widthOf(e),height:this.heightOf(e),resolution:this.resolutionOf(e)})}widthOf(e){return f(e.width,256)}heightOf(e){return f(e.height,256)}resolutionOf(e){return f(e.resolutionScale,1)}resizeRecord(e){const t=this.widthOf(e.component),r=this.heightOf(e.component),n=this.resolutionOf(e.component);if(e.width===t&&e.height===r&&e.resolutionScale===n)return;e.width=t,e.height=r,e.resolutionScale=n;const o=e.texture;if("function"==typeof o.resize)return void o.resize(t,r,n);const i=e.texture;e.texture=this.createTexture(e.component),this.bindOutput(e);try{i.destroy(!0)}catch(e){}}updateOutput(e){const t=b(e.component.output);e.output!==t&&(this.unbindOutput(e),e.output=t,this.bindOutput(e))}bindOutput(e){e.output&&(this.outputs.set(e.output,e),y.set(e.output,e.owner,e.texture))}unbindOutput(e){e.output&&(this.outputs.get(e.output)===e&&this.outputs.delete(e.output),y.delete(e.output,e.owner))}disposeRecord(e){if(!e.disposed){e.disposed=!0,this.records.delete(e.gameObjectId),this.unbindOutput(e);try{e.component.off("captureRequested",e.onCaptureRequested)}catch(e){}try{e.texture.destroy(!0)}catch(e){}}}ensurePresentationParticipant(){var e;if(this.destroyed||this.hasLivePresentationParticipant())return;const t=this.renderSystem;if(!(null==t?void 0:t.application)||"function"!=typeof t.registerPresentationParticipant)return;const r=null===(e=t.getPresentationApplicationId)||void 0===e?void 0:e.call(t,t.application);let n;n=t.registerPresentationParticipant({id:this.participantId,applicationId:r,build:()=>({writes:Array.from(this.outputs.keys(),e=>`scene-capture:${e}`)}),submit:e=>{this.captureForApplication(e.application)},dispose:()=>{this.presentationHandle===n&&(this.presentationHandle=void 0)}}),this.presentationHandle=n}hasLivePresentationParticipant(){return Boolean(this.presentationHandle&&!this.presentationHandle.disposed)}captureForApplication(e){const t=null==e?void 0:e.renderer;if(null==t?void 0:t.render)for(const r of this.records.values())this.shouldCapture(r)&&this.captureRecord(t,e,r)&&(r.dirty=!1,r.lastCaptureRevision=r.component.captureRevision)}shouldCapture(e){const t=e.component;return!e.disposed&&!1!==t.enabled&&("always"===t.updateMode||(t.captureRevision!==e.lastCaptureRevision&&(e.dirty=!0),e.dirty))}captureRecord(e,t,r){const n=this.resolveSourceContainers(r.component,t),o=this.toClearColor(r.component);try{if(0===n.length)return e.render({container:this.emptyCaptureRoot,target:r.texture,clear:!0,clearColor:o}),!0;for(let t=0;t<n.length;t++){const i=n[t],s={container:i,target:r.texture,clear:0===t};0===t&&(s.clearColor=o),i.worldTransform&&(s.transform=i.worldTransform),e.render(s)}return!0}catch(e){return!1}}resolveSourceContainers(e,t){var r;const n=[],o=Array.isArray(e.sourceNames)?e.sourceNames:[],i=this.game;for(const e of o){if(!e||"function"!=typeof(null==i?void 0:i.findAllByName))continue;const o=i.findAllByName(e);for(const e of o||[]){if(!e||e.destroyed)continue;const o=null===(r=this.containerManager)||void 0===r?void 0:r.getContainer(e.id);o&&!o.destroyed&&o!==t.stage&&o!==this.emptyCaptureRoot&&(n.includes(o)||n.push(o))}}return n}toClearColor(e){const t=(Number(e.clearColor)||0)>>>0;return[(t>>>16&255)/255,(t>>>8&255)/255,(255&t)/255,g(e.clearAlpha)]}};v.systemName="SceneCapture",v=o([t.decorators.componentObserver({SceneCapture:[{prop:["sourceNames"],deep:!0},{prop:["output"],deep:!1},{prop:["width"],deep:!1},{prop:["height"],deep:!1},{prop:["resolutionScale"],deep:!1},{prop:["updateMode"],deep:!1},{prop:["clearColor"],deep:!1},{prop:["clearAlpha"],deep:!1},{prop:["enabled"],deep:!1},{prop:["captureRevision"],deep:!1}]})],v);var R=v;return e.SceneCapture=l,e.SceneCaptureSystem=R,e.SceneCaptureTextureRegistry=h,e.getSceneCaptureTexture=function(e){return y.get(e)},e.sceneCaptureTextureRegistry=y,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.scene.capture=globalThis.EVA.plugin.renderer.scene.capture||_EVA_IIFE_capture;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)({}).hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_extends.apply(null,arguments)}var globalThis="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{},globalThis.EVA.plugin.renderer.scene=globalThis.EVA.plugin.renderer.scene||{};var _EVA_IIFE_capture=function(e,t,r,i,o){"use strict";function n(e,t,r,i){var o,n=arguments.length,s=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(n<3?o(s):n>3?o(t,r,s):o(t,r))||s);return n>3&&s&&Object.defineProperty(t,r,s),s}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}const a=(e,t)=>{const r=Number(e);return Number.isFinite(r)&&r>0?r:t};class u extends t.Component{constructor(){super(...arguments),this.sourceNames=[],this.output="",this.width=256,this.height=256,this.resolutionScale=1,this.updateMode="always",this.clearColor=0,this.clearAlpha=0,this.enabled=!0,this.captureRevision=0}init(e){e&&_extends(this,e),this.sourceNames=Array.isArray(this.sourceNames)?this.sourceNames.filter(e=>"string"==typeof e&&e.trim().length>0):[],this.output="string"==typeof this.output?this.output.trim():"",this.width=a(this.width,256),this.height=a(this.height,256),this.resolutionScale=a(this.resolutionScale,1),this.updateMode=this.normalizeUpdateMode(this.updateMode),this.clearColor=Math.max(0,Math.min(16777215,Number(this.clearColor)||0))>>>0,this.clearAlpha=((e,t,r,i)=>{const o=Number(e);return Number.isFinite(o)?Math.min(r,Math.max(t,o)):i})(this.clearAlpha,0,1,0),this.enabled=!1!==this.enabled}requestCapture(){this.captureRevision++,this.emit("captureRequested",{revision:this.captureRevision})}normalizeUpdateMode(e){return"onDirty"===e||"manual"===e?e:"always"}}u.componentName="SceneCapture",n([r.type("array"),s("design:type",Array)],u.prototype,"sourceNames",void 0),n([r.type("string"),s("design:type",String)],u.prototype,"output",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"width",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"height",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"resolutionScale",void 0),n([r.type("string"),s("design:type",String)],u.prototype,"updateMode",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"clearColor",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"clearAlpha",void 0),n([r.type("boolean"),s("design:type",Boolean)],u.prototype,"enabled",void 0),n([r.type("number"),s("design:type",Number)],u.prototype,"captureRevision",void 0);class p{constructor(){this.entries=new Map}get(e){var t;return null===(t=this.entries.get(this.normalize(e)))||void 0===t?void 0:t.texture}getEntry(e){return this.entries.get(this.normalize(e))}has(e){return this.entries.has(this.normalize(e))}set(e,t,r){const i=this.normalize(e);i&&t&&r&&this.entries.set(i,Object.freeze({output:i,owner:t,texture:r}))}delete(e,t){const r=this.normalize(e),i=this.entries.get(r);return!(!i||t&&i.owner!==t)&&this.entries.delete(r)}normalize(e){return"string"==typeof e?e.trim():""}}const d=new p;let c=0;const h=(e,t)=>{const r=Number(e);return Number.isFinite(r)&&r>0?r:t},l=e=>{const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0},m=e=>"string"==typeof e?e.trim():"";let y=class extends i.Renderer{constructor(){super(...arguments),this.name="SceneCapture",this.presentationAddFlushEnabled=!0,this.records=new Map,this.outputs=new Map,this.emptyCaptureRoot=new o.Container,this.participantId="scene-capture:"+ ++c,this.destroyed=!1}init(){if(this.renderSystem=this.game.getSystem(i.RendererSystem),!this.renderSystem)throw new Error("[SceneCapture] RendererSystem must be registered before SceneCaptureSystem.");this.renderSystem.rendererManager.register(this),this.ensurePresentationParticipant()}update(e){super.update(e),this.ensurePresentationParticipant()}lateUpdate(){var e;if(this.hasLivePresentationParticipant())return;const t=null===(e=this.renderSystem)||void 0===e?void 0:e.application;t&&this.captureForApplication(t)}componentChanged(e){if("SceneCapture"!==e.componentName)return;const r=e.component,i=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD)return void this.addRecord(i,r);if(e.type===t.OBSERVER_TYPE.REMOVE){const e=this.records.get(i);return void(e&&this.disposeRecord(e))}const o=this.records.get(i);o&&(o.component=r,this.resizeRecord(o),this.updateOutput(o),"manual"!==r.updateMode&&(o.dirty=!0),r.captureRevision!==o.lastCaptureRevision&&(o.dirty=!0))}getTexture(e){var t;return null===(t=this.outputs.get(m(e)))||void 0===t?void 0:t.texture}onDestroy(){var e;this.destroyed=!0,null===(e=this.presentationHandle)||void 0===e||e.dispose(),this.presentationHandle=void 0;for(const e of Array.from(this.records.values()))this.disposeRecord(e);try{this.emptyCaptureRoot.destroy({children:!1})}catch(e){}}addRecord(e,t){const r=this.records.get(e);r&&this.disposeRecord(r);const i={};_extends(i,{owner:i,gameObjectId:e,component:t,texture:this.createTexture(t),output:m(t.output),width:this.widthOf(t),height:this.heightOf(t),resolutionScale:this.resolutionOf(t),dirty:"manual"!==t.updateMode||t.captureRevision>0,lastCaptureRevision:0,disposed:!1,onCaptureRequested:()=>{i.disposed||(i.dirty=!0)}}),t.on("captureRequested",i.onCaptureRequested),this.records.set(e,i),this.bindOutput(i)}createTexture(e){return o.RenderTexture.create({width:this.widthOf(e),height:this.heightOf(e),resolution:this.resolutionOf(e)})}widthOf(e){return h(e.width,256)}heightOf(e){return h(e.height,256)}resolutionOf(e){return h(e.resolutionScale,1)}resizeRecord(e){const t=this.widthOf(e.component),r=this.heightOf(e.component),i=this.resolutionOf(e.component);if(e.width===t&&e.height===r&&e.resolutionScale===i)return;e.width=t,e.height=r,e.resolutionScale=i;const o=e.texture;if("function"==typeof o.resize)return void o.resize(t,r,i);const n=e.texture;e.texture=this.createTexture(e.component),this.bindOutput(e);try{n.destroy(!0)}catch(e){}}updateOutput(e){const t=m(e.component.output);e.output!==t&&(this.unbindOutput(e),e.output=t,this.bindOutput(e))}bindOutput(e){e.output&&(this.outputs.set(e.output,e),d.set(e.output,e.owner,e.texture))}unbindOutput(e){e.output&&(this.outputs.get(e.output)===e&&this.outputs.delete(e.output),d.delete(e.output,e.owner))}disposeRecord(e){if(!e.disposed){e.disposed=!0,this.records.delete(e.gameObjectId),this.unbindOutput(e);try{e.component.off("captureRequested",e.onCaptureRequested)}catch(e){}try{e.texture.destroy(!0)}catch(e){}}}ensurePresentationParticipant(){var e;if(this.destroyed||this.hasLivePresentationParticipant())return;const t=this.renderSystem;if(!(null==t?void 0:t.application)||"function"!=typeof t.registerPresentationParticipant)return;const r=null===(e=t.getPresentationApplicationId)||void 0===e?void 0:e.call(t,t.application);let i;i=t.registerPresentationParticipant({id:this.participantId,applicationId:r,build:()=>({writes:Array.from(this.outputs.keys(),e=>`scene-capture:${e}`)}),submit:e=>{this.captureForApplication(e.application)},dispose:()=>{this.presentationHandle===i&&(this.presentationHandle=void 0)}}),this.presentationHandle=i}hasLivePresentationParticipant(){return Boolean(this.presentationHandle&&!this.presentationHandle.disposed)}captureForApplication(e){const t=null==e?void 0:e.renderer;if(null==t?void 0:t.render)for(const r of this.records.values())this.shouldCapture(r)&&this.captureRecord(t,e,r)&&(r.dirty=!1,r.lastCaptureRevision=r.component.captureRevision)}shouldCapture(e){const t=e.component;return!e.disposed&&!1!==t.enabled&&("always"===t.updateMode||(t.captureRevision!==e.lastCaptureRevision&&(e.dirty=!0),e.dirty))}captureRecord(e,t,r){const i=this.resolveSourceContainers(r.component,t),o=this.toClearColor(r.component);try{if(0===i.length)return e.render({container:this.emptyCaptureRoot,target:r.texture,clear:!0,clearColor:o}),!0;for(let t=0;t<i.length;t++){const n=i[t],s={container:n,target:r.texture,clear:0===t};0===t&&(s.clearColor=o),n.worldTransform&&(s.transform=n.worldTransform),e.render(s)}return!0}catch(e){return!1}}resolveSourceContainers(e,t){var r;const i=[],o=Array.isArray(e.sourceNames)?e.sourceNames:[],n=this.game;for(const e of o){if(!e||"function"!=typeof(null==n?void 0:n.findAllByName))continue;const o=n.findAllByName(e);for(const e of o||[]){if(!e||e.destroyed)continue;const o=null===(r=this.containerManager)||void 0===r?void 0:r.getContainer(e.id);o&&!o.destroyed&&o!==t.stage&&o!==this.emptyCaptureRoot&&(i.includes(o)||i.push(o))}}return i}toClearColor(e){const t=(Number(e.clearColor)||0)>>>0;return[(t>>>16&255)/255,(t>>>8&255)/255,(255&t)/255,l(e.clearAlpha)]}};y.systemName="SceneCapture",y=n([t.decorators.componentObserver({SceneCapture:[{prop:["sourceNames"],deep:!0},{prop:["output"],deep:!1},{prop:["width"],deep:!1},{prop:["height"],deep:!1},{prop:["resolutionScale"],deep:!1},{prop:["updateMode"],deep:!1},{prop:["clearColor"],deep:!1},{prop:["clearAlpha"],deep:!1},{prop:["enabled"],deep:!1},{prop:["captureRevision"],deep:!1}]})],y);var g=y;return e.SceneCapture=u,e.SceneCaptureSystem=g,e.SceneCaptureTextureRegistry=p,e.getSceneCaptureTexture=function(e){return d.get(e)},e.sceneCaptureTextureRegistry=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,inspectorDecorator,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.scene.capture=globalThis.EVA.plugin.renderer.scene.capture||_EVA_IIFE_capture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-scene-capture",
3
- "version": "2.1.0-beta.14",
3
+ "version": "2.1.0-beta.15",
4
4
  "description": "Live Eva.js GameObject scene capture rendered into a Pixi RenderTexture.",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-scene-capture.esm.js",
@@ -17,9 +17,9 @@
17
17
  ],
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@eva/eva.js": "2.1.0-beta.14",
20
+ "@eva/eva.js": "2.1.0-beta.15",
21
21
  "@eva/inspector-decorator": "^2.0.0-beta.0",
22
- "@eva/plugin-renderer": "2.1.0-beta.14",
22
+ "@eva/plugin-renderer": "2.1.0-beta.15",
23
23
  "pixi.js": "8.19.0"
24
24
  }
25
25
  }