From e540dbca475322cca7a263dbd8559fa41c27337f Mon Sep 17 00:00:00 2001 From: Tahir Akhlaq Date: Wed, 23 Jan 2019 14:26:17 +0000 Subject: [PATCH] more pcb_reader things --- src/tools/pcb_reader/CMakeLists.txt | 4 +- src/tools/pcb_reader/lgb.h | 49 +++++++++++++++++++++++++ src/tools/pcb_reader/navmesh_exporter.h | 48 ++++++------------------ 3 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/tools/pcb_reader/CMakeLists.txt b/src/tools/pcb_reader/CMakeLists.txt index 96b4af4e..6156b25c 100644 --- a/src/tools/pcb_reader/CMakeLists.txt +++ b/src/tools/pcb_reader/CMakeLists.txt @@ -8,9 +8,9 @@ file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*") add_executable(pcb_reader2 ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES}) if (UNIX) - target_link_libraries( pcb_reader2 common xivdat pthread mysqlclient dl z stdc++fs Recast Detour ) + target_link_libraries( pcb_reader2 common xivdat pthread mysqlclient dl z stdc++fs Recast Detour DetourTileCache ) else() - target_link_libraries( pcb_reader2 common xivdat mysql zlib Recast Detour ) + target_link_libraries( pcb_reader2 common xivdat mysql zlib Recast Detour DetourTileCache ) endif() target_include_directories( pcb_reader2 diff --git a/src/tools/pcb_reader/lgb.h b/src/tools/pcb_reader/lgb.h index 21628b68..d59feb2c 100644 --- a/src/tools/pcb_reader/lgb.h +++ b/src/tools/pcb_reader/lgb.h @@ -9,6 +9,10 @@ #include #include +#include +#include +#include + #include "matrix4.h" #include "vec3.h" #include "sgb.h" @@ -238,6 +242,47 @@ public: }; }; +struct LGB_COLLISION_BOX_HEADER : + public LGB_ENTRY_HEADER +{ + uint8_t unk[100]; +}; + +struct LGB_COLLISION_BOX_ENTRY : + public LGB_ENTRY +{ + LGB_COLLISION_BOX_HEADER header; + std::string name; + + LGB_COLLISION_BOX_ENTRY( char* buf, uint32_t offset ) : + LGB_ENTRY( buf, offset ) + { + header = *reinterpret_cast< LGB_COLLISION_BOX_HEADER* >( buf + offset ); + header.type = LgbEntryType::CollisionBox; + name = std::string( buf + offset + header.nameOffset ); + std::stringstream ss; + ss << "\nName: " << name << "Id: " << header.unknown << "\n"; + ss << "Pos: " << header.translation.x << " " << header.translation.y << " " << header.translation.z << "\n"; + ss << "Rot?: " << header.rotation.x << " " << header.rotation.y << " " << header.rotation.z << "\n"; + ss << "Scale?: " << header.scale.x << " " << header.scale.y << " " << header.scale.z << "\n"; + ss << "00 01 02 03 04 05 06 07 | 08 09 0A 0B 0C 0D 0E 0F\n"; + ss << "-------------------------------------------------\n"; + ss << std::hex; + ss << std::setw( 2 ); + ss << std::setfill( '0' ); + + for( auto i = 1; i < sizeof( header.unk ); ++i ) + if( i % 16 == 0 ) + ss << std::setw(2) << (int)header.unk[i - 1] << "\n"; + else if( i % 8 == 0 ) + ss << std::setw(2) << (int)header.unk[i - 1] << " | "; + else + ss << std::setw(2) << (int)header.unk[i - 1] << " "; + ss << "\n"; + std::cout << ss.str(); + } +}; + struct LGB_GROUP_HEADER { uint32_t unknown; @@ -289,7 +334,11 @@ struct LGB_GROUP case LgbEntryType::EventObject: entries.push_back( std::make_shared< LGB_EOBJ_ENTRY >( buf, entryOffset ) ); break; + case LgbEntryType::CollisionBox: + entries.push_back( std::make_shared< LGB_COLLISION_BOX_ENTRY >( buf, entryOffset ) ); + break; default: + //std::cout << "\t\tUnknown SGB entry! Group: " << name << " type: " << ( int )type << " index: " << i << " entryOffset: " << entryOffset << "\n"; break; } } diff --git a/src/tools/pcb_reader/navmesh_exporter.h b/src/tools/pcb_reader/navmesh_exporter.h index e5f2cb5b..7042e9db 100644 --- a/src/tools/pcb_reader/navmesh_exporter.h +++ b/src/tools/pcb_reader/navmesh_exporter.h @@ -11,17 +11,15 @@ #include "exporter.h" #include "obj_exporter.h" -/* +//* #include #include #include #include #include #include -#include -#include -#include -*/ + +//*/ class NavmeshExporter { public: @@ -33,7 +31,8 @@ public: auto fileName = currPath + "/" + zone.name + "/" + zone.name + ".nav"; exportZoneCommandline( zone, deleteObj ); - + //for( auto& group : zone.groups ) + //buildTileMesh(group.second, 0, 0); auto end = std::chrono::high_resolution_clock::now(); printf( "[Navmesh] Finished exporting %s in %u ms\n", fileName.c_str(), @@ -133,13 +132,15 @@ private: for( const auto& mesh : model.second.meshes ) { auto size = mesh.verts.size(); + if (!size) + continue; rcCalcBounds( mesh.verts.data(), size / 3, &cfg.bmin[0], &cfg.bmax[0] ); - verts.reserve( verts.size() + size ); + verts.resize( verts.size() + size ); memcpy( &verts[i], mesh.verts.data(), size ); i += size; size = mesh.indices.size(); - indices.reserve( indices.size() + size ); + indices.resize( indices.size() + size ); for( auto j = 0; j < mesh.indices.size(); j += 3 ) { indices[j] = mesh.indices[j] + numIndices; @@ -150,8 +151,7 @@ private: } } - auto chunkyMesh = new rcChunkyTriMesh; - rcCreateChunkyTriMesh( &verts[0], &indices[0], verts.size() / 3, 256, chunkyMesh ); + if( !rcCreateHeightfield( &ctx, *hf, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch ) ) { @@ -162,33 +162,10 @@ private: tbmax[0] = cfg.bmax[0]; tbmax[1] = cfg.bmax[2]; int cid[512];// TODO: Make grow when returning too many items. - const int ncid = rcGetChunksOverlappingRect(chunkyMesh, tbmin, tbmax, cid, 512); - if (!ncid) - return 0; + auto tileTriCount = 0; - auto triareas = new unsigned char[chunkyMesh->maxTrisPerChunk]; - for (int i = 0; i < ncid; ++i) - { - const rcChunkyTriMeshNode& node = chunkyMesh->nodes[cid[i]]; - const int* ctris = &chunkyMesh->tris[node.i*3]; - const int nctris = node.n; - - tileTriCount += nctris; - - memset(triareas, 0, nctris*sizeof(unsigned char)); - rcMarkWalkableTriangles(&ctx, cfg.walkableSlopeAngle, - &verts[0], verts.size() / 3, ctris, nctris, triareas); - - if (!rcRasterizeTriangles(&ctx, &verts[0], verts.size() / 3, ctris, triareas, nctris, *hf, cfg.walkableClimb)) - return 0; - } - - { - delete [] triareas; - triareas = 0; - } - + // Once all geometry is rasterized, we do initial pass of filtering to // remove unwanted overhangs caused by the conservative rasterization // as well as filter spans where the character cannot possibly stand. @@ -343,7 +320,6 @@ private: cs = 0; } - unsigned char* navData = 0; int navDataSize = 0; if (cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON) {