@woosh/meep-engine 2.109.10 → 2.109.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/editor/tools/v2/GizmoNode.js +71 -0
- package/editor/tools/v2/TransformControls.js +10 -980
- package/editor/tools/v2/TransformControlsGizmo.js +774 -0
- package/editor/tools/v2/TransformControlsPlane.js +118 -0
- package/editor/tools/v2/TransformMode.js +8 -0
- package/editor/tools/v2/TranslateHelperGeometry.js +14 -0
- package/package.json +1 -1
- package/src/core/model/node-graph/NodeGraph.spec.js +1 -1
- package/src/core/model/node-graph/node/NodeDescription.d.ts +1 -1
- package/src/core/model/node-graph/node/NodeDescription.spec.js +1 -1
- package/src/core/model/node-graph/node/NodeInstance.spec.js +1 -1
- package/src/core/model/node-graph/node/NodeInstancePortReference.spec.js +1 -1
- package/src/core/model/node-graph/node/NodeRegistry.d.ts +1 -1
- package/src/core/model/node-graph/node/NodeRegistry.d.ts.map +1 -1
- package/src/core/model/node-graph/node/NodeRegistry.js +5 -5
- package/src/core/model/node-graph/node/NodeRegistry.spec.js +1 -1
- package/src/core/model/node-graph/node/Port.d.ts.map +1 -1
- package/src/core/model/node-graph/node/Port.js +3 -2
- package/src/core/model/node-graph/node/Port.spec.js +1 -1
- package/src/core/model/node-graph/type/DataType.d.ts.map +1 -0
- package/src/core/model/node-graph/{DataType.js → type/DataType.js} +2 -2
- package/src/core/model/node-graph/type/DataType.spec.d.ts.map +1 -0
- package/src/core/model/node-graph/{ParametricDataType.d.ts → type/ParametricDataType.d.ts} +6 -1
- package/src/core/model/node-graph/type/ParametricDataType.d.ts.map +1 -0
- package/src/core/model/node-graph/{ParametricDataType.js → type/ParametricDataType.js} +19 -4
- package/src/core/model/node-graph/type/ParametricDataType.spec.d.ts +2 -0
- package/src/core/model/node-graph/type/ParametricDataType.spec.d.ts.map +1 -0
- package/src/core/model/node-graph/type/ParametricDataType.spec.js +63 -0
- package/src/core/model/node-graph/type/deserializeDataTypeFromJSON.d.ts +8 -0
- package/src/core/model/node-graph/type/deserializeDataTypeFromJSON.d.ts.map +1 -0
- package/src/core/model/node-graph/type/deserializeDataTypeFromJSON.js +24 -0
- package/src/engine/graphics/geometry/CircleGeometry.d.ts +20 -0
- package/src/engine/graphics/geometry/CircleGeometry.d.ts.map +1 -0
- package/src/engine/graphics/geometry/CircleGeometry.js +17 -0
- package/src/engine/graphics/particles/node-based/nodes/ParticleDataTypes.js +1 -1
- package/src/engine/graphics/particles/node-based/particle/ParticleAttributeSpecification.d.ts +10 -8
- package/src/engine/graphics/particles/node-based/particle/ParticleAttributeSpecification.d.ts.map +1 -1
- package/src/engine/graphics/sh3/gi/material/common.glsl +171 -95
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +4 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +4 -0
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +52 -0
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +4 -4
- package/src/core/model/node-graph/DataType.d.ts.map +0 -1
- package/src/core/model/node-graph/DataType.spec.d.ts.map +0 -1
- package/src/core/model/node-graph/ParametricDataType.d.ts.map +0 -1
- /package/src/core/model/node-graph/{DataType.d.ts → type/DataType.d.ts} +0 -0
- /package/src/core/model/node-graph/{DataType.spec.d.ts → type/DataType.spec.d.ts} +0 -0
- /package/src/core/model/node-graph/{DataType.spec.js → type/DataType.spec.js} +0 -0
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoxGeometry,
|
|
3
|
-
BufferGeometry,
|
|
4
|
-
CylinderGeometry,
|
|
5
|
-
DoubleSide,
|
|
6
|
-
Euler,
|
|
7
|
-
Float32BufferAttribute,
|
|
8
|
-
LineBasicMaterial,
|
|
9
|
-
Matrix4,
|
|
10
|
-
MeshBasicMaterial,
|
|
11
|
-
OctahedronGeometry,
|
|
12
|
-
PlaneGeometry,
|
|
13
|
-
Quaternion,
|
|
14
|
-
Raycaster,
|
|
15
|
-
SphereGeometry,
|
|
16
|
-
TorusGeometry,
|
|
17
|
-
Vector3
|
|
18
|
-
} from 'three';
|
|
1
|
+
import { Quaternion, Raycaster, Vector3 } from 'three';
|
|
19
2
|
import { assert } from "../../../src/core/assert.js";
|
|
20
3
|
import { SurfacePoint3 } from "../../../src/core/geom/3d/SurfacePoint3.js";
|
|
21
4
|
import { EntityNode } from "../../../src/engine/ecs/parent/EntityNode.js";
|
|
22
5
|
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
23
|
-
import { DrawMode } from "../../../src/engine/graphics/ecs/mesh-v2/DrawMode.js";
|
|
24
6
|
import { ShadedGeometry } from "../../../src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
|
|
25
7
|
import { ShadedGeometryFlags } from "../../../src/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js";
|
|
26
8
|
import { FrameRunner } from "../../../src/engine/graphics/FrameRunner.js";
|
|
9
|
+
import { GizmoNode } from "./GizmoNode.js";
|
|
10
|
+
import { TransformControlsGizmo } from "./TransformControlsGizmo.js";
|
|
11
|
+
import { TransformControlsPlane } from "./TransformControlsPlane.js";
|
|
12
|
+
import { TransformMode } from "./TransformMode.js";
|
|
27
13
|
|
|
28
14
|
const _raycaster = new Raycaster();
|
|
29
15
|
|
|
30
|
-
const _tempVector = new Vector3();
|
|
31
16
|
const _tempVector2 = new Vector3();
|
|
32
|
-
const _tempQuaternion = new Quaternion();
|
|
33
17
|
const _unit = {
|
|
34
18
|
X: new Vector3(1, 0, 0),
|
|
35
19
|
Y: new Vector3(0, 1, 0),
|
|
@@ -41,111 +25,16 @@ const _mouseDownEvent = { type: 'mouseDown' };
|
|
|
41
25
|
const _mouseUpEvent = { type: 'mouseUp', mode: null };
|
|
42
26
|
const _objectChangeEvent = { type: 'objectChange' };
|
|
43
27
|
|
|
28
|
+
const _tempVector = new Vector3();
|
|
29
|
+
const _tempQuaternion = new Quaternion();
|
|
30
|
+
|
|
31
|
+
|
|
44
32
|
/**
|
|
45
33
|
* @readonly
|
|
46
34
|
* @type {Transform}
|
|
47
35
|
*/
|
|
48
36
|
const _tempTransform = new Transform();
|
|
49
37
|
|
|
50
|
-
function CircleGeometry(radius, arc) {
|
|
51
|
-
|
|
52
|
-
const geometry = new TorusGeometry(radius, 0.0075, 3, 64, arc * Math.PI * 2);
|
|
53
|
-
geometry.rotateY(Math.PI / 2);
|
|
54
|
-
geometry.rotateX(Math.PI / 2);
|
|
55
|
-
return geometry;
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
|
|
60
|
-
|
|
61
|
-
function TranslateHelperGeometry() {
|
|
62
|
-
|
|
63
|
-
const geometry = new BufferGeometry();
|
|
64
|
-
|
|
65
|
-
geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 1, 1, 1], 3));
|
|
66
|
-
|
|
67
|
-
return geometry;
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @enum {string}
|
|
73
|
-
*/
|
|
74
|
-
const TransformMode = {
|
|
75
|
-
Scale: 'scale',
|
|
76
|
-
Translate: 'translate',
|
|
77
|
-
Rotate: 'rotate'
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
class GizmoNode extends EntityNode {
|
|
81
|
-
constructor() {
|
|
82
|
-
super();
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
* @type {boolean}
|
|
87
|
-
* @private
|
|
88
|
-
*/
|
|
89
|
-
this._visible = true;
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @type {EntityComponentDataset|null}
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
this.__ecd = null;
|
|
96
|
-
|
|
97
|
-
this.entity.add(new Transform());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
build(ecd) {
|
|
101
|
-
this.__ecd = ecd;
|
|
102
|
-
|
|
103
|
-
if (this._visible) {
|
|
104
|
-
super.build(ecd);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
set visible(v) {
|
|
109
|
-
if (this._visible === v) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this._visible = v;
|
|
114
|
-
|
|
115
|
-
if (this.__ecd !== null) {
|
|
116
|
-
|
|
117
|
-
if (v) {
|
|
118
|
-
super.build(this.__ecd);
|
|
119
|
-
} else {
|
|
120
|
-
this.destroy();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
get visible() {
|
|
127
|
-
return this._visible;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
update() {
|
|
131
|
-
// do nothing
|
|
132
|
-
const children = this.children;
|
|
133
|
-
const n = children.length;
|
|
134
|
-
for (let i = 0; i < n; i++) {
|
|
135
|
-
const child = children[i];
|
|
136
|
-
if (!(child instanceof GizmoNode)) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!child.isBuilt) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
child.update();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
38
|
class TransformControls extends GizmoNode {
|
|
150
39
|
|
|
151
40
|
/**
|
|
@@ -927,863 +816,4 @@ function intersectObjectWithRay(object, raycaster, includeInvisible = false) {
|
|
|
927
816
|
return contacts[0];
|
|
928
817
|
}
|
|
929
818
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
// Reusable utility variables
|
|
933
|
-
|
|
934
|
-
const _tempEuler = new Euler();
|
|
935
|
-
const _alignVector = new Vector3(0, 1, 0);
|
|
936
|
-
const _zeroVector = new Vector3(0, 0, 0);
|
|
937
|
-
const _lookAtMatrix = new Matrix4();
|
|
938
|
-
const _tempQuaternion2 = new Quaternion();
|
|
939
|
-
const _identityQuaternion = new Quaternion();
|
|
940
|
-
const _dirVector = new Vector3();
|
|
941
|
-
const _tempMatrix = new Matrix4();
|
|
942
|
-
|
|
943
|
-
const _unitX = new Vector3(1, 0, 0);
|
|
944
|
-
const _unitY = new Vector3(0, 1, 0);
|
|
945
|
-
const _unitZ = new Vector3(0, 0, 1);
|
|
946
|
-
|
|
947
|
-
const _v1 = new Vector3();
|
|
948
|
-
const _v2 = new Vector3();
|
|
949
|
-
const _v3 = new Vector3();
|
|
950
|
-
|
|
951
|
-
class TransformControlsGizmo extends GizmoNode {
|
|
952
|
-
|
|
953
|
-
constructor() {
|
|
954
|
-
|
|
955
|
-
super();
|
|
956
|
-
|
|
957
|
-
this.isTransformControlsGizmo = true;
|
|
958
|
-
|
|
959
|
-
this.type = 'TransformControlsGizmo';
|
|
960
|
-
|
|
961
|
-
// shared materials
|
|
962
|
-
|
|
963
|
-
const gizmoMaterial = new MeshBasicMaterial({
|
|
964
|
-
depthTest: false,
|
|
965
|
-
depthWrite: false,
|
|
966
|
-
fog: false,
|
|
967
|
-
toneMapped: false,
|
|
968
|
-
transparent: true
|
|
969
|
-
});
|
|
970
|
-
|
|
971
|
-
const gizmoLineMaterial = new LineBasicMaterial({
|
|
972
|
-
depthTest: false,
|
|
973
|
-
depthWrite: false,
|
|
974
|
-
fog: false,
|
|
975
|
-
toneMapped: false,
|
|
976
|
-
transparent: true
|
|
977
|
-
});
|
|
978
|
-
|
|
979
|
-
// Make unique material for each axis/color
|
|
980
|
-
|
|
981
|
-
const matInvisible = gizmoMaterial.clone();
|
|
982
|
-
matInvisible.opacity = 0.15;
|
|
983
|
-
|
|
984
|
-
const matHelper = gizmoLineMaterial.clone();
|
|
985
|
-
matHelper.opacity = 0.5;
|
|
986
|
-
|
|
987
|
-
const matRed = gizmoMaterial.clone();
|
|
988
|
-
matRed.color.setHex(0xff0000);
|
|
989
|
-
|
|
990
|
-
const matGreen = gizmoMaterial.clone();
|
|
991
|
-
matGreen.color.setHex(0x00ff00);
|
|
992
|
-
|
|
993
|
-
const matBlue = gizmoMaterial.clone();
|
|
994
|
-
matBlue.color.setHex(0x0000ff);
|
|
995
|
-
|
|
996
|
-
const matRedTransparent = gizmoMaterial.clone();
|
|
997
|
-
matRedTransparent.color.setHex(0xff0000);
|
|
998
|
-
matRedTransparent.opacity = 0.5;
|
|
999
|
-
|
|
1000
|
-
const matGreenTransparent = gizmoMaterial.clone();
|
|
1001
|
-
matGreenTransparent.color.setHex(0x00ff00);
|
|
1002
|
-
matGreenTransparent.opacity = 0.5;
|
|
1003
|
-
|
|
1004
|
-
const matBlueTransparent = gizmoMaterial.clone();
|
|
1005
|
-
matBlueTransparent.color.setHex(0x0000ff);
|
|
1006
|
-
matBlueTransparent.opacity = 0.5;
|
|
1007
|
-
|
|
1008
|
-
const matWhiteTransparent = gizmoMaterial.clone();
|
|
1009
|
-
matWhiteTransparent.opacity = 0.25;
|
|
1010
|
-
|
|
1011
|
-
const matYellowTransparent = gizmoMaterial.clone();
|
|
1012
|
-
matYellowTransparent.color.setHex(0xffff00);
|
|
1013
|
-
matYellowTransparent.opacity = 0.25;
|
|
1014
|
-
|
|
1015
|
-
const matYellow = gizmoMaterial.clone();
|
|
1016
|
-
matYellow.color.setHex(0xffff00);
|
|
1017
|
-
|
|
1018
|
-
const matGray = gizmoMaterial.clone();
|
|
1019
|
-
matGray.color.setHex(0x787878);
|
|
1020
|
-
|
|
1021
|
-
// reusable geometry
|
|
1022
|
-
|
|
1023
|
-
const arrowGeometry = new CylinderGeometry(0, 0.04, 0.1, 12);
|
|
1024
|
-
arrowGeometry.translate(0, 0.05, 0);
|
|
1025
|
-
|
|
1026
|
-
const scaleHandleGeometry = new BoxGeometry(0.08, 0.08, 0.08);
|
|
1027
|
-
scaleHandleGeometry.translate(0, 0.04, 0);
|
|
1028
|
-
|
|
1029
|
-
const lineGeometry = new BufferGeometry();
|
|
1030
|
-
lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 1, 0, 0], 3));
|
|
1031
|
-
|
|
1032
|
-
const lineGeometry2 = new CylinderGeometry(0.0075, 0.0075, 0.5, 3);
|
|
1033
|
-
lineGeometry2.translate(0, 0.25, 0);
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
// Gizmo definitions - custom hierarchy definitions for setupGizmo() function
|
|
1037
|
-
|
|
1038
|
-
const gizmoTranslate = {
|
|
1039
|
-
X: [
|
|
1040
|
-
[ShadedGeometry.from(arrowGeometry, matRed, DrawMode.Triangles), [0.5, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1041
|
-
[ShadedGeometry.from(arrowGeometry, matRed, DrawMode.Triangles), [-0.5, 0, 0], [0, 0, Math.PI / 2]],
|
|
1042
|
-
[ShadedGeometry.from(lineGeometry2, matRed, DrawMode.Triangles), [0, 0, 0], [0, 0, -Math.PI / 2]]
|
|
1043
|
-
],
|
|
1044
|
-
Y: [
|
|
1045
|
-
[ShadedGeometry.from(arrowGeometry, matGreen, DrawMode.Triangles), [0, 0.5, 0]],
|
|
1046
|
-
[ShadedGeometry.from(arrowGeometry, matGreen, DrawMode.Triangles), [0, -0.5, 0], [Math.PI, 0, 0]],
|
|
1047
|
-
[ShadedGeometry.from(lineGeometry2, matGreen, DrawMode.Triangles)]
|
|
1048
|
-
],
|
|
1049
|
-
Z: [
|
|
1050
|
-
[ShadedGeometry.from(arrowGeometry, matBlue, DrawMode.Triangles), [0, 0, 0.5], [Math.PI / 2, 0, 0]],
|
|
1051
|
-
[ShadedGeometry.from(arrowGeometry, matBlue, DrawMode.Triangles), [0, 0, -0.5], [-Math.PI / 2, 0, 0]],
|
|
1052
|
-
[ShadedGeometry.from(lineGeometry2, matBlue, DrawMode.Triangles), null, [Math.PI / 2, 0, 0]]
|
|
1053
|
-
],
|
|
1054
|
-
XYZ: [
|
|
1055
|
-
[ShadedGeometry.from(new OctahedronGeometry(0.1, 0), matWhiteTransparent.clone(), DrawMode.Triangles), [0, 0, 0]]
|
|
1056
|
-
],
|
|
1057
|
-
XY: [
|
|
1058
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent.clone(), DrawMode.Triangles), [0.15, 0.15, 0]]
|
|
1059
|
-
],
|
|
1060
|
-
YZ: [
|
|
1061
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matRedTransparent.clone(), DrawMode.Triangles), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
|
|
1062
|
-
],
|
|
1063
|
-
XZ: [
|
|
1064
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent.clone(), DrawMode.Triangles), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
|
|
1065
|
-
]
|
|
1066
|
-
};
|
|
1067
|
-
|
|
1068
|
-
const pickerTranslate = {
|
|
1069
|
-
X: [
|
|
1070
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [0.3, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1071
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [-0.3, 0, 0], [0, 0, Math.PI / 2]]
|
|
1072
|
-
],
|
|
1073
|
-
Y: [
|
|
1074
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [0, 0.3, 0]],
|
|
1075
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [0, -0.3, 0], [0, 0, Math.PI]]
|
|
1076
|
-
],
|
|
1077
|
-
Z: [
|
|
1078
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [0, 0, 0.3], [Math.PI / 2, 0, 0]],
|
|
1079
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible, DrawMode.Triangles), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]
|
|
1080
|
-
],
|
|
1081
|
-
XYZ: [
|
|
1082
|
-
[ShadedGeometry.from(new OctahedronGeometry(0.2, 0), matInvisible, DrawMode.Triangles)]
|
|
1083
|
-
],
|
|
1084
|
-
XY: [
|
|
1085
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible, DrawMode.Triangles), [0.15, 0.15, 0]]
|
|
1086
|
-
],
|
|
1087
|
-
YZ: [
|
|
1088
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible, DrawMode.Triangles), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
|
|
1089
|
-
],
|
|
1090
|
-
XZ: [
|
|
1091
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible, DrawMode.Triangles), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
|
|
1092
|
-
]
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
const helperTranslate = {
|
|
1096
|
-
START: [
|
|
1097
|
-
[ShadedGeometry.from(new OctahedronGeometry(0.01, 2), matHelper, DrawMode.Triangles), null, null, null, 'helper']
|
|
1098
|
-
],
|
|
1099
|
-
END: [
|
|
1100
|
-
[ShadedGeometry.from(new OctahedronGeometry(0.01, 2), matHelper, DrawMode.Triangles), null, null, null, 'helper']
|
|
1101
|
-
],
|
|
1102
|
-
DELTA: [
|
|
1103
|
-
[ShadedGeometry.from(TranslateHelperGeometry(), matHelper, DrawMode.Lines), null, null, null, 'helper']
|
|
1104
|
-
],
|
|
1105
|
-
X: [
|
|
1106
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']
|
|
1107
|
-
],
|
|
1108
|
-
Y: [
|
|
1109
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']
|
|
1110
|
-
],
|
|
1111
|
-
Z: [
|
|
1112
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']
|
|
1113
|
-
]
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
const gizmoRotate = {
|
|
1117
|
-
XYZE: [
|
|
1118
|
-
[ShadedGeometry.from(CircleGeometry(0.5, 1), matGray, DrawMode.Triangles), null, [0, Math.PI / 2, 0]]
|
|
1119
|
-
],
|
|
1120
|
-
X: [
|
|
1121
|
-
[ShadedGeometry.from(CircleGeometry(0.5, 0.5), matRed, DrawMode.Triangles)]
|
|
1122
|
-
],
|
|
1123
|
-
Y: [
|
|
1124
|
-
[ShadedGeometry.from(CircleGeometry(0.5, 0.5), matGreen, DrawMode.Triangles), null, [0, 0, -Math.PI / 2]]
|
|
1125
|
-
],
|
|
1126
|
-
Z: [
|
|
1127
|
-
[ShadedGeometry.from(CircleGeometry(0.5, 0.5), matBlue, DrawMode.Triangles), null, [0, Math.PI / 2, 0]]
|
|
1128
|
-
],
|
|
1129
|
-
E: [
|
|
1130
|
-
[ShadedGeometry.from(CircleGeometry(0.75, 1), matYellowTransparent, DrawMode.Triangles), null, [0, Math.PI / 2, 0]]
|
|
1131
|
-
]
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
|
-
const helperRotate = {
|
|
1135
|
-
AXIS: [
|
|
1136
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']
|
|
1137
|
-
]
|
|
1138
|
-
};
|
|
1139
|
-
|
|
1140
|
-
const pickerRotate = {
|
|
1141
|
-
XYZE: [
|
|
1142
|
-
[ShadedGeometry.from(new SphereGeometry(0.25, 10, 8), matInvisible, DrawMode.Triangles)]
|
|
1143
|
-
],
|
|
1144
|
-
X: [
|
|
1145
|
-
[ShadedGeometry.from(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible, DrawMode.Triangles), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]],
|
|
1146
|
-
],
|
|
1147
|
-
Y: [
|
|
1148
|
-
[ShadedGeometry.from(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible, DrawMode.Triangles), [0, 0, 0], [Math.PI / 2, 0, 0]],
|
|
1149
|
-
],
|
|
1150
|
-
Z: [
|
|
1151
|
-
[ShadedGeometry.from(new TorusGeometry(0.5, 0.1, 4, 24), matInvisible, DrawMode.Triangles), [0, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1152
|
-
],
|
|
1153
|
-
E: [
|
|
1154
|
-
[ShadedGeometry.from(new TorusGeometry(0.75, 0.1, 2, 24), matInvisible, DrawMode.Triangles)]
|
|
1155
|
-
]
|
|
1156
|
-
};
|
|
1157
|
-
|
|
1158
|
-
const gizmoScale = {
|
|
1159
|
-
X: [
|
|
1160
|
-
[ShadedGeometry.from(scaleHandleGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1161
|
-
[ShadedGeometry.from(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1162
|
-
[ShadedGeometry.from(scaleHandleGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]],
|
|
1163
|
-
],
|
|
1164
|
-
Y: [
|
|
1165
|
-
[ShadedGeometry.from(scaleHandleGeometry, matGreen), [0, 0.5, 0]],
|
|
1166
|
-
[ShadedGeometry.from(lineGeometry2, matGreen)],
|
|
1167
|
-
[ShadedGeometry.from(scaleHandleGeometry, matGreen), [0, -0.5, 0], [0, 0, Math.PI]],
|
|
1168
|
-
],
|
|
1169
|
-
Z: [
|
|
1170
|
-
[ShadedGeometry.from(scaleHandleGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]],
|
|
1171
|
-
[ShadedGeometry.from(lineGeometry2, matBlue), [0, 0, 0], [Math.PI / 2, 0, 0]],
|
|
1172
|
-
[ShadedGeometry.from(scaleHandleGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]]
|
|
1173
|
-
],
|
|
1174
|
-
XY: [
|
|
1175
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent), [0.15, 0.15, 0]]
|
|
1176
|
-
],
|
|
1177
|
-
YZ: [
|
|
1178
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matRedTransparent), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
|
|
1179
|
-
],
|
|
1180
|
-
XZ: [
|
|
1181
|
-
[ShadedGeometry.from(new BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
|
|
1182
|
-
],
|
|
1183
|
-
XYZ: [
|
|
1184
|
-
[ShadedGeometry.from(new BoxGeometry(0.1, 0.1, 0.1), matWhiteTransparent.clone())],
|
|
1185
|
-
]
|
|
1186
|
-
};
|
|
1187
|
-
|
|
1188
|
-
const pickerScale = {
|
|
1189
|
-
X: [
|
|
1190
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]],
|
|
1191
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]
|
|
1192
|
-
],
|
|
1193
|
-
Y: [
|
|
1194
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]],
|
|
1195
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]
|
|
1196
|
-
],
|
|
1197
|
-
Z: [
|
|
1198
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]],
|
|
1199
|
-
[ShadedGeometry.from(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]
|
|
1200
|
-
],
|
|
1201
|
-
XY: [
|
|
1202
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]],
|
|
1203
|
-
],
|
|
1204
|
-
YZ: [
|
|
1205
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]],
|
|
1206
|
-
],
|
|
1207
|
-
XZ: [
|
|
1208
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]],
|
|
1209
|
-
],
|
|
1210
|
-
XYZ: [
|
|
1211
|
-
[ShadedGeometry.from(new BoxGeometry(0.2, 0.2, 0.2), matInvisible), [0, 0, 0]],
|
|
1212
|
-
]
|
|
1213
|
-
};
|
|
1214
|
-
|
|
1215
|
-
const helperScale = {
|
|
1216
|
-
X: [
|
|
1217
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']
|
|
1218
|
-
],
|
|
1219
|
-
Y: [
|
|
1220
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']
|
|
1221
|
-
],
|
|
1222
|
-
Z: [
|
|
1223
|
-
[ShadedGeometry.from(lineGeometry, matHelper.clone(), DrawMode.Lines), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']
|
|
1224
|
-
]
|
|
1225
|
-
};
|
|
1226
|
-
|
|
1227
|
-
// Creates an Object3D with gizmos described in custom hierarchy definition.
|
|
1228
|
-
|
|
1229
|
-
/**
|
|
1230
|
-
*
|
|
1231
|
-
* @returns {EntityNode}
|
|
1232
|
-
*/
|
|
1233
|
-
function setupGizmo(gizmoMap) {
|
|
1234
|
-
|
|
1235
|
-
const gizmo = new GizmoNode();
|
|
1236
|
-
|
|
1237
|
-
for (const name in gizmoMap) {
|
|
1238
|
-
|
|
1239
|
-
const gizmo_elements = gizmoMap[name];
|
|
1240
|
-
|
|
1241
|
-
for (let i = gizmo_elements.length; i--;) {
|
|
1242
|
-
const gizmo_element = gizmo_elements[i];
|
|
1243
|
-
|
|
1244
|
-
/**
|
|
1245
|
-
* @type {ShadedGeometry}
|
|
1246
|
-
*/
|
|
1247
|
-
const shaded_geometry = gizmo_element[0].clone();
|
|
1248
|
-
|
|
1249
|
-
// disable shadows
|
|
1250
|
-
shaded_geometry.clearFlag(ShadedGeometryFlags.CastShadow | ShadedGeometryFlags.ReceiveShadow);
|
|
1251
|
-
|
|
1252
|
-
// make it so that gizmo is always drawn using direct mode
|
|
1253
|
-
shaded_geometry.draw_method = 0;
|
|
1254
|
-
shaded_geometry.setFlag(ShadedGeometryFlags.DrawMethodLocked);
|
|
1255
|
-
|
|
1256
|
-
const node = new GizmoNode();
|
|
1257
|
-
const transform = node.entity.getComponent(Transform);
|
|
1258
|
-
node.entity.add(shaded_geometry);
|
|
1259
|
-
|
|
1260
|
-
/**
|
|
1261
|
-
* @type {number[]|undefined}
|
|
1262
|
-
*/
|
|
1263
|
-
const position = gizmo_element[1];
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* @type {number[]|undefined}
|
|
1267
|
-
*/
|
|
1268
|
-
const rotation = gizmo_element[2];
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* @type {number[]|undefined}
|
|
1272
|
-
*/
|
|
1273
|
-
const scale = gizmo_element[3];
|
|
1274
|
-
|
|
1275
|
-
/**
|
|
1276
|
-
* @type {string|undefined}
|
|
1277
|
-
*/
|
|
1278
|
-
const tag = gizmo_element[4];
|
|
1279
|
-
|
|
1280
|
-
// name and tag properties are essential for picking and updating logic.
|
|
1281
|
-
node.name = name;
|
|
1282
|
-
node.tag = tag;
|
|
1283
|
-
|
|
1284
|
-
if (position) {
|
|
1285
|
-
|
|
1286
|
-
transform.position.set(position[0], position[1], position[2]);
|
|
1287
|
-
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
if (rotation) {
|
|
1291
|
-
|
|
1292
|
-
transform.rotation.fromEulerAnglesXYZ(rotation[0], rotation[1], rotation[2]);
|
|
1293
|
-
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
if (scale) {
|
|
1297
|
-
|
|
1298
|
-
transform.scale.set(scale[0], scale[1], scale[2]);
|
|
1299
|
-
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
const tempGeometry = shaded_geometry.geometry.clone();
|
|
1303
|
-
const m4 = new Matrix4();
|
|
1304
|
-
transform.toMatrix4(m4.elements);
|
|
1305
|
-
tempGeometry.applyMatrix4(m4);
|
|
1306
|
-
|
|
1307
|
-
shaded_geometry.geometry = tempGeometry;
|
|
1308
|
-
// TODO add support for render order to ShadedGeometry
|
|
1309
|
-
shaded_geometry.renderOrder = Infinity;
|
|
1310
|
-
|
|
1311
|
-
transform.makeIdentity();
|
|
1312
|
-
|
|
1313
|
-
gizmo.addChild(node);
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
return gizmo;
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
// Gizmo creation
|
|
1324
|
-
|
|
1325
|
-
/**
|
|
1326
|
-
*
|
|
1327
|
-
* @type {Object<EntityNode>}
|
|
1328
|
-
*/
|
|
1329
|
-
this.gizmo = {};
|
|
1330
|
-
/**
|
|
1331
|
-
*
|
|
1332
|
-
* @type {Object<EntityNode>}
|
|
1333
|
-
*/
|
|
1334
|
-
this.picker = {};
|
|
1335
|
-
/**
|
|
1336
|
-
*
|
|
1337
|
-
* @type {Object<EntityNode>}
|
|
1338
|
-
*/
|
|
1339
|
-
this.helper = {};
|
|
1340
|
-
|
|
1341
|
-
this.addChild(this.gizmo[TransformMode.Translate] = setupGizmo(gizmoTranslate));
|
|
1342
|
-
this.addChild(this.gizmo[TransformMode.Rotate] = setupGizmo(gizmoRotate));
|
|
1343
|
-
this.addChild(this.gizmo[TransformMode.Scale] = setupGizmo(gizmoScale));
|
|
1344
|
-
this.addChild(this.picker[TransformMode.Translate] = setupGizmo(pickerTranslate));
|
|
1345
|
-
this.addChild(this.picker[TransformMode.Rotate] = setupGizmo(pickerRotate));
|
|
1346
|
-
this.addChild(this.picker[TransformMode.Scale] = setupGizmo(pickerScale));
|
|
1347
|
-
this.addChild(this.helper[TransformMode.Translate] = setupGizmo(helperTranslate));
|
|
1348
|
-
this.addChild(this.helper[TransformMode.Rotate] = setupGizmo(helperRotate));
|
|
1349
|
-
this.addChild(this.helper[TransformMode.Scale] = setupGizmo(helperScale));
|
|
1350
|
-
|
|
1351
|
-
// Pickers should be hidden always
|
|
1352
|
-
|
|
1353
|
-
this.picker[TransformMode.Translate].visible = false;
|
|
1354
|
-
this.picker[TransformMode.Rotate].visible = false;
|
|
1355
|
-
this.picker[TransformMode.Scale].visible = false;
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
// updateMatrixWorld will update transformations and appearance of individual handles
|
|
1359
|
-
|
|
1360
|
-
update(force) {
|
|
1361
|
-
|
|
1362
|
-
const space = (this.mode === TransformMode.Scale) ? 'local' : this.space; // scale always oriented to local rotation
|
|
1363
|
-
|
|
1364
|
-
const quaternion = (space === 'local') ? this.worldQuaternion : _identityQuaternion;
|
|
1365
|
-
|
|
1366
|
-
// Show only gizmos for current transform mode
|
|
1367
|
-
|
|
1368
|
-
this.gizmo[TransformMode.Translate].visible = this.mode === TransformMode.Translate;
|
|
1369
|
-
this.gizmo[TransformMode.Rotate].visible = this.mode === TransformMode.Rotate;
|
|
1370
|
-
this.gizmo[TransformMode.Scale].visible = this.mode === TransformMode.Scale;
|
|
1371
|
-
|
|
1372
|
-
this.helper[TransformMode.Translate].visible = this.mode === TransformMode.Translate;
|
|
1373
|
-
this.helper[TransformMode.Rotate].visible = this.mode === TransformMode.Rotate;
|
|
1374
|
-
this.helper[TransformMode.Scale].visible = this.mode === TransformMode.Scale;
|
|
1375
|
-
|
|
1376
|
-
/**
|
|
1377
|
-
*
|
|
1378
|
-
* @type {(GizmoNode|{name:string,tag:string})[]}
|
|
1379
|
-
*/
|
|
1380
|
-
let handles = [];
|
|
1381
|
-
handles = handles.concat(this.picker[this.mode].children);
|
|
1382
|
-
handles = handles.concat(this.gizmo[this.mode].children);
|
|
1383
|
-
handles = handles.concat(this.helper[this.mode].children);
|
|
1384
|
-
|
|
1385
|
-
for (let i = 0; i < handles.length; i++) {
|
|
1386
|
-
|
|
1387
|
-
const handle = handles[i];
|
|
1388
|
-
|
|
1389
|
-
// hide aligned to camera
|
|
1390
|
-
|
|
1391
|
-
handle.visible = true;
|
|
1392
|
-
handle.transform.rotation.fromEulerAnglesXYZ(0, 0, 0);
|
|
1393
|
-
handle.transform.position.copy(this.worldPosition);
|
|
1394
|
-
|
|
1395
|
-
let factor;
|
|
1396
|
-
|
|
1397
|
-
if (this.camera.isOrthographicCamera) {
|
|
1398
|
-
|
|
1399
|
-
factor = (this.camera.top - this.camera.bottom) / this.camera.zoom;
|
|
1400
|
-
|
|
1401
|
-
} else {
|
|
1402
|
-
|
|
1403
|
-
factor = this.worldPosition.distanceTo(this.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * this.camera.fov / 360) / this.camera.zoom, 7);
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
if (factor === 0) {
|
|
1408
|
-
// prevent 0 size
|
|
1409
|
-
factor = 1e-10;
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
handle.transform.scale.setScalar(factor * this.size / 4);
|
|
1413
|
-
|
|
1414
|
-
// TODO: simplify helpers and consider decoupling from gizmo
|
|
1415
|
-
|
|
1416
|
-
if (handle.tag === 'helper') {
|
|
1417
|
-
handle.visible = false;
|
|
1418
|
-
|
|
1419
|
-
if (handle.name === 'AXIS') {
|
|
1420
|
-
|
|
1421
|
-
handle.transform.position.copy(this.worldPositionStart);
|
|
1422
|
-
handle.visible = !!this.axis;
|
|
1423
|
-
|
|
1424
|
-
if (this.axis === 'X') {
|
|
1425
|
-
|
|
1426
|
-
_tempQuaternion.setFromEuler(_tempEuler.set(0, 0, 0));
|
|
1427
|
-
handle.transform.rotation.copy(quaternion);
|
|
1428
|
-
handle.transform.rotation.multiply(_tempQuaternion);
|
|
1429
|
-
|
|
1430
|
-
if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
|
|
1431
|
-
|
|
1432
|
-
handle.visible = false;
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
if (this.axis === 'Y') {
|
|
1439
|
-
|
|
1440
|
-
_tempQuaternion.setFromEuler(_tempEuler.set(0, 0, Math.PI / 2));
|
|
1441
|
-
handle.transform.rotation.copy(quaternion);
|
|
1442
|
-
handle.transform.rotation.multiply(_tempQuaternion);
|
|
1443
|
-
|
|
1444
|
-
if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
|
|
1445
|
-
|
|
1446
|
-
handle.visible = false;
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
if (this.axis === 'Z') {
|
|
1453
|
-
|
|
1454
|
-
_tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
|
|
1455
|
-
handle.transform.rotation.copy(quaternion);
|
|
1456
|
-
handle.transform.rotation.multiply(_tempQuaternion);
|
|
1457
|
-
|
|
1458
|
-
if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
|
|
1459
|
-
|
|
1460
|
-
handle.visible = false;
|
|
1461
|
-
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
if (this.axis === 'XYZE') {
|
|
1467
|
-
|
|
1468
|
-
_tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
|
|
1469
|
-
_alignVector.copy(this.rotationAxis);
|
|
1470
|
-
handle.transform.rotation.setFromRotationMatrix(_lookAtMatrix.lookAt(_zeroVector, _alignVector, _unitY));
|
|
1471
|
-
handle.transform.rotation.multiply(_tempQuaternion);
|
|
1472
|
-
handle.visible = this.dragging;
|
|
1473
|
-
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
if (this.axis === 'E') {
|
|
1477
|
-
|
|
1478
|
-
handle.visible = false;
|
|
1479
|
-
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
} else if (handle.name === 'START') {
|
|
1484
|
-
|
|
1485
|
-
handle.transform.position.copy(this.worldPositionStart);
|
|
1486
|
-
handle.visible = this.dragging;
|
|
1487
|
-
|
|
1488
|
-
} else if (handle.name === 'END') {
|
|
1489
|
-
|
|
1490
|
-
handle.transform.position.copy(this.worldPosition);
|
|
1491
|
-
handle.visible = this.dragging;
|
|
1492
|
-
|
|
1493
|
-
} else if (handle.name === 'DELTA') {
|
|
1494
|
-
|
|
1495
|
-
handle.transform.position.copy(this.worldPositionStart);
|
|
1496
|
-
handle.transform.rotation.copy(this.worldQuaternionStart);
|
|
1497
|
-
_tempVector.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1);
|
|
1498
|
-
_tempVector.applyQuaternion(this.worldQuaternionStart.clone().invert());
|
|
1499
|
-
handle.transform.scale.copy(_tempVector);
|
|
1500
|
-
handle.visible = this.dragging;
|
|
1501
|
-
|
|
1502
|
-
} else {
|
|
1503
|
-
|
|
1504
|
-
handle.transform.rotation.copy(quaternion);
|
|
1505
|
-
|
|
1506
|
-
if (this.dragging) {
|
|
1507
|
-
|
|
1508
|
-
handle.transform.position.copy(this.worldPositionStart);
|
|
1509
|
-
|
|
1510
|
-
} else {
|
|
1511
|
-
|
|
1512
|
-
handle.transform.position.copy(this.worldPosition);
|
|
1513
|
-
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
if (this.axis) {
|
|
1517
|
-
|
|
1518
|
-
handle.visible = this.axis.search(handle.name) !== -1;
|
|
1519
|
-
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
// If updating helper, skip rest of the loop
|
|
1525
|
-
continue;
|
|
1526
|
-
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
// Align handles to current local or world rotation
|
|
1530
|
-
|
|
1531
|
-
handle.transform.rotation.copy(quaternion);
|
|
1532
|
-
|
|
1533
|
-
if (this.mode === TransformMode.Translate || this.mode === TransformMode.Scale) {
|
|
1534
|
-
|
|
1535
|
-
// Hide translate and scale axis facing the camera
|
|
1536
|
-
|
|
1537
|
-
const AXIS_HIDE_TRESHOLD = 0.99;
|
|
1538
|
-
const PLANE_HIDE_TRESHOLD = 0.2;
|
|
1539
|
-
|
|
1540
|
-
if (handle.name === 'X') {
|
|
1541
|
-
|
|
1542
|
-
if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
|
|
1543
|
-
|
|
1544
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1545
|
-
handle.visible = false;
|
|
1546
|
-
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
if (handle.name === 'Y') {
|
|
1552
|
-
|
|
1553
|
-
if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
|
|
1554
|
-
|
|
1555
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1556
|
-
handle.visible = false;
|
|
1557
|
-
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
if (handle.name === 'Z') {
|
|
1563
|
-
|
|
1564
|
-
if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
|
|
1565
|
-
|
|
1566
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1567
|
-
handle.visible = false;
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
if (handle.name === 'XY') {
|
|
1574
|
-
|
|
1575
|
-
if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
|
|
1576
|
-
|
|
1577
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1578
|
-
handle.visible = false;
|
|
1579
|
-
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
if (handle.name === 'YZ') {
|
|
1585
|
-
|
|
1586
|
-
if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
|
|
1587
|
-
|
|
1588
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1589
|
-
handle.visible = false;
|
|
1590
|
-
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
if (handle.name === 'XZ') {
|
|
1596
|
-
|
|
1597
|
-
if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
|
|
1598
|
-
|
|
1599
|
-
handle.transform.scale.set(1e-10, 1e-10, 1e-10);
|
|
1600
|
-
handle.visible = false;
|
|
1601
|
-
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
} else if (this.mode === TransformMode.Rotate) {
|
|
1607
|
-
|
|
1608
|
-
// Align handles to current local or world rotation
|
|
1609
|
-
|
|
1610
|
-
_tempQuaternion2.copy(quaternion);
|
|
1611
|
-
_alignVector.copy(this.eye).applyQuaternion(_tempQuaternion.copy(quaternion).invert());
|
|
1612
|
-
|
|
1613
|
-
if (handle.name.search('E') !== -1) {
|
|
1614
|
-
|
|
1615
|
-
handle.transform.rotation.setFromRotationMatrix(_lookAtMatrix.lookAt(this.eye, _zeroVector, _unitY));
|
|
1616
|
-
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
if (handle.name === 'X') {
|
|
1620
|
-
|
|
1621
|
-
_tempQuaternion.setFromAxisAngle(_unitX, Math.atan2(-_alignVector.y, _alignVector.z));
|
|
1622
|
-
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1623
|
-
handle.transform.rotation.copy(_tempQuaternion);
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
if (handle.name === 'Y') {
|
|
1628
|
-
|
|
1629
|
-
_tempQuaternion.setFromAxisAngle(_unitY, Math.atan2(_alignVector.x, _alignVector.z));
|
|
1630
|
-
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1631
|
-
handle.transform.rotation.copy(_tempQuaternion);
|
|
1632
|
-
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
if (handle.name === 'Z') {
|
|
1636
|
-
|
|
1637
|
-
_tempQuaternion.setFromAxisAngle(_unitZ, Math.atan2(_alignVector.y, _alignVector.x));
|
|
1638
|
-
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1639
|
-
handle.transform.rotation.copy(_tempQuaternion);
|
|
1640
|
-
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
// Hide disabled axes
|
|
1646
|
-
handle.visible = handle.visible && (handle.name.indexOf('X') === -1 || this.showX);
|
|
1647
|
-
handle.visible = handle.visible && (handle.name.indexOf('Y') === -1 || this.showY);
|
|
1648
|
-
handle.visible = handle.visible && (handle.name.indexOf('Z') === -1 || this.showZ);
|
|
1649
|
-
handle.visible = handle.visible && (handle.name.indexOf('E') === -1 || (this.showX && this.showY && this.showZ));
|
|
1650
|
-
|
|
1651
|
-
// highlight selected axis
|
|
1652
|
-
const sg = handle.entity.getComponent(ShadedGeometry);
|
|
1653
|
-
|
|
1654
|
-
sg.material._color = sg.material._color || sg.material.color.clone();
|
|
1655
|
-
sg.material._opacity = sg.material._opacity || sg.material.opacity;
|
|
1656
|
-
|
|
1657
|
-
sg.material.color.copy(sg.material._color);
|
|
1658
|
-
sg.material.opacity = sg.material._opacity;
|
|
1659
|
-
|
|
1660
|
-
if (this.enabled && this.axis) {
|
|
1661
|
-
|
|
1662
|
-
if (handle.name === this.axis) {
|
|
1663
|
-
|
|
1664
|
-
sg.material.color.setHex(0xffff00);
|
|
1665
|
-
sg.material.opacity = 1.0;
|
|
1666
|
-
|
|
1667
|
-
} else if (this.axis.split('').some(function (a) {
|
|
1668
|
-
|
|
1669
|
-
return handle.name === a;
|
|
1670
|
-
|
|
1671
|
-
})) {
|
|
1672
|
-
|
|
1673
|
-
sg.material.color.setHex(0xffff00);
|
|
1674
|
-
sg.material.opacity = 1.0;
|
|
1675
|
-
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
super.update();
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
//
|
|
1688
|
-
|
|
1689
|
-
class TransformControlsPlane extends GizmoNode {
|
|
1690
|
-
|
|
1691
|
-
constructor() {
|
|
1692
|
-
|
|
1693
|
-
super();
|
|
1694
|
-
|
|
1695
|
-
this.entity.add(ShadedGeometry.from(new PlaneGeometry(100000, 100000, 2, 2),
|
|
1696
|
-
new MeshBasicMaterial({
|
|
1697
|
-
visible: false,
|
|
1698
|
-
wireframe: true,
|
|
1699
|
-
side: DoubleSide,
|
|
1700
|
-
transparent: true,
|
|
1701
|
-
opacity: 0.1,
|
|
1702
|
-
toneMapped: false
|
|
1703
|
-
})));
|
|
1704
|
-
|
|
1705
|
-
this.isTransformControlsPlane = true;
|
|
1706
|
-
|
|
1707
|
-
this.type = 'TransformControlsPlane';
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
update() {
|
|
1711
|
-
|
|
1712
|
-
let space = this.space;
|
|
1713
|
-
|
|
1714
|
-
const transform = this.transform;
|
|
1715
|
-
|
|
1716
|
-
transform.position.copy(this.worldPosition);
|
|
1717
|
-
|
|
1718
|
-
if (this.mode === TransformMode.Scale) space = 'local'; // scale always oriented to local rotation
|
|
1719
|
-
|
|
1720
|
-
_v1.copy(_unitX).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
|
|
1721
|
-
_v2.copy(_unitY).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
|
|
1722
|
-
_v3.copy(_unitZ).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
|
|
1723
|
-
|
|
1724
|
-
// Align the plane for current transform mode, axis and space.
|
|
1725
|
-
|
|
1726
|
-
_alignVector.copy(_v2);
|
|
1727
|
-
|
|
1728
|
-
switch (this.mode) {
|
|
1729
|
-
|
|
1730
|
-
case TransformMode.Translate:
|
|
1731
|
-
case TransformMode.Scale:
|
|
1732
|
-
switch (this.axis) {
|
|
1733
|
-
|
|
1734
|
-
case 'X':
|
|
1735
|
-
_alignVector.copy(this.eye).cross(_v1);
|
|
1736
|
-
_dirVector.copy(_v1).cross(_alignVector);
|
|
1737
|
-
break;
|
|
1738
|
-
case 'Y':
|
|
1739
|
-
_alignVector.copy(this.eye).cross(_v2);
|
|
1740
|
-
_dirVector.copy(_v2).cross(_alignVector);
|
|
1741
|
-
break;
|
|
1742
|
-
case 'Z':
|
|
1743
|
-
_alignVector.copy(this.eye).cross(_v3);
|
|
1744
|
-
_dirVector.copy(_v3).cross(_alignVector);
|
|
1745
|
-
break;
|
|
1746
|
-
case 'XY':
|
|
1747
|
-
_dirVector.copy(_v3);
|
|
1748
|
-
break;
|
|
1749
|
-
case 'YZ':
|
|
1750
|
-
_dirVector.copy(_v1);
|
|
1751
|
-
break;
|
|
1752
|
-
case 'XZ':
|
|
1753
|
-
_alignVector.copy(_v3);
|
|
1754
|
-
_dirVector.copy(_v2);
|
|
1755
|
-
break;
|
|
1756
|
-
case 'XYZ':
|
|
1757
|
-
case 'E':
|
|
1758
|
-
_dirVector.set(0, 0, 0);
|
|
1759
|
-
break;
|
|
1760
|
-
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
break;
|
|
1764
|
-
case TransformMode.Rotate:
|
|
1765
|
-
default:
|
|
1766
|
-
// special case for rotate
|
|
1767
|
-
_dirVector.set(0, 0, 0);
|
|
1768
|
-
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
if (_dirVector.length() === 0) {
|
|
1772
|
-
|
|
1773
|
-
// If in rotate mode, make the plane parallel to camera
|
|
1774
|
-
transform.rotation.copy(this.cameraQuaternion);
|
|
1775
|
-
|
|
1776
|
-
} else {
|
|
1777
|
-
|
|
1778
|
-
_tempMatrix.lookAt(_tempVector.set(0, 0, 0), _dirVector, _alignVector);
|
|
1779
|
-
|
|
1780
|
-
transform.rotation.setFromRotationMatrix(_tempMatrix);
|
|
1781
|
-
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
super.update();
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
export { TransformControls, TransformControlsGizmo, TransformControlsPlane };
|
|
819
|
+
export { TransformControls };
|