diff --git a/lroom_converter.cpp b/lroom_converter.cpp index 2d4bffc..b5dba4e 100644 --- a/lroom_converter.cpp +++ b/lroom_converter.cpp @@ -378,27 +378,8 @@ bool LRoomConverter::Bound_AddPlaneIfUnique(LVector &planes, const Plane return true; } -bool LRoomConverter::Convert_Bound(LRoom &lroom, MeshInstance * pMI) +bool LRoomConverter::Convert_Bound_FromPoints(LRoom &lroom, const Vector &points) { - LPRINT(2, "\tCONVERT_BOUND : '" + pMI->get_name() + "' for room '" + lroom.get_name() + "'"); - - // some godot jiggery pokery to get the mesh verts in local space - Ref rmesh = pMI->get_mesh(); - Array arrays = rmesh->surface_get_arrays(0); - PoolVector p_vertices = arrays[VS::ARRAY_VERTEX]; - - // convert to world space - Transform trans = pMI->get_global_transform(); - Vector points; - for (int n=0; n 3) { Geometry::MeshData md; @@ -436,6 +417,39 @@ bool LRoomConverter::Convert_Bound(LRoom &lroom, MeshInstance * pMI) return false; } + +void LRoomConverter::GetWorldVertsFromMesh(const MeshInstance &mi, Vector &pts) const +{ + // some godot jiggery pokery to get the mesh verts in local space + Ref rmesh = mi.get_mesh(); + Array arrays = rmesh->surface_get_arrays(0); + PoolVector p_vertices = arrays[VS::ARRAY_VERTEX]; + + // convert to world space + Transform trans = mi.get_global_transform(); + + for (int n=0; nget_name() + "' for room '" + lroom.get_name() + "'"); + + Vector points; + GetWorldVertsFromMesh(*pMI, points); + for (int n=0; n(pChild); assert (pMesh); - Convert_Bound(lroom, pMesh); + Convert_ManualBound(lroom, pMesh); // delete the mesh pGRoom->remove_child(pChild); @@ -894,10 +908,38 @@ void LRoomConverter::Convert_Bounds() } } + // if no manual bound is found, we will create one by using qhull on all the points + if (!lroom.m_Bound.IsActive()) + { + Vector pts; + Bound_FindPoints_Recursive(pGRoom, pts); + + LPRINT(2, "\tCONVERT_AUTO_BOUND room : '" + lroom.get_name() + "' (" + itos(pts.size()) + " verts)"); + + // use qhull + Convert_Bound_FromPoints(lroom, pts); + } } } +void LRoomConverter::Bound_FindPoints_Recursive(Node * pNode, Vector &pts) +{ + // is it a mesh instance? + MeshInstance * pMI = Object::cast_to(pNode); + if (pMI) + { + // get the points in world space + GetWorldVertsFromMesh(*pMI, pts); + } + + for (int n=0; nget_child_count(); n++) + { + Node * pChild = pNode->get_child(n); + Bound_FindPoints_Recursive(pChild, pts); + } +} + void LRoomConverter::Convert_Portals() { for (int pass=0; pass<3; pass++) diff --git a/lroom_converter.h b/lroom_converter.h index d35f997..a8e29be 100644 --- a/lroom_converter.h +++ b/lroom_converter.h @@ -97,7 +97,10 @@ private: void Convert_Portals(); void Convert_Bounds(); - bool Convert_Bound(LRoom &lroom, MeshInstance * pMI); + bool Convert_ManualBound(LRoom &lroom, MeshInstance * pMI); + void GetWorldVertsFromMesh(const MeshInstance &mi, Vector &pts) const; + void Bound_FindPoints_Recursive(Node * pNode, Vector &pts); + bool Convert_Bound_FromPoints(LRoom &lroom, const Vector &points); void Convert_ShadowCasters(); void Convert_Lights(); void Convert_AreaLights();