diff options
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 141 |
1 files changed, 136 insertions, 5 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 8c90d86b9e..2652b09763 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -299,13 +299,24 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi } } -void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size) { +void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position) { ERR_FAIL_COND(!spatial_node); CubeMesh cubem; cubem.set_size(p_size); + + Array arrays = cubem.surface_get_arrays(0); + PoolVector3Array vertex = arrays[VS::ARRAY_VERTEX]; + PoolVector3Array::Write w = vertex.write(); + + for (int i = 0; i < vertex.size(); ++i) { + w[i] += p_position; + } + + arrays[VS::ARRAY_VERTEX] = vertex; + Ref<ArrayMesh> m = memnew(ArrayMesh); - m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), cubem.surface_get_arrays(0)); + m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), arrays); m->surface_set_material(0, p_material); add_mesh(m); } @@ -1523,6 +1534,120 @@ SkeletonSpatialGizmo::SkeletonSpatialGizmo(Skeleton *p_skel) { set_spatial_node(p_skel); } +PhysicalBoneSpatialGizmo::PhysicalBoneSpatialGizmo(PhysicalBone *p_pb) : + EditorSpatialGizmo(), + physical_bone(p_pb) { + set_spatial_node(p_pb); +} + +void PhysicalBoneSpatialGizmo::redraw() { + + clear(); + + if (!physical_bone) + return; + + Skeleton *sk(physical_bone->find_skeleton_parent()); + PhysicalBone *pb(sk->get_physical_bone(physical_bone->get_bone_id())); + PhysicalBone *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id())); + + Vector<Vector3> points; + + switch (physical_bone->get_joint_type()) { + case PhysicalBone::JOINT_TYPE_PIN: { + + PinJointSpatialGizmo::CreateGizmo(physical_bone->get_joint_offset(), points); + } break; + case PhysicalBone::JOINT_TYPE_CONE: { + + const PhysicalBone::ConeJointData *cjd(static_cast<const PhysicalBone::ConeJointData *>(physical_bone->get_joint_data())); + ConeTwistJointSpatialGizmo::CreateGizmo( + physical_bone->get_joint_offset(), + physical_bone->get_global_transform() * physical_bone->get_joint_offset(), + pb ? pb->get_global_transform() : Transform(), + pbp ? pbp->get_global_transform() : Transform(), + cjd->swing_span, + cjd->twist_span, + points, + pb ? &points : NULL, + pbp ? &points : NULL); + } break; + case PhysicalBone::JOINT_TYPE_HINGE: { + + const PhysicalBone::HingeJointData *hjd(static_cast<const PhysicalBone::HingeJointData *>(physical_bone->get_joint_data())); + HingeJointSpatialGizmo::CreateGizmo( + physical_bone->get_joint_offset(), + physical_bone->get_global_transform() * physical_bone->get_joint_offset(), + pb ? pb->get_global_transform() : Transform(), + pbp ? pbp->get_global_transform() : Transform(), + hjd->angular_limit_lower, + hjd->angular_limit_upper, + hjd->angular_limit_enabled, + points, + pb ? &points : NULL, + pbp ? &points : NULL); + } break; + case PhysicalBone::JOINT_TYPE_SLIDER: { + + const PhysicalBone::SliderJointData *sjd(static_cast<const PhysicalBone::SliderJointData *>(physical_bone->get_joint_data())); + SliderJointSpatialGizmo::CreateGizmo( + physical_bone->get_joint_offset(), + physical_bone->get_global_transform() * physical_bone->get_joint_offset(), + pb ? pb->get_global_transform() : Transform(), + pbp ? pbp->get_global_transform() : Transform(), + sjd->angular_limit_lower, + sjd->angular_limit_upper, + sjd->linear_limit_lower, + sjd->linear_limit_upper, + points, + pb ? &points : NULL, + pbp ? &points : NULL); + } break; + case PhysicalBone::JOINT_TYPE_6DOF: { + + const PhysicalBone::SixDOFJointData *sdofjd(static_cast<const PhysicalBone::SixDOFJointData *>(physical_bone->get_joint_data())); + Generic6DOFJointSpatialGizmo::CreateGizmo( + physical_bone->get_joint_offset(), + + physical_bone->get_global_transform() * physical_bone->get_joint_offset(), + pb ? pb->get_global_transform() : Transform(), + pbp ? pbp->get_global_transform() : Transform(), + + sdofjd->axis_data[0].angular_limit_lower, + sdofjd->axis_data[0].angular_limit_upper, + sdofjd->axis_data[0].linear_limit_lower, + sdofjd->axis_data[0].linear_limit_upper, + sdofjd->axis_data[0].angular_limit_enabled, + sdofjd->axis_data[0].linear_limit_enabled, + + sdofjd->axis_data[1].angular_limit_lower, + sdofjd->axis_data[1].angular_limit_upper, + sdofjd->axis_data[1].linear_limit_lower, + sdofjd->axis_data[1].linear_limit_upper, + sdofjd->axis_data[1].angular_limit_enabled, + sdofjd->axis_data[1].linear_limit_enabled, + + sdofjd->axis_data[2].angular_limit_lower, + sdofjd->axis_data[2].angular_limit_upper, + sdofjd->axis_data[2].linear_limit_lower, + sdofjd->axis_data[2].linear_limit_upper, + sdofjd->axis_data[2].angular_limit_enabled, + sdofjd->axis_data[2].linear_limit_enabled, + + points, + pb ? &points : NULL, + pbp ? &points : NULL); + } break; + default: + return; + } + + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); + + add_collision_segments(points); + add_lines(points, material); +} + // FIXME: Kept as reference for reimplementation in 3.1+ #if 0 void RoomSpatialGizmo::redraw() { @@ -2411,7 +2536,7 @@ void ParticlesGizmo::redraw() { gizmo_color.a = 0.1; Ref<Material> solid_material = create_material("particles_solid_material", gizmo_color); - add_solid_box(solid_material, aabb.get_size()); + add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0); } //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); @@ -3724,6 +3849,12 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return lsg; } + if (Object::cast_to<PhysicalBone>(p_spatial)) { + + Ref<PhysicalBoneSpatialGizmo> pbsg = memnew(PhysicalBoneSpatialGizmo(Object::cast_to<PhysicalBone>(p_spatial))); + return pbsg; + } + if (Object::cast_to<Position3D>(p_spatial)) { Ref<Position3DSpatialGizmo> lsg = memnew(Position3DSpatialGizmo(Object::cast_to<Position3D>(p_spatial))); @@ -4052,9 +4183,9 @@ SpatialEditorGizmos::SpatialEditorGizmos() { for (int k = 0; k < 3; k++) { if (i < 3) - face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); + face_points[j][(i + k) % 3] = v[k]; else - face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); + face_points[3 - j][(i + k) % 3] = -v[k]; } } //tri 1 |