From fc3c01db0f1a9559a1823733a62e12e4821b518a Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sun, 8 Aug 2021 15:43:24 +0100 Subject: [PATCH] Portals - add support for Sprite3D Add support for Sprite3D and animated Sprite3D. --- scene/3d/room_manager.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/scene/3d/room_manager.cpp b/scene/3d/room_manager.cpp index e305584634..a8e99fc4af 100644 --- a/scene/3d/room_manager.cpp +++ b/scene/3d/room_manager.cpp @@ -41,6 +41,7 @@ #include "room_group.h" #include "scene/3d/camera.h" #include "scene/3d/light.h" +#include "scene/3d/sprite_3d.h" #include "visibility_notifier.h" #ifdef TOOLS_ENABLED @@ -1728,11 +1729,11 @@ bool RoomManager::_bound_findpoints_geom_instance(GeometryInstance *p_gi, Vector // convert to world space for (int n = 0; n < vertices.size(); n++) { - Vector3 ptWorld = trans.xform(vertices[n]); - r_room_pts.push_back(ptWorld); + Vector3 pt_world = trans.xform(vertices[n]); + r_room_pts.push_back(pt_world); // keep the bound up to date - r_aabb.expand_to(ptWorld); + r_aabb.expand_to(pt_world); } } // for through the surfaces @@ -1788,16 +1789,37 @@ bool RoomManager::_bound_findpoints_geom_instance(GeometryInstance *p_gi, Vector trans = mmi->get_global_transform() * trans; for (int n = 0; n < local_verts.size(); n++) { - Vector3 ptWorld = trans.xform(local_verts[n]); - r_room_pts.push_back(ptWorld); + Vector3 pt_world = trans.xform(local_verts[n]); + r_room_pts.push_back(pt_world); // keep the bound up to date - r_aabb.expand_to(ptWorld); + r_aabb.expand_to(pt_world); } } return true; } + // Sprite3D + SpriteBase3D *sprite = Object::cast_to(p_gi); + if (sprite) { + Ref tmesh = sprite->generate_triangle_mesh(); + PoolVector vertices = tmesh->get_vertices(); + + // for converting meshes to world space + Transform trans = p_gi->get_global_transform(); + + // convert to world space + for (int n = 0; n < vertices.size(); n++) { + Vector3 pt_world = trans.xform(vertices[n]); + r_room_pts.push_back(pt_world); + + // keep the bound up to date + r_aabb.expand_to(pt_world); + } + + return true; + } + return false; }