@galacean/effects-plugin-stats 0.0.0-experimental-20250512
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/LICENSE +22 -0
- package/README.md +1 -0
- package/dist/core.d.ts +45 -0
- package/dist/hooks/drawcall-hook.d.ts +20 -0
- package/dist/hooks/program-hook.d.ts +15 -0
- package/dist/hooks/shader-hook.d.ts +16 -0
- package/dist/hooks/texture-hook.d.ts +16 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +763 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +8 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.mjs +739 -0
- package/dist/index.mjs.map +1 -0
- package/dist/monitor.d.ts +31 -0
- package/dist/stats-component.d.ts +12 -0
- package/dist/stats.d.ts +37 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Name: @galacean/effects-plugin-stats
|
|
3
|
+
* Description: Galacean Effects runtime stats for the web
|
|
4
|
+
* Author: Ant Group CO., Ltd.
|
|
5
|
+
* Contributors: 云垣
|
|
6
|
+
* Version: v0.0.0-experimental-20250512
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
12
|
+
|
|
13
|
+
var EFFECTS = require('@galacean/effects');
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n["default"] = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var EFFECTS__namespace = /*#__PURE__*/_interopNamespace(EFFECTS);
|
|
34
|
+
|
|
35
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
36
|
+
try {
|
|
37
|
+
var info = gen[key](arg);
|
|
38
|
+
var value = info.value;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
reject(error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (info.done) resolve(value);
|
|
44
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
45
|
+
}
|
|
46
|
+
function _async_to_generator(fn) {
|
|
47
|
+
return function() {
|
|
48
|
+
var self = this, args = arguments;
|
|
49
|
+
return new Promise(function(resolve, reject) {
|
|
50
|
+
var gen = fn.apply(self, args);
|
|
51
|
+
function _next(value) {
|
|
52
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
53
|
+
}
|
|
54
|
+
function _throw(err) {
|
|
55
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
56
|
+
}
|
|
57
|
+
_next(undefined);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _extends() {
|
|
63
|
+
_extends = Object.assign || function assign(target) {
|
|
64
|
+
for(var i = 1; i < arguments.length; i++){
|
|
65
|
+
var source = arguments[i];
|
|
66
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
67
|
+
}
|
|
68
|
+
return target;
|
|
69
|
+
};
|
|
70
|
+
return _extends.apply(this, arguments);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _instanceof1(left, right) {
|
|
74
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
75
|
+
return !!right[Symbol.hasInstance](left);
|
|
76
|
+
} else return _instanceof1(left, right);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function __generator(thisArg, body) {
|
|
80
|
+
var _ = {
|
|
81
|
+
label: 0,
|
|
82
|
+
sent: function sent() {
|
|
83
|
+
if (t[0] & 1) throw t[1];
|
|
84
|
+
return t[1];
|
|
85
|
+
},
|
|
86
|
+
trys: [],
|
|
87
|
+
ops: []
|
|
88
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
89
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
90
|
+
return this;
|
|
91
|
+
}), g;
|
|
92
|
+
function verb(n) {
|
|
93
|
+
return function(v) {
|
|
94
|
+
return step([
|
|
95
|
+
n,
|
|
96
|
+
v
|
|
97
|
+
]);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function step(op) {
|
|
101
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
102
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
103
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
104
|
+
if (y = 0, t) op = [
|
|
105
|
+
op[0] & 2,
|
|
106
|
+
t.value
|
|
107
|
+
];
|
|
108
|
+
switch(op[0]){
|
|
109
|
+
case 0:
|
|
110
|
+
case 1:
|
|
111
|
+
t = op;
|
|
112
|
+
break;
|
|
113
|
+
case 4:
|
|
114
|
+
_.label++;
|
|
115
|
+
return {
|
|
116
|
+
value: op[1],
|
|
117
|
+
done: false
|
|
118
|
+
};
|
|
119
|
+
case 5:
|
|
120
|
+
_.label++;
|
|
121
|
+
y = op[1];
|
|
122
|
+
op = [
|
|
123
|
+
0
|
|
124
|
+
];
|
|
125
|
+
continue;
|
|
126
|
+
case 7:
|
|
127
|
+
op = _.ops.pop();
|
|
128
|
+
_.trys.pop();
|
|
129
|
+
continue;
|
|
130
|
+
default:
|
|
131
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
132
|
+
_ = 0;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
136
|
+
_.label = op[1];
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
140
|
+
_.label = t[1];
|
|
141
|
+
t = op;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (t && _.label < t[2]) {
|
|
145
|
+
_.label = t[2];
|
|
146
|
+
_.ops.push(op);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (t[2]) _.ops.pop();
|
|
150
|
+
_.trys.pop();
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
op = body.call(thisArg, _);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
op = [
|
|
156
|
+
6,
|
|
157
|
+
e
|
|
158
|
+
];
|
|
159
|
+
y = 0;
|
|
160
|
+
} finally{
|
|
161
|
+
f = t = 0;
|
|
162
|
+
}
|
|
163
|
+
if (op[0] & 5) throw op[1];
|
|
164
|
+
return {
|
|
165
|
+
value: op[0] ? op[1] : void 0,
|
|
166
|
+
done: true
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
|
|
171
|
+
var e = new Error(message);
|
|
172
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
function _set_prototype_of(o, p) {
|
|
176
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
177
|
+
o.__proto__ = p;
|
|
178
|
+
return o;
|
|
179
|
+
};
|
|
180
|
+
return _set_prototype_of(o, p);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function _inherits(subClass, superClass) {
|
|
184
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
185
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
186
|
+
}
|
|
187
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
188
|
+
constructor: {
|
|
189
|
+
value: subClass,
|
|
190
|
+
writable: true,
|
|
191
|
+
configurable: true
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* DrawCallHook
|
|
199
|
+
*/ var DrawCallHook = /*#__PURE__*/ function() {
|
|
200
|
+
function DrawCallHook(gl, debug) {
|
|
201
|
+
this.gl = gl;
|
|
202
|
+
this.debug = debug;
|
|
203
|
+
this.drawCall = 0;
|
|
204
|
+
this.triangles = 0;
|
|
205
|
+
this.lines = 0;
|
|
206
|
+
this.points = 0;
|
|
207
|
+
this.hooked = true;
|
|
208
|
+
this.realDrawElements = gl.drawElements;
|
|
209
|
+
this.realDrawArrays = gl.drawArrays;
|
|
210
|
+
gl.drawElements = this.hookedDrawElements.bind(this);
|
|
211
|
+
gl.drawArrays = this.hookedDrawArrays.bind(this);
|
|
212
|
+
if (debug) {
|
|
213
|
+
console.debug("DrawCall is hooked.");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
var _proto = DrawCallHook.prototype;
|
|
217
|
+
_proto.hookedDrawElements = function hookedDrawElements(mode, count, type, offset) {
|
|
218
|
+
this.realDrawElements.call(this.gl, mode, count, type, offset);
|
|
219
|
+
this.update(count, mode);
|
|
220
|
+
};
|
|
221
|
+
_proto.hookedDrawArrays = function hookedDrawArrays(mode, first, count) {
|
|
222
|
+
this.realDrawArrays.call(this.gl, mode, first, count);
|
|
223
|
+
this.update(count, mode);
|
|
224
|
+
};
|
|
225
|
+
_proto.update = function update(count, mode) {
|
|
226
|
+
var gl = this.gl;
|
|
227
|
+
this.drawCall++;
|
|
228
|
+
switch(mode){
|
|
229
|
+
case gl.TRIANGLES:
|
|
230
|
+
this.triangles += count / 3;
|
|
231
|
+
break;
|
|
232
|
+
case gl.TRIANGLE_STRIP:
|
|
233
|
+
case gl.TRIANGLE_FAN:
|
|
234
|
+
this.triangles += count - 2;
|
|
235
|
+
break;
|
|
236
|
+
case gl.LINES:
|
|
237
|
+
this.lines += count / 2;
|
|
238
|
+
break;
|
|
239
|
+
case gl.LINE_STRIP:
|
|
240
|
+
this.lines += count - 1;
|
|
241
|
+
break;
|
|
242
|
+
case gl.LINE_LOOP:
|
|
243
|
+
this.lines += count;
|
|
244
|
+
break;
|
|
245
|
+
case gl.POINTS:
|
|
246
|
+
this.points += count;
|
|
247
|
+
break;
|
|
248
|
+
default:
|
|
249
|
+
console.error("Unknown draw mode: " + mode + ". Count: " + count);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
_proto.reset = function reset() {
|
|
254
|
+
this.drawCall = 0;
|
|
255
|
+
this.triangles = 0;
|
|
256
|
+
this.lines = 0;
|
|
257
|
+
this.points = 0;
|
|
258
|
+
};
|
|
259
|
+
_proto.release = function release() {
|
|
260
|
+
if (this.hooked) {
|
|
261
|
+
this.gl.drawElements = this.realDrawElements;
|
|
262
|
+
this.gl.drawArrays = this.realDrawArrays;
|
|
263
|
+
this.hooked = false;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
return DrawCallHook;
|
|
267
|
+
}();
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* ProgramHook
|
|
271
|
+
* 每一帧的 shader 数量
|
|
272
|
+
*/ var ProgramHook = /*#__PURE__*/ function() {
|
|
273
|
+
function ProgramHook(gl, debug) {
|
|
274
|
+
this.gl = gl;
|
|
275
|
+
this.debug = debug;
|
|
276
|
+
this.programs = 0;
|
|
277
|
+
this.hooked = true;
|
|
278
|
+
this.realUseProgram = gl.useProgram;
|
|
279
|
+
gl.useProgram = this.hookedUseProgram.bind(this);
|
|
280
|
+
if (debug) {
|
|
281
|
+
console.debug("Program is hooked.");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
var _proto = ProgramHook.prototype;
|
|
285
|
+
_proto.hookedUseProgram = function hookedUseProgram(program) {
|
|
286
|
+
this.realUseProgram.call(this.gl, program);
|
|
287
|
+
this.programs++;
|
|
288
|
+
if (this.debug) {
|
|
289
|
+
console.debug("UseProgram: " + program + ", program: " + this.programs + ".");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
_proto.reset = function reset() {
|
|
293
|
+
this.programs = 0;
|
|
294
|
+
};
|
|
295
|
+
_proto.release = function release() {
|
|
296
|
+
if (this.hooked) {
|
|
297
|
+
this.gl.useProgram = this.realUseProgram;
|
|
298
|
+
this.hooked = false;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
return ProgramHook;
|
|
302
|
+
}();
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* ShaderHook
|
|
306
|
+
*/ var ShaderHook = /*#__PURE__*/ function() {
|
|
307
|
+
function ShaderHook(gl, debug) {
|
|
308
|
+
this.gl = gl;
|
|
309
|
+
this.debug = debug;
|
|
310
|
+
this.shaders = 0;
|
|
311
|
+
this.hooked = true;
|
|
312
|
+
this.realAttachShader = gl.attachShader;
|
|
313
|
+
this.realDetachShader = gl.detachShader;
|
|
314
|
+
gl.attachShader = this.hookedAttachShader.bind(this);
|
|
315
|
+
gl.detachShader = this.hookedDetachShader.bind(this);
|
|
316
|
+
if (debug) {
|
|
317
|
+
console.debug("Shader is hooked.");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
var _proto = ShaderHook.prototype;
|
|
321
|
+
_proto.hookedAttachShader = function hookedAttachShader(program, shader) {
|
|
322
|
+
this.realAttachShader.call(this.gl, program, shader);
|
|
323
|
+
this.shaders++;
|
|
324
|
+
if (this.debug) {
|
|
325
|
+
console.debug("AttachShader: " + shader + ". shaders: " + this.shaders);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
_proto.hookedDetachShader = function hookedDetachShader(program, shader) {
|
|
329
|
+
this.realDetachShader.call(this.gl, program, shader);
|
|
330
|
+
this.shaders--;
|
|
331
|
+
if (this.debug) {
|
|
332
|
+
console.debug("DetachShader. shaders: " + this.shaders);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
_proto.reset = function reset() {
|
|
336
|
+
this.shaders = 0;
|
|
337
|
+
};
|
|
338
|
+
_proto.release = function release() {
|
|
339
|
+
if (this.hooked) {
|
|
340
|
+
this.gl.attachShader = this.realAttachShader;
|
|
341
|
+
this.gl.detachShader = this.realDetachShader;
|
|
342
|
+
this.hooked = false;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
return ShaderHook;
|
|
346
|
+
}();
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* TextureHook
|
|
350
|
+
*/ var TextureHook = /*#__PURE__*/ function() {
|
|
351
|
+
function TextureHook(gl, debug) {
|
|
352
|
+
this.gl = gl;
|
|
353
|
+
this.debug = debug;
|
|
354
|
+
this.textures = 0;
|
|
355
|
+
this.hooked = true;
|
|
356
|
+
this.realCreateTexture = gl.createTexture;
|
|
357
|
+
this.realDeleteTexture = gl.deleteTexture;
|
|
358
|
+
gl.createTexture = this.hookedCreateTexture.bind(this);
|
|
359
|
+
gl.deleteTexture = this.hookedDeleteTexture.bind(this);
|
|
360
|
+
if (debug) {
|
|
361
|
+
console.debug("Texture is hooked.");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
var _proto = TextureHook.prototype;
|
|
365
|
+
_proto.hookedCreateTexture = function hookedCreateTexture() {
|
|
366
|
+
var texture = this.realCreateTexture.call(this.gl);
|
|
367
|
+
this.textures++;
|
|
368
|
+
if (this.debug) {
|
|
369
|
+
console.debug("CreateTexture: " + texture + ", textures: " + this.textures + ".");
|
|
370
|
+
}
|
|
371
|
+
return texture;
|
|
372
|
+
};
|
|
373
|
+
_proto.hookedDeleteTexture = function hookedDeleteTexture(texture) {
|
|
374
|
+
this.realDeleteTexture.call(this.gl, texture);
|
|
375
|
+
this.textures--;
|
|
376
|
+
if (this.debug) {
|
|
377
|
+
console.debug("DeleteTexture, textures: " + this.textures + ".");
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
_proto.reset = function reset() {
|
|
381
|
+
this.textures = 0;
|
|
382
|
+
};
|
|
383
|
+
_proto.release = function release() {
|
|
384
|
+
if (this.hooked) {
|
|
385
|
+
this.gl.createTexture = this.realCreateTexture;
|
|
386
|
+
this.gl.deleteTexture = this.realDeleteTexture;
|
|
387
|
+
this.hooked = false;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
return TextureHook;
|
|
391
|
+
}();
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Hook gl to calculate stats
|
|
395
|
+
*/ var Core = /*#__PURE__*/ function() {
|
|
396
|
+
function Core(gl, debug) {
|
|
397
|
+
if (debug === void 0) debug = false;
|
|
398
|
+
this.gl = gl;
|
|
399
|
+
this.samplingFrames = 60;
|
|
400
|
+
this.samplingIndex = 0;
|
|
401
|
+
this.updateCounter = 0;
|
|
402
|
+
this.updateTime = 0;
|
|
403
|
+
if (!gl) {
|
|
404
|
+
throw new Error("Unsupported WebGL context.");
|
|
405
|
+
}
|
|
406
|
+
this.hook(gl, debug);
|
|
407
|
+
}
|
|
408
|
+
var _proto = Core.prototype;
|
|
409
|
+
_proto.hook = function hook(gl, debug) {
|
|
410
|
+
this.drawCallHook = new DrawCallHook(gl, debug);
|
|
411
|
+
this.textureHook = new TextureHook(gl, debug);
|
|
412
|
+
this.shaderHook = new ShaderHook(gl, debug);
|
|
413
|
+
this.programHook = new ProgramHook(gl, debug);
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* reset draw call hook
|
|
417
|
+
*/ _proto.reset = function reset() {
|
|
418
|
+
var _this_drawCallHook, _this_programHook;
|
|
419
|
+
(_this_drawCallHook = this.drawCallHook) == null ? void 0 : _this_drawCallHook.reset();
|
|
420
|
+
(_this_programHook = this.programHook) == null ? void 0 : _this_programHook.reset();
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* release hook
|
|
424
|
+
*/ _proto.release = function release() {
|
|
425
|
+
var _this_drawCallHook, _this_textureHook, _this_shaderHook, _this_programHook;
|
|
426
|
+
(_this_drawCallHook = this.drawCallHook) == null ? void 0 : _this_drawCallHook.release();
|
|
427
|
+
(_this_textureHook = this.textureHook) == null ? void 0 : _this_textureHook.release();
|
|
428
|
+
(_this_shaderHook = this.shaderHook) == null ? void 0 : _this_shaderHook.release();
|
|
429
|
+
(_this_programHook = this.programHook) == null ? void 0 : _this_programHook.release();
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* update performance data
|
|
433
|
+
*/ _proto.update = function update(dt) {
|
|
434
|
+
var now = performance.now();
|
|
435
|
+
this.updateCounter++;
|
|
436
|
+
if (now - this.updateTime < 1000) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
if (this.samplingIndex !== this.samplingFrames) {
|
|
440
|
+
this.reset();
|
|
441
|
+
this.samplingIndex++;
|
|
442
|
+
return undefined;
|
|
443
|
+
}
|
|
444
|
+
this.samplingIndex = 0;
|
|
445
|
+
var data = {
|
|
446
|
+
fps: Math.round(this.updateCounter * 1000 / (now - this.updateTime)),
|
|
447
|
+
// eslint-disable-next-line compat/compat -- performance.memory is not standard
|
|
448
|
+
memory: performance.memory && performance.memory.usedJSHeapSize / 1048576 >> 0,
|
|
449
|
+
drawCall: this.drawCallHook.drawCall === 0 ? 0 : this.drawCallHook.drawCall,
|
|
450
|
+
triangles: this.drawCallHook.triangles === 0 ? 0 : this.drawCallHook.triangles,
|
|
451
|
+
lines: this.drawCallHook.lines,
|
|
452
|
+
points: this.drawCallHook.points,
|
|
453
|
+
textures: this.textureHook.textures,
|
|
454
|
+
shaders: this.shaderHook.shaders === 0 ? 0 : this.shaderHook.shaders,
|
|
455
|
+
programs: this.programHook.programs,
|
|
456
|
+
webglContext: _instanceof1(this.gl, WebGL2RenderingContext) ? "2.0" : "1.0"
|
|
457
|
+
};
|
|
458
|
+
this.reset();
|
|
459
|
+
this.updateCounter = 0;
|
|
460
|
+
this.updateTime = now;
|
|
461
|
+
return data;
|
|
462
|
+
};
|
|
463
|
+
return Core;
|
|
464
|
+
}();
|
|
465
|
+
|
|
466
|
+
var tpl = '\n <dl>\n <dt>FPS</dt>\n <dd>0</dd>\n <dt>Memory <span class="unit">(MB)</span></dt>\n <dd>0</dd>\n <dt>DrawCall</dt>\n <dd>0</dd>\n <dt>Triangles</dt>\n <dd>0</dd>\n <dt>Textures</dt>\n <dd>0</dd>\n <dt>Shaders</dt>\n <dd>0</dd>\n <dt>Program</dt>\n <dd>0</dd>\n <dt>WebGL</dt>\n <dd></dd>\n </dl>\n';
|
|
467
|
+
var css = "\n .gl-perf {\n pointer-events: none;\n user-select: none;\n position: absolute;\n top: 0;\n left: 0;\n padding: " + 10 / 7.5 + "vh " + 10 / 7.5 + "vh 0 " + 10 / 7.5 + "vh;\n background: rgba(0, 0, 0, 0.3);\n color: #fff;\n font: " + 10 / 7.5 + "vh arial;\n }\n\n .gl-perf dl,\n .gl-perf dt,\n .gl-perf dd {\n padding: 0;\n margin: 0;\n }\n\n .gl-perf dt {\n color: #fff;\n text-shadow: #000 0 0 1px;\n }\n\n .gl-perf dt .unit{\n font-size: " + 10 / 7.5 + "vh;\n }\n\n .gl-perf dd {\n font-size: " + 20 / 7.5 + "vh;\n padding: " + 10 / 7.5 + "vh 0 " + 10 / 7.5 + "vh;\n }\n";
|
|
468
|
+
var Monitor = /*#__PURE__*/ function() {
|
|
469
|
+
function Monitor(gl, options) {
|
|
470
|
+
this.options = options;
|
|
471
|
+
this.items = [
|
|
472
|
+
"fps",
|
|
473
|
+
"memory",
|
|
474
|
+
"drawCall",
|
|
475
|
+
"triangles",
|
|
476
|
+
"textures",
|
|
477
|
+
"shaders",
|
|
478
|
+
"programs",
|
|
479
|
+
"webglContext"
|
|
480
|
+
];
|
|
481
|
+
this.data = {
|
|
482
|
+
fps: 60,
|
|
483
|
+
memory: 0,
|
|
484
|
+
drawCall: 0,
|
|
485
|
+
triangles: 0,
|
|
486
|
+
lines: 0,
|
|
487
|
+
points: 0,
|
|
488
|
+
textures: 0,
|
|
489
|
+
shaders: 0,
|
|
490
|
+
programs: 0,
|
|
491
|
+
webglContext: "2.0"
|
|
492
|
+
};
|
|
493
|
+
this.core = new Core(gl, options.debug);
|
|
494
|
+
this.createContainer();
|
|
495
|
+
this.update = this.update.bind(this);
|
|
496
|
+
}
|
|
497
|
+
var _proto = Monitor.prototype;
|
|
498
|
+
_proto.createContainer = function createContainer() {
|
|
499
|
+
var container = document.createElement("div");
|
|
500
|
+
this.container = container;
|
|
501
|
+
if (!this.options.visible) {
|
|
502
|
+
this.hide();
|
|
503
|
+
}
|
|
504
|
+
container.classList.add("gl-perf");
|
|
505
|
+
container.innerHTML = tpl;
|
|
506
|
+
container.appendChild(this.createStyle());
|
|
507
|
+
this.options.container.appendChild(container);
|
|
508
|
+
this.doms = Array.prototype.slice.apply(container.querySelectorAll("dd"));
|
|
509
|
+
};
|
|
510
|
+
_proto.createStyle = function createStyle() {
|
|
511
|
+
var style = document.createElement("style");
|
|
512
|
+
style.appendChild(document.createTextNode(css));
|
|
513
|
+
return style;
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Update per frame
|
|
517
|
+
*/ _proto.update = function update(dt) {
|
|
518
|
+
var _this, _loop = function(i, l) {
|
|
519
|
+
var dom = _this.doms[i];
|
|
520
|
+
var item = _this.items[i];
|
|
521
|
+
var value = data[item] || 0;
|
|
522
|
+
// see: http://wilsonpage.co.uk/preventing-layout-thrashing/
|
|
523
|
+
requestAnimationFrame(function() {
|
|
524
|
+
dom.innerText = String(value);
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
var data = this.core.update(dt);
|
|
528
|
+
if (!data || data.triangles === 0) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
for(var i = 0, l = this.items.length; i < l; i++)_this = this, _loop(i);
|
|
532
|
+
};
|
|
533
|
+
_proto.hide = function hide() {
|
|
534
|
+
this.container.style.display = "none";
|
|
535
|
+
};
|
|
536
|
+
_proto.show = function show() {
|
|
537
|
+
this.container.style.display = "block";
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* reset all hooks
|
|
541
|
+
*/ _proto.reset = function reset() {
|
|
542
|
+
var _this, _loop = function(i, l) {
|
|
543
|
+
var dom = _this.doms[i];
|
|
544
|
+
var item = _this.items[i];
|
|
545
|
+
var value = _this.data[item] || 0;
|
|
546
|
+
// see: http://wilsonpage.co.uk/preventing-layout-thrashing/
|
|
547
|
+
requestAnimationFrame(function() {
|
|
548
|
+
dom.innerText = String(value);
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
this.core.reset();
|
|
552
|
+
for(var i = 0, l = this.items.length; i < l; i++)_this = this, _loop(i);
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* release all hooks
|
|
556
|
+
*/ _proto.release = function release() {
|
|
557
|
+
this.core.release();
|
|
558
|
+
};
|
|
559
|
+
/**
|
|
560
|
+
* dispose the instance
|
|
561
|
+
*/ _proto.dispose = function dispose() {
|
|
562
|
+
this.release();
|
|
563
|
+
this.container.remove();
|
|
564
|
+
};
|
|
565
|
+
return Monitor;
|
|
566
|
+
}();
|
|
567
|
+
|
|
568
|
+
var StatsComponent = /*#__PURE__*/ function(Behaviour) {
|
|
569
|
+
_inherits(StatsComponent, Behaviour);
|
|
570
|
+
function StatsComponent() {
|
|
571
|
+
return Behaviour.apply(this, arguments);
|
|
572
|
+
}
|
|
573
|
+
var _proto = StatsComponent.prototype;
|
|
574
|
+
_proto.init = function init(options) {
|
|
575
|
+
var renderer = this.engine.renderer;
|
|
576
|
+
var gl = renderer.pipelineContext.gl;
|
|
577
|
+
this.monitor = new Monitor(gl, options);
|
|
578
|
+
};
|
|
579
|
+
_proto.onUpdate = function onUpdate(dt) {
|
|
580
|
+
this.monitor.update(dt);
|
|
581
|
+
};
|
|
582
|
+
_proto.dispose = function dispose() {
|
|
583
|
+
Behaviour.prototype.dispose.call(this);
|
|
584
|
+
this.monitor.dispose();
|
|
585
|
+
};
|
|
586
|
+
return StatsComponent;
|
|
587
|
+
}(EFFECTS.Behaviour);
|
|
588
|
+
|
|
589
|
+
var defaultStatsOptions = {
|
|
590
|
+
debug: false,
|
|
591
|
+
visible: true,
|
|
592
|
+
container: document.body
|
|
593
|
+
};
|
|
594
|
+
var json = {
|
|
595
|
+
"images": [],
|
|
596
|
+
"fonts": [],
|
|
597
|
+
"version": "3.0",
|
|
598
|
+
"shapes": [],
|
|
599
|
+
"plugins": [],
|
|
600
|
+
"type": "ge",
|
|
601
|
+
"compositions": [
|
|
602
|
+
{
|
|
603
|
+
"id": "2",
|
|
604
|
+
"name": "stats",
|
|
605
|
+
"duration": 5,
|
|
606
|
+
"startTime": 0,
|
|
607
|
+
"endBehavior": 2,
|
|
608
|
+
"previewSize": [
|
|
609
|
+
750,
|
|
610
|
+
1624
|
|
611
|
+
],
|
|
612
|
+
"items": [
|
|
613
|
+
{
|
|
614
|
+
"id": "05e1c616baf34cc084968a05703719cd"
|
|
615
|
+
}
|
|
616
|
+
],
|
|
617
|
+
"camera": {
|
|
618
|
+
"fov": 60,
|
|
619
|
+
"far": 40,
|
|
620
|
+
"near": 0.1,
|
|
621
|
+
"clipMode": 1,
|
|
622
|
+
"position": [
|
|
623
|
+
0,
|
|
624
|
+
0,
|
|
625
|
+
8
|
|
626
|
+
],
|
|
627
|
+
"rotation": [
|
|
628
|
+
0,
|
|
629
|
+
0,
|
|
630
|
+
0
|
|
631
|
+
]
|
|
632
|
+
},
|
|
633
|
+
"sceneBindings": []
|
|
634
|
+
}
|
|
635
|
+
],
|
|
636
|
+
"components": [],
|
|
637
|
+
"geometries": [],
|
|
638
|
+
"materials": [],
|
|
639
|
+
"items": [
|
|
640
|
+
{
|
|
641
|
+
"id": "05e1c616baf34cc084968a05703719cd",
|
|
642
|
+
"name": "component",
|
|
643
|
+
"duration": 99999,
|
|
644
|
+
"type": "1",
|
|
645
|
+
"visible": true,
|
|
646
|
+
"endBehavior": 0,
|
|
647
|
+
"delay": 0,
|
|
648
|
+
"renderLevel": "B+",
|
|
649
|
+
"components": [],
|
|
650
|
+
"transform": {
|
|
651
|
+
"position": {
|
|
652
|
+
"x": 0,
|
|
653
|
+
"y": 0,
|
|
654
|
+
"z": 0
|
|
655
|
+
},
|
|
656
|
+
"eulerHint": {
|
|
657
|
+
"x": 0,
|
|
658
|
+
"y": 0,
|
|
659
|
+
"z": 0
|
|
660
|
+
},
|
|
661
|
+
"anchor": {
|
|
662
|
+
"x": 0,
|
|
663
|
+
"y": 0
|
|
664
|
+
},
|
|
665
|
+
"size": {
|
|
666
|
+
"x": 1.2,
|
|
667
|
+
"y": 1.2
|
|
668
|
+
},
|
|
669
|
+
"scale": {
|
|
670
|
+
"x": 1,
|
|
671
|
+
"y": 1,
|
|
672
|
+
"z": 1
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
"dataType": "VFXItemData"
|
|
676
|
+
}
|
|
677
|
+
],
|
|
678
|
+
"shaders": [],
|
|
679
|
+
"bins": [],
|
|
680
|
+
"textures": [],
|
|
681
|
+
"animations": [],
|
|
682
|
+
"compositionId": "2"
|
|
683
|
+
};
|
|
684
|
+
/**
|
|
685
|
+
*
|
|
686
|
+
*/ var Stats = /*#__PURE__*/ function() {
|
|
687
|
+
function Stats(player, options) {
|
|
688
|
+
this.player = player;
|
|
689
|
+
this.options = options;
|
|
690
|
+
this.disposed = false;
|
|
691
|
+
void this.init();
|
|
692
|
+
}
|
|
693
|
+
var _proto = Stats.prototype;
|
|
694
|
+
_proto.init = function init() {
|
|
695
|
+
var _this = this;
|
|
696
|
+
return _async_to_generator(function() {
|
|
697
|
+
var composition, item, e;
|
|
698
|
+
return __generator(this, function(_state) {
|
|
699
|
+
switch(_state.label){
|
|
700
|
+
case 0:
|
|
701
|
+
_state.trys.push([
|
|
702
|
+
0,
|
|
703
|
+
2,
|
|
704
|
+
,
|
|
705
|
+
3
|
|
706
|
+
]);
|
|
707
|
+
return [
|
|
708
|
+
4,
|
|
709
|
+
_this.player.loadScene(json)
|
|
710
|
+
];
|
|
711
|
+
case 1:
|
|
712
|
+
composition = _state.sent();
|
|
713
|
+
item = composition.getItemByName("component");
|
|
714
|
+
if (item) {
|
|
715
|
+
item.addComponent(StatsComponent).init(_extends({}, defaultStatsOptions, _this.options));
|
|
716
|
+
_this.component = item.getComponent(StatsComponent);
|
|
717
|
+
}
|
|
718
|
+
return [
|
|
719
|
+
3,
|
|
720
|
+
3
|
|
721
|
+
];
|
|
722
|
+
case 2:
|
|
723
|
+
e = _state.sent();
|
|
724
|
+
throw new Error("Failed to load stats scene: " + e.message + ".");
|
|
725
|
+
case 3:
|
|
726
|
+
return [
|
|
727
|
+
2
|
|
728
|
+
];
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
})();
|
|
732
|
+
};
|
|
733
|
+
_proto.hide = function hide() {
|
|
734
|
+
var _this_component;
|
|
735
|
+
(_this_component = this.component) == null ? void 0 : _this_component.monitor.hide();
|
|
736
|
+
};
|
|
737
|
+
_proto.show = function show() {
|
|
738
|
+
var _this_component;
|
|
739
|
+
(_this_component = this.component) == null ? void 0 : _this_component.monitor.show();
|
|
740
|
+
};
|
|
741
|
+
_proto.dispose = function dispose() {
|
|
742
|
+
var _this_component;
|
|
743
|
+
if (this.disposed) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this.disposed = true;
|
|
747
|
+
(_this_component = this.component) == null ? void 0 : _this_component.dispose();
|
|
748
|
+
this.component = undefined;
|
|
749
|
+
};
|
|
750
|
+
return Stats;
|
|
751
|
+
}();
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* 插件版本号
|
|
755
|
+
*/ var version = "0.0.0-experimental-20250512";
|
|
756
|
+
EFFECTS.logger.info("Plugin stats version: " + version + ".");
|
|
757
|
+
if (version !== EFFECTS__namespace.version) {
|
|
758
|
+
console.error("注意:请统一 Stats 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Stats plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
exports.Stats = Stats;
|
|
762
|
+
exports.version = version;
|
|
763
|
+
//# sourceMappingURL=index.js.map
|