@woosh/meep-engine 2.39.37 → 2.39.38
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 +13 -0
- package/core/assert.js +14 -5
- package/core/bvh2/aabb3/AABB3.js +2 -2
- package/core/bvh2/aabb3/aabb3_detailed_volume_intersection.js +3 -2
- package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +2 -2
- package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +7 -0
- package/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +149 -6
- package/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +41 -0
- package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +2 -2
- package/core/bvh2/traversal/__process_point_if_within_planes.js +2 -2
- package/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +3 -0
- package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +8 -0
- package/core/geom/3d/aabb/{aabb3_computeDistanceAbovePlane.js → aabb3_compute_distance_above_plane_max.js} +3 -2
- package/core/geom/3d/aabb/computeAABB3PlaneSide.js +3 -3
- package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +3 -2
- package/core/geom/3d/plane/is_point_within_planes.js +2 -2
- package/core/geom/3d/plane/plane3_projectPoint.js +2 -2
- package/core/geom/3d/plane/plane3_projectPoint.spec.js +54 -0
- package/core/geom/Plane.js +0 -19
- package/core/geom/v3_distance_above_plane.js +20 -0
- package/core/geom/v3_distance_above_plane.spec.js +40 -0
- package/core/math/statistics/halton_sequence.js +26 -0
- package/engine/asset/loaders/ArrayBufferLoader.js +76 -16
- package/engine/ecs/EntityComponentDataset.js +18 -28
- package/engine/graphics/GraphicsEngine.d.ts +2 -2
- package/engine/graphics/GraphicsEngine.js +11 -15
- package/engine/graphics/composit/LayerCompositer.js +1 -0
- package/engine/graphics/ecs/camera/Camera.js +2 -2
- package/engine/graphics/ecs/camera/CameraSystem.js +6 -0
- package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +1 -1
- package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +17 -20
- package/engine/graphics/filter/FlipArrayInPlace.js +11 -6
- package/engine/graphics/geometry/clipping/ClippedGeometry.js +4 -4
- package/engine/graphics/micron/prototypeVirtualGeometry.js +3 -1
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +2 -0
- package/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +95 -0
- package/engine/graphics/render/buffer/simple-fx/taa/prototypeTAA.js +61 -0
- package/engine/graphics/render/forward_plus/LightManager.js +4 -4
- package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +6 -7
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +6 -2
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +4 -2
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +4 -2
- package/engine/graphics/render/frame_graph/GraphNode.js +22 -0
- package/engine/graphics/render/frame_graph/RenderGraph.js +405 -0
- package/engine/graphics/render/frame_graph/RenderGraphBuilder.js +77 -0
- package/engine/graphics/render/frame_graph/RenderPass.js +30 -12
- package/engine/graphics/render/frame_graph/RenderPassNode.js +103 -0
- package/engine/graphics/render/frame_graph/RenderPassResources.js +54 -4
- package/engine/graphics/render/frame_graph/ResourceEntry.js +77 -0
- package/engine/graphics/render/frame_graph/ResourceNode.js +23 -0
- package/engine/graphics/render/frame_graph/TextureDescriptor.js +38 -4
- package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +11 -5
- package/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +24 -0
- package/engine/graphics/render/frame_graph/sample/deferred/run.js +31 -0
- package/engine/graphics/render/frame_graph/sample/meep-v1/ColorDepthPass.js +38 -0
- package/engine/graphics/render/frame_graph/sample/meep-v1/OutlinePass.js +9 -0
- package/engine/graphics/render/frame_graph/sample/meep-v1/SSAOPass.js +5 -0
- package/engine/graphics/render/frame_graph/sample/meep-v1/render.js +7 -0
- package/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +5 -0
- package/engine/graphics/render/layers/RenderLayerUtils.js +5 -3
- package/engine/graphics/render/view/CameraView.js +38 -0
- package/engine/knowledge/database/DATABASE_SERIALIZATION_IGNORE_PROPERTY.js +1 -0
- package/engine/knowledge/database/StaticKnowledgeDataTable.js +5 -4
- package/package.json +1 -1
- package/core/geom/Plane.spec.js +0 -12
- package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +0 -36
- package/engine/graphics/render/frame_graph/Resource.js +0 -21
- package/engine/graphics/render/frame_graph/ResourceReference.js +0 -14
- package/engine/graphics/render/frame_graph/UsageModeType.js +0 -5
- package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +0 -17
|
@@ -4,20 +4,84 @@ import { CrossOriginKind } from "../CORS/CrossOriginKind.js";
|
|
|
4
4
|
|
|
5
5
|
export class ArrayBufferLoader extends AssetLoader {
|
|
6
6
|
load(path, success, failure, progress) {
|
|
7
|
+
const coc = this.assetManager.crossOriginConfig;
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
xhr.open('GET', path, true);
|
|
10
|
-
xhr.responseType = "arraybuffer";
|
|
9
|
+
const headers = new Headers();
|
|
11
10
|
|
|
12
|
-
const
|
|
11
|
+
const request = new Request(path, {
|
|
12
|
+
credentials: coc.kind === CrossOriginKind.UseCredentials ? 'include' : 'same-origin',
|
|
13
|
+
headers: headers
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
fetch(request)
|
|
17
|
+
.then(response => {
|
|
18
|
+
if (response.status === 200 || response.status === 0) {
|
|
19
|
+
|
|
20
|
+
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
21
|
+
// e.g. 'file://' or 'data://'. Handle as success.
|
|
22
|
+
|
|
23
|
+
if (response.status === 0) {
|
|
24
|
+
|
|
25
|
+
console.warn('HTTP Status 0 received.');
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
30
|
+
|
|
31
|
+
return response;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const reader = response.body.getReader();
|
|
36
|
+
const contentLength = response.headers.get('Content-Length');
|
|
37
|
+
const total = contentLength ? parseInt(contentLength) : 0;
|
|
38
|
+
const lengthComputable = total !== 0;
|
|
39
|
+
let loaded = 0;
|
|
40
|
+
|
|
41
|
+
// periodically read data into the new stream tracking while download progress
|
|
42
|
+
const stream = new ReadableStream({
|
|
43
|
+
start(controller) {
|
|
44
|
+
|
|
45
|
+
readData();
|
|
46
|
+
|
|
47
|
+
function readData() {
|
|
48
|
+
|
|
49
|
+
reader.read().then(({ done, value }) => {
|
|
50
|
+
|
|
51
|
+
if (done) {
|
|
52
|
+
|
|
53
|
+
controller.close();
|
|
54
|
+
|
|
55
|
+
} else {
|
|
56
|
+
|
|
57
|
+
loaded += value.byteLength;
|
|
58
|
+
|
|
59
|
+
progress(loaded, length);
|
|
60
|
+
|
|
61
|
+
controller.enqueue(value);
|
|
62
|
+
readData();
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return new Response(stream);
|
|
75
|
+
|
|
76
|
+
} else {
|
|
77
|
+
|
|
78
|
+
throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`);
|
|
13
79
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
.then(async response => {
|
|
83
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
17
84
|
|
|
18
|
-
xhr.addEventListener('load', function () {
|
|
19
|
-
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
|
|
20
|
-
const arrayBuffer = xhr.response;
|
|
21
85
|
const asset = new Asset(
|
|
22
86
|
function () {
|
|
23
87
|
return arrayBuffer;
|
|
@@ -26,13 +90,9 @@ export class ArrayBufferLoader extends AssetLoader {
|
|
|
26
90
|
);
|
|
27
91
|
|
|
28
92
|
success(asset);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}, false);
|
|
93
|
+
})
|
|
94
|
+
.catch(failure);
|
|
33
95
|
|
|
34
|
-
xhr.addEventListener('error', failure, false);
|
|
35
96
|
|
|
36
|
-
xhr.send();
|
|
37
97
|
}
|
|
38
98
|
}
|
|
@@ -949,11 +949,9 @@ export class EntityComponentDataset {
|
|
|
949
949
|
*/
|
|
950
950
|
addComponentToEntity(entityIndex, componentInstance) {
|
|
951
951
|
|
|
952
|
-
|
|
953
|
-
assert.notNull(componentInstance, "componentInstance");
|
|
952
|
+
assert.notNull(componentInstance, "componentInstance");
|
|
954
953
|
|
|
955
|
-
|
|
956
|
-
}
|
|
954
|
+
assert.defined(componentInstance, "componentInstance");
|
|
957
955
|
|
|
958
956
|
const klass = componentInstance.constructor;
|
|
959
957
|
|
|
@@ -976,15 +974,13 @@ export class EntityComponentDataset {
|
|
|
976
974
|
*/
|
|
977
975
|
addComponentToEntityByIndex(entityIndex, componentIndex, componentInstance) {
|
|
978
976
|
|
|
979
|
-
|
|
977
|
+
assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
|
|
978
|
+
assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
|
|
980
979
|
|
|
981
|
-
|
|
982
|
-
assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
|
|
980
|
+
assert.notEqual(componentInstance, undefined, "componentInstance is undefined");
|
|
983
981
|
|
|
984
|
-
|
|
982
|
+
assert.equal(this.getComponentByIndex(entityIndex, componentIndex), undefined, `entity ${entityIndex} already has component ${componentIndex}`);
|
|
985
983
|
|
|
986
|
-
assert.equal(this.getComponentByIndex(entityIndex, componentIndex), undefined, `entity ${entityIndex} already has component ${componentIndex}`);
|
|
987
|
-
}
|
|
988
984
|
|
|
989
985
|
const componentOccupancyIndex = entityIndex * this.componentTypeCount + componentIndex;
|
|
990
986
|
|
|
@@ -1011,10 +1007,10 @@ export class EntityComponentDataset {
|
|
|
1011
1007
|
* @returns {C|undefined}
|
|
1012
1008
|
*/
|
|
1013
1009
|
getComponentByIndex(entityIndex, componentIndex) {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1010
|
+
|
|
1011
|
+
assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
|
|
1012
|
+
assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
|
|
1013
|
+
|
|
1018
1014
|
|
|
1019
1015
|
return this.components[componentIndex][entityIndex];
|
|
1020
1016
|
}
|
|
@@ -1037,10 +1033,8 @@ export class EntityComponentDataset {
|
|
|
1037
1033
|
* @returns {T|undefined}
|
|
1038
1034
|
*/
|
|
1039
1035
|
getComponent(entityIndex, klass) {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
assert.defined(klass, "klass");
|
|
1043
|
-
}
|
|
1036
|
+
assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
|
|
1037
|
+
assert.defined(klass, "klass");
|
|
1044
1038
|
|
|
1045
1039
|
const componentIndex = this.computeComponentTypeIndex(klass);
|
|
1046
1040
|
|
|
@@ -1078,11 +1072,9 @@ export class EntityComponentDataset {
|
|
|
1078
1072
|
*/
|
|
1079
1073
|
traverseEntities(classes, visitor, thisArg) {
|
|
1080
1074
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
assert.isFunction(visitor, "visitor");
|
|
1085
|
-
}
|
|
1075
|
+
assert.isArray(classes, "classes");
|
|
1076
|
+
// assert.notOk(classes.some((c, i) => classes.indexOf(c) !== i), 'classes contains duplicates');
|
|
1077
|
+
assert.isFunction(visitor, "visitor");
|
|
1086
1078
|
|
|
1087
1079
|
let entityIndex, i;
|
|
1088
1080
|
|
|
@@ -1152,7 +1144,7 @@ export class EntityComponentDataset {
|
|
|
1152
1144
|
}
|
|
1153
1145
|
|
|
1154
1146
|
/**
|
|
1155
|
-
* does traversal on a subset of entities which have only the specified components
|
|
1147
|
+
* does traversal on a subset of entities which have only the specified components and no others
|
|
1156
1148
|
* @example traverseEntitiesExact([Transform,Renderable,Tag],function(transform, renderable, tag, entity){ ... }, this);
|
|
1157
1149
|
* @param {Array.<class>} classes
|
|
1158
1150
|
* @param {Function} visitor
|
|
@@ -1472,10 +1464,8 @@ export class EntityComponentDataset {
|
|
|
1472
1464
|
*/
|
|
1473
1465
|
addEntityEventListener(entity, eventName, listener, thisArg) {
|
|
1474
1466
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
assert.isFunction(listener, "listener");
|
|
1478
|
-
}
|
|
1467
|
+
assert.isString(eventName, "eventName");
|
|
1468
|
+
assert.isFunction(listener, "listener");
|
|
1479
1469
|
|
|
1480
1470
|
if (!this.entityExists(entity)) {
|
|
1481
1471
|
throw new Error(`Entity '${entity}' does not exist`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {PerspectiveCamera, Scene, WebGLRenderer
|
|
1
|
+
import {PerspectiveCamera, Scene, WebGLRenderer} from "three";
|
|
2
2
|
import {RenderLayerManager} from "./render/layers/RenderLayerManager";
|
|
3
3
|
import Vector3 from "../../core/geom/Vector3";
|
|
4
4
|
import Vector2 from "../../core/geom/Vector2";
|
|
@@ -28,7 +28,7 @@ export class GraphicsEngine {
|
|
|
28
28
|
public needDraw: boolean
|
|
29
29
|
public autoDraw: boolean
|
|
30
30
|
|
|
31
|
-
render(
|
|
31
|
+
render(): void
|
|
32
32
|
|
|
33
33
|
normalizeViewportPoint(input: Vector3 | Vector2, result: Vector2 | Vector3): void
|
|
34
34
|
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
Scene as ThreeScene,
|
|
12
12
|
Vector3 as ThreeVector3,
|
|
13
13
|
VSMShadowMap,
|
|
14
|
-
WebGLRenderer
|
|
15
|
-
WebGLRenderTarget
|
|
14
|
+
WebGLRenderer
|
|
16
15
|
} from "three";
|
|
17
16
|
|
|
18
17
|
import Signal from "../../core/events/signal/Signal.js";
|
|
@@ -232,6 +231,12 @@ function GraphicsEngine(camera, entityManger) {
|
|
|
232
231
|
* @type {boolean}
|
|
233
232
|
*/
|
|
234
233
|
this.autoDraw = true;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Monotonically increasing rendered-frame counter
|
|
237
|
+
* @type {number}
|
|
238
|
+
*/
|
|
239
|
+
this.frameIndex = 0;
|
|
235
240
|
}
|
|
236
241
|
|
|
237
242
|
/**
|
|
@@ -625,14 +630,14 @@ GraphicsEngine.prototype.renderTransparent = function () {
|
|
|
625
630
|
|
|
626
631
|
/**
|
|
627
632
|
*
|
|
628
|
-
* @param {WebGLRenderTarget} [renderTarget] if not present - renders to screen
|
|
629
633
|
*/
|
|
630
|
-
GraphicsEngine.prototype.render = function (
|
|
631
|
-
|
|
634
|
+
GraphicsEngine.prototype.render = function () {
|
|
632
635
|
if (this.needDraw && !this.autoDraw) {
|
|
633
636
|
this.needDraw = false;
|
|
634
637
|
}
|
|
635
638
|
|
|
639
|
+
this.frameIndex++;
|
|
640
|
+
|
|
636
641
|
const renderer = this.renderer;
|
|
637
642
|
|
|
638
643
|
//reset renderer statistics (used for debug)
|
|
@@ -653,14 +658,10 @@ GraphicsEngine.prototype.render = function (renderTarget) {
|
|
|
653
658
|
|
|
654
659
|
this.constructVisibleScene(renderer, camera, scene);
|
|
655
660
|
|
|
656
|
-
if (renderTarget !== undefined) {
|
|
657
|
-
renderer.setRenderTarget(renderTarget);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
661
|
//dispatch pre-render event
|
|
661
662
|
this.on.preRender.send3(renderer, camera, scene);
|
|
662
663
|
|
|
663
|
-
this.main_view.on.preRender.
|
|
664
|
+
this.main_view.on.preRender.send1(this.main_view);
|
|
664
665
|
|
|
665
666
|
//do the opaque pass
|
|
666
667
|
this.renderOpaque();
|
|
@@ -674,12 +675,7 @@ GraphicsEngine.prototype.render = function (renderTarget) {
|
|
|
674
675
|
|
|
675
676
|
this.layerComposer.composite(renderer, CompositingStages.POST_TRANSPARENT);
|
|
676
677
|
|
|
677
|
-
|
|
678
678
|
//dispatch post-render event
|
|
679
679
|
this.on.postRender.send3(renderer, camera, scene);
|
|
680
|
-
|
|
681
|
-
if (renderTarget !== undefined) {
|
|
682
|
-
renderer.setRenderTarget(null);
|
|
683
|
-
}
|
|
684
680
|
};
|
|
685
681
|
export { GraphicsEngine };
|
|
@@ -8,11 +8,11 @@ import ObservedEnum from "../../../../core/model/ObservedEnum.js";
|
|
|
8
8
|
import { Frustum } from 'three';
|
|
9
9
|
import { assert } from "../../../../core/assert.js";
|
|
10
10
|
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
11
|
-
import { computePointDistanceToPlane } from "../../../../core/geom/Plane.js";
|
|
12
11
|
import { unprojectPoint } from "./unprojectPoint.js";
|
|
13
12
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
14
13
|
import { frustum_from_camera } from "./frustum_from_camera.js";
|
|
15
14
|
import { invertQuaternionOrientation } from "./InvertQuaternionOrientation.js";
|
|
15
|
+
import { v3_distance_above_plane } from "../../../../core/geom/v3_distance_above_plane.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
@@ -248,7 +248,7 @@ export class Camera {
|
|
|
248
248
|
|
|
249
249
|
const normal = near.normal;
|
|
250
250
|
|
|
251
|
-
const distance_to_plane =
|
|
251
|
+
const distance_to_plane = v3_distance_above_plane(x, y, z, normal.x, normal.y, normal.z, near.constant);
|
|
252
252
|
|
|
253
253
|
const negative_distance_to_plane = -distance_to_plane;
|
|
254
254
|
|
|
@@ -212,6 +212,12 @@ export class CameraSystem extends System {
|
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
if(c.object.updateProjectionMatrix !== undefined) {
|
|
216
|
+
c.object.updateProjectionMatrix();
|
|
217
|
+
c.object.updateMatrix();
|
|
218
|
+
c.object.updateMatrixWorld(true);
|
|
219
|
+
}
|
|
220
|
+
|
|
215
221
|
if (c.autoClip === true) {
|
|
216
222
|
auto_set_camera_clipping_planes(c, layers);
|
|
217
223
|
} else {
|
|
@@ -239,7 +239,7 @@ export class ThreeLightBinding extends LightBinding {
|
|
|
239
239
|
const cameraView = this.__shadow_map.views[0];
|
|
240
240
|
|
|
241
241
|
// signal that we're about to render this view
|
|
242
|
-
cameraView.on.preRender.
|
|
242
|
+
cameraView.on.preRender.send1(cameraView);
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
245
|
*
|
|
@@ -20,10 +20,7 @@ import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
|
20
20
|
import { BehaviorComponent } from "../../../../intelligence/behavior/ecs/BehaviorComponent.js";
|
|
21
21
|
import { OrbitingBehavior } from "../../../../../../model/game/util/behavior/OrbitingBehavior.js";
|
|
22
22
|
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
23
|
-
import { GizmoRenderingPlugin } from "../../../render/gizmo/GizmoRenderingPlugin.js";
|
|
24
|
-
import { Gizmo } from "../../../render/gizmo/Gizmo.js";
|
|
25
23
|
import { AABB3 } from "../../../../../core/bvh2/aabb3/AABB3.js";
|
|
26
|
-
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
27
24
|
import { randomFloatBetween } from "../../../../../core/math/random/randomFloatBetween.js";
|
|
28
25
|
|
|
29
26
|
new EngineHarness().initialize({
|
|
@@ -38,8 +35,8 @@ new EngineHarness().initialize({
|
|
|
38
35
|
new ShadedGeometryHighlightSystem(engine)
|
|
39
36
|
);
|
|
40
37
|
|
|
41
|
-
config.addPlugin(GizmoRenderingPlugin);
|
|
42
|
-
config.addPlugin(MicronRenderPlugin);
|
|
38
|
+
// config.addPlugin(GizmoRenderingPlugin);
|
|
39
|
+
// config.addPlugin(MicronRenderPlugin);
|
|
43
40
|
|
|
44
41
|
const gltfAssetLoader = new GLTFAssetLoader();
|
|
45
42
|
|
|
@@ -79,11 +76,11 @@ function make_grid(ecd, engine) {
|
|
|
79
76
|
radius: 5
|
|
80
77
|
});
|
|
81
78
|
|
|
82
|
-
const ctx = {
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const color = [random(), random(), random(), 1];
|
|
79
|
+
// const ctx = {
|
|
80
|
+
// time: Math.sin(i * Math.PI / (GRID_FREQUENCY_SIZE - 1)) + Math.cos(j * Math.PI / (GRID_FREQUENCY_SIZE - 1))
|
|
81
|
+
// };
|
|
82
|
+
//
|
|
83
|
+
// const color = [random(), random(), random(), 1];
|
|
87
84
|
|
|
88
85
|
engine.graphics.on.preRender.add(() => {
|
|
89
86
|
|
|
@@ -93,16 +90,16 @@ function make_grid(ecd, engine) {
|
|
|
93
90
|
|
|
94
91
|
// mesh.getBoundingBox(bounds);
|
|
95
92
|
|
|
96
|
-
Gizmo.color = color;
|
|
97
|
-
|
|
98
|
-
Gizmo.draw_wire_cube(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
);
|
|
93
|
+
// Gizmo.color = color;
|
|
94
|
+
//
|
|
95
|
+
// Gizmo.draw_wire_cube(
|
|
96
|
+
// [
|
|
97
|
+
// bounds.getCenterX(), bounds.getCenterY(), bounds.getCenterZ()
|
|
98
|
+
// ],
|
|
99
|
+
// [
|
|
100
|
+
// bounds.getExtentsX(), bounds.getExtentsY(), bounds.getExtentsZ()
|
|
101
|
+
// ]
|
|
102
|
+
// );
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
|
|
@@ -5,21 +5,26 @@
|
|
|
5
5
|
* @param {number} channel_count
|
|
6
6
|
*/
|
|
7
7
|
export function flipArrayInPlace(input, width, height, channel_count = 4) {
|
|
8
|
-
const
|
|
8
|
+
const row_size = width * channel_count;
|
|
9
9
|
let t, x0, x1;
|
|
10
10
|
let i = 0;
|
|
11
|
-
const
|
|
11
|
+
const column_count = height >> 1;
|
|
12
|
+
|
|
13
|
+
for (; i < column_count; i++) {
|
|
12
14
|
|
|
13
|
-
for (; i < l; i++) {
|
|
14
15
|
//swap lines
|
|
15
|
-
const k = (height - i - 1) *
|
|
16
|
-
const m = i *
|
|
17
|
-
|
|
16
|
+
const k = (height - i - 1) * row_size;
|
|
17
|
+
const m = i * row_size;
|
|
18
|
+
|
|
19
|
+
for (let j = 0; j < row_size; j++) {
|
|
18
20
|
x0 = m + j;
|
|
19
21
|
x1 = k + j;
|
|
22
|
+
|
|
20
23
|
t = input[x0];
|
|
24
|
+
|
|
21
25
|
input[x0] = input[x1];
|
|
22
26
|
input[x1] = t;
|
|
23
27
|
}
|
|
28
|
+
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v3_distance_above_plane } from "../../../../core/geom/v3_distance_above_plane.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
// TODO incomplete
|
|
@@ -107,9 +107,9 @@ export class ClippedGeometry {
|
|
|
107
107
|
|
|
108
108
|
const plane_constant = plane.constant;
|
|
109
109
|
|
|
110
|
-
const a_distance =
|
|
111
|
-
const b_distance =
|
|
112
|
-
const c_distance =
|
|
110
|
+
const a_distance = v3_distance_above_plane(a_x, a_y, a_z, normal_x, normal_y, normal_z, plane_constant);
|
|
111
|
+
const b_distance = v3_distance_above_plane(b_x, b_y, b_z, normal_x, normal_y, normal_z, plane_constant);
|
|
112
|
+
const c_distance = v3_distance_above_plane(c_x, c_y, c_z, normal_x, normal_y, normal_z, plane_constant);
|
|
113
113
|
|
|
114
114
|
const a_out = a_distance <= 0;
|
|
115
115
|
const b_out = b_distance <= 0;
|
|
@@ -516,7 +516,9 @@ function init() {
|
|
|
516
516
|
// gltf_sample('moicon/A4/A4/model.gltf');
|
|
517
517
|
// gltf_sample('moicon/06_04_hapro/08-clickable-assets-new/model.gltf');
|
|
518
518
|
// gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
|
|
519
|
-
gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
|
|
519
|
+
// gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
|
|
520
|
+
// gltf_sample('moicon/62cf22227f7b8f0012ca5988/model.gltf');
|
|
521
|
+
gltf_sample('moicon/gnutti_not_optimized/model.gltf');
|
|
520
522
|
// gltf_grid('data/models/moicon/Kople/EVCharger1.gltf');
|
|
521
523
|
// gltf_sample('data/models/moicon/Kople/EVCharger1.gltf');
|
|
522
524
|
// gltf_sample('data/models/moicon/isiflow_Oct_15_21/0/model.gltf');
|
|
@@ -356,7 +356,9 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
356
356
|
this.__composit_layer.on.preRender.remove(this.__render, this);
|
|
357
357
|
graphics.viewport.size.onChanged.add(this.__update_render_target_size, this);
|
|
358
358
|
|
|
359
|
+
// release memory
|
|
359
360
|
this.__blur.dispose();
|
|
361
|
+
this.__render_target.dispose();
|
|
360
362
|
|
|
361
363
|
return super.shutdown();
|
|
362
364
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { EnginePlugin } from "../../../../../plugin/EnginePlugin.js";
|
|
2
|
+
import { halton_sequence } from "../../../../../../core/math/statistics/halton_sequence.js";
|
|
3
|
+
import { array_copy } from "../../../../../../core/collection/array/copyArray.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates a number of 2d jitter offsets in range -1...1
|
|
7
|
+
* @param {number} point_count
|
|
8
|
+
* @return {Float32Array}
|
|
9
|
+
*/
|
|
10
|
+
function generate_jitter(point_count) {
|
|
11
|
+
const result = new Float32Array(point_count * 2);
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < point_count; i++) {
|
|
14
|
+
const i2 = i * 2;
|
|
15
|
+
result[i2] = halton_sequence(2, i) * 2 - 1;
|
|
16
|
+
result[i2 + 1] = halton_sequence(3, i) * 2 - 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class TemporalSupersamplingRenderPlugin extends EnginePlugin {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @type {number}
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
this.__frame_index = 0;
|
|
32
|
+
|
|
33
|
+
this.__sample_count = 16;
|
|
34
|
+
this.__jitter_offset = generate_jitter(this.__sample_count);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
this.__projection_modifier = {
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {number[]} input
|
|
41
|
+
* @param {number[]} output
|
|
42
|
+
*/
|
|
43
|
+
transform: (input, output) => {
|
|
44
|
+
|
|
45
|
+
const viewport_width = this.engine.graphics.viewport.size.x;
|
|
46
|
+
const viewport_height = this.engine.graphics.viewport.size.y;
|
|
47
|
+
|
|
48
|
+
// apply jitter to projection matrix
|
|
49
|
+
const jitter_index = this.__frame_index % this.__sample_count;
|
|
50
|
+
|
|
51
|
+
const jitter_offset_x = this.__jitter_offset[jitter_index * 2];
|
|
52
|
+
const jitter_offset_y = this.__jitter_offset[jitter_index * 2 + 1];
|
|
53
|
+
|
|
54
|
+
array_copy(input, 0, output, 0, 16);
|
|
55
|
+
|
|
56
|
+
output[8] = jitter_offset_x / viewport_width;
|
|
57
|
+
output[9] = jitter_offset_y / viewport_height;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
__hook_post_render() {
|
|
63
|
+
|
|
64
|
+
// increment frame index
|
|
65
|
+
this.__frame_index++;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
initialize(engine) {
|
|
69
|
+
super.initialize(engine);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
finalize() {
|
|
73
|
+
super.finalize();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async startup() {
|
|
77
|
+
// modify projection matrix
|
|
78
|
+
this.engine.graphics.main_view.addProjectionModifier(this.__projection_modifier);
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
this.engine.graphics.on.postRender.add(this.__hook_post_render, this);
|
|
82
|
+
|
|
83
|
+
// reset frame counter
|
|
84
|
+
this.__frame_index = 0;
|
|
85
|
+
|
|
86
|
+
return super.startup();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async shutdown() {
|
|
90
|
+
this.engine.graphics.main_view.removeProjectionModifier(this.__projection_modifier);
|
|
91
|
+
this.engine.graphics.on.postRender.remove(this.__hook_post_render, this);
|
|
92
|
+
|
|
93
|
+
return super.shutdown();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../../../EngineHarness.js";
|
|
2
|
+
import EntityBuilder from "../../../../../ecs/EntityBuilder.js";
|
|
3
|
+
import { Transform } from "../../../../../ecs/transform/Transform.js";
|
|
4
|
+
import { ShadedGeometry } from "../../../../ecs/mesh-v2/ShadedGeometry.js";
|
|
5
|
+
import { BoxBufferGeometry, MeshStandardMaterial } from "three";
|
|
6
|
+
import { ShadedGeometrySystem } from "../../../../ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
7
|
+
import { AmbientOcclusionPostProcessEffect } from "../ao/AmbientOcclusionPostProcessEffect.js";
|
|
8
|
+
import { ShadedGeometryHighlightSystem } from "../../../../ecs/highlight/system/ShadedGeometryHighlightSystem.js";
|
|
9
|
+
import { seededRandom } from "../../../../../../core/math/random/seededRandom.js";
|
|
10
|
+
import Highlight from "../../../../ecs/highlight/Highlight.js";
|
|
11
|
+
|
|
12
|
+
const eh = new EngineHarness();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {Engine} engine
|
|
17
|
+
* @return {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
async function main(engine) {
|
|
20
|
+
await EngineHarness.buildBasics({
|
|
21
|
+
engine
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// add a bunch of cubes
|
|
25
|
+
const mat = new MeshStandardMaterial({ color: 0xFFFFFF });
|
|
26
|
+
const geo = new BoxBufferGeometry();
|
|
27
|
+
|
|
28
|
+
const random = seededRandom();
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < 5; i++) {
|
|
31
|
+
for (let j = 0; j < 5; j++) {
|
|
32
|
+
const entityBuilder = new EntityBuilder();
|
|
33
|
+
|
|
34
|
+
if (random() > 0.5) {
|
|
35
|
+
entityBuilder.add(Highlight.fromOne(random(), random(), random()));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
entityBuilder
|
|
39
|
+
.add(Transform.fromJSON({
|
|
40
|
+
position: {
|
|
41
|
+
x: i * 2,
|
|
42
|
+
z: j * 2,
|
|
43
|
+
y: 0.5
|
|
44
|
+
}
|
|
45
|
+
}))
|
|
46
|
+
.add(ShadedGeometry.from(geo, mat))
|
|
47
|
+
.build(engine.entityManager.dataset);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
eh.initialize({
|
|
53
|
+
configuration(config, engine) {
|
|
54
|
+
// config.addPlugin(TemporalSupersamplingRenderPlugin);
|
|
55
|
+
config.addPlugin(AmbientOcclusionPostProcessEffect);
|
|
56
|
+
|
|
57
|
+
config.addSystem(new ShadedGeometrySystem(engine));
|
|
58
|
+
|
|
59
|
+
config.addSystem(new ShadedGeometryHighlightSystem(engine));
|
|
60
|
+
}
|
|
61
|
+
}).then(main);
|
|
@@ -592,7 +592,7 @@ export class LightManager {
|
|
|
592
592
|
* @private
|
|
593
593
|
*/
|
|
594
594
|
__build_view_frustum(camera) {
|
|
595
|
-
frustum_from_camera(camera, this.__view_frustum);
|
|
595
|
+
frustum_from_camera(camera, this.__view_frustum, false);
|
|
596
596
|
|
|
597
597
|
arraySwapElements(this.__view_frustum.planes, 4, 5);
|
|
598
598
|
|
|
@@ -1038,9 +1038,9 @@ export class LightManager {
|
|
|
1038
1038
|
* @param {Camera|THREE.PerspectiveCamera} camera
|
|
1039
1039
|
*/
|
|
1040
1040
|
buildTiles(camera) {
|
|
1041
|
-
camera.updateProjectionMatrix();
|
|
1042
|
-
camera.updateMatrix();
|
|
1043
|
-
camera.updateMatrixWorld(true);
|
|
1041
|
+
// camera.updateProjectionMatrix();
|
|
1042
|
+
// camera.updateMatrix();
|
|
1043
|
+
// camera.updateMatrixWorld(true);
|
|
1044
1044
|
|
|
1045
1045
|
//update world inverse matrix
|
|
1046
1046
|
camera.matrixWorldInverse.copy(camera.matrixWorld);
|