|
66 | 66 | joint.isBoneIndicator = true; |
67 | 67 | joint.renderOrder = RENDER_ORDER_BONE; |
68 | 68 |
|
69 | | - scene.add(arrow, axes, joint); |
| 69 | + three_grid.add(arrow, axes, joint); |
70 | 70 | return { arrow, axes, joint }; |
71 | 71 | } |
72 | 72 |
|
73 | 73 | function disposeIndicators(entry) { |
74 | 74 | if (!entry) return; |
75 | | - scene.remove(entry.arrow, entry.axes, entry.joint); |
| 75 | + three_grid.remove(entry.arrow, entry.axes, entry.joint); |
76 | 76 | } |
77 | 77 |
|
78 | 78 | function ensureFor(group) { |
|
116 | 116 |
|
117 | 117 | const parentPos = new THREE.Vector3(); |
118 | 118 | parentGroup.mesh.getWorldPosition(parentPos); |
119 | | - const length = worldPos.distanceTo(parentPos); |
120 | | - if (length <= 0.001) { |
121 | | - return { worldPos, worldQuat, valid: false }; |
122 | | - } |
123 | | - |
124 | | - const dir = new THREE.Vector3().subVectors(parentPos, worldPos).normalize(); |
125 | | - return { worldPos, worldQuat, dir, length, parentPos, valid: true }; |
| 119 | + |
| 120 | + return { worldPos, worldQuat, parentPos, valid: true }; |
126 | 121 | } |
127 | 122 |
|
128 | 123 | function updateTransforms() { |
129 | 124 | ResourceManager.updateColors(); |
130 | 125 | const active = pluginAction && pluginAction.value; |
131 | | - // offset by root x,y,z |
132 | | - const rootOffset = new THREE.Vector3(0, 0, 0); |
133 | | - if (Group.all.length) { |
134 | | - var group = Group.all[0]; |
135 | | - var origin = group.origin; |
136 | | - rootOffset.set(origin[0], origin[1], origin[2]); |
137 | | - } |
| 126 | + |
| 127 | + const inverseParentMatrix = new THREE.Matrix4(); |
| 128 | + three_grid.updateWorldMatrix(true, false); |
| 129 | + inverseParentMatrix.copy(three_grid.matrixWorld).invert(); |
| 130 | + |
| 131 | + const parentWorldQuat = new THREE.Quaternion(); |
| 132 | + three_grid.getWorldQuaternion(parentWorldQuat); |
| 133 | + const inverseParentQuat = parentWorldQuat.clone().invert(); |
138 | 134 |
|
139 | 135 | for (const group of Group.all) { |
140 | 136 | const entry = ensureFor(group); |
|
153 | 149 | entry.joint.visible = false; |
154 | 150 | continue; |
155 | 151 | } |
| 152 | + |
| 153 | + const localPos = data.worldPos.clone().applyMatrix4(inverseParentMatrix); |
| 154 | + const parentLocalPos = data.parentPos.clone().applyMatrix4(inverseParentMatrix); |
| 155 | + const localQuat = inverseParentQuat.clone().multiply(data.worldQuat); |
156 | 156 |
|
157 | | - const offsetWorldPos = new THREE.Vector3().copy(data.worldPos).add(rootOffset); |
| 157 | + const length = localPos.distanceTo(parentLocalPos); |
| 158 | + if (length <= 0.001) { |
| 159 | + entry.arrow.visible = false; |
| 160 | + entry.axes.visible = false; |
| 161 | + entry.joint.visible = false; |
| 162 | + continue; |
| 163 | + } |
| 164 | + const dir = new THREE.Vector3().subVectors(parentLocalPos, localPos).normalize(); |
158 | 165 |
|
159 | 166 | entry.axes.visible = true; |
160 | | - entry.axes.position.copy(offsetWorldPos); |
161 | | - entry.axes.quaternion.copy(data.worldQuat); |
| 167 | + entry.axes.position.copy(localPos); |
| 168 | + entry.axes.quaternion.copy(localQuat); |
162 | 169 |
|
163 | 170 | entry.joint.visible = true; |
164 | | - entry.joint.position.copy(offsetWorldPos); |
| 171 | + entry.joint.position.copy(localPos); |
165 | 172 |
|
166 | 173 | entry.arrow.visible = true; |
167 | | - const qToDir = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 1, 0), data.dir); |
| 174 | + const qToDir = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 1, 0), dir); |
168 | 175 | entry.arrow.quaternion.copy(qToDir); |
169 | 176 |
|
170 | | - const mid = new THREE.Vector3().copy(offsetWorldPos).addScaledVector(data.dir, data.length / 2); |
| 177 | + const mid = new THREE.Vector3().copy(localPos).addScaledVector(dir, length / 2); |
171 | 178 | entry.arrow.position.copy(mid); |
172 | 179 |
|
173 | | - entry.arrow.scale.set(BONE_RADIUS, data.length, BONE_RADIUS); |
| 180 | + entry.arrow.scale.set(BONE_RADIUS, length, BONE_RADIUS); |
174 | 181 | } |
175 | 182 | } |
176 | 183 |
|
|
0 commit comments