mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Fixed stud LOD not working. Fixes #390.
Also fixed cached pieces not updating their logo settings.
This commit is contained in:
parent
4269e84a16
commit
9499dd9daa
7 changed files with 49 additions and 41 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<QFuture<void>> mLoadFutures;
|
||||
QList<PieceInfo*> mLoadQueue;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<quint32> IndexRemap[LC_NUM_MESHDATA_TYPES];
|
||||
std::vector<quint32> TexturedIndexRemap[LC_NUM_MESHDATA_TYPES];
|
||||
|
||||
if (!MeshData.mHasTextures)
|
||||
if (!mHasTextures)
|
||||
{
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
{
|
||||
lcArray<lcLibraryMeshSection*>& Sections = MeshData.mSections[MeshDataIdx];
|
||||
lcArray<lcLibraryMeshSection*>& 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<lcLibraryMeshSection*>& Sections = MeshData.mSections[MeshDataIdx];
|
||||
lcArray<lcLibraryMeshSection*>& 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<lcLibraryMeshVertex>& Vertices = MeshData.mVertices[MeshDataIdx];
|
||||
const lcArray<lcLibraryMeshVertex>& 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<lcLibraryMeshSection*>& SharedSections = MeshData.mSections[LC_MESHDATA_SHARED];
|
||||
const lcArray<lcLibraryMeshSection*>& Sections = MeshData.mSections[LodIdx];
|
||||
const lcArray<lcLibraryMeshSection*>& SharedSections = mSections[LC_MESHDATA_SHARED];
|
||||
const lcArray<lcLibraryMeshSection*>& 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<lcLibraryMeshVertex>& Vertices = MeshData.mVertices[MeshDataIdx];
|
||||
const lcArray<lcLibraryMeshVertex>& 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<lcLibraryMeshVertex>& Vertices = MeshData.mVertices[MeshDataIdx];
|
||||
const lcArray<lcLibraryMeshVertex>& 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;
|
||||
|
|
|
@ -25,7 +25,6 @@ PieceInfo::PieceInfo()
|
|||
mModel = nullptr;
|
||||
mProject = nullptr;
|
||||
mSynthInfo = nullptr;
|
||||
mHasLogoStud = false;
|
||||
}
|
||||
|
||||
PieceInfo::~PieceInfo()
|
||||
|
|
|
@ -169,7 +169,6 @@ public:
|
|||
lcPieceInfoState mState;
|
||||
int mFolderType;
|
||||
int mFolderIndex;
|
||||
bool mHasLogoStud;
|
||||
|
||||
protected:
|
||||
void ReleaseMesh();
|
||||
|
|
Loading…
Add table
Reference in a new issue