mirror of
https://github.com/leozide/leocad
synced 2024-11-16 07:47:27 +01:00
Removed lcArray.
This commit is contained in:
parent
39cb7e13d1
commit
3a62411f0b
8 changed files with 65 additions and 320 deletions
|
@ -1,244 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
template <class T>
|
||||
class lcArray
|
||||
{
|
||||
public:
|
||||
lcArray(int Size = 0, int Grow = 16)
|
||||
{
|
||||
mData = nullptr;
|
||||
mLength = 0;
|
||||
mAlloc = 0;
|
||||
mGrow = Grow;
|
||||
|
||||
if (Size != 0)
|
||||
AllocGrow(Size);
|
||||
}
|
||||
|
||||
lcArray(const lcArray<T>& Array)
|
||||
{
|
||||
mData = nullptr;
|
||||
*this = Array;
|
||||
}
|
||||
|
||||
lcArray(std::initializer_list<T> Init)
|
||||
: lcArray((int)Init.size())
|
||||
{
|
||||
for (const T& Element : Init)
|
||||
emplace_back(Element);
|
||||
}
|
||||
|
||||
~lcArray()
|
||||
{
|
||||
delete[] mData;
|
||||
}
|
||||
|
||||
lcArray<T>& operator=(const lcArray<T>& Array)
|
||||
{
|
||||
mLength = Array.mLength;
|
||||
mAlloc = Array.mAlloc;
|
||||
mGrow = Array.mGrow;
|
||||
|
||||
delete[] mData;
|
||||
mData = new T[mAlloc];
|
||||
|
||||
for (int i = 0; i < mLength; i++)
|
||||
mData[i] = Array.mData[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
lcArray(lcArray<T>&& Array)
|
||||
{
|
||||
mData = nullptr;
|
||||
*this = std::move(Array);
|
||||
}
|
||||
|
||||
lcArray<T>& operator=(lcArray<T>&& Array)
|
||||
{
|
||||
delete[] mData;
|
||||
|
||||
mData = Array.mData;
|
||||
Array.mData = nullptr;
|
||||
mLength = Array.mLength;
|
||||
Array.mLength = 0;
|
||||
mAlloc = Array.mAlloc;
|
||||
Array.mAlloc = 0;
|
||||
mGrow = Array.mGrow;
|
||||
Array.mGrow = 16;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const T& operator[](int Index) const
|
||||
{
|
||||
return mData[Index];
|
||||
}
|
||||
|
||||
T& operator[](int Index)
|
||||
{
|
||||
return mData[Index];
|
||||
}
|
||||
|
||||
bool operator==(const lcArray<T>& Array) const
|
||||
{
|
||||
if (mLength != Array.mLength)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < mLength; i++)
|
||||
if (mData[i] != Array.mData[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
T* begin()
|
||||
{
|
||||
return &mData[0];
|
||||
}
|
||||
|
||||
T* end()
|
||||
{
|
||||
return &mData[0] + mLength;
|
||||
}
|
||||
|
||||
const T* begin() const
|
||||
{
|
||||
return &mData[0];
|
||||
}
|
||||
|
||||
const T* end() const
|
||||
{
|
||||
return &mData[0] + mLength;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return mLength == 0;
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
void resize(size_t NewSize)
|
||||
{
|
||||
if (NewSize > mAlloc)
|
||||
AllocGrow(NewSize - mLength);
|
||||
|
||||
mLength = (int)NewSize;
|
||||
}
|
||||
|
||||
void SetGrow(int Grow)
|
||||
{
|
||||
if (Grow)
|
||||
mGrow = Grow;
|
||||
}
|
||||
|
||||
void AllocGrow(size_t Grow)
|
||||
{
|
||||
if ((mLength + Grow) > mAlloc)
|
||||
{
|
||||
const size_t NewSize = ((mLength + Grow + mGrow - 1) / mGrow) * mGrow;
|
||||
T* NewData = new T[NewSize];
|
||||
|
||||
for (int i = 0; i < mLength; i++)
|
||||
NewData[i] = mData[i];
|
||||
|
||||
delete[] mData;
|
||||
mData = NewData;
|
||||
mAlloc = NewSize;
|
||||
}
|
||||
}
|
||||
|
||||
void emplace_back(const T& NewItem)
|
||||
{
|
||||
AllocGrow(1);
|
||||
mData[mLength++] = NewItem;
|
||||
}
|
||||
|
||||
T& emplace_back()
|
||||
{
|
||||
AllocGrow(1);
|
||||
mData[mLength++] = T();
|
||||
return mData[mLength - 1];
|
||||
}
|
||||
|
||||
T& InsertAt(int Index)
|
||||
{
|
||||
if (Index >= mLength)
|
||||
AllocGrow(Index - mLength + 1);
|
||||
else
|
||||
AllocGrow(1);
|
||||
|
||||
mLength++;
|
||||
for (int i = mLength - 1; i > Index; i--)
|
||||
mData[i] = mData[i - 1];
|
||||
|
||||
return mData[Index];
|
||||
}
|
||||
|
||||
void InsertAt(int Index, const T& NewItem)
|
||||
{
|
||||
if (Index >= mLength)
|
||||
AllocGrow(Index - mLength + 1);
|
||||
else
|
||||
AllocGrow(1);
|
||||
|
||||
mLength++;
|
||||
for (int i = mLength - 1; i > Index; i--)
|
||||
mData[i] = mData[i - 1];
|
||||
|
||||
mData[Index] = NewItem;
|
||||
}
|
||||
|
||||
void RemoveIndex(int Index)
|
||||
{
|
||||
mLength--;
|
||||
|
||||
for (int i = Index; i < mLength; i++)
|
||||
mData[i] = mData[i + 1];
|
||||
}
|
||||
|
||||
void Remove(const T& Item)
|
||||
{
|
||||
for (int i = 0; i < mLength; i++)
|
||||
{
|
||||
if (mData[i] == Item)
|
||||
{
|
||||
RemoveIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
void DeleteAll()
|
||||
{
|
||||
for (int i = 0; i < mLength; i++)
|
||||
delete mData[i];
|
||||
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
int FindIndex(const T& Item) const
|
||||
{
|
||||
for (int i = 0; i < mLength; i++)
|
||||
if (mData[i] == Item)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected:
|
||||
T* mData;
|
||||
int mLength;
|
||||
size_t mAlloc;
|
||||
int mGrow;
|
||||
};
|
||||
|
|
@ -168,7 +168,7 @@ quint32 lcMeshLoaderTypeData::AddVertex(const lcVector3& Position, bool Optimize
|
|||
{
|
||||
if (Optimize)
|
||||
{
|
||||
for (int VertexIdx = mVertices.size() - 1; VertexIdx >= 0; VertexIdx--)
|
||||
for (int VertexIdx = static_cast<int>(mVertices.size()) - 1; VertexIdx >= 0; VertexIdx--)
|
||||
{
|
||||
const lcMeshLoaderVertex& Vertex = mVertices[VertexIdx];
|
||||
|
||||
|
@ -183,14 +183,14 @@ quint32 lcMeshLoaderTypeData::AddVertex(const lcVector3& Position, bool Optimize
|
|||
Vertex.Normal = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
Vertex.NormalWeight = 0.0f;
|
||||
|
||||
return mVertices.size() - 1;
|
||||
return static_cast<quint32>(mVertices.size()) - 1;
|
||||
}
|
||||
|
||||
quint32 lcMeshLoaderTypeData::AddVertex(const lcVector3& Position, const lcVector3& Normal, float NormalWeight, bool Optimize)
|
||||
{
|
||||
if (Optimize)
|
||||
{
|
||||
for (int VertexIdx = mVertices.size() - 1; VertexIdx >= 0; VertexIdx--)
|
||||
for (int VertexIdx = static_cast<int>(mVertices.size()) - 1; VertexIdx >= 0; VertexIdx--)
|
||||
{
|
||||
lcMeshLoaderVertex& Vertex = mVertices[VertexIdx];
|
||||
|
||||
|
@ -218,7 +218,7 @@ quint32 lcMeshLoaderTypeData::AddVertex(const lcVector3& Position, const lcVecto
|
|||
Vertex.Normal = Normal;
|
||||
Vertex.NormalWeight = 1.0f;
|
||||
|
||||
return mVertices.size() - 1;
|
||||
return static_cast<quint32>(mVertices.size()) - 1;
|
||||
}
|
||||
|
||||
quint32 lcMeshLoaderTypeData::AddConditionalVertex(const lcVector3(&Position)[4])
|
||||
|
@ -230,7 +230,7 @@ quint32 lcMeshLoaderTypeData::AddConditionalVertex(const lcVector3(&Position)[4]
|
|||
Vertex.Position[2] = Position[2];
|
||||
Vertex.Position[3] = Position[3];
|
||||
|
||||
return mConditionalVertices.size() - 1;
|
||||
return static_cast<quint32>(mConditionalVertices.size()) - 1;
|
||||
}
|
||||
|
||||
void lcMeshLoaderTypeData::ProcessLine(int LineType, lcMeshLoaderMaterial* Material, bool WindingCCW, lcVector3 (&Vertices)[4], bool Optimize)
|
||||
|
@ -319,11 +319,12 @@ void lcMeshLoaderTypeData::ProcessLine(int LineType, lcMeshLoaderMaterial* Mater
|
|||
|
||||
void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap)
|
||||
{
|
||||
const lcArray<lcMeshLoaderVertex>& DataVertices = Data.mVertices;
|
||||
lcArray<quint32> IndexRemap(DataVertices.size());
|
||||
const std::vector<lcMeshLoaderVertex>& DataVertices = Data.mVertices;
|
||||
std::vector<quint32> IndexRemap;
|
||||
const lcMatrix33 NormalTransform = lcMatrix33Transpose(lcMatrix33(lcMatrix44Inverse(Transform)));
|
||||
|
||||
mVertices.AllocGrow(DataVertices.size());
|
||||
IndexRemap.reserve(DataVertices.size());
|
||||
mVertices.reserve(mVertices.size() + DataVertices.size());
|
||||
|
||||
for (const lcMeshLoaderVertex& DataVertex : DataVertices)
|
||||
{
|
||||
|
@ -343,8 +344,8 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
|
|||
IndexRemap.emplace_back(Index);
|
||||
}
|
||||
|
||||
mConditionalVertices.AllocGrow(Data.mConditionalVertices.size());
|
||||
lcArray<quint32> ConditionalRemap(Data.mConditionalVertices.size());
|
||||
mConditionalVertices.reserve(mConditionalVertices.size() + Data.mConditionalVertices.size());
|
||||
std::vector<quint32> ConditionalRemap(Data.mConditionalVertices.size());
|
||||
|
||||
for (const lcMeshLoaderConditionalVertex& DataVertex : Data.mConditionalVertices)
|
||||
{
|
||||
|
@ -385,7 +386,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
|
|||
DstSection = AddSection(PrimitiveType, mMeshData->GetMaterial(ColorCode));
|
||||
}
|
||||
|
||||
DstSection->mIndices.AllocGrow(SrcSection->mIndices.size());
|
||||
DstSection->mIndices.reserve(DstSection->mIndices.size() + SrcSection->mIndices.size());
|
||||
|
||||
if (PrimitiveType == LC_MESH_CONDITIONAL_LINES)
|
||||
{
|
||||
|
@ -399,7 +400,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
|
|||
}
|
||||
else
|
||||
{
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx += 3)
|
||||
for (size_t IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx += 3)
|
||||
{
|
||||
DstSection->mIndices.emplace_back(IndexRemap[SrcSection->mIndices[IndexIdx + 2]]);
|
||||
DstSection->mIndices.emplace_back(IndexRemap[SrcSection->mIndices[IndexIdx + 1]]);
|
||||
|
@ -411,18 +412,16 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l
|
|||
|
||||
void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap)
|
||||
{
|
||||
const lcArray<lcMeshLoaderVertex>& DataVertices = Data.mVertices;
|
||||
const std::vector<lcMeshLoaderVertex>& DataVertices = Data.mVertices;
|
||||
quint32 BaseIndex;
|
||||
const lcMatrix33 NormalTransform = lcMatrix33Transpose(lcMatrix33(lcMatrix44Inverse(Transform)));
|
||||
|
||||
BaseIndex = mVertices.size();
|
||||
BaseIndex = static_cast<quint32>(mVertices.size());
|
||||
|
||||
mVertices.SetGrow(lcMin(mVertices.size(), 8 * 1024 * 1024));
|
||||
mVertices.AllocGrow(DataVertices.size());
|
||||
mVertices.reserve(mVertices.size() + DataVertices.size());
|
||||
|
||||
for (int SrcVertexIdx = 0; SrcVertexIdx < DataVertices.size(); SrcVertexIdx++)
|
||||
for (const lcMeshLoaderVertex& SrcVertex : DataVertices)
|
||||
{
|
||||
const lcMeshLoaderVertex& SrcVertex = DataVertices[SrcVertexIdx];
|
||||
lcMeshLoaderVertex& DstVertex = mVertices.emplace_back();
|
||||
DstVertex.Position = lcMul31(SrcVertex.Position, Transform);
|
||||
DstVertex.Normal = lcNormalize(lcMul(SrcVertex.Normal, NormalTransform));
|
||||
|
@ -431,8 +430,8 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
|
|||
DstVertex.NormalWeight = SrcVertex.NormalWeight;
|
||||
}
|
||||
|
||||
mConditionalVertices.AllocGrow(Data.mConditionalVertices.size());
|
||||
const quint32 BaseConditional = mConditionalVertices.size();
|
||||
mConditionalVertices.reserve(mConditionalVertices.size() + Data.mConditionalVertices.size());
|
||||
const quint32 BaseConditional = static_cast<quint32>(mConditionalVertices.size());
|
||||
|
||||
for (const lcMeshLoaderConditionalVertex& DataVertex : Data.mConditionalVertices)
|
||||
{
|
||||
|
@ -470,8 +469,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
|
|||
DstSection = AddSection(PrimitiveType, mMeshData->GetMaterial(ColorCode));
|
||||
}
|
||||
|
||||
DstSection->mIndices.SetGrow(lcMin(DstSection->mIndices.size(), 8 * 1024 * 1024));
|
||||
DstSection->mIndices.AllocGrow(SrcSection->mIndices.size());
|
||||
DstSection->mIndices.reserve(DstSection->mIndices.size() + SrcSection->mIndices.size());
|
||||
|
||||
if (PrimitiveType == LC_MESH_CONDITIONAL_LINES)
|
||||
{
|
||||
|
@ -485,7 +483,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
|
|||
}
|
||||
else
|
||||
{
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx += 3)
|
||||
for (size_t IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx += 3)
|
||||
{
|
||||
DstSection->mIndices.emplace_back(BaseIndex + SrcSection->mIndices[IndexIdx + 2]);
|
||||
DstSection->mIndices.emplace_back(BaseIndex + SrcSection->mIndices[IndexIdx + 1]);
|
||||
|
@ -497,8 +495,8 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat
|
|||
|
||||
void lcLibraryMeshData::AddVertices(lcMeshDataType MeshDataType, size_t VertexCount, int* BaseVertex, lcMeshLoaderVertex** VertexBuffer)
|
||||
{
|
||||
lcArray<lcMeshLoaderVertex>& Vertices = mData[MeshDataType].mVertices;
|
||||
int CurrentSize = Vertices.size();
|
||||
std::vector<lcMeshLoaderVertex>& Vertices = mData[MeshDataType].mVertices;
|
||||
int CurrentSize = static_cast<int>(Vertices.size());
|
||||
|
||||
Vertices.resize(CurrentSize + VertexCount);
|
||||
|
||||
|
@ -509,8 +507,8 @@ void lcLibraryMeshData::AddVertices(lcMeshDataType MeshDataType, size_t VertexCo
|
|||
void lcLibraryMeshData::AddIndices(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, size_t IndexCount, quint32** IndexBuffer)
|
||||
{
|
||||
lcMeshLoaderSection* Section = mData[MeshDataType].AddSection(PrimitiveType, GetMaterial(ColorCode));
|
||||
lcArray<quint32>& Indices = Section->mIndices;
|
||||
const int CurrentSize = Indices.size();
|
||||
std::vector<quint32>& Indices = Section->mIndices;
|
||||
const size_t CurrentSize = Indices.size();
|
||||
|
||||
Indices.resize(CurrentSize + IndexCount);
|
||||
|
||||
|
@ -631,7 +629,7 @@ static bool lcMeshLoaderFinalSectionCompare(const lcMeshLoaderFinalSection& a, c
|
|||
|
||||
quint32 lcLibraryMeshData::AddTexturedVertex(const lcVector3& Position, const lcVector3& Normal, const lcVector2& TexCoords)
|
||||
{
|
||||
for (int VertexIndex = mTexturedVertices.size() - 1; VertexIndex >= 0; VertexIndex--)
|
||||
for (int VertexIndex = static_cast<int>(mTexturedVertices.size()) - 1; VertexIndex >= 0; VertexIndex--)
|
||||
{
|
||||
const lcMeshLoaderTexturedVertex& Vertex = mTexturedVertices[VertexIndex];
|
||||
|
||||
|
@ -645,7 +643,7 @@ quint32 lcLibraryMeshData::AddTexturedVertex(const lcVector3& Position, const lc
|
|||
Vertex.Normal = Normal;
|
||||
Vertex.TexCoords = TexCoords;
|
||||
|
||||
return mTexturedVertices.size() - 1;
|
||||
return static_cast<quint32>(mTexturedVertices.size()) - 1;
|
||||
}
|
||||
|
||||
void lcLibraryMeshData::GeneratePlanarTexcoords(lcMeshLoaderSection* Section, const lcMeshLoaderTypeData& Data)
|
||||
|
@ -688,7 +686,7 @@ void lcLibraryMeshData::GenerateCylindricalTexcoords(lcMeshLoaderSection* Sectio
|
|||
const lcVector4 Plane2 = lcVector4(Plane2Normal, -lcDot(Plane2Normal, Material->Points[1]));
|
||||
const float Angle = 360.0f / Material->Angles[0];
|
||||
|
||||
for (int TriangleIndex = 0; TriangleIndex < Section->mIndices.size(); TriangleIndex += 3)
|
||||
for (size_t TriangleIndex = 0; TriangleIndex < Section->mIndices.size(); TriangleIndex += 3)
|
||||
{
|
||||
const lcVector3 Positions[3] =
|
||||
{
|
||||
|
@ -731,7 +729,7 @@ void lcLibraryMeshData::GenerateSphericalTexcoords(lcMeshLoaderSection* Section,
|
|||
const float Angle1 = 360.0f / Material->Angles[0];
|
||||
const float Angle2 = 180.0f / Material->Angles[1];
|
||||
|
||||
for (int TriangleIndex = 0; TriangleIndex < Section->mIndices.size(); TriangleIndex += 3)
|
||||
for (size_t TriangleIndex = 0; TriangleIndex < Section->mIndices.size(); TriangleIndex += 3)
|
||||
{
|
||||
const lcVector3 Positions[3] =
|
||||
{
|
||||
|
@ -808,9 +806,9 @@ lcMesh* lcLibraryMeshData::CreateMesh()
|
|||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
{
|
||||
BaseVertices[MeshDataIdx] = NumVertices;
|
||||
NumVertices += mData[MeshDataIdx].mVertices.size();
|
||||
NumVertices += static_cast<int>(mData[MeshDataIdx].mVertices.size());
|
||||
BaseConditionalVertices[MeshDataIdx] = ConditionalVertexCount;
|
||||
ConditionalVertexCount += mData[MeshDataIdx].mConditionalVertices.size();
|
||||
ConditionalVertexCount += static_cast<int>(mData[MeshDataIdx].mConditionalVertices.size());
|
||||
}
|
||||
|
||||
if (mHasTextures)
|
||||
|
@ -819,11 +817,11 @@ lcMesh* lcLibraryMeshData::CreateMesh()
|
|||
quint16 NumSections[LC_NUM_MESH_LODS];
|
||||
int NumIndices = 0;
|
||||
|
||||
lcArray<lcMeshLoaderFinalSection> FinalSections[LC_NUM_MESH_LODS];
|
||||
std::vector<lcMeshLoaderFinalSection> FinalSections[LC_NUM_MESH_LODS];
|
||||
|
||||
for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++)
|
||||
{
|
||||
auto AddFinalSection = [](lcMeshLoaderSection* Section, lcArray<lcMeshLoaderFinalSection>& FinalSections)
|
||||
auto AddFinalSection = [](lcMeshLoaderSection* Section, std::vector<lcMeshLoaderFinalSection>& FinalSections)
|
||||
{
|
||||
for (const lcMeshLoaderFinalSection& FinalSection : FinalSections)
|
||||
if (FinalSection.PrimitiveType == Section->mPrimitiveType && FinalSection.Color == Section->mMaterial->Color && !strcmp(FinalSection.Name, Section->mMaterial->Name))
|
||||
|
@ -838,23 +836,23 @@ lcMesh* lcLibraryMeshData::CreateMesh()
|
|||
|
||||
for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections)
|
||||
{
|
||||
NumIndices += Section->mIndices.size();
|
||||
NumIndices += static_cast<int>(Section->mIndices.size());
|
||||
|
||||
AddFinalSection(Section.get(), FinalSections[LodIdx]);
|
||||
}
|
||||
|
||||
for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LodIdx].mSections)
|
||||
{
|
||||
NumIndices += Section->mIndices.size();
|
||||
NumIndices += static_cast<int>(Section->mIndices.size());
|
||||
|
||||
AddFinalSection(Section.get(), FinalSections[LodIdx]);
|
||||
}
|
||||
|
||||
NumSections[LodIdx] = FinalSections[LodIdx].size();
|
||||
NumSections[LodIdx] = static_cast<quint16>(FinalSections[LodIdx].size());
|
||||
std::sort(FinalSections[LodIdx].begin(), FinalSections[LodIdx].end(), lcMeshLoaderFinalSectionCompare);
|
||||
}
|
||||
|
||||
Mesh->Create(NumSections, NumVertices, mTexturedVertices.size(), ConditionalVertexCount, NumIndices);
|
||||
Mesh->Create(NumSections, NumVertices, static_cast<int>(mTexturedVertices.size()), ConditionalVertexCount, NumIndices);
|
||||
|
||||
lcVertex* DstVerts = (lcVertex*)Mesh->mVertexData;
|
||||
|
||||
|
@ -912,16 +910,16 @@ lcMesh* lcLibraryMeshData::CreateMesh()
|
|||
}
|
||||
|
||||
template<typename IndexType>
|
||||
void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFinalSection> (&FinalSections)[LC_NUM_MESH_LODS], int(&BaseVertices)[LC_NUM_MESHDATA_TYPES], int(&BaseConditionalVertices)[LC_NUM_MESHDATA_TYPES])
|
||||
void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const std::vector<lcMeshLoaderFinalSection> (&FinalSections)[LC_NUM_MESH_LODS], int(&BaseVertices)[LC_NUM_MESHDATA_TYPES], int(&BaseConditionalVertices)[LC_NUM_MESHDATA_TYPES])
|
||||
{
|
||||
int NumIndices = 0;
|
||||
|
||||
for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++)
|
||||
{
|
||||
for (int SectionIdx = 0; SectionIdx < FinalSections[LodIdx].size(); SectionIdx++)
|
||||
for (size_t SectionIndex = 0; SectionIndex < FinalSections[LodIdx].size(); SectionIndex++)
|
||||
{
|
||||
const lcMeshLoaderFinalSection& FinalSection = FinalSections[LodIdx][SectionIdx];
|
||||
lcMeshSection& DstSection = Mesh->mLods[LodIdx].Sections[SectionIdx];
|
||||
const lcMeshLoaderFinalSection& FinalSection = FinalSections[LodIdx][SectionIndex];
|
||||
lcMeshSection& DstSection = Mesh->mLods[LodIdx].Sections[SectionIndex];
|
||||
|
||||
DstSection.ColorIndex = FinalSection.Color;
|
||||
DstSection.PrimitiveType = FinalSection.PrimitiveType;
|
||||
|
@ -953,7 +951,7 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
|
|||
{
|
||||
const IndexType BaseVertex = BaseVertices[SrcDataType];
|
||||
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
for (size_t IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
*Index++ = BaseVertex + SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
break;
|
||||
|
@ -962,14 +960,14 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
|
|||
{
|
||||
const IndexType BaseVertex = BaseConditionalVertices[SrcDataType];
|
||||
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
for (size_t IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
*Index++ = BaseVertex + SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
break;
|
||||
|
||||
case LC_MESH_TEXTURED_TRIANGLES:
|
||||
{
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
for (size_t IndexIdx = 0; IndexIdx < SrcSection->mIndices.size(); IndexIdx++)
|
||||
*Index++ = SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
break;
|
||||
|
@ -978,7 +976,7 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
|
|||
break;
|
||||
}
|
||||
|
||||
DstSection.NumIndices += SrcSection->mIndices.size();
|
||||
DstSection.NumIndices += static_cast<int>(SrcSection->mIndices.size());
|
||||
};
|
||||
|
||||
for (const std::unique_ptr<lcMeshLoaderSection>& Section : mData[LC_MESHDATA_SHARED].mSections)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "lc_array.h"
|
||||
#include "lc_math.h"
|
||||
#include "lc_mesh.h"
|
||||
|
||||
|
@ -55,13 +54,14 @@ class lcMeshLoaderSection
|
|||
{
|
||||
public:
|
||||
lcMeshLoaderSection(lcMeshPrimitiveType PrimitiveType, lcMeshLoaderMaterial* Material)
|
||||
: mMaterial(Material), mPrimitiveType(PrimitiveType), mIndices(1024, 1024)
|
||||
: mMaterial(Material), mPrimitiveType(PrimitiveType)
|
||||
{
|
||||
mIndices.reserve(1024);
|
||||
}
|
||||
|
||||
lcMeshLoaderMaterial* mMaterial;
|
||||
lcMeshPrimitiveType mPrimitiveType;
|
||||
lcArray<quint32> mIndices;
|
||||
std::vector<quint32> mIndices;
|
||||
};
|
||||
|
||||
struct lcMeshLoaderFinalSection
|
||||
|
@ -96,11 +96,7 @@ struct lcMeshLoaderTextureMap
|
|||
class lcMeshLoaderTypeData
|
||||
{
|
||||
public:
|
||||
lcMeshLoaderTypeData()
|
||||
{
|
||||
mVertices.SetGrow(1024);
|
||||
mConditionalVertices.SetGrow(1024);
|
||||
}
|
||||
lcMeshLoaderTypeData() = default;
|
||||
|
||||
lcMeshLoaderTypeData(const lcMeshLoaderTypeData&) = delete;
|
||||
lcMeshLoaderTypeData& operator=(const lcMeshLoaderTypeData&) = delete;
|
||||
|
@ -113,8 +109,8 @@ public:
|
|||
void Clear()
|
||||
{
|
||||
mSections.clear();
|
||||
mVertices.RemoveAll();
|
||||
mConditionalVertices.RemoveAll();
|
||||
mVertices.clear();
|
||||
mConditionalVertices.clear();
|
||||
}
|
||||
|
||||
void SetMeshData(lcLibraryMeshData* MeshData)
|
||||
|
@ -134,8 +130,8 @@ public:
|
|||
void AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap);
|
||||
|
||||
std::vector<std::unique_ptr<lcMeshLoaderSection>> mSections;
|
||||
lcArray<lcMeshLoaderVertex> mVertices;
|
||||
lcArray<lcMeshLoaderConditionalVertex> mConditionalVertices;
|
||||
std::vector<lcMeshLoaderVertex> mVertices;
|
||||
std::vector<lcMeshLoaderConditionalVertex> mConditionalVertices;
|
||||
|
||||
protected:
|
||||
lcLibraryMeshData* mMeshData = nullptr;
|
||||
|
@ -195,7 +191,7 @@ public:
|
|||
protected:
|
||||
lcMeshLoader* mMeshLoader = nullptr;
|
||||
std::vector<std::unique_ptr<lcMeshLoaderMaterial>> mMaterials;
|
||||
lcArray<lcMeshLoaderTexturedVertex> mTexturedVertices;
|
||||
std::vector<lcMeshLoaderTexturedVertex> mTexturedVertices;
|
||||
|
||||
void GenerateTexturedVertices();
|
||||
void GeneratePlanarTexcoords(lcMeshLoaderSection* Section, const lcMeshLoaderTypeData& Data);
|
||||
|
@ -204,7 +200,7 @@ protected:
|
|||
quint32 AddTexturedVertex(const lcVector3& Position, const lcVector3& Normal, const lcVector2& TexCoords);
|
||||
|
||||
template<typename IndexType>
|
||||
void WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFinalSection> (&FinalSections)[LC_NUM_MESH_LODS], int (&BaseVertices)[LC_NUM_MESHDATA_TYPES], int (&BaseConditionalVertices)[LC_NUM_MESHDATA_TYPES]);
|
||||
void WriteSections(lcMesh* Mesh, const std::vector<lcMeshLoaderFinalSection> (&FinalSections)[LC_NUM_MESH_LODS], int (&BaseVertices)[LC_NUM_MESHDATA_TYPES], int (&BaseConditionalVertices)[LC_NUM_MESHDATA_TYPES]);
|
||||
|
||||
static void UpdateMeshBoundingBox(lcMesh* Mesh);
|
||||
template<typename IndexType>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "lc_math.h"
|
||||
#include "lc_commands.h"
|
||||
#include "lc_array.h"
|
||||
|
||||
enum class lcObjectPropertyId;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "lc_array.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class lcModelListDialog;
|
||||
|
|
|
@ -693,9 +693,9 @@ void lcSynthInfoCurved::CalculateSections(const std::vector<lcPieceControlPoint>
|
|||
SegmentControlPoints[2] = lcMul31(lcVector3(0.0f, -ControlPoints[ControlPointIndex + 1].Scale, 0.0f), EndTransform);
|
||||
SegmentControlPoints[3] = EndTransform.GetTranslation();
|
||||
|
||||
const int NumCurvePoints = 8192;
|
||||
lcArray<lcVector3> CurvePoints;
|
||||
CurvePoints.AllocGrow(NumCurvePoints);
|
||||
const int NumCurvePoints = 4096;
|
||||
std::vector<lcVector3> CurvePoints;
|
||||
CurvePoints.reserve(NumCurvePoints);
|
||||
|
||||
for (int PointIdx = 0; PointIdx < NumCurvePoints; PointIdx++)
|
||||
{
|
||||
|
@ -709,12 +709,12 @@ void lcSynthInfoCurved::CalculateSections(const std::vector<lcPieceControlPoint>
|
|||
float CurrentSegmentLength = 0.0f;
|
||||
float TotalSegmentLength = 0.0f;
|
||||
|
||||
for (int PointIdx = 0; PointIdx < CurvePoints.size() - 1; PointIdx++)
|
||||
for (size_t PointIdx = 0; PointIdx < CurvePoints.size() - 1; PointIdx++)
|
||||
TotalSegmentLength += lcLength(CurvePoints[PointIdx] - CurvePoints[PointIdx + 1]);
|
||||
|
||||
lcVector3 StartUp = lcMul30(lcVector3(1.0f, 0.0f, 0.0f), StartTransform);
|
||||
float Twist = GetSectionTwist(StartTransform, EndTransform);
|
||||
int CurrentPointIndex = 0;
|
||||
size_t CurrentPointIndex = 0;
|
||||
|
||||
while (CurrentPointIndex < CurvePoints.size() - 1)
|
||||
{
|
||||
|
@ -818,9 +818,9 @@ void lcSynthInfoBraidedString::CalculateSections(const std::vector<lcPieceContro
|
|||
SegmentControlPoints[2] = lcMul31(lcVector3(-ControlPoints[ControlPointIndex + 1].Scale, 0.0f, 0.0f), EndTransform);
|
||||
SegmentControlPoints[3] = EndTransform.GetTranslation();
|
||||
|
||||
const int NumCurvePoints = 8192;
|
||||
lcArray<lcVector3> CurvePoints;
|
||||
CurvePoints.AllocGrow(NumCurvePoints);
|
||||
const int NumCurvePoints = 4096;
|
||||
std::vector<lcVector3> CurvePoints;
|
||||
CurvePoints.reserve(NumCurvePoints);
|
||||
|
||||
for (int PointIdx = 0; PointIdx < NumCurvePoints; PointIdx++)
|
||||
{
|
||||
|
@ -834,12 +834,12 @@ void lcSynthInfoBraidedString::CalculateSections(const std::vector<lcPieceContro
|
|||
float CurrentSegmentLength = 0.0f;
|
||||
float TotalSegmentLength = 0.0f;
|
||||
|
||||
for (int PointIdx = 0; PointIdx < CurvePoints.size() - 1; PointIdx++)
|
||||
for (size_t PointIdx = 0; PointIdx < CurvePoints.size() - 1; PointIdx++)
|
||||
TotalSegmentLength += lcLength(CurvePoints[PointIdx] - CurvePoints[PointIdx + 1]);
|
||||
|
||||
lcVector3 StartUp = lcMul30(lcVector3(0.0f, 1.0f, 0.0f), StartTransform);
|
||||
float Twist = GetSectionTwist(StartTransform, EndTransform);
|
||||
int CurrentPointIndex = 0;
|
||||
size_t CurrentPointIndex = 0;
|
||||
|
||||
while (CurrentPointIndex < CurvePoints.size() - 1)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "lc_array.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
#define LC_HTML_SINGLEPAGE 0x01
|
||||
|
|
|
@ -245,7 +245,6 @@ HEADERS += \
|
|||
common/light.h \
|
||||
common/lc_aboutdialog.h \
|
||||
common/lc_application.h \
|
||||
common/lc_array.h \
|
||||
common/lc_arraydialog.h \
|
||||
common/lc_blenderpreferences.h \
|
||||
common/lc_bricklink.h \
|
||||
|
|
Loading…
Reference in a new issue