mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Implement global rest
This commit is contained in:
parent
690fefe43e
commit
4d4ffa3a2c
4 changed files with 37 additions and 16 deletions
|
|
@ -1283,9 +1283,6 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
surface_tool->set_material(unselected_mat);
|
||||
}
|
||||
|
||||
Vector<Transform3D> grests;
|
||||
grests.resize(skeleton->get_bone_count());
|
||||
|
||||
LocalVector<int> bones;
|
||||
LocalVector<float> weights;
|
||||
bones.resize(4);
|
||||
|
|
@ -1309,11 +1306,6 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
child_bones_vector = skeleton->get_bone_children(current_bone_idx);
|
||||
int child_bones_size = child_bones_vector.size();
|
||||
|
||||
// You have children but no parent, then you must be a root/parentless bone.
|
||||
if (skeleton->get_bone_parent(current_bone_idx) < 0) {
|
||||
grests.write[current_bone_idx] = skeleton->get_bone_rest(current_bone_idx);
|
||||
}
|
||||
|
||||
for (int i = 0; i < child_bones_size; i++) {
|
||||
// Something wrong.
|
||||
if (child_bones_vector[i] < 0) {
|
||||
|
|
@ -1322,10 +1314,8 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
|
||||
int child_bone_idx = child_bones_vector[i];
|
||||
|
||||
grests.write[child_bone_idx] = grests[current_bone_idx] * skeleton->get_bone_rest(child_bone_idx);
|
||||
|
||||
Vector3 v0 = grests[current_bone_idx].origin;
|
||||
Vector3 v1 = grests[child_bone_idx].origin;
|
||||
Vector3 v0 = skeleton->get_bone_global_rest(current_bone_idx).origin;
|
||||
Vector3 v1 = skeleton->get_bone_global_rest(child_bone_idx).origin;
|
||||
Vector3 d = (v1 - v0).normalized();
|
||||
real_t dist = v0.distance_to(v1);
|
||||
|
||||
|
|
@ -1333,7 +1323,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
int closest = -1;
|
||||
real_t closest_d = 0.0;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
real_t dp = Math::abs(grests[current_bone_idx].basis[j].normalized().dot(d));
|
||||
real_t dp = Math::abs(skeleton->get_bone_global_rest(current_bone_idx).basis[j].normalized().dot(d));
|
||||
if (j == 0 || dp > closest_d) {
|
||||
closest = j;
|
||||
}
|
||||
|
|
@ -1360,7 +1350,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
for (int j = 0; j < 3; j++) {
|
||||
Vector3 axis;
|
||||
if (first == Vector3()) {
|
||||
axis = d.cross(d.cross(grests[current_bone_idx].basis[j])).normalized();
|
||||
axis = d.cross(d.cross(skeleton->get_bone_global_rest(current_bone_idx).basis[j])).normalized();
|
||||
first = axis;
|
||||
} else {
|
||||
axis = d.cross(first).normalized();
|
||||
|
|
@ -1415,7 +1405,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
surface_tool->add_vertex(v0);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->add_vertex(v0 + (grests[current_bone_idx].basis.inverse())[j].normalized() * dist * bone_axis_length);
|
||||
surface_tool->add_vertex(v0 + (skeleton->get_bone_global_rest(current_bone_idx).basis.inverse())[j].normalized() * dist * bone_axis_length);
|
||||
|
||||
if (j == closest) {
|
||||
continue;
|
||||
|
|
@ -1432,7 +1422,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
surface_tool->add_vertex(v1);
|
||||
surface_tool->set_bones(bones);
|
||||
surface_tool->set_weights(weights);
|
||||
surface_tool->add_vertex(v1 + (grests[child_bone_idx].basis.inverse())[j].normalized() * dist * bone_axis_length);
|
||||
surface_tool->add_vertex(v1 + (skeleton->get_bone_global_rest(child_bone_idx).basis.inverse())[j].normalized() * dist * bone_axis_length);
|
||||
|
||||
if (j == closest) {
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue