@xtctwins/tctwins-core 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tctwins-core.es.js
CHANGED
|
@@ -42162,149 +42162,155 @@ math.vec3();
|
|
|
42162
42162
|
* ````
|
|
42163
42163
|
*/
|
|
42164
42164
|
class SectionPlane extends Component {
|
|
42165
|
-
|
|
42166
|
-
/**
|
|
42165
|
+
/**
|
|
42167
42166
|
@private
|
|
42168
42167
|
*/
|
|
42169
|
-
|
|
42170
|
-
|
|
42171
|
-
|
|
42168
|
+
get type() {
|
|
42169
|
+
return "SectionPlane";
|
|
42170
|
+
}
|
|
42172
42171
|
|
|
42173
|
-
|
|
42174
|
-
|
|
42175
|
-
|
|
42176
|
-
|
|
42177
|
-
|
|
42178
|
-
|
|
42179
|
-
|
|
42180
|
-
|
|
42181
|
-
|
|
42182
|
-
|
|
42172
|
+
/**
|
|
42173
|
+
* @constructor
|
|
42174
|
+
* @param {Component} [owner] Owner component. When destroyed, the owner will destroy this SectionPlane as well.
|
|
42175
|
+
* @param {*} [cfg] SectionPlane configuration
|
|
42176
|
+
* @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted.
|
|
42177
|
+
* @param {Boolean} [cfg.active=true] Indicates whether or not this SectionPlane is active.
|
|
42178
|
+
* @param {Number[]} [cfg.pos=[0,0,0]] World-space position of the SectionPlane.
|
|
42179
|
+
* @param {Number[]} [cfg.dir=[0,0,-1]] Vector perpendicular to the plane surface, indicating the SectionPlane plane orientation.
|
|
42180
|
+
*/
|
|
42181
|
+
constructor(owner, cfg = {}) {
|
|
42182
|
+
super(owner, cfg);
|
|
42183
42183
|
|
|
42184
|
-
|
|
42184
|
+
this._state = new RenderState({
|
|
42185
|
+
active: true,
|
|
42186
|
+
pos: math.vec3(),
|
|
42187
|
+
dir: math.vec3(),
|
|
42188
|
+
dist: 0
|
|
42189
|
+
});
|
|
42185
42190
|
|
|
42186
|
-
|
|
42187
|
-
|
|
42188
|
-
|
|
42189
|
-
dir: math.vec3(),
|
|
42190
|
-
dist: 0
|
|
42191
|
-
});
|
|
42191
|
+
this.active = cfg.active;
|
|
42192
|
+
this.pos = cfg.pos;
|
|
42193
|
+
this.dir = cfg.dir;
|
|
42192
42194
|
|
|
42193
|
-
|
|
42194
|
-
|
|
42195
|
-
this.dir = cfg.dir;
|
|
42195
|
+
this.scene._sectionPlaneCreated(this);
|
|
42196
|
+
}
|
|
42196
42197
|
|
|
42197
|
-
|
|
42198
|
-
|
|
42198
|
+
set control(control) {
|
|
42199
|
+
this._control = control;
|
|
42200
|
+
}
|
|
42199
42201
|
|
|
42200
|
-
|
|
42201
|
-
|
|
42202
|
-
|
|
42203
|
-
* Default value is ````true````.
|
|
42204
|
-
*
|
|
42205
|
-
* @param {Boolean} value Set ````true```` to activate else ````false```` to deactivate.
|
|
42206
|
-
*/
|
|
42207
|
-
set active(value) {
|
|
42208
|
-
this._state.active = value !== false;
|
|
42209
|
-
this.glRedraw();
|
|
42210
|
-
this.fire("active", this._state.active);
|
|
42211
|
-
}
|
|
42202
|
+
get control() {
|
|
42203
|
+
return this._control;
|
|
42204
|
+
}
|
|
42212
42205
|
|
|
42213
|
-
|
|
42214
|
-
|
|
42215
|
-
|
|
42216
|
-
|
|
42217
|
-
|
|
42218
|
-
|
|
42219
|
-
|
|
42220
|
-
|
|
42221
|
-
|
|
42222
|
-
|
|
42206
|
+
/**
|
|
42207
|
+
* Sets if this SectionPlane is active or not.
|
|
42208
|
+
*
|
|
42209
|
+
* Default value is ````true````.
|
|
42210
|
+
*
|
|
42211
|
+
* @param {Boolean} value Set ````true```` to activate else ````false```` to deactivate.
|
|
42212
|
+
*/
|
|
42213
|
+
set active(value) {
|
|
42214
|
+
this._state.active = value !== false;
|
|
42215
|
+
this.glRedraw();
|
|
42216
|
+
this.fire("active", this._state.active);
|
|
42217
|
+
}
|
|
42223
42218
|
|
|
42224
|
-
|
|
42225
|
-
|
|
42226
|
-
|
|
42227
|
-
|
|
42228
|
-
|
|
42229
|
-
|
|
42230
|
-
|
|
42231
|
-
|
|
42232
|
-
|
|
42233
|
-
|
|
42234
|
-
this.fire("pos", this._state.pos);
|
|
42235
|
-
this.scene.fire("sectionPlaneUpdated", this);
|
|
42236
|
-
}
|
|
42219
|
+
/**
|
|
42220
|
+
* Gets if this SectionPlane is active or not.
|
|
42221
|
+
*
|
|
42222
|
+
* Default value is ````true````.
|
|
42223
|
+
*
|
|
42224
|
+
* @returns {Boolean} Returns ````true```` if active.
|
|
42225
|
+
*/
|
|
42226
|
+
get active() {
|
|
42227
|
+
return this._state.active;
|
|
42228
|
+
}
|
|
42237
42229
|
|
|
42238
|
-
|
|
42239
|
-
|
|
42240
|
-
|
|
42241
|
-
|
|
42242
|
-
|
|
42243
|
-
|
|
42244
|
-
|
|
42245
|
-
|
|
42246
|
-
|
|
42247
|
-
|
|
42230
|
+
/**
|
|
42231
|
+
* Sets the World-space position of this SectionPlane's plane.
|
|
42232
|
+
*
|
|
42233
|
+
* Default value is ````[0, 0, 0]````.
|
|
42234
|
+
*
|
|
42235
|
+
* @param {Number[]} value New position.
|
|
42236
|
+
*/
|
|
42237
|
+
set pos(value) {
|
|
42238
|
+
this._state.pos.set(value || [0, 0, 0]);
|
|
42239
|
+
this._state.dist = -math.dotVec3(this._state.pos, this._state.dir);
|
|
42240
|
+
this.fire("pos", this._state.pos);
|
|
42241
|
+
this.scene.fire("sectionPlaneUpdated", this);
|
|
42242
|
+
}
|
|
42248
42243
|
|
|
42249
|
-
|
|
42250
|
-
|
|
42251
|
-
|
|
42252
|
-
|
|
42253
|
-
|
|
42254
|
-
|
|
42255
|
-
|
|
42256
|
-
|
|
42257
|
-
|
|
42258
|
-
|
|
42259
|
-
this.glRedraw();
|
|
42260
|
-
this.fire("dir", this._state.dir);
|
|
42261
|
-
this.scene.fire("sectionPlaneUpdated", this);
|
|
42262
|
-
}
|
|
42244
|
+
/**
|
|
42245
|
+
* Gets the World-space position of this SectionPlane's plane.
|
|
42246
|
+
*
|
|
42247
|
+
* Default value is ````[0, 0, 0]````.
|
|
42248
|
+
*
|
|
42249
|
+
* @returns {Number[]} Current position.
|
|
42250
|
+
*/
|
|
42251
|
+
get pos() {
|
|
42252
|
+
return this._state.pos;
|
|
42253
|
+
}
|
|
42263
42254
|
|
|
42264
|
-
|
|
42265
|
-
|
|
42266
|
-
|
|
42267
|
-
|
|
42268
|
-
|
|
42269
|
-
|
|
42270
|
-
|
|
42271
|
-
|
|
42272
|
-
|
|
42273
|
-
|
|
42255
|
+
/**
|
|
42256
|
+
* Sets the direction of this SectionPlane's plane.
|
|
42257
|
+
*
|
|
42258
|
+
* Default value is ````[0, 0, -1]````.
|
|
42259
|
+
*
|
|
42260
|
+
* @param {Number[]} value New direction.
|
|
42261
|
+
*/
|
|
42262
|
+
set dir(value) {
|
|
42263
|
+
this._state.dir.set(value || [0, 0, -1]);
|
|
42264
|
+
this._state.dist = -math.dotVec3(this._state.pos, this._state.dir);
|
|
42265
|
+
this.glRedraw();
|
|
42266
|
+
this.fire("dir", this._state.dir);
|
|
42267
|
+
this.scene.fire("sectionPlaneUpdated", this);
|
|
42268
|
+
}
|
|
42274
42269
|
|
|
42275
|
-
|
|
42276
|
-
|
|
42277
|
-
|
|
42278
|
-
|
|
42279
|
-
|
|
42280
|
-
|
|
42281
|
-
|
|
42282
|
-
|
|
42283
|
-
|
|
42284
|
-
|
|
42285
|
-
}
|
|
42270
|
+
/**
|
|
42271
|
+
* Gets the direction of this SectionPlane's plane.
|
|
42272
|
+
*
|
|
42273
|
+
* Default value is ````[0, 0, -1]````.
|
|
42274
|
+
*
|
|
42275
|
+
* @returns {Number[]} value Current direction.
|
|
42276
|
+
*/
|
|
42277
|
+
get dir() {
|
|
42278
|
+
return this._state.dir;
|
|
42279
|
+
}
|
|
42286
42280
|
|
|
42287
|
-
|
|
42288
|
-
|
|
42289
|
-
|
|
42290
|
-
|
|
42291
|
-
|
|
42292
|
-
|
|
42293
|
-
|
|
42294
|
-
|
|
42295
|
-
|
|
42296
|
-
|
|
42297
|
-
|
|
42298
|
-
}
|
|
42281
|
+
/**
|
|
42282
|
+
* Gets this SectionPlane's distance to the origin of the World-space coordinate system.
|
|
42283
|
+
*
|
|
42284
|
+
* This is the dot product of {@link SectionPlane#pos} and {@link SectionPlane#dir} and is automatically re-calculated
|
|
42285
|
+
* each time either of two properties are updated.
|
|
42286
|
+
*
|
|
42287
|
+
* @returns {Number}
|
|
42288
|
+
*/
|
|
42289
|
+
get dist() {
|
|
42290
|
+
return this._state.dist;
|
|
42291
|
+
}
|
|
42299
42292
|
|
|
42300
|
-
|
|
42301
|
-
|
|
42302
|
-
|
|
42303
|
-
|
|
42304
|
-
|
|
42305
|
-
|
|
42306
|
-
|
|
42307
|
-
|
|
42293
|
+
/**
|
|
42294
|
+
* Inverts the direction of {@link SectionPlane#dir}.
|
|
42295
|
+
*/
|
|
42296
|
+
flipDir() {
|
|
42297
|
+
const dir = this._state.dir;
|
|
42298
|
+
dir[0] *= -1.0;
|
|
42299
|
+
dir[1] *= -1.0;
|
|
42300
|
+
dir[2] *= -1.0;
|
|
42301
|
+
this._state.dist = -math.dotVec3(this._state.pos, this._state.dir);
|
|
42302
|
+
this.fire("dir", this._state.dir);
|
|
42303
|
+
this.glRedraw();
|
|
42304
|
+
}
|
|
42305
|
+
|
|
42306
|
+
/**
|
|
42307
|
+
* @destroy
|
|
42308
|
+
*/
|
|
42309
|
+
destroy() {
|
|
42310
|
+
this._state.destroy();
|
|
42311
|
+
this.scene._sectionPlaneDestroyed(this);
|
|
42312
|
+
super.destroy();
|
|
42313
|
+
}
|
|
42308
42314
|
}
|
|
42309
42315
|
|
|
42310
42316
|
const angleAxis$1 = math.vec4(4);
|
|
@@ -91343,7 +91349,7 @@ CameraPathAnimation.PLAYING_TO = 3;
|
|
|
91343
91349
|
const tempVec3$3 = math.vec3();
|
|
91344
91350
|
const tempVec3b$5 = math.vec3();
|
|
91345
91351
|
math.vec3();
|
|
91346
|
-
const zeroVec$
|
|
91352
|
+
const zeroVec$4 = math.vec3([0, -1, 0]);
|
|
91347
91353
|
const tempQuat = math.vec4([0, 0, 0, 1]);
|
|
91348
91354
|
|
|
91349
91355
|
/**
|
|
@@ -91770,7 +91776,7 @@ class ImagePlane extends Component {
|
|
|
91770
91776
|
|
|
91771
91777
|
math.normalizeVec3(negDir);
|
|
91772
91778
|
math.mulVec3Scalar(negDir, dist, tempVec3b$5);
|
|
91773
|
-
math.vec3PairToQuaternion(zeroVec$
|
|
91779
|
+
math.vec3PairToQuaternion(zeroVec$4, dir, tempQuat);
|
|
91774
91780
|
|
|
91775
91781
|
this._node.quaternion = tempQuat;
|
|
91776
91782
|
}
|
|
@@ -118022,7 +118028,6 @@ class NavCubePlugin extends Plugin {
|
|
|
118022
118028
|
if (hit) {
|
|
118023
118029
|
if (hit.uv) {
|
|
118024
118030
|
var areaId = self._cubeTextureCanvas.getArea(hit.uv);
|
|
118025
|
-
console.log(areaId);
|
|
118026
118031
|
if (areaId >= 0) {
|
|
118027
118032
|
document.body.style.cursor = "pointer";
|
|
118028
118033
|
if (lastAreaId >= 0) {
|
|
@@ -118044,8 +118049,6 @@ class NavCubePlugin extends Plugin {
|
|
|
118044
118049
|
dir = rotateTrueNorth(+1, dir, tempVec3a$4);
|
|
118045
118050
|
up = rotateTrueNorth(+1, up, tempVec3b$1);
|
|
118046
118051
|
}
|
|
118047
|
-
console.log(dir);
|
|
118048
|
-
console.log(up);
|
|
118049
118052
|
flyTo(dir, up, function () {
|
|
118050
118053
|
if (lastAreaId >= 0) {
|
|
118051
118054
|
self._cubeTextureCanvas.setAreaHighlighted(lastAreaId, false);
|
|
@@ -119332,8 +119335,8 @@ class OBJLoaderPlugin extends Plugin {
|
|
|
119332
119335
|
}
|
|
119333
119336
|
}
|
|
119334
119337
|
|
|
119335
|
-
const zeroVec$
|
|
119336
|
-
const quat$
|
|
119338
|
+
const zeroVec$3 = new Float64Array([0, 0, 1]);
|
|
119339
|
+
const quat$3 = new Float64Array(4);
|
|
119337
119340
|
|
|
119338
119341
|
/**
|
|
119339
119342
|
* Controls a {@link SectionPlane} with mouse and touch input.
|
|
@@ -119352,8 +119355,10 @@ class Control {
|
|
|
119352
119355
|
* @type {String|Number}
|
|
119353
119356
|
*/
|
|
119354
119357
|
this.id = null;
|
|
119358
|
+
this.type = "control";
|
|
119355
119359
|
|
|
119356
119360
|
this._viewer = plugin.viewer;
|
|
119361
|
+
this._scene = plugin.viewer.scene;
|
|
119357
119362
|
|
|
119358
119363
|
this._visible = false;
|
|
119359
119364
|
this._pos = math.vec3(); // Full-precision position of the center of the Control
|
|
@@ -119411,6 +119416,44 @@ class Control {
|
|
|
119411
119416
|
return this._sectionPlane;
|
|
119412
119417
|
}
|
|
119413
119418
|
|
|
119419
|
+
/**
|
|
119420
|
+
* 设置剖切面位置
|
|
119421
|
+
* @param {any} value
|
|
119422
|
+
*/
|
|
119423
|
+
set pos(posRate) {
|
|
119424
|
+
if (posRate < 0 || posRate > 100) return;
|
|
119425
|
+
|
|
119426
|
+
const { aabb } = this._scene;
|
|
119427
|
+
const { look } = this._scene.camera;
|
|
119428
|
+
const xRange = aabb[3] - aabb[0]; //前后
|
|
119429
|
+
const yRange = aabb[4] - aabb[1]; //上下
|
|
119430
|
+
const zRange = aabb[5] - aabb[2]; //左右
|
|
119431
|
+
|
|
119432
|
+
const newSectionPos = math.vec3();
|
|
119433
|
+
newSectionPos[0] = this.pos[0];
|
|
119434
|
+
newSectionPos[1] = this.pos[1];
|
|
119435
|
+
newSectionPos[2] = this.pos[2];
|
|
119436
|
+
|
|
119437
|
+
const { dir } = this._sectionPlane;
|
|
119438
|
+
let rateDis;
|
|
119439
|
+
if (dir[0] != 0) {
|
|
119440
|
+
rateDis = (posRate / 100) * xRange;
|
|
119441
|
+
newSectionPos[0] = look[0] - xRange / 2 + rateDis;
|
|
119442
|
+
} else if (dir[1] != 0) {
|
|
119443
|
+
rateDis = (posRate / 100) * yRange;
|
|
119444
|
+
newSectionPos[1] = look[1] - yRange / 2 + rateDis;
|
|
119445
|
+
} else if (dir[2] != 0) {
|
|
119446
|
+
rateDis = (posRate / 100) * zRange;
|
|
119447
|
+
newSectionPos[2] = look[2] - zRange / 2 + rateDis;
|
|
119448
|
+
}
|
|
119449
|
+
|
|
119450
|
+
this._sectionPlane.pos = newSectionPos;
|
|
119451
|
+
}
|
|
119452
|
+
|
|
119453
|
+
get pos() {
|
|
119454
|
+
return this._pos;
|
|
119455
|
+
}
|
|
119456
|
+
|
|
119414
119457
|
/** @private */
|
|
119415
119458
|
_setPos(xyz) {
|
|
119416
119459
|
this._pos.set(xyz);
|
|
@@ -119424,7 +119467,7 @@ class Control {
|
|
|
119424
119467
|
/** @private */
|
|
119425
119468
|
_setDir(xyz) {
|
|
119426
119469
|
this._baseDir.set(xyz);
|
|
119427
|
-
this._rootNode.quaternion = math.vec3PairToQuaternion(zeroVec$
|
|
119470
|
+
this._rootNode.quaternion = math.vec3PairToQuaternion(zeroVec$3, xyz, quat$3);
|
|
119428
119471
|
}
|
|
119429
119472
|
|
|
119430
119473
|
_setSectionPlaneDir(dir) {
|
|
@@ -120819,7 +120862,6 @@ class Control {
|
|
|
120819
120862
|
);
|
|
120820
120863
|
|
|
120821
120864
|
this._onCameraControlHover = this._viewer.cameraControl.on("touchEntity", (hit) => {
|
|
120822
|
-
console.log("111");
|
|
120823
120865
|
if (!this._visible || down || grabbed) return;
|
|
120824
120866
|
grabbed = false;
|
|
120825
120867
|
if (lastAffordanceMesh) {
|
|
@@ -120887,7 +120929,6 @@ class Control {
|
|
|
120887
120929
|
canvas.addEventListener(
|
|
120888
120930
|
"touchstart",
|
|
120889
120931
|
(this._canvasMouseDownListener = (e) => {
|
|
120890
|
-
console.log("222");
|
|
120891
120932
|
e.preventDefault();
|
|
120892
120933
|
if (!this._visible || !grabbed) return;
|
|
120893
120934
|
|
|
@@ -120938,7 +120979,7 @@ class Control {
|
|
|
120938
120979
|
canvas.addEventListener(
|
|
120939
120980
|
"touchend",
|
|
120940
120981
|
(this._canvasTouchEndListener = (e) => {
|
|
120941
|
-
|
|
120982
|
+
if (!this._visible) return;
|
|
120942
120983
|
this._viewer.cameraControl.pointerEnabled = true;
|
|
120943
120984
|
if (lastAffordanceMesh) {
|
|
120944
120985
|
lastAffordanceMesh.visible = false;
|
|
@@ -120989,221 +121030,1841 @@ class Control {
|
|
|
120989
121030
|
}
|
|
120990
121031
|
}
|
|
120991
121032
|
|
|
121033
|
+
const zeroVec$2 = new Float64Array([0, 0, 1]);
|
|
121034
|
+
const quat$2 = new Float64Array(4);
|
|
121035
|
+
|
|
120992
121036
|
/**
|
|
120993
|
-
*
|
|
121037
|
+
* Controls a {@link SectionPlane} with mouse and touch input.
|
|
120994
121038
|
*
|
|
120995
121039
|
* @private
|
|
120996
121040
|
*/
|
|
120997
|
-
class
|
|
120998
|
-
|
|
120999
|
-
|
|
121000
|
-
|
|
121041
|
+
class ClippingBox {
|
|
121042
|
+
/** @private */
|
|
121043
|
+
constructor(plugin, cfg) {
|
|
121044
|
+
/**
|
|
121045
|
+
* ID of this Control.
|
|
121046
|
+
*
|
|
121047
|
+
* SectionPlaneControls are mapped by this ID in {@link SectionPlanesPlugin#sectionPlaneControls}.
|
|
121048
|
+
*
|
|
121049
|
+
* @property id
|
|
121050
|
+
* @type {String|Number}
|
|
121051
|
+
*/
|
|
121052
|
+
this.id = null;
|
|
121053
|
+
this.type = "box";
|
|
121001
121054
|
|
|
121002
|
-
|
|
121003
|
-
|
|
121004
|
-
*
|
|
121005
|
-
* @type {String}
|
|
121006
|
-
*/
|
|
121007
|
-
this.id = sectionPlane.id;
|
|
121055
|
+
this._viewer = plugin.viewer;
|
|
121056
|
+
this._scene = plugin.viewer.scene;
|
|
121008
121057
|
|
|
121009
|
-
|
|
121010
|
-
|
|
121011
|
-
|
|
121012
|
-
|
|
121013
|
-
*/
|
|
121014
|
-
this._sectionPlane = sectionPlane;
|
|
121058
|
+
this._controlFillColor = !!cfg && !!cfg.controlFillColor ? cfg.controlFillColor : [0.1, 0.4, 0.99];
|
|
121059
|
+
this._planeSize = !!cfg && !!cfg.planeSize ? cfg.planeSize : 1;
|
|
121060
|
+
this._controlSize = !!cfg && !!cfg.controlSize ? cfg.controlSize : 0.07;
|
|
121061
|
+
this._planeOpacity = !!cfg && !!cfg.planeOpacity ? cfg.planeOpacity : 0.4;
|
|
121015
121062
|
|
|
121016
|
-
|
|
121017
|
-
|
|
121018
|
-
|
|
121019
|
-
|
|
121020
|
-
ySize: .5,
|
|
121021
|
-
zSize: .001
|
|
121022
|
-
})),
|
|
121023
|
-
material: new PhongMaterial(overviewScene, {
|
|
121024
|
-
emissive: [1, 1, 1],
|
|
121025
|
-
diffuse: [0, 0, 0],
|
|
121026
|
-
backfaces: false
|
|
121027
|
-
}),
|
|
121028
|
-
edgeMaterial: new EdgeMaterial(overviewScene, {
|
|
121029
|
-
edgeColor: [0.0, 0.0, 0.0],
|
|
121030
|
-
edgeAlpha: 1.0,
|
|
121031
|
-
edgeWidth: 1
|
|
121032
|
-
}),
|
|
121033
|
-
highlightMaterial: new EmphasisMaterial(overviewScene, {
|
|
121034
|
-
fill: true,
|
|
121035
|
-
fillColor: [0.5, 1, 0.5],
|
|
121036
|
-
fillAlpha: 0.7,
|
|
121037
|
-
edges: true,
|
|
121038
|
-
edgeColor: [0.0, 0.0, 0.0],
|
|
121039
|
-
edgeAlpha: 1.0,
|
|
121040
|
-
edgeWidth: 1
|
|
121041
|
-
}),
|
|
121042
|
-
selectedMaterial: new EmphasisMaterial(overviewScene, {
|
|
121043
|
-
fill: true,
|
|
121044
|
-
fillColor: [0, 0, 1],
|
|
121045
|
-
fillAlpha: 0.7,
|
|
121046
|
-
edges: true,
|
|
121047
|
-
edgeColor: [1.0, 0.0, 0.0],
|
|
121048
|
-
edgeAlpha: 1.0,
|
|
121049
|
-
edgeWidth: 1
|
|
121050
|
-
}),
|
|
121051
|
-
highlighted: true,
|
|
121052
|
-
scale: [3, 3, 3],
|
|
121053
|
-
position: [0, 0, 0],
|
|
121054
|
-
rotation: [0, 0, 0],
|
|
121055
|
-
opacity: 0.3,
|
|
121056
|
-
edges: true
|
|
121057
|
-
});
|
|
121063
|
+
this._visible = false;
|
|
121064
|
+
this._pos = math.vec3(); // Full-precision position of the center of the Control
|
|
121065
|
+
this._origin = math.vec3();
|
|
121066
|
+
this._rtcPos = math.vec3();
|
|
121058
121067
|
|
|
121068
|
+
this._baseDir = math.vec3(); // Saves direction of clip plane when we start dragging an arrow or ring.
|
|
121069
|
+
this._rootNode = null; // Root of Node graph that represents this control in the 3D scene
|
|
121070
|
+
this._displayMeshes = null; // Meshes that are always visible
|
|
121071
|
+
this._affordanceMeshes = null; // Meshes displayed momentarily for affordance
|
|
121059
121072
|
|
|
121060
|
-
|
|
121061
|
-
const vec = math.vec3([0, 0, 0]);
|
|
121062
|
-
const pos2 = math.vec3();
|
|
121063
|
-
const zeroVec = math.vec3([0, 0, 1]);
|
|
121064
|
-
const quat = math.vec4(4);
|
|
121065
|
-
const pos3 = math.vec3();
|
|
121073
|
+
this._ignoreNextSectionPlaneDirUpdate = false;
|
|
121066
121074
|
|
|
121067
|
-
|
|
121075
|
+
this._createNodes();
|
|
121076
|
+
this._bindEvents();
|
|
121077
|
+
}
|
|
121068
121078
|
|
|
121069
|
-
|
|
121079
|
+
/**
|
|
121080
|
+
* Called by SectionPlanesPlugin to assign this Control to a SectionPlane.
|
|
121081
|
+
* SectionPlanesPlugin keeps SectionPlaneControls in a reuse pool.
|
|
121082
|
+
* Call with a null or undefined value to disconnect the Control ffrom whatever SectionPlane it was assigned to.
|
|
121083
|
+
* @private
|
|
121084
|
+
*/
|
|
121085
|
+
_setSectionPlane(sectionPlane) {
|
|
121086
|
+
if (this._sectionPlane) {
|
|
121087
|
+
this._sectionPlane.off(this._onSectionPlanePos);
|
|
121088
|
+
this._sectionPlane.off(this._onSectionPlaneDir);
|
|
121089
|
+
this._onSectionPlanePos = null;
|
|
121090
|
+
this._onSectionPlaneDir = null;
|
|
121091
|
+
this._sectionPlane = null;
|
|
121092
|
+
}
|
|
121093
|
+
if (sectionPlane) {
|
|
121094
|
+
this.id = sectionPlane.id;
|
|
121095
|
+
this._setPos(sectionPlane.pos);
|
|
121096
|
+
this._setDir(sectionPlane.dir);
|
|
121097
|
+
this._sectionPlane = sectionPlane;
|
|
121098
|
+
this._onSectionPlanePos = sectionPlane.on("pos", () => {
|
|
121099
|
+
this._setPos(this._sectionPlane.pos);
|
|
121100
|
+
});
|
|
121101
|
+
this._onSectionPlaneDir = sectionPlane.on("dir", () => {
|
|
121102
|
+
if (!this._ignoreNextSectionPlaneDirUpdate) {
|
|
121103
|
+
this._setDir(this._sectionPlane.dir);
|
|
121104
|
+
} else {
|
|
121105
|
+
this._ignoreNextSectionPlaneDirUpdate = false;
|
|
121106
|
+
}
|
|
121107
|
+
});
|
|
121108
|
+
}
|
|
121109
|
+
}
|
|
121070
121110
|
|
|
121071
|
-
|
|
121072
|
-
|
|
121073
|
-
|
|
121111
|
+
/**
|
|
121112
|
+
* Gets the {@link SectionPlane} controlled by this Control.
|
|
121113
|
+
* @returns {SectionPlane} The SectionPlane.
|
|
121114
|
+
*/
|
|
121115
|
+
get sectionPlane() {
|
|
121116
|
+
return this._sectionPlane;
|
|
121117
|
+
}
|
|
121074
121118
|
|
|
121075
|
-
|
|
121076
|
-
|
|
121077
|
-
|
|
121119
|
+
/**
|
|
121120
|
+
* 设置剖切面位置
|
|
121121
|
+
* @param {any} value
|
|
121122
|
+
*/
|
|
121123
|
+
set pos(posRate) {
|
|
121124
|
+
if (posRate < 0 || posRate > 100) return;
|
|
121125
|
+
|
|
121126
|
+
const { aabb } = this._scene;
|
|
121127
|
+
const { look } = this._scene.camera;
|
|
121128
|
+
const xRange = aabb[3] - aabb[0]; //前后
|
|
121129
|
+
const yRange = aabb[4] - aabb[1]; //上下
|
|
121130
|
+
const zRange = aabb[5] - aabb[2]; //左右
|
|
121131
|
+
|
|
121132
|
+
const newSectionPos = math.vec3();
|
|
121133
|
+
newSectionPos[0] = this.pos[0];
|
|
121134
|
+
newSectionPos[1] = this.pos[1];
|
|
121135
|
+
newSectionPos[2] = this.pos[2];
|
|
121136
|
+
|
|
121137
|
+
const { dir } = this._sectionPlane;
|
|
121138
|
+
let rateDis;
|
|
121139
|
+
if (dir[0] != 0) {
|
|
121140
|
+
rateDis = (posRate / 100) * xRange;
|
|
121141
|
+
newSectionPos[0] = look[0] - xRange / 2 + rateDis;
|
|
121142
|
+
} else if (dir[1] != 0) {
|
|
121143
|
+
rateDis = (posRate / 100) * yRange;
|
|
121144
|
+
newSectionPos[1] = look[1] - yRange / 2 + rateDis;
|
|
121145
|
+
} else if (dir[2] != 0) {
|
|
121146
|
+
rateDis = (posRate / 100) * zRange;
|
|
121147
|
+
newSectionPos[2] = look[2] - zRange / 2 + rateDis;
|
|
121148
|
+
}
|
|
121078
121149
|
|
|
121079
|
-
|
|
121080
|
-
|
|
121081
|
-
pos3[2] = pos2[2] * 0.1;
|
|
121150
|
+
this._sectionPlane.pos = newSectionPos;
|
|
121151
|
+
}
|
|
121082
121152
|
|
|
121083
|
-
|
|
121084
|
-
|
|
121085
|
-
|
|
121153
|
+
get pos() {
|
|
121154
|
+
return this._pos;
|
|
121155
|
+
}
|
|
121086
121156
|
|
|
121087
|
-
|
|
121088
|
-
|
|
121157
|
+
/** @private */
|
|
121158
|
+
_setPos(xyz) {
|
|
121159
|
+
this._pos.set(xyz);
|
|
121089
121160
|
|
|
121090
|
-
|
|
121091
|
-
}
|
|
121161
|
+
worldToRTCPos(this._pos, this._origin, this._rtcPos);
|
|
121092
121162
|
|
|
121093
|
-
|
|
121094
|
-
|
|
121095
|
-
|
|
121163
|
+
this._rootNode.origin = this._origin;
|
|
121164
|
+
this._rootNode.position = this._rtcPos;
|
|
121165
|
+
}
|
|
121096
121166
|
|
|
121097
|
-
|
|
121098
|
-
|
|
121099
|
-
|
|
121100
|
-
|
|
121101
|
-
|
|
121102
|
-
*/
|
|
121103
|
-
setHighlighted(highlighted) {
|
|
121104
|
-
this._highlighted = !!highlighted;
|
|
121105
|
-
this._mesh.highlighted = this._highlighted;
|
|
121106
|
-
this._mesh.highlightMaterial.fillColor = highlighted ? [0, 0.7, 0] : [0, 0, 0];
|
|
121107
|
-
// this._selectedMesh.highlighted = true;
|
|
121108
|
-
}
|
|
121167
|
+
/** @private */
|
|
121168
|
+
_setDir(xyz) {
|
|
121169
|
+
this._baseDir.set(xyz);
|
|
121170
|
+
this._rootNode.quaternion = math.vec3PairToQuaternion(zeroVec$2, xyz, quat$2);
|
|
121171
|
+
}
|
|
121109
121172
|
|
|
121110
|
-
|
|
121111
|
-
|
|
121112
|
-
|
|
121113
|
-
|
|
121114
|
-
|
|
121115
|
-
|
|
121116
|
-
getHighlighted() {
|
|
121117
|
-
return this._highlighted;
|
|
121118
|
-
}
|
|
121173
|
+
_setSectionPlaneDir(dir) {
|
|
121174
|
+
if (this._sectionPlane) {
|
|
121175
|
+
this._ignoreNextSectionPlaneDirUpdate = true;
|
|
121176
|
+
this._sectionPlane.dir = dir;
|
|
121177
|
+
}
|
|
121178
|
+
}
|
|
121119
121179
|
|
|
121120
|
-
|
|
121121
|
-
|
|
121122
|
-
|
|
121123
|
-
|
|
121124
|
-
|
|
121125
|
-
|
|
121126
|
-
|
|
121127
|
-
|
|
121128
|
-
|
|
121129
|
-
|
|
121180
|
+
/**
|
|
121181
|
+
* Sets if this Control is visible.
|
|
121182
|
+
*
|
|
121183
|
+
* @type {Boolean}
|
|
121184
|
+
*/
|
|
121185
|
+
setVisible(visible = true) {
|
|
121186
|
+
if (this._visible === visible) {
|
|
121187
|
+
return;
|
|
121188
|
+
}
|
|
121189
|
+
this._visible = visible;
|
|
121190
|
+
var id;
|
|
121191
|
+
for (id in this._displayMeshes) {
|
|
121192
|
+
if (this._displayMeshes.hasOwnProperty(id)) {
|
|
121193
|
+
this._displayMeshes[id].visible = visible;
|
|
121194
|
+
}
|
|
121195
|
+
}
|
|
121196
|
+
if (!visible) {
|
|
121197
|
+
for (id in this._affordanceMeshes) {
|
|
121198
|
+
if (this._affordanceMeshes.hasOwnProperty(id)) {
|
|
121199
|
+
this._affordanceMeshes[id].visible = visible;
|
|
121200
|
+
}
|
|
121201
|
+
}
|
|
121202
|
+
}
|
|
121203
|
+
}
|
|
121130
121204
|
|
|
121131
|
-
|
|
121205
|
+
/**
|
|
121206
|
+
* Gets if this Control is visible.
|
|
121207
|
+
*
|
|
121208
|
+
* @type {Boolean}
|
|
121209
|
+
*/
|
|
121210
|
+
getVisible() {
|
|
121211
|
+
return this._visible;
|
|
121212
|
+
}
|
|
121132
121213
|
|
|
121133
|
-
|
|
121134
|
-
|
|
121135
|
-
|
|
121136
|
-
|
|
121137
|
-
|
|
121138
|
-
|
|
121139
|
-
|
|
121140
|
-
|
|
121141
|
-
|
|
121214
|
+
/**
|
|
121215
|
+
* Sets if this Control is culled. This is called by SectionPlanesPlugin to
|
|
121216
|
+
* temporarily hide the Control while a snapshot is being taken by Viewer#getSnapshot().
|
|
121217
|
+
* @param culled
|
|
121218
|
+
*/
|
|
121219
|
+
setCulled(culled) {
|
|
121220
|
+
var id;
|
|
121221
|
+
for (id in this._displayMeshes) {
|
|
121222
|
+
if (this._displayMeshes.hasOwnProperty(id)) {
|
|
121223
|
+
this._displayMeshes[id].culled = culled;
|
|
121224
|
+
}
|
|
121225
|
+
}
|
|
121226
|
+
if (!culled) {
|
|
121227
|
+
for (id in this._affordanceMeshes) {
|
|
121228
|
+
if (this._affordanceMeshes.hasOwnProperty(id)) {
|
|
121229
|
+
this._affordanceMeshes[id].culled = culled;
|
|
121230
|
+
}
|
|
121231
|
+
}
|
|
121232
|
+
}
|
|
121233
|
+
}
|
|
121142
121234
|
|
|
121143
|
-
/** @private */
|
|
121144
|
-
destroy() {
|
|
121145
|
-
this._sectionPlane.off(this._onSectionPlanePos);
|
|
121146
|
-
this._sectionPlane.off(this._onSectionPlaneDir);
|
|
121147
|
-
this._mesh.destroy();
|
|
121148
|
-
}
|
|
121149
|
-
}
|
|
121150
|
-
|
|
121151
|
-
/**
|
|
121152
|
-
* @desc An interactive 3D overview for navigating the {@link SectionPlane}s created by its {@link SectionPlanesPlugin}.
|
|
121153
|
-
*
|
|
121154
|
-
* * Located at {@link SectionPlanesPlugin#overview}.
|
|
121155
|
-
* * Renders the overview on a separate canvas at a corner of the {@link Viewer}'s {@link Scene} {@link Canvas}.
|
|
121156
|
-
* * The overview shows a 3D plane object for each {@link SectionPlane} in the {@link Scene}.
|
|
121157
|
-
* * Click a plane object in the overview to toggle the visibility of a 3D gizmo to edit the position and orientation of its {@link SectionPlane}.
|
|
121158
|
-
*
|
|
121159
|
-
* @private
|
|
121160
|
-
*/
|
|
121161
|
-
class Overview$1 {
|
|
121162
121235
|
/**
|
|
121236
|
+
* Builds the Entities that represent this Control.
|
|
121163
121237
|
* @private
|
|
121164
121238
|
*/
|
|
121165
|
-
|
|
121166
|
-
|
|
121167
|
-
|
|
121168
|
-
}
|
|
121239
|
+
_createNodes() {
|
|
121240
|
+
const NO_STATE_INHERIT = false;
|
|
121241
|
+
const scene = this._viewer.scene;
|
|
121169
121242
|
|
|
121170
|
-
|
|
121171
|
-
|
|
121172
|
-
|
|
121173
|
-
|
|
121174
|
-
|
|
121175
|
-
this.plugin = plugin;
|
|
121243
|
+
this._rootNode = new Node$2(scene, {
|
|
121244
|
+
position: [0, 0, 0],
|
|
121245
|
+
scale: [5, 5, 5],
|
|
121246
|
+
isObject: false
|
|
121247
|
+
});
|
|
121176
121248
|
|
|
121177
|
-
|
|
121249
|
+
const rootNode = this._rootNode;
|
|
121178
121250
|
|
|
121179
|
-
|
|
121180
|
-
|
|
121181
|
-
|
|
121182
|
-
|
|
121183
|
-
|
|
121251
|
+
const newMesh = (color) => {
|
|
121252
|
+
return new Mesh(rootNode, {
|
|
121253
|
+
geometry: MeshConfigs.geometry,
|
|
121254
|
+
material: new PhongMaterial(rootNode, {
|
|
121255
|
+
emissive: [0, 0, 0],
|
|
121256
|
+
diffuse: color,
|
|
121257
|
+
backfaces: true
|
|
121258
|
+
}),
|
|
121259
|
+
opacity: this._planeOpacity,
|
|
121260
|
+
ghosted: true,
|
|
121261
|
+
ghostMaterial: new EmphasisMaterial(rootNode, {
|
|
121262
|
+
edges: false,
|
|
121263
|
+
filled: true,
|
|
121264
|
+
fillColor: color,
|
|
121265
|
+
fillAlpha: 0.1,
|
|
121266
|
+
backfaces: true
|
|
121267
|
+
}),
|
|
121268
|
+
pickable: true,
|
|
121269
|
+
collidable: true,
|
|
121270
|
+
clippable: false,
|
|
121271
|
+
visible: false,
|
|
121272
|
+
scale: [2.4, 2.4, 1],
|
|
121273
|
+
isObject: false
|
|
121274
|
+
});
|
|
121275
|
+
};
|
|
121184
121276
|
|
|
121185
|
-
this.
|
|
121277
|
+
this._displayMeshes = {
|
|
121278
|
+
front_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT),
|
|
121279
|
+
back_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT),
|
|
121280
|
+
right_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT),
|
|
121281
|
+
left_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT),
|
|
121282
|
+
top_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT),
|
|
121283
|
+
bottom_plane: rootNode.addChild(newMesh(this._controlFillColor), NO_STATE_INHERIT)
|
|
121284
|
+
};
|
|
121186
121285
|
|
|
121187
|
-
|
|
121188
|
-
|
|
121189
|
-
|
|
121286
|
+
this._affordanceMeshes = {
|
|
121287
|
+
front_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT),
|
|
121288
|
+
back_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT),
|
|
121289
|
+
right_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT),
|
|
121290
|
+
left_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT),
|
|
121291
|
+
top_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT),
|
|
121292
|
+
bottom_plane: rootNode.addChild(newMesh(this._controlEdgeColor), NO_STATE_INHERIT)
|
|
121293
|
+
};
|
|
121294
|
+
}
|
|
121190
121295
|
|
|
121191
|
-
|
|
121296
|
+
_bindEvents() {
|
|
121297
|
+
const self = this;
|
|
121298
|
+
var grabbed = false;
|
|
121299
|
+
const DRAG_ACTIONS = {
|
|
121300
|
+
none: -1,
|
|
121301
|
+
left_Translate: 0,
|
|
121302
|
+
top_Translate: 1,
|
|
121303
|
+
front_Translate: 2,
|
|
121304
|
+
right_Translate: 3,
|
|
121305
|
+
bottom_Translate: 4,
|
|
121306
|
+
back_Translate: 5
|
|
121307
|
+
};
|
|
121308
|
+
const rootNode = this._rootNode;
|
|
121309
|
+
var nextDragAction = null; // As we hover grabbed an arrow or hoop, self is the action we would do if we then dragged it.
|
|
121310
|
+
var dragAction = null; // Action we're doing while we drag an arrow or hoop.
|
|
121311
|
+
const lastCanvasPos = math.vec2();
|
|
121312
|
+
this.lastCanvasPos = lastCanvasPos;
|
|
121313
|
+
const xBaseAxis = math.vec3([1, 0, 0]);
|
|
121314
|
+
const yBaseAxis = math.vec3([0, 1, 0]);
|
|
121315
|
+
const zBaseAxis = math.vec3([0, 0, 1]);
|
|
121192
121316
|
|
|
121193
|
-
|
|
121194
|
-
|
|
121195
|
-
|
|
121317
|
+
const canvas = this._viewer.scene.canvas.canvas;
|
|
121318
|
+
const camera = this._viewer.camera;
|
|
121319
|
+
const scene = this._viewer.scene;
|
|
121196
121320
|
|
|
121197
|
-
|
|
121198
|
-
|
|
121199
|
-
|
|
121200
|
-
|
|
121201
|
-
|
|
121202
|
-
|
|
121203
|
-
|
|
121204
|
-
|
|
121205
|
-
|
|
121206
|
-
|
|
121321
|
+
{
|
|
121322
|
+
// Keep gizmo screen size constant
|
|
121323
|
+
const tempVec3a = math.vec3([0, 0, 0]);
|
|
121324
|
+
let lastDist = -1;
|
|
121325
|
+
|
|
121326
|
+
this._onCameraViewMatrix = scene.camera.on("viewMatrix", () => {
|
|
121327
|
+
});
|
|
121328
|
+
|
|
121329
|
+
this._onCameraProjMatrix = scene.camera.on("projMatrix", () => {
|
|
121330
|
+
});
|
|
121331
|
+
|
|
121332
|
+
this._onSceneTick = scene.on("tick", () => {
|
|
121333
|
+
const dist = Math.abs(math.lenVec3(math.subVec3(scene.camera.eye, this._pos, tempVec3a)));
|
|
121334
|
+
|
|
121335
|
+
if (dist !== lastDist) {
|
|
121336
|
+
if (camera.projection === "perspective") {
|
|
121337
|
+
const worldSize = Math.tan(camera.perspective.fov * math.DEGTORAD) * dist;
|
|
121338
|
+
const size = this._controlSize * worldSize;
|
|
121339
|
+
rootNode.scale = [size, size, size];
|
|
121340
|
+
lastDist = dist;
|
|
121341
|
+
}
|
|
121342
|
+
}
|
|
121343
|
+
|
|
121344
|
+
if (camera.projection === "ortho") {
|
|
121345
|
+
const worldSize = camera.ortho.scale / 10;
|
|
121346
|
+
const size = worldSize;
|
|
121347
|
+
rootNode.scale = [size, size, size];
|
|
121348
|
+
lastDist = dist;
|
|
121349
|
+
}
|
|
121350
|
+
});
|
|
121351
|
+
}
|
|
121352
|
+
|
|
121353
|
+
//鼠标获取屏幕点击坐标
|
|
121354
|
+
const getClickCoordsWithinElement = (function () {
|
|
121355
|
+
const canvasPos = new Float64Array(2);
|
|
121356
|
+
return function (event) {
|
|
121357
|
+
if (!event) {
|
|
121358
|
+
event = window.event;
|
|
121359
|
+
canvasPos[0] = event.x;
|
|
121360
|
+
canvasPos[1] = event.y;
|
|
121361
|
+
} else {
|
|
121362
|
+
var element = event.target;
|
|
121363
|
+
var totalOffsetLeft = 0;
|
|
121364
|
+
var totalOffsetTop = 0;
|
|
121365
|
+
|
|
121366
|
+
while (element.offsetParent) {
|
|
121367
|
+
totalOffsetLeft += element.offsetLeft;
|
|
121368
|
+
totalOffsetTop += element.offsetTop;
|
|
121369
|
+
element = element.offsetParent;
|
|
121370
|
+
}
|
|
121371
|
+
canvasPos[0] = event.pageX - totalOffsetLeft;
|
|
121372
|
+
canvasPos[1] = event.pageY - totalOffsetTop;
|
|
121373
|
+
}
|
|
121374
|
+
return canvasPos;
|
|
121375
|
+
};
|
|
121376
|
+
})();
|
|
121377
|
+
|
|
121378
|
+
//触屏获取屏幕点击坐标
|
|
121379
|
+
const getTouchCoordsWithinElement = (function () {
|
|
121380
|
+
const canvasPos = new Float64Array(2);
|
|
121381
|
+
return function (event) {
|
|
121382
|
+
if (!event) {
|
|
121383
|
+
event = window.event;
|
|
121384
|
+
}
|
|
121385
|
+
if (event.touches && event.touches.length) {
|
|
121386
|
+
// 如果有触摸事件,使用第一个触摸点的坐标
|
|
121387
|
+
canvasPos[0] = event.touches[0].pageX;
|
|
121388
|
+
canvasPos[1] = event.touches[0].pageY;
|
|
121389
|
+
} else {
|
|
121390
|
+
// 否则,假设是鼠标事件
|
|
121391
|
+
var element = event.target;
|
|
121392
|
+
var totalOffsetLeft = 0;
|
|
121393
|
+
var totalOffsetTop = 0;
|
|
121394
|
+
|
|
121395
|
+
while (element.offsetParent) {
|
|
121396
|
+
totalOffsetLeft += element.offsetLeft;
|
|
121397
|
+
totalOffsetTop += element.offsetTop;
|
|
121398
|
+
element = element.offsetParent;
|
|
121399
|
+
}
|
|
121400
|
+
canvasPos[0] = event.pageX - totalOffsetLeft;
|
|
121401
|
+
canvasPos[1] = event.pageY - totalOffsetTop;
|
|
121402
|
+
}
|
|
121403
|
+
return canvasPos;
|
|
121404
|
+
};
|
|
121405
|
+
})();
|
|
121406
|
+
|
|
121407
|
+
const localToWorldVec = (function () {
|
|
121408
|
+
const mat = math.mat4();
|
|
121409
|
+
return function (localVec, worldVec) {
|
|
121410
|
+
math.quaternionToMat4(self._rootNode.quaternion, mat);
|
|
121411
|
+
math.transformVec3(mat, localVec, worldVec);
|
|
121412
|
+
math.normalizeVec3(worldVec);
|
|
121413
|
+
return worldVec;
|
|
121414
|
+
};
|
|
121415
|
+
})();
|
|
121416
|
+
|
|
121417
|
+
var getTranslationPlane = (function () {
|
|
121418
|
+
const planeNormal = math.vec3();
|
|
121419
|
+
return function (worldAxis) {
|
|
121420
|
+
const absX = Math.abs(worldAxis[0]);
|
|
121421
|
+
if (absX > Math.abs(worldAxis[1]) && absX > Math.abs(worldAxis[2])) {
|
|
121422
|
+
math.cross3Vec3(worldAxis, [0, 1, 0], planeNormal);
|
|
121423
|
+
} else {
|
|
121424
|
+
math.cross3Vec3(worldAxis, [1, 0, 0], planeNormal);
|
|
121425
|
+
}
|
|
121426
|
+
math.cross3Vec3(planeNormal, worldAxis, planeNormal);
|
|
121427
|
+
math.normalizeVec3(planeNormal);
|
|
121428
|
+
return planeNormal;
|
|
121429
|
+
};
|
|
121430
|
+
})();
|
|
121431
|
+
|
|
121432
|
+
const dragTranslateSectionPlane = (function () {
|
|
121433
|
+
const p1 = math.vec3();
|
|
121434
|
+
const p2 = math.vec3();
|
|
121435
|
+
const worldAxis = math.vec4();
|
|
121436
|
+
return function (baseAxis, fromMouse, toMouse) {
|
|
121437
|
+
localToWorldVec(baseAxis, worldAxis);
|
|
121438
|
+
const planeNormal = getTranslationPlane(worldAxis, fromMouse, toMouse);
|
|
121439
|
+
getPointerPlaneIntersect(fromMouse, planeNormal, p1);
|
|
121440
|
+
getPointerPlaneIntersect(toMouse, planeNormal, p2);
|
|
121441
|
+
math.subVec3(p2, p1);
|
|
121442
|
+
const dot = math.dotVec3(p2, worldAxis);
|
|
121443
|
+
self._pos[0] += worldAxis[0] * dot;
|
|
121444
|
+
self._pos[1] += worldAxis[1] * dot;
|
|
121445
|
+
self._pos[2] += worldAxis[2] * dot;
|
|
121446
|
+
self._rootNode.position = self._pos;
|
|
121447
|
+
if (self._sectionPlane) {
|
|
121448
|
+
self._sectionPlane.pos = self._pos;
|
|
121449
|
+
}
|
|
121450
|
+
};
|
|
121451
|
+
})();
|
|
121452
|
+
|
|
121453
|
+
var dragRotateSectionPlane = (function () {
|
|
121454
|
+
const p1 = math.vec4();
|
|
121455
|
+
const p2 = math.vec4();
|
|
121456
|
+
const c = math.vec4();
|
|
121457
|
+
const worldAxis = math.vec4();
|
|
121458
|
+
return function (baseAxis, fromMouse, toMouse) {
|
|
121459
|
+
localToWorldVec(baseAxis, worldAxis);
|
|
121460
|
+
const hasData =
|
|
121461
|
+
getPointerPlaneIntersect(fromMouse, worldAxis, p1) && getPointerPlaneIntersect(toMouse, worldAxis, p2);
|
|
121462
|
+
if (!hasData) {
|
|
121463
|
+
// Find intersections with view plane and project down to origin
|
|
121464
|
+
const planeNormal = getTranslationPlane(worldAxis, fromMouse, toMouse);
|
|
121465
|
+
getPointerPlaneIntersect(fromMouse, planeNormal, p1, 1); // Ensure plane moves closer to camera so angles become workable
|
|
121466
|
+
getPointerPlaneIntersect(toMouse, planeNormal, p2, 1);
|
|
121467
|
+
var dot = math.dotVec3(p1, worldAxis);
|
|
121468
|
+
p1[0] -= dot * worldAxis[0];
|
|
121469
|
+
p1[1] -= dot * worldAxis[1];
|
|
121470
|
+
p1[2] -= dot * worldAxis[2];
|
|
121471
|
+
dot = math.dotVec3(p2, worldAxis);
|
|
121472
|
+
p2[0] -= dot * worldAxis[0];
|
|
121473
|
+
p2[1] -= dot * worldAxis[1];
|
|
121474
|
+
p2[2] -= dot * worldAxis[2];
|
|
121475
|
+
}
|
|
121476
|
+
math.normalizeVec3(p1);
|
|
121477
|
+
math.normalizeVec3(p2);
|
|
121478
|
+
dot = math.dotVec3(p1, p2);
|
|
121479
|
+
dot = math.clamp(dot, -1.0, 1.0); // Rounding errors cause dot to exceed allowed range
|
|
121480
|
+
var incDegrees = Math.acos(dot) * math.RADTODEG;
|
|
121481
|
+
math.cross3Vec3(p1, p2, c);
|
|
121482
|
+
if (math.dotVec3(c, worldAxis) < 0.0) {
|
|
121483
|
+
incDegrees = -incDegrees;
|
|
121484
|
+
}
|
|
121485
|
+
self._rootNode.rotate(baseAxis, incDegrees);
|
|
121486
|
+
rotateSectionPlane();
|
|
121487
|
+
};
|
|
121488
|
+
})();
|
|
121489
|
+
|
|
121490
|
+
var getPointerPlaneIntersect = (function () {
|
|
121491
|
+
const dir = math.vec4([0, 0, 0, 1]);
|
|
121492
|
+
const matrix = math.mat4();
|
|
121493
|
+
return function (mouse, axis, dest, offset) {
|
|
121494
|
+
offset = offset || 0;
|
|
121495
|
+
dir[0] = (mouse[0] / canvas.width) * 2.0 - 1.0;
|
|
121496
|
+
dir[1] = -((mouse[1] / canvas.height) * 2.0 - 1.0);
|
|
121497
|
+
dir[2] = 0.0;
|
|
121498
|
+
dir[3] = 1.0;
|
|
121499
|
+
math.mulMat4(camera.projMatrix, camera.viewMatrix, matrix); // Unproject norm device coords to view coords
|
|
121500
|
+
math.inverseMat4(matrix);
|
|
121501
|
+
math.transformVec4(matrix, dir, dir);
|
|
121502
|
+
math.mulVec4Scalar(dir, 1.0 / dir[3]); // This is now point A on the ray in world space
|
|
121503
|
+
var rayO = camera.eye; // The direction
|
|
121504
|
+
math.subVec4(dir, rayO, dir);
|
|
121505
|
+
const origin = self._sectionPlane.pos; // Plane origin:
|
|
121506
|
+
var d = -math.dotVec3(origin, axis) - offset;
|
|
121507
|
+
var dot = math.dotVec3(axis, dir);
|
|
121508
|
+
if (Math.abs(dot) > 0.005) {
|
|
121509
|
+
var t = -(math.dotVec3(axis, rayO) + d) / dot;
|
|
121510
|
+
math.mulVec3Scalar(dir, t, dest);
|
|
121511
|
+
math.addVec3(dest, rayO);
|
|
121512
|
+
math.subVec3(dest, origin, dest);
|
|
121513
|
+
return true;
|
|
121514
|
+
}
|
|
121515
|
+
return false;
|
|
121516
|
+
};
|
|
121517
|
+
})();
|
|
121518
|
+
|
|
121519
|
+
const rotateSectionPlane = (function () {
|
|
121520
|
+
const dir = math.vec3();
|
|
121521
|
+
const mat = math.mat4();
|
|
121522
|
+
return function () {
|
|
121523
|
+
if (self.sectionPlane) {
|
|
121524
|
+
math.quaternionToMat4(rootNode.quaternion, mat); // << ---
|
|
121525
|
+
math.transformVec3(mat, [0, 0, 1], dir);
|
|
121526
|
+
self._setSectionPlaneDir(dir);
|
|
121527
|
+
}
|
|
121528
|
+
};
|
|
121529
|
+
})();
|
|
121530
|
+
|
|
121531
|
+
{
|
|
121532
|
+
var down = false;
|
|
121533
|
+
var lastAffordanceMesh;
|
|
121534
|
+
|
|
121535
|
+
this._onCameraControlHover = this._viewer.cameraControl.on("hoverEnter", (hit) => {
|
|
121536
|
+
if (!this._visible) {
|
|
121537
|
+
return;
|
|
121538
|
+
}
|
|
121539
|
+
if (down) {
|
|
121540
|
+
return;
|
|
121541
|
+
}
|
|
121542
|
+
grabbed = false;
|
|
121543
|
+
if (lastAffordanceMesh) {
|
|
121544
|
+
lastAffordanceMesh.visible = false;
|
|
121545
|
+
}
|
|
121546
|
+
var affordanceMesh;
|
|
121547
|
+
const meshId = hit.entity.id;
|
|
121548
|
+
switch (meshId) {
|
|
121549
|
+
case this._displayMeshes.plane.id:
|
|
121550
|
+
affordanceMesh = this._affordanceMeshes.plane;
|
|
121551
|
+
nextDragAction = DRAG_ACTIONS.front_Translate;
|
|
121552
|
+
break;
|
|
121553
|
+
|
|
121554
|
+
case this._displayMeshes.xAxisArrowHandle.id:
|
|
121555
|
+
affordanceMesh = this._affordanceMeshes.xAxisArrow;
|
|
121556
|
+
nextDragAction = DRAG_ACTIONS.xTranslate;
|
|
121557
|
+
break;
|
|
121558
|
+
|
|
121559
|
+
case this._displayMeshes.xAxisHandle.id:
|
|
121560
|
+
affordanceMesh = this._affordanceMeshes.xAxisArrow;
|
|
121561
|
+
nextDragAction = DRAG_ACTIONS.xTranslate;
|
|
121562
|
+
break;
|
|
121563
|
+
|
|
121564
|
+
case this._displayMeshes.yAxisArrowHandle.id:
|
|
121565
|
+
affordanceMesh = this._affordanceMeshes.yAxisArrow;
|
|
121566
|
+
nextDragAction = DRAG_ACTIONS.yTranslate;
|
|
121567
|
+
break;
|
|
121568
|
+
|
|
121569
|
+
case this._displayMeshes.yShaftHandle.id:
|
|
121570
|
+
affordanceMesh = this._affordanceMeshes.yAxisArrow;
|
|
121571
|
+
nextDragAction = DRAG_ACTIONS.yTranslate;
|
|
121572
|
+
break;
|
|
121573
|
+
|
|
121574
|
+
case this._displayMeshes.zAxisArrowHandle.id:
|
|
121575
|
+
affordanceMesh = this._affordanceMeshes.zAxisArrow;
|
|
121576
|
+
nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
121577
|
+
break;
|
|
121578
|
+
|
|
121579
|
+
case this._displayMeshes.zAxisHandle.id:
|
|
121580
|
+
affordanceMesh = this._affordanceMeshes.zAxisArrow;
|
|
121581
|
+
nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
121582
|
+
break;
|
|
121583
|
+
|
|
121584
|
+
case this._displayMeshes.xCurveHandle.id:
|
|
121585
|
+
affordanceMesh = this._affordanceMeshes.xHoop;
|
|
121586
|
+
nextDragAction = DRAG_ACTIONS.xRotate;
|
|
121587
|
+
break;
|
|
121588
|
+
|
|
121589
|
+
default:
|
|
121590
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
121591
|
+
return; // Not clicked an arrow or hoop
|
|
121592
|
+
}
|
|
121593
|
+
if (affordanceMesh) {
|
|
121594
|
+
affordanceMesh.visible = true;
|
|
121595
|
+
}
|
|
121596
|
+
lastAffordanceMesh = affordanceMesh;
|
|
121597
|
+
grabbed = true;
|
|
121598
|
+
});
|
|
121599
|
+
|
|
121600
|
+
this._onCameraControlHoverLeave = this._viewer.cameraControl.on("hoverOutEntity", (hit) => {
|
|
121601
|
+
if (!this._visible) {
|
|
121602
|
+
return;
|
|
121603
|
+
}
|
|
121604
|
+
if (lastAffordanceMesh) {
|
|
121605
|
+
lastAffordanceMesh.visible = false;
|
|
121606
|
+
}
|
|
121607
|
+
lastAffordanceMesh = null;
|
|
121608
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
121609
|
+
});
|
|
121610
|
+
|
|
121611
|
+
//mousedown
|
|
121612
|
+
canvas.addEventListener(
|
|
121613
|
+
"mousedown",
|
|
121614
|
+
(this._canvasMouseDownListener = (e) => {
|
|
121615
|
+
e.preventDefault();
|
|
121616
|
+
if (!this._visible || !grabbed) return;
|
|
121617
|
+
|
|
121618
|
+
this._viewer.cameraControl.pointerEnabled = false;
|
|
121619
|
+
switch (e.which) {
|
|
121620
|
+
case 1: // Left button
|
|
121621
|
+
mouseDownLeft = true;
|
|
121622
|
+
down = true;
|
|
121623
|
+
var canvasPos = getClickCoordsWithinElement(e);
|
|
121624
|
+
dragAction = nextDragAction;
|
|
121625
|
+
lastCanvasPos[0] = canvasPos[0];
|
|
121626
|
+
lastCanvasPos[1] = canvasPos[1];
|
|
121627
|
+
break;
|
|
121628
|
+
}
|
|
121629
|
+
})
|
|
121630
|
+
);
|
|
121631
|
+
//mousemove
|
|
121632
|
+
canvas.addEventListener(
|
|
121633
|
+
"mousemove",
|
|
121634
|
+
(this._canvasMouseMoveListener = (e) => {
|
|
121635
|
+
if (!this._visible) {
|
|
121636
|
+
return;
|
|
121637
|
+
}
|
|
121638
|
+
if (!down) {
|
|
121639
|
+
return;
|
|
121640
|
+
}
|
|
121641
|
+
var canvasPos = getClickCoordsWithinElement(e);
|
|
121642
|
+
const x = canvasPos[0];
|
|
121643
|
+
const y = canvasPos[1];
|
|
121644
|
+
|
|
121645
|
+
switch (dragAction) {
|
|
121646
|
+
case DRAG_ACTIONS.xTranslate:
|
|
121647
|
+
dragTranslateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
121648
|
+
break;
|
|
121649
|
+
case DRAG_ACTIONS.yTranslate:
|
|
121650
|
+
dragTranslateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
121651
|
+
break;
|
|
121652
|
+
case DRAG_ACTIONS.zTranslate:
|
|
121653
|
+
dragTranslateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
121654
|
+
break;
|
|
121655
|
+
case DRAG_ACTIONS.xRotate:
|
|
121656
|
+
dragRotateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
121657
|
+
break;
|
|
121658
|
+
case DRAG_ACTIONS.yRotate:
|
|
121659
|
+
dragRotateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
121660
|
+
break;
|
|
121661
|
+
case DRAG_ACTIONS.zRotate:
|
|
121662
|
+
dragRotateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
121663
|
+
break;
|
|
121664
|
+
}
|
|
121665
|
+
|
|
121666
|
+
lastCanvasPos[0] = x;
|
|
121667
|
+
lastCanvasPos[1] = y;
|
|
121668
|
+
})
|
|
121669
|
+
);
|
|
121670
|
+
//mouseup
|
|
121671
|
+
canvas.addEventListener(
|
|
121672
|
+
"mouseup",
|
|
121673
|
+
(this._canvasMouseUpListener = (e) => {
|
|
121674
|
+
if (!this._visible) return;
|
|
121675
|
+
this._viewer.cameraControl.pointerEnabled = true;
|
|
121676
|
+
if (!down) {
|
|
121677
|
+
return;
|
|
121678
|
+
}
|
|
121679
|
+
switch (e.which) {
|
|
121680
|
+
case 1: // Left button
|
|
121681
|
+
mouseDownLeft = false;
|
|
121682
|
+
break;
|
|
121683
|
+
case 2: // Middle/both buttons
|
|
121684
|
+
mouseDownMiddle = false;
|
|
121685
|
+
break;
|
|
121686
|
+
case 3: // Right button
|
|
121687
|
+
mouseDownRight = false;
|
|
121688
|
+
break;
|
|
121689
|
+
}
|
|
121690
|
+
down = false;
|
|
121691
|
+
grabbed = false;
|
|
121692
|
+
})
|
|
121693
|
+
);
|
|
121694
|
+
|
|
121695
|
+
//wheel
|
|
121696
|
+
canvas.addEventListener(
|
|
121697
|
+
"wheel",
|
|
121698
|
+
(this._canvasWheelListener = (e) => {
|
|
121699
|
+
if (!this._visible) {
|
|
121700
|
+
return;
|
|
121701
|
+
}
|
|
121702
|
+
var delta = Math.max(-1, Math.min(1, -e.deltaY * 40));
|
|
121703
|
+
if (delta === 0) {
|
|
121704
|
+
return;
|
|
121705
|
+
}
|
|
121706
|
+
})
|
|
121707
|
+
);
|
|
121708
|
+
|
|
121709
|
+
this._onCameraControlHover = this._viewer.cameraControl.on("touchEntity", (hit) => {
|
|
121710
|
+
if (!this._visible || down || grabbed) return;
|
|
121711
|
+
grabbed = false;
|
|
121712
|
+
if (lastAffordanceMesh) {
|
|
121713
|
+
lastAffordanceMesh.visible = false;
|
|
121714
|
+
}
|
|
121715
|
+
var affordanceMesh;
|
|
121716
|
+
const meshId = hit.entity.id;
|
|
121717
|
+
switch (meshId) {
|
|
121718
|
+
case this._displayMeshes.plane.id:
|
|
121719
|
+
affordanceMesh = this._affordanceMeshes.plane;
|
|
121720
|
+
nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
121721
|
+
break;
|
|
121722
|
+
// case this._displayMeshes.xAxisArrowHandle.id:
|
|
121723
|
+
// affordanceMesh = this._affordanceMeshes.xAxisArrow;
|
|
121724
|
+
// nextDragAction = DRAG_ACTIONS.xTranslate;
|
|
121725
|
+
// break;
|
|
121726
|
+
|
|
121727
|
+
// case this._displayMeshes.xAxisHandle.id:
|
|
121728
|
+
// affordanceMesh = this._affordanceMeshes.xAxisArrow;
|
|
121729
|
+
// nextDragAction = DRAG_ACTIONS.xTranslate;
|
|
121730
|
+
// break;
|
|
121731
|
+
|
|
121732
|
+
// case this._displayMeshes.yAxisArrowHandle.id:
|
|
121733
|
+
// affordanceMesh = this._affordanceMeshes.yAxisArrow;
|
|
121734
|
+
// nextDragAction = DRAG_ACTIONS.yTranslate;
|
|
121735
|
+
// break;
|
|
121736
|
+
|
|
121737
|
+
// case this._displayMeshes.yShaftHandle.id:
|
|
121738
|
+
// affordanceMesh = this._affordanceMeshes.yAxisArrow;
|
|
121739
|
+
// nextDragAction = DRAG_ACTIONS.yTranslate;
|
|
121740
|
+
// break;
|
|
121741
|
+
|
|
121742
|
+
// case this._displayMeshes.zAxisArrowHandle.id:
|
|
121743
|
+
// affordanceMesh = this._affordanceMeshes.zAxisArrow;
|
|
121744
|
+
// nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
121745
|
+
// break;
|
|
121746
|
+
|
|
121747
|
+
// case this._displayMeshes.zAxisHandle.id:
|
|
121748
|
+
// affordanceMesh = this._affordanceMeshes.zAxisArrow;
|
|
121749
|
+
// nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
121750
|
+
// break;
|
|
121751
|
+
|
|
121752
|
+
// case this._displayMeshes.xCurveHandle.id:
|
|
121753
|
+
// affordanceMesh = this._affordanceMeshes.xHoop;
|
|
121754
|
+
// nextDragAction = DRAG_ACTIONS.xRotate;
|
|
121755
|
+
// break;
|
|
121756
|
+
|
|
121757
|
+
// case this._displayMeshes.yCurveHandle.id:
|
|
121758
|
+
// affordanceMesh = this._affordanceMeshes.yHoop;
|
|
121759
|
+
// nextDragAction = DRAG_ACTIONS.yRotate;
|
|
121760
|
+
// break;
|
|
121761
|
+
|
|
121762
|
+
// case this._displayMeshes.zCurveHandle.id:
|
|
121763
|
+
// affordanceMesh = this._affordanceMeshes.zHoop;
|
|
121764
|
+
// nextDragAction = DRAG_ACTIONS.zRotate;
|
|
121765
|
+
// break;
|
|
121766
|
+
|
|
121767
|
+
default:
|
|
121768
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
121769
|
+
return; // Not clicked an arrow or hoop
|
|
121770
|
+
}
|
|
121771
|
+
if (affordanceMesh) {
|
|
121772
|
+
affordanceMesh.visible = true;
|
|
121773
|
+
}
|
|
121774
|
+
lastAffordanceMesh = affordanceMesh;
|
|
121775
|
+
grabbed = true;
|
|
121776
|
+
});
|
|
121777
|
+
//touchstart
|
|
121778
|
+
canvas.addEventListener(
|
|
121779
|
+
"touchstart",
|
|
121780
|
+
(this._canvasMouseDownListener = (e) => {
|
|
121781
|
+
e.preventDefault();
|
|
121782
|
+
if (!this._visible || !grabbed) return;
|
|
121783
|
+
this._viewer.cameraControl.pointerEnabled = false;
|
|
121784
|
+
if (lastAffordanceMesh) {
|
|
121785
|
+
lastAffordanceMesh.visible = true;
|
|
121786
|
+
}
|
|
121787
|
+
down = true;
|
|
121788
|
+
var canvasPos = getTouchCoordsWithinElement(e);
|
|
121789
|
+
dragAction = nextDragAction;
|
|
121790
|
+
lastCanvasPos[0] = canvasPos[0];
|
|
121791
|
+
lastCanvasPos[1] = canvasPos[1];
|
|
121792
|
+
})
|
|
121793
|
+
);
|
|
121794
|
+
//touchmove
|
|
121795
|
+
canvas.addEventListener(
|
|
121796
|
+
"touchmove",
|
|
121797
|
+
(this._canvasMouseMoveListener = (e) => {
|
|
121798
|
+
if (!this._visible || !down) return;
|
|
121799
|
+
|
|
121800
|
+
var canvasPos = getTouchCoordsWithinElement(e);
|
|
121801
|
+
const x = canvasPos[0];
|
|
121802
|
+
const y = canvasPos[1];
|
|
121803
|
+
|
|
121804
|
+
switch (dragAction) {
|
|
121805
|
+
case DRAG_ACTIONS.xTranslate:
|
|
121806
|
+
dragTranslateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
121807
|
+
break;
|
|
121808
|
+
case DRAG_ACTIONS.yTranslate:
|
|
121809
|
+
dragTranslateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
121810
|
+
break;
|
|
121811
|
+
case DRAG_ACTIONS.zTranslate:
|
|
121812
|
+
dragTranslateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
121813
|
+
break;
|
|
121814
|
+
case DRAG_ACTIONS.xRotate:
|
|
121815
|
+
dragRotateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
121816
|
+
break;
|
|
121817
|
+
case DRAG_ACTIONS.yRotate:
|
|
121818
|
+
dragRotateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
121819
|
+
break;
|
|
121820
|
+
case DRAG_ACTIONS.zRotate:
|
|
121821
|
+
dragRotateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
121822
|
+
break;
|
|
121823
|
+
}
|
|
121824
|
+
|
|
121825
|
+
lastCanvasPos[0] = x;
|
|
121826
|
+
lastCanvasPos[1] = y;
|
|
121827
|
+
})
|
|
121828
|
+
);
|
|
121829
|
+
//touchend
|
|
121830
|
+
canvas.addEventListener(
|
|
121831
|
+
"touchend",
|
|
121832
|
+
(this._canvasTouchEndListener = (e) => {
|
|
121833
|
+
// if (!this._visible) return;
|
|
121834
|
+
this._viewer.cameraControl.pointerEnabled = true;
|
|
121835
|
+
if (lastAffordanceMesh) {
|
|
121836
|
+
lastAffordanceMesh.visible = false;
|
|
121837
|
+
}
|
|
121838
|
+
lastAffordanceMesh = null;
|
|
121839
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
121840
|
+
down = false;
|
|
121841
|
+
grabbed = false;
|
|
121842
|
+
})
|
|
121843
|
+
);
|
|
121844
|
+
canvas.addEventListener("touchcancel", this._canvasTouchEndListener);
|
|
121845
|
+
}
|
|
121846
|
+
}
|
|
121847
|
+
|
|
121848
|
+
_destroy() {
|
|
121849
|
+
this._unbindEvents();
|
|
121850
|
+
this._destroyNodes();
|
|
121851
|
+
}
|
|
121852
|
+
|
|
121853
|
+
_unbindEvents() {
|
|
121854
|
+
const viewer = this._viewer;
|
|
121855
|
+
const scene = viewer.scene;
|
|
121856
|
+
const canvas = scene.canvas.canvas;
|
|
121857
|
+
const camera = viewer.camera;
|
|
121858
|
+
const cameraControl = viewer.cameraControl;
|
|
121859
|
+
|
|
121860
|
+
scene.off(this._onSceneTick);
|
|
121861
|
+
|
|
121862
|
+
canvas.removeEventListener("mousedown", this._canvasMouseDownListener);
|
|
121863
|
+
canvas.removeEventListener("mousemove", this._canvasMouseMoveListener);
|
|
121864
|
+
canvas.removeEventListener("mouseup", this._canvasMouseUpListener);
|
|
121865
|
+
canvas.removeEventListener("wheel", this._canvasWheelListener);
|
|
121866
|
+
canvas.removeEventListener("touchend", this._canvasTouchEndListener);
|
|
121867
|
+
canvas.removeEventListener("touchcancel", this._canvasTouchEndListener);
|
|
121868
|
+
|
|
121869
|
+
camera.off(this._onCameraViewMatrix);
|
|
121870
|
+
camera.off(this._onCameraProjMatrix);
|
|
121871
|
+
|
|
121872
|
+
cameraControl.off(this._onCameraControlHover);
|
|
121873
|
+
cameraControl.off(this._onCameraControlHoverLeave);
|
|
121874
|
+
}
|
|
121875
|
+
|
|
121876
|
+
_destroyNodes() {
|
|
121877
|
+
this._setSectionPlane(null);
|
|
121878
|
+
this._rootNode.destroy();
|
|
121879
|
+
this._displayMeshes = {};
|
|
121880
|
+
this._affordanceMeshes = {};
|
|
121881
|
+
}
|
|
121882
|
+
}
|
|
121883
|
+
|
|
121884
|
+
const zeroVec$1 = new Float64Array([0, 0, 1]);
|
|
121885
|
+
const quat$1 = new Float64Array(4);
|
|
121886
|
+
|
|
121887
|
+
/**
|
|
121888
|
+
* Controls a {@link SectionPlane} with mouse and touch input.
|
|
121889
|
+
*
|
|
121890
|
+
* @private
|
|
121891
|
+
*/
|
|
121892
|
+
class ClippingPlane {
|
|
121893
|
+
/** @private */
|
|
121894
|
+
constructor(plugin, cfg) {
|
|
121895
|
+
/**
|
|
121896
|
+
* ID of this Control.
|
|
121897
|
+
*
|
|
121898
|
+
* SectionPlaneControls are mapped by this ID in {@link SectionPlanesPlugin#sectionPlaneControls}.
|
|
121899
|
+
*
|
|
121900
|
+
* @property id
|
|
121901
|
+
* @type {String|Number}
|
|
121902
|
+
*/
|
|
121903
|
+
this.id = null;
|
|
121904
|
+
this.type = "plane";
|
|
121905
|
+
|
|
121906
|
+
this._viewer = plugin.viewer;
|
|
121907
|
+
this._scene = plugin.viewer.scene;
|
|
121908
|
+
|
|
121909
|
+
this._controlFillColor = !!cfg && !!cfg.controlFillColor ? cfg.controlFillColor : [0.1, 0.4, 0.99];
|
|
121910
|
+
this._planeSize = !!cfg && !!cfg.planeSize ? cfg.planeSize : 1;
|
|
121911
|
+
this._controlSize = !!cfg && !!cfg.controlSize ? cfg.controlSize : 0.07;
|
|
121912
|
+
this._planeOpacity = !!cfg && !!cfg.planeOpacity ? cfg.planeOpacity : 0.4;
|
|
121913
|
+
|
|
121914
|
+
this._visible = false;
|
|
121915
|
+
this._pos = math.vec3(); // Full-precision position of the center of the Control
|
|
121916
|
+
this._origin = math.vec3();
|
|
121917
|
+
this._rtcPos = math.vec3();
|
|
121918
|
+
|
|
121919
|
+
this._baseDir = math.vec3(); // Saves direction of clip plane when we start dragging an arrow or ring.
|
|
121920
|
+
this._rootNode = null; // Root of Node graph that represents this control in the 3D scene
|
|
121921
|
+
this._displayMeshes = null; // Meshes that are always visible
|
|
121922
|
+
this._affordanceMeshes = null; // Meshes displayed momentarily for affordance
|
|
121923
|
+
|
|
121924
|
+
this._ignoreNextSectionPlaneDirUpdate = false;
|
|
121925
|
+
|
|
121926
|
+
this._createNodes();
|
|
121927
|
+
this._bindEvents();
|
|
121928
|
+
}
|
|
121929
|
+
|
|
121930
|
+
/**
|
|
121931
|
+
* Builds the Entities that represent this Control.
|
|
121932
|
+
* @private
|
|
121933
|
+
*/
|
|
121934
|
+
_createNodes() {
|
|
121935
|
+
const NO_STATE_INHERIT = false;
|
|
121936
|
+
const scene = this._viewer.scene;
|
|
121937
|
+
|
|
121938
|
+
this._rootNode = new Node$2(scene, {
|
|
121939
|
+
position: [0, 0, 0],
|
|
121940
|
+
scale: [5, 5, 5],
|
|
121941
|
+
isObject: false
|
|
121942
|
+
});
|
|
121943
|
+
|
|
121944
|
+
const rootNode = this._rootNode;
|
|
121945
|
+
|
|
121946
|
+
this._displayMeshes = {
|
|
121947
|
+
plane: rootNode.addChild(
|
|
121948
|
+
new Mesh(rootNode, {
|
|
121949
|
+
geometry: new ReadableGeometry(rootNode, {
|
|
121950
|
+
primitive: "triangles",
|
|
121951
|
+
positions: [
|
|
121952
|
+
0.5,
|
|
121953
|
+
0.5,
|
|
121954
|
+
0.0,
|
|
121955
|
+
0.5,
|
|
121956
|
+
-0.5,
|
|
121957
|
+
0.0, // 0
|
|
121958
|
+
-0.5,
|
|
121959
|
+
-0.5,
|
|
121960
|
+
0.0,
|
|
121961
|
+
-0.5,
|
|
121962
|
+
0.5,
|
|
121963
|
+
0.0, // 1
|
|
121964
|
+
0.5,
|
|
121965
|
+
0.5,
|
|
121966
|
+
-0.0,
|
|
121967
|
+
0.5,
|
|
121968
|
+
-0.5,
|
|
121969
|
+
-0.0, // 2
|
|
121970
|
+
-0.5,
|
|
121971
|
+
-0.5,
|
|
121972
|
+
-0.0,
|
|
121973
|
+
-0.5,
|
|
121974
|
+
0.5,
|
|
121975
|
+
-0.0 // 3
|
|
121976
|
+
],
|
|
121977
|
+
indices: [0, 1, 2, 2, 3, 0]
|
|
121978
|
+
}),
|
|
121979
|
+
material: new PhongMaterial(rootNode, {
|
|
121980
|
+
emissive: [0, 0, 0],
|
|
121981
|
+
diffuse: this._controlFillColor,
|
|
121982
|
+
backfaces: true
|
|
121983
|
+
}),
|
|
121984
|
+
opacity: this._planeOpacity,
|
|
121985
|
+
ghosted: true,
|
|
121986
|
+
ghostMaterial: new EmphasisMaterial(rootNode, {
|
|
121987
|
+
edges: false,
|
|
121988
|
+
filled: true,
|
|
121989
|
+
fillColor: this._controlFillColor ? this._controlFillColor : [0.1, 0.4, 0.99],
|
|
121990
|
+
fillAlpha: 0.1,
|
|
121991
|
+
backfaces: true
|
|
121992
|
+
}),
|
|
121993
|
+
pickable: true,
|
|
121994
|
+
collidable: true,
|
|
121995
|
+
clippable: false,
|
|
121996
|
+
visible: false,
|
|
121997
|
+
scale: [2.4 * this._planeSize, 2.4 * this._planeSize, 1 * this._planeSize],
|
|
121998
|
+
isObject: false
|
|
121999
|
+
}),
|
|
122000
|
+
NO_STATE_INHERIT
|
|
122001
|
+
)
|
|
122002
|
+
};
|
|
122003
|
+
|
|
122004
|
+
this._affordanceMeshes = {
|
|
122005
|
+
// plane: rootNode.addChild(
|
|
122006
|
+
// new Mesh(rootNode, {
|
|
122007
|
+
// geometry: new ReadableGeometry(rootNode, {
|
|
122008
|
+
// primitive: "triangles",
|
|
122009
|
+
// positions: [
|
|
122010
|
+
// 0.5,
|
|
122011
|
+
// 0.5,
|
|
122012
|
+
// 0.0,
|
|
122013
|
+
// 0.5,
|
|
122014
|
+
// -0.5,
|
|
122015
|
+
// 0.0, // 0
|
|
122016
|
+
// -0.5,
|
|
122017
|
+
// -0.5,
|
|
122018
|
+
// 0.0,
|
|
122019
|
+
// -0.5,
|
|
122020
|
+
// 0.5,
|
|
122021
|
+
// 0.0, // 1
|
|
122022
|
+
// 0.5,
|
|
122023
|
+
// 0.5,
|
|
122024
|
+
// -0.0,
|
|
122025
|
+
// 0.5,
|
|
122026
|
+
// -0.5,
|
|
122027
|
+
// -0.0, // 2
|
|
122028
|
+
// -0.5,
|
|
122029
|
+
// -0.5,
|
|
122030
|
+
// -0.0,
|
|
122031
|
+
// -0.5,
|
|
122032
|
+
// 0.5,
|
|
122033
|
+
// -0.0 // 3
|
|
122034
|
+
// ],
|
|
122035
|
+
// indices: [0, 1, 2, 2, 3, 0]
|
|
122036
|
+
// }),
|
|
122037
|
+
// material: new PhongMaterial(rootNode, {
|
|
122038
|
+
// emissive: [0, 0, 0],
|
|
122039
|
+
// diffuse: this._controlFillColor,
|
|
122040
|
+
// backfaces: true
|
|
122041
|
+
// }),
|
|
122042
|
+
// opacity: this._planeOpacity,
|
|
122043
|
+
// ghosted: true,
|
|
122044
|
+
// ghostMaterial: new EmphasisMaterial(rootNode, {
|
|
122045
|
+
// edges: false,
|
|
122046
|
+
// filled: true,
|
|
122047
|
+
// fillColor: this._controlFillColor,
|
|
122048
|
+
// fillAlpha: 0.1,
|
|
122049
|
+
// backfaces: true
|
|
122050
|
+
// }),
|
|
122051
|
+
// pickable: true,
|
|
122052
|
+
// collidable: true,
|
|
122053
|
+
// clippable: false,
|
|
122054
|
+
// visible: false,
|
|
122055
|
+
// scale: [2.4 * this._planeSize, 2.4 * this._planeSize, 1 * this._planeSize],
|
|
122056
|
+
// isObject: false
|
|
122057
|
+
// }),
|
|
122058
|
+
// NO_STATE_INHERIT
|
|
122059
|
+
// )
|
|
122060
|
+
};
|
|
122061
|
+
}
|
|
122062
|
+
|
|
122063
|
+
/**
|
|
122064
|
+
* Called by SectionPlanesPlugin to assign this Control to a SectionPlane.
|
|
122065
|
+
* SectionPlanesPlugin keeps SectionPlaneControls in a reuse pool.
|
|
122066
|
+
* Call with a null or undefined value to disconnect the Control ffrom whatever SectionPlane it was assigned to.
|
|
122067
|
+
* @private
|
|
122068
|
+
*/
|
|
122069
|
+
_setSectionPlane(sectionPlane) {
|
|
122070
|
+
if (this._sectionPlane) {
|
|
122071
|
+
this._sectionPlane.off(this._onSectionPlanePos);
|
|
122072
|
+
this._sectionPlane.off(this._onSectionPlaneDir);
|
|
122073
|
+
this._onSectionPlanePos = null;
|
|
122074
|
+
this._onSectionPlaneDir = null;
|
|
122075
|
+
this._sectionPlane = null;
|
|
122076
|
+
}
|
|
122077
|
+
if (sectionPlane) {
|
|
122078
|
+
this.id = sectionPlane.id;
|
|
122079
|
+
this._setPos(sectionPlane.pos);
|
|
122080
|
+
this._setDir(sectionPlane.dir);
|
|
122081
|
+
this._sectionPlane = sectionPlane;
|
|
122082
|
+
sectionPlane.control = this;
|
|
122083
|
+
this._onSectionPlanePos = sectionPlane.on("pos", () => {
|
|
122084
|
+
this._setPos(this._sectionPlane.pos);
|
|
122085
|
+
});
|
|
122086
|
+
this._onSectionPlaneDir = sectionPlane.on("dir", () => {
|
|
122087
|
+
if (!this._ignoreNextSectionPlaneDirUpdate) {
|
|
122088
|
+
this._setDir(this._sectionPlane.dir);
|
|
122089
|
+
} else {
|
|
122090
|
+
this._ignoreNextSectionPlaneDirUpdate = false;
|
|
122091
|
+
}
|
|
122092
|
+
});
|
|
122093
|
+
}
|
|
122094
|
+
}
|
|
122095
|
+
|
|
122096
|
+
/**
|
|
122097
|
+
* Gets the {@link SectionPlane} controlled by this Control.
|
|
122098
|
+
* @returns {SectionPlane} The SectionPlane.
|
|
122099
|
+
*/
|
|
122100
|
+
get sectionPlane() {
|
|
122101
|
+
return this._sectionPlane;
|
|
122102
|
+
}
|
|
122103
|
+
|
|
122104
|
+
/**
|
|
122105
|
+
* 设置剖切面位置
|
|
122106
|
+
* @param {any} value
|
|
122107
|
+
*/
|
|
122108
|
+
set pos(posRate) {
|
|
122109
|
+
if (posRate < 0 || posRate > 100) return;
|
|
122110
|
+
|
|
122111
|
+
const { aabb } = this._scene;
|
|
122112
|
+
const { look } = this._scene.camera;
|
|
122113
|
+
const xRange = aabb[3] - aabb[0]; //前后
|
|
122114
|
+
const yRange = aabb[4] - aabb[1]; //上下
|
|
122115
|
+
const zRange = aabb[5] - aabb[2]; //左右
|
|
122116
|
+
|
|
122117
|
+
const newSectionPos = math.vec3();
|
|
122118
|
+
newSectionPos[0] = this.pos[0];
|
|
122119
|
+
newSectionPos[1] = this.pos[1];
|
|
122120
|
+
newSectionPos[2] = this.pos[2];
|
|
122121
|
+
|
|
122122
|
+
const { dir } = this._sectionPlane;
|
|
122123
|
+
let rateDis;
|
|
122124
|
+
if (dir[0] != 0) {
|
|
122125
|
+
rateDis = (posRate / 100) * xRange;
|
|
122126
|
+
newSectionPos[0] = look[0] - xRange / 2 + rateDis; // console.log("xRange", rateDis, rateDis + aabb[0]);
|
|
122127
|
+
} else if (dir[1] != 0) {
|
|
122128
|
+
rateDis = (posRate / 100) * yRange;
|
|
122129
|
+
newSectionPos[1] = look[1] - yRange / 2 + rateDis; // console.log("yRange", rateDis, rateDis + aabb[1]);
|
|
122130
|
+
} else if (dir[2] != 0) {
|
|
122131
|
+
rateDis = (posRate / 100) * zRange;
|
|
122132
|
+
newSectionPos[2] = look[2] - zRange / 2 + rateDis; // console.log("zRange", rateDis, rateDis + aabb[2]);
|
|
122133
|
+
}
|
|
122134
|
+
|
|
122135
|
+
this._sectionPlane.pos = newSectionPos;
|
|
122136
|
+
}
|
|
122137
|
+
|
|
122138
|
+
get pos() {
|
|
122139
|
+
return this._pos;
|
|
122140
|
+
}
|
|
122141
|
+
|
|
122142
|
+
/** @private */
|
|
122143
|
+
_setPos(xyz) {
|
|
122144
|
+
this._pos.set(xyz);
|
|
122145
|
+
worldToRTCPos(this._pos, this._origin, this._rtcPos);
|
|
122146
|
+
this._rootNode.origin = this._origin;
|
|
122147
|
+
this._rootNode.position = this._rtcPos;
|
|
122148
|
+
}
|
|
122149
|
+
|
|
122150
|
+
/** @private */
|
|
122151
|
+
_setDir(xyz) {
|
|
122152
|
+
this._baseDir.set(xyz);
|
|
122153
|
+
this._rootNode.quaternion = math.vec3PairToQuaternion(zeroVec$1, xyz, quat$1);
|
|
122154
|
+
}
|
|
122155
|
+
|
|
122156
|
+
_setSectionPlaneDir(dir) {
|
|
122157
|
+
if (this._sectionPlane) {
|
|
122158
|
+
this._ignoreNextSectionPlaneDirUpdate = true;
|
|
122159
|
+
this._sectionPlane.dir = dir;
|
|
122160
|
+
}
|
|
122161
|
+
}
|
|
122162
|
+
|
|
122163
|
+
/**
|
|
122164
|
+
* Sets if this Control is visible.
|
|
122165
|
+
*
|
|
122166
|
+
* @type {Boolean}
|
|
122167
|
+
*/
|
|
122168
|
+
setVisible(visible = true) {
|
|
122169
|
+
if (this._visible === visible) {
|
|
122170
|
+
return;
|
|
122171
|
+
}
|
|
122172
|
+
this._visible = visible;
|
|
122173
|
+
var id;
|
|
122174
|
+
for (id in this._displayMeshes) {
|
|
122175
|
+
if (this._displayMeshes.hasOwnProperty(id)) {
|
|
122176
|
+
this._displayMeshes[id].visible = visible;
|
|
122177
|
+
}
|
|
122178
|
+
}
|
|
122179
|
+
if (!visible) {
|
|
122180
|
+
for (id in this._affordanceMeshes) {
|
|
122181
|
+
if (this._affordanceMeshes.hasOwnProperty(id)) {
|
|
122182
|
+
this._affordanceMeshes[id].visible = visible;
|
|
122183
|
+
}
|
|
122184
|
+
}
|
|
122185
|
+
}
|
|
122186
|
+
}
|
|
122187
|
+
|
|
122188
|
+
/**
|
|
122189
|
+
* Gets if this Control is visible.
|
|
122190
|
+
*
|
|
122191
|
+
* @type {Boolean}
|
|
122192
|
+
*/
|
|
122193
|
+
getVisible() {
|
|
122194
|
+
return this._visible;
|
|
122195
|
+
}
|
|
122196
|
+
|
|
122197
|
+
/**
|
|
122198
|
+
* Sets if this Control is culled. This is called by SectionPlanesPlugin to
|
|
122199
|
+
* temporarily hide the Control while a snapshot is being taken by Viewer#getSnapshot().
|
|
122200
|
+
* @param culled
|
|
122201
|
+
*/
|
|
122202
|
+
setCulled(culled) {
|
|
122203
|
+
var id;
|
|
122204
|
+
for (id in this._displayMeshes) {
|
|
122205
|
+
if (this._displayMeshes.hasOwnProperty(id)) {
|
|
122206
|
+
this._displayMeshes[id].culled = culled;
|
|
122207
|
+
}
|
|
122208
|
+
}
|
|
122209
|
+
if (!culled) {
|
|
122210
|
+
for (id in this._affordanceMeshes) {
|
|
122211
|
+
if (this._affordanceMeshes.hasOwnProperty(id)) {
|
|
122212
|
+
this._affordanceMeshes[id].culled = culled;
|
|
122213
|
+
}
|
|
122214
|
+
}
|
|
122215
|
+
}
|
|
122216
|
+
}
|
|
122217
|
+
|
|
122218
|
+
_bindEvents() {
|
|
122219
|
+
const self = this;
|
|
122220
|
+
|
|
122221
|
+
var grabbed = false;
|
|
122222
|
+
|
|
122223
|
+
const DRAG_ACTIONS = {
|
|
122224
|
+
none: -1,
|
|
122225
|
+
xTranslate: 0,
|
|
122226
|
+
yTranslate: 1,
|
|
122227
|
+
zTranslate: 2,
|
|
122228
|
+
xRotate: 3,
|
|
122229
|
+
yRotate: 4,
|
|
122230
|
+
zRotate: 5
|
|
122231
|
+
};
|
|
122232
|
+
|
|
122233
|
+
this._rootNode;
|
|
122234
|
+
|
|
122235
|
+
var nextDragAction = null; // As we hover grabbed an arrow or hoop, self is the action we would do if we then dragged it.
|
|
122236
|
+
var dragAction = null; // Action we're doing while we drag an arrow or hoop.
|
|
122237
|
+
const lastCanvasPos = math.vec2();
|
|
122238
|
+
this.lastCanvasPos = lastCanvasPos;
|
|
122239
|
+
const xBaseAxis = math.vec3([1, 0, 0]);
|
|
122240
|
+
const yBaseAxis = math.vec3([0, 1, 0]);
|
|
122241
|
+
const zBaseAxis = math.vec3([0, 0, 1]);
|
|
122242
|
+
|
|
122243
|
+
const canvas = this._viewer.scene.canvas.canvas;
|
|
122244
|
+
const camera = this._viewer.camera;
|
|
122245
|
+
const scene = this._viewer.scene;
|
|
122246
|
+
|
|
122247
|
+
{
|
|
122248
|
+
// Keep gizmo screen size constant
|
|
122249
|
+
|
|
122250
|
+
const tempVec3a = math.vec3([0, 0, 0]);
|
|
122251
|
+
let lastDist = -1;
|
|
122252
|
+
|
|
122253
|
+
this._onCameraViewMatrix = scene.camera.on("viewMatrix", () => {
|
|
122254
|
+
});
|
|
122255
|
+
|
|
122256
|
+
this._onCameraProjMatrix = scene.camera.on("projMatrix", () => {
|
|
122257
|
+
});
|
|
122258
|
+
|
|
122259
|
+
this._onSceneTick = scene.on("tick", () => {
|
|
122260
|
+
const dist = Math.abs(math.lenVec3(math.subVec3(scene.camera.eye, this._pos, tempVec3a)));
|
|
122261
|
+
|
|
122262
|
+
if (dist !== lastDist) {
|
|
122263
|
+
if (camera.projection === "perspective") {
|
|
122264
|
+
Math.tan(camera.perspective.fov * math.DEGTORAD) * dist;
|
|
122265
|
+
// const size = this._controlSize * worldSize;
|
|
122266
|
+
// rootNode.scale = [size, size, size];
|
|
122267
|
+
lastDist = dist;
|
|
122268
|
+
}
|
|
122269
|
+
}
|
|
122270
|
+
|
|
122271
|
+
if (camera.projection === "ortho") {
|
|
122272
|
+
camera.ortho.scale / 10;
|
|
122273
|
+
// const size = worldSize;
|
|
122274
|
+
// rootNode.scale = [size, size, size];
|
|
122275
|
+
lastDist = dist;
|
|
122276
|
+
}
|
|
122277
|
+
});
|
|
122278
|
+
}
|
|
122279
|
+
|
|
122280
|
+
const getClickCoordsWithinElement = (function () {
|
|
122281
|
+
const canvasPos = new Float64Array(2);
|
|
122282
|
+
return function (event) {
|
|
122283
|
+
if (!event) {
|
|
122284
|
+
event = window.event;
|
|
122285
|
+
canvasPos[0] = event.x;
|
|
122286
|
+
canvasPos[1] = event.y;
|
|
122287
|
+
} else {
|
|
122288
|
+
var element = event.target;
|
|
122289
|
+
var totalOffsetLeft = 0;
|
|
122290
|
+
var totalOffsetTop = 0;
|
|
122291
|
+
|
|
122292
|
+
while (element.offsetParent) {
|
|
122293
|
+
totalOffsetLeft += element.offsetLeft;
|
|
122294
|
+
totalOffsetTop += element.offsetTop;
|
|
122295
|
+
element = element.offsetParent;
|
|
122296
|
+
}
|
|
122297
|
+
canvasPos[0] = event.pageX - totalOffsetLeft;
|
|
122298
|
+
canvasPos[1] = event.pageY - totalOffsetTop;
|
|
122299
|
+
}
|
|
122300
|
+
return canvasPos;
|
|
122301
|
+
};
|
|
122302
|
+
})();
|
|
122303
|
+
|
|
122304
|
+
const getTouchCoordsWithinElement = (function () {
|
|
122305
|
+
const canvasPos = new Float64Array(2);
|
|
122306
|
+
return function (event) {
|
|
122307
|
+
if (!event) {
|
|
122308
|
+
event = window.event;
|
|
122309
|
+
}
|
|
122310
|
+
if (event.touches && event.touches.length) {
|
|
122311
|
+
// 如果有触摸事件,使用第一个触摸点的坐标
|
|
122312
|
+
canvasPos[0] = event.touches[0].pageX;
|
|
122313
|
+
canvasPos[1] = event.touches[0].pageY;
|
|
122314
|
+
} else {
|
|
122315
|
+
// 否则,假设是鼠标事件
|
|
122316
|
+
var element = event.target;
|
|
122317
|
+
var totalOffsetLeft = 0;
|
|
122318
|
+
var totalOffsetTop = 0;
|
|
122319
|
+
|
|
122320
|
+
while (element.offsetParent) {
|
|
122321
|
+
totalOffsetLeft += element.offsetLeft;
|
|
122322
|
+
totalOffsetTop += element.offsetTop;
|
|
122323
|
+
element = element.offsetParent;
|
|
122324
|
+
}
|
|
122325
|
+
canvasPos[0] = event.pageX - totalOffsetLeft;
|
|
122326
|
+
canvasPos[1] = event.pageY - totalOffsetTop;
|
|
122327
|
+
}
|
|
122328
|
+
return canvasPos;
|
|
122329
|
+
};
|
|
122330
|
+
})();
|
|
122331
|
+
|
|
122332
|
+
//转换为世界坐标
|
|
122333
|
+
const localToWorldVec = (function () {
|
|
122334
|
+
const mat = math.mat4();
|
|
122335
|
+
return function (localVec, worldVec) {
|
|
122336
|
+
math.quaternionToMat4(self._rootNode.quaternion, mat);
|
|
122337
|
+
math.transformVec3(mat, localVec, worldVec);
|
|
122338
|
+
math.normalizeVec3(worldVec);
|
|
122339
|
+
return worldVec;
|
|
122340
|
+
};
|
|
122341
|
+
})();
|
|
122342
|
+
|
|
122343
|
+
var getTranslationPlane = (function () {
|
|
122344
|
+
const planeNormal = math.vec3();
|
|
122345
|
+
return function (worldAxis) {
|
|
122346
|
+
const absX = Math.abs(worldAxis[0]);
|
|
122347
|
+
if (absX > Math.abs(worldAxis[1]) && absX > Math.abs(worldAxis[2])) {
|
|
122348
|
+
math.cross3Vec3(worldAxis, [0, 1, 0], planeNormal);
|
|
122349
|
+
} else {
|
|
122350
|
+
math.cross3Vec3(worldAxis, [1, 0, 0], planeNormal);
|
|
122351
|
+
}
|
|
122352
|
+
math.cross3Vec3(planeNormal, worldAxis, planeNormal);
|
|
122353
|
+
math.normalizeVec3(planeNormal);
|
|
122354
|
+
return planeNormal;
|
|
122355
|
+
};
|
|
122356
|
+
})();
|
|
122357
|
+
|
|
122358
|
+
//拖拽平面
|
|
122359
|
+
const dragTranslateSectionPlane = (function () {
|
|
122360
|
+
const p1 = math.vec3();
|
|
122361
|
+
const p2 = math.vec3();
|
|
122362
|
+
const worldAxis = math.vec4();
|
|
122363
|
+
return function (baseAxis, fromMouse, toMouse) {
|
|
122364
|
+
localToWorldVec(baseAxis, worldAxis);
|
|
122365
|
+
const planeNormal = getTranslationPlane(worldAxis, fromMouse, toMouse);
|
|
122366
|
+
getPointerPlaneIntersect(fromMouse, planeNormal, p1);
|
|
122367
|
+
getPointerPlaneIntersect(toMouse, planeNormal, p2);
|
|
122368
|
+
math.subVec3(p2, p1);
|
|
122369
|
+
const dot = math.dotVec3(p2, worldAxis);
|
|
122370
|
+
self._pos[0] += worldAxis[0] * dot;
|
|
122371
|
+
self._pos[1] += worldAxis[1] * dot;
|
|
122372
|
+
self._pos[2] += worldAxis[2] * dot;
|
|
122373
|
+
self._rootNode.position = self._pos;
|
|
122374
|
+
if (self._sectionPlane) {
|
|
122375
|
+
self._sectionPlane.pos = self._pos;
|
|
122376
|
+
}
|
|
122377
|
+
};
|
|
122378
|
+
})();
|
|
122379
|
+
|
|
122380
|
+
var getPointerPlaneIntersect = (function () {
|
|
122381
|
+
const dir = math.vec4([0, 0, 0, 1]);
|
|
122382
|
+
const matrix = math.mat4();
|
|
122383
|
+
return function (mouse, axis, dest, offset) {
|
|
122384
|
+
offset = offset || 0;
|
|
122385
|
+
dir[0] = (mouse[0] / canvas.width) * 2.0 - 1.0;
|
|
122386
|
+
dir[1] = -((mouse[1] / canvas.height) * 2.0 - 1.0);
|
|
122387
|
+
dir[2] = 0.0;
|
|
122388
|
+
dir[3] = 1.0;
|
|
122389
|
+
math.mulMat4(camera.projMatrix, camera.viewMatrix, matrix); // Unproject norm device coords to view coords
|
|
122390
|
+
math.inverseMat4(matrix);
|
|
122391
|
+
math.transformVec4(matrix, dir, dir);
|
|
122392
|
+
math.mulVec4Scalar(dir, 1.0 / dir[3]); // This is now point A on the ray in world space
|
|
122393
|
+
var rayO = camera.eye; // The direction
|
|
122394
|
+
math.subVec4(dir, rayO, dir);
|
|
122395
|
+
const origin = self._sectionPlane.pos; // Plane origin:
|
|
122396
|
+
var d = -math.dotVec3(origin, axis) - offset;
|
|
122397
|
+
var dot = math.dotVec3(axis, dir);
|
|
122398
|
+
if (Math.abs(dot) > 0.005) {
|
|
122399
|
+
var t = -(math.dotVec3(axis, rayO) + d) / dot;
|
|
122400
|
+
math.mulVec3Scalar(dir, t, dest);
|
|
122401
|
+
math.addVec3(dest, rayO);
|
|
122402
|
+
math.subVec3(dest, origin, dest);
|
|
122403
|
+
return true;
|
|
122404
|
+
}
|
|
122405
|
+
return false;
|
|
122406
|
+
};
|
|
122407
|
+
})();
|
|
122408
|
+
|
|
122409
|
+
{
|
|
122410
|
+
var down = false;
|
|
122411
|
+
// var lastAffordanceMesh;
|
|
122412
|
+
|
|
122413
|
+
this._onCameraControlHover = this._viewer.cameraControl.on("hoverEnter", (hit) => {
|
|
122414
|
+
if (!this._visible) {
|
|
122415
|
+
return;
|
|
122416
|
+
}
|
|
122417
|
+
if (down) {
|
|
122418
|
+
return;
|
|
122419
|
+
}
|
|
122420
|
+
grabbed = false;
|
|
122421
|
+
// if (lastAffordanceMesh) {
|
|
122422
|
+
// lastAffordanceMesh.visible = false;
|
|
122423
|
+
// }
|
|
122424
|
+
// var affordanceMesh;
|
|
122425
|
+
const meshId = hit.entity.id;
|
|
122426
|
+
switch (meshId) {
|
|
122427
|
+
case this._displayMeshes.plane.id:
|
|
122428
|
+
// affordanceMesh = this._affordanceMeshes.plane;
|
|
122429
|
+
nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
122430
|
+
break;
|
|
122431
|
+
default:
|
|
122432
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
122433
|
+
return; // Not clicked an arrow or hoop
|
|
122434
|
+
}
|
|
122435
|
+
// if (affordanceMesh) {
|
|
122436
|
+
// affordanceMesh.visible = true;
|
|
122437
|
+
// }
|
|
122438
|
+
// lastAffordanceMesh = affordanceMesh;
|
|
122439
|
+
grabbed = true;
|
|
122440
|
+
});
|
|
122441
|
+
|
|
122442
|
+
this._onCameraControlHoverLeave = this._viewer.cameraControl.on("hoverOutEntity", (hit) => {
|
|
122443
|
+
if (!this._visible) {
|
|
122444
|
+
return;
|
|
122445
|
+
}
|
|
122446
|
+
// if (lastAffordanceMesh) {
|
|
122447
|
+
// lastAffordanceMesh.visible = false;
|
|
122448
|
+
// }
|
|
122449
|
+
// lastAffordanceMesh = null;
|
|
122450
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
122451
|
+
});
|
|
122452
|
+
|
|
122453
|
+
//mousedown
|
|
122454
|
+
canvas.addEventListener(
|
|
122455
|
+
"mousedown",
|
|
122456
|
+
(this._canvasMouseDownListener = (e) => {
|
|
122457
|
+
e.preventDefault();
|
|
122458
|
+
if (!this._visible || !grabbed) return;
|
|
122459
|
+
|
|
122460
|
+
this._viewer.cameraControl.pointerEnabled = false;
|
|
122461
|
+
switch (e.which) {
|
|
122462
|
+
case 1: // Left button
|
|
122463
|
+
down = true;
|
|
122464
|
+
var canvasPos = getClickCoordsWithinElement(e); //获取鼠标点击对应坐标
|
|
122465
|
+
dragAction = nextDragAction;
|
|
122466
|
+
lastCanvasPos[0] = canvasPos[0];
|
|
122467
|
+
lastCanvasPos[1] = canvasPos[1];
|
|
122468
|
+
break;
|
|
122469
|
+
}
|
|
122470
|
+
})
|
|
122471
|
+
);
|
|
122472
|
+
//mousemove
|
|
122473
|
+
canvas.addEventListener(
|
|
122474
|
+
"mousemove",
|
|
122475
|
+
(this._canvasMouseMoveListener = (e) => {
|
|
122476
|
+
if (!this._visible) {
|
|
122477
|
+
return;
|
|
122478
|
+
}
|
|
122479
|
+
if (!down) {
|
|
122480
|
+
return;
|
|
122481
|
+
}
|
|
122482
|
+
var canvasPos = getClickCoordsWithinElement(e);
|
|
122483
|
+
const x = canvasPos[0];
|
|
122484
|
+
const y = canvasPos[1];
|
|
122485
|
+
|
|
122486
|
+
switch (dragAction) {
|
|
122487
|
+
case DRAG_ACTIONS.xTranslate:
|
|
122488
|
+
dragTranslateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
122489
|
+
break;
|
|
122490
|
+
case DRAG_ACTIONS.yTranslate:
|
|
122491
|
+
dragTranslateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
122492
|
+
break;
|
|
122493
|
+
case DRAG_ACTIONS.zTranslate:
|
|
122494
|
+
dragTranslateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
122495
|
+
break;
|
|
122496
|
+
}
|
|
122497
|
+
|
|
122498
|
+
lastCanvasPos[0] = x;
|
|
122499
|
+
lastCanvasPos[1] = y;
|
|
122500
|
+
})
|
|
122501
|
+
);
|
|
122502
|
+
//mouseup
|
|
122503
|
+
canvas.addEventListener(
|
|
122504
|
+
"mouseup",
|
|
122505
|
+
(this._canvasMouseUpListener = (e) => {
|
|
122506
|
+
if (!this._visible) return;
|
|
122507
|
+
this._viewer.cameraControl.pointerEnabled = true;
|
|
122508
|
+
if (!down) {
|
|
122509
|
+
return;
|
|
122510
|
+
}
|
|
122511
|
+
switch (e.which) {
|
|
122512
|
+
}
|
|
122513
|
+
down = false;
|
|
122514
|
+
grabbed = false;
|
|
122515
|
+
})
|
|
122516
|
+
);
|
|
122517
|
+
|
|
122518
|
+
//wheel
|
|
122519
|
+
canvas.addEventListener(
|
|
122520
|
+
"wheel",
|
|
122521
|
+
(this._canvasWheelListener = (e) => {
|
|
122522
|
+
if (!this._visible) {
|
|
122523
|
+
return;
|
|
122524
|
+
}
|
|
122525
|
+
var delta = Math.max(-1, Math.min(1, -e.deltaY * 40));
|
|
122526
|
+
if (delta === 0) {
|
|
122527
|
+
return;
|
|
122528
|
+
}
|
|
122529
|
+
})
|
|
122530
|
+
);
|
|
122531
|
+
|
|
122532
|
+
this._onCameraControlHover = this._viewer.cameraControl.on("touchEntity", (hit) => {
|
|
122533
|
+
if (!this._visible || down || grabbed) return;
|
|
122534
|
+
// if (lastAffordanceMesh) {
|
|
122535
|
+
// lastAffordanceMesh.visible = false;
|
|
122536
|
+
// }
|
|
122537
|
+
var affordanceMesh;
|
|
122538
|
+
const meshId = hit.entity.id;
|
|
122539
|
+
switch (meshId) {
|
|
122540
|
+
case this._displayMeshes.plane.id:
|
|
122541
|
+
affordanceMesh = this._affordanceMeshes.plane;
|
|
122542
|
+
nextDragAction = DRAG_ACTIONS.zTranslate;
|
|
122543
|
+
break;
|
|
122544
|
+
|
|
122545
|
+
default:
|
|
122546
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
122547
|
+
return; // Not clicked an arrow or hoop
|
|
122548
|
+
}
|
|
122549
|
+
if (affordanceMesh) {
|
|
122550
|
+
affordanceMesh.visible = true;
|
|
122551
|
+
}
|
|
122552
|
+
// lastAffordanceMesh = affordanceMesh;
|
|
122553
|
+
grabbed = true;
|
|
122554
|
+
down = true;
|
|
122555
|
+
});
|
|
122556
|
+
//touchstart
|
|
122557
|
+
canvas.addEventListener(
|
|
122558
|
+
"touchstart",
|
|
122559
|
+
(this._canvasMouseDownListener = (e) => {
|
|
122560
|
+
e.preventDefault();
|
|
122561
|
+
if (!this._visible || !grabbed || !down) return;
|
|
122562
|
+
this._viewer.cameraControl.pointerEnabled = false;
|
|
122563
|
+
// if (lastAffordanceMesh) {
|
|
122564
|
+
// lastAffordanceMesh.visible = true;
|
|
122565
|
+
// }
|
|
122566
|
+
var canvasPos = getTouchCoordsWithinElement(e);
|
|
122567
|
+
dragAction = nextDragAction;
|
|
122568
|
+
lastCanvasPos[0] = canvasPos[0];
|
|
122569
|
+
lastCanvasPos[1] = canvasPos[1];
|
|
122570
|
+
})
|
|
122571
|
+
);
|
|
122572
|
+
//touchmove
|
|
122573
|
+
canvas.addEventListener(
|
|
122574
|
+
"touchmove",
|
|
122575
|
+
(this._canvasMouseMoveListener = (e) => {
|
|
122576
|
+
if (!this._visible || !down || !grabbed) return;
|
|
122577
|
+
|
|
122578
|
+
var canvasPos = getTouchCoordsWithinElement(e);
|
|
122579
|
+
const x = canvasPos[0];
|
|
122580
|
+
const y = canvasPos[1];
|
|
122581
|
+
|
|
122582
|
+
switch (dragAction) {
|
|
122583
|
+
case DRAG_ACTIONS.xTranslate:
|
|
122584
|
+
dragTranslateSectionPlane(xBaseAxis, lastCanvasPos, canvasPos);
|
|
122585
|
+
break;
|
|
122586
|
+
case DRAG_ACTIONS.yTranslate:
|
|
122587
|
+
dragTranslateSectionPlane(yBaseAxis, lastCanvasPos, canvasPos);
|
|
122588
|
+
break;
|
|
122589
|
+
case DRAG_ACTIONS.zTranslate:
|
|
122590
|
+
dragTranslateSectionPlane(zBaseAxis, lastCanvasPos, canvasPos);
|
|
122591
|
+
break;
|
|
122592
|
+
}
|
|
122593
|
+
|
|
122594
|
+
lastCanvasPos[0] = x;
|
|
122595
|
+
lastCanvasPos[1] = y;
|
|
122596
|
+
})
|
|
122597
|
+
);
|
|
122598
|
+
//touchend
|
|
122599
|
+
canvas.addEventListener(
|
|
122600
|
+
"touchend",
|
|
122601
|
+
(this._canvasTouchEndListener = (e) => {
|
|
122602
|
+
if (!this._visible) return;
|
|
122603
|
+
if (grabbed) this._viewer.cameraControl.pointerEnabled = true;
|
|
122604
|
+
// if (lastAffordanceMesh) {
|
|
122605
|
+
// lastAffordanceMesh.visible = false;
|
|
122606
|
+
// }
|
|
122607
|
+
// lastAffordanceMesh = null;
|
|
122608
|
+
nextDragAction = DRAG_ACTIONS.none;
|
|
122609
|
+
down = false;
|
|
122610
|
+
grabbed = false;
|
|
122611
|
+
})
|
|
122612
|
+
);
|
|
122613
|
+
canvas.addEventListener("touchcancel", this._canvasTouchEndListener);
|
|
122614
|
+
}
|
|
122615
|
+
}
|
|
122616
|
+
|
|
122617
|
+
_destroy() {
|
|
122618
|
+
this._unbindEvents();
|
|
122619
|
+
this._destroyNodes();
|
|
122620
|
+
}
|
|
122621
|
+
|
|
122622
|
+
_unbindEvents() {
|
|
122623
|
+
const viewer = this._viewer;
|
|
122624
|
+
const scene = viewer.scene;
|
|
122625
|
+
const canvas = scene.canvas.canvas;
|
|
122626
|
+
const camera = viewer.camera;
|
|
122627
|
+
const cameraControl = viewer.cameraControl;
|
|
122628
|
+
|
|
122629
|
+
scene.off(this._onSceneTick);
|
|
122630
|
+
|
|
122631
|
+
canvas.removeEventListener("mousedown", this._canvasMouseDownListener);
|
|
122632
|
+
canvas.removeEventListener("mousemove", this._canvasMouseMoveListener);
|
|
122633
|
+
canvas.removeEventListener("mouseup", this._canvasMouseUpListener);
|
|
122634
|
+
canvas.removeEventListener("wheel", this._canvasWheelListener);
|
|
122635
|
+
canvas.removeEventListener("touchend", this._canvasTouchEndListener);
|
|
122636
|
+
canvas.removeEventListener("touchcancel", this._canvasTouchEndListener);
|
|
122637
|
+
|
|
122638
|
+
camera.off(this._onCameraViewMatrix);
|
|
122639
|
+
camera.off(this._onCameraProjMatrix);
|
|
122640
|
+
|
|
122641
|
+
cameraControl.off(this._onCameraControlHover);
|
|
122642
|
+
cameraControl.off(this._onCameraControlHoverLeave);
|
|
122643
|
+
}
|
|
122644
|
+
|
|
122645
|
+
_destroyNodes() {
|
|
122646
|
+
this._setSectionPlane(null);
|
|
122647
|
+
this._rootNode.destroy();
|
|
122648
|
+
this._displayMeshes = {};
|
|
122649
|
+
this._affordanceMeshes = {};
|
|
122650
|
+
}
|
|
122651
|
+
}
|
|
122652
|
+
|
|
122653
|
+
/**
|
|
122654
|
+
* Renders a 3D plane within an {@link Overview} to indicate its {@link SectionPlane}'s current position and orientation.
|
|
122655
|
+
*
|
|
122656
|
+
* @private
|
|
122657
|
+
*/
|
|
122658
|
+
class Plane$1 {
|
|
122659
|
+
|
|
122660
|
+
/** @private */
|
|
122661
|
+
constructor(overview, overviewScene, sectionPlane) {
|
|
122662
|
+
|
|
122663
|
+
/**
|
|
122664
|
+
* The ID of this SectionPlanesOverviewPlane.
|
|
122665
|
+
*
|
|
122666
|
+
* @type {String}
|
|
122667
|
+
*/
|
|
122668
|
+
this.id = sectionPlane.id;
|
|
122669
|
+
|
|
122670
|
+
/**
|
|
122671
|
+
* The {@link SectionPlane} represented by this SectionPlanesOverviewPlane.
|
|
122672
|
+
*
|
|
122673
|
+
* @type {SectionPlane}
|
|
122674
|
+
*/
|
|
122675
|
+
this._sectionPlane = sectionPlane;
|
|
122676
|
+
|
|
122677
|
+
this._mesh = new Mesh(overviewScene, {
|
|
122678
|
+
id: sectionPlane.id,
|
|
122679
|
+
geometry: new ReadableGeometry(overviewScene, buildBoxGeometry({
|
|
122680
|
+
xSize: .5,
|
|
122681
|
+
ySize: .5,
|
|
122682
|
+
zSize: .001
|
|
122683
|
+
})),
|
|
122684
|
+
material: new PhongMaterial(overviewScene, {
|
|
122685
|
+
emissive: [1, 1, 1],
|
|
122686
|
+
diffuse: [0, 0, 0],
|
|
122687
|
+
backfaces: false
|
|
122688
|
+
}),
|
|
122689
|
+
edgeMaterial: new EdgeMaterial(overviewScene, {
|
|
122690
|
+
edgeColor: [0.0, 0.0, 0.0],
|
|
122691
|
+
edgeAlpha: 1.0,
|
|
122692
|
+
edgeWidth: 1
|
|
122693
|
+
}),
|
|
122694
|
+
highlightMaterial: new EmphasisMaterial(overviewScene, {
|
|
122695
|
+
fill: true,
|
|
122696
|
+
fillColor: [0.5, 1, 0.5],
|
|
122697
|
+
fillAlpha: 0.7,
|
|
122698
|
+
edges: true,
|
|
122699
|
+
edgeColor: [0.0, 0.0, 0.0],
|
|
122700
|
+
edgeAlpha: 1.0,
|
|
122701
|
+
edgeWidth: 1
|
|
122702
|
+
}),
|
|
122703
|
+
selectedMaterial: new EmphasisMaterial(overviewScene, {
|
|
122704
|
+
fill: true,
|
|
122705
|
+
fillColor: [0, 0, 1],
|
|
122706
|
+
fillAlpha: 0.7,
|
|
122707
|
+
edges: true,
|
|
122708
|
+
edgeColor: [1.0, 0.0, 0.0],
|
|
122709
|
+
edgeAlpha: 1.0,
|
|
122710
|
+
edgeWidth: 1
|
|
122711
|
+
}),
|
|
122712
|
+
highlighted: true,
|
|
122713
|
+
scale: [3, 3, 3],
|
|
122714
|
+
position: [0, 0, 0],
|
|
122715
|
+
rotation: [0, 0, 0],
|
|
122716
|
+
opacity: 0.3,
|
|
122717
|
+
edges: true
|
|
122718
|
+
});
|
|
122719
|
+
|
|
122720
|
+
|
|
122721
|
+
{
|
|
122722
|
+
const vec = math.vec3([0, 0, 0]);
|
|
122723
|
+
const pos2 = math.vec3();
|
|
122724
|
+
const zeroVec = math.vec3([0, 0, 1]);
|
|
122725
|
+
const quat = math.vec4(4);
|
|
122726
|
+
const pos3 = math.vec3();
|
|
122727
|
+
|
|
122728
|
+
const update = () => {
|
|
122729
|
+
|
|
122730
|
+
const origin = this._sectionPlane.scene.center;
|
|
122731
|
+
|
|
122732
|
+
const negDir = [-this._sectionPlane.dir[0], -this._sectionPlane.dir[1], -this._sectionPlane.dir[2]];
|
|
122733
|
+
math.subVec3(origin, this._sectionPlane.pos, vec);
|
|
122734
|
+
const dist = -math.dotVec3(negDir, vec);
|
|
122735
|
+
|
|
122736
|
+
math.normalizeVec3(negDir);
|
|
122737
|
+
math.mulVec3Scalar(negDir, dist, pos2);
|
|
122738
|
+
const quaternion = math.vec3PairToQuaternion(zeroVec, this._sectionPlane.dir, quat);
|
|
122739
|
+
|
|
122740
|
+
pos3[0] = pos2[0] * 0.1;
|
|
122741
|
+
pos3[1] = pos2[1] * 0.1;
|
|
122742
|
+
pos3[2] = pos2[2] * 0.1;
|
|
122743
|
+
|
|
122744
|
+
this._mesh.quaternion = quaternion;
|
|
122745
|
+
this._mesh.position = pos3;
|
|
122746
|
+
};
|
|
122747
|
+
|
|
122748
|
+
this._onSectionPlanePos = this._sectionPlane.on("pos", update);
|
|
122749
|
+
this._onSectionPlaneDir = this._sectionPlane.on("dir", update);
|
|
122750
|
+
|
|
122751
|
+
// update();
|
|
122752
|
+
}
|
|
122753
|
+
|
|
122754
|
+
this._highlighted = false;
|
|
122755
|
+
this._selected = false;
|
|
122756
|
+
}
|
|
122757
|
+
|
|
122758
|
+
/**
|
|
122759
|
+
* Sets if this SectionPlanesOverviewPlane is highlighted.
|
|
122760
|
+
*
|
|
122761
|
+
* @type {Boolean}
|
|
122762
|
+
* @private
|
|
122763
|
+
*/
|
|
122764
|
+
setHighlighted(highlighted) {
|
|
122765
|
+
this._highlighted = !!highlighted;
|
|
122766
|
+
this._mesh.highlighted = this._highlighted;
|
|
122767
|
+
this._mesh.highlightMaterial.fillColor = highlighted ? [0, 0.7, 0] : [0, 0, 0];
|
|
122768
|
+
// this._selectedMesh.highlighted = true;
|
|
122769
|
+
}
|
|
122770
|
+
|
|
122771
|
+
/**
|
|
122772
|
+
* Gets if this SectionPlanesOverviewPlane is highlighted.
|
|
122773
|
+
*
|
|
122774
|
+
* @type {Boolean}
|
|
122775
|
+
* @private
|
|
122776
|
+
*/
|
|
122777
|
+
getHighlighted() {
|
|
122778
|
+
return this._highlighted;
|
|
122779
|
+
}
|
|
122780
|
+
|
|
122781
|
+
/**
|
|
122782
|
+
* Sets if this SectionPlanesOverviewPlane is selected.
|
|
122783
|
+
*
|
|
122784
|
+
* @type {Boolean}
|
|
122785
|
+
* @private
|
|
122786
|
+
*/
|
|
122787
|
+
setSelected(selected) {
|
|
122788
|
+
this._selected = !!selected;
|
|
122789
|
+
this._mesh.edgeMaterial.edgeWidth = selected ? 3 : 1;
|
|
122790
|
+
this._mesh.highlightMaterial.edgeWidth = selected ? 3 : 1;
|
|
122791
|
+
|
|
122792
|
+
}
|
|
122793
|
+
|
|
122794
|
+
/**
|
|
122795
|
+
* Gets if this SectionPlanesOverviewPlane is selected.
|
|
122796
|
+
*
|
|
122797
|
+
* @type {Boolean}
|
|
122798
|
+
* @private
|
|
122799
|
+
*/
|
|
122800
|
+
getSelected() {
|
|
122801
|
+
return this._selected;
|
|
122802
|
+
}
|
|
122803
|
+
|
|
122804
|
+
/** @private */
|
|
122805
|
+
destroy() {
|
|
122806
|
+
this._sectionPlane.off(this._onSectionPlanePos);
|
|
122807
|
+
this._sectionPlane.off(this._onSectionPlaneDir);
|
|
122808
|
+
this._mesh.destroy();
|
|
122809
|
+
}
|
|
122810
|
+
}
|
|
122811
|
+
|
|
122812
|
+
/**
|
|
122813
|
+
* @desc An interactive 3D overview for navigating the {@link SectionPlane}s created by its {@link SectionPlanesPlugin}.
|
|
122814
|
+
*
|
|
122815
|
+
* * Located at {@link SectionPlanesPlugin#overview}.
|
|
122816
|
+
* * Renders the overview on a separate canvas at a corner of the {@link Viewer}'s {@link Scene} {@link Canvas}.
|
|
122817
|
+
* * The overview shows a 3D plane object for each {@link SectionPlane} in the {@link Scene}.
|
|
122818
|
+
* * Click a plane object in the overview to toggle the visibility of a 3D gizmo to edit the position and orientation of its {@link SectionPlane}.
|
|
122819
|
+
*
|
|
122820
|
+
* @private
|
|
122821
|
+
*/
|
|
122822
|
+
class Overview$1 {
|
|
122823
|
+
/**
|
|
122824
|
+
* @private
|
|
122825
|
+
*/
|
|
122826
|
+
constructor(plugin, cfg) {
|
|
122827
|
+
if (!cfg.onHoverEnterPlane || !cfg.onHoverLeavePlane || !cfg.onClickedNothing || !cfg.onClickedPlane) {
|
|
122828
|
+
throw "Missing config(s): onHoverEnterPlane, onHoverLeavePlane, onClickedNothing || onClickedPlane";
|
|
122829
|
+
}
|
|
122830
|
+
|
|
122831
|
+
/**
|
|
122832
|
+
* The {@link SectionPlanesPlugin} that owns this SectionPlanesOverview.
|
|
122833
|
+
*
|
|
122834
|
+
* @type {SectionPlanesPlugin}
|
|
122835
|
+
*/
|
|
122836
|
+
this.plugin = plugin;
|
|
122837
|
+
|
|
122838
|
+
this._viewer = plugin.viewer;
|
|
122839
|
+
|
|
122840
|
+
this._onHoverEnterPlane = cfg.onHoverEnterPlane;
|
|
122841
|
+
this._onHoverLeavePlane = cfg.onHoverLeavePlane;
|
|
122842
|
+
this._onClickedNothing = cfg.onClickedNothing;
|
|
122843
|
+
this._onClickedPlane = cfg.onClickedPlane;
|
|
122844
|
+
this._visible = true;
|
|
122845
|
+
|
|
122846
|
+
this._planes = {};
|
|
122847
|
+
|
|
122848
|
+
//--------------------------------------------------------------------------------------------------------------
|
|
122849
|
+
// Init canvas
|
|
122850
|
+
//--------------------------------------------------------------------------------------------------------------
|
|
122851
|
+
|
|
122852
|
+
this._canvas = cfg.overviewCanvas;
|
|
122853
|
+
|
|
122854
|
+
//--------------------------------------------------------------------------------------------------------------
|
|
122855
|
+
// Init scene
|
|
122856
|
+
//--------------------------------------------------------------------------------------------------------------
|
|
122857
|
+
|
|
122858
|
+
this._scene = new Scene(this._viewer, {
|
|
122859
|
+
canvasId: this._canvas.id,
|
|
122860
|
+
transparent: true
|
|
122861
|
+
});
|
|
122862
|
+
this._scene.clearLights();
|
|
122863
|
+
new DirLight(this._scene, {
|
|
122864
|
+
dir: [0.4, -0.4, 0.8],
|
|
122865
|
+
color: [0.8, 1.0, 1.0],
|
|
122866
|
+
intensity: 1.0,
|
|
122867
|
+
space: "view"
|
|
121207
122868
|
});
|
|
121208
122869
|
new DirLight(this._scene, {
|
|
121209
122870
|
dir: [-0.8, -0.3, -0.4],
|
|
@@ -121485,312 +123146,410 @@ const tempVec3$1 = math.vec3();
|
|
|
121485
123146
|
* ````
|
|
121486
123147
|
*/
|
|
121487
123148
|
class SectionPlanesPlugin extends Plugin {
|
|
123149
|
+
/**
|
|
123150
|
+
* @constructor
|
|
123151
|
+
* @param {Viewer} viewer The Viewer.
|
|
123152
|
+
* @param {Object} cfg Plugin configuration.
|
|
123153
|
+
* @param {String} [cfg.id="SectionPlanes"] Optional ID for this plugin, so that we can find it within {@link Viewer#plugins}.
|
|
123154
|
+
* @param {String} [cfg.overviewCanvasId] ID of a canvas element to display the overview.
|
|
123155
|
+
* @param {String} [cfg.overviewVisible=true] Initial visibility of the overview canvas.
|
|
123156
|
+
*/
|
|
123157
|
+
constructor(viewer, cfg = {}) {
|
|
123158
|
+
super("SectionPlanes", viewer);
|
|
121488
123159
|
|
|
121489
|
-
|
|
121490
|
-
|
|
121491
|
-
|
|
121492
|
-
|
|
121493
|
-
|
|
121494
|
-
* @param {String} [cfg.overviewCanvasId] ID of a canvas element to display the overview.
|
|
121495
|
-
* @param {String} [cfg.overviewVisible=true] Initial visibility of the overview canvas.
|
|
121496
|
-
*/
|
|
121497
|
-
constructor(viewer, cfg = {}) {
|
|
121498
|
-
|
|
121499
|
-
super("SectionPlanes", viewer);
|
|
123160
|
+
this._freeControls = [];
|
|
123161
|
+
this._sectionPlanes = viewer.scene.sectionPlanes;
|
|
123162
|
+
this._controls = {};
|
|
123163
|
+
this._currentControl = null;
|
|
123164
|
+
this._shownControlId = null;
|
|
121500
123165
|
|
|
121501
|
-
|
|
121502
|
-
|
|
121503
|
-
this._controls = {};
|
|
121504
|
-
this._shownControlId = null;
|
|
123166
|
+
if (cfg.overviewCanvasId !== null && cfg.overviewCanvasId !== undefined) {
|
|
123167
|
+
const overviewCanvas = document.getElementById(cfg.overviewCanvasId);
|
|
121505
123168
|
|
|
121506
|
-
|
|
123169
|
+
if (!overviewCanvas) {
|
|
123170
|
+
this.warn("Can't find overview canvas: '" + cfg.overviewCanvasId + "' - will create plugin without overview");
|
|
123171
|
+
} else {
|
|
123172
|
+
this._overview = new Overview$1(this, {
|
|
123173
|
+
overviewCanvas: overviewCanvas,
|
|
123174
|
+
visible: cfg.overviewVisible,
|
|
121507
123175
|
|
|
121508
|
-
|
|
123176
|
+
onHoverEnterPlane: (id) => {
|
|
123177
|
+
this._overview.setPlaneHighlighted(id, true);
|
|
123178
|
+
},
|
|
121509
123179
|
|
|
121510
|
-
|
|
121511
|
-
|
|
123180
|
+
onHoverLeavePlane: (id) => {
|
|
123181
|
+
this._overview.setPlaneHighlighted(id, false);
|
|
123182
|
+
},
|
|
121512
123183
|
|
|
121513
|
-
|
|
123184
|
+
onClickedPlane: (id) => {
|
|
123185
|
+
if (this.getShownControl() === id) {
|
|
123186
|
+
this.hideControl();
|
|
123187
|
+
return;
|
|
123188
|
+
}
|
|
123189
|
+
this.showControl(id);
|
|
123190
|
+
const sectionPlane = this.sectionPlanes[id];
|
|
123191
|
+
const sectionPlanePos = sectionPlane.pos;
|
|
123192
|
+
tempAABB$1.set(this.viewer.scene.aabb);
|
|
123193
|
+
math.getAABB3Center(tempAABB$1, tempVec3$1);
|
|
123194
|
+
tempAABB$1[0] += sectionPlanePos[0] - tempVec3$1[0];
|
|
123195
|
+
tempAABB$1[1] += sectionPlanePos[1] - tempVec3$1[1];
|
|
123196
|
+
tempAABB$1[2] += sectionPlanePos[2] - tempVec3$1[2];
|
|
123197
|
+
tempAABB$1[3] += sectionPlanePos[0] - tempVec3$1[0];
|
|
123198
|
+
tempAABB$1[4] += sectionPlanePos[1] - tempVec3$1[1];
|
|
123199
|
+
tempAABB$1[5] += sectionPlanePos[2] - tempVec3$1[2];
|
|
123200
|
+
this.viewer.cameraFlight.flyTo({
|
|
123201
|
+
aabb: tempAABB$1,
|
|
123202
|
+
fitFOV: 65
|
|
123203
|
+
});
|
|
123204
|
+
},
|
|
121514
123205
|
|
|
121515
|
-
|
|
121516
|
-
|
|
121517
|
-
|
|
123206
|
+
onClickedNothing: () => {
|
|
123207
|
+
this.hideControl();
|
|
123208
|
+
}
|
|
123209
|
+
});
|
|
123210
|
+
}
|
|
123211
|
+
}
|
|
121518
123212
|
|
|
121519
|
-
|
|
121520
|
-
|
|
121521
|
-
|
|
123213
|
+
this._onSceneSectionPlaneCreated = viewer.scene.on("sectionPlaneCreated", (sectionPlane) => {
|
|
123214
|
+
// SectionPlane created, either via SectionPlanesPlugin#createSectionPlane(), or by directly
|
|
123215
|
+
// instantiating a SectionPlane independently of SectionPlanesPlugin, which can be done
|
|
123216
|
+
// by BCFViewpointsPlugin#loadViewpoint().
|
|
121522
123217
|
|
|
121523
|
-
|
|
121524
|
-
|
|
121525
|
-
|
|
123218
|
+
this._sectionPlaneCreated(sectionPlane);
|
|
123219
|
+
});
|
|
123220
|
+
}
|
|
121526
123221
|
|
|
121527
|
-
|
|
121528
|
-
|
|
121529
|
-
|
|
121530
|
-
|
|
121531
|
-
|
|
121532
|
-
|
|
121533
|
-
|
|
121534
|
-
|
|
121535
|
-
|
|
121536
|
-
|
|
121537
|
-
tempAABB$1[0] += sectionPlanePos[0] - tempVec3$1[0];
|
|
121538
|
-
tempAABB$1[1] += sectionPlanePos[1] - tempVec3$1[1];
|
|
121539
|
-
tempAABB$1[2] += sectionPlanePos[2] - tempVec3$1[2];
|
|
121540
|
-
tempAABB$1[3] += sectionPlanePos[0] - tempVec3$1[0];
|
|
121541
|
-
tempAABB$1[4] += sectionPlanePos[1] - tempVec3$1[1];
|
|
121542
|
-
tempAABB$1[5] += sectionPlanePos[2] - tempVec3$1[2];
|
|
121543
|
-
this.viewer.cameraFlight.flyTo({
|
|
121544
|
-
aabb: tempAABB$1,
|
|
121545
|
-
fitFOV: 65
|
|
121546
|
-
});
|
|
121547
|
-
}),
|
|
123222
|
+
/**
|
|
123223
|
+
* Sets if the overview canvas is visible.
|
|
123224
|
+
*
|
|
123225
|
+
* @param {Boolean} visible Whether or not the overview canvas is visible.
|
|
123226
|
+
*/
|
|
123227
|
+
setOverviewVisible(visible) {
|
|
123228
|
+
if (this._overview) {
|
|
123229
|
+
this._overview.setVisible(visible);
|
|
123230
|
+
}
|
|
123231
|
+
}
|
|
121548
123232
|
|
|
121549
|
-
|
|
121550
|
-
|
|
121551
|
-
|
|
121552
|
-
|
|
121553
|
-
|
|
121554
|
-
|
|
123233
|
+
/**
|
|
123234
|
+
* Gets if the overview canvas is visible.
|
|
123235
|
+
*
|
|
123236
|
+
* @return {Boolean} True when the overview canvas is visible.
|
|
123237
|
+
*/
|
|
123238
|
+
getOverviewVisible() {
|
|
123239
|
+
if (this._overview) {
|
|
123240
|
+
return this._overview.getVisible();
|
|
123241
|
+
}
|
|
123242
|
+
}
|
|
121555
123243
|
|
|
121556
|
-
|
|
123244
|
+
/**
|
|
123245
|
+
* Returns a map of the {@link SectionPlane}s created by this SectionPlanesPlugin.
|
|
123246
|
+
*
|
|
123247
|
+
* @returns {{String:SectionPlane}} A map containing the {@link SectionPlane}s, each mapped to its {@link SectionPlane#id}.
|
|
123248
|
+
*/
|
|
123249
|
+
get sectionPlanes() {
|
|
123250
|
+
return this._sectionPlanes;
|
|
123251
|
+
}
|
|
121557
123252
|
|
|
121558
|
-
|
|
121559
|
-
|
|
121560
|
-
|
|
123253
|
+
/**
|
|
123254
|
+
* Creates a {@link SectionPlane}.
|
|
123255
|
+
*
|
|
123256
|
+
* The {@link SectionPlane} will be registered by {@link SectionPlane#id} in {@link SectionPlanesPlugin#sectionPlanes}.
|
|
123257
|
+
*
|
|
123258
|
+
* @param {Object} params {@link SectionPlane} configuration.
|
|
123259
|
+
* @param {String} [params.id] Unique ID to assign to the {@link SectionPlane}. Must be unique among all components in the {@link Viewer}'s {@link Scene}. Auto-generated when omitted.
|
|
123260
|
+
* @param {Number[]} [params.pos=[0,0,0]] World-space position of the {@link SectionPlane}.
|
|
123261
|
+
* @param {Number[]} [params.dir=[0,0,-1]] World-space vector indicating the orientation of the {@link SectionPlane}.
|
|
123262
|
+
* @param {Boolean} [params.active=true] Whether the {@link SectionPlane} is initially active. Only clips while this is true.
|
|
123263
|
+
* @returns {SectionPlane} The new {@link SectionPlane}.
|
|
123264
|
+
*/
|
|
123265
|
+
createSectionPlane(params = {}) {
|
|
123266
|
+
if (params.id !== undefined && params.id !== null && this.viewer.scene.components[params.id]) {
|
|
123267
|
+
this.error("Viewer component with this ID already exists: " + params.id);
|
|
123268
|
+
delete params.id;
|
|
123269
|
+
}
|
|
121561
123270
|
|
|
121562
|
-
|
|
121563
|
-
|
|
121564
|
-
}
|
|
123271
|
+
// Note that SectionPlane constructor fires "sectionPlaneCreated" on the Scene,
|
|
123272
|
+
// which SectionPlanesPlugin handles and calls #_sectionPlaneCreated to create gizmo and add to overview canvas.
|
|
121565
123273
|
|
|
121566
|
-
|
|
121567
|
-
|
|
121568
|
-
|
|
121569
|
-
|
|
121570
|
-
|
|
121571
|
-
|
|
121572
|
-
|
|
121573
|
-
|
|
121574
|
-
}
|
|
121575
|
-
}
|
|
123274
|
+
const sectionPlane = new SectionPlane(this.viewer.scene, {
|
|
123275
|
+
id: params.id,
|
|
123276
|
+
pos: params.pos,
|
|
123277
|
+
dir: params.dir,
|
|
123278
|
+
active: true
|
|
123279
|
+
});
|
|
123280
|
+
return sectionPlane;
|
|
123281
|
+
}
|
|
121576
123282
|
|
|
121577
|
-
|
|
121578
|
-
|
|
121579
|
-
|
|
121580
|
-
|
|
121581
|
-
|
|
121582
|
-
|
|
121583
|
-
|
|
121584
|
-
|
|
121585
|
-
|
|
121586
|
-
|
|
123283
|
+
//剖切面创建后,创建一个控制器
|
|
123284
|
+
_sectionPlaneCreated(sectionPlane) {
|
|
123285
|
+
let newControl;
|
|
123286
|
+
switch (this._sectionWay) {
|
|
123287
|
+
case "plane":
|
|
123288
|
+
newControl = new ClippingPlane(this, this._controlsConfig);
|
|
123289
|
+
break;
|
|
123290
|
+
case "box":
|
|
123291
|
+
newControl = new ClippingBox(this, this._controlsConfig);
|
|
123292
|
+
break;
|
|
123293
|
+
default:
|
|
123294
|
+
newControl = new Control(this);
|
|
123295
|
+
break;
|
|
123296
|
+
}
|
|
123297
|
+
const control = this._freeControls.length > 0 ? this._freeControls.pop() : newControl;
|
|
123298
|
+
control._setSectionPlane(sectionPlane);
|
|
123299
|
+
control.setVisible(true);
|
|
123300
|
+
this._currentControl = control;
|
|
123301
|
+
this._controls[sectionPlane.id] = control;
|
|
123302
|
+
if (this._overview) {
|
|
123303
|
+
this._overview.addSectionPlane(sectionPlane);
|
|
123304
|
+
}
|
|
123305
|
+
sectionPlane.once("destroyed", () => {
|
|
123306
|
+
this._sectionPlaneDestroyed(sectionPlane);
|
|
123307
|
+
});
|
|
123308
|
+
}
|
|
121587
123309
|
|
|
121588
|
-
|
|
121589
|
-
|
|
121590
|
-
|
|
121591
|
-
|
|
121592
|
-
|
|
121593
|
-
|
|
121594
|
-
|
|
121595
|
-
|
|
123310
|
+
/**
|
|
123311
|
+
* 设置是否是触屏模式
|
|
123312
|
+
* @param {boolean} touch
|
|
123313
|
+
*/
|
|
123314
|
+
set isTouch(touch) {
|
|
123315
|
+
this._isTouch = touch;
|
|
123316
|
+
if (touch === true) this.sectionWay = "plane";
|
|
123317
|
+
else this.sectionWay = "control";
|
|
123318
|
+
}
|
|
121596
123319
|
|
|
121597
|
-
|
|
121598
|
-
|
|
121599
|
-
|
|
121600
|
-
|
|
121601
|
-
|
|
121602
|
-
|
|
121603
|
-
|
|
121604
|
-
|
|
121605
|
-
|
|
121606
|
-
|
|
121607
|
-
|
|
121608
|
-
|
|
121609
|
-
createSectionPlane(params = {}) {
|
|
123320
|
+
/**
|
|
123321
|
+
* 设置剖切对象样式
|
|
123322
|
+
* @param {any} cfg
|
|
123323
|
+
* @param {number} cfg.planeSize?
|
|
123324
|
+
* @param {number} cfg.controlSize?
|
|
123325
|
+
* @param {number} cfg.planeOpacity?
|
|
123326
|
+
* @param {number[]} cfg.controlFillColor?
|
|
123327
|
+
* @param {number[]} cfg.controlEdgeColor?
|
|
123328
|
+
*/
|
|
123329
|
+
set sectionConfigs(cfg) {
|
|
123330
|
+
this._controlsConfig = cfg;
|
|
123331
|
+
}
|
|
121610
123332
|
|
|
121611
|
-
|
|
121612
|
-
|
|
121613
|
-
|
|
121614
|
-
|
|
123333
|
+
/**
|
|
123334
|
+
* 设置剖切方式
|
|
123335
|
+
* @param {string} way
|
|
123336
|
+
*/
|
|
123337
|
+
set sectionWay(way) {
|
|
123338
|
+
this._sectionWay = way;
|
|
123339
|
+
}
|
|
121615
123340
|
|
|
121616
|
-
|
|
121617
|
-
|
|
123341
|
+
/**
|
|
123342
|
+
* 设置剖切面方向
|
|
123343
|
+
* @param {number} direction
|
|
123344
|
+
*/
|
|
123345
|
+
set sectionDirection(direction) {
|
|
123346
|
+
this.clear();
|
|
123347
|
+
let dir;
|
|
123348
|
+
switch (direction) {
|
|
123349
|
+
case 0:
|
|
123350
|
+
dir = [0, 0, -1];
|
|
123351
|
+
break;
|
|
123352
|
+
case 1:
|
|
123353
|
+
dir = [0, -1, 0];
|
|
123354
|
+
break;
|
|
123355
|
+
case 2:
|
|
123356
|
+
dir = [-1, 0, 0];
|
|
123357
|
+
break;
|
|
123358
|
+
}
|
|
123359
|
+
this.createSectionPlane({
|
|
123360
|
+
pos: this.viewer.camera.look,
|
|
123361
|
+
dir: dir
|
|
123362
|
+
});
|
|
123363
|
+
}
|
|
121618
123364
|
|
|
121619
|
-
|
|
121620
|
-
|
|
121621
|
-
|
|
121622
|
-
|
|
121623
|
-
|
|
121624
|
-
|
|
121625
|
-
|
|
121626
|
-
|
|
123365
|
+
/**
|
|
123366
|
+
* 设置剖切面位置
|
|
123367
|
+
* @param id
|
|
123368
|
+
* @param pos
|
|
123369
|
+
*/
|
|
123370
|
+
setControlPos(posRate) {
|
|
123371
|
+
if (this._currentControl == null) return;
|
|
123372
|
+
// if (this._currentControl.type != "plane") return;
|
|
123373
|
+
this._currentControl.pos = posRate;
|
|
123374
|
+
}
|
|
121627
123375
|
|
|
121628
|
-
|
|
121629
|
-
|
|
121630
|
-
|
|
121631
|
-
|
|
121632
|
-
|
|
121633
|
-
|
|
121634
|
-
|
|
121635
|
-
|
|
121636
|
-
|
|
121637
|
-
|
|
121638
|
-
|
|
121639
|
-
|
|
123376
|
+
/**
|
|
123377
|
+
* Inverts the direction of {@link SectionPlane#dir} on every existing SectionPlane.
|
|
123378
|
+
*
|
|
123379
|
+
* Inverts all SectionPlanes, including those that were not created with SectionPlanesPlugin.
|
|
123380
|
+
*/
|
|
123381
|
+
flipSectionPlanes() {
|
|
123382
|
+
const sectionPlanes = this.viewer.scene.sectionPlanes;
|
|
123383
|
+
for (let id in sectionPlanes) {
|
|
123384
|
+
const sectionPlane = sectionPlanes[id];
|
|
123385
|
+
sectionPlane.flipDir();
|
|
123386
|
+
}
|
|
123387
|
+
}
|
|
121640
123388
|
|
|
121641
|
-
|
|
121642
|
-
|
|
121643
|
-
|
|
121644
|
-
|
|
121645
|
-
|
|
121646
|
-
|
|
121647
|
-
|
|
121648
|
-
|
|
121649
|
-
|
|
121650
|
-
|
|
121651
|
-
|
|
121652
|
-
|
|
123389
|
+
/**
|
|
123390
|
+
* Shows the 3D editing gizmo for a {@link SectionPlane}.
|
|
123391
|
+
*
|
|
123392
|
+
* @param {String} id ID of the {@link SectionPlane}.
|
|
123393
|
+
*/
|
|
123394
|
+
showControl(id) {
|
|
123395
|
+
const control = this._controls[id];
|
|
123396
|
+
if (!control) {
|
|
123397
|
+
this.error("Control not found: " + id);
|
|
123398
|
+
return;
|
|
123399
|
+
}
|
|
123400
|
+
this.hideControl();
|
|
123401
|
+
control.setVisible(true);
|
|
123402
|
+
if (this._overview) {
|
|
123403
|
+
this._overview.setPlaneSelected(id, true);
|
|
123404
|
+
}
|
|
123405
|
+
this._shownControlId = id;
|
|
123406
|
+
}
|
|
121653
123407
|
|
|
121654
|
-
|
|
121655
|
-
|
|
121656
|
-
|
|
121657
|
-
|
|
121658
|
-
|
|
121659
|
-
|
|
121660
|
-
|
|
121661
|
-
|
|
121662
|
-
|
|
121663
|
-
return;
|
|
121664
|
-
}
|
|
121665
|
-
this.hideControl();
|
|
121666
|
-
control.setVisible(true);
|
|
121667
|
-
if (this._overview) {
|
|
121668
|
-
this._overview.setPlaneSelected(id, true);
|
|
121669
|
-
}
|
|
121670
|
-
this._shownControlId = id;
|
|
121671
|
-
}
|
|
123408
|
+
/**
|
|
123409
|
+
* 设置剖切对象的尺寸
|
|
123410
|
+
* @param {*} size
|
|
123411
|
+
*/
|
|
123412
|
+
setControlsSize(size) {
|
|
123413
|
+
for (let id in this._controls) {
|
|
123414
|
+
this._controls[id].controlSize = size;
|
|
123415
|
+
}
|
|
123416
|
+
}
|
|
121672
123417
|
|
|
121673
|
-
|
|
121674
|
-
|
|
121675
|
-
|
|
121676
|
-
|
|
121677
|
-
|
|
121678
|
-
|
|
121679
|
-
|
|
121680
|
-
|
|
121681
|
-
|
|
121682
|
-
|
|
123418
|
+
/**
|
|
123419
|
+
* 设置指定id剖切对象的尺寸
|
|
123420
|
+
* @param {*} id
|
|
123421
|
+
* @param {*} size
|
|
123422
|
+
* @returns
|
|
123423
|
+
*/
|
|
123424
|
+
setControlSizeByID(id, size) {
|
|
123425
|
+
const control = this._controls[id];
|
|
123426
|
+
if (!control) {
|
|
123427
|
+
this.error("Control not found: " + id);
|
|
123428
|
+
return;
|
|
123429
|
+
}
|
|
123430
|
+
this._controls[id].controlSize = size;
|
|
123431
|
+
}
|
|
121683
123432
|
|
|
121684
|
-
|
|
121685
|
-
|
|
121686
|
-
|
|
121687
|
-
|
|
121688
|
-
|
|
121689
|
-
|
|
121690
|
-
|
|
121691
|
-
|
|
121692
|
-
|
|
121693
|
-
|
|
121694
|
-
}
|
|
121695
|
-
}
|
|
121696
|
-
this._shownControlId = null;
|
|
121697
|
-
}
|
|
123433
|
+
/**
|
|
123434
|
+
* Gets the ID of the {@link SectionPlane} that the 3D editing gizmo is shown for.
|
|
123435
|
+
*
|
|
123436
|
+
* Returns ````null```` when the editing gizmo is not shown.
|
|
123437
|
+
*
|
|
123438
|
+
* @returns {String} ID of the the {@link SectionPlane} that the 3D editing gizmo is shown for, if shown, else ````null````.
|
|
123439
|
+
*/
|
|
123440
|
+
getShownControl() {
|
|
123441
|
+
return this._shownControlId;
|
|
123442
|
+
}
|
|
121698
123443
|
|
|
121699
|
-
|
|
121700
|
-
|
|
121701
|
-
|
|
121702
|
-
|
|
121703
|
-
|
|
121704
|
-
|
|
121705
|
-
|
|
121706
|
-
|
|
121707
|
-
|
|
121708
|
-
|
|
121709
|
-
|
|
121710
|
-
|
|
121711
|
-
|
|
123444
|
+
/**
|
|
123445
|
+
* Hides the 3D {@link SectionPlane} editing gizmo if shown.
|
|
123446
|
+
*/
|
|
123447
|
+
hideControl() {
|
|
123448
|
+
for (var id in this._controls) {
|
|
123449
|
+
if (this._controls.hasOwnProperty(id)) {
|
|
123450
|
+
this._controls[id].setVisible(false);
|
|
123451
|
+
if (this._overview) {
|
|
123452
|
+
this._overview.setPlaneSelected(id, false);
|
|
123453
|
+
}
|
|
123454
|
+
}
|
|
123455
|
+
}
|
|
123456
|
+
this._shownControlId = null;
|
|
123457
|
+
}
|
|
121712
123458
|
|
|
121713
|
-
|
|
121714
|
-
|
|
121715
|
-
|
|
121716
|
-
|
|
123459
|
+
/**
|
|
123460
|
+
* Destroys a {@link SectionPlane} created by this SectionPlanesPlugin.
|
|
123461
|
+
*
|
|
123462
|
+
* @param {String} id ID of the {@link SectionPlane}.
|
|
123463
|
+
*/
|
|
123464
|
+
destroySectionPlane(id) {
|
|
123465
|
+
var sectionPlane = this.viewer.scene.sectionPlanes[id];
|
|
123466
|
+
if (!sectionPlane) {
|
|
123467
|
+
this.error("SectionPlane not found: " + id);
|
|
123468
|
+
return;
|
|
123469
|
+
}
|
|
123470
|
+
this._sectionPlaneDestroyed(sectionPlane);
|
|
123471
|
+
sectionPlane.destroy();
|
|
121717
123472
|
|
|
121718
|
-
|
|
121719
|
-
|
|
121720
|
-
|
|
121721
|
-
|
|
121722
|
-
const control = this._controls[sectionPlane.id];
|
|
121723
|
-
if (!control) {
|
|
121724
|
-
return;
|
|
121725
|
-
}
|
|
121726
|
-
control.setVisible(false);
|
|
121727
|
-
control._setSectionPlane(null);
|
|
121728
|
-
delete this._controls[sectionPlane.id];
|
|
121729
|
-
this._freeControls.push(control);
|
|
121730
|
-
}
|
|
123473
|
+
if (id === this._shownControlId) {
|
|
123474
|
+
this._shownControlId = null;
|
|
123475
|
+
}
|
|
123476
|
+
}
|
|
121731
123477
|
|
|
121732
|
-
|
|
121733
|
-
|
|
121734
|
-
|
|
121735
|
-
|
|
121736
|
-
|
|
121737
|
-
|
|
121738
|
-
|
|
121739
|
-
|
|
121740
|
-
|
|
123478
|
+
_sectionPlaneDestroyed(sectionPlane) {
|
|
123479
|
+
if (this._overview) {
|
|
123480
|
+
this._overview.removeSectionPlane(sectionPlane);
|
|
123481
|
+
}
|
|
123482
|
+
const control = this._controls[sectionPlane.id];
|
|
123483
|
+
if (!control) {
|
|
123484
|
+
return;
|
|
123485
|
+
}
|
|
123486
|
+
control.setVisible(false);
|
|
123487
|
+
control._setSectionPlane(null);
|
|
123488
|
+
delete this._controls[sectionPlane.id];
|
|
123489
|
+
this._freeControls.push(control);
|
|
123490
|
+
}
|
|
121741
123491
|
|
|
121742
|
-
|
|
121743
|
-
|
|
121744
|
-
|
|
121745
|
-
|
|
121746
|
-
|
|
123492
|
+
/**
|
|
123493
|
+
* Destroys all {@link SectionPlane}s created by this SectionPlanesPlugin.
|
|
123494
|
+
*/
|
|
123495
|
+
clear() {
|
|
123496
|
+
const ids = Object.keys(this._sectionPlanes);
|
|
123497
|
+
for (var i = 0, len = ids.length; i < len; i++) {
|
|
123498
|
+
this.destroySectionPlane(ids[i]);
|
|
123499
|
+
}
|
|
123500
|
+
}
|
|
121747
123501
|
|
|
121748
|
-
|
|
121749
|
-
|
|
121750
|
-
|
|
121751
|
-
|
|
121752
|
-
|
|
121753
|
-
|
|
121754
|
-
|
|
123502
|
+
/**
|
|
123503
|
+
* @private
|
|
123504
|
+
*/
|
|
123505
|
+
send(name, value) {
|
|
123506
|
+
switch (name) {
|
|
123507
|
+
case "snapshotStarting": // Viewer#getSnapshot() about to take snapshot - hide controls
|
|
123508
|
+
for (let id in this._controls) {
|
|
123509
|
+
if (this._controls.hasOwnProperty(id)) {
|
|
123510
|
+
this._controls[id].setCulled(true);
|
|
123511
|
+
}
|
|
123512
|
+
}
|
|
123513
|
+
break;
|
|
121755
123514
|
|
|
121756
|
-
|
|
121757
|
-
|
|
121758
|
-
|
|
121759
|
-
|
|
121760
|
-
|
|
121761
|
-
|
|
121762
|
-
|
|
123515
|
+
case "snapshotFinished": // Viewer#getSnapshot() finished taking snapshot - show controls again
|
|
123516
|
+
for (let id in this._controls) {
|
|
123517
|
+
if (this._controls.hasOwnProperty(id)) {
|
|
123518
|
+
this._controls[id].setCulled(false);
|
|
123519
|
+
}
|
|
123520
|
+
}
|
|
123521
|
+
break;
|
|
121763
123522
|
|
|
121764
|
-
|
|
121765
|
-
|
|
121766
|
-
|
|
121767
|
-
|
|
121768
|
-
|
|
123523
|
+
case "clearSectionPlanes":
|
|
123524
|
+
this.clear();
|
|
123525
|
+
break;
|
|
123526
|
+
}
|
|
123527
|
+
}
|
|
121769
123528
|
|
|
121770
|
-
|
|
121771
|
-
|
|
121772
|
-
|
|
121773
|
-
|
|
121774
|
-
|
|
121775
|
-
|
|
121776
|
-
|
|
121777
|
-
|
|
121778
|
-
|
|
121779
|
-
|
|
121780
|
-
|
|
121781
|
-
|
|
121782
|
-
|
|
121783
|
-
|
|
121784
|
-
|
|
123529
|
+
/**
|
|
123530
|
+
* Destroys this SectionPlanesPlugin.
|
|
123531
|
+
*
|
|
123532
|
+
* Also destroys each {@link SectionPlane} created by this SectionPlanesPlugin.
|
|
123533
|
+
*
|
|
123534
|
+
* Does not destroy the canvas the SectionPlanesPlugin was configured with.
|
|
123535
|
+
*/
|
|
123536
|
+
destroy() {
|
|
123537
|
+
this.clear();
|
|
123538
|
+
if (this._overview) {
|
|
123539
|
+
this._overview.destroy();
|
|
123540
|
+
}
|
|
123541
|
+
this._destroyFreeControls();
|
|
123542
|
+
super.destroy();
|
|
123543
|
+
}
|
|
121785
123544
|
|
|
121786
|
-
|
|
121787
|
-
|
|
121788
|
-
|
|
121789
|
-
|
|
121790
|
-
|
|
121791
|
-
|
|
121792
|
-
|
|
121793
|
-
|
|
123545
|
+
_destroyFreeControls() {
|
|
123546
|
+
var control = this._freeControls.pop();
|
|
123547
|
+
while (control) {
|
|
123548
|
+
control._destroy();
|
|
123549
|
+
control = this._freeControls.pop();
|
|
123550
|
+
}
|
|
123551
|
+
this.viewer.scene.off(this._onSceneSectionPlaneCreated);
|
|
123552
|
+
}
|
|
121794
123553
|
}
|
|
121795
123554
|
|
|
121796
123555
|
/**
|