@xtctwins/tctwins-core 1.0.33 → 1.0.34
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/tctwins-core.es.js +354 -341
- package/dist/tctwins-core.min.es.js +5 -5
- package/package.json +2 -2
- package/types/viewer/Viewer.d.ts +2 -0
package/dist/tctwins-core.es.js
CHANGED
|
@@ -7339,8 +7339,8 @@ const utils = {
|
|
|
7339
7339
|
|
|
7340
7340
|
const scenesRenderInfo = {}; // Used for throttling FPS for each Scene
|
|
7341
7341
|
const sceneIDMap = new Map$1(); // Ensures unique scene IDs
|
|
7342
|
-
const taskQueue = new Queue(); // Task queue, which is pumped on each frame; tasks are pushed to it with calls to
|
|
7343
|
-
const tickEvent = {sceneId: null, time: null, startTime: null, prevTime: null, deltaTime: null};
|
|
7342
|
+
const taskQueue = new Queue(); // Task queue, which is pumped on each frame; tasks are pushed to it with calls to tctwins.schedule
|
|
7343
|
+
const tickEvent = { sceneId: null, time: null, startTime: null, prevTime: null, deltaTime: null };
|
|
7344
7344
|
const taskBudget = 10; // Millisecs we're allowed to spend on tasks in each frame
|
|
7345
7345
|
const fpsSamples = [];
|
|
7346
7346
|
const numFPSSamples = 30;
|
|
@@ -7349,119 +7349,121 @@ let lastTime = 0;
|
|
|
7349
7349
|
let elapsedTime;
|
|
7350
7350
|
let totalFPS = 0;
|
|
7351
7351
|
|
|
7352
|
-
|
|
7353
7352
|
/**
|
|
7354
7353
|
* @private
|
|
7355
7354
|
*/
|
|
7356
7355
|
function Core() {
|
|
7357
|
-
|
|
7358
|
-
/**
|
|
7356
|
+
/**
|
|
7359
7357
|
Semantic version number. The value for this is set by an expression that's concatenated to
|
|
7360
|
-
the end of the built binary by the
|
|
7358
|
+
the end of the built binary by the tctwins build script.
|
|
7361
7359
|
@property version
|
|
7362
|
-
@namespace
|
|
7360
|
+
@namespace tctwins
|
|
7363
7361
|
@type {String}
|
|
7364
7362
|
*/
|
|
7365
|
-
|
|
7363
|
+
this.version = "1.0.0";
|
|
7366
7364
|
|
|
7367
|
-
|
|
7365
|
+
/**
|
|
7368
7366
|
Existing {@link Scene}s , mapped to their IDs
|
|
7369
7367
|
@property scenes
|
|
7370
|
-
@namespace
|
|
7368
|
+
@namespace tctwins
|
|
7371
7369
|
@type {Scene}
|
|
7372
7370
|
*/
|
|
7373
|
-
|
|
7371
|
+
this.scenes = {};
|
|
7374
7372
|
|
|
7375
|
-
|
|
7373
|
+
this._superTypes = {}; // For each component type, a list of its supertypes, ordered upwards in the hierarchy.
|
|
7376
7374
|
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7375
|
+
/**
|
|
7376
|
+
* Registers a scene on tctwins.
|
|
7377
|
+
* This is called within the tctwins.Scene constructor.
|
|
7378
|
+
* @private
|
|
7379
|
+
*/
|
|
7380
|
+
this._addScene = function (scene) {
|
|
7381
|
+
if (scene.id) {
|
|
7382
|
+
// User-supplied ID
|
|
7383
|
+
if (core.scenes[scene.id]) {
|
|
7384
|
+
console.error(`[ERROR] Scene ${utils.inQuotes(scene.id)} already exists`);
|
|
7385
|
+
return;
|
|
7386
|
+
}
|
|
7387
|
+
} else {
|
|
7388
|
+
// Auto-generated ID
|
|
7389
|
+
scene.id = sceneIDMap.addItem({});
|
|
7390
|
+
}
|
|
7391
|
+
core.scenes[scene.id] = scene;
|
|
7392
|
+
const ticksPerOcclusionTest = scene.ticksPerOcclusionTest;
|
|
7393
|
+
const ticksPerRender = scene.ticksPerRender;
|
|
7394
|
+
scenesRenderInfo[scene.id] = {
|
|
7395
|
+
ticksPerOcclusionTest: ticksPerOcclusionTest,
|
|
7396
|
+
ticksPerRender: ticksPerRender,
|
|
7397
|
+
renderCountdown: ticksPerRender
|
|
7398
|
+
};
|
|
7399
|
+
stats.components.scenes++;
|
|
7400
|
+
scene.once("destroyed", () => {
|
|
7401
|
+
// Unregister destroyed scenes
|
|
7402
|
+
sceneIDMap.removeItem(scene.id);
|
|
7403
|
+
delete core.scenes[scene.id];
|
|
7404
|
+
delete scenesRenderInfo[scene.id];
|
|
7405
|
+
stats.components.scenes--;
|
|
7406
|
+
});
|
|
7407
|
+
};
|
|
7407
7408
|
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7409
|
+
/**
|
|
7410
|
+
* @private
|
|
7411
|
+
*/
|
|
7412
|
+
this.clear = function () {
|
|
7413
|
+
let scene;
|
|
7414
|
+
for (const id in core.scenes) {
|
|
7415
|
+
if (core.scenes.hasOwnProperty(id)) {
|
|
7416
|
+
scene = core.scenes[id];
|
|
7417
|
+
// Only clear the default Scene
|
|
7418
|
+
// but destroy all the others
|
|
7419
|
+
if (id === "default.scene") {
|
|
7420
|
+
scene.clear();
|
|
7421
|
+
} else {
|
|
7422
|
+
scene.destroy();
|
|
7423
|
+
delete core.scenes[scene.id];
|
|
7424
|
+
}
|
|
7425
|
+
}
|
|
7426
|
+
}
|
|
7427
|
+
};
|
|
7427
7428
|
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7429
|
+
/**
|
|
7430
|
+
* Schedule a task to run at the next frame.
|
|
7431
|
+
*
|
|
7432
|
+
* Internally, this pushes the task to a FIFO queue. Within each frame interval, tctwins processes the queue
|
|
7433
|
+
* for a certain period of time, popping tasks and running them. After each frame interval, tasks that did not
|
|
7434
|
+
* get a chance to run during the task are left in the queue to be run next time.
|
|
7435
|
+
*
|
|
7436
|
+
* @param {Function} callback Callback that runs the task.
|
|
7437
|
+
* @param {Object} [scope] Scope for the callback.
|
|
7438
|
+
*/
|
|
7439
|
+
this.scheduleTask = function (callback, scope = null) {
|
|
7440
|
+
taskQueue.push(callback);
|
|
7441
|
+
taskQueue.push(scope);
|
|
7442
|
+
};
|
|
7442
7443
|
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7444
|
+
this.runTasks = function (until = -1) {
|
|
7445
|
+
// Pops and processes tasks in the queue, until the given number of milliseconds has elapsed.
|
|
7446
|
+
let time = new Date().getTime();
|
|
7447
|
+
let callback;
|
|
7448
|
+
let scope;
|
|
7449
|
+
let tasksRun = 0;
|
|
7450
|
+
while (taskQueue.length > 0 && (until < 0 || time < until)) {
|
|
7451
|
+
callback = taskQueue.shift();
|
|
7452
|
+
scope = taskQueue.shift();
|
|
7453
|
+
if (scope) {
|
|
7454
|
+
callback.call(scope);
|
|
7455
|
+
} else {
|
|
7456
|
+
callback();
|
|
7457
|
+
}
|
|
7458
|
+
time = new Date().getTime();
|
|
7459
|
+
tasksRun++;
|
|
7460
|
+
}
|
|
7461
|
+
return tasksRun;
|
|
7462
|
+
};
|
|
7461
7463
|
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7464
|
+
this.getNumTasks = function () {
|
|
7465
|
+
return taskQueue.length;
|
|
7466
|
+
};
|
|
7465
7467
|
}
|
|
7466
7468
|
|
|
7467
7469
|
/**
|
|
@@ -7471,132 +7473,137 @@ function Core() {
|
|
|
7471
7473
|
const core = new Core();
|
|
7472
7474
|
|
|
7473
7475
|
const frame = function () {
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7476
|
+
let time = Date.now();
|
|
7477
|
+
elapsedTime = time - lastTime;
|
|
7478
|
+
if (lastTime > 0 && elapsedTime > 0) {
|
|
7479
|
+
// Log FPS stats
|
|
7480
|
+
var newFPS = 1000 / elapsedTime; // Moving average of FPS
|
|
7481
|
+
totalFPS += newFPS;
|
|
7482
|
+
fpsSamples.push(newFPS);
|
|
7483
|
+
if (fpsSamples.length >= numFPSSamples) {
|
|
7484
|
+
totalFPS -= fpsSamples.shift();
|
|
7485
|
+
}
|
|
7486
|
+
stats.frame.fps = Math.round(totalFPS / fpsSamples.length);
|
|
7487
|
+
}
|
|
7488
|
+
for (let id in core.scenes) {
|
|
7489
|
+
core.scenes[id].compile();
|
|
7490
|
+
}
|
|
7491
|
+
runTasks(time);
|
|
7492
|
+
lastTime = time;
|
|
7490
7493
|
};
|
|
7491
7494
|
|
|
7492
7495
|
class WorkerInterval {
|
|
7493
|
-
|
|
7496
|
+
worker = null;
|
|
7494
7497
|
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7498
|
+
constructor(callback, interval) {
|
|
7499
|
+
const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
|
|
7500
|
+
const workerScript = URL.createObjectURL(blob);
|
|
7501
|
+
this.worker = new Worker(workerScript);
|
|
7502
|
+
this.worker.onmessage = callback;
|
|
7503
|
+
}
|
|
7501
7504
|
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
+
stop() {
|
|
7506
|
+
this.worker.terminate();
|
|
7507
|
+
}
|
|
7505
7508
|
}
|
|
7506
7509
|
|
|
7507
7510
|
new WorkerInterval(frame, 100);
|
|
7508
7511
|
|
|
7509
7512
|
const renderFrame = function () {
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7513
|
+
let time = Date.now();
|
|
7514
|
+
elapsedTime = time - lastTime;
|
|
7515
|
+
if (lastTime > 0 && elapsedTime > 0) {
|
|
7516
|
+
// Log FPS stats
|
|
7517
|
+
var newFPS = 1000 / elapsedTime; // Moving average of FPS
|
|
7518
|
+
totalFPS += newFPS;
|
|
7519
|
+
fpsSamples.push(newFPS);
|
|
7520
|
+
if (fpsSamples.length >= numFPSSamples) {
|
|
7521
|
+
totalFPS -= fpsSamples.shift();
|
|
7522
|
+
}
|
|
7523
|
+
stats.frame.fps = Math.round(totalFPS / fpsSamples.length);
|
|
7524
|
+
}
|
|
7525
|
+
runTasks(time);
|
|
7526
|
+
fireTickEvents(time);
|
|
7527
|
+
renderScenes();
|
|
7528
|
+
window.requestPostAnimationFrame !== undefined
|
|
7529
|
+
? window.requestPostAnimationFrame(frame)
|
|
7530
|
+
: requestAnimationFrame(renderFrame);
|
|
7525
7531
|
};
|
|
7526
7532
|
|
|
7527
7533
|
renderFrame();
|
|
7528
7534
|
|
|
7529
|
-
function runTasks(time) {
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
+
function runTasks(time) {
|
|
7536
|
+
// Process as many enqueued tasks as we can within the per-frame task budget
|
|
7537
|
+
const tasksRun = core.runTasks(time + taskBudget);
|
|
7538
|
+
const tasksScheduled = core.getNumTasks();
|
|
7539
|
+
stats.frame.tasksRun = tasksRun;
|
|
7540
|
+
stats.frame.tasksScheduled = tasksScheduled;
|
|
7541
|
+
stats.frame.tasksBudget = taskBudget;
|
|
7535
7542
|
}
|
|
7536
7543
|
|
|
7537
|
-
function fireTickEvents(time) {
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7544
|
+
function fireTickEvents(time) {
|
|
7545
|
+
// Fire tick event on each Scene
|
|
7546
|
+
tickEvent.time = time;
|
|
7547
|
+
for (var id in core.scenes) {
|
|
7548
|
+
if (core.scenes.hasOwnProperty(id)) {
|
|
7549
|
+
var scene = core.scenes[id];
|
|
7550
|
+
tickEvent.sceneId = id;
|
|
7551
|
+
tickEvent.startTime = scene.startTime;
|
|
7552
|
+
tickEvent.deltaTime = tickEvent.prevTime != null ? tickEvent.time - tickEvent.prevTime : 0;
|
|
7553
|
+
/**
|
|
7554
|
+
* Fired on each game loop iteration.
|
|
7555
|
+
*
|
|
7556
|
+
* @event tick
|
|
7557
|
+
* @param {String} sceneID The ID of this Scene.
|
|
7558
|
+
* @param {Number} startTime The time in seconds since 1970 that this Scene was instantiated.
|
|
7559
|
+
* @param {Number} time The time in seconds since 1970 of this "tick" event.
|
|
7560
|
+
* @param {Number} prevTime The time of the previous "tick" event from this Scene.
|
|
7561
|
+
* @param {Number} deltaTime The time in seconds since the previous "tick" event from this Scene.
|
|
7562
|
+
*/
|
|
7563
|
+
scene.fire("tick", tickEvent, true);
|
|
7564
|
+
}
|
|
7565
|
+
}
|
|
7566
|
+
tickEvent.prevTime = time;
|
|
7559
7567
|
}
|
|
7560
7568
|
|
|
7561
7569
|
function renderScenes() {
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
}
|
|
7570
|
+
const scenes = core.scenes;
|
|
7571
|
+
const forceRender = false;
|
|
7572
|
+
let scene;
|
|
7573
|
+
let renderInfo;
|
|
7574
|
+
let ticksPerOcclusionTest;
|
|
7575
|
+
let ticksPerRender;
|
|
7576
|
+
let id;
|
|
7577
|
+
for (id in scenes) {
|
|
7578
|
+
if (scenes.hasOwnProperty(id)) {
|
|
7579
|
+
scene = scenes[id];
|
|
7580
|
+
renderInfo = scenesRenderInfo[id];
|
|
7581
|
+
|
|
7582
|
+
if (!renderInfo) {
|
|
7583
|
+
renderInfo = scenesRenderInfo[id] = {}; // FIXME
|
|
7584
|
+
}
|
|
7578
7585
|
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7586
|
+
ticksPerOcclusionTest = scene.ticksPerOcclusionTest;
|
|
7587
|
+
if (renderInfo.ticksPerOcclusionTest !== ticksPerOcclusionTest) {
|
|
7588
|
+
renderInfo.ticksPerOcclusionTest = ticksPerOcclusionTest;
|
|
7589
|
+
renderInfo.renderCountdown = ticksPerOcclusionTest;
|
|
7590
|
+
}
|
|
7591
|
+
if (--scene.occlusionTestCountdown <= 0) {
|
|
7592
|
+
scene.doOcclusionTest();
|
|
7593
|
+
scene.occlusionTestCountdown = ticksPerOcclusionTest;
|
|
7594
|
+
}
|
|
7588
7595
|
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7596
|
+
ticksPerRender = scene.ticksPerRender;
|
|
7597
|
+
if (renderInfo.ticksPerRender !== ticksPerRender) {
|
|
7598
|
+
renderInfo.ticksPerRender = ticksPerRender;
|
|
7599
|
+
renderInfo.renderCountdown = ticksPerRender;
|
|
7600
|
+
}
|
|
7601
|
+
if (--renderInfo.renderCountdown === 0) {
|
|
7602
|
+
scene.render(forceRender);
|
|
7603
|
+
renderInfo.renderCountdown = ticksPerRender;
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7600
7607
|
}
|
|
7601
7608
|
|
|
7602
7609
|
/**
|
|
@@ -18401,7 +18408,7 @@ class SAOOcclusionRenderer {
|
|
|
18401
18408
|
}
|
|
18402
18409
|
}
|
|
18403
18410
|
|
|
18404
|
-
const blurStdDev =
|
|
18411
|
+
const blurStdDev = 10;
|
|
18405
18412
|
const blurDepthCutoff = 0.01;
|
|
18406
18413
|
const KERNEL_RADIUS = 16;
|
|
18407
18414
|
|
|
@@ -18416,49 +18423,45 @@ const tempVec2a$1 = new Float32Array(2);
|
|
|
18416
18423
|
* @private
|
|
18417
18424
|
*/
|
|
18418
18425
|
class SAODepthLimitedBlurRenderer {
|
|
18426
|
+
constructor(scene) {
|
|
18427
|
+
this._scene = scene;
|
|
18419
18428
|
|
|
18420
|
-
|
|
18429
|
+
// The program
|
|
18421
18430
|
|
|
18422
|
-
|
|
18431
|
+
this._program = null;
|
|
18432
|
+
this._programError = false;
|
|
18423
18433
|
|
|
18424
|
-
|
|
18434
|
+
// Variable locations
|
|
18425
18435
|
|
|
18426
|
-
|
|
18427
|
-
|
|
18436
|
+
this._aPosition = null;
|
|
18437
|
+
this._aUV = null;
|
|
18428
18438
|
|
|
18429
|
-
|
|
18439
|
+
this._uDepthTexture = "uDepthTexture";
|
|
18440
|
+
this._uOcclusionTexture = "uOcclusionTexture";
|
|
18430
18441
|
|
|
18431
|
-
|
|
18432
|
-
|
|
18442
|
+
this._uViewport = null;
|
|
18443
|
+
this._uCameraNear = null;
|
|
18444
|
+
this._uCameraFar = null;
|
|
18445
|
+
this._uCameraProjectionMatrix = null;
|
|
18446
|
+
this._uCameraInverseProjectionMatrix = null;
|
|
18433
18447
|
|
|
18434
|
-
|
|
18435
|
-
this._uOcclusionTexture = "uOcclusionTexture";
|
|
18448
|
+
// VBOs
|
|
18436
18449
|
|
|
18437
|
-
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
this._uCameraProjectionMatrix = null;
|
|
18441
|
-
this._uCameraInverseProjectionMatrix = null;
|
|
18450
|
+
this._uvBuf = null;
|
|
18451
|
+
this._positionsBuf = null;
|
|
18452
|
+
this._indicesBuf = null;
|
|
18442
18453
|
|
|
18443
|
-
|
|
18444
|
-
|
|
18445
|
-
this._uvBuf = null;
|
|
18446
|
-
this._positionsBuf = null;
|
|
18447
|
-
this._indicesBuf = null;
|
|
18448
|
-
|
|
18449
|
-
this.init();
|
|
18450
|
-
}
|
|
18451
|
-
|
|
18452
|
-
init() {
|
|
18453
|
-
|
|
18454
|
-
// Create program & VBOs, locate attributes and uniforms
|
|
18454
|
+
this.init();
|
|
18455
|
+
}
|
|
18455
18456
|
|
|
18456
|
-
|
|
18457
|
+
init() {
|
|
18458
|
+
// Create program & VBOs, locate attributes and uniforms
|
|
18457
18459
|
|
|
18458
|
-
|
|
18460
|
+
const gl = this._scene.canvas.gl;
|
|
18459
18461
|
|
|
18460
|
-
|
|
18461
|
-
|
|
18462
|
+
this._program = new Program(gl, {
|
|
18463
|
+
vertex: [
|
|
18464
|
+
`#version 300 es
|
|
18462
18465
|
precision highp float;
|
|
18463
18466
|
precision highp int;
|
|
18464
18467
|
|
|
@@ -18471,10 +18474,11 @@ class SAODepthLimitedBlurRenderer {
|
|
|
18471
18474
|
vUV = aUV;
|
|
18472
18475
|
vInvSize = 1.0 / uViewport;
|
|
18473
18476
|
gl_Position = vec4(aPosition, 1.0);
|
|
18474
|
-
}`
|
|
18477
|
+
}`
|
|
18478
|
+
],
|
|
18475
18479
|
|
|
18476
|
-
|
|
18477
|
-
|
|
18480
|
+
fragment: [
|
|
18481
|
+
`#version 300 es
|
|
18478
18482
|
precision highp float;
|
|
18479
18483
|
precision highp int;
|
|
18480
18484
|
|
|
@@ -18588,135 +18592,137 @@ class SAODepthLimitedBlurRenderer {
|
|
|
18588
18592
|
|
|
18589
18593
|
outColor = packFloatToRGBA(occlusionSum / weightSum);
|
|
18590
18594
|
}`
|
|
18591
|
-
|
|
18592
|
-
|
|
18595
|
+
]
|
|
18596
|
+
});
|
|
18593
18597
|
|
|
18594
|
-
|
|
18595
|
-
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
|
|
18598
|
+
if (this._program.errors) {
|
|
18599
|
+
console.error(this._program.errors.join("\n"));
|
|
18600
|
+
this._programError = true;
|
|
18601
|
+
return;
|
|
18602
|
+
}
|
|
18599
18603
|
|
|
18600
|
-
|
|
18601
|
-
|
|
18604
|
+
const uv = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0]);
|
|
18605
|
+
const positions = new Float32Array([1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0]);
|
|
18602
18606
|
|
|
18603
|
-
|
|
18604
|
-
|
|
18607
|
+
// Mitigation: if Uint8Array is used, the geometry is corrupted on OSX when using Chrome with data-textures
|
|
18608
|
+
const indices = new Uint32Array([0, 1, 2, 0, 2, 3]);
|
|
18605
18609
|
|
|
18606
|
-
|
|
18607
|
-
|
|
18608
|
-
|
|
18610
|
+
this._positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positions, positions.length, 3, gl.STATIC_DRAW);
|
|
18611
|
+
this._uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uv, uv.length, 2, gl.STATIC_DRAW);
|
|
18612
|
+
this._indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, indices, indices.length, 1, gl.STATIC_DRAW);
|
|
18609
18613
|
|
|
18610
|
-
|
|
18614
|
+
this._program.bind();
|
|
18611
18615
|
|
|
18612
|
-
|
|
18616
|
+
this._uViewport = this._program.getLocation("uViewport");
|
|
18613
18617
|
|
|
18614
|
-
|
|
18615
|
-
|
|
18616
|
-
|
|
18617
|
-
this._uDepthCutoff = this._program.getLocation("uDepthCutoff");
|
|
18618
|
+
this._uCameraNear = this._program.getLocation("uCameraNear");
|
|
18619
|
+
this._uCameraFar = this._program.getLocation("uCameraFar");
|
|
18618
18620
|
|
|
18619
|
-
|
|
18620
|
-
this._uSampleWeights = gl.getUniformLocation(this._program.handle, "uSampleWeights");
|
|
18621
|
+
this._uDepthCutoff = this._program.getLocation("uDepthCutoff");
|
|
18621
18622
|
|
|
18622
|
-
|
|
18623
|
-
|
|
18624
|
-
}
|
|
18623
|
+
this._uSampleOffsets = gl.getUniformLocation(this._program.handle, "uSampleOffsets");
|
|
18624
|
+
this._uSampleWeights = gl.getUniformLocation(this._program.handle, "uSampleWeights");
|
|
18625
18625
|
|
|
18626
|
-
|
|
18626
|
+
this._aPosition = this._program.getAttribute("aPosition");
|
|
18627
|
+
this._aUV = this._program.getAttribute("aUV");
|
|
18628
|
+
}
|
|
18627
18629
|
|
|
18628
|
-
|
|
18629
|
-
|
|
18630
|
-
|
|
18630
|
+
render(depthRenderBuffer, occlusionRenderBuffer, direction) {
|
|
18631
|
+
if (this._programError) {
|
|
18632
|
+
return;
|
|
18633
|
+
}
|
|
18631
18634
|
|
|
18632
|
-
|
|
18633
|
-
|
|
18634
|
-
|
|
18635
|
-
|
|
18636
|
-
|
|
18637
|
-
|
|
18638
|
-
|
|
18639
|
-
|
|
18640
|
-
|
|
18641
|
-
|
|
18642
|
-
|
|
18643
|
-
|
|
18644
|
-
|
|
18645
|
-
|
|
18646
|
-
|
|
18635
|
+
if (!this._getInverseProjectMat) {
|
|
18636
|
+
// HACK: scene.camera not defined until render time
|
|
18637
|
+
this._getInverseProjectMat = (() => {
|
|
18638
|
+
let projMatDirty = true;
|
|
18639
|
+
this._scene.camera.on("projMatrix", function () {
|
|
18640
|
+
projMatDirty = true;
|
|
18641
|
+
});
|
|
18642
|
+
const inverseProjectMat = math.mat4();
|
|
18643
|
+
return () => {
|
|
18644
|
+
if (projMatDirty) {
|
|
18645
|
+
math.inverseMat4(scene.camera.projMatrix, inverseProjectMat);
|
|
18646
|
+
}
|
|
18647
|
+
return inverseProjectMat;
|
|
18648
|
+
};
|
|
18649
|
+
})();
|
|
18650
|
+
}
|
|
18647
18651
|
|
|
18648
|
-
|
|
18649
|
-
|
|
18650
|
-
|
|
18651
|
-
|
|
18652
|
-
|
|
18653
|
-
|
|
18654
|
-
|
|
18655
|
-
|
|
18652
|
+
const gl = this._scene.canvas.gl;
|
|
18653
|
+
const program = this._program;
|
|
18654
|
+
const scene = this._scene;
|
|
18655
|
+
const viewportWidth = gl.drawingBufferWidth;
|
|
18656
|
+
const viewportHeight = gl.drawingBufferHeight;
|
|
18657
|
+
const projectState = scene.camera.project._state;
|
|
18658
|
+
const near = projectState.near;
|
|
18659
|
+
const far = projectState.far;
|
|
18656
18660
|
|
|
18657
|
-
|
|
18658
|
-
|
|
18659
|
-
|
|
18660
|
-
|
|
18661
|
-
|
|
18662
|
-
|
|
18661
|
+
gl.viewport(0, 0, viewportWidth, viewportHeight);
|
|
18662
|
+
gl.clearColor(0, 0, 0, 1);
|
|
18663
|
+
gl.enable(gl.DEPTH_TEST);
|
|
18664
|
+
gl.disable(gl.BLEND);
|
|
18665
|
+
gl.frontFace(gl.CCW);
|
|
18666
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
18663
18667
|
|
|
18664
|
-
|
|
18668
|
+
program.bind();
|
|
18665
18669
|
|
|
18666
|
-
|
|
18667
|
-
|
|
18670
|
+
tempVec2a$1[0] = viewportWidth;
|
|
18671
|
+
tempVec2a$1[1] = viewportHeight;
|
|
18668
18672
|
|
|
18669
|
-
|
|
18670
|
-
|
|
18671
|
-
|
|
18673
|
+
gl.uniform2fv(this._uViewport, tempVec2a$1);
|
|
18674
|
+
gl.uniform1f(this._uCameraNear, near);
|
|
18675
|
+
gl.uniform1f(this._uCameraFar, far);
|
|
18672
18676
|
|
|
18673
|
-
|
|
18677
|
+
gl.uniform1f(this._uDepthCutoff, blurDepthCutoff);
|
|
18674
18678
|
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18679
|
-
|
|
18679
|
+
if (direction === 0) {
|
|
18680
|
+
// Horizontal
|
|
18681
|
+
gl.uniform2fv(this._uSampleOffsets, sampleOffsetsHor);
|
|
18682
|
+
} else {
|
|
18683
|
+
// Vertical
|
|
18684
|
+
gl.uniform2fv(this._uSampleOffsets, sampleOffsetsVert);
|
|
18685
|
+
}
|
|
18680
18686
|
|
|
18681
|
-
|
|
18687
|
+
gl.uniform1fv(this._uSampleWeights, sampleWeights);
|
|
18682
18688
|
|
|
18683
|
-
|
|
18684
|
-
|
|
18689
|
+
const depthTexture = depthRenderBuffer.getDepthTexture();
|
|
18690
|
+
const occlusionTexture = occlusionRenderBuffer.getTexture();
|
|
18685
18691
|
|
|
18686
|
-
|
|
18687
|
-
|
|
18692
|
+
program.bindTexture(this._uDepthTexture, depthTexture, 0); // TODO: use FrameCtx.textureUnit
|
|
18693
|
+
program.bindTexture(this._uOcclusionTexture, occlusionTexture, 1);
|
|
18688
18694
|
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18695
|
+
this._aUV.bindArrayBuffer(this._uvBuf);
|
|
18696
|
+
this._aPosition.bindArrayBuffer(this._positionsBuf);
|
|
18697
|
+
this._indicesBuf.bind();
|
|
18692
18698
|
|
|
18693
|
-
|
|
18694
|
-
|
|
18699
|
+
gl.drawElements(gl.TRIANGLES, this._indicesBuf.numItems, this._indicesBuf.itemType, 0);
|
|
18700
|
+
}
|
|
18695
18701
|
|
|
18696
|
-
|
|
18697
|
-
|
|
18698
|
-
|
|
18702
|
+
destroy() {
|
|
18703
|
+
this._program.destroy();
|
|
18704
|
+
}
|
|
18699
18705
|
}
|
|
18700
18706
|
|
|
18701
18707
|
function createSampleWeights(kernelRadius, stdDev) {
|
|
18702
|
-
|
|
18703
|
-
|
|
18704
|
-
|
|
18705
|
-
|
|
18706
|
-
|
|
18708
|
+
const weights = [];
|
|
18709
|
+
for (let i = 0; i <= kernelRadius; i++) {
|
|
18710
|
+
weights.push(gaussian(i, stdDev));
|
|
18711
|
+
}
|
|
18712
|
+
return weights; // TODO: Optimize
|
|
18707
18713
|
}
|
|
18708
18714
|
|
|
18709
18715
|
function gaussian(x, stdDev) {
|
|
18710
|
-
|
|
18716
|
+
return Math.exp(-(x * x) / (2.0 * (stdDev * stdDev))) / (Math.sqrt(2.0 * Math.PI) * stdDev);
|
|
18711
18717
|
}
|
|
18712
18718
|
|
|
18713
18719
|
function createSampleOffsets(kernelRadius, uvIncrement) {
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
|
|
18719
|
-
|
|
18720
|
+
const offsets = [];
|
|
18721
|
+
for (let i = 0; i <= kernelRadius; i++) {
|
|
18722
|
+
offsets.push(uvIncrement[0] * i);
|
|
18723
|
+
offsets.push(uvIncrement[1] * i);
|
|
18724
|
+
}
|
|
18725
|
+
return offsets;
|
|
18720
18726
|
}
|
|
18721
18727
|
|
|
18722
18728
|
/**
|
|
@@ -30283,7 +30289,8 @@ class Scene extends Component {
|
|
|
30283
30289
|
contextAttr: cfg.contextAttr || {},
|
|
30284
30290
|
backgroundColor: cfg.backgroundColor,
|
|
30285
30291
|
backgroundColorFromAmbientLight: cfg.backgroundColorFromAmbientLight,
|
|
30286
|
-
premultipliedAlpha: cfg.premultipliedAlpha
|
|
30292
|
+
premultipliedAlpha: cfg.premultipliedAlpha,
|
|
30293
|
+
resolutionScale: cfg.resolutionScale
|
|
30287
30294
|
});
|
|
30288
30295
|
|
|
30289
30296
|
this.canvas.on("boundary", () => {
|
|
@@ -30291,7 +30298,7 @@ class Scene extends Component {
|
|
|
30291
30298
|
});
|
|
30292
30299
|
|
|
30293
30300
|
this.canvas.on("webglContextFailed", () => {
|
|
30294
|
-
alert("
|
|
30301
|
+
alert("tctwins failed to find WebGL!");
|
|
30295
30302
|
});
|
|
30296
30303
|
|
|
30297
30304
|
this._renderer = new Renderer$1(this, {
|
|
@@ -108662,7 +108669,8 @@ class Viewer {
|
|
|
108662
108669
|
dtxEnabled: !!cfg.dtxEnabled,
|
|
108663
108670
|
edgesEnabled: cfg.edgesEnabled,
|
|
108664
108671
|
numCachedSectionPlanes: cfg.numCachedSectionPlanes,
|
|
108665
|
-
lodEnabled: !!cfg.lodEnabled
|
|
108672
|
+
lodEnabled: !!cfg.lodEnabled,
|
|
108673
|
+
resolutionScale: cfg.resolutionScale
|
|
108666
108674
|
});
|
|
108667
108675
|
|
|
108668
108676
|
/**
|
|
@@ -134695,18 +134703,18 @@ class XTCLoaderPlugin extends Plugin {
|
|
|
134695
134703
|
// }
|
|
134696
134704
|
}
|
|
134697
134705
|
|
|
134698
|
-
function getBaseDirectory(filePath) {
|
|
134699
|
-
const pathArray = filePath.split("/");
|
|
134700
|
-
pathArray.pop(); // Remove the file name or the last segment of the path
|
|
134701
|
-
return pathArray.join("/") + "/";
|
|
134702
|
-
}
|
|
134703
134706
|
function createInlineWorker() {
|
|
134704
134707
|
const workerCode = `
|
|
134705
134708
|
self.importScripts('https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.11/pako.min.js');
|
|
134706
134709
|
|
|
134707
134710
|
function inflateMetadata(deflatedData) {
|
|
134708
|
-
|
|
134709
|
-
|
|
134711
|
+
try {
|
|
134712
|
+
return JSON.parse(self.pako.inflate(deflatedData, { to: "string" }));
|
|
134713
|
+
} catch (error) {
|
|
134714
|
+
console.error("Error inflating metadata:", error);
|
|
134715
|
+
throw error;
|
|
134716
|
+
}
|
|
134717
|
+
}
|
|
134710
134718
|
|
|
134711
134719
|
self.onmessage = function (e) {
|
|
134712
134720
|
console.log("start worker:");
|
|
@@ -134721,6 +134729,11 @@ function createInlineWorker() {
|
|
|
134721
134729
|
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
134722
134730
|
const workerUrl = URL.createObjectURL(blob);
|
|
134723
134731
|
return new Worker(workerUrl);
|
|
134732
|
+
}
|
|
134733
|
+
function getBaseDirectory(filePath) {
|
|
134734
|
+
const pathArray = filePath.split("/");
|
|
134735
|
+
pathArray.pop(); // Remove the file name or the last segment of the path
|
|
134736
|
+
return pathArray.join("/") + "/";
|
|
134724
134737
|
}
|
|
134725
134738
|
|
|
134726
134739
|
/*
|