diff --git a/common/lc_library.cpp b/common/lc_library.cpp index a8664bfc..3d5a2b2c 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -1259,10 +1259,7 @@ bool lcPiecesLibrary::LoadPieceData(PieceInfo* Info) return false; if (Info) - { - Info->mHasLogoStud = MeshData.mHasLogoStud; Info->SetMesh(MeshData.CreateMesh()); - } if (SaveCache) SaveCachePiece(Info); @@ -1583,7 +1580,7 @@ void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload) { PieceInfo* Info = PieceIt.second; - if (Info->mState == LC_PIECEINFO_LOADED && Info->mHasLogoStud) + if (Info->mState == LC_PIECEINFO_LOADED && Info->GetMesh() && Info->GetMesh()->mFlags & lcMeshFlag::HasLogoStud) { Info->Unload(); mLoadQueue.append(Info); @@ -1597,7 +1594,7 @@ void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload) } } -bool lcPiecesLibrary::GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud) +bool lcPiecesLibrary::GetStudLogoFile(lcMemFile& PrimFile, int StudLogo, bool OpenStud) { // validate logo choice and unofficial lib available if (!StudLogo || (!mZipFiles[LC_ZIPFILE_UNOFFICIAL] && !mHasUnofficial)) @@ -1654,22 +1651,23 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive) if (Primitive->mStud) { - if (strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries. - { - char Name[LC_PIECE_NAME_LEN]; - strcpy(Name, "8/"); - strcat(Name, Primitive->mName); - - LowPrimitive = FindPrimitive(Name); - } - bool OpenStud = !strcmp(Primitive->mName,"stud2.dat"); if (OpenStud || !strcmp(Primitive->mName,"stud.dat")) { Primitive->mMeshData.mHasLogoStud = true; if (mStudLogo) - SetStudLogo = GetStudLogo(PrimFile, mStudLogo, OpenStud); + SetStudLogo = GetStudLogoFile(PrimFile, mStudLogo, OpenStud); + } + + if (!SetStudLogo && strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries. + { + char Name[LC_PIECE_NAME_LEN]; + strcpy(Name, "8/"); + strcat(Name, Primitive->mName); + strupr(Name); + + LowPrimitive = FindPrimitive(Name); } } @@ -1706,7 +1704,7 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive) { lcMemFile PrimFile; - if (GetStudLogo(PrimFile, mStudLogo, OpenStud)) + if (GetStudLogoFile(PrimFile, mStudLogo, OpenStud)) SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED); } } diff --git a/common/lc_library.h b/common/lc_library.h index c247055b..9eea8ee7 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -119,10 +119,13 @@ public: bool LoadPrimitive(lcLibraryPrimitive* Primitive); - bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud); - void SetStudLogo(int StudLogo, bool Reload); + int GetStudLogo() const + { + return mStudLogo; + } + void SetOfficialPieces() { if (mZipFiles[LC_ZIPFILE_OFFICIAL]) @@ -169,6 +172,8 @@ protected: bool ReadDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile); bool WriteDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile); + bool GetStudLogoFile(lcMemFile& PrimFile, int StudLogo, bool OpenStud); + QMutex mLoadMutex; QList> mLoadFutures; QList mLoadQueue; diff --git a/common/lc_mesh.cpp b/common/lc_mesh.cpp index 1ad001fe..d66c8ebc 100644 --- a/common/lc_mesh.cpp +++ b/common/lc_mesh.cpp @@ -7,6 +7,9 @@ #include "lc_application.h" #include "lc_library.h" +#define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H') +#define LC_MESH_FILE_VERSION 0x0116 + lcMesh* gPlaceholderMesh; lcMesh::lcMesh() @@ -480,6 +483,9 @@ bool lcMesh::FileSave(lcMemFile& File) int lcMesh::GetLodIndex(float Distance) const { + if (lcGetPiecesLibrary()->GetStudLogo()) + return LC_MESH_LOD_HIGH; + if (mLods[LC_MESH_LOD_LOW].NumSections && (Distance - mRadius) > 250.0f) return LC_MESH_LOD_LOW; else diff --git a/common/lc_mesh.h b/common/lc_mesh.h index a227c247..c84850a6 100644 --- a/common/lc_mesh.h +++ b/common/lc_mesh.h @@ -2,9 +2,6 @@ #include "lc_math.h" -#define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H') -#define LC_MESH_FILE_VERSION 0x0115 - enum lcMeshPrimitiveType { LC_MESH_LINES = 0x01, @@ -60,7 +57,8 @@ enum lcMeshFlag HasSolid = 0x02, // Mesh has triangles using a solid color HasTranslucent = 0x04, // Mesh has triangles using a translucent color HasLines = 0x08, // Mesh has lines - HasTexture = 0x10 // Mesh has sections using textures + HasTexture = 0x10, // Mesh has sections using textures + HasLogoStud = 0x20 // Mesh has a stud that can have a logo applied }; Q_DECLARE_FLAGS(lcMeshFlags, lcMeshFlag) diff --git a/common/lc_meshloader.cpp b/common/lc_meshloader.cpp index 50074538..3c0d846a 100644 --- a/common/lc_meshloader.cpp +++ b/common/lc_meshloader.cpp @@ -909,7 +909,6 @@ static int LibraryMeshSectionCompare(lcMergeSection const& First, lcMergeSection lcMesh* lcLibraryMeshData::CreateMesh() { - lcLibraryMeshData& MeshData = *this; lcMesh* Mesh = new lcMesh(); int BaseVertices[LC_NUM_MESHDATA_TYPES]; @@ -919,11 +918,11 @@ lcMesh* lcLibraryMeshData::CreateMesh() std::vector IndexRemap[LC_NUM_MESHDATA_TYPES]; std::vector TexturedIndexRemap[LC_NUM_MESHDATA_TYPES]; - if (!MeshData.mHasTextures) + if (!mHasTextures) { for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - lcArray& Sections = MeshData.mSections[MeshDataIdx]; + lcArray& Sections = mSections[MeshDataIdx]; for (int SectionIdx = 0; SectionIdx < Sections.GetSize(); SectionIdx++) { @@ -932,14 +931,14 @@ lcMesh* lcLibraryMeshData::CreateMesh() } BaseVertices[MeshDataIdx] = NumVertices; - NumVertices += MeshData.mVertices[MeshDataIdx].GetSize(); + NumVertices += mVertices[MeshDataIdx].GetSize(); } } else { for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - lcArray& Sections = MeshData.mSections[MeshDataIdx]; + lcArray& Sections = mSections[MeshDataIdx]; for (int SectionIdx = 0; SectionIdx < Sections.GetSize(); SectionIdx++) { @@ -950,7 +949,7 @@ lcMesh* lcLibraryMeshData::CreateMesh() BaseVertices[MeshDataIdx] = NumVertices; BaseTexturedVertices[MeshDataIdx] = NumTexturedVertices; - const lcArray& Vertices = MeshData.mVertices[MeshDataIdx]; + const lcArray& Vertices = mVertices[MeshDataIdx]; IndexRemap[MeshDataIdx].resize(Vertices.GetSize()); TexturedIndexRemap[MeshDataIdx].resize(Vertices.GetSize()); @@ -980,8 +979,8 @@ lcMesh* lcLibraryMeshData::CreateMesh() for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++) { - const lcArray& SharedSections = MeshData.mSections[LC_MESHDATA_SHARED]; - const lcArray& Sections = MeshData.mSections[LodIdx]; + const lcArray& SharedSections = mSections[LC_MESHDATA_SHARED]; + const lcArray& Sections = mSections[LodIdx]; for (int SharedSectionIdx = 0; SharedSectionIdx < SharedSections.GetSize(); SharedSectionIdx++) { @@ -1031,11 +1030,11 @@ lcMesh* lcLibraryMeshData::CreateMesh() lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX); bool UpdatedBoundingBox = false; - if (!MeshData.mHasTextures) + if (!mHasTextures) { for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - const lcArray& Vertices = MeshData.mVertices[MeshDataIdx]; + const lcArray& Vertices = mVertices[MeshDataIdx]; for (const lcLibraryMeshVertex& SrcVertex : Vertices) { @@ -1045,7 +1044,7 @@ lcMesh* lcLibraryMeshData::CreateMesh() DstVertex.Normal = lcPackNormal(lcVector3LDrawToLeoCAD(SrcVertex.Normal)); } - for (const lcLibraryMeshSection* Section : MeshData.mSections[MeshDataIdx]) + for (const lcLibraryMeshSection* Section : mSections[MeshDataIdx]) { if (Section->mPrimitiveType != LC_MESH_TRIANGLES) continue; @@ -1065,7 +1064,7 @@ lcMesh* lcLibraryMeshData::CreateMesh() { for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - for (const lcLibraryMeshVertex& SrcVertex : MeshData.mVertices[MeshDataIdx]) + for (const lcLibraryMeshVertex& SrcVertex : mVertices[MeshDataIdx]) { if ((SrcVertex.Usage & LC_LIBRARY_VERTEX_UNTEXTURED) == 0) continue; @@ -1081,7 +1080,7 @@ lcMesh* lcLibraryMeshData::CreateMesh() for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - for (const lcLibraryMeshVertex& SrcVertex : MeshData.mVertices[MeshDataIdx]) + for (const lcLibraryMeshVertex& SrcVertex : mVertices[MeshDataIdx]) { if ((SrcVertex.Usage & LC_LIBRARY_VERTEX_TEXTURED) == 0) continue; @@ -1100,9 +1099,9 @@ lcMesh* lcLibraryMeshData::CreateMesh() for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++) { - const lcArray& Vertices = MeshData.mVertices[MeshDataIdx]; + const lcArray& Vertices = mVertices[MeshDataIdx]; - for (lcLibraryMeshSection* Section : MeshData.mSections[MeshDataIdx]) + for (lcLibraryMeshSection* Section : mSections[MeshDataIdx]) { if (Section->mPrimitiveType == LC_MESH_TRIANGLES) { @@ -1238,11 +1237,15 @@ lcMesh* lcLibraryMeshData::CreateMesh() NumIndices += DstSection.NumIndices; } } + + if (mHasLogoStud) + Mesh->mFlags |= lcMeshFlag::HasLogoStud; + /* - for (int SectionIdx = 0; SectionIdx < MeshData.mSections.GetSize(); SectionIdx++) + for (int SectionIdx = 0; SectionIdx < mSections.GetSize(); SectionIdx++) { lcMeshSection& DstSection = Mesh->mSections[SectionIdx]; - lcLibraryMeshSection* SrcSection = MeshData.mSections[SectionIdx]; + lcLibraryMeshSection* SrcSection = mSections[SectionIdx]; DstSection.ColorIndex = SrcSection->mColor; DstSection.PrimitiveType = SrcSection->mPrimitiveType; diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp index a0e1722e..9143899f 100644 --- a/common/pieceinf.cpp +++ b/common/pieceinf.cpp @@ -25,7 +25,6 @@ PieceInfo::PieceInfo() mModel = nullptr; mProject = nullptr; mSynthInfo = nullptr; - mHasLogoStud = false; } PieceInfo::~PieceInfo() diff --git a/common/pieceinf.h b/common/pieceinf.h index d51ea842..0ae81c14 100644 --- a/common/pieceinf.h +++ b/common/pieceinf.h @@ -169,7 +169,6 @@ public: lcPieceInfoState mState; int mFolderType; int mFolderIndex; - bool mHasLogoStud; protected: void ReleaseMesh();