@woosh/meep-engine 2.50.3 → 2.51.0
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/editor/actions/concrete/WriteGridValueAction.js +13 -18
- package/editor/ecs/component/editors/Sampler2DEditor.js +2 -2
- package/editor/process/SymbolicDisplayProcess.js +1 -1
- package/editor/process/symbolic/buildThreeJSHelperEntity.js +1 -1
- package/editor/process/symbolic/makeCameraSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
- package/editor/process/symbolic/makeLightSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makePathSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +1 -1
- package/editor/view/ecs/components/GridObstacleController.js +2 -2
- package/editor/view/ecs/components/TerrainController.js +2 -2
- package/package.json +1 -1
- package/samples/terrain/editor.js +2 -2
- package/src/core/UUID.spec.js +8 -0
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.d.ts +4 -0
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +57 -55
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +54 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +3 -3
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +60 -0
- package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +2 -2
- package/src/core/cache/Cache.js +3 -5
- package/src/core/cache/CacheElement.js +1 -0
- package/src/core/geom/2d/quad-tree/PointQuadTree.js +10 -0
- package/src/core/geom/3d/aabb/aabb3_array_combine.js +3 -3
- package/src/core/graph/{convertGraphToDotString.js → convert_graph_to_dot_string.js} +1 -1
- package/src/core/graph/convert_graph_to_dot_string.spec.js +28 -0
- package/src/core/math/noise/sdnoise.js +5 -7
- package/src/core/math/noise/sdnoise.spec.js +87 -0
- package/src/engine/{Platform.js → browserInfo.js} +1 -5
- package/src/engine/ecs/fow/FogOfWar.js +48 -54
- package/src/engine/ecs/{systems → renderable}/RenderSystem.d.ts +1 -1
- package/src/engine/ecs/{systems → renderable}/RenderSystem.js +10 -38
- package/src/engine/ecs/renderable/Renderable.d.ts +25 -0
- package/src/engine/ecs/{components → renderable}/Renderable.js +18 -83
- package/src/engine/ecs/renderable/Renderable.spec.js +10 -0
- package/src/engine/ecs/speaker/VoiceSystem.js +15 -9
- package/src/engine/ecs/systems/MeshColliderSystem.js +1 -1
- package/src/engine/ecs/systems/RangedAttackSystem.js +1 -1
- package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +1 -1
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +2 -2
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +3 -3
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +2 -2
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +2 -2
- package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
- package/src/engine/graphics/copy_transform_to_threejs_object.js +12 -0
- package/src/engine/graphics/debug/VisualSymbolLine.js +1 -1
- package/src/engine/graphics/ecs/decal/DecalSystem.js +1 -1
- package/src/engine/graphics/ecs/highlight/renderer/makeGaussianBlurShader.js +1 -4
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts +1 -1
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +2 -2
- package/src/engine/graphics/ecs/mesh/applyTransformToThreeObject.js +2 -5
- package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +2 -2
- package/src/engine/graphics/geometry/optimization/merge/prototypeGeometryMerge.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
- package/src/engine/graphics/shaders/SoftOutlineShader.js +2 -4
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +24 -0
- package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +46 -0
- package/src/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
- package/src/engine/graphics/texture/sampler/bicubic.spec.js +13 -0
- package/src/engine/graphics/texture/sampler/differenceSampler.js +1 -1
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +5 -1
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.spec.js +183 -0
- package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +20 -0
- package/src/engine/graphics/texture/sampler/filter/mitchell.js +0 -21
- package/src/engine/graphics/texture/sampler/filter/mitchell_v1.js +21 -0
- package/src/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +17 -16
- package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +11 -9
- package/src/engine/graphics/texture/sampler/{scaleSampler2D.js → resize/sampler2d_scale.js} +8 -8
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale.spec.js +73 -0
- package/src/engine/graphics/texture/sampler/{sampler2_d_scale_down_lanczos.js → resize/sampler2d_scale_down_lanczos.js} +3 -24
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +29 -0
- package/src/engine/graphics/texture/sampler/{sampler2d_scale_down_linear.js → resize/sampler2d_scale_down_linear.js} +5 -5
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.spec.js +44 -0
- package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.js → sampler2d_scale_down_mipmap.js} +2 -2
- package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.spec.js → sampler2d_scale_down_mipmap.spec.js} +2 -2
- package/src/engine/graphics/texture/sampler/{genericResampleSampler2D.js → resize/sampler2d_scale_generic.js} +16 -12
- package/src/engine/graphics/texture/sampler/{upsampleSampler2D.js → resize/sampler2d_scale_up_linear.js} +5 -2
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_up_linear.spec.js +14 -0
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +4 -2
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.spec.js +15 -0
- package/src/engine/graphics/texture/sampler/util/drawSamplerHTML.js +2 -2
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +66 -0
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.spec.js +108 -0
- package/src/engine/graphics/trail/TemporalPath.js +83 -78
- package/src/engine/graphics/trail/TemporalPath.spec.js +5 -0
- package/src/engine/graphics/trail/x/RibbonX.spec.js +5 -0
- package/src/engine/input/devices/InputDeviceSwitch.spec.js +5 -0
- package/src/engine/input/ecs/{InputBinding.js → components/InputBinding.js} +1 -1
- package/src/engine/input/ecs/components/InputController.js +2 -2
- package/src/engine/input/ecs/ism/InputBinding.js +2 -2
- package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
- package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +1 -1
- package/src/engine/intelligence/behavior/behavior_to_dot.spec.js +25 -0
- package/src/engine/intelligence/behavior/util/DelayBehavior.js +6 -4
- package/src/engine/intelligence/blackboard/Blackboard.d.ts +2 -0
- package/src/engine/intelligence/blackboard/Blackboard.js +36 -2
- package/src/engine/intelligence/blackboard/Blackboard.spec.js +49 -0
- package/src/engine/intelligence/blackboard/BlackboardSerializationAdapter.spec.js +2 -0
- package/src/engine/navigation/grid/{AStar.js → find_path_on_grid_astar.js} +21 -18
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +7 -0
- package/src/engine/sound/ecs/SoundListenerSystem.js +1 -1
- package/src/generation/markers/debug/visualizeMarkers.js +1 -1
- package/src/engine/MeepSettings.js +0 -9
- package/src/engine/User.js +0 -28
- package/src/engine/UserController.js +0 -273
- package/src/engine/ecs/components/AABB.js +0 -33
- package/src/engine/ecs/components/AABBCollider.js +0 -15
- package/src/engine/ecs/components/Renderable.d.ts +0 -14
- package/src/engine/ecs/grid/Sampler2DDecoder.js +0 -57
- package/src/engine/ecs/grid/makeTerrainGeometry.js +0 -110
- package/src/engine/ecs/systems/AABBColliderSystem.js +0 -61
- package/src/engine/ecs/systems/AABBSystem.js +0 -89
- package/src/engine/graphics/texture/sampler/sampler2d_make_array_filler_function.js +0 -65
- package/src/engine/graphics/texture/sampler/sampler2d_scale_down_linear.spec.js +0 -17
- package/src/engine/graphics/trail/x/simulator/RibbonState.js +0 -10
- package/src/engine/grid/Grid.js +0 -131
- package/src/engine/navigation/grid/GridField.js +0 -328
- /package/src/engine/ecs/{components → renderable}/RenderableFlags.js +0 -0
package/src/engine/User.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 11/08/2015.
|
|
3
|
-
*/
|
|
4
|
-
const User = function () {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @type {boolean}
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
this.__isLoggedIn = false;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
User.prototype.getAchievement = function () {
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
User.prototype.submitScore = function (value, options) {
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
User.prototype.login = function () {
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
User.prototype.isLoggedIn = function () {
|
|
25
|
-
return this.__isLoggedIn;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default User;
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 29/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
import Vector3 from "../core/geom/Vector3.js";
|
|
5
|
-
import { Transform } from './ecs/transform/Transform.js';
|
|
6
|
-
import Hammer from 'Hammer';
|
|
7
|
-
import { Euler as ThreeEuler, Vector2 as ThreeVector2, Vector3 as ThreeVector3 } from 'three';
|
|
8
|
-
import { DEG_TO_RAD } from "../core/math/DEG_TO_RAD.js";
|
|
9
|
-
|
|
10
|
-
const keyboardRotationSpeed = 1.2;
|
|
11
|
-
|
|
12
|
-
// pass in distance in world space to move left
|
|
13
|
-
function panLeft(distance, object, result) {
|
|
14
|
-
|
|
15
|
-
const panOffset = new Vector3();
|
|
16
|
-
const te = object.matrix.elements;
|
|
17
|
-
// get X column of matrix
|
|
18
|
-
panOffset.set(te[0], te[1], te[2]);
|
|
19
|
-
panOffset.multiplyScalar(-distance);
|
|
20
|
-
|
|
21
|
-
result.add(panOffset);
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// pass in distance in world space to move up
|
|
26
|
-
function panUp(distance, object, result) {
|
|
27
|
-
|
|
28
|
-
const panOffset = new Vector3();
|
|
29
|
-
const te = object.matrix.elements;
|
|
30
|
-
// get Y column of matrix
|
|
31
|
-
panOffset.set(te[4], te[5], te[6]);
|
|
32
|
-
panOffset.multiplyScalar(distance);
|
|
33
|
-
|
|
34
|
-
result.add(panOffset);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// main entry point; pass in Vector2 of change desired in pixel space,
|
|
38
|
-
// right and down are positive
|
|
39
|
-
function pan(delta, object, element, targetDistance, fov, result) {
|
|
40
|
-
// half of the fov is center to top of screen
|
|
41
|
-
targetDistance *= Math.tan((fov / 2) * DEG_TO_RAD);
|
|
42
|
-
// we actually don't use screenWidth, since perspective camera is fixed to screen height
|
|
43
|
-
panLeft(2 * delta.x * targetDistance / element.clientHeight, object, result);
|
|
44
|
-
panUp(2 * delta.y * targetDistance / element.clientHeight, object, result);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const Controller = function (engine) {
|
|
48
|
-
const target = new Vector3();
|
|
49
|
-
let cameraDistance;
|
|
50
|
-
const cameraMinDistance = 0.1;
|
|
51
|
-
const cameraMaxDistance = 100;
|
|
52
|
-
let cameraTransform;
|
|
53
|
-
let cameraPosition;
|
|
54
|
-
let cameraDistanceDelta = 0;
|
|
55
|
-
let camera;
|
|
56
|
-
const controller = {
|
|
57
|
-
forward: false,
|
|
58
|
-
back: false,
|
|
59
|
-
left: false,
|
|
60
|
-
right: false,
|
|
61
|
-
rotateLeft: false,
|
|
62
|
-
rotateRight: false
|
|
63
|
-
};
|
|
64
|
-
const io = engine.inputEngine;
|
|
65
|
-
const domElement = engine.graphics.domElement;
|
|
66
|
-
|
|
67
|
-
window.addEventListener("mousewheel", function (event) {
|
|
68
|
-
// console.log(event);
|
|
69
|
-
const wheelDelta = event.wheelDelta;
|
|
70
|
-
//unit is about 120
|
|
71
|
-
const normalized = wheelDelta / 100;
|
|
72
|
-
if (cameraPosition !== void 0) {
|
|
73
|
-
cameraDistanceDelta -= normalized;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
//deltas to operate on
|
|
77
|
-
const translationDelta = new ThreeVector2();
|
|
78
|
-
let rotationDelta = 0;
|
|
79
|
-
|
|
80
|
-
function translateCamera2(deltaX, deltaY) {
|
|
81
|
-
const worldDisplacement = new ThreeVector3();
|
|
82
|
-
pan(new ThreeVector2(-deltaX, -deltaY), camera, domElement, 200, camera.fov, worldDisplacement);
|
|
83
|
-
//
|
|
84
|
-
cameraPosition.add(worldDisplacement);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function translateCamera(deltaX, deltaY) {
|
|
88
|
-
if (cameraPositionSwap !== void 0) {
|
|
89
|
-
const transform = cameraTransform;
|
|
90
|
-
//obtain facing direction
|
|
91
|
-
const euler = new ThreeEuler();
|
|
92
|
-
euler.setFromQuaternion(transform.rotation);
|
|
93
|
-
//vector pointing in the direction of travel
|
|
94
|
-
const vector = new ThreeVector3(deltaX, 0, deltaY);
|
|
95
|
-
const rotationMatrix = new ThreeMatrix4().makeRotationFromQuaternion(transform.rotation);
|
|
96
|
-
vector.applyMatrix4(rotationMatrix);
|
|
97
|
-
//add to delta vector
|
|
98
|
-
vector.y = 0;
|
|
99
|
-
cameraPositionSwap.add(vector);
|
|
100
|
-
target.x += vector.x;
|
|
101
|
-
target.z += vector.z;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function dollyCamera(distance) {
|
|
106
|
-
if (Number.isNaN(distance)) {
|
|
107
|
-
distance = 0;
|
|
108
|
-
} else if (distance < cameraMinDistance) {
|
|
109
|
-
distance = cameraMinDistance;
|
|
110
|
-
} else if (distance > cameraMaxDistance) {
|
|
111
|
-
distance = cameraMaxDistance;
|
|
112
|
-
}
|
|
113
|
-
const v = target.clone().sub(cameraPositionSwap);
|
|
114
|
-
v.normalize().multiplyScalar(cameraDistance - distance);
|
|
115
|
-
cameraPositionSwap.add(v);
|
|
116
|
-
cameraDistance = distance;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function rotateCameraY(delta) {
|
|
120
|
-
if (delta === 0) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (cameraTransform !== void 0) {
|
|
124
|
-
const cameraRotation = cameraTransform.rotation;
|
|
125
|
-
const euler = new ThreeEuler();
|
|
126
|
-
euler.setFromQuaternion(cameraRotation, "YXZ");
|
|
127
|
-
euler.y += delta;
|
|
128
|
-
//change camera position
|
|
129
|
-
let planarDistance = Math.abs(cameraDistance * Math.cos(euler.x));
|
|
130
|
-
let verticalDistance = cameraDistance * Math.sin(euler.x);
|
|
131
|
-
cameraPositionSwap.sub(target).applyAxisAngle(new ThreeVector3(0, 1, 0), delta).add(target);
|
|
132
|
-
//cameraPosition.x = target.x+Math.sin(delta)*planarDistance;
|
|
133
|
-
//cameraPosition.z = target.z+Math.cos(delta)*planarDistance;
|
|
134
|
-
cameraRotation.setFromEuler(euler);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const mc = new Hammer(domElement);
|
|
139
|
-
|
|
140
|
-
mc.add(new Hammer.Pan({ threshold: 0, pointers: 0 }));
|
|
141
|
-
|
|
142
|
-
mc.add(new Hammer.Swipe()).recognizeWith(mc.get('pan'));
|
|
143
|
-
mc.add(new Hammer.Rotate({ threshold: 0 })).recognizeWith(mc.get('pan'));
|
|
144
|
-
mc.add(new Hammer.Pinch({ threshold: 0 })).recognizeWith([mc.get('pan'), mc.get('rotate')]);
|
|
145
|
-
|
|
146
|
-
mc.add(new Hammer.Tap({ event: 'doubletap', taps: 2 }));
|
|
147
|
-
mc.add(new Hammer.Tap());
|
|
148
|
-
|
|
149
|
-
mc.on("panstart", onPanStart);
|
|
150
|
-
mc.on("panmove", onPanMove);
|
|
151
|
-
mc.on("rotatestart rotatemove", onRotate);
|
|
152
|
-
mc.on("pinchstart pinchmove", onPinch);
|
|
153
|
-
//mc.on("swipe", onSwipe);
|
|
154
|
-
//mc.on("tap", onTap);
|
|
155
|
-
//mc.on("doubletap", onDoubleTap);
|
|
156
|
-
let initAngle = 0;
|
|
157
|
-
|
|
158
|
-
function onRotate(ev) {
|
|
159
|
-
if (ev.type == 'rotatestart') {
|
|
160
|
-
initAngle = 0;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const delta = ev.rotation - initAngle;
|
|
164
|
-
initAngle = ev.rotation;
|
|
165
|
-
rotationDelta += delta;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let initScale = 1;
|
|
169
|
-
|
|
170
|
-
function onPinch(evt) {
|
|
171
|
-
if (evt.type == 'pinchstart') {
|
|
172
|
-
initScale = cameraPosition.y;
|
|
173
|
-
}
|
|
174
|
-
const delta = evt.scale - initScale;
|
|
175
|
-
initScale = evt.scale;
|
|
176
|
-
cameraDistanceDelta -= cameraDistance * delta;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const panDelta = new ThreeVector2();
|
|
180
|
-
|
|
181
|
-
function onPanStart(evt) {
|
|
182
|
-
panDelta.set(0, 0);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function onPanMove(evt) {
|
|
186
|
-
const _x = panDelta.x;
|
|
187
|
-
const _y = panDelta.y;
|
|
188
|
-
|
|
189
|
-
const deltaX = evt.deltaX;
|
|
190
|
-
const deltaY = evt.deltaY;
|
|
191
|
-
//change
|
|
192
|
-
const cx = deltaX - _x;
|
|
193
|
-
const cy = deltaY - _y;
|
|
194
|
-
panDelta.set(deltaX, deltaY);
|
|
195
|
-
translationDelta.x -= cx / 10;
|
|
196
|
-
translationDelta.y -= cy / 10;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const cameraPositionSwap = new Vector3();
|
|
200
|
-
|
|
201
|
-
function processKeyboardControls() {
|
|
202
|
-
let x = 0;
|
|
203
|
-
let y = 0;
|
|
204
|
-
let rotation = 0;
|
|
205
|
-
if (controller.forward) {
|
|
206
|
-
y--;
|
|
207
|
-
}
|
|
208
|
-
if (controller.back) {
|
|
209
|
-
y++;
|
|
210
|
-
}
|
|
211
|
-
if (controller.left) {
|
|
212
|
-
x--;
|
|
213
|
-
}
|
|
214
|
-
if (controller.right) {
|
|
215
|
-
x++;
|
|
216
|
-
}
|
|
217
|
-
//
|
|
218
|
-
translationDelta.x += x;
|
|
219
|
-
translationDelta.y += y;
|
|
220
|
-
if (controller.rotateLeft) {
|
|
221
|
-
rotation++;
|
|
222
|
-
}
|
|
223
|
-
if (controller.rotateRight) {
|
|
224
|
-
rotation--;
|
|
225
|
-
}
|
|
226
|
-
rotationDelta += rotation * keyboardRotationSpeed;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function animate() {
|
|
230
|
-
processKeyboardControls();
|
|
231
|
-
if (cameraPosition !== void 0) {
|
|
232
|
-
cameraPositionSwap.copy(cameraPosition);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (rotationDelta !== 0) {
|
|
236
|
-
rotateCameraY(rotationDelta * (Math.PI * 0.01));
|
|
237
|
-
rotationDelta = 0;
|
|
238
|
-
}
|
|
239
|
-
if (translationDelta.x !== 0 || translationDelta.y !== 0) {
|
|
240
|
-
translateCamera(translationDelta.x, translationDelta.y);
|
|
241
|
-
translationDelta.set(0, 0);
|
|
242
|
-
}
|
|
243
|
-
if (cameraDistanceDelta !== 0) {
|
|
244
|
-
dollyCamera(cameraDistance + cameraDistanceDelta);
|
|
245
|
-
cameraDistanceDelta = 0;
|
|
246
|
-
}
|
|
247
|
-
//
|
|
248
|
-
if (cameraPosition !== void 0 && !cameraPositionSwap.equals(cameraPosition)) {
|
|
249
|
-
cameraPosition.copy(cameraPositionSwap);
|
|
250
|
-
}
|
|
251
|
-
requestAnimationFrame(animate);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
this.init = function () {
|
|
255
|
-
cameraTransform = engine.entityManager.getComponent(engine.cameraEntity, Transform);
|
|
256
|
-
cameraPosition = cameraTransform.position;
|
|
257
|
-
cameraTransform.position.onChanged.add(function (x, y, z, _x, _y, _z) {
|
|
258
|
-
target._add(_x - x, _y - y, _z - z);
|
|
259
|
-
cameraDistance = cameraPosition.distanceTo(target);
|
|
260
|
-
});
|
|
261
|
-
cameraDistance = cameraPosition.distanceTo(target);
|
|
262
|
-
camera = engine.camera;
|
|
263
|
-
//
|
|
264
|
-
io.mapKeyBoolean(87, controller, "forward")
|
|
265
|
-
.mapKeyBoolean(83, controller, "back")
|
|
266
|
-
.mapKeyBoolean(65, controller, "left")
|
|
267
|
-
.mapKeyBoolean(68, controller, "right")
|
|
268
|
-
.mapKeyBoolean(81, controller, "rotateLeft")
|
|
269
|
-
.mapKeyBoolean(69, controller, "rotateRight");
|
|
270
|
-
};
|
|
271
|
-
animate();
|
|
272
|
-
};
|
|
273
|
-
export default Controller;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 17/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Axis-Aligned Bounding Box
|
|
8
|
-
* @param options
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
function AABB(options) {
|
|
12
|
-
let s = this.size = {
|
|
13
|
-
x: options.x !== void 0 ? options.x : 0,
|
|
14
|
-
y: options.y !== void 0 ? options.y : 0,
|
|
15
|
-
z: options.z !== void 0 ? options.z : 0
|
|
16
|
-
};
|
|
17
|
-
this.position = {
|
|
18
|
-
x: 0,
|
|
19
|
-
y: 0,
|
|
20
|
-
z: 0
|
|
21
|
-
};
|
|
22
|
-
this.positionOffset = {
|
|
23
|
-
x: 0,
|
|
24
|
-
y: 0,
|
|
25
|
-
z: 0
|
|
26
|
-
};
|
|
27
|
-
this.__bvhLeaf = void 0;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
AABB.typeName = "AABB";
|
|
32
|
-
|
|
33
|
-
export default AABB;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 25/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function AABBCollider(options) {
|
|
7
|
-
this.tags = options.tags.slice();
|
|
8
|
-
this.position = {
|
|
9
|
-
x: Number.POSITIVE_INFINITY,
|
|
10
|
-
y: Number.POSITIVE_INFINITY,
|
|
11
|
-
z: Number.POSITIVE_INFINITY
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default AABBCollider;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {Object3D} from "three";
|
|
2
|
-
import {AABB3} from "../../../core/geom/3d/aabb/AABB3";
|
|
3
|
-
import {LeafNode} from "../../../core/bvh2/LeafNode";
|
|
4
|
-
|
|
5
|
-
export default class Renderable {
|
|
6
|
-
object: Object3D
|
|
7
|
-
boundingBox: AABB3
|
|
8
|
-
matrixAutoUpdate: boolean
|
|
9
|
-
boundingBoxNeedsUpdate: boolean
|
|
10
|
-
|
|
11
|
-
bvh: LeafNode<Object3D>
|
|
12
|
-
|
|
13
|
-
constructor(object: Object3D)
|
|
14
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Vector2 from "../../../core/geom/Vector2.js";
|
|
2
|
-
|
|
3
|
-
const Sampler2DDecoder = function () {
|
|
4
|
-
this.types = {};
|
|
5
|
-
};
|
|
6
|
-
Sampler2DDecoder.prototype.registerType = function (id, r, g, b, a) {
|
|
7
|
-
this.types[id] = {
|
|
8
|
-
r: r,
|
|
9
|
-
g: g,
|
|
10
|
-
b: b,
|
|
11
|
-
a: a
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
Sampler2DDecoder.prototype.decode = function (sampler2d) {
|
|
15
|
-
const result = {};
|
|
16
|
-
const types = this.types;
|
|
17
|
-
//make a result container
|
|
18
|
-
for (let id in types) {
|
|
19
|
-
if (types.hasOwnProperty(id)) {
|
|
20
|
-
result[id] = [];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const data = sampler2d.data;
|
|
24
|
-
const dataWidth = sampler2d.width;
|
|
25
|
-
|
|
26
|
-
function recordType(id, index) {
|
|
27
|
-
const i4 = Math.floor(index / 4);
|
|
28
|
-
const x = i4 % dataWidth;
|
|
29
|
-
const y = Math.floor(i4 / dataWidth);
|
|
30
|
-
|
|
31
|
-
result[id].push(new Vector2(x, y));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//iterate over pixels
|
|
35
|
-
//TODO this can be optimized in the future using code generation and early bailouts
|
|
36
|
-
let i = 0;
|
|
37
|
-
const l = data.length;
|
|
38
|
-
for (; i < l; i += 4) {
|
|
39
|
-
const r = data[i];
|
|
40
|
-
const g = data[i + 1];
|
|
41
|
-
const b = data[i + 2];
|
|
42
|
-
const a = data[i + 3];
|
|
43
|
-
for (let typeId in types) {
|
|
44
|
-
if (!types.hasOwnProperty(typeId)) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const type = types[typeId];
|
|
48
|
-
if (type.r === r && type.g === g && type.b === b && type.a === a) {
|
|
49
|
-
//type match
|
|
50
|
-
recordType(typeId, i);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
};
|
|
57
|
-
export default Sampler2DDecoder;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 16/01/2015.
|
|
3
|
-
*/
|
|
4
|
-
import * as THREE from 'three';
|
|
5
|
-
|
|
6
|
-
const makeTerrainGeometry = function (samplerHeight, resolution, targetSize, samplePosition, sampleSize) {
|
|
7
|
-
const width = resolution.x;
|
|
8
|
-
const height = resolution.y;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const gridX1 = width;
|
|
12
|
-
const gridY1 = height;
|
|
13
|
-
|
|
14
|
-
const gridX2 = width - 1;
|
|
15
|
-
const gridY2 = height - 1;
|
|
16
|
-
|
|
17
|
-
const xScale = targetSize.x / gridX2;
|
|
18
|
-
const yScale = targetSize.y / gridY2;
|
|
19
|
-
|
|
20
|
-
let offset = 0;
|
|
21
|
-
|
|
22
|
-
const vertexCount = gridX1 * gridY1;
|
|
23
|
-
const geometry = new THREE.Geometry();
|
|
24
|
-
const vertices = geometry.vertices = new Array(vertexCount);
|
|
25
|
-
const vertexNormals = new Array(vertexCount);
|
|
26
|
-
const faces = geometry.faces = new Array(gridX2 * gridY2 * 2);
|
|
27
|
-
const tempUVs = new Array(vertexCount);
|
|
28
|
-
let y, x;
|
|
29
|
-
//fill vertices
|
|
30
|
-
for (y = 0; y < gridY1; y++) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (x = 0; x < gridX1; x++) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const u = x / gridX2;
|
|
37
|
-
const v = y / gridY2;
|
|
38
|
-
//get sample
|
|
39
|
-
const val = samplerHeight.sample(u, v);
|
|
40
|
-
const v3 = new THREE.Vector3(x * xScale, val, y * yScale);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
vertices[offset] = v3;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
tempUVs[offset] = new THREE.Vector2(u, 1 - v);
|
|
47
|
-
//normal sampling
|
|
48
|
-
//samplerNormal.sample(u, v, vertexNormal);
|
|
49
|
-
vertexNormals[offset] = new THREE.Vector3();
|
|
50
|
-
offset += 1;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const tempColors = [];
|
|
55
|
-
|
|
56
|
-
const cb = new THREE.Vector3(), ab = new THREE.Vector3();
|
|
57
|
-
|
|
58
|
-
function addFace(a, b, c) {
|
|
59
|
-
//compute normal
|
|
60
|
-
const vA = vertices[a];
|
|
61
|
-
const vB = vertices[b];
|
|
62
|
-
const vC = vertices[c];
|
|
63
|
-
|
|
64
|
-
cb.subVectors(vC, vB);
|
|
65
|
-
ab.subVectors(vA, vB);
|
|
66
|
-
cb.cross(ab);
|
|
67
|
-
|
|
68
|
-
cb.normalize();
|
|
69
|
-
//
|
|
70
|
-
const f0 = new THREE.Face3(a, b, c, cb.clone(), tempColors);
|
|
71
|
-
//write vertex normals
|
|
72
|
-
const vnA = vertexNormals[a];
|
|
73
|
-
const vnB = vertexNormals[b];
|
|
74
|
-
const vnC = vertexNormals[c];
|
|
75
|
-
vnA.add(cb);
|
|
76
|
-
vnB.add(cb);
|
|
77
|
-
vnC.add(cb);
|
|
78
|
-
f0.vertexNormals = [vnA, vnB, vnC];
|
|
79
|
-
//
|
|
80
|
-
const f0uv = [tempUVs[a], tempUVs[b], tempUVs[c]];
|
|
81
|
-
faces[offset] = f0;
|
|
82
|
-
geometry.faceVertexUvs[0][offset] = f0uv;
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
offset = 0;
|
|
87
|
-
//add faces
|
|
88
|
-
for (y = 0; y < gridY2; y++) {
|
|
89
|
-
|
|
90
|
-
for (x = 0; x < gridX2; x++) {
|
|
91
|
-
const a = x + gridX1 * y;
|
|
92
|
-
const b = x + gridX1 * (y + 1);
|
|
93
|
-
const c = (x + 1) + gridX1 * (y + 1);
|
|
94
|
-
const d = (x + 1) + gridX1 * y;
|
|
95
|
-
addFace(a, b, d);
|
|
96
|
-
offset++;
|
|
97
|
-
addFace(b, c, d);
|
|
98
|
-
offset++;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//normalize vertex normals
|
|
102
|
-
let i = 0;
|
|
103
|
-
const l = vertexNormal.length;
|
|
104
|
-
for (; i < l; i++) {
|
|
105
|
-
vertexNormal[i].normalize();
|
|
106
|
-
}
|
|
107
|
-
//CleanupGeometry(geometry);
|
|
108
|
-
return geometry;
|
|
109
|
-
};
|
|
110
|
-
export default makeTerrainGeometry;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 25/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import Tag from '../components/Tag.js';
|
|
6
|
-
import { Transform } from '../transform/Transform.js';
|
|
7
|
-
import AABB from '../components/AABB.js';
|
|
8
|
-
import AABBCollider from '../components/AABBCollider.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AABBColliderSystem extends System {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.dependencies = [AABBCollider];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get componentClass() {
|
|
19
|
-
return AABBCollider;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
add(component, entity) {
|
|
23
|
-
this.entityManager.getComponentAsync(entity, Transform, function (transform) {
|
|
24
|
-
const p0 = component.position;
|
|
25
|
-
const p1 = transform.position;
|
|
26
|
-
p0.x = p1.x;
|
|
27
|
-
p0.y = p1.y;
|
|
28
|
-
p0.z = p1.z;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
remove(component) {
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
update(timeDelta) {
|
|
36
|
-
const entityManager = this.entityManager;
|
|
37
|
-
const aabbSystem = entityManager.getOwnerSystemByComponentClass(AABB);
|
|
38
|
-
entityManager.traverseEntities([Transform, AABBCollider], function (transform, collider, entity) {
|
|
39
|
-
|
|
40
|
-
const p1 = transform.position;
|
|
41
|
-
const p2 = collider.position;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (p2.x !== p1.x || p2.y !== p1.y || p2.z !== p1.z) {
|
|
45
|
-
aabbSystem.traverseLineSegment(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, function (otherEntity) {
|
|
46
|
-
const tag = entityManager.getComponent(otherEntity, Tag);
|
|
47
|
-
if (collider.tags.indexOf(tag.name) != -1) {
|
|
48
|
-
entityManager.sendEvent(entity, "collision", otherEntity);
|
|
49
|
-
return false; //stop traversal
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
//write new position
|
|
53
|
-
p2.x = p1.x;
|
|
54
|
-
p2.y = p1.y;
|
|
55
|
-
p2.z = p1.z;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default AABBColliderSystem;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 17/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import AABB from '../components/AABB.js';
|
|
6
|
-
import { Transform } from '../transform/Transform.js';
|
|
7
|
-
import { BinaryNode } from '../../../core/bvh2/BinaryNode.js';
|
|
8
|
-
|
|
9
|
-
class AABBSystem extends System {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
|
|
13
|
-
this.dependencies = [AABB];
|
|
14
|
-
|
|
15
|
-
const bvh = this.bvh = new BinaryNode();
|
|
16
|
-
bvh.setBounds(0, 0, 0, 0, 0, 0);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get componentClass() {
|
|
20
|
-
return AABB;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
traverseLineSegment(startX, startY, startZ, endX, endY, endZ, visitor) {
|
|
24
|
-
this.bvh.traverseSegmentLeafIntersections(startX, startY, startZ, endX, endY, endZ, function (leaf) {
|
|
25
|
-
visitor(leaf.object);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
link(aabb, entity) {
|
|
30
|
-
const em = this.entityManager;
|
|
31
|
-
const bvh = this.bvh;
|
|
32
|
-
em.getComponentAsync(entity, Transform, function (transform) {
|
|
33
|
-
const p = transform.position;
|
|
34
|
-
const s = aabb.size;
|
|
35
|
-
const o = aabb.positionOffset;
|
|
36
|
-
const x2 = s.x / 2;
|
|
37
|
-
const y2 = s.y / 2;
|
|
38
|
-
const z2 = s.z / 2;
|
|
39
|
-
//
|
|
40
|
-
const px = p.x + o.x,
|
|
41
|
-
py = p.y + o.y,
|
|
42
|
-
pz = p.z + o.z;
|
|
43
|
-
const x0 = px - x2,
|
|
44
|
-
y0 = py - y2,
|
|
45
|
-
z0 = pz - z2,
|
|
46
|
-
x1 = px + x2,
|
|
47
|
-
y1 = py + y2,
|
|
48
|
-
z1 = pz + z2;
|
|
49
|
-
aabb.__bvhLeaf = bvh.insert(x0, y0, z0, x1, y1, z1, entity);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
unlink(component, entity) {
|
|
54
|
-
if (component.__bvhLeaf !== void 0) {
|
|
55
|
-
component.__bvhLeaf.remove();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
update(timeDelta) {
|
|
60
|
-
const em = this.entityManager;
|
|
61
|
-
em.traverseEntities([AABB, Transform], function (aabb, transform, entity) {
|
|
62
|
-
const p0 = transform.position;
|
|
63
|
-
const offset = aabb.positionOffset;
|
|
64
|
-
const x0 = p0.x + offset.x,
|
|
65
|
-
y0 = p0.y + offset.y,
|
|
66
|
-
z0 = p0.z + offset.z;
|
|
67
|
-
const p1 = aabb.position;
|
|
68
|
-
if (x0 !== p1.x || y0 !== p1.y || z0 !== p1.z) {
|
|
69
|
-
let dx = x0 - p1.x,
|
|
70
|
-
dy = y0 - p1.y,
|
|
71
|
-
dz = z0 - p1.z;
|
|
72
|
-
//
|
|
73
|
-
const s = aabb.size;
|
|
74
|
-
const x2 = s.x / 2,
|
|
75
|
-
y2 = s.y / 2,
|
|
76
|
-
z2 = s.z / 2;
|
|
77
|
-
//aabb.__bvhLeaf.move(dx, dy, dz);
|
|
78
|
-
aabb.__bvhLeaf.resize(x0 - x2, y0 - y2, z0 - z2, x0 + x2, y0 + y2, z0 + z2);
|
|
79
|
-
//
|
|
80
|
-
p1.x = x0;
|
|
81
|
-
p1.y = y0;
|
|
82
|
-
p1.z = z0;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export default AABBSystem;
|