@ccpc/canvas 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/index.js +1976 -0
- package/package.json +16 -0
- package/types/canvas/c_canvas.d.ts +82 -0
- package/types/canvas/c_canvas.d.ts.map +1 -0
- package/types/canvas/i_c_canvas.d.ts +4 -0
- package/types/canvas/i_c_canvas.d.ts.map +1 -0
- package/types/canvas/work_plane.d.ts +10 -0
- package/types/canvas/work_plane.d.ts.map +1 -0
- package/types/controller/default_controller.d.ts +26 -0
- package/types/controller/default_controller.d.ts.map +1 -0
- package/types/controller/fn_key.d.ts +15 -0
- package/types/controller/fn_key.d.ts.map +1 -0
- package/types/controller/i_keyboard_controller.d.ts +20 -0
- package/types/controller/i_keyboard_controller.d.ts.map +1 -0
- package/types/controller/i_mouse_controller.d.ts +32 -0
- package/types/controller/i_mouse_controller.d.ts.map +1 -0
- package/types/controller/i_process_event.d.ts +8 -0
- package/types/controller/i_process_event.d.ts.map +1 -0
- package/types/controller/keyboard_interactor.d.ts +16 -0
- package/types/controller/keyboard_interactor.d.ts.map +1 -0
- package/types/controller/mouse_interactor.d.ts +43 -0
- package/types/controller/mouse_interactor.d.ts.map +1 -0
- package/types/index.d.ts +12 -0
- package/types/index.d.ts.map +1 -0
- package/types/render/active_selection_op.d.ts +27 -0
- package/types/render/active_selection_op.d.ts.map +1 -0
- package/types/render/c_renderer.d.ts +76 -0
- package/types/render/c_renderer.d.ts.map +1 -0
- package/types/render/render_hub.d.ts +32 -0
- package/types/render/render_hub.d.ts.map +1 -0
- package/types/toolkit/canvas_config.d.ts +11 -0
- package/types/toolkit/canvas_config.d.ts.map +1 -0
- package/types/toolkit/three_util.d.ts +6 -0
- package/types/toolkit/three_util.d.ts.map +1 -0
- package/types/types/type_define.d.ts +75 -0
- package/types/types/type_define.d.ts.map +1 -0
package/index.js
ADDED
|
@@ -0,0 +1,1976 @@
|
|
|
1
|
+
import { Controls as Ht, Vector3 as d, MOUSE as z, TOUCH as A, Quaternion as lt, Spherical as ct, Vector2 as w, Ray as Gt, Plane as Ft, MathUtils as Et, InstancedBufferGeometry as Vt, Float32BufferAttribute as x, InstancedInterleavedBuffer as tt, InterleavedBufferAttribute as R, WireframeGeometry as Xt, Box3 as it, Sphere as St, ShaderMaterial as Zt, ShaderLib as N, UniformsUtils as Mt, UniformsLib as Y, Mesh as st, Vector4 as k, Line3 as qt, Matrix4 as vt, Group as H, BufferGeometry as G, PointsMaterial as xt, Points as Tt, BufferAttribute as Dt, MeshBasicMaterial as Pt, WebGLRenderer as Qt, SRGBColorSpace as $t, Scene as dt, OrthographicCamera as Jt, Raycaster as ut } from "three";
|
|
2
|
+
import { RenderGroup as te, RenderPoint as Lt, RenderEdge as Ot, RenderMesh as Ct, RenderText as Ut, EN_AnchorX as At, EN_AnchorY as Rt, RenderNodeUtil as ee, IRender as ie, DisplayObjectMgr as pt } from "@ccpc/core";
|
|
3
|
+
import { Vec3 as X, Vec2 as j, Ln3 as se, CONST as zt, Plane as ne, alg as oe } from "@ccpc/math";
|
|
4
|
+
import { Text as jt } from "troika-three-text";
|
|
5
|
+
var y = /* @__PURE__ */ ((n) => (n.MOUSE_DOWN = "mousedown", n.MOUSE_MOVE = "mousemove", n.MOUSE_UP = "mouseup", n.WHEEL = "wheel", n.CONTEXT_MENU = "contextmenu", n.MOUSE_LEAVE = "mouseleave", n.MOUSE_ENTER = "mouseenter", n))(y || {}), P = /* @__PURE__ */ ((n) => (n.KEY_DOWN = "keydown", n.KEY_UP = "keyup", n.KEY_PRESS = "keypress", n))(P || {}), h = /* @__PURE__ */ ((n) => (n.MOUSE_MOVE = "move", n.L_BUTTON_DOWN = "l_down", n.L_BUTTON_UP = "l_up", n.R_BUTTON_DOWN = "r_down", n.R_BUTTON_UP = "r_up", n.M_BUTTON_DOWN = "m_down", n.M_BUTTON_UP = "m_up", n.WHEEL_FORWARD = "wheel+", n.WHEEL_BACKWARD = "wheel-", n.WHEEL_START = "wheel_start", n.WHEEL_END = "wheel_end", n.R_CLICK = "r_clk", n.CLICK = "clk", n.SGL_CLICK = "sgl_clk", n.DBL_CLICK = "db_clk", n.MOUSE_LEAVE = "mouse_leave", n.MOUSE_ENTER = "mouse_enter", n))(h || {}), L = /* @__PURE__ */ ((n) => (n.KEY_DOWN = "down", n.KEY_UP = "up", n.KEY_PRESS = "press", n))(L || {});
|
|
6
|
+
const U = {
|
|
7
|
+
common: {
|
|
8
|
+
/**鼠标从mousedown到mouseup的移动容差: 4px*/
|
|
9
|
+
click_to_tolerance: 4,
|
|
10
|
+
/**两次点击触发dbclick的间隔: 0.3s*/
|
|
11
|
+
dbl_click_interval: 0.3 * 1e3,
|
|
12
|
+
/**背景色*/
|
|
13
|
+
color_background: 0
|
|
14
|
+
}
|
|
15
|
+
}, _t = { type: "change" }, nt = { type: "start" }, kt = { type: "end" }, B = new Gt(), ft = new Ft(), re = Math.cos(70 * Et.DEG2RAD), u = new d(), g = 2 * Math.PI, l = {
|
|
16
|
+
NONE: -1,
|
|
17
|
+
ROTATE: 0,
|
|
18
|
+
DOLLY: 1,
|
|
19
|
+
PAN: 2,
|
|
20
|
+
TOUCH_ROTATE: 3,
|
|
21
|
+
TOUCH_PAN: 4,
|
|
22
|
+
TOUCH_DOLLY_PAN: 5,
|
|
23
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
24
|
+
}, q = 1e-6;
|
|
25
|
+
class ae extends Ht {
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new controls instance.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object3D} object - The object that is managed by the controls.
|
|
30
|
+
* @param {?HTMLElement} domElement - The HTML element used for event listeners.
|
|
31
|
+
*/
|
|
32
|
+
constructor(t, e = null) {
|
|
33
|
+
super(t, e), this.state = l.NONE, this.target = new d(), this.cursor = new d(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: z.ROTATE, MIDDLE: z.DOLLY, RIGHT: z.PAN }, this.touches = { ONE: A.ROTATE, TWO: A.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new d(), this._lastQuaternion = new lt(), this._lastTargetPosition = new d(), this._quat = new lt().setFromUnitVectors(t.up, new d(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new ct(), this._sphericalDelta = new ct(), this._scale = 1, this._panOffset = new d(), this._rotateStart = new w(), this._rotateEnd = new w(), this._rotateDelta = new w(), this._panStart = new w(), this._panEnd = new w(), this._panDelta = new w(), this._dollyStart = new w(), this._dollyEnd = new w(), this._dollyDelta = new w(), this._dollyDirection = new d(), this._mouse = new w(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = le.bind(this), this._onPointerDown = he.bind(this), this._onPointerUp = ce.bind(this), this._onContextMenu = ye.bind(this), this._onMouseWheel = pe.bind(this), this._onKeyDown = _e.bind(this), this._onTouchStart = fe.bind(this), this._onTouchMove = me.bind(this), this._onMouseDown = de.bind(this), this._onMouseMove = ue.bind(this), this._interceptControlDown = ge.bind(this), this._interceptControlUp = we.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
|
|
34
|
+
}
|
|
35
|
+
connect(t) {
|
|
36
|
+
super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerUp), this.domElement.removeEventListener("wheel", this._onMouseWheel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.stopListenToKeyEvents(), this.domElement.getRootNode().removeEventListener("keydown", this._interceptControlDown, { capture: !0 }), this.domElement.style.touchAction = "auto";
|
|
40
|
+
}
|
|
41
|
+
dispose() {
|
|
42
|
+
this.disconnect();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the current vertical rotation, in radians.
|
|
46
|
+
*
|
|
47
|
+
* @return {number} The current vertical rotation, in radians.
|
|
48
|
+
*/
|
|
49
|
+
getPolarAngle() {
|
|
50
|
+
return this._spherical.phi;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the current horizontal rotation, in radians.
|
|
54
|
+
*
|
|
55
|
+
* @return {number} The current horizontal rotation, in radians.
|
|
56
|
+
*/
|
|
57
|
+
getAzimuthalAngle() {
|
|
58
|
+
return this._spherical.theta;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the distance from the camera to the target.
|
|
62
|
+
*
|
|
63
|
+
* @return {number} The distance from the camera to the target.
|
|
64
|
+
*/
|
|
65
|
+
getDistance() {
|
|
66
|
+
return this.object.position.distanceTo(this.target);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Adds key event listeners to the given DOM element.
|
|
70
|
+
* `window` is a recommended argument for using this method.
|
|
71
|
+
*
|
|
72
|
+
* @param {HTMLElement} domElement - The DOM element
|
|
73
|
+
*/
|
|
74
|
+
listenToKeyEvents(t) {
|
|
75
|
+
t.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = t;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Removes the key event listener previously defined with `listenToKeyEvents()`.
|
|
79
|
+
*/
|
|
80
|
+
stopListenToKeyEvents() {
|
|
81
|
+
this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Save the current state of the controls. This can later be recovered with `reset()`.
|
|
85
|
+
*/
|
|
86
|
+
saveState() {
|
|
87
|
+
this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reset the controls to their state from either the last time the `saveState()`
|
|
91
|
+
* was called, or the initial state.
|
|
92
|
+
*/
|
|
93
|
+
reset() {
|
|
94
|
+
this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(_t), this.update(), this.state = l.NONE;
|
|
95
|
+
}
|
|
96
|
+
update(t = null) {
|
|
97
|
+
const e = this.object.position;
|
|
98
|
+
u.copy(e).sub(this.target), u.applyQuaternion(this._quat), this._spherical.setFromVector3(u), this.autoRotate && this.state === l.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
|
|
99
|
+
let s = this.minAzimuthAngle, i = this.maxAzimuthAngle;
|
|
100
|
+
isFinite(s) && isFinite(i) && (s < -Math.PI ? s += g : s > Math.PI && (s -= g), i < -Math.PI ? i += g : i > Math.PI && (i -= g), s <= i ? this._spherical.theta = Math.max(s, Math.min(i, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (s + i) / 2 ? Math.max(s, this._spherical.theta) : Math.min(i, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
|
|
101
|
+
let o = !1;
|
|
102
|
+
if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
|
|
103
|
+
this._spherical.radius = this._clampDistance(this._spherical.radius);
|
|
104
|
+
else {
|
|
105
|
+
const r = this._spherical.radius;
|
|
106
|
+
this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), o = r != this._spherical.radius;
|
|
107
|
+
}
|
|
108
|
+
if (u.setFromSpherical(this._spherical), u.applyQuaternion(this._quatInverse), e.copy(this.target).add(u), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
|
|
109
|
+
let r = null;
|
|
110
|
+
if (this.object.isPerspectiveCamera) {
|
|
111
|
+
const a = u.length();
|
|
112
|
+
r = this._clampDistance(a * this._scale);
|
|
113
|
+
const c = a - r;
|
|
114
|
+
this.object.position.addScaledVector(this._dollyDirection, c), this.object.updateMatrixWorld(), o = !!c;
|
|
115
|
+
} else if (this.object.isOrthographicCamera) {
|
|
116
|
+
const a = new d(this._mouse.x, this._mouse.y, 0);
|
|
117
|
+
a.unproject(this.object);
|
|
118
|
+
const c = this.object.zoom;
|
|
119
|
+
this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), o = c !== this.object.zoom;
|
|
120
|
+
const p = new d(this._mouse.x, this._mouse.y, 0);
|
|
121
|
+
p.unproject(this.object), this.object.position.sub(p).add(a), this.object.updateMatrixWorld(), r = u.length();
|
|
122
|
+
} else
|
|
123
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
|
|
124
|
+
r !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(r).add(this.object.position) : (B.origin.copy(this.object.position), B.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(B.direction)) < re ? this.object.lookAt(this.target) : (ft.setFromNormalAndCoplanarPoint(this.object.up, this.target), B.intersectPlane(ft, this.target))));
|
|
125
|
+
} else if (this.object.isOrthographicCamera) {
|
|
126
|
+
const r = this.object.zoom;
|
|
127
|
+
this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), r !== this.object.zoom && (this.object.updateProjectionMatrix(), o = !0);
|
|
128
|
+
}
|
|
129
|
+
return this._scale = 1, this._performCursorZoom = !1, o || this._lastPosition.distanceToSquared(this.object.position) > q || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > q || this._lastTargetPosition.distanceToSquared(this.target) > q ? (this.dispatchEvent(_t), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
|
|
130
|
+
}
|
|
131
|
+
_getAutoRotationAngle(t) {
|
|
132
|
+
return t !== null ? g / 60 * this.autoRotateSpeed * t : g / 60 / 60 * this.autoRotateSpeed;
|
|
133
|
+
}
|
|
134
|
+
_getZoomScale(t) {
|
|
135
|
+
const e = Math.abs(t * 0.01);
|
|
136
|
+
return Math.pow(0.95, this.zoomSpeed * e);
|
|
137
|
+
}
|
|
138
|
+
_rotateLeft(t) {
|
|
139
|
+
this._sphericalDelta.theta -= t;
|
|
140
|
+
}
|
|
141
|
+
_rotateUp(t) {
|
|
142
|
+
this._sphericalDelta.phi -= t;
|
|
143
|
+
}
|
|
144
|
+
_panLeft(t, e) {
|
|
145
|
+
u.setFromMatrixColumn(e, 0), u.multiplyScalar(-t), this._panOffset.add(u);
|
|
146
|
+
}
|
|
147
|
+
_panUp(t, e) {
|
|
148
|
+
this.screenSpacePanning === !0 ? u.setFromMatrixColumn(e, 1) : (u.setFromMatrixColumn(e, 0), u.crossVectors(this.object.up, u)), u.multiplyScalar(t), this._panOffset.add(u);
|
|
149
|
+
}
|
|
150
|
+
// deltaX and deltaY are in pixels; right and down are positive
|
|
151
|
+
_pan(t, e) {
|
|
152
|
+
const s = this.domElement;
|
|
153
|
+
if (this.object.isPerspectiveCamera) {
|
|
154
|
+
const i = this.object.position;
|
|
155
|
+
u.copy(i).sub(this.target);
|
|
156
|
+
let o = u.length();
|
|
157
|
+
o *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * o / s.clientHeight, this.object.matrix), this._panUp(2 * e * o / s.clientHeight, this.object.matrix);
|
|
158
|
+
} else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / s.clientWidth, this.object.matrix), this._panUp(e * (this.object.top - this.object.bottom) / this.object.zoom / s.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
|
|
159
|
+
}
|
|
160
|
+
_dollyOut(t) {
|
|
161
|
+
this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
|
|
162
|
+
}
|
|
163
|
+
_dollyIn(t) {
|
|
164
|
+
this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
|
|
165
|
+
}
|
|
166
|
+
_updateZoomParameters(t, e) {
|
|
167
|
+
if (!this.zoomToCursor)
|
|
168
|
+
return;
|
|
169
|
+
this._performCursorZoom = !0;
|
|
170
|
+
const s = this.domElement.getBoundingClientRect(), i = t - s.left, o = e - s.top, r = s.width, a = s.height;
|
|
171
|
+
this._mouse.x = i / r * 2 - 1, this._mouse.y = -(o / a) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
|
|
172
|
+
}
|
|
173
|
+
_clampDistance(t) {
|
|
174
|
+
return Math.max(this.minDistance, Math.min(this.maxDistance, t));
|
|
175
|
+
}
|
|
176
|
+
//
|
|
177
|
+
// event callbacks - update the object state
|
|
178
|
+
//
|
|
179
|
+
_handleMouseDownRotate(t) {
|
|
180
|
+
this._rotateStart.set(t.clientX, t.clientY);
|
|
181
|
+
}
|
|
182
|
+
_handleMouseDownDolly(t) {
|
|
183
|
+
this._updateZoomParameters(t.clientX, t.clientX), this._dollyStart.set(t.clientX, t.clientY);
|
|
184
|
+
}
|
|
185
|
+
_handleMouseDownPan(t) {
|
|
186
|
+
this._panStart.set(t.clientX, t.clientY);
|
|
187
|
+
}
|
|
188
|
+
_handleMouseMoveRotate(t) {
|
|
189
|
+
this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
|
|
190
|
+
const e = this.domElement;
|
|
191
|
+
this._rotateLeft(g * this._rotateDelta.x / e.clientHeight), this._rotateUp(g * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
|
|
192
|
+
}
|
|
193
|
+
_handleMouseMoveDolly(t) {
|
|
194
|
+
this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
|
|
195
|
+
}
|
|
196
|
+
_handleMouseMovePan(t) {
|
|
197
|
+
this._panEnd.set(t.clientX, t.clientY), this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd), this.update();
|
|
198
|
+
}
|
|
199
|
+
_handleMouseWheel(t) {
|
|
200
|
+
this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
|
|
201
|
+
}
|
|
202
|
+
_handleKeyDown(t) {
|
|
203
|
+
let e = !1;
|
|
204
|
+
switch (t.code) {
|
|
205
|
+
case this.keys.UP:
|
|
206
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(g * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), e = !0;
|
|
207
|
+
break;
|
|
208
|
+
case this.keys.BOTTOM:
|
|
209
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-g * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), e = !0;
|
|
210
|
+
break;
|
|
211
|
+
case this.keys.LEFT:
|
|
212
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(g * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), e = !0;
|
|
213
|
+
break;
|
|
214
|
+
case this.keys.RIGHT:
|
|
215
|
+
t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-g * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), e = !0;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
e && (t.preventDefault(), this.update());
|
|
219
|
+
}
|
|
220
|
+
_handleTouchStartRotate(t) {
|
|
221
|
+
if (this._pointers.length === 1)
|
|
222
|
+
this._rotateStart.set(t.pageX, t.pageY);
|
|
223
|
+
else {
|
|
224
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), i = 0.5 * (t.pageY + e.y);
|
|
225
|
+
this._rotateStart.set(s, i);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
_handleTouchStartPan(t) {
|
|
229
|
+
if (this._pointers.length === 1)
|
|
230
|
+
this._panStart.set(t.pageX, t.pageY);
|
|
231
|
+
else {
|
|
232
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), i = 0.5 * (t.pageY + e.y);
|
|
233
|
+
this._panStart.set(s, i);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
_handleTouchStartDolly(t) {
|
|
237
|
+
const e = this._getSecondPointerPosition(t), s = t.pageX - e.x, i = t.pageY - e.y, o = Math.sqrt(s * s + i * i);
|
|
238
|
+
this._dollyStart.set(0, o);
|
|
239
|
+
}
|
|
240
|
+
_handleTouchStartDollyPan(t) {
|
|
241
|
+
this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
|
|
242
|
+
}
|
|
243
|
+
_handleTouchStartDollyRotate(t) {
|
|
244
|
+
this.enableZoom && this._handleTouchStartDolly(t), this.enableRotate && this._handleTouchStartRotate(t);
|
|
245
|
+
}
|
|
246
|
+
_handleTouchMoveRotate(t) {
|
|
247
|
+
if (this._pointers.length == 1)
|
|
248
|
+
this._rotateEnd.set(t.pageX, t.pageY);
|
|
249
|
+
else {
|
|
250
|
+
const s = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + s.x), o = 0.5 * (t.pageY + s.y);
|
|
251
|
+
this._rotateEnd.set(i, o);
|
|
252
|
+
}
|
|
253
|
+
this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
|
|
254
|
+
const e = this.domElement;
|
|
255
|
+
this._rotateLeft(g * this._rotateDelta.x / e.clientHeight), this._rotateUp(g * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd);
|
|
256
|
+
}
|
|
257
|
+
_handleTouchMovePan(t) {
|
|
258
|
+
if (this._pointers.length === 1)
|
|
259
|
+
this._panEnd.set(t.pageX, t.pageY);
|
|
260
|
+
else {
|
|
261
|
+
const e = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + e.x), i = 0.5 * (t.pageY + e.y);
|
|
262
|
+
this._panEnd.set(s, i);
|
|
263
|
+
}
|
|
264
|
+
this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
|
|
265
|
+
}
|
|
266
|
+
_handleTouchMoveDolly(t) {
|
|
267
|
+
const e = this._getSecondPointerPosition(t), s = t.pageX - e.x, i = t.pageY - e.y, o = Math.sqrt(s * s + i * i);
|
|
268
|
+
this._dollyEnd.set(0, o), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
|
|
269
|
+
const r = (t.pageX + e.x) * 0.5, a = (t.pageY + e.y) * 0.5;
|
|
270
|
+
this._updateZoomParameters(r, a);
|
|
271
|
+
}
|
|
272
|
+
_handleTouchMoveDollyPan(t) {
|
|
273
|
+
this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
|
|
274
|
+
}
|
|
275
|
+
_handleTouchMoveDollyRotate(t) {
|
|
276
|
+
this.enableZoom && this._handleTouchMoveDolly(t), this.enableRotate && this._handleTouchMoveRotate(t);
|
|
277
|
+
}
|
|
278
|
+
// pointers
|
|
279
|
+
_addPointer(t) {
|
|
280
|
+
this._pointers.push(t.pointerId);
|
|
281
|
+
}
|
|
282
|
+
_removePointer(t) {
|
|
283
|
+
delete this._pointerPositions[t.pointerId];
|
|
284
|
+
for (let e = 0; e < this._pointers.length; e++)
|
|
285
|
+
if (this._pointers[e] == t.pointerId) {
|
|
286
|
+
this._pointers.splice(e, 1);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
_isTrackingPointer(t) {
|
|
291
|
+
for (let e = 0; e < this._pointers.length; e++)
|
|
292
|
+
if (this._pointers[e] == t.pointerId) return !0;
|
|
293
|
+
return !1;
|
|
294
|
+
}
|
|
295
|
+
_trackPointer(t) {
|
|
296
|
+
let e = this._pointerPositions[t.pointerId];
|
|
297
|
+
e === void 0 && (e = new w(), this._pointerPositions[t.pointerId] = e), e.set(t.pageX, t.pageY);
|
|
298
|
+
}
|
|
299
|
+
_getSecondPointerPosition(t) {
|
|
300
|
+
const e = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
|
|
301
|
+
return this._pointerPositions[e];
|
|
302
|
+
}
|
|
303
|
+
//
|
|
304
|
+
_customWheelEvent(t) {
|
|
305
|
+
const e = t.deltaMode, s = {
|
|
306
|
+
clientX: t.clientX,
|
|
307
|
+
clientY: t.clientY,
|
|
308
|
+
deltaY: t.deltaY
|
|
309
|
+
};
|
|
310
|
+
switch (e) {
|
|
311
|
+
case 1:
|
|
312
|
+
s.deltaY *= 16;
|
|
313
|
+
break;
|
|
314
|
+
case 2:
|
|
315
|
+
s.deltaY *= 100;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
return t.ctrlKey && !this._controlActive && (s.deltaY *= 10), s;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function he(n) {
|
|
322
|
+
this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(n.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.domElement.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(n) && (this._addPointer(n), n.pointerType === "touch" ? this._onTouchStart(n) : this._onMouseDown(n)));
|
|
323
|
+
}
|
|
324
|
+
function le(n) {
|
|
325
|
+
this.enabled !== !1 && (n.pointerType === "touch" ? this._onTouchMove(n) : this._onMouseMove(n));
|
|
326
|
+
}
|
|
327
|
+
function ce(n) {
|
|
328
|
+
switch (this._removePointer(n), this._pointers.length) {
|
|
329
|
+
case 0:
|
|
330
|
+
this.domElement.releasePointerCapture(n.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(kt), this.state = l.NONE;
|
|
331
|
+
break;
|
|
332
|
+
case 1:
|
|
333
|
+
const t = this._pointers[0], e = this._pointerPositions[t];
|
|
334
|
+
this._onTouchStart({ pointerId: t, pageX: e.x, pageY: e.y });
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function de(n) {
|
|
339
|
+
let t;
|
|
340
|
+
switch (n.button) {
|
|
341
|
+
case 0:
|
|
342
|
+
t = this.mouseButtons.LEFT;
|
|
343
|
+
break;
|
|
344
|
+
case 1:
|
|
345
|
+
t = this.mouseButtons.MIDDLE;
|
|
346
|
+
break;
|
|
347
|
+
case 2:
|
|
348
|
+
t = this.mouseButtons.RIGHT;
|
|
349
|
+
break;
|
|
350
|
+
default:
|
|
351
|
+
t = -1;
|
|
352
|
+
}
|
|
353
|
+
switch (t) {
|
|
354
|
+
case z.DOLLY:
|
|
355
|
+
if (this.enableZoom === !1) return;
|
|
356
|
+
this._handleMouseDownDolly(n), this.state = l.DOLLY;
|
|
357
|
+
break;
|
|
358
|
+
case z.ROTATE:
|
|
359
|
+
if (n.ctrlKey || n.metaKey || n.shiftKey) {
|
|
360
|
+
if (this.enablePan === !1) return;
|
|
361
|
+
this._handleMouseDownPan(n), this.state = l.PAN;
|
|
362
|
+
} else {
|
|
363
|
+
if (this.enableRotate === !1) return;
|
|
364
|
+
this._handleMouseDownRotate(n), this.state = l.ROTATE;
|
|
365
|
+
}
|
|
366
|
+
break;
|
|
367
|
+
case z.PAN:
|
|
368
|
+
if (n.ctrlKey || n.metaKey || n.shiftKey) {
|
|
369
|
+
if (this.enableRotate === !1) return;
|
|
370
|
+
this._handleMouseDownRotate(n), this.state = l.ROTATE;
|
|
371
|
+
} else {
|
|
372
|
+
if (this.enablePan === !1) return;
|
|
373
|
+
this._handleMouseDownPan(n), this.state = l.PAN;
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
this.state = l.NONE;
|
|
378
|
+
}
|
|
379
|
+
this.state !== l.NONE && this.dispatchEvent(nt);
|
|
380
|
+
}
|
|
381
|
+
function ue(n) {
|
|
382
|
+
switch (this.state) {
|
|
383
|
+
case l.ROTATE:
|
|
384
|
+
if (this.enableRotate === !1) return;
|
|
385
|
+
this._handleMouseMoveRotate(n);
|
|
386
|
+
break;
|
|
387
|
+
case l.DOLLY:
|
|
388
|
+
if (this.enableZoom === !1) return;
|
|
389
|
+
this._handleMouseMoveDolly(n);
|
|
390
|
+
break;
|
|
391
|
+
case l.PAN:
|
|
392
|
+
if (this.enablePan === !1) return;
|
|
393
|
+
this._handleMouseMovePan(n);
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function pe(n) {
|
|
398
|
+
this.enabled === !1 || this.enableZoom === !1 || this.state !== l.NONE || (n.preventDefault(), this.dispatchEvent(nt), this._handleMouseWheel(this._customWheelEvent(n)), this.dispatchEvent(kt));
|
|
399
|
+
}
|
|
400
|
+
function _e(n) {
|
|
401
|
+
this.enabled !== !1 && this._handleKeyDown(n);
|
|
402
|
+
}
|
|
403
|
+
function fe(n) {
|
|
404
|
+
switch (this._trackPointer(n), this._pointers.length) {
|
|
405
|
+
case 1:
|
|
406
|
+
switch (this.touches.ONE) {
|
|
407
|
+
case A.ROTATE:
|
|
408
|
+
if (this.enableRotate === !1) return;
|
|
409
|
+
this._handleTouchStartRotate(n), this.state = l.TOUCH_ROTATE;
|
|
410
|
+
break;
|
|
411
|
+
case A.PAN:
|
|
412
|
+
if (this.enablePan === !1) return;
|
|
413
|
+
this._handleTouchStartPan(n), this.state = l.TOUCH_PAN;
|
|
414
|
+
break;
|
|
415
|
+
default:
|
|
416
|
+
this.state = l.NONE;
|
|
417
|
+
}
|
|
418
|
+
break;
|
|
419
|
+
case 2:
|
|
420
|
+
switch (this.touches.TWO) {
|
|
421
|
+
case A.DOLLY_PAN:
|
|
422
|
+
if (this.enableZoom === !1 && this.enablePan === !1) return;
|
|
423
|
+
this._handleTouchStartDollyPan(n), this.state = l.TOUCH_DOLLY_PAN;
|
|
424
|
+
break;
|
|
425
|
+
case A.DOLLY_ROTATE:
|
|
426
|
+
if (this.enableZoom === !1 && this.enableRotate === !1) return;
|
|
427
|
+
this._handleTouchStartDollyRotate(n), this.state = l.TOUCH_DOLLY_ROTATE;
|
|
428
|
+
break;
|
|
429
|
+
default:
|
|
430
|
+
this.state = l.NONE;
|
|
431
|
+
}
|
|
432
|
+
break;
|
|
433
|
+
default:
|
|
434
|
+
this.state = l.NONE;
|
|
435
|
+
}
|
|
436
|
+
this.state !== l.NONE && this.dispatchEvent(nt);
|
|
437
|
+
}
|
|
438
|
+
function me(n) {
|
|
439
|
+
switch (this._trackPointer(n), this.state) {
|
|
440
|
+
case l.TOUCH_ROTATE:
|
|
441
|
+
if (this.enableRotate === !1) return;
|
|
442
|
+
this._handleTouchMoveRotate(n), this.update();
|
|
443
|
+
break;
|
|
444
|
+
case l.TOUCH_PAN:
|
|
445
|
+
if (this.enablePan === !1) return;
|
|
446
|
+
this._handleTouchMovePan(n), this.update();
|
|
447
|
+
break;
|
|
448
|
+
case l.TOUCH_DOLLY_PAN:
|
|
449
|
+
if (this.enableZoom === !1 && this.enablePan === !1) return;
|
|
450
|
+
this._handleTouchMoveDollyPan(n), this.update();
|
|
451
|
+
break;
|
|
452
|
+
case l.TOUCH_DOLLY_ROTATE:
|
|
453
|
+
if (this.enableZoom === !1 && this.enableRotate === !1) return;
|
|
454
|
+
this._handleTouchMoveDollyRotate(n), this.update();
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
this.state = l.NONE;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function ye(n) {
|
|
461
|
+
this.enabled !== !1 && n.preventDefault();
|
|
462
|
+
}
|
|
463
|
+
function ge(n) {
|
|
464
|
+
n.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
465
|
+
}
|
|
466
|
+
function we(n) {
|
|
467
|
+
n.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
468
|
+
}
|
|
469
|
+
const mt = new it(), K = new d();
|
|
470
|
+
class Bt extends Vt {
|
|
471
|
+
/**
|
|
472
|
+
* Constructs a new line segments geometry.
|
|
473
|
+
*/
|
|
474
|
+
constructor() {
|
|
475
|
+
super(), this.isLineSegmentsGeometry = !0, this.type = "LineSegmentsGeometry";
|
|
476
|
+
const t = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0], e = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2], s = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5];
|
|
477
|
+
this.setIndex(s), this.setAttribute("position", new x(t, 3)), this.setAttribute("uv", new x(e, 2));
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Applies the given 4x4 transformation matrix to the geometry.
|
|
481
|
+
*
|
|
482
|
+
* @param {Matrix4} matrix - The matrix to apply.
|
|
483
|
+
* @return {LineSegmentsGeometry} A reference to this instance.
|
|
484
|
+
*/
|
|
485
|
+
applyMatrix4(t) {
|
|
486
|
+
const e = this.attributes.instanceStart, s = this.attributes.instanceEnd;
|
|
487
|
+
return e !== void 0 && (e.applyMatrix4(t), s.applyMatrix4(t), e.needsUpdate = !0), this.boundingBox !== null && this.computeBoundingBox(), this.boundingSphere !== null && this.computeBoundingSphere(), this;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Sets the given line positions for this geometry. The length must be a multiple of six since
|
|
491
|
+
* each line segment is defined by a start end vertex in the pattern `(xyz xyz)`.
|
|
492
|
+
*
|
|
493
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
494
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
495
|
+
*/
|
|
496
|
+
setPositions(t) {
|
|
497
|
+
let e;
|
|
498
|
+
t instanceof Float32Array ? e = t : Array.isArray(t) && (e = new Float32Array(t));
|
|
499
|
+
const s = new tt(e, 6, 1);
|
|
500
|
+
return this.setAttribute("instanceStart", new R(s, 3, 0)), this.setAttribute("instanceEnd", new R(s, 3, 3)), this.instanceCount = this.attributes.instanceStart.count, this.computeBoundingBox(), this.computeBoundingSphere(), this;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Sets the given line colors for this geometry. The length must be a multiple of six since
|
|
504
|
+
* each line segment is defined by a start end color in the pattern `(rgb rgb)`.
|
|
505
|
+
*
|
|
506
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
507
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
508
|
+
*/
|
|
509
|
+
setColors(t) {
|
|
510
|
+
let e;
|
|
511
|
+
t instanceof Float32Array ? e = t : Array.isArray(t) && (e = new Float32Array(t));
|
|
512
|
+
const s = new tt(e, 6, 1);
|
|
513
|
+
return this.setAttribute("instanceColorStart", new R(s, 3, 0)), this.setAttribute("instanceColorEnd", new R(s, 3, 3)), this;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Setups this line segments geometry from the given wireframe geometry.
|
|
517
|
+
*
|
|
518
|
+
* @param {WireframeGeometry} geometry - The geometry that should be used as a data source for this geometry.
|
|
519
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
520
|
+
*/
|
|
521
|
+
fromWireframeGeometry(t) {
|
|
522
|
+
return this.setPositions(t.attributes.position.array), this;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Setups this line segments geometry from the given edges geometry.
|
|
526
|
+
*
|
|
527
|
+
* @param {EdgesGeometry} geometry - The geometry that should be used as a data source for this geometry.
|
|
528
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
529
|
+
*/
|
|
530
|
+
fromEdgesGeometry(t) {
|
|
531
|
+
return this.setPositions(t.attributes.position.array), this;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Setups this line segments geometry from the given mesh.
|
|
535
|
+
*
|
|
536
|
+
* @param {Mesh} mesh - The mesh geometry that should be used as a data source for this geometry.
|
|
537
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
538
|
+
*/
|
|
539
|
+
fromMesh(t) {
|
|
540
|
+
return this.fromWireframeGeometry(new Xt(t.geometry)), this;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Setups this line segments geometry from the given line segments.
|
|
544
|
+
*
|
|
545
|
+
* @param {LineSegments} lineSegments - The line segments that should be used as a data source for this geometry.
|
|
546
|
+
* Assumes the source geometry is not using indices.
|
|
547
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
548
|
+
*/
|
|
549
|
+
fromLineSegments(t) {
|
|
550
|
+
const e = t.geometry;
|
|
551
|
+
return this.setPositions(e.attributes.position.array), this;
|
|
552
|
+
}
|
|
553
|
+
computeBoundingBox() {
|
|
554
|
+
this.boundingBox === null && (this.boundingBox = new it());
|
|
555
|
+
const t = this.attributes.instanceStart, e = this.attributes.instanceEnd;
|
|
556
|
+
t !== void 0 && e !== void 0 && (this.boundingBox.setFromBufferAttribute(t), mt.setFromBufferAttribute(e), this.boundingBox.union(mt));
|
|
557
|
+
}
|
|
558
|
+
computeBoundingSphere() {
|
|
559
|
+
this.boundingSphere === null && (this.boundingSphere = new St()), this.boundingBox === null && this.computeBoundingBox();
|
|
560
|
+
const t = this.attributes.instanceStart, e = this.attributes.instanceEnd;
|
|
561
|
+
if (t !== void 0 && e !== void 0) {
|
|
562
|
+
const s = this.boundingSphere.center;
|
|
563
|
+
this.boundingBox.getCenter(s);
|
|
564
|
+
let i = 0;
|
|
565
|
+
for (let o = 0, r = t.count; o < r; o++)
|
|
566
|
+
K.fromBufferAttribute(t, o), i = Math.max(i, s.distanceToSquared(K)), K.fromBufferAttribute(e, o), i = Math.max(i, s.distanceToSquared(K));
|
|
567
|
+
this.boundingSphere.radius = Math.sqrt(i), isNaN(this.boundingSphere.radius) && console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.", this);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
toJSON() {
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
Y.line = {
|
|
574
|
+
worldUnits: { value: 1 },
|
|
575
|
+
linewidth: { value: 1 },
|
|
576
|
+
resolution: { value: new w(1, 1) },
|
|
577
|
+
dashOffset: { value: 0 },
|
|
578
|
+
dashScale: { value: 1 },
|
|
579
|
+
dashSize: { value: 1 },
|
|
580
|
+
gapSize: { value: 1 }
|
|
581
|
+
// todo FIX - maybe change to totalSize
|
|
582
|
+
};
|
|
583
|
+
N.line = {
|
|
584
|
+
uniforms: Mt.merge([
|
|
585
|
+
Y.common,
|
|
586
|
+
Y.fog,
|
|
587
|
+
Y.line
|
|
588
|
+
]),
|
|
589
|
+
vertexShader: (
|
|
590
|
+
/* glsl */
|
|
591
|
+
`
|
|
592
|
+
#include <common>
|
|
593
|
+
#include <color_pars_vertex>
|
|
594
|
+
#include <fog_pars_vertex>
|
|
595
|
+
#include <logdepthbuf_pars_vertex>
|
|
596
|
+
#include <clipping_planes_pars_vertex>
|
|
597
|
+
|
|
598
|
+
uniform float linewidth;
|
|
599
|
+
uniform vec2 resolution;
|
|
600
|
+
|
|
601
|
+
attribute vec3 instanceStart;
|
|
602
|
+
attribute vec3 instanceEnd;
|
|
603
|
+
|
|
604
|
+
attribute vec3 instanceColorStart;
|
|
605
|
+
attribute vec3 instanceColorEnd;
|
|
606
|
+
|
|
607
|
+
#ifdef WORLD_UNITS
|
|
608
|
+
|
|
609
|
+
varying vec4 worldPos;
|
|
610
|
+
varying vec3 worldStart;
|
|
611
|
+
varying vec3 worldEnd;
|
|
612
|
+
|
|
613
|
+
#ifdef USE_DASH
|
|
614
|
+
|
|
615
|
+
varying vec2 vUv;
|
|
616
|
+
|
|
617
|
+
#endif
|
|
618
|
+
|
|
619
|
+
#else
|
|
620
|
+
|
|
621
|
+
varying vec2 vUv;
|
|
622
|
+
|
|
623
|
+
#endif
|
|
624
|
+
|
|
625
|
+
#ifdef USE_DASH
|
|
626
|
+
|
|
627
|
+
uniform float dashScale;
|
|
628
|
+
attribute float instanceDistanceStart;
|
|
629
|
+
attribute float instanceDistanceEnd;
|
|
630
|
+
varying float vLineDistance;
|
|
631
|
+
|
|
632
|
+
#endif
|
|
633
|
+
|
|
634
|
+
void trimSegment( const in vec4 start, inout vec4 end ) {
|
|
635
|
+
|
|
636
|
+
// trim end segment so it terminates between the camera plane and the near plane
|
|
637
|
+
|
|
638
|
+
// conservative estimate of the near plane
|
|
639
|
+
float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
|
|
640
|
+
float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
|
|
641
|
+
float nearEstimate = - 0.5 * b / a;
|
|
642
|
+
|
|
643
|
+
float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );
|
|
644
|
+
|
|
645
|
+
end.xyz = mix( start.xyz, end.xyz, alpha );
|
|
646
|
+
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
void main() {
|
|
650
|
+
|
|
651
|
+
#ifdef USE_COLOR
|
|
652
|
+
|
|
653
|
+
vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
|
|
654
|
+
|
|
655
|
+
#endif
|
|
656
|
+
|
|
657
|
+
#ifdef USE_DASH
|
|
658
|
+
|
|
659
|
+
vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
|
|
660
|
+
vUv = uv;
|
|
661
|
+
|
|
662
|
+
#endif
|
|
663
|
+
|
|
664
|
+
float aspect = resolution.x / resolution.y;
|
|
665
|
+
|
|
666
|
+
// camera space
|
|
667
|
+
vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
|
|
668
|
+
vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
|
|
669
|
+
|
|
670
|
+
#ifdef WORLD_UNITS
|
|
671
|
+
|
|
672
|
+
worldStart = start.xyz;
|
|
673
|
+
worldEnd = end.xyz;
|
|
674
|
+
|
|
675
|
+
#else
|
|
676
|
+
|
|
677
|
+
vUv = uv;
|
|
678
|
+
|
|
679
|
+
#endif
|
|
680
|
+
|
|
681
|
+
// special case for perspective projection, and segments that terminate either in, or behind, the camera plane
|
|
682
|
+
// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
|
|
683
|
+
// but we need to perform ndc-space calculations in the shader, so we must address this issue directly
|
|
684
|
+
// perhaps there is a more elegant solution -- WestLangley
|
|
685
|
+
|
|
686
|
+
bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column
|
|
687
|
+
|
|
688
|
+
if ( perspective ) {
|
|
689
|
+
|
|
690
|
+
if ( start.z < 0.0 && end.z >= 0.0 ) {
|
|
691
|
+
|
|
692
|
+
trimSegment( start, end );
|
|
693
|
+
|
|
694
|
+
} else if ( end.z < 0.0 && start.z >= 0.0 ) {
|
|
695
|
+
|
|
696
|
+
trimSegment( end, start );
|
|
697
|
+
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// clip space
|
|
703
|
+
vec4 clipStart = projectionMatrix * start;
|
|
704
|
+
vec4 clipEnd = projectionMatrix * end;
|
|
705
|
+
|
|
706
|
+
// ndc space
|
|
707
|
+
vec3 ndcStart = clipStart.xyz / clipStart.w;
|
|
708
|
+
vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
|
|
709
|
+
|
|
710
|
+
// direction
|
|
711
|
+
vec2 dir = ndcEnd.xy - ndcStart.xy;
|
|
712
|
+
|
|
713
|
+
// account for clip-space aspect ratio
|
|
714
|
+
dir.x *= aspect;
|
|
715
|
+
dir = normalize( dir );
|
|
716
|
+
|
|
717
|
+
#ifdef WORLD_UNITS
|
|
718
|
+
|
|
719
|
+
vec3 worldDir = normalize( end.xyz - start.xyz );
|
|
720
|
+
vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );
|
|
721
|
+
vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );
|
|
722
|
+
vec3 worldFwd = cross( worldDir, worldUp );
|
|
723
|
+
worldPos = position.y < 0.5 ? start: end;
|
|
724
|
+
|
|
725
|
+
// height offset
|
|
726
|
+
float hw = linewidth * 0.5;
|
|
727
|
+
worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;
|
|
728
|
+
|
|
729
|
+
// don't extend the line if we're rendering dashes because we
|
|
730
|
+
// won't be rendering the endcaps
|
|
731
|
+
#ifndef USE_DASH
|
|
732
|
+
|
|
733
|
+
// cap extension
|
|
734
|
+
worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;
|
|
735
|
+
|
|
736
|
+
// add width to the box
|
|
737
|
+
worldPos.xyz += worldFwd * hw;
|
|
738
|
+
|
|
739
|
+
// endcaps
|
|
740
|
+
if ( position.y > 1.0 || position.y < 0.0 ) {
|
|
741
|
+
|
|
742
|
+
worldPos.xyz -= worldFwd * 2.0 * hw;
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
#endif
|
|
747
|
+
|
|
748
|
+
// project the worldpos
|
|
749
|
+
vec4 clip = projectionMatrix * worldPos;
|
|
750
|
+
|
|
751
|
+
// shift the depth of the projected points so the line
|
|
752
|
+
// segments overlap neatly
|
|
753
|
+
vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
|
|
754
|
+
clip.z = clipPose.z * clip.w;
|
|
755
|
+
|
|
756
|
+
#else
|
|
757
|
+
|
|
758
|
+
vec2 offset = vec2( dir.y, - dir.x );
|
|
759
|
+
// undo aspect ratio adjustment
|
|
760
|
+
dir.x /= aspect;
|
|
761
|
+
offset.x /= aspect;
|
|
762
|
+
|
|
763
|
+
// sign flip
|
|
764
|
+
if ( position.x < 0.0 ) offset *= - 1.0;
|
|
765
|
+
|
|
766
|
+
// endcaps
|
|
767
|
+
if ( position.y < 0.0 ) {
|
|
768
|
+
|
|
769
|
+
offset += - dir;
|
|
770
|
+
|
|
771
|
+
} else if ( position.y > 1.0 ) {
|
|
772
|
+
|
|
773
|
+
offset += dir;
|
|
774
|
+
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// adjust for linewidth
|
|
778
|
+
offset *= linewidth;
|
|
779
|
+
|
|
780
|
+
// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
|
|
781
|
+
offset /= resolution.y;
|
|
782
|
+
|
|
783
|
+
// select end
|
|
784
|
+
vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
|
|
785
|
+
|
|
786
|
+
// back to clip space
|
|
787
|
+
offset *= clip.w;
|
|
788
|
+
|
|
789
|
+
clip.xy += offset;
|
|
790
|
+
|
|
791
|
+
#endif
|
|
792
|
+
|
|
793
|
+
gl_Position = clip;
|
|
794
|
+
|
|
795
|
+
vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation
|
|
796
|
+
|
|
797
|
+
#include <logdepthbuf_vertex>
|
|
798
|
+
#include <clipping_planes_vertex>
|
|
799
|
+
#include <fog_vertex>
|
|
800
|
+
|
|
801
|
+
}
|
|
802
|
+
`
|
|
803
|
+
),
|
|
804
|
+
fragmentShader: (
|
|
805
|
+
/* glsl */
|
|
806
|
+
`
|
|
807
|
+
uniform vec3 diffuse;
|
|
808
|
+
uniform float opacity;
|
|
809
|
+
uniform float linewidth;
|
|
810
|
+
|
|
811
|
+
#ifdef USE_DASH
|
|
812
|
+
|
|
813
|
+
uniform float dashOffset;
|
|
814
|
+
uniform float dashSize;
|
|
815
|
+
uniform float gapSize;
|
|
816
|
+
|
|
817
|
+
#endif
|
|
818
|
+
|
|
819
|
+
varying float vLineDistance;
|
|
820
|
+
|
|
821
|
+
#ifdef WORLD_UNITS
|
|
822
|
+
|
|
823
|
+
varying vec4 worldPos;
|
|
824
|
+
varying vec3 worldStart;
|
|
825
|
+
varying vec3 worldEnd;
|
|
826
|
+
|
|
827
|
+
#ifdef USE_DASH
|
|
828
|
+
|
|
829
|
+
varying vec2 vUv;
|
|
830
|
+
|
|
831
|
+
#endif
|
|
832
|
+
|
|
833
|
+
#else
|
|
834
|
+
|
|
835
|
+
varying vec2 vUv;
|
|
836
|
+
|
|
837
|
+
#endif
|
|
838
|
+
|
|
839
|
+
#include <common>
|
|
840
|
+
#include <color_pars_fragment>
|
|
841
|
+
#include <fog_pars_fragment>
|
|
842
|
+
#include <logdepthbuf_pars_fragment>
|
|
843
|
+
#include <clipping_planes_pars_fragment>
|
|
844
|
+
|
|
845
|
+
vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
|
|
846
|
+
|
|
847
|
+
float mua;
|
|
848
|
+
float mub;
|
|
849
|
+
|
|
850
|
+
vec3 p13 = p1 - p3;
|
|
851
|
+
vec3 p43 = p4 - p3;
|
|
852
|
+
|
|
853
|
+
vec3 p21 = p2 - p1;
|
|
854
|
+
|
|
855
|
+
float d1343 = dot( p13, p43 );
|
|
856
|
+
float d4321 = dot( p43, p21 );
|
|
857
|
+
float d1321 = dot( p13, p21 );
|
|
858
|
+
float d4343 = dot( p43, p43 );
|
|
859
|
+
float d2121 = dot( p21, p21 );
|
|
860
|
+
|
|
861
|
+
float denom = d2121 * d4343 - d4321 * d4321;
|
|
862
|
+
|
|
863
|
+
float numer = d1343 * d4321 - d1321 * d4343;
|
|
864
|
+
|
|
865
|
+
mua = numer / denom;
|
|
866
|
+
mua = clamp( mua, 0.0, 1.0 );
|
|
867
|
+
mub = ( d1343 + d4321 * ( mua ) ) / d4343;
|
|
868
|
+
mub = clamp( mub, 0.0, 1.0 );
|
|
869
|
+
|
|
870
|
+
return vec2( mua, mub );
|
|
871
|
+
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
void main() {
|
|
875
|
+
|
|
876
|
+
float alpha = opacity;
|
|
877
|
+
vec4 diffuseColor = vec4( diffuse, alpha );
|
|
878
|
+
|
|
879
|
+
#include <clipping_planes_fragment>
|
|
880
|
+
|
|
881
|
+
#ifdef USE_DASH
|
|
882
|
+
|
|
883
|
+
if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps
|
|
884
|
+
|
|
885
|
+
if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX
|
|
886
|
+
|
|
887
|
+
#endif
|
|
888
|
+
|
|
889
|
+
#ifdef WORLD_UNITS
|
|
890
|
+
|
|
891
|
+
// Find the closest points on the view ray and the line segment
|
|
892
|
+
vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
|
|
893
|
+
vec3 lineDir = worldEnd - worldStart;
|
|
894
|
+
vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
|
|
895
|
+
|
|
896
|
+
vec3 p1 = worldStart + lineDir * params.x;
|
|
897
|
+
vec3 p2 = rayEnd * params.y;
|
|
898
|
+
vec3 delta = p1 - p2;
|
|
899
|
+
float len = length( delta );
|
|
900
|
+
float norm = len / linewidth;
|
|
901
|
+
|
|
902
|
+
#ifndef USE_DASH
|
|
903
|
+
|
|
904
|
+
#ifdef USE_ALPHA_TO_COVERAGE
|
|
905
|
+
|
|
906
|
+
float dnorm = fwidth( norm );
|
|
907
|
+
alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
|
|
908
|
+
|
|
909
|
+
#else
|
|
910
|
+
|
|
911
|
+
if ( norm > 0.5 ) {
|
|
912
|
+
|
|
913
|
+
discard;
|
|
914
|
+
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
#endif
|
|
918
|
+
|
|
919
|
+
#endif
|
|
920
|
+
|
|
921
|
+
#else
|
|
922
|
+
|
|
923
|
+
#ifdef USE_ALPHA_TO_COVERAGE
|
|
924
|
+
|
|
925
|
+
// artifacts appear on some hardware if a derivative is taken within a conditional
|
|
926
|
+
float a = vUv.x;
|
|
927
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
928
|
+
float len2 = a * a + b * b;
|
|
929
|
+
float dlen = fwidth( len2 );
|
|
930
|
+
|
|
931
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
932
|
+
|
|
933
|
+
alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
|
|
934
|
+
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
#else
|
|
938
|
+
|
|
939
|
+
if ( abs( vUv.y ) > 1.0 ) {
|
|
940
|
+
|
|
941
|
+
float a = vUv.x;
|
|
942
|
+
float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
|
|
943
|
+
float len2 = a * a + b * b;
|
|
944
|
+
|
|
945
|
+
if ( len2 > 1.0 ) discard;
|
|
946
|
+
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
#endif
|
|
950
|
+
|
|
951
|
+
#endif
|
|
952
|
+
|
|
953
|
+
#include <logdepthbuf_fragment>
|
|
954
|
+
#include <color_fragment>
|
|
955
|
+
|
|
956
|
+
gl_FragColor = vec4( diffuseColor.rgb, alpha );
|
|
957
|
+
|
|
958
|
+
#include <tonemapping_fragment>
|
|
959
|
+
#include <colorspace_fragment>
|
|
960
|
+
#include <fog_fragment>
|
|
961
|
+
#include <premultiplied_alpha_fragment>
|
|
962
|
+
|
|
963
|
+
}
|
|
964
|
+
`
|
|
965
|
+
)
|
|
966
|
+
};
|
|
967
|
+
class Z extends Zt {
|
|
968
|
+
/**
|
|
969
|
+
* Constructs a new line segments geometry.
|
|
970
|
+
*
|
|
971
|
+
* @param {Object} [parameters] - An object with one or more properties
|
|
972
|
+
* defining the material's appearance. Any property of the material
|
|
973
|
+
* (including any property from inherited materials) can be passed
|
|
974
|
+
* in here. Color values can be passed any type of value accepted
|
|
975
|
+
* by {@link Color#set}.
|
|
976
|
+
*/
|
|
977
|
+
constructor(t) {
|
|
978
|
+
super({
|
|
979
|
+
type: "LineMaterial",
|
|
980
|
+
uniforms: Mt.clone(N.line.uniforms),
|
|
981
|
+
vertexShader: N.line.vertexShader,
|
|
982
|
+
fragmentShader: N.line.fragmentShader,
|
|
983
|
+
clipping: !0
|
|
984
|
+
// required for clipping support
|
|
985
|
+
}), this.isLineMaterial = !0, this.setValues(t);
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* The material's color.
|
|
989
|
+
*
|
|
990
|
+
* @type {Color}
|
|
991
|
+
* @default (1,1,1)
|
|
992
|
+
*/
|
|
993
|
+
get color() {
|
|
994
|
+
return this.uniforms.diffuse.value;
|
|
995
|
+
}
|
|
996
|
+
set color(t) {
|
|
997
|
+
this.uniforms.diffuse.value = t;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Whether the material's sizes (width, dash gaps) are in world units.
|
|
1001
|
+
*
|
|
1002
|
+
* @type {boolean}
|
|
1003
|
+
* @default false
|
|
1004
|
+
*/
|
|
1005
|
+
get worldUnits() {
|
|
1006
|
+
return "WORLD_UNITS" in this.defines;
|
|
1007
|
+
}
|
|
1008
|
+
set worldUnits(t) {
|
|
1009
|
+
t === !0 ? this.defines.WORLD_UNITS = "" : delete this.defines.WORLD_UNITS;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Controls line thickness in CSS pixel units when `worldUnits` is `false` (default),
|
|
1013
|
+
* or in world units when `worldUnits` is `true`.
|
|
1014
|
+
*
|
|
1015
|
+
* @type {number}
|
|
1016
|
+
* @default 1
|
|
1017
|
+
*/
|
|
1018
|
+
get linewidth() {
|
|
1019
|
+
return this.uniforms.linewidth.value;
|
|
1020
|
+
}
|
|
1021
|
+
set linewidth(t) {
|
|
1022
|
+
this.uniforms.linewidth && (this.uniforms.linewidth.value = t);
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Whether the line is dashed, or solid.
|
|
1026
|
+
*
|
|
1027
|
+
* @type {boolean}
|
|
1028
|
+
* @default false
|
|
1029
|
+
*/
|
|
1030
|
+
get dashed() {
|
|
1031
|
+
return "USE_DASH" in this.defines;
|
|
1032
|
+
}
|
|
1033
|
+
set dashed(t) {
|
|
1034
|
+
t === !0 !== this.dashed && (this.needsUpdate = !0), t === !0 ? this.defines.USE_DASH = "" : delete this.defines.USE_DASH;
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* The scale of the dashes and gaps.
|
|
1038
|
+
*
|
|
1039
|
+
* @type {number}
|
|
1040
|
+
* @default 1
|
|
1041
|
+
*/
|
|
1042
|
+
get dashScale() {
|
|
1043
|
+
return this.uniforms.dashScale.value;
|
|
1044
|
+
}
|
|
1045
|
+
set dashScale(t) {
|
|
1046
|
+
this.uniforms.dashScale.value = t;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* The size of the dash.
|
|
1050
|
+
*
|
|
1051
|
+
* @type {number}
|
|
1052
|
+
* @default 1
|
|
1053
|
+
*/
|
|
1054
|
+
get dashSize() {
|
|
1055
|
+
return this.uniforms.dashSize.value;
|
|
1056
|
+
}
|
|
1057
|
+
set dashSize(t) {
|
|
1058
|
+
this.uniforms.dashSize.value = t;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Where in the dash cycle the dash starts.
|
|
1062
|
+
*
|
|
1063
|
+
* @type {number}
|
|
1064
|
+
* @default 0
|
|
1065
|
+
*/
|
|
1066
|
+
get dashOffset() {
|
|
1067
|
+
return this.uniforms.dashOffset.value;
|
|
1068
|
+
}
|
|
1069
|
+
set dashOffset(t) {
|
|
1070
|
+
this.uniforms.dashOffset.value = t;
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* The size of the gap.
|
|
1074
|
+
*
|
|
1075
|
+
* @type {number}
|
|
1076
|
+
* @default 0
|
|
1077
|
+
*/
|
|
1078
|
+
get gapSize() {
|
|
1079
|
+
return this.uniforms.gapSize.value;
|
|
1080
|
+
}
|
|
1081
|
+
set gapSize(t) {
|
|
1082
|
+
this.uniforms.gapSize.value = t;
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* The opacity.
|
|
1086
|
+
*
|
|
1087
|
+
* @type {number}
|
|
1088
|
+
* @default 1
|
|
1089
|
+
*/
|
|
1090
|
+
get opacity() {
|
|
1091
|
+
return this.uniforms.opacity.value;
|
|
1092
|
+
}
|
|
1093
|
+
set opacity(t) {
|
|
1094
|
+
this.uniforms && (this.uniforms.opacity.value = t);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* The size of the viewport, in screen pixels. This must be kept updated to make
|
|
1098
|
+
* screen-space rendering accurate.The `LineSegments2.onBeforeRender` callback
|
|
1099
|
+
* performs the update for visible objects.
|
|
1100
|
+
*
|
|
1101
|
+
* @type {Vector2}
|
|
1102
|
+
*/
|
|
1103
|
+
get resolution() {
|
|
1104
|
+
return this.uniforms.resolution.value;
|
|
1105
|
+
}
|
|
1106
|
+
set resolution(t) {
|
|
1107
|
+
this.uniforms.resolution.value.copy(t);
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Whether to use alphaToCoverage or not. When enabled, this can improve the
|
|
1111
|
+
* anti-aliasing of line edges when using MSAA.
|
|
1112
|
+
*
|
|
1113
|
+
* @type {boolean}
|
|
1114
|
+
*/
|
|
1115
|
+
get alphaToCoverage() {
|
|
1116
|
+
return "USE_ALPHA_TO_COVERAGE" in this.defines;
|
|
1117
|
+
}
|
|
1118
|
+
set alphaToCoverage(t) {
|
|
1119
|
+
this.defines && (t === !0 !== this.alphaToCoverage && (this.needsUpdate = !0), t === !0 ? this.defines.USE_ALPHA_TO_COVERAGE = "" : delete this.defines.USE_ALPHA_TO_COVERAGE);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
const Q = new k(), yt = new d(), gt = new d(), _ = new k(), f = new k(), S = new k(), $ = new d(), J = new vt(), m = new qt(), wt = new d(), W = new it(), I = new St(), M = new k();
|
|
1123
|
+
let v, O;
|
|
1124
|
+
function bt(n, t, e) {
|
|
1125
|
+
return M.set(0, 0, -t, 1).applyMatrix4(n.projectionMatrix), M.multiplyScalar(1 / M.w), M.x = O / e.width, M.y = O / e.height, M.applyMatrix4(n.projectionMatrixInverse), M.multiplyScalar(1 / M.w), Math.abs(Math.max(M.x, M.y));
|
|
1126
|
+
}
|
|
1127
|
+
function be(n, t) {
|
|
1128
|
+
const e = n.matrixWorld, s = n.geometry, i = s.attributes.instanceStart, o = s.attributes.instanceEnd, r = Math.min(s.instanceCount, i.count);
|
|
1129
|
+
for (let a = 0, c = r; a < c; a++) {
|
|
1130
|
+
m.start.fromBufferAttribute(i, a), m.end.fromBufferAttribute(o, a), m.applyMatrix4(e);
|
|
1131
|
+
const p = new d(), E = new d();
|
|
1132
|
+
v.distanceSqToSegment(m.start, m.end, E, p), E.distanceTo(p) < O * 0.5 && t.push({
|
|
1133
|
+
point: E,
|
|
1134
|
+
pointOnLine: p,
|
|
1135
|
+
distance: v.origin.distanceTo(E),
|
|
1136
|
+
object: n,
|
|
1137
|
+
face: null,
|
|
1138
|
+
faceIndex: a,
|
|
1139
|
+
uv: null,
|
|
1140
|
+
uv1: null
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function Ee(n, t, e) {
|
|
1145
|
+
const s = t.projectionMatrix, o = n.material.resolution, r = n.matrixWorld, a = n.geometry, c = a.attributes.instanceStart, p = a.attributes.instanceEnd, E = Math.min(a.instanceCount, c.count), b = -t.near;
|
|
1146
|
+
v.at(1, S), S.w = 1, S.applyMatrix4(t.matrixWorldInverse), S.applyMatrix4(s), S.multiplyScalar(1 / S.w), S.x *= o.x / 2, S.y *= o.y / 2, S.z = 0, $.copy(S), J.multiplyMatrices(t.matrixWorldInverse, r);
|
|
1147
|
+
for (let T = 0, It = E; T < It; T++) {
|
|
1148
|
+
if (_.fromBufferAttribute(c, T), f.fromBufferAttribute(p, T), _.w = 1, f.w = 1, _.applyMatrix4(J), f.applyMatrix4(J), _.z > b && f.z > b)
|
|
1149
|
+
continue;
|
|
1150
|
+
if (_.z > b) {
|
|
1151
|
+
const C = _.z - f.z, D = (_.z - b) / C;
|
|
1152
|
+
_.lerp(f, D);
|
|
1153
|
+
} else if (f.z > b) {
|
|
1154
|
+
const C = f.z - _.z, D = (f.z - b) / C;
|
|
1155
|
+
f.lerp(_, D);
|
|
1156
|
+
}
|
|
1157
|
+
_.applyMatrix4(s), f.applyMatrix4(s), _.multiplyScalar(1 / _.w), f.multiplyScalar(1 / f.w), _.x *= o.x / 2, _.y *= o.y / 2, f.x *= o.x / 2, f.y *= o.y / 2, m.start.copy(_), m.start.z = 0, m.end.copy(f), m.end.z = 0;
|
|
1158
|
+
const at = m.closestPointToPointParameter($, !0);
|
|
1159
|
+
m.at(at, wt);
|
|
1160
|
+
const ht = Et.lerp(_.z, f.z, at), Nt = ht >= -1 && ht <= 1, Yt = $.distanceTo(wt) < O * 0.5;
|
|
1161
|
+
if (Nt && Yt) {
|
|
1162
|
+
m.start.fromBufferAttribute(c, T), m.end.fromBufferAttribute(p, T), m.start.applyMatrix4(r), m.end.applyMatrix4(r);
|
|
1163
|
+
const C = new d(), D = new d();
|
|
1164
|
+
v.distanceSqToSegment(m.start, m.end, D, C), e.push({
|
|
1165
|
+
point: D,
|
|
1166
|
+
pointOnLine: C,
|
|
1167
|
+
distance: v.origin.distanceTo(D),
|
|
1168
|
+
object: n,
|
|
1169
|
+
face: null,
|
|
1170
|
+
faceIndex: T,
|
|
1171
|
+
uv: null,
|
|
1172
|
+
uv1: null
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
class Se extends st {
|
|
1178
|
+
/**
|
|
1179
|
+
* Constructs a new wide line.
|
|
1180
|
+
*
|
|
1181
|
+
* @param {LineSegmentsGeometry} [geometry] - The line geometry.
|
|
1182
|
+
* @param {LineMaterial} [material] - The line material.
|
|
1183
|
+
*/
|
|
1184
|
+
constructor(t = new Bt(), e = new Z({ color: Math.random() * 16777215 })) {
|
|
1185
|
+
super(t, e), this.isLineSegments2 = !0, this.type = "LineSegments2";
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Computes an array of distance values which are necessary for rendering dashed lines.
|
|
1189
|
+
* For each vertex in the geometry, the method calculates the cumulative length from the
|
|
1190
|
+
* current point to the very beginning of the line.
|
|
1191
|
+
*
|
|
1192
|
+
* @return {LineSegments2} A reference to this instance.
|
|
1193
|
+
*/
|
|
1194
|
+
computeLineDistances() {
|
|
1195
|
+
const t = this.geometry, e = t.attributes.instanceStart, s = t.attributes.instanceEnd, i = new Float32Array(2 * e.count);
|
|
1196
|
+
for (let r = 0, a = 0, c = e.count; r < c; r++, a += 2)
|
|
1197
|
+
yt.fromBufferAttribute(e, r), gt.fromBufferAttribute(s, r), i[a] = a === 0 ? 0 : i[a - 1], i[a + 1] = i[a] + yt.distanceTo(gt);
|
|
1198
|
+
const o = new tt(i, 2, 1);
|
|
1199
|
+
return t.setAttribute("instanceDistanceStart", new R(o, 1, 0)), t.setAttribute("instanceDistanceEnd", new R(o, 1, 1)), this;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Computes intersection points between a casted ray and this instance.
|
|
1203
|
+
*
|
|
1204
|
+
* @param {Raycaster} raycaster - The raycaster.
|
|
1205
|
+
* @param {Array<Object>} intersects - The target array that holds the intersection points.
|
|
1206
|
+
*/
|
|
1207
|
+
raycast(t, e) {
|
|
1208
|
+
const s = this.material.worldUnits, i = t.camera;
|
|
1209
|
+
i === null && !s && console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');
|
|
1210
|
+
const o = t.params.Line2 !== void 0 && t.params.Line2.threshold || 0;
|
|
1211
|
+
v = t.ray;
|
|
1212
|
+
const r = this.matrixWorld, a = this.geometry, c = this.material;
|
|
1213
|
+
O = c.linewidth + o, a.boundingSphere === null && a.computeBoundingSphere(), I.copy(a.boundingSphere).applyMatrix4(r);
|
|
1214
|
+
let p;
|
|
1215
|
+
if (s)
|
|
1216
|
+
p = O * 0.5;
|
|
1217
|
+
else {
|
|
1218
|
+
const b = Math.max(i.near, I.distanceToPoint(v.origin));
|
|
1219
|
+
p = bt(i, b, c.resolution);
|
|
1220
|
+
}
|
|
1221
|
+
if (I.radius += p, v.intersectsSphere(I) === !1)
|
|
1222
|
+
return;
|
|
1223
|
+
a.boundingBox === null && a.computeBoundingBox(), W.copy(a.boundingBox).applyMatrix4(r);
|
|
1224
|
+
let E;
|
|
1225
|
+
if (s)
|
|
1226
|
+
E = O * 0.5;
|
|
1227
|
+
else {
|
|
1228
|
+
const b = Math.max(i.near, W.distanceToPoint(v.origin));
|
|
1229
|
+
E = bt(i, b, c.resolution);
|
|
1230
|
+
}
|
|
1231
|
+
W.expandByScalar(E), v.intersectsBox(W) !== !1 && (s ? be(this, e) : Ee(this, i, e));
|
|
1232
|
+
}
|
|
1233
|
+
onBeforeRender(t) {
|
|
1234
|
+
const e = this.material.uniforms;
|
|
1235
|
+
e && e.resolution && (t.getViewport(Q), this.material.uniforms.resolution.value.set(Q.z, Q.w));
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
class ot extends Bt {
|
|
1239
|
+
/**
|
|
1240
|
+
* Constructs a new line geometry.
|
|
1241
|
+
*/
|
|
1242
|
+
constructor() {
|
|
1243
|
+
super(), this.isLineGeometry = !0, this.type = "LineGeometry";
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Sets the given line positions for this geometry.
|
|
1247
|
+
*
|
|
1248
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
1249
|
+
* @return {LineGeometry} A reference to this geometry.
|
|
1250
|
+
*/
|
|
1251
|
+
setPositions(t) {
|
|
1252
|
+
const e = t.length - 3, s = new Float32Array(2 * e);
|
|
1253
|
+
for (let i = 0; i < e; i += 3)
|
|
1254
|
+
s[2 * i] = t[i], s[2 * i + 1] = t[i + 1], s[2 * i + 2] = t[i + 2], s[2 * i + 3] = t[i + 3], s[2 * i + 4] = t[i + 4], s[2 * i + 5] = t[i + 5];
|
|
1255
|
+
return super.setPositions(s), this;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Sets the given line colors for this geometry.
|
|
1259
|
+
*
|
|
1260
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
1261
|
+
* @return {LineGeometry} A reference to this geometry.
|
|
1262
|
+
*/
|
|
1263
|
+
setColors(t) {
|
|
1264
|
+
const e = t.length - 3, s = new Float32Array(2 * e);
|
|
1265
|
+
for (let i = 0; i < e; i += 3)
|
|
1266
|
+
s[2 * i] = t[i], s[2 * i + 1] = t[i + 1], s[2 * i + 2] = t[i + 2], s[2 * i + 3] = t[i + 3], s[2 * i + 4] = t[i + 4], s[2 * i + 5] = t[i + 5];
|
|
1267
|
+
return super.setColors(s), this;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Setups this line segments geometry from the given sequence of points.
|
|
1271
|
+
*
|
|
1272
|
+
* @param {Array<Vector3|Vector2>} points - An array of points in 2D or 3D space.
|
|
1273
|
+
* @return {LineGeometry} A reference to this geometry.
|
|
1274
|
+
*/
|
|
1275
|
+
setFromPoints(t) {
|
|
1276
|
+
const e = t.length - 1, s = new Float32Array(6 * e);
|
|
1277
|
+
for (let i = 0; i < e; i++)
|
|
1278
|
+
s[6 * i] = t[i].x, s[6 * i + 1] = t[i].y, s[6 * i + 2] = t[i].z || 0, s[6 * i + 3] = t[i + 1].x, s[6 * i + 4] = t[i + 1].y, s[6 * i + 5] = t[i + 1].z || 0;
|
|
1279
|
+
return super.setPositions(s), this;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Setups this line segments geometry from the given line.
|
|
1283
|
+
*
|
|
1284
|
+
* @param {Line} line - The line that should be used as a data source for this geometry.
|
|
1285
|
+
* @return {LineGeometry} A reference to this geometry.
|
|
1286
|
+
*/
|
|
1287
|
+
fromLine(t) {
|
|
1288
|
+
const e = t.geometry;
|
|
1289
|
+
return this.setPositions(e.attributes.position.array), this;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
class Kt extends Se {
|
|
1293
|
+
/**
|
|
1294
|
+
* Constructs a new wide line.
|
|
1295
|
+
*
|
|
1296
|
+
* @param {LineGeometry} [geometry] - The line geometry.
|
|
1297
|
+
* @param {LineMaterial} [material] - The line material.
|
|
1298
|
+
*/
|
|
1299
|
+
constructor(t = new ot(), e = new Z({ color: Math.random() * 16777215 })) {
|
|
1300
|
+
super(t, e), this.isLine2 = !0, this.type = "Line2";
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
class F {
|
|
1304
|
+
static mathMatrix4toThreeMatrix4(t) {
|
|
1305
|
+
const [e, s, i, o] = t.data;
|
|
1306
|
+
return new vt().set(
|
|
1307
|
+
e[0],
|
|
1308
|
+
s[0],
|
|
1309
|
+
i[0],
|
|
1310
|
+
o[0],
|
|
1311
|
+
e[1],
|
|
1312
|
+
s[1],
|
|
1313
|
+
i[1],
|
|
1314
|
+
o[1],
|
|
1315
|
+
e[2],
|
|
1316
|
+
s[2],
|
|
1317
|
+
i[2],
|
|
1318
|
+
o[2],
|
|
1319
|
+
e[3],
|
|
1320
|
+
s[3],
|
|
1321
|
+
i[3],
|
|
1322
|
+
o[3]
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
class Me {
|
|
1327
|
+
constructor() {
|
|
1328
|
+
this._objectGNodeMap = /* @__PURE__ */ new WeakMap();
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* 添加GRep
|
|
1332
|
+
*/
|
|
1333
|
+
addGrep(t) {
|
|
1334
|
+
const e = t.toRenderNode(), s = this._flatLeafRNodes(e), i = new H();
|
|
1335
|
+
for (const o of s) {
|
|
1336
|
+
const r = this._buildLeafObject3d(o);
|
|
1337
|
+
r && (i.add(r), this._objectGNodeMap.set(r, o.gnode));
|
|
1338
|
+
}
|
|
1339
|
+
return i;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* 移除GRep
|
|
1343
|
+
*/
|
|
1344
|
+
removeGRep(t) {
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* 根据渲染对象查GNode
|
|
1348
|
+
*/
|
|
1349
|
+
getGNodesByObject3d(t) {
|
|
1350
|
+
let e = t;
|
|
1351
|
+
for (; e; ) {
|
|
1352
|
+
const s = this._objectGNodeMap.get(e);
|
|
1353
|
+
if (s) return s;
|
|
1354
|
+
e = e.parent;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* 叶子节点拍平
|
|
1359
|
+
*/
|
|
1360
|
+
_flatLeafRNodes(t) {
|
|
1361
|
+
const e = [];
|
|
1362
|
+
return t instanceof te ? (t.children.forEach((s) => {
|
|
1363
|
+
e.push(...this._flatLeafRNodes(s));
|
|
1364
|
+
}), e) : (e.push(t), e);
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* 根据叶子 RenderNode 构建对应的 three Object3D
|
|
1368
|
+
*/
|
|
1369
|
+
// TODO 拆成两步, 单独创建几何和材质
|
|
1370
|
+
_buildLeafObject3d(t) {
|
|
1371
|
+
if (t instanceof Lt) {
|
|
1372
|
+
const e = new X(t.point);
|
|
1373
|
+
t.globalMatrix && e.transform(t.globalMatrix);
|
|
1374
|
+
const s = new G();
|
|
1375
|
+
s.setAttribute("position", new x([e.x, e.y, e.z], 3));
|
|
1376
|
+
const i = t.style.point, o = new xt({
|
|
1377
|
+
color: i?.color ?? 16777215,
|
|
1378
|
+
size: i?.size ?? 8,
|
|
1379
|
+
sizeAttenuation: !1,
|
|
1380
|
+
opacity: i?.opacity ?? 1
|
|
1381
|
+
});
|
|
1382
|
+
return o.opacity < 1 && (o.transparent = !0), new Tt(s, o);
|
|
1383
|
+
}
|
|
1384
|
+
if (t instanceof Ot) {
|
|
1385
|
+
const e = [];
|
|
1386
|
+
for (const r of t.points) {
|
|
1387
|
+
const a = r.clone();
|
|
1388
|
+
t.globalMatrix && a.transform(t.globalMatrix), e.push(a.x, a.y, a.z);
|
|
1389
|
+
}
|
|
1390
|
+
const s = new ot();
|
|
1391
|
+
s.setPositions(e);
|
|
1392
|
+
const i = t.style.line, o = new Z({
|
|
1393
|
+
color: i?.color ?? 16777215,
|
|
1394
|
+
linewidth: i?.width ?? 2,
|
|
1395
|
+
opacity: i?.opacity ?? 1
|
|
1396
|
+
});
|
|
1397
|
+
return o.opacity < 1 && (o.transparent = !0), new Kt(s, o);
|
|
1398
|
+
}
|
|
1399
|
+
if (t instanceof Ct) {
|
|
1400
|
+
const e = new G(), s = t.getVerts(), i = t.getIndices(), o = t.getNormals();
|
|
1401
|
+
e.setAttribute("position", new x(s, 3)), e.setAttribute("normal", new x(o, 3)), e.setIndex(new Dt(i, 1));
|
|
1402
|
+
const r = t.globalMatrix;
|
|
1403
|
+
r && e.applyMatrix4(F.mathMatrix4toThreeMatrix4(r));
|
|
1404
|
+
const a = t.style.face, c = new Pt({
|
|
1405
|
+
color: a?.color ?? 16777215,
|
|
1406
|
+
opacity: a?.opacity ?? 1
|
|
1407
|
+
});
|
|
1408
|
+
return c.opacity < 1 && (c.transparent = !0), new st(e, c);
|
|
1409
|
+
}
|
|
1410
|
+
if (t instanceof Ut) {
|
|
1411
|
+
const e = new jt();
|
|
1412
|
+
e.position.set(t.position.x, t.position.y, t.position.z), e.text = t.text;
|
|
1413
|
+
const s = t.style.text;
|
|
1414
|
+
return e.fontSize = s?.fontSize ?? 16, e.color = s?.color ?? 16777215, e.anchorX = s?.anchorX ?? At.Center, e.anchorY = s?.anchorY ?? Rt.Middle, t.globalMatrix && e.applyMatrix4(F.mathMatrix4toThreeMatrix4(t.globalMatrix)), e.sync(), e;
|
|
1415
|
+
}
|
|
1416
|
+
return null;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
class ve {
|
|
1420
|
+
constructor(t) {
|
|
1421
|
+
this._activeGroup = new H(), this._selectionGroup = new H(), t.add(this._activeGroup), t.add(this._selectionGroup);
|
|
1422
|
+
}
|
|
1423
|
+
clearActive() {
|
|
1424
|
+
this._clearGroup(this._activeGroup);
|
|
1425
|
+
}
|
|
1426
|
+
clearSelection() {
|
|
1427
|
+
this._clearGroup(this._selectionGroup);
|
|
1428
|
+
}
|
|
1429
|
+
drawActives(t) {
|
|
1430
|
+
this.clearActive(), t.forEach((e) => {
|
|
1431
|
+
const s = this._buildOverlayGroup(e);
|
|
1432
|
+
s.children.length && this._activeGroup.add(s);
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
drawSelections(t) {
|
|
1436
|
+
this.clearSelection(), t.forEach((e) => {
|
|
1437
|
+
const s = this._buildOverlayGroup(e);
|
|
1438
|
+
s.children.length && this._selectionGroup.add(s);
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* GRep转为可渲染Group
|
|
1443
|
+
*/
|
|
1444
|
+
_buildOverlayGroup(t) {
|
|
1445
|
+
const e = new H(), s = t.toRenderNode();
|
|
1446
|
+
return ee.flatLeafRNodes(s).forEach((o) => {
|
|
1447
|
+
const r = this._buildLeafObject(o);
|
|
1448
|
+
r && e.add(r);
|
|
1449
|
+
}), e;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* 根据RenderNode构建渲染对象
|
|
1453
|
+
*/
|
|
1454
|
+
_buildLeafObject(t) {
|
|
1455
|
+
if (t instanceof Lt) {
|
|
1456
|
+
const e = new X(t.point);
|
|
1457
|
+
t.globalMatrix && e.transform(t.globalMatrix);
|
|
1458
|
+
const s = new G();
|
|
1459
|
+
s.setAttribute("position", new x([e.x, e.y, e.z], 3));
|
|
1460
|
+
const i = t.style.point, o = new xt({
|
|
1461
|
+
color: i?.color ?? 16777215,
|
|
1462
|
+
size: i?.size ?? 8,
|
|
1463
|
+
sizeAttenuation: !1,
|
|
1464
|
+
opacity: i?.opacity ?? 1
|
|
1465
|
+
});
|
|
1466
|
+
return o.opacity < 1 && (o.transparent = !0), new Tt(s, o);
|
|
1467
|
+
}
|
|
1468
|
+
if (t instanceof Ot) {
|
|
1469
|
+
const e = [];
|
|
1470
|
+
for (const r of t.points) {
|
|
1471
|
+
const a = r.clone();
|
|
1472
|
+
t.globalMatrix && a.transform(t.globalMatrix), e.push(a.x, a.y, a.z);
|
|
1473
|
+
}
|
|
1474
|
+
const s = new ot();
|
|
1475
|
+
s.setPositions(e);
|
|
1476
|
+
const i = t.style.line, o = new Z({
|
|
1477
|
+
color: i?.color ?? 16777215,
|
|
1478
|
+
linewidth: i?.width ?? 2,
|
|
1479
|
+
opacity: i?.opacity ?? 1
|
|
1480
|
+
});
|
|
1481
|
+
return o.opacity < 1 && (o.transparent = !0), new Kt(s, o);
|
|
1482
|
+
}
|
|
1483
|
+
if (t instanceof Ct) {
|
|
1484
|
+
const e = new G();
|
|
1485
|
+
e.setAttribute("position", new x(t.getVerts(), 3)), e.setAttribute("normal", new x(t.getNormals(), 3)), e.setIndex(new Dt(t.getIndices(), 1)), t.globalMatrix && e.applyMatrix4(F.mathMatrix4toThreeMatrix4(t.globalMatrix));
|
|
1486
|
+
const s = t.style.face, i = new Pt({
|
|
1487
|
+
color: s?.color ?? 16777215,
|
|
1488
|
+
opacity: s?.opacity ?? 1
|
|
1489
|
+
});
|
|
1490
|
+
return i.opacity < 1 && (i.transparent = !0), new st(e, i);
|
|
1491
|
+
}
|
|
1492
|
+
if (t instanceof Ut) {
|
|
1493
|
+
const e = new jt();
|
|
1494
|
+
e.position.set(t.position.x, t.position.y, t.position.z), e.text = t.text;
|
|
1495
|
+
const s = t.style.text;
|
|
1496
|
+
return e.fontSize = s?.fontSize ?? 16, e.color = s?.color ?? 16777215, e.anchorX = s?.anchorX ?? At.Center, e.anchorY = s?.anchorY ?? Rt.Middle, t.globalMatrix && e.applyMatrix4(F.mathMatrix4toThreeMatrix4(t.globalMatrix)), e.sync(), e;
|
|
1497
|
+
}
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* 清空渲染组
|
|
1502
|
+
*/
|
|
1503
|
+
_clearGroup(t) {
|
|
1504
|
+
for (; t.children.length; )
|
|
1505
|
+
t.children.pop()?.removeFromParent();
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
const V = class V extends ie {
|
|
1509
|
+
constructor(t) {
|
|
1510
|
+
super(), this._didToObject = /* @__PURE__ */ new Map(), this.render = () => {
|
|
1511
|
+
requestAnimationFrame(this.render);
|
|
1512
|
+
const { update: o, remove: r } = pt.instance().onBeforeRender();
|
|
1513
|
+
r.forEach((a) => {
|
|
1514
|
+
this._removeGrepByDisplayId(a);
|
|
1515
|
+
}), o.forEach((a) => {
|
|
1516
|
+
this._updateDisplayByRenderData(a);
|
|
1517
|
+
}), this._cameraControls.update(), this._renderer.clear(), this._renderer.render(this._scene, this._camera), this._renderer.clearDepth(), this._renderer.render(this._activeScene, this._camera);
|
|
1518
|
+
}, this._container = t, this._width = this._container.clientWidth, this._height = this._container.clientHeight, this._renderer = new Qt({
|
|
1519
|
+
antialias: !0
|
|
1520
|
+
}), this._renderer.autoClear = !1, this._renderer.setPixelRatio(window.devicePixelRatio), this._renderer.setClearColor(U.common.color_background), this._renderer.outputColorSpace = $t, this._renderer.setSize(this._width, this._height), this._container.appendChild(this._renderer.domElement), this._resizeObserver = new ResizeObserver(() => {
|
|
1521
|
+
this._onResize();
|
|
1522
|
+
}), this._resizeObserver.observe(this._container), this._scene = new dt(), this._activeScene = new dt();
|
|
1523
|
+
const e = this._width / this._height, s = 500, i = s * e;
|
|
1524
|
+
this._camera = new Jt(-i / 2, i / 2, s / 2, -s / 2, 0.1, 100), this._camera.position.set(0, 0, 20), this._cameraControls = new ae(this._camera, this._renderer.domElement), this._cameraControls.enableRotate = !1, this._cameraControls.enablePan = !0, this._renderHub = new Me(), this._activeSelectionOp = new ve(this._activeScene), this.render();
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* 修改完场景后,调update才会真正刷新
|
|
1528
|
+
*/
|
|
1529
|
+
updateView() {
|
|
1530
|
+
}
|
|
1531
|
+
updateImmediately() {
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* 根据渲染数据更新显示对象
|
|
1535
|
+
*/
|
|
1536
|
+
_updateDisplayByRenderData(t) {
|
|
1537
|
+
const { id: e, gRep: s } = t, i = pt.instance().getDisplay(e);
|
|
1538
|
+
i && s && (this._didToObject.get(i.id) ? (this._removeGrepByDisplayId(e), this._addGrepByDisplay(i, s)) : this._addGrepByDisplay(i, s));
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* 根据显示对象添加GRep
|
|
1542
|
+
*/
|
|
1543
|
+
_addGrepByDisplay(t, e) {
|
|
1544
|
+
const s = t.id, i = this._renderHub.addGrep(e);
|
|
1545
|
+
this._scene.add(i), this._didToObject.set(s, i), i.visible = t.testVisible();
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* 根据显示对象移除GRep
|
|
1549
|
+
*/
|
|
1550
|
+
_removeGrepByDisplayId(t) {
|
|
1551
|
+
const e = this._didToObject.get(t);
|
|
1552
|
+
if (!e) return !1;
|
|
1553
|
+
this._didToObject.delete(t), e.removeFromParent();
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* NDC转屏幕坐标
|
|
1557
|
+
*/
|
|
1558
|
+
NDCToScreen(t, e) {
|
|
1559
|
+
const s = new j();
|
|
1560
|
+
return s.x = this._width * (t + 1) / 2, s.y = this._height * (1 - e) / 2, s;
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* 屏幕坐标转NDC
|
|
1564
|
+
*/
|
|
1565
|
+
screenToNDC(t) {
|
|
1566
|
+
const e = new j();
|
|
1567
|
+
return e.x = t.x / this._width * 2 - 1, e.y = -(t.y / this._height) * 2 + 1, e;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* NDC坐标转世界坐标
|
|
1571
|
+
*/
|
|
1572
|
+
NDCToWorld(t, e) {
|
|
1573
|
+
const i = new d(t, e, 0).unproject(this._camera);
|
|
1574
|
+
return new X(i);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* 世界坐标转NDC坐标
|
|
1578
|
+
*/
|
|
1579
|
+
worldToNDC(t) {
|
|
1580
|
+
const e = new d(t.x, t.y, 0).project(this._camera);
|
|
1581
|
+
return new j(e.x, e.y);
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* 生成相机射线
|
|
1585
|
+
*/
|
|
1586
|
+
generateCameraRay(t) {
|
|
1587
|
+
const e = new ut(), s = this.screenToNDC(t), i = new w(s.x, s.y);
|
|
1588
|
+
e.setFromCamera(i, this._camera);
|
|
1589
|
+
const { ray: o } = e, r = new se(o.origin, o.direction, [0, 1]);
|
|
1590
|
+
return r.extend(zt.MODEL_MAX_LENGTH * 100, !0), r;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* 根据屏幕坐标拾取
|
|
1594
|
+
*/
|
|
1595
|
+
pick(t, e) {
|
|
1596
|
+
const s = new ut(), i = this.screenToNDC(new j(t, e));
|
|
1597
|
+
s.setFromCamera(new w(i.x, i.y), this._camera), s.params.Line2 = { threshold: V.PICK_TOLERANCE };
|
|
1598
|
+
const o = s.intersectObjects(this._scene.children, !0), r = [], a = /* @__PURE__ */ new Set();
|
|
1599
|
+
for (const c of o) {
|
|
1600
|
+
const p = this._renderHub.getGNodesByObject3d(c.object);
|
|
1601
|
+
p && (a.has(p.globalID) || (a.add(p.globalID), r.push(p)));
|
|
1602
|
+
}
|
|
1603
|
+
return r;
|
|
1604
|
+
}
|
|
1605
|
+
clearActive() {
|
|
1606
|
+
this._activeSelectionOp.clearActive();
|
|
1607
|
+
}
|
|
1608
|
+
clearSelection() {
|
|
1609
|
+
this._activeSelectionOp.clearSelection();
|
|
1610
|
+
}
|
|
1611
|
+
drawSelections(t) {
|
|
1612
|
+
this._activeSelectionOp.drawSelections(t);
|
|
1613
|
+
}
|
|
1614
|
+
drawActives(t) {
|
|
1615
|
+
this._activeSelectionOp.drawActives(t);
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* 监听画布大小变化
|
|
1619
|
+
*/
|
|
1620
|
+
// TODO 需要重构
|
|
1621
|
+
_onResize() {
|
|
1622
|
+
this._width = this._container.clientWidth, this._height = this._container.clientHeight, this._renderer.setSize(this._width, this._height);
|
|
1623
|
+
const t = this._width / this._height, e = 1e3, s = e * t;
|
|
1624
|
+
this._camera.left = -s / 2, this._camera.right = s / 2, this._camera.top = e / 2, this._camera.bottom = -e / 2, this._camera.updateProjectionMatrix();
|
|
1625
|
+
}
|
|
1626
|
+
// TODO 补充完整
|
|
1627
|
+
destroy() {
|
|
1628
|
+
this._resizeObserver.disconnect(), this._renderer.dispose(), this._renderer.domElement.remove();
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
V.PICK_TOLERANCE = 16;
|
|
1632
|
+
let et = V;
|
|
1633
|
+
class Wt {
|
|
1634
|
+
constructor(t) {
|
|
1635
|
+
this._ctrlKey = t.ctrlKey, this._altKey = t.altKey, this._shiftKey = t.shiftKey, this._metaKey = t.metaKey;
|
|
1636
|
+
}
|
|
1637
|
+
get ctrlKey() {
|
|
1638
|
+
return this._ctrlKey;
|
|
1639
|
+
}
|
|
1640
|
+
get altKey() {
|
|
1641
|
+
return this._altKey;
|
|
1642
|
+
}
|
|
1643
|
+
get shiftKey() {
|
|
1644
|
+
return this._shiftKey;
|
|
1645
|
+
}
|
|
1646
|
+
get metaKey() {
|
|
1647
|
+
return this._metaKey;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
class xe {
|
|
1651
|
+
constructor(t, e, s) {
|
|
1652
|
+
this._mouseControllers = [], this._mouseDown = !1, this._wheeling = !1, this._onMouseDown = (i) => {
|
|
1653
|
+
const o = this._getScreenPos(i);
|
|
1654
|
+
this._mouseDown = !0;
|
|
1655
|
+
let r = !1;
|
|
1656
|
+
i.button === 0 ? (this._lMouseDownPos = o.clone(), r = this._processMouseEvent(h.L_BUTTON_DOWN, i)) : i.button === 1 ? (this._mMouseDownPos = o.clone(), r = this._processMouseEvent(h.M_BUTTON_DOWN, i)) : i.button === 2 && (this._rMouseDownPos = o.clone(), r = this._processMouseEvent(h.R_BUTTON_DOWN, i)), r && i.stopPropagation();
|
|
1657
|
+
}, this._onMouseMove = (i) => {
|
|
1658
|
+
let o = !1;
|
|
1659
|
+
o = this._processMouseEvent(h.MOUSE_MOVE, i), o && i.stopPropagation();
|
|
1660
|
+
}, this._onMouseUp = (i) => {
|
|
1661
|
+
const o = this._getScreenPos(i);
|
|
1662
|
+
this._mouseDown = !1;
|
|
1663
|
+
let r = !1;
|
|
1664
|
+
i.button === 0 ? (this._lMouseDownPos && this._lMouseDownPos.sqDistanceTo(o) < U.common.click_to_tolerance && this._processMouseEvent(h.CLICK, i), this._dblClickTimeout ? (window.clearTimeout(this._dblClickTimeout), this._lastLMouseUpPos && this._lastLMouseUpPos.sqDistanceTo(o) < U.common.click_to_tolerance ? (delete this._dblClickTimeout, this._processMouseEvent(h.DBL_CLICK, i)) : this._dblClickTimeout = window.setTimeout(() => {
|
|
1665
|
+
delete this._dblClickTimeout, this._processMouseEvent(h.SGL_CLICK, i);
|
|
1666
|
+
}, U.common.dbl_click_interval)) : this._dblClickTimeout = window.setTimeout(() => {
|
|
1667
|
+
delete this._dblClickTimeout, this._processMouseEvent(h.SGL_CLICK, i);
|
|
1668
|
+
}, U.common.dbl_click_interval), this._lastLMouseUpPos = o.clone(), r = this._processMouseEvent(h.L_BUTTON_UP, i), delete this._lMouseDownPos) : i.button === 1 ? (delete this._mMouseDownPos, r = this._processMouseEvent(h.M_BUTTON_UP, i)) : i.button === 2 && (r = this._processMouseEvent(h.R_BUTTON_UP, i), !r && this._rMouseDownPos && this._rMouseDownPos.sqDistanceTo(o) < U.common.click_to_tolerance && (r = this._processMouseEvent(h.R_CLICK, i), delete this._rMouseDownPos)), r && i.stopPropagation();
|
|
1669
|
+
}, this._onMouseWheel = (i) => {
|
|
1670
|
+
const o = () => {
|
|
1671
|
+
this._wheeling === !0 && (this._wheeling = !1, delete this._wheelTimer, this._processMouseEvent(h.WHEEL_END, i));
|
|
1672
|
+
};
|
|
1673
|
+
this._wheelTimer !== void 0 && window.clearTimeout(this._wheelTimer), this._wheeling || (this._wheeling = !0, this._processMouseEvent(h.WHEEL_START, i)), this._wheelTimer = window.setTimeout(o, 500), this._processMouseEvent(
|
|
1674
|
+
i.deltaY < 0 ? h.WHEEL_FORWARD : h.WHEEL_BACKWARD,
|
|
1675
|
+
i
|
|
1676
|
+
) && i.stopPropagation();
|
|
1677
|
+
}, this._onContextMenu = (i) => {
|
|
1678
|
+
i.preventDefault();
|
|
1679
|
+
}, this._onMouseLeave = (i) => {
|
|
1680
|
+
this._processMouseEvent(h.MOUSE_LEAVE, i), delete this._lMouseDownPos;
|
|
1681
|
+
}, this._onMouseEnter = (i) => {
|
|
1682
|
+
this._processMouseEvent(h.MOUSE_ENTER, i);
|
|
1683
|
+
}, this._canvas = t, this._container = e, this._mouseControllers = s;
|
|
1684
|
+
}
|
|
1685
|
+
startListening() {
|
|
1686
|
+
this._container.addEventListener(y.MOUSE_DOWN, this._onMouseDown), this._container.addEventListener(y.MOUSE_MOVE, this._onMouseMove), this._container.addEventListener(y.MOUSE_UP, this._onMouseUp), this._container.addEventListener(y.WHEEL, this._onMouseWheel), this._container.addEventListener(y.CONTEXT_MENU, this._onContextMenu), this._container.addEventListener(y.MOUSE_LEAVE, this._onMouseLeave), this._container.addEventListener(y.MOUSE_ENTER, this._onMouseEnter);
|
|
1687
|
+
}
|
|
1688
|
+
stopListening() {
|
|
1689
|
+
this._container.removeEventListener(y.MOUSE_DOWN, this._onMouseDown), this._container.removeEventListener(y.MOUSE_MOVE, this._onMouseMove), this._container.removeEventListener(y.MOUSE_UP, this._onMouseUp), this._container.removeEventListener(y.WHEEL, this._onMouseWheel), this._container.removeEventListener(y.CONTEXT_MENU, this._onContextMenu), this._container.removeEventListener(y.MOUSE_LEAVE, this._onMouseLeave), this._container.removeEventListener(y.MOUSE_ENTER, this._onMouseEnter);
|
|
1690
|
+
}
|
|
1691
|
+
_processMouseEvent(t, e) {
|
|
1692
|
+
let s = !1;
|
|
1693
|
+
const i = new Wt(e);
|
|
1694
|
+
for (let o = 0; o < this._mouseControllers.length && (s = this._mouseControllers[o].processMouseEvent({
|
|
1695
|
+
type: t,
|
|
1696
|
+
domEvent: e,
|
|
1697
|
+
pos: this._getScreenPos(e),
|
|
1698
|
+
fnKey: i
|
|
1699
|
+
}), !s); o++)
|
|
1700
|
+
;
|
|
1701
|
+
return s;
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* 获取相对于canvas的屏幕坐标
|
|
1705
|
+
*/
|
|
1706
|
+
_getScreenPos(t) {
|
|
1707
|
+
const e = this._container.getBoundingClientRect(), s = t.clientX - e.left, i = t.clientY - e.top;
|
|
1708
|
+
return new j(s, i);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
class rt {
|
|
1712
|
+
constructor(t) {
|
|
1713
|
+
const e = t || ne.XOY();
|
|
1714
|
+
this._plane = e;
|
|
1715
|
+
}
|
|
1716
|
+
get plane() {
|
|
1717
|
+
return this._plane;
|
|
1718
|
+
}
|
|
1719
|
+
set plane(t) {
|
|
1720
|
+
this._plane = t;
|
|
1721
|
+
}
|
|
1722
|
+
clone() {
|
|
1723
|
+
const t = new rt();
|
|
1724
|
+
return t.plane = this._plane.clone(), t;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
class Te {
|
|
1728
|
+
constructor(t) {
|
|
1729
|
+
this._mouseControllers = [], this._onKeyDown = (e) => {
|
|
1730
|
+
this._processKeyboardEvent(L.KEY_DOWN, e);
|
|
1731
|
+
}, this._onKeyUp = (e) => {
|
|
1732
|
+
this._processKeyboardEvent(L.KEY_UP, e);
|
|
1733
|
+
}, this._onKeyPress = (e) => {
|
|
1734
|
+
this._processKeyboardEvent(L.KEY_PRESS, e);
|
|
1735
|
+
}, this._mouseControllers = t;
|
|
1736
|
+
}
|
|
1737
|
+
startListening() {
|
|
1738
|
+
window.addEventListener(P.KEY_DOWN, this._onKeyDown), window.addEventListener(P.KEY_UP, this._onKeyUp), window.addEventListener(P.KEY_DOWN, this._onKeyPress);
|
|
1739
|
+
}
|
|
1740
|
+
stopListening() {
|
|
1741
|
+
window.removeEventListener(P.KEY_DOWN, this._onKeyDown), window.removeEventListener(P.KEY_UP, this._onKeyUp), window.removeEventListener(P.KEY_DOWN, this._onKeyPress);
|
|
1742
|
+
}
|
|
1743
|
+
_processKeyboardEvent(t, e) {
|
|
1744
|
+
let s = !1;
|
|
1745
|
+
const i = new Wt(e);
|
|
1746
|
+
for (let o = 0; o < this._mouseControllers.length && (s = this._mouseControllers[o].processKeyboardEvent({
|
|
1747
|
+
type: t,
|
|
1748
|
+
domEvent: e,
|
|
1749
|
+
fnKey: i
|
|
1750
|
+
}), !s); o++)
|
|
1751
|
+
;
|
|
1752
|
+
return s;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
class Ue {
|
|
1756
|
+
constructor(t, e) {
|
|
1757
|
+
this._container = t, this._mouseInteractor = new xe(this, this._container, e), this._keyboardInteractor = new Te(e), this._renderer = new et(this._container);
|
|
1758
|
+
}
|
|
1759
|
+
get container() {
|
|
1760
|
+
return this._container;
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* 开启事件监听
|
|
1764
|
+
*/
|
|
1765
|
+
startListening() {
|
|
1766
|
+
this._mouseInteractor.startListening(), this._keyboardInteractor.startListening();
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* 停止监听
|
|
1770
|
+
*/
|
|
1771
|
+
stopListening() {
|
|
1772
|
+
this._mouseInteractor.stopListening(), this._keyboardInteractor.stopListening();
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* 给模型层视图绑定渲染器实例
|
|
1776
|
+
*/
|
|
1777
|
+
resetModelView(t) {
|
|
1778
|
+
t.iRender = this._renderer;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* 获取当前工作平面
|
|
1782
|
+
*/
|
|
1783
|
+
getWorkPlane() {
|
|
1784
|
+
return new rt();
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* NDC转屏幕坐标
|
|
1788
|
+
*/
|
|
1789
|
+
NDCToScreen(t, e) {
|
|
1790
|
+
return this._renderer.NDCToScreen(t, e);
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* 屏幕坐标转NDC
|
|
1794
|
+
*/
|
|
1795
|
+
screenToNDC(t) {
|
|
1796
|
+
return this._renderer.screenToNDC(t);
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* 屏幕坐标投影到世界坐标系中的指定平面上
|
|
1800
|
+
* @param screenPos 屏幕坐标
|
|
1801
|
+
* @param plane 世界坐标系下的平面
|
|
1802
|
+
*/
|
|
1803
|
+
screenToWorldPlane(t, e) {
|
|
1804
|
+
const s = this._renderer.generateCameraRay(t);
|
|
1805
|
+
s.extendDouble(zt.MODEL_MAX_LENGTH);
|
|
1806
|
+
const i = oe.X.curveSurface(s, e);
|
|
1807
|
+
return i.length ? i[0] : X.O();
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* 屏幕坐标转当前工作平面下的世界坐标
|
|
1811
|
+
*/
|
|
1812
|
+
screenToWorkPlane(t) {
|
|
1813
|
+
const { plane: e } = this.getWorkPlane();
|
|
1814
|
+
return this.screenToWorldPlane(t, e);
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* 世界坐标转屏幕坐标
|
|
1818
|
+
*/
|
|
1819
|
+
worldToScreen(t) {
|
|
1820
|
+
const e = this._renderer.worldToNDC(t);
|
|
1821
|
+
return this.NDCToScreen(e.x, e.y);
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* 屏幕坐标转换为指定平面下的二维局部坐标
|
|
1825
|
+
* @param screenPos 屏幕坐标
|
|
1826
|
+
* @param plane 目标平面
|
|
1827
|
+
*/
|
|
1828
|
+
screenToPlaneLocal(t, e) {
|
|
1829
|
+
const s = this.screenToWorldPlane(t, e);
|
|
1830
|
+
return e.getUVAt(s);
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* 屏幕坐标转换为当前工作平面下的二维局部坐标
|
|
1834
|
+
* @param screenPos 屏幕坐标
|
|
1835
|
+
*/
|
|
1836
|
+
screenToWorkPlaneLocal(t) {
|
|
1837
|
+
const { plane: e } = this.getWorkPlane();
|
|
1838
|
+
return this.screenToPlaneLocal(t, e);
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* 获取当前工作平面下,1世界单位对应多少像素
|
|
1842
|
+
*/
|
|
1843
|
+
pixelsPerUnit() {
|
|
1844
|
+
const { plane: t } = this.getWorkPlane(), e = t.getPtAt({ x: 0, y: 0 }), s = t.getPtAt({ x: 1, y: 0 }), i = this.worldToScreen(e), o = this.worldToScreen(s);
|
|
1845
|
+
return i.distanceTo(o);
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* 生成相机射线
|
|
1849
|
+
*/
|
|
1850
|
+
generateCameraRay(t) {
|
|
1851
|
+
return this._renderer.generateCameraRay(t);
|
|
1852
|
+
}
|
|
1853
|
+
pick(t, e) {
|
|
1854
|
+
return this._renderer.pick(t, e);
|
|
1855
|
+
}
|
|
1856
|
+
// TODO 补充完整
|
|
1857
|
+
destroy() {
|
|
1858
|
+
this.stopListening();
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
class Ae {
|
|
1862
|
+
processKeyboardEvent(t) {
|
|
1863
|
+
switch (t.type) {
|
|
1864
|
+
case L.KEY_DOWN:
|
|
1865
|
+
return this.onKeyDown(t);
|
|
1866
|
+
case L.KEY_UP:
|
|
1867
|
+
return this.onKeyUp(t);
|
|
1868
|
+
case L.KEY_PRESS:
|
|
1869
|
+
return this.onKeyPress(t);
|
|
1870
|
+
default:
|
|
1871
|
+
return !1;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
processMouseEvent(t) {
|
|
1875
|
+
switch (t.type) {
|
|
1876
|
+
case h.MOUSE_ENTER:
|
|
1877
|
+
return this.onMouseEnter(t);
|
|
1878
|
+
case h.MOUSE_MOVE:
|
|
1879
|
+
return this.onMouseMove(t);
|
|
1880
|
+
case h.MOUSE_LEAVE:
|
|
1881
|
+
return this.onMouseLeave(t);
|
|
1882
|
+
case h.L_BUTTON_DOWN:
|
|
1883
|
+
return this.onLButtonDown(t);
|
|
1884
|
+
case h.L_BUTTON_UP:
|
|
1885
|
+
return this.onLButtonUp(t);
|
|
1886
|
+
case h.R_BUTTON_DOWN:
|
|
1887
|
+
return this.onRButtonDown(t);
|
|
1888
|
+
case h.R_BUTTON_UP:
|
|
1889
|
+
return this.onRButtonUp(t);
|
|
1890
|
+
case h.M_BUTTON_DOWN:
|
|
1891
|
+
return this.onMButtonDown(t);
|
|
1892
|
+
case h.M_BUTTON_UP:
|
|
1893
|
+
return this.onMButtonUp(t);
|
|
1894
|
+
case h.WHEEL_FORWARD:
|
|
1895
|
+
return this.onWheelForward(t);
|
|
1896
|
+
case h.WHEEL_BACKWARD:
|
|
1897
|
+
return this.onWheelBackward(t);
|
|
1898
|
+
case h.CLICK:
|
|
1899
|
+
return this.onClick(t);
|
|
1900
|
+
case h.SGL_CLICK:
|
|
1901
|
+
return this.onSglClick(t);
|
|
1902
|
+
case h.DBL_CLICK:
|
|
1903
|
+
return this.onDblClick(t);
|
|
1904
|
+
case h.R_CLICK:
|
|
1905
|
+
return this.onRClick(t);
|
|
1906
|
+
default:
|
|
1907
|
+
return !1;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
onMouseEnter(t) {
|
|
1911
|
+
return !1;
|
|
1912
|
+
}
|
|
1913
|
+
onMouseMove(t) {
|
|
1914
|
+
return !1;
|
|
1915
|
+
}
|
|
1916
|
+
onLButtonDown(t) {
|
|
1917
|
+
return !1;
|
|
1918
|
+
}
|
|
1919
|
+
onLButtonUp(t) {
|
|
1920
|
+
return !1;
|
|
1921
|
+
}
|
|
1922
|
+
onRClick(t) {
|
|
1923
|
+
return !1;
|
|
1924
|
+
}
|
|
1925
|
+
onRButtonDown(t) {
|
|
1926
|
+
return !1;
|
|
1927
|
+
}
|
|
1928
|
+
onRButtonUp(t) {
|
|
1929
|
+
return !1;
|
|
1930
|
+
}
|
|
1931
|
+
onMButtonDown(t) {
|
|
1932
|
+
return !1;
|
|
1933
|
+
}
|
|
1934
|
+
onMButtonUp(t) {
|
|
1935
|
+
return !1;
|
|
1936
|
+
}
|
|
1937
|
+
onWheelForward(t) {
|
|
1938
|
+
return !1;
|
|
1939
|
+
}
|
|
1940
|
+
onWheelBackward(t) {
|
|
1941
|
+
return !1;
|
|
1942
|
+
}
|
|
1943
|
+
onClick(t) {
|
|
1944
|
+
return !1;
|
|
1945
|
+
}
|
|
1946
|
+
onSglClick(t) {
|
|
1947
|
+
return !1;
|
|
1948
|
+
}
|
|
1949
|
+
onDblClick(t) {
|
|
1950
|
+
return !1;
|
|
1951
|
+
}
|
|
1952
|
+
onMouseLeave(t) {
|
|
1953
|
+
return !1;
|
|
1954
|
+
}
|
|
1955
|
+
onKeyDown(t) {
|
|
1956
|
+
return !1;
|
|
1957
|
+
}
|
|
1958
|
+
onKeyUp(t) {
|
|
1959
|
+
return !1;
|
|
1960
|
+
}
|
|
1961
|
+
onKeyPress(t) {
|
|
1962
|
+
return !1;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
export {
|
|
1966
|
+
Ue as CCanvas,
|
|
1967
|
+
Ae as DefaultController,
|
|
1968
|
+
L as EN_KeyboardEvent,
|
|
1969
|
+
h as EN_MouseEvent,
|
|
1970
|
+
P as EN_NativeKeyboardEvent,
|
|
1971
|
+
y as EN_NativeMouseEvent,
|
|
1972
|
+
Wt as FnKey,
|
|
1973
|
+
Te as KeyboardInteractor,
|
|
1974
|
+
xe as MouseInteractor,
|
|
1975
|
+
U as canvasConfig
|
|
1976
|
+
};
|