Removing bounding box calculations from 3D scene drag and drop and collide against physics rather than visual geometry.
(cherry picked from commit fbda490d0f
)
This commit is contained in:
parent
6a6b6fa5cb
commit
462231e297
1 changed files with 6 additions and 48 deletions
|
@ -3448,58 +3448,16 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const
|
|||
Vector3 world_ray = _get_ray(p_pos);
|
||||
Vector3 world_pos = _get_ray_pos(p_pos);
|
||||
|
||||
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world()->get_scenario());
|
||||
Set<Ref<EditorSpatialGizmo>> found_gizmos;
|
||||
|
||||
float closest_dist = MAX_DISTANCE;
|
||||
|
||||
Vector3 point = world_pos + world_ray * MAX_DISTANCE;
|
||||
Vector3 normal = Vector3(0.0, 0.0, 0.0);
|
||||
|
||||
for (int i = 0; i < instances.size(); i++) {
|
||||
MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(ObjectDB::get_instance(instances[i]));
|
||||
PhysicsDirectSpaceState *ss = get_tree()->get_root()->get_world()->get_direct_space_state();
|
||||
PhysicsDirectSpaceState::RayResult result;
|
||||
|
||||
if (!mesh_instance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Ref<EditorSpatialGizmo> seg = mesh_instance->get_gizmo();
|
||||
|
||||
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
found_gizmos.insert(seg);
|
||||
|
||||
Vector3 hit_point;
|
||||
Vector3 hit_normal;
|
||||
bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal, nullptr, false);
|
||||
|
||||
if (!inters) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist = world_pos.distance_to(hit_point);
|
||||
|
||||
if (dist < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dist < closest_dist) {
|
||||
closest_dist = dist;
|
||||
point = hit_point;
|
||||
normal = hit_normal;
|
||||
}
|
||||
if (ss->intersect_ray(world_pos, world_pos + world_ray * MAX_DISTANCE, result)) {
|
||||
point = result.position;
|
||||
}
|
||||
Vector3 offset = Vector3();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (normal[i] > 0.0) {
|
||||
offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i]));
|
||||
} else if (normal[i] < 0.0) {
|
||||
offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]);
|
||||
}
|
||||
}
|
||||
return point + offset;
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform) {
|
||||
|
|
Loading…
Reference in a new issue