@eva/plugin-renderer-render-texture 2.1.0-beta.3 → 2.1.0-beta.4
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/EVA.plugin.renderer.render.texture.js +549 -0
- package/dist/EVA.plugin.renderer.render.texture.min.js +1 -0
- package/dist/plugin-renderer-render-texture.cjs.js +493 -0
- package/dist/plugin-renderer-render-texture.cjs.prod.js +1 -0
- package/dist/plugin-renderer-render-texture.d.ts +167 -0
- package/dist/plugin-renderer-render-texture.esm.js +488 -0
- package/package.json +3 -3
|
@@ -0,0 +1,549 @@
|
|
|
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
|
+
globalThis.EVA = globalThis.EVA || {};
|
|
3
|
+
globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
4
|
+
globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
|
|
5
|
+
globalThis.EVA.plugin.renderer.render = globalThis.EVA.plugin.renderer.render || {};
|
|
6
|
+
var _EVA_IIFE_texture = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
7
|
+
'use strict';
|
|
8
|
+
function __decorate(decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length,
|
|
10
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
11
|
+
d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
}
|
|
15
|
+
function __metadata(metadataKey, metadataValue) {
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
17
|
+
}
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) {
|
|
20
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
21
|
+
resolve(value);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.next(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function rejected(value) {
|
|
33
|
+
try {
|
|
34
|
+
step(generator["throw"](value));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function step(result) {
|
|
40
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
41
|
+
}
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
46
|
+
var e = new Error(message);
|
|
47
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
48
|
+
};
|
|
49
|
+
function __rest(s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
}
|
|
57
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
58
|
+
var e = new Error(message);
|
|
59
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
60
|
+
};
|
|
61
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
62
|
+
constructor() {
|
|
63
|
+
super('Symbol keys are not supported yet!');
|
|
64
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
68
|
+
function transformBasicType(type) {
|
|
69
|
+
if (type === String) {
|
|
70
|
+
return 'string';
|
|
71
|
+
}
|
|
72
|
+
if (type === Number) {
|
|
73
|
+
return 'number';
|
|
74
|
+
}
|
|
75
|
+
if (type === Boolean) {
|
|
76
|
+
return 'boolean';
|
|
77
|
+
}
|
|
78
|
+
return 'unknown';
|
|
79
|
+
}
|
|
80
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
81
|
+
const constructor = target.constructor;
|
|
82
|
+
const current = constructor.IDEProps || {};
|
|
83
|
+
current[propertyKey] = _extends(_extends({
|
|
84
|
+
key: propertyKey
|
|
85
|
+
}, current[propertyKey]), patch);
|
|
86
|
+
constructor.IDEProps = current;
|
|
87
|
+
}
|
|
88
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
89
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
90
|
+
let isArray = type === Array;
|
|
91
|
+
const str = transformBasicType(type);
|
|
92
|
+
if (str !== 'unknown') {
|
|
93
|
+
type = str;
|
|
94
|
+
}
|
|
95
|
+
if (returnTypeFunction) {
|
|
96
|
+
const returnType = returnTypeFunction();
|
|
97
|
+
if (Array.isArray(returnType)) {
|
|
98
|
+
isArray = true;
|
|
99
|
+
type = returnType[0];
|
|
100
|
+
} else {
|
|
101
|
+
type = returnType;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
105
|
+
const current = properties[key] || {};
|
|
106
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
107
|
+
type,
|
|
108
|
+
isArray: isArray
|
|
109
|
+
}), options);
|
|
110
|
+
properties[key] = property;
|
|
111
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
112
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
113
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
114
|
+
}
|
|
115
|
+
function type(type) {
|
|
116
|
+
return Field({
|
|
117
|
+
type
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
121
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
122
|
+
return {
|
|
123
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
124
|
+
options: maybeOptions || {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
options: returnTypeFuncOrOptions || {}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
132
|
+
return (target, propertyKey) => {
|
|
133
|
+
if (typeof propertyKey === 'symbol') {
|
|
134
|
+
throw new SymbolKeysNotSupportedError();
|
|
135
|
+
}
|
|
136
|
+
const {
|
|
137
|
+
options,
|
|
138
|
+
returnTypeFunc
|
|
139
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
140
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var ExecuteMode;
|
|
144
|
+
(function (ExecuteMode) {
|
|
145
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
146
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
147
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
148
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
149
|
+
class RenderTexture extends eva_js.Component {
|
|
150
|
+
constructor() {
|
|
151
|
+
super(...arguments);
|
|
152
|
+
this.width = 256;
|
|
153
|
+
this.height = 256;
|
|
154
|
+
this.ops = [];
|
|
155
|
+
this.backgroundColor = -1;
|
|
156
|
+
this.backgroundAlpha = 1;
|
|
157
|
+
this.append = true;
|
|
158
|
+
this.dirty = 0;
|
|
159
|
+
}
|
|
160
|
+
init(obj) {
|
|
161
|
+
if (obj) _extends(this, obj);
|
|
162
|
+
if (!Array.isArray(this.ops)) this.ops = [];
|
|
163
|
+
}
|
|
164
|
+
addOp(op) {
|
|
165
|
+
this.ops = [...this.ops, op];
|
|
166
|
+
this.dirty++;
|
|
167
|
+
}
|
|
168
|
+
clearOps() {
|
|
169
|
+
this.ops = [{
|
|
170
|
+
type: 'clear'
|
|
171
|
+
}];
|
|
172
|
+
this.dirty++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
RenderTexture.componentName = 'RenderTexture';
|
|
176
|
+
__decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "width", void 0);
|
|
177
|
+
__decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "height", void 0);
|
|
178
|
+
__decorate([type('array'), __metadata("design:type", Array)], RenderTexture.prototype, "ops", void 0);
|
|
179
|
+
__decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "backgroundColor", void 0);
|
|
180
|
+
__decorate([type('number'), __metadata("design:type", Number)], RenderTexture.prototype, "backgroundAlpha", void 0);
|
|
181
|
+
const FRAME_SEP = '#';
|
|
182
|
+
let RenderTextureSystem = class RenderTextureSystem extends pluginRenderer.Renderer {
|
|
183
|
+
constructor() {
|
|
184
|
+
super(...arguments);
|
|
185
|
+
this.name = 'RenderTexture';
|
|
186
|
+
this.records = {};
|
|
187
|
+
}
|
|
188
|
+
init() {
|
|
189
|
+
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
190
|
+
this.renderSystem.rendererManager.register(this);
|
|
191
|
+
}
|
|
192
|
+
rendererUpdate(gameObject) {
|
|
193
|
+
const record = this.records[gameObject.id];
|
|
194
|
+
if (!record) return;
|
|
195
|
+
if (record.needsReplay) {
|
|
196
|
+
record.needsReplay = false;
|
|
197
|
+
this.replay(gameObject.id);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
componentChanged(changed) {
|
|
201
|
+
var _a, _b, _c, _d;
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
if (changed.componentName !== 'RenderTexture') return;
|
|
204
|
+
const component = changed.component;
|
|
205
|
+
const gameObjectId = changed.gameObject.id;
|
|
206
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
207
|
+
const rt = pixi_js.RenderTexture.create({
|
|
208
|
+
width: Math.max(1, component.width || 1),
|
|
209
|
+
height: Math.max(1, component.height || 1),
|
|
210
|
+
resolution: 1
|
|
211
|
+
});
|
|
212
|
+
const sprite = new pixi_js.Sprite(rt);
|
|
213
|
+
sprite.width = component.width;
|
|
214
|
+
sprite.height = component.height;
|
|
215
|
+
this.containerManager.getContainer(gameObjectId).addChildAt(sprite, 0);
|
|
216
|
+
this.records[gameObjectId] = {
|
|
217
|
+
rt,
|
|
218
|
+
sprite,
|
|
219
|
+
component,
|
|
220
|
+
lastSig: '',
|
|
221
|
+
needsReplay: true
|
|
222
|
+
};
|
|
223
|
+
this.maybeSave(gameObjectId);
|
|
224
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
|
|
225
|
+
const record = this.records[gameObjectId];
|
|
226
|
+
if (!record) return;
|
|
227
|
+
record.component = component;
|
|
228
|
+
if (record.rt.width !== component.width || record.rt.height !== component.height) {
|
|
229
|
+
try {
|
|
230
|
+
(_b = (_a = record.rt).resize) === null || _b === void 0 ? void 0 : _b.call(_a, Math.max(1, component.width), Math.max(1, component.height));
|
|
231
|
+
} catch (e) {}
|
|
232
|
+
record.sprite.width = component.width;
|
|
233
|
+
record.sprite.height = component.height;
|
|
234
|
+
}
|
|
235
|
+
record.needsReplay = true;
|
|
236
|
+
this.maybeSave(gameObjectId);
|
|
237
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
238
|
+
const record = this.records[gameObjectId];
|
|
239
|
+
if (!record) return;
|
|
240
|
+
(_d = (_c = this.containerManager) === null || _c === void 0 ? void 0 : _c.getContainer(gameObjectId)) === null || _d === void 0 ? void 0 : _d.removeChild(record.sprite);
|
|
241
|
+
record.sprite.destroy({
|
|
242
|
+
children: true
|
|
243
|
+
});
|
|
244
|
+
record.rt.destroy(true);
|
|
245
|
+
delete this.records[gameObjectId];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
resolveTexture(name, explicitFrame) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
if (!name) return null;
|
|
252
|
+
let resName = name;
|
|
253
|
+
let frame = explicitFrame;
|
|
254
|
+
if (!frame && name.includes(FRAME_SEP)) {
|
|
255
|
+
const idx = name.indexOf(FRAME_SEP);
|
|
256
|
+
resName = name.slice(0, idx);
|
|
257
|
+
frame = name.slice(idx + 1);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
const {
|
|
261
|
+
instance
|
|
262
|
+
} = yield eva_js.resource.getResource(resName);
|
|
263
|
+
if (!instance) return null;
|
|
264
|
+
if (frame) {
|
|
265
|
+
if (instance && instance[frame] instanceof pixi_js.Texture) {
|
|
266
|
+
return instance[frame];
|
|
267
|
+
}
|
|
268
|
+
const textures = instance.textures;
|
|
269
|
+
if (textures && textures[frame] instanceof pixi_js.Texture) {
|
|
270
|
+
return textures[frame];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (instance instanceof pixi_js.Texture) return instance;
|
|
274
|
+
if (instance.baseTexture) return instance;
|
|
275
|
+
if (typeof instance === 'object') {
|
|
276
|
+
const keys = Object.keys(instance);
|
|
277
|
+
for (const k of keys) {
|
|
278
|
+
const v = instance[k];
|
|
279
|
+
if (v instanceof pixi_js.Texture) return v;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
} catch (_a) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
replay(gameObjectId) {
|
|
289
|
+
var _a, _b, _c, _d, _e, _f;
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const record = this.records[gameObjectId];
|
|
292
|
+
if (!record) return;
|
|
293
|
+
const {
|
|
294
|
+
rt,
|
|
295
|
+
component
|
|
296
|
+
} = record;
|
|
297
|
+
const sig = `${component.dirty}|${(_b = (_a = component.ops) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0}|${component.width}|${component.height}`;
|
|
298
|
+
if (record.lastSig === sig && component.append) ;
|
|
299
|
+
record.lastSig = sig;
|
|
300
|
+
const renderer = (_c = this.renderSystem.application) === null || _c === void 0 ? void 0 : _c.renderer;
|
|
301
|
+
if (!renderer) return;
|
|
302
|
+
const stage = new pixi_js.Container();
|
|
303
|
+
const bg = component.backgroundColor;
|
|
304
|
+
const bgA = (_d = component.backgroundAlpha) !== null && _d !== void 0 ? _d : 1;
|
|
305
|
+
if (!component.append) {
|
|
306
|
+
const g = new pixi_js.Graphics();
|
|
307
|
+
if (bg != null && bg >= 0) {
|
|
308
|
+
g.rect(0, 0, component.width, component.height).fill({
|
|
309
|
+
color: bg,
|
|
310
|
+
alpha: bgA
|
|
311
|
+
});
|
|
312
|
+
} else {
|
|
313
|
+
g.rect(0, 0, component.width, component.height).fill({
|
|
314
|
+
color: 0x000000,
|
|
315
|
+
alpha: 0
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
stage.addChild(g);
|
|
319
|
+
}
|
|
320
|
+
for (const op of component.ops || []) {
|
|
321
|
+
const node = yield this.buildOpNode(op);
|
|
322
|
+
if (node) stage.addChild(node);
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
renderer.render({
|
|
326
|
+
container: stage,
|
|
327
|
+
target: rt,
|
|
328
|
+
clear: !component.append
|
|
329
|
+
});
|
|
330
|
+
if (globalThis.__RT_DEBUG) {
|
|
331
|
+
console.log('[RT] replayed', {
|
|
332
|
+
ops: (_e = component.ops) === null || _e === void 0 ? void 0 : _e.length,
|
|
333
|
+
w: rt.width,
|
|
334
|
+
h: rt.height,
|
|
335
|
+
stageChildren: (_f = stage.children) === null || _f === void 0 ? void 0 : _f.length
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
} catch (e) {
|
|
339
|
+
try {
|
|
340
|
+
renderer.render(stage, {
|
|
341
|
+
renderTexture: rt,
|
|
342
|
+
clear: !component.append
|
|
343
|
+
});
|
|
344
|
+
} catch (_g) {
|
|
345
|
+
console.warn('[RenderTexture] renderer.render failed', e);
|
|
346
|
+
}
|
|
347
|
+
} finally {
|
|
348
|
+
Promise.resolve().then(() => {
|
|
349
|
+
try {
|
|
350
|
+
stage.destroy({
|
|
351
|
+
children: true
|
|
352
|
+
});
|
|
353
|
+
} catch (_a) {}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
buildOpNode(op) {
|
|
359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
|
360
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
if (op.type === 'clear') {
|
|
362
|
+
const g = new pixi_js.Graphics();
|
|
363
|
+
g.rect(0, 0, 1e6, 1e6).fill({
|
|
364
|
+
color: 0x000000,
|
|
365
|
+
alpha: 0
|
|
366
|
+
});
|
|
367
|
+
return g;
|
|
368
|
+
}
|
|
369
|
+
if (op.type === 'fill') {
|
|
370
|
+
const g = new pixi_js.Graphics();
|
|
371
|
+
const x = (_a = op.x) !== null && _a !== void 0 ? _a : 0;
|
|
372
|
+
const y = (_b = op.y) !== null && _b !== void 0 ? _b : 0;
|
|
373
|
+
const w = (_c = op.width) !== null && _c !== void 0 ? _c : 1e6;
|
|
374
|
+
const h = (_d = op.height) !== null && _d !== void 0 ? _d : 1e6;
|
|
375
|
+
g.rect(x, y, w, h).fill({
|
|
376
|
+
color: op.color,
|
|
377
|
+
alpha: (_e = op.alpha) !== null && _e !== void 0 ? _e : 1
|
|
378
|
+
});
|
|
379
|
+
return g;
|
|
380
|
+
}
|
|
381
|
+
if (op.type === 'draw' || op.type === 'drawFrame') {
|
|
382
|
+
const tex = yield this.resolveTexture(op.resource, op.frame);
|
|
383
|
+
if (!tex) return null;
|
|
384
|
+
const sp = new pixi_js.Sprite(tex);
|
|
385
|
+
sp.x = (_f = op.x) !== null && _f !== void 0 ? _f : 0;
|
|
386
|
+
sp.y = (_g = op.y) !== null && _g !== void 0 ? _g : 0;
|
|
387
|
+
const o = op;
|
|
388
|
+
sp.alpha = (_h = o.alpha) !== null && _h !== void 0 ? _h : 1;
|
|
389
|
+
if (o.tint != null) sp.tint = o.tint;
|
|
390
|
+
if (o.width != null) sp.width = o.width;
|
|
391
|
+
if (o.height != null) sp.height = o.height;
|
|
392
|
+
if (o.rotation != null) sp.rotation = o.rotation;
|
|
393
|
+
if (o.anchorX != null || o.anchorY != null) {
|
|
394
|
+
sp.anchor.set((_j = o.anchorX) !== null && _j !== void 0 ? _j : 0, (_k = o.anchorY) !== null && _k !== void 0 ? _k : 0);
|
|
395
|
+
}
|
|
396
|
+
if (o.scaleX != null || o.scaleY != null) {
|
|
397
|
+
sp.scale.set((_l = o.scaleX) !== null && _l !== void 0 ? _l : 1, (_m = o.scaleY) !== null && _m !== void 0 ? _m : 1);
|
|
398
|
+
}
|
|
399
|
+
if (o.blendMode) {
|
|
400
|
+
try {
|
|
401
|
+
sp.blendMode = o.blendMode;
|
|
402
|
+
} catch (_15) {}
|
|
403
|
+
}
|
|
404
|
+
return sp;
|
|
405
|
+
}
|
|
406
|
+
if (op.type === 'erase') {
|
|
407
|
+
const g = new pixi_js.Graphics();
|
|
408
|
+
const w = (_o = op.width) !== null && _o !== void 0 ? _o : 16;
|
|
409
|
+
const h = (_p = op.height) !== null && _p !== void 0 ? _p : 16;
|
|
410
|
+
const ax = (_q = op.anchorX) !== null && _q !== void 0 ? _q : 0;
|
|
411
|
+
const ay = (_r = op.anchorY) !== null && _r !== void 0 ? _r : 0;
|
|
412
|
+
const x = ((_s = op.x) !== null && _s !== void 0 ? _s : 0) - w * ax;
|
|
413
|
+
const y = ((_t = op.y) !== null && _t !== void 0 ? _t : 0) - h * ay;
|
|
414
|
+
g.rect(x, y, w, h).fill({
|
|
415
|
+
color: 0xffffff,
|
|
416
|
+
alpha: 1
|
|
417
|
+
});
|
|
418
|
+
try {
|
|
419
|
+
g.blendMode = 'erase';
|
|
420
|
+
} catch (_16) {}
|
|
421
|
+
return g;
|
|
422
|
+
}
|
|
423
|
+
if (op.type === 'drawText') {
|
|
424
|
+
const t = new pixi_js.Text({
|
|
425
|
+
text: op.text,
|
|
426
|
+
style: {
|
|
427
|
+
fontFamily: (_v = (_u = op.style) === null || _u === void 0 ? void 0 : _u.fontFamily) !== null && _v !== void 0 ? _v : 'Arial',
|
|
428
|
+
fontSize: (_x = (_w = op.style) === null || _w === void 0 ? void 0 : _w.fontSize) !== null && _x !== void 0 ? _x : 32,
|
|
429
|
+
fontWeight: (_z = (_y = op.style) === null || _y === void 0 ? void 0 : _y.fontWeight) !== null && _z !== void 0 ? _z : 'normal',
|
|
430
|
+
fill: (_1 = (_0 = op.style) === null || _0 === void 0 ? void 0 : _0.fill) !== null && _1 !== void 0 ? _1 : 0xffffff,
|
|
431
|
+
stroke: (_2 = op.style) === null || _2 === void 0 ? void 0 : _2.stroke,
|
|
432
|
+
align: (_4 = (_3 = op.style) === null || _3 === void 0 ? void 0 : _3.align) !== null && _4 !== void 0 ? _4 : 'left'
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
t.x = (_5 = op.x) !== null && _5 !== void 0 ? _5 : 0;
|
|
436
|
+
t.y = (_6 = op.y) !== null && _6 !== void 0 ? _6 : 0;
|
|
437
|
+
if (op.alpha != null) t.alpha = op.alpha;
|
|
438
|
+
if (op.tint != null) t.tint = op.tint;
|
|
439
|
+
return t;
|
|
440
|
+
}
|
|
441
|
+
if (op.type === 'paint') {
|
|
442
|
+
const tex = yield this.resolveTexture(op.resource, op.frame);
|
|
443
|
+
if (!tex) return null;
|
|
444
|
+
const c = new pixi_js.Container();
|
|
445
|
+
const times = Math.max(1, (_7 = op.times) !== null && _7 !== void 0 ? _7 : 1);
|
|
446
|
+
const dx = (_9 = (_8 = op.step) === null || _8 === void 0 ? void 0 : _8.x) !== null && _9 !== void 0 ? _9 : 0;
|
|
447
|
+
const dy = (_11 = (_10 = op.step) === null || _10 === void 0 ? void 0 : _10.y) !== null && _11 !== void 0 ? _11 : 0;
|
|
448
|
+
for (let i = 0; i < times; i++) {
|
|
449
|
+
const sp = new pixi_js.Sprite(tex);
|
|
450
|
+
sp.x = ((_12 = op.x) !== null && _12 !== void 0 ? _12 : 0) + dx * i;
|
|
451
|
+
sp.y = ((_13 = op.y) !== null && _13 !== void 0 ? _13 : 0) + dy * i;
|
|
452
|
+
sp.anchor.set(0.5, 0.5);
|
|
453
|
+
sp.alpha = (_14 = op.alpha) !== null && _14 !== void 0 ? _14 : 1;
|
|
454
|
+
if (op.tintCycle && op.tintCycle.length > 0) {
|
|
455
|
+
sp.tint = op.tintCycle[i % op.tintCycle.length];
|
|
456
|
+
} else if (op.tint != null) {
|
|
457
|
+
sp.tint = op.tint;
|
|
458
|
+
}
|
|
459
|
+
c.addChild(sp);
|
|
460
|
+
}
|
|
461
|
+
return c;
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
maybeSave(gameObjectId) {
|
|
467
|
+
var _a;
|
|
468
|
+
const record = this.records[gameObjectId];
|
|
469
|
+
if (!record) return;
|
|
470
|
+
const key = record.component.saveAs;
|
|
471
|
+
if (!key) return;
|
|
472
|
+
try {
|
|
473
|
+
const existing = (_a = eva_js.resource.resourcesMap) === null || _a === void 0 ? void 0 : _a[key];
|
|
474
|
+
if (existing) {
|
|
475
|
+
existing.complete = true;
|
|
476
|
+
existing.instance = record.rt;
|
|
477
|
+
const promiseMap = eva_js.resource.promiseMap;
|
|
478
|
+
if (promiseMap) {
|
|
479
|
+
promiseMap[key] = Promise.resolve({
|
|
480
|
+
instance: record.rt,
|
|
481
|
+
name: key
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
eva_js.resource.resourcesMap = eva_js.resource.resourcesMap || {};
|
|
487
|
+
eva_js.resource.resourcesMap[key] = {
|
|
488
|
+
name: key,
|
|
489
|
+
type: 'IMAGE',
|
|
490
|
+
complete: true,
|
|
491
|
+
instance: record.rt,
|
|
492
|
+
data: {}
|
|
493
|
+
};
|
|
494
|
+
const promiseMap = eva_js.resource.promiseMap;
|
|
495
|
+
if (promiseMap) {
|
|
496
|
+
promiseMap[key] = Promise.resolve({
|
|
497
|
+
instance: record.rt,
|
|
498
|
+
name: key
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
} catch (e) {
|
|
502
|
+
console.warn('[RenderTexture] saveAs failed', e);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
destroy() {
|
|
506
|
+
var _a, _b;
|
|
507
|
+
for (const key in this.records) {
|
|
508
|
+
const id = parseInt(key);
|
|
509
|
+
const record = this.records[id];
|
|
510
|
+
(_b = (_a = this.containerManager) === null || _a === void 0 ? void 0 : _a.getContainer(id)) === null || _b === void 0 ? void 0 : _b.removeChild(record.sprite);
|
|
511
|
+
record.sprite.destroy({
|
|
512
|
+
children: true
|
|
513
|
+
});
|
|
514
|
+
record.rt.destroy(true);
|
|
515
|
+
delete this.records[id];
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
RenderTextureSystem.systemName = 'RenderTexture';
|
|
520
|
+
RenderTextureSystem = __decorate([eva_js.decorators.componentObserver({
|
|
521
|
+
RenderTexture: [{
|
|
522
|
+
prop: ['width'],
|
|
523
|
+
deep: false
|
|
524
|
+
}, {
|
|
525
|
+
prop: ['height'],
|
|
526
|
+
deep: false
|
|
527
|
+
}, {
|
|
528
|
+
prop: ['ops'],
|
|
529
|
+
deep: true
|
|
530
|
+
}, {
|
|
531
|
+
prop: ['dirty'],
|
|
532
|
+
deep: false
|
|
533
|
+
}, {
|
|
534
|
+
prop: ['backgroundColor'],
|
|
535
|
+
deep: false
|
|
536
|
+
}, {
|
|
537
|
+
prop: ['backgroundAlpha'],
|
|
538
|
+
deep: false
|
|
539
|
+
}]
|
|
540
|
+
})], RenderTextureSystem);
|
|
541
|
+
var RenderTextureSystem$1 = RenderTextureSystem;
|
|
542
|
+
exports.RenderTexture = RenderTexture;
|
|
543
|
+
exports.RenderTextureSystem = RenderTextureSystem$1;
|
|
544
|
+
Object.defineProperty(exports, '__esModule', {
|
|
545
|
+
value: true
|
|
546
|
+
});
|
|
547
|
+
return exports;
|
|
548
|
+
}({}, EVA, EVA.plugin.renderer, PIXI);
|
|
549
|
+
globalThis.EVA.plugin.renderer.render.texture = globalThis.EVA.plugin.renderer.render.texture || _EVA_IIFE_texture;
|
|
@@ -0,0 +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.render=globalThis.EVA.plugin.renderer.render||{};var _EVA_IIFE_texture=function(e,t,r,n){"use strict";function o(e,t,r,n){var o,i=arguments.length,l=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(l=(i<3?o(l):i>3?o(t,r,l):o(t,r))||l);return i>3&&l&&Object.defineProperty(t,r,l),l}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t,r,n){return new(r||(r=Promise))(function(o,i){function l(e){try{d(n.next(e))}catch(e){i(e)}}function s(e){try{d(n.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(l,s)}d((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class s extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const d="IDE_PROPERTY_METADATA";function a(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const l=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==l&&(o=l),n){const e=n();Array.isArray(e)?(i=!0,o=e[0]):o=e}const s=Reflect.getMetadata(d,e.constructor)||{},a=_extends(_extends(_extends({},s[t]||{}),{type:o,isArray:i}),r);s[t]=a,Reflect.defineMetadata(d,s,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}(a,["isArray"]))}function c(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);a(e,n,o,i)};var t,r}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class p extends t.Component{constructor(){super(...arguments),this.width=256,this.height=256,this.ops=[],this.backgroundColor=-1,this.backgroundAlpha=1,this.append=!0,this.dirty=0}init(e){e&&_extends(this,e),Array.isArray(this.ops)||(this.ops=[])}addOp(e){this.ops=[...this.ops,e],this.dirty++}clearOps(){this.ops=[{type:"clear"}],this.dirty++}}p.componentName="RenderTexture",o([c("number"),i("design:type",Number)],p.prototype,"width",void 0),o([c("number"),i("design:type",Number)],p.prototype,"height",void 0),o([c("array"),i("design:type",Array)],p.prototype,"ops",void 0),o([c("number"),i("design:type",Number)],p.prototype,"backgroundColor",void 0),o([c("number"),i("design:type",Number)],p.prototype,"backgroundAlpha",void 0);let h=class extends r.Renderer{constructor(){super(...arguments),this.name="RenderTexture",this.records={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const t=this.records[e.id];t&&t.needsReplay&&(t.needsReplay=!1,this.replay(e.id))}componentChanged(e){var r,o,i,s;return l(this,void 0,void 0,function*(){if("RenderTexture"!==e.componentName)return;const l=e.component,d=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){const e=n.RenderTexture.create({width:Math.max(1,l.width||1),height:Math.max(1,l.height||1),resolution:1}),t=new n.Sprite(e);t.width=l.width,t.height=l.height,this.containerManager.getContainer(d).addChildAt(t,0),this.records[d]={rt:e,sprite:t,component:l,lastSig:"",needsReplay:!0},this.maybeSave(d)}else if(e.type===t.OBSERVER_TYPE.CHANGE){const e=this.records[d];if(!e)return;if(e.component=l,e.rt.width!==l.width||e.rt.height!==l.height){try{null===(o=(r=e.rt).resize)||void 0===o||o.call(r,Math.max(1,l.width),Math.max(1,l.height))}catch(e){}e.sprite.width=l.width,e.sprite.height=l.height}e.needsReplay=!0,this.maybeSave(d)}else if(e.type===t.OBSERVER_TYPE.REMOVE){const e=this.records[d];if(!e)return;null===(s=null===(i=this.containerManager)||void 0===i?void 0:i.getContainer(d))||void 0===s||s.removeChild(e.sprite),e.sprite.destroy({children:!0}),e.rt.destroy(!0),delete this.records[d]}})}resolveTexture(e,r){return l(this,void 0,void 0,function*(){if(!e)return null;let o=e,i=r;if(!i&&e.includes("#")){const t=e.indexOf("#");o=e.slice(0,t),i=e.slice(t+1)}try{const{instance:e}=yield t.resource.getResource(o);if(!e)return null;if(i){if(e&&e[i]instanceof n.Texture)return e[i];const t=e.textures;if(t&&t[i]instanceof n.Texture)return t[i]}if(e instanceof n.Texture)return e;if(e.baseTexture)return e;if("object"==typeof e){const t=Object.keys(e);for(const r of t){const t=e[r];if(t instanceof n.Texture)return t}}return null}catch(e){return null}})}replay(e){var t,r,o,i,s,d;return l(this,void 0,void 0,function*(){const l=this.records[e];if(!l)return;const{rt:a,component:c}=l,u=`${c.dirty}|${null!==(r=null===(t=c.ops)||void 0===t?void 0:t.length)&&void 0!==r?r:0}|${c.width}|${c.height}`;l.lastSig===u&&c.append,l.lastSig=u;const p=null===(o=this.renderSystem.application)||void 0===o?void 0:o.renderer;if(!p)return;const h=new n.Container,y=c.backgroundColor,f=null!==(i=c.backgroundAlpha)&&void 0!==i?i:1;if(!c.append){const e=new n.Graphics;null!=y&&y>=0?e.rect(0,0,c.width,c.height).fill({color:y,alpha:f}):e.rect(0,0,c.width,c.height).fill({color:0,alpha:0}),h.addChild(e)}for(const e of c.ops||[]){const t=yield this.buildOpNode(e);t&&h.addChild(t)}try{p.render({container:h,target:a,clear:!c.append}),globalThis.__RT_DEBUG&&console.log("[RT] replayed",{ops:null===(s=c.ops)||void 0===s?void 0:s.length,w:a.width,h:a.height,stageChildren:null===(d=h.children)||void 0===d?void 0:d.length})}catch(e){try{p.render(h,{renderTexture:a,clear:!c.append})}catch(t){console.warn("[RenderTexture] renderer.render failed",e)}}finally{Promise.resolve().then(()=>{try{h.destroy({children:!0})}catch(e){}})}})}buildOpNode(e){var t,r,o,i,s,d,a,c,u,p,h,y,f,v,g,m,b,x,w,E,T,A,R,O,S,M,_,C,P,V,j,k,I,N,G,Y,D,F,X;return l(this,void 0,void 0,function*(){if("clear"===e.type){const e=new n.Graphics;return e.rect(0,0,1e6,1e6).fill({color:0,alpha:0}),e}if("fill"===e.type){const l=new n.Graphics,d=null!==(t=e.x)&&void 0!==t?t:0,a=null!==(r=e.y)&&void 0!==r?r:0,c=null!==(o=e.width)&&void 0!==o?o:1e6,u=null!==(i=e.height)&&void 0!==i?i:1e6;return l.rect(d,a,c,u).fill({color:e.color,alpha:null!==(s=e.alpha)&&void 0!==s?s:1}),l}if("draw"===e.type||"drawFrame"===e.type){const t=yield this.resolveTexture(e.resource,e.frame);if(!t)return null;const r=new n.Sprite(t);r.x=null!==(d=e.x)&&void 0!==d?d:0,r.y=null!==(a=e.y)&&void 0!==a?a:0;const o=e;if(r.alpha=null!==(c=o.alpha)&&void 0!==c?c:1,null!=o.tint&&(r.tint=o.tint),null!=o.width&&(r.width=o.width),null!=o.height&&(r.height=o.height),null!=o.rotation&&(r.rotation=o.rotation),null==o.anchorX&&null==o.anchorY||r.anchor.set(null!==(u=o.anchorX)&&void 0!==u?u:0,null!==(p=o.anchorY)&&void 0!==p?p:0),null==o.scaleX&&null==o.scaleY||r.scale.set(null!==(h=o.scaleX)&&void 0!==h?h:1,null!==(y=o.scaleY)&&void 0!==y?y:1),o.blendMode)try{r.blendMode=o.blendMode}catch(e){}return r}if("erase"===e.type){const t=new n.Graphics,r=null!==(f=e.width)&&void 0!==f?f:16,o=null!==(v=e.height)&&void 0!==v?v:16,i=null!==(g=e.anchorX)&&void 0!==g?g:0,l=null!==(m=e.anchorY)&&void 0!==m?m:0,s=(null!==(b=e.x)&&void 0!==b?b:0)-r*i,d=(null!==(x=e.y)&&void 0!==x?x:0)-o*l;t.rect(s,d,r,o).fill({color:16777215,alpha:1});try{t.blendMode="erase"}catch(e){}return t}if("drawText"===e.type){const t=new n.Text({text:e.text,style:{fontFamily:null!==(E=null===(w=e.style)||void 0===w?void 0:w.fontFamily)&&void 0!==E?E:"Arial",fontSize:null!==(A=null===(T=e.style)||void 0===T?void 0:T.fontSize)&&void 0!==A?A:32,fontWeight:null!==(O=null===(R=e.style)||void 0===R?void 0:R.fontWeight)&&void 0!==O?O:"normal",fill:null!==(M=null===(S=e.style)||void 0===S?void 0:S.fill)&&void 0!==M?M:16777215,stroke:null===(_=e.style)||void 0===_?void 0:_.stroke,align:null!==(P=null===(C=e.style)||void 0===C?void 0:C.align)&&void 0!==P?P:"left"}});return t.x=null!==(V=e.x)&&void 0!==V?V:0,t.y=null!==(j=e.y)&&void 0!==j?j:0,null!=e.alpha&&(t.alpha=e.alpha),null!=e.tint&&(t.tint=e.tint),t}if("paint"===e.type){const t=yield this.resolveTexture(e.resource,e.frame);if(!t)return null;const r=new n.Container,o=Math.max(1,null!==(k=e.times)&&void 0!==k?k:1),i=null!==(N=null===(I=e.step)||void 0===I?void 0:I.x)&&void 0!==N?N:0,l=null!==(Y=null===(G=e.step)||void 0===G?void 0:G.y)&&void 0!==Y?Y:0;for(let s=0;s<o;s++){const o=new n.Sprite(t);o.x=(null!==(D=e.x)&&void 0!==D?D:0)+i*s,o.y=(null!==(F=e.y)&&void 0!==F?F:0)+l*s,o.anchor.set(.5,.5),o.alpha=null!==(X=e.alpha)&&void 0!==X?X:1,e.tintCycle&&e.tintCycle.length>0?o.tint=e.tintCycle[s%e.tintCycle.length]:null!=e.tint&&(o.tint=e.tint),r.addChild(o)}return r}return null})}maybeSave(e){var r;const n=this.records[e];if(!n)return;const o=n.component.saveAs;if(o)try{const e=null===(r=t.resource.resourcesMap)||void 0===r?void 0:r[o];if(e){e.complete=!0,e.instance=n.rt;const r=t.resource.promiseMap;return void(r&&(r[o]=Promise.resolve({instance:n.rt,name:o})))}t.resource.resourcesMap=t.resource.resourcesMap||{},t.resource.resourcesMap[o]={name:o,type:"IMAGE",complete:!0,instance:n.rt,data:{}};const i=t.resource.promiseMap;i&&(i[o]=Promise.resolve({instance:n.rt,name:o}))}catch(e){console.warn("[RenderTexture] saveAs failed",e)}}destroy(){var e,t;for(const r in this.records){const n=parseInt(r),o=this.records[n];null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(n))||void 0===t||t.removeChild(o.sprite),o.sprite.destroy({children:!0}),o.rt.destroy(!0),delete this.records[n]}}};h.systemName="RenderTexture",h=o([t.decorators.componentObserver({RenderTexture:[{prop:["width"],deep:!1},{prop:["height"],deep:!1},{prop:["ops"],deep:!0},{prop:["dirty"],deep:!1},{prop:["backgroundColor"],deep:!1},{prop:["backgroundAlpha"],deep:!1}]})],h);var y=h;return e.RenderTexture=p,e.RenderTextureSystem=y,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.render.texture=globalThis.EVA.plugin.renderer.render.texture||_EVA_IIFE_texture;
|