bg2e-js 2.0.1 → 2.0.2
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/bg2e-js.js +11001 -0
- package/dist/bg2e-js.js.map +1 -0
- package/package.json +17 -6
- package/app/AppController.d.ts +0 -37
- package/app/AppController.js +0 -32
- package/app/Canvas.d.ts +0 -42
- package/app/Canvas.js +0 -98
- package/app/EventBase.js +0 -8
- package/app/KeyboardEvent.js +0 -51
- package/app/MainLoop.d.ts +0 -245
- package/app/MainLoop.js +0 -251
- package/app/MouseEvent.js +0 -77
- package/app/TouchEvent.js +0 -15
- package/base/Color.js +0 -131
- package/base/Environment.js +0 -78
- package/base/Light.js +0 -176
- package/base/Material.js +0 -619
- package/base/PolyList.js +0 -336
- package/base/Texture.js +0 -545
- package/db/Bg2LoaderPlugin.js +0 -113
- package/db/DBPluginApi.js +0 -40
- package/db/Loader.js +0 -91
- package/db/LoaderPlugin.js +0 -26
- package/db/MtlParser.js +0 -7
- package/db/ObjLoaderPlugin.js +0 -51
- package/db/ObjParser.js +0 -233
- package/db/ObjWriterPlugin.js +0 -18
- package/db/VitscnjLoaderPlugin.js +0 -87
- package/db/Writer.js +0 -49
- package/db/WriterPlugin.js +0 -20
- package/debug/DebugRenderer.js +0 -138
- package/debug/WebGLTextureViewer.js +0 -67
- package/manipulation/SelectionBuffer.js +0 -65
- package/manipulation/SelectionHighlight.js +0 -69
- package/manipulation/SelectionIdAssignVisitor.js +0 -86
- package/manipulation/SelectionManager.js +0 -134
- package/manipulation/SelectionMode.js +0 -6
- package/math/Mat3.js +0 -248
- package/math/Mat4.js +0 -694
- package/math/MatrixStrategy.js +0 -23
- package/math/Quat.js +0 -60
- package/math/Vec.js +0 -728
- package/math/constants.js +0 -44
- package/math/functions.js +0 -104
- package/math/index.js +0 -74
- package/phsics/joint.js +0 -124
- package/primitives/arrow.js +0 -58
- package/primitives/cone.js +0 -137
- package/primitives/cube.js +0 -59
- package/primitives/cylinder.js +0 -215
- package/primitives/index.js +0 -13
- package/primitives/plane.js +0 -31
- package/primitives/sphere.js +0 -808
- package/render/BRDFIntegrationMap.js +0 -4
- package/render/Environment.js +0 -105
- package/render/EnvironmentRenderer.js +0 -12
- package/render/FrameBuffer.js +0 -26
- package/render/MaterialRenderer.js +0 -28
- package/render/Pipeline.js +0 -83
- package/render/PolyListRenderer.js +0 -42
- package/render/RenderBuffer.js +0 -189
- package/render/RenderQueue.js +0 -162
- package/render/RenderState.js +0 -82
- package/render/Renderer.js +0 -202
- package/render/SceneAppController.js +0 -208
- package/render/SceneRenderer.js +0 -310
- package/render/Shader.js +0 -21
- package/render/ShadowRenderer.js +0 -159
- package/render/SkyCube.js +0 -77
- package/render/SkySphere.js +0 -94
- package/render/TextureMergerRenderer.js +0 -58
- package/render/TextureRenderer.js +0 -29
- package/render/webgl/FrameBuffer.js +0 -9
- package/render/webgl/MaterialRenderer.js +0 -99
- package/render/webgl/Pipeline.js +0 -82
- package/render/webgl/PolyListRenderer.js +0 -224
- package/render/webgl/RenderBuffer.js +0 -244
- package/render/webgl/Renderer.js +0 -239
- package/render/webgl/SceneRenderer.js +0 -43
- package/render/webgl/ShaderProgram.js +0 -350
- package/render/webgl/ShadowRenderer.js +0 -6
- package/render/webgl/SkyCube.js +0 -15
- package/render/webgl/SkySphere.js +0 -14
- package/render/webgl/State.js +0 -149
- package/render/webgl/TextureRenderer.js +0 -167
- package/render/webgl/VertexBuffer.js +0 -128
- package/scene/Camera.js +0 -378
- package/scene/Chain.js +0 -43
- package/scene/ChainJoint.js +0 -55
- package/scene/Component.js +0 -146
- package/scene/ComponentMap.js +0 -99
- package/scene/Drawable.js +0 -130
- package/scene/EnvironmentComponent.js +0 -123
- package/scene/FindNodeVisitor.js +0 -55
- package/scene/LightComponent.js +0 -146
- package/scene/MatrixState.js +0 -39
- package/scene/Node.js +0 -300
- package/scene/NodeVisitor.js +0 -12
- package/scene/OrbitCameraController.js +0 -407
- package/scene/SmoothOrbitCameraController.js +0 -92
- package/scene/Transform.js +0 -74
- package/scene/index.js +0 -24
- package/shaders/BasicDiffuseColorShader.js +0 -91
- package/shaders/BasicPBRLightShader.js +0 -238
- package/shaders/DebugRenderShader.js +0 -79
- package/shaders/DepthRenderShader.js +0 -69
- package/shaders/IrradianceMapCubeShader.js +0 -99
- package/shaders/PBRLightIBLShader.js +0 -380
- package/shaders/PickSelectionShader.js +0 -75
- package/shaders/PresentDebugFramebufferShader.js +0 -90
- package/shaders/PresentTextureShader.js +0 -73
- package/shaders/SelectionHighlightShader.js +0 -98
- package/shaders/ShaderFunction.js +0 -72
- package/shaders/SkyCubeShader.js +0 -78
- package/shaders/SkySphereShader.js +0 -77
- package/shaders/SpecularMapCubeShader.js +0 -145
- package/shaders/TextureMergerShader.js +0 -127
- package/shaders/webgl_shader_lib.js +0 -187
- package/tools/BinaryResourceProvider.js +0 -15
- package/tools/ImageResourceProvider.js +0 -65
- package/tools/MaterialModifier.js +0 -228
- package/tools/Resource.js +0 -177
- package/tools/ResourceProvider.js +0 -56
- package/tools/TextResourceProvider.js +0 -24
- package/tools/TextureCache.js +0 -44
- package/tools/TextureResourceDatabase.js +0 -87
- package/tools/UserAgent.js +0 -294
- package/tools/VideoResourceProvider.js +0 -51
- package/tools/WriteStrategy.js +0 -22
- package/tools/base64.js +0 -15
- package/tools/crypto.js +0 -15
- package/tools/endiantess.js +0 -15
- package/tools/image.js +0 -15
- package/tools/index.js +0 -33
- package/tools/processType.js +0 -56
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import Color from "../base/Color";
|
|
2
|
-
import Vec from "../math/Vec";
|
|
3
|
-
import { ProjectionStrategy, OrthographicProjectionStrategy } from "./Camera";
|
|
4
|
-
import Component from "./Component";
|
|
5
|
-
import { SpecialKey } from "../app/KeyboardEvent";
|
|
6
|
-
import MouseEvent, {
|
|
7
|
-
leftMouseButton,
|
|
8
|
-
middleMouseButton,
|
|
9
|
-
rightMouseButton
|
|
10
|
-
} from "../app/MouseEvent";
|
|
11
|
-
import { degreesToRadians } from "../math/functions";
|
|
12
|
-
|
|
13
|
-
export const Action = {
|
|
14
|
-
NONE: 0,
|
|
15
|
-
ROTATE: 1,
|
|
16
|
-
PAN: 2,
|
|
17
|
-
ZOOM: 3
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export function getOrbitAction(cameraCtrl) {
|
|
21
|
-
let left = leftMouseButton(),
|
|
22
|
-
middle = middleMouseButton(),
|
|
23
|
-
right = rightMouseButton();
|
|
24
|
-
|
|
25
|
-
switch (true) {
|
|
26
|
-
case left==cameraCtrl._rotateButtons.left &&
|
|
27
|
-
middle==cameraCtrl._rotateButtons.middle &&
|
|
28
|
-
right==cameraCtrl._rotateButtons.right:
|
|
29
|
-
return Action.ROTATE;
|
|
30
|
-
case left==cameraCtrl._panButtons.left &&
|
|
31
|
-
middle==cameraCtrl._panButtons.middle &&
|
|
32
|
-
right==cameraCtrl._panButtons.right:
|
|
33
|
-
return Action.PAN;
|
|
34
|
-
case left==cameraCtrl._zoomButtons.left &&
|
|
35
|
-
middle==cameraCtrl._zoomButtons.middle &&
|
|
36
|
-
right==cameraCtrl._zoomButtons.right:
|
|
37
|
-
return Action.ZOOM;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export default class OrbitCameraController extends Component {
|
|
41
|
-
constructor(id = null) {
|
|
42
|
-
super(id ?? "OrbitCameraController");
|
|
43
|
-
|
|
44
|
-
this._rotateButtons = { left:true, middle:false, right:false };
|
|
45
|
-
this._panButtons = { left:false, middle:false, right:true };
|
|
46
|
-
this._zoomButtons = { left:false, middle:true, right:false };
|
|
47
|
-
|
|
48
|
-
this._rotation = new Vec([0, 0]);
|
|
49
|
-
this._distance = 5;
|
|
50
|
-
this._center = new Vec([0, 0, 0]);
|
|
51
|
-
this._rotationSpeed = 0.2;
|
|
52
|
-
this._forward = 0;
|
|
53
|
-
this._left = 0;
|
|
54
|
-
this._wheelSpeed = 1;
|
|
55
|
-
this._minFocus = 2;
|
|
56
|
-
|
|
57
|
-
this._minPitch = -85.0;
|
|
58
|
-
this._maxPitch = 85.0;
|
|
59
|
-
this._minDistance = 0.4;
|
|
60
|
-
this._maxDistance = 24.0;
|
|
61
|
-
|
|
62
|
-
this._maxX = 45;
|
|
63
|
-
this._minX = -45;
|
|
64
|
-
this._minY = -45;
|
|
65
|
-
this._maxY = 45;
|
|
66
|
-
this._maxZ = 45;
|
|
67
|
-
this._minZ = -45;
|
|
68
|
-
|
|
69
|
-
this._displacementSpeed = 0.1;
|
|
70
|
-
|
|
71
|
-
this._enabled = true;
|
|
72
|
-
|
|
73
|
-
// Non-serializable attributes
|
|
74
|
-
this._keys = {};
|
|
75
|
-
this._lastTouch = [];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
clone() {
|
|
79
|
-
const result = new OrbitCameraController();
|
|
80
|
-
result.assign(this);
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
assign(other) {
|
|
85
|
-
this._rotateButtons.left = other._rotateButtons.left;
|
|
86
|
-
this._rotateButtons.middle = other._rotateButtons.middle;
|
|
87
|
-
this._rotateButtons.right = other._rotateButtons.right;
|
|
88
|
-
|
|
89
|
-
this._panButtons.left = other._panButtons.left;
|
|
90
|
-
this._panButtons.middle = other._panButtons.middle;
|
|
91
|
-
this._panButtons.right = other._panButtons.right;
|
|
92
|
-
|
|
93
|
-
this._zoomButtons.left = other._zoomButtons.left;
|
|
94
|
-
this._zoomButtons.middle = other._zoomButtons.middle;
|
|
95
|
-
this._zoomButtons.right = other._zoomButtons.right;
|
|
96
|
-
|
|
97
|
-
this._rotation = new Vec(other.rotation);
|
|
98
|
-
this._distance = other.distance;
|
|
99
|
-
this._center = new Vec(other.center);
|
|
100
|
-
this._rotationSpeed = other.rotationSpeed;
|
|
101
|
-
this._forward = other.forward;
|
|
102
|
-
this._left = other.left;
|
|
103
|
-
this._wheelSpeed = other.wheelSpeed;
|
|
104
|
-
this._minFocus = other.minCameraFocus;
|
|
105
|
-
this._minPitch = other.minPitch;
|
|
106
|
-
this._maxPitch = other.maxPitch;
|
|
107
|
-
this._minDistance = other.minDistance;
|
|
108
|
-
this._maxDistance = other.maxDistance;
|
|
109
|
-
this._maxX = other.maxX;
|
|
110
|
-
this._minX = other.minX;
|
|
111
|
-
this._minY = other.minY;
|
|
112
|
-
this._maxY = other.maxY;
|
|
113
|
-
this._maxZ = other.maxZ;
|
|
114
|
-
this._minZ = other.minZ;
|
|
115
|
-
this._displacementSpeed = other.displacementSpeed;
|
|
116
|
-
this._enabled = other.enabled;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get rotation() { return this._rotation; }
|
|
120
|
-
set rotation(r) { this._rotation = r; }
|
|
121
|
-
get distance() { return this._distance; }
|
|
122
|
-
set distance(d) { this._distance = d; }
|
|
123
|
-
get center() { return this._center; }
|
|
124
|
-
set center(c) { this._center = c; }
|
|
125
|
-
get rotationSpeed() { return this._rotationSpeed; }
|
|
126
|
-
set rotationSpeed(rs) { this._rotationSpeed = rs; }
|
|
127
|
-
get forward() { return this._forward; }
|
|
128
|
-
set forward(f) { this._forward = f; }
|
|
129
|
-
get left() { return this._left; }
|
|
130
|
-
set left(l) { this._left = l; }
|
|
131
|
-
get wheelSpeed() { return this._wheelSpeed; }
|
|
132
|
-
set wheelSpeed(w) { this._wheelSpeed = w; }
|
|
133
|
-
|
|
134
|
-
get viewWidth() { return this._viewWidth; }
|
|
135
|
-
|
|
136
|
-
get minCameraFocus() { return this._minFocus; }
|
|
137
|
-
set minCameraFocus(f) { this._minFocus = f; }
|
|
138
|
-
get minPitch() { return this._minPitch; }
|
|
139
|
-
set minPitch(p) { this._minPitch = p; }
|
|
140
|
-
get maxPitch() { return this._maxPitch; }
|
|
141
|
-
set maxPitch(p) { this._maxPitch = p; }
|
|
142
|
-
get minDistance() { return this._minDistance; }
|
|
143
|
-
set minDistance(d) { this._minDistance = d; }
|
|
144
|
-
get maxDistance() { return this._maxDistance; }
|
|
145
|
-
set maxDistance(d) { this._maxDistance = d; }
|
|
146
|
-
|
|
147
|
-
get minX() { return this._minX; }
|
|
148
|
-
get maxX() { return this._maxX; }
|
|
149
|
-
get minY() { return this._minY; }
|
|
150
|
-
get maxY() { return this._maxY; }
|
|
151
|
-
get minZ() { return this._minZ; }
|
|
152
|
-
get maxZ() { return this._maxZ; }
|
|
153
|
-
|
|
154
|
-
set minX(val) { this._minX = val; }
|
|
155
|
-
set maxX(val) { this._maxX = val; }
|
|
156
|
-
set minY(val) { this._minY = val; }
|
|
157
|
-
set maxY(val) { this._maxY = val; }
|
|
158
|
-
set minZ(val) { this._minZ = val; }
|
|
159
|
-
set maxZ(val) { this._maxZ = val; }
|
|
160
|
-
|
|
161
|
-
get displacementSpeed() { return this._displacementSpeed; }
|
|
162
|
-
set displacementSpeed(s) { this._displacementSpeed = s; }
|
|
163
|
-
|
|
164
|
-
get enabled() { return this._enabled; }
|
|
165
|
-
set enabled(e) { this._enabled = e; }
|
|
166
|
-
|
|
167
|
-
setRotateButtons(left,middle,right) {
|
|
168
|
-
this._rotateButtons = { left:left, middle:middle, right:right };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
setPanButtons(left,middle,right) {
|
|
172
|
-
this._panButtons = { left:left, middle:middle, right:right };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
setZoomButtons(left,middle,right) {
|
|
176
|
-
this._zoomButtons = { left:left, middle:middle, right:right };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async deserialize(sceneData,loader) {
|
|
180
|
-
this._rotateButtons = sceneData.rotateButtons || this._rotateButtons;
|
|
181
|
-
this._panButtons = sceneData.panButtons || this._panButtons;
|
|
182
|
-
this._zoomButtons = sceneData.zoomButtons || this._zoomButtons;
|
|
183
|
-
this._rotation = new Vec(sceneData.rotation) || this._rotation;
|
|
184
|
-
this._distance = sceneData.distance!==undefined ? sceneData.distance : this._distance;
|
|
185
|
-
this._center = new Vec(sceneData.center) || this._center;
|
|
186
|
-
this._rotationSpeed = sceneData.rotationSpeed!==undefined ? sceneData.rotationSpeed : this._rotationSpeed;
|
|
187
|
-
this._forward = sceneData.forward!==undefined ? sceneData.forward : this._forward;
|
|
188
|
-
this._left = sceneData.left!==undefined ? sceneData.left : this._left;
|
|
189
|
-
this._wheelSpeed = sceneData.wheelSpeed!==undefined ? sceneData.wheelSpeed : this._wheelSpeed;
|
|
190
|
-
this._minFocus = sceneData.minFocus!==undefined ? sceneData.minFocus : this._minFocus;
|
|
191
|
-
this._minPitch = sceneData.minPitch!==undefined ? sceneData.minPitch : this._minPitch;
|
|
192
|
-
this._maxPitch = sceneData.maxPitch!==undefined ? sceneData.maxPitch : this._maxPitch;
|
|
193
|
-
this._minDistance = sceneData.minDistance!==undefined ? sceneData.minDistance : this._minDistance;
|
|
194
|
-
this._maxDistance = sceneData.maxDistance!==undefined ? sceneData.maxDistance : this._maxDistance;
|
|
195
|
-
this._maxX = sceneData.maxX!==undefined ? sceneData.maxX : this._maxX;
|
|
196
|
-
this._minX = sceneData.minX!==undefined ? sceneData.minX : this._minX;
|
|
197
|
-
this._minY = sceneData.minY!==undefined ? sceneData.minY : this._minY;
|
|
198
|
-
this._maxY = sceneData.maxY!==undefined ? sceneData.maxY : this._maxY;
|
|
199
|
-
this._maxZ = sceneData.maxZ!==undefined ? sceneData.maxZ : this._maxZ;
|
|
200
|
-
this._minZ = sceneData.minZ!==undefined ? sceneData.minZ : this._minZ;
|
|
201
|
-
this._displacementSpeed = sceneData.displacementSpeed!==undefined ? sceneData.displacementSpeed : this._displacementSpeed;
|
|
202
|
-
this._enabled = sceneData.enabled!==undefined ? sceneData.enabled : this._enabled;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async serialize(sceneData,writer) {
|
|
206
|
-
super.serialize(sceneData,writer);
|
|
207
|
-
sceneData.rotateButtons = this._rotateButtons;
|
|
208
|
-
sceneData.panButtons = this._panButtons;
|
|
209
|
-
sceneData.zoomButtons = this._zoomButtons;
|
|
210
|
-
sceneData.rotation = this._rotation.toArray();
|
|
211
|
-
sceneData.distance = this._distance;
|
|
212
|
-
sceneData.center = this._center.toArray();
|
|
213
|
-
sceneData.rotationSpeed = this._rotationSpeed;
|
|
214
|
-
sceneData.forward = this._forward;
|
|
215
|
-
sceneData.left = this._left;
|
|
216
|
-
sceneData.wheelSpeed = this._wheelSpeed;
|
|
217
|
-
sceneData.minFocus = this._minFocus;
|
|
218
|
-
sceneData.minPitch = this._minPitch;
|
|
219
|
-
sceneData.maxPitch = this._maxPitch;
|
|
220
|
-
sceneData.minDistance = this._minDistance;
|
|
221
|
-
sceneData.maxDistance = this._maxDistance;
|
|
222
|
-
sceneData.maxX = this._maxX;
|
|
223
|
-
sceneData.minX = this._minX;
|
|
224
|
-
sceneData.minY = this._minY;
|
|
225
|
-
sceneData.maxY = this._maxY;
|
|
226
|
-
sceneData.maxZ = this._maxZ;
|
|
227
|
-
sceneData.minZ = this._minZ;
|
|
228
|
-
sceneData.displacementSpeed = this._displacementSpeed;
|
|
229
|
-
sceneData.enabled = this._enabled;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
willUpdate(delta) {
|
|
233
|
-
let orthoStrategy = this.camera && this.camera.projectionStrategy instanceof OrthographicProjectionStrategy ?
|
|
234
|
-
this.camera.projectionStrategy : null;
|
|
235
|
-
|
|
236
|
-
if (this.transform && this.enabled) {
|
|
237
|
-
let forward = this.transform.matrix.forwardVector;
|
|
238
|
-
let left = this.transform.matrix.leftVector;
|
|
239
|
-
forward.scale(this._forward);
|
|
240
|
-
left.scale(this._left);
|
|
241
|
-
this._center = Vec.Add(Vec.Add(this._center, forward), left);
|
|
242
|
-
|
|
243
|
-
let pitch = this._rotation.x>this._minPitch ? this._rotation.x:this._minPitch;
|
|
244
|
-
pitch = pitch<this._maxPitch ? pitch : this._maxPitch;
|
|
245
|
-
this._rotation.x = pitch;
|
|
246
|
-
|
|
247
|
-
this._distance = this._distance>this._minDistance ? this._distance:this._minDistance;
|
|
248
|
-
this._distance = this._distance<this._maxDistance ? this._distance:this._maxDistance;
|
|
249
|
-
|
|
250
|
-
if (this._mouseButtonPressed) {
|
|
251
|
-
let displacement = new Vec([0,0,0]);
|
|
252
|
-
if (this._keys[SpecialKey.UP_ARROW]) {
|
|
253
|
-
displacement = Vec.Add(displacement, this.transform.matrix.backwardVector);
|
|
254
|
-
}
|
|
255
|
-
if (this._keys[SpecialKey.DOWN_ARROW]) {
|
|
256
|
-
displacement = Vec.Add(displacement, this.transform.matrix.forwardVector);
|
|
257
|
-
}
|
|
258
|
-
if (this._keys[SpecialKey.LEFT_ARROW]) {
|
|
259
|
-
displacement = Vec.Add(displacement, this.transform.matrix.leftVector);
|
|
260
|
-
}
|
|
261
|
-
if (this._keys[SpecialKey.RIGHT_ARROW]) {
|
|
262
|
-
displacement = Vec.Add(displacement, this.transform.matrix.rightVector);
|
|
263
|
-
}
|
|
264
|
-
displacement.scale(this._displacementSpeed);
|
|
265
|
-
this._center = Vec.Add(this._center, displacement);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (this._center.x<this._minX) this._center.x = this._minX;
|
|
269
|
-
else if (this._center.x>this._maxX) this._center.x = this._maxX;
|
|
270
|
-
|
|
271
|
-
if (this._center.y<this._minY) this._center.y = this._minY;
|
|
272
|
-
else if (this._center.y>this._maxY) this._center.y = this._maxY;
|
|
273
|
-
|
|
274
|
-
if (this._center.z<this._minZ) this._center.z = this._minZ;
|
|
275
|
-
else if (this._center.z>this._maxZ) this._center.z = this._maxZ;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
this.transform.matrix.identity();
|
|
279
|
-
|
|
280
|
-
if (orthoStrategy) {
|
|
281
|
-
orthoStrategy.viewWidth = this._viewWidth;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.transform.matrix.translate(0,0,this._distance);
|
|
285
|
-
if (this.camera) {
|
|
286
|
-
// Update the camera focus distance to optimize the shadow map rendering
|
|
287
|
-
this.camera.focusDistance = this._distance;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
this.transform.matrix.rotate(degreesToRadians(pitch), -1,0,0)
|
|
291
|
-
.rotate(degreesToRadians(this._rotation.y), 0,1,0)
|
|
292
|
-
.translate(this._center);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
mouseDown(evt) {
|
|
298
|
-
if (!this.enabled) return;
|
|
299
|
-
this._mouseButtonPressed = true;
|
|
300
|
-
this._lastPos = new Vec(evt.x,evt.y);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
mouseUp(evt) {
|
|
304
|
-
this._mouseButtonPressed = false;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
mouseDrag(evt) {
|
|
308
|
-
if (this.transform && this._lastPos && this.enabled) {
|
|
309
|
-
let delta = new Vec(this._lastPos.y - evt.y,
|
|
310
|
-
this._lastPos.x - evt.x);
|
|
311
|
-
this._lastPos.set(evt.x,evt.y);
|
|
312
|
-
let orthoStrategy = this.camera && this.camera.projectionStrategy instanceof OrthographicProjectionStrategy || false;
|
|
313
|
-
|
|
314
|
-
switch (getOrbitAction(this)) {
|
|
315
|
-
case Action.ROTATE:
|
|
316
|
-
delta.x = delta.x * -1;
|
|
317
|
-
this._rotation = Vec.Add(this._rotation, delta.scale(0.5));
|
|
318
|
-
break;
|
|
319
|
-
case Action.PAN:
|
|
320
|
-
let up = this.transform.matrix.upVector;
|
|
321
|
-
let left = this.transform.matrix.leftVector;
|
|
322
|
-
|
|
323
|
-
if (orthoStrategy) {
|
|
324
|
-
up.scale(delta.x * -0.0005 * this._viewWidth);
|
|
325
|
-
left.scale(delta.y * -0.0005 * this._viewWidth);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
up.scale(delta.x * -0.001 * this._distance);
|
|
329
|
-
left.scale(delta.y * -0.001 * this._distance);
|
|
330
|
-
}
|
|
331
|
-
this._center = Vec.Add(Vec.Add(this._center, up), left);
|
|
332
|
-
break;
|
|
333
|
-
case Action.ZOOM:
|
|
334
|
-
this._distance += delta.x * 0.01 * this._distance;
|
|
335
|
-
this._viewWidth += delta.x * 0.01 * this._viewWidth;
|
|
336
|
-
if (this._viewWidth<0.5) this._viewWidth = 0.5;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
mouseWheel(evt) {
|
|
343
|
-
if (!this.enabled) return;
|
|
344
|
-
let mult = this._distance>0.01 ? this._distance:0.01;
|
|
345
|
-
let wMult = this._viewWidth>1 ? this._viewWidth:1;
|
|
346
|
-
this._distance += evt.delta * 0.001 * mult * this._wheelSpeed;
|
|
347
|
-
this._viewWidth += evt.delta * 0.0001 * wMult * this._wheelSpeed;
|
|
348
|
-
if (this._viewWidth<0.5) this._viewWidth = 0.5;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
touchStart(evt) {
|
|
352
|
-
if (!this.enabled) return;
|
|
353
|
-
this._lastTouch = evt.touches;
|
|
354
|
-
evt.stopPropagation();
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
touchMove(evt) {
|
|
358
|
-
if (this._lastTouch.length==evt.touches.length && this.transform && this.enabled) {
|
|
359
|
-
if (this._lastTouch.length==1) {
|
|
360
|
-
// Rotate
|
|
361
|
-
let last = this._lastTouch[0];
|
|
362
|
-
let t = evt.touches[0];
|
|
363
|
-
let delta = new Vec((last.y - t.y) * -1.0, last.x - t.x);
|
|
364
|
-
|
|
365
|
-
this._rotation = Vec.Add(this._rotation, delta.scale(0.5));
|
|
366
|
-
}
|
|
367
|
-
else if (this._lastTouch.length==2) {
|
|
368
|
-
// Pan/zoom
|
|
369
|
-
let l0 = this._lastTouch[0];
|
|
370
|
-
let l1 = this._lastTouch[1];
|
|
371
|
-
let t0 = null;
|
|
372
|
-
let t1 = null;
|
|
373
|
-
evt.touches.forEach((touch) => {
|
|
374
|
-
if (touch.identifier==l0.identifier) {
|
|
375
|
-
t0 = touch;
|
|
376
|
-
}
|
|
377
|
-
else if (touch.identifier==l1.identifier) {
|
|
378
|
-
t1 = touch;
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
const dist0 = Vec.Magnitude(Vec.Sub(new Vec(l0.x,l0.y), new Vec(l1.x,l1.y)));
|
|
382
|
-
const dist1 = Vec.Magnitude(Vec.Sub(new Vec(t0.x,t0.y), new Vec(t1.x,t1.y)));
|
|
383
|
-
const delta = new Vec(l0.y - t0.y, l1.x - t1.x);
|
|
384
|
-
const up = this.transform.matrix.upVector;
|
|
385
|
-
const left = this.transform.matrix.leftVector;
|
|
386
|
-
|
|
387
|
-
up.scale(delta.x * -0.001 * this._distance);
|
|
388
|
-
left.scale(delta.y * -0.001 * this._distance);
|
|
389
|
-
this._center = Vec.Add(this._center, Vec.Add(up, left));
|
|
390
|
-
|
|
391
|
-
this._distance += (dist0 - dist1) * 0.005 * this._distance;
|
|
392
|
-
}
|
|
393
|
-
evt.stopPropagation();
|
|
394
|
-
}
|
|
395
|
-
this._lastTouch = evt.touches;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
keyDown(evt) {
|
|
399
|
-
if (!this.enabled) return;
|
|
400
|
-
this._keys[evt.key] = true;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
keyUp(evt) {
|
|
404
|
-
if (!this.enabled) return;
|
|
405
|
-
this._keys[evt.key] = false;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import Component from './Component';
|
|
2
|
-
import OrbitCameraController, { Action, getOrbitAction } from './OrbitCameraController';
|
|
3
|
-
import MouseEvent, {
|
|
4
|
-
leftMouseButton,
|
|
5
|
-
middleMouseButton,
|
|
6
|
-
rightMouseButton
|
|
7
|
-
} from '../app/MouseEvent';
|
|
8
|
-
import { SpecialKey } from '../app/KeyboardEvent';
|
|
9
|
-
import { degreesToRadians, lerp, clamp } from '../math/functions';
|
|
10
|
-
import Vec from '../math/Vec';
|
|
11
|
-
import { OrthographicProjectionStrategy } from './Camera';
|
|
12
|
-
import Mat4 from '../math/Mat4';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default class SmoothOrbitCameraController extends OrbitCameraController {
|
|
16
|
-
constructor() {
|
|
17
|
-
super("SmoothOrbitCameraController");
|
|
18
|
-
this._smoothFactor = 0.009;
|
|
19
|
-
this._action = Action.NONE;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
clone() {
|
|
23
|
-
const result = new SmoothOrbitCameraController();
|
|
24
|
-
result.asign(this);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
assign(other) {
|
|
29
|
-
super.assign(other);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
willUpdate(delta) {
|
|
33
|
-
if (this.transform && this.enabled) {
|
|
34
|
-
let orthoStrategy = this.camera && this.camera.projectionStrategy instanceof OrthographicProjectionStrategy ?
|
|
35
|
-
this.camera.projectionStrategy : null;
|
|
36
|
-
|
|
37
|
-
if (this._mouseButtonPressed) {
|
|
38
|
-
let displacement = new Vec([0,0,0]);
|
|
39
|
-
if (this._keys[SpecialKey.UP_ARROW]) {
|
|
40
|
-
displacement = Vec.Add(displacement, this.transform.matrix.backwardVector);
|
|
41
|
-
}
|
|
42
|
-
if (this._keys[SpecialKey.DOWN_ARROW]) {
|
|
43
|
-
displacement = Vec.Add(displacement, this.transform.matrix.forwardVector);
|
|
44
|
-
}
|
|
45
|
-
if (this._keys[SpecialKey.LEFT_ARROW]) {
|
|
46
|
-
displacement = Vec.Add(displacement, this.transform.matrix.leftVector);
|
|
47
|
-
}
|
|
48
|
-
if (this._keys[SpecialKey.RIGHT_ARROW]) {
|
|
49
|
-
displacement = Vec.Add(displacement, this.transform.matrix.rightVector);
|
|
50
|
-
}
|
|
51
|
-
displacement.scale(this._displacementSpeed);
|
|
52
|
-
this._center = Vec.Add(this._center, displacement);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this._center0 = this._center0 ?? Mat4.GetPosition(this.transform.matrix);
|
|
56
|
-
this._distance0 = this._distance0 ?? Vec.Distance(this._center0, this._center);
|
|
57
|
-
this._center0 = Vec.Lerp(this._center0, this._center, delta * this._smoothFactor);
|
|
58
|
-
this._distance0 = lerp(this._distance0, this._distance, delta * this._smoothFactor * 2);
|
|
59
|
-
this._pitch0 = this._pitch0 ?? this._rotation.x;
|
|
60
|
-
this._yaw0 = this._yaw0 ?? this._rotation.y;
|
|
61
|
-
|
|
62
|
-
this._pitch0 = lerp(this._pitch0, this._rotation.x, delta * this._smoothFactor);
|
|
63
|
-
this._yaw0 = lerp(this._yaw0, this._rotation.y, delta * this._smoothFactor);
|
|
64
|
-
|
|
65
|
-
// Clamp values
|
|
66
|
-
this._distance = clamp(this._distance, this.minDistance, this.maxDistance);
|
|
67
|
-
this._distance0 = clamp(this._distance0, this.minDistance, this.maxDistance);
|
|
68
|
-
this._pitch0 = clamp(this._pitch0, this.minPitch, this.maxPitch);
|
|
69
|
-
this._rotation.x = clamp(this._rotation.x, this.minPitch, this.maxPitch);
|
|
70
|
-
const minDisp = new Vec(this.minX, this.minY, this.minZ);
|
|
71
|
-
const maxDisp = new Vec(this.maxX, this.maxY, this.maxZ);
|
|
72
|
-
this._center0 = Vec.Clamp(this._center0, minDisp, maxDisp);
|
|
73
|
-
this._center = Vec.Clamp(this._center, minDisp, maxDisp);
|
|
74
|
-
|
|
75
|
-
this.transform.matrix.identity();
|
|
76
|
-
if (orthoStrategy) {
|
|
77
|
-
orthoStrategy.viewWidth = this._viewWidth;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.transform.matrix.translate(0, 0, this._distance0);
|
|
81
|
-
if (this.camera) {
|
|
82
|
-
// Update the camera focus distance to optimize the shadow map rendering
|
|
83
|
-
this.camera.focusDistance = this._distance0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
this.transform.matrix.rotate(degreesToRadians(-this._pitch0), 1, 0, 0)
|
|
87
|
-
.rotate(degreesToRadians(this._yaw0), 0, 1, 0)
|
|
88
|
-
.translate(this._center0);
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
package/scene/Transform.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Component from './Component';
|
|
2
|
-
import Mat4 from "../math/Mat4";
|
|
3
|
-
import NodeVisitor from './NodeVisitor';
|
|
4
|
-
|
|
5
|
-
export class TransformVisitor extends NodeVisitor {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
this._matrix = Mat4.MakeIdentity();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get matrix() {
|
|
12
|
-
return this._matrix;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
visit(node) {
|
|
16
|
-
if (node.transform) {
|
|
17
|
-
this._matrix = Mat4.Mult(this._matrix, node.transform.matrix);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default class Transform extends Component {
|
|
23
|
-
static GetWorldMatrix(node) {
|
|
24
|
-
if (!node instanceof Node && !node instanceof Component) {
|
|
25
|
-
throw new Error("Invalid parameter in Transform.GetWorldMatrix() function. The parameter is not an instance of Node or Component");
|
|
26
|
-
}
|
|
27
|
-
else if (node instanceof Component) {
|
|
28
|
-
node = node.node;
|
|
29
|
-
}
|
|
30
|
-
const visitor = new TransformVisitor();
|
|
31
|
-
node.acceptReverse(visitor);
|
|
32
|
-
return visitor.matrix;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constructor(mat = Mat4.MakeIdentity()) {
|
|
36
|
-
super("Transform");
|
|
37
|
-
if (!mat instanceof Mat4) {
|
|
38
|
-
throw new Error("Invalid parameter in Transform component initialization. The parameter must be a Mat4 instance.");
|
|
39
|
-
}
|
|
40
|
-
this._matrix = mat;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get matrix() { return this._matrix; }
|
|
44
|
-
set matrix(m) { this._matrix = m; }
|
|
45
|
-
|
|
46
|
-
clone() {
|
|
47
|
-
const result = new Transform();
|
|
48
|
-
result.assign(this);
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
assign(other) {
|
|
53
|
-
this._matrix = new Mat4(other.matrix);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async deserialize(sceneData,loader) {
|
|
57
|
-
if (Array.isArray(sceneData.transformMatrix) && sceneData.transformMatrix.length === 16) {
|
|
58
|
-
this._matrix.assign(sceneData.transformMatrix);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.warn("Transform.deserialize(): invalid transformMatrix attribute found in scene data");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async serialize(sceneData,writer) {
|
|
66
|
-
await super.serialize(sceneData,writer);
|
|
67
|
-
throw new Error("Transform.serialice() not implemented");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
update(delta,modelMatrix) {
|
|
71
|
-
//modelMatrix.mult(this._matrix);
|
|
72
|
-
modelMatrix.assign(Mat4.Mult(modelMatrix, this._matrix));
|
|
73
|
-
}
|
|
74
|
-
}
|
package/scene/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import Drawable from "./Drawable";
|
|
4
|
-
import Transform from "./Transform";
|
|
5
|
-
import Chain from "./Chain";
|
|
6
|
-
import { InputChainJoint, OutputChainJoint } from "./ChainJoint";
|
|
7
|
-
import Light from "./LightComponent";
|
|
8
|
-
import Camera from "./Camera";
|
|
9
|
-
import OrbitCameraController from "./OrbitCameraController";
|
|
10
|
-
import EnvironmentComponent from "./EnvironmentComponent";
|
|
11
|
-
import { registerComponent } from "./Component";
|
|
12
|
-
|
|
13
|
-
export const registerComponents = () => {
|
|
14
|
-
registerComponent("Drawable", Drawable);
|
|
15
|
-
registerComponent("Transform", Transform);
|
|
16
|
-
registerComponent("Light", Light);
|
|
17
|
-
registerComponent("Chain", Chain);
|
|
18
|
-
registerComponent("InputChainJoint", InputChainJoint);
|
|
19
|
-
registerComponent("OutputChainJoint", OutputChainJoint);
|
|
20
|
-
registerComponent("Camera", Camera);
|
|
21
|
-
registerComponent("OrbitCameraController", OrbitCameraController);
|
|
22
|
-
registerComponent("Environment", EnvironmentComponent);
|
|
23
|
-
// TODO: Register more components
|
|
24
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import Shader from "../render/Shader";
|
|
2
|
-
import ShaderProgram from "../render/webgl/ShaderProgram";
|
|
3
|
-
import Texture, { ProceduralTextureFunction, TextureTargetName } from "../base/Texture";
|
|
4
|
-
import Vec from "../math/Vec";
|
|
5
|
-
|
|
6
|
-
const g_code = {
|
|
7
|
-
webgl: {
|
|
8
|
-
vertex: `precision mediump float;
|
|
9
|
-
|
|
10
|
-
attribute vec3 vertPosition;
|
|
11
|
-
attribute vec2 t0Position;
|
|
12
|
-
|
|
13
|
-
varying vec2 fragT0Pos;
|
|
14
|
-
|
|
15
|
-
uniform mat4 mWorld;
|
|
16
|
-
uniform mat4 mView;
|
|
17
|
-
uniform mat4 mProj;
|
|
18
|
-
|
|
19
|
-
void main() {
|
|
20
|
-
fragT0Pos = t0Position;
|
|
21
|
-
gl_Position = mProj * mView * mWorld * vec4(vertPosition, 1.0);
|
|
22
|
-
}`,
|
|
23
|
-
|
|
24
|
-
fragment: `
|
|
25
|
-
precision mediump float;
|
|
26
|
-
|
|
27
|
-
varying vec2 fragT0Pos;
|
|
28
|
-
|
|
29
|
-
uniform vec3 uFixedColor;
|
|
30
|
-
uniform sampler2D uTexture;
|
|
31
|
-
|
|
32
|
-
void main() {
|
|
33
|
-
vec4 texColor = texture2D(uTexture, fragT0Pos);
|
|
34
|
-
gl_FragColor = vec4(texColor.rgb * uFixedColor, 1.0);
|
|
35
|
-
}`
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default class BasicDiffuseColorShader extends Shader {
|
|
40
|
-
constructor(renderer) {
|
|
41
|
-
super(renderer);
|
|
42
|
-
|
|
43
|
-
if (renderer.typeId !== "WebGL") {
|
|
44
|
-
throw Error("PresentTextureShader is only compatible with WebGL renderer");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async load() {
|
|
49
|
-
const { gl } = this.renderer;
|
|
50
|
-
this._program = new ShaderProgram(gl, "BasicDiffuseColorShader");
|
|
51
|
-
this._program.attachVertexSource(g_code.webgl.vertex);
|
|
52
|
-
this._program.attachFragmentSource(g_code.webgl.fragment);
|
|
53
|
-
this._program.link();
|
|
54
|
-
|
|
55
|
-
this._whiteTexture = new Texture();
|
|
56
|
-
this._whiteTexture.proceduralFunction = ProceduralTextureFunction.PLAIN_COLOR;
|
|
57
|
-
this._whiteTexture.proceduralParameters = [1,1,1,1];
|
|
58
|
-
this._whiteTexture.size = new Vec(4,4);
|
|
59
|
-
await this._whiteTexture.loadImageData();
|
|
60
|
-
this._whiteTextureRenderer = this.renderer.factory.texture(this._whiteTexture);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
|
|
64
|
-
const { material } = materialRenderer;
|
|
65
|
-
const { gl } = this.renderer;
|
|
66
|
-
this.renderer.state.shaderProgram = this._program;
|
|
67
|
-
|
|
68
|
-
this._program.uniformMatrix4fv('mWorld', false, modelMatrix);
|
|
69
|
-
this._program.uniformMatrix4fv('mView', false, viewMatrix);
|
|
70
|
-
this._program.uniformMatrix4fv('mProj', false, projectionMatrix);
|
|
71
|
-
|
|
72
|
-
this._program.uniform1i('uTexture', 0);
|
|
73
|
-
let texRenderer = this._whiteTextureRenderer;
|
|
74
|
-
if (material.diffuse instanceof Vec) {
|
|
75
|
-
this._program.uniform3fv('uFixedColor', material.diffuse.rgb);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
texRenderer = materialRenderer.getTextureRenderer('diffuse');
|
|
79
|
-
this._program.uniform3fv('uFixedColor', new Vec(1,1,1));
|
|
80
|
-
}
|
|
81
|
-
texRenderer.activeTexture(0);
|
|
82
|
-
texRenderer.bindTexture();
|
|
83
|
-
|
|
84
|
-
this._program.positionAttribPointer(plistRenderer.positionAttribParams("vertPosition"));
|
|
85
|
-
this._program.texCoordAttribPointer(plistRenderer.texCoord0AttribParams("t0Position"));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
destroy() {
|
|
89
|
-
ShaderProgram.Delete(this._program);
|
|
90
|
-
}
|
|
91
|
-
}
|