From 787b8be82c1a5d6183308596c8ae865a6f858092 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 4 Mar 2018 15:10:44 -0600 Subject: [PATCH] Adds handling for the proper updated exporting of mesh for convexShapes --- Engine/source/T3D/convexShape.cpp | 51 +++++++++++++++++++++++ Engine/source/T3D/convexShape.h | 1 + Engine/source/ts/collada/colladaUtils.cpp | 26 ++++++++++-- Engine/source/ts/collada/colladaUtils.h | 5 +++ 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/Engine/source/T3D/convexShape.cpp b/Engine/source/T3D/convexShape.cpp index b5134be65..ceaa75616 100644 --- a/Engine/source/T3D/convexShape.cpp +++ b/Engine/source/T3D/convexShape.cpp @@ -697,6 +697,57 @@ bool ConvexShape::buildPolyList( PolyListContext context, AbstractPolyList *plis return true; } +bool ConvexShape::buildExportPolyList(PolyListContext context, ColladaUtils::ExportData* exportData, const Box3F &box, const SphereF &) +{ + if (mGeometry.points.empty()) + return false; + + //Get the collision mesh geometry + { + ColladaUtils::ExportData::colMesh* colMesh; + exportData->colMeshes.increment(); + colMesh = &exportData->colMeshes.last(); + + colMesh->mesh.setTransform(&mObjToWorld, mObjScale); + colMesh->mesh.setObject(this); + + //Just get the visible + buildPolyList(PLC_Export, &colMesh->mesh, getWorldBox(), getWorldSphere()); + + colMesh->colMeshName = String::ToString("ColMesh%d-1", exportData->colMeshes.size()); + } + + //Next, process the geometry and materials. + //Convex shapes only have the one 'level', so we'll just rely on the export post-process to back-fill + if (isServerObject() && getClientObject()) + { + ConvexShape* clientShape = dynamic_cast(getClientObject()); + + exportData->meshData.increment(); + + //Prep a meshData for this shape in particular + ColladaUtils::ExportData::meshLODData* meshData = &exportData->meshData.last(); + + //Fill out the info we'll need later to actually append our mesh data for the detail levels during the processing phase + meshData->shapeInst = nullptr; + meshData->originatingObject = this; + meshData->meshTransform = mObjToWorld; + meshData->scale = mObjScale; + meshData->fillWithSingleDetail = true; + + meshData->meshDetailLevels.increment(); + + ColladaUtils::ExportData::detailLevel* curDetail = &meshData->meshDetailLevels.last(); + + //Make sure we denote the size this detail level has + curDetail->size = getNextPow2(getObjBox().len()); + + bool t = true; + } + + return true; +} + void ConvexShape::_export( OptimizedPolyList *plist, const Box3F &box, const SphereF &sphere ) { BaseMatInstance *matInst = mMaterialInst; diff --git a/Engine/source/T3D/convexShape.h b/Engine/source/T3D/convexShape.h index d0f30eeaa..32d0122f5 100644 --- a/Engine/source/T3D/convexShape.h +++ b/Engine/source/T3D/convexShape.h @@ -172,6 +172,7 @@ public: virtual void prepRenderImage( SceneRenderState *state ); virtual void buildConvex( const Box3F &box, Convex *convex ); virtual bool buildPolyList( PolyListContext context, AbstractPolyList *polyList, const Box3F &box, const SphereF &sphere ); + virtual bool buildExportPolyList(PolyListContext context, ColladaUtils::ExportData* exportData, const Box3F &box, const SphereF &); virtual bool castRay( const Point3F &start, const Point3F &end, RayInfo *info ); virtual bool collideBox( const Point3F &start, const Point3F &end, RayInfo *info ); diff --git a/Engine/source/ts/collada/colladaUtils.cpp b/Engine/source/ts/collada/colladaUtils.cpp index 32c559077..8ad5bff9b 100644 --- a/Engine/source/ts/collada/colladaUtils.cpp +++ b/Engine/source/ts/collada/colladaUtils.cpp @@ -26,6 +26,9 @@ #include "ts/collada/colladaUtils.h" #include "materials/matInstance.h" +//special handling for export classes +#include "T3D/convexShape.h" + using namespace ColladaUtils; #define MAX_PATH_LENGTH 256 @@ -2994,10 +2997,27 @@ void ColladaUtils::ExportData::processData() curDetail->mesh.setTransform(&meshData[m].meshTransform, meshData[m].scale); curDetail->mesh.setObject(meshData[m].originatingObject); - if (!meshData[m].shapeInst->buildPolyList(&curDetail->mesh, detailLevelIdx)) + if (meshData[m].shapeInst != nullptr) { - Con::errorf("TSStatic::buildExportPolyList - failed to build polylist for LOD %i", i); - continue; + + if (!meshData[m].shapeInst->buildPolyList(&curDetail->mesh, detailLevelIdx)) + { + Con::errorf("TSStatic::buildExportPolyList - failed to build polylist for LOD %i", i); + continue; + } + } + else + { + //special handling classes + ConvexShape* convexShp = dynamic_cast(meshData[m].originatingObject); + if (convexShp != nullptr) + { + if (!convexShp->buildPolyList(PLC_Export, &curDetail->mesh, meshData[m].originatingObject->getWorldBox(), meshData[m].originatingObject->getWorldSphere())) + { + Con::errorf("TSStatic::buildExportPolyList - failed to build ConvexShape polylist for LOD %i", i); + continue; + } + } } //lastly, get material diff --git a/Engine/source/ts/collada/colladaUtils.h b/Engine/source/ts/collada/colladaUtils.h index 4997a8803..62a453ed3 100644 --- a/Engine/source/ts/collada/colladaUtils.h +++ b/Engine/source/ts/collada/colladaUtils.h @@ -140,6 +140,8 @@ namespace ColladaUtils Point3F scale; + bool fillWithSingleDetail; + S32 hasDetailLevel(S32 size) { for (U32 i = 0; i < meshDetailLevels.size(); ++i) @@ -152,6 +154,9 @@ namespace ColladaUtils return -1; } + + meshLODData() : shapeInst(nullptr), meshTransform(true), originatingObject(nullptr), scale(0), fillWithSingleDetail(false) + {} }; struct colMesh