From 57edf44020b3ed5397699ad40a68e396e3dd880a Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 15 Mar 2021 21:46:15 +0100 Subject: [PATCH 1/4] Fix incorrect control points of second and later synthesized pieces. When a model that was not create by LeoCAD contains two different pieces that are handled by lcSynth, then a set of default control points is generated for the first piece. When the following synthesized pieces are loaded, this set of control points is reused for the other pieces. But the values generated for the first piece may not be a suitable default for the subsequent pieces. Clear the control points after they have been applied to a piece so that later pieces receive a new set of defaults. --- common/lc_model.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 6515f736..f5277b12 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -659,6 +659,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) Piece->SetColorCode(ColorCode); Piece->VerifyControlPoints(ControlPoints); Piece->SetControlPoints(ControlPoints); + ControlPoints.RemoveAll(); if (Piece->mPieceInfo->IsModel() && Piece->mPieceInfo->GetModel()->IncludesModel(this)) { From a460075278f91c50e7460cd0f9dd9a917148c4a2 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Wed, 17 Mar 2021 21:43:02 -0700 Subject: [PATCH 2/4] Fixed normal transforms. --- common/lc_meshloader.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/lc_meshloader.cpp b/common/lc_meshloader.cpp index c7d19937..e5301f69 100644 --- a/common/lc_meshloader.cpp +++ b/common/lc_meshloader.cpp @@ -573,6 +573,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l { const lcArray& DataVertices = Data.mVertices; lcArray IndexRemap(DataVertices.GetSize()); + const lcMatrix33 NormalTransform = lcMatrix33Transpose(lcMatrix33(lcMatrix44Inverse(Transform))); if (!TextureMap) { @@ -589,7 +590,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l Index = AddVertex(Position, true); else { - lcVector3 Normal = lcNormalize(lcMul30(DataVertex.Normal, Transform)); + lcVector3 Normal = lcNormalize(lcMul(DataVertex.Normal, NormalTransform)); if (InvertNormals) Normal = -Normal; Index = AddVertex(Position, Normal, true); @@ -601,7 +602,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l Index = AddTexturedVertex(Position, DataVertex.TexCoord, true); else { - lcVector3 Normal = lcNormalize(lcMul30(DataVertex.Normal, Transform)); + lcVector3 Normal = lcNormalize(lcMul(DataVertex.Normal, NormalTransform)); if (InvertNormals) Normal = -Normal; Index = AddTexturedVertex(Position, Normal, DataVertex.TexCoord, true); @@ -625,7 +626,7 @@ void lcMeshLoaderTypeData::AddMeshData(const lcMeshLoaderTypeData& Data, const l Index = AddTexturedVertex(Position, TexCoord, true); else { - lcVector3 Normal = lcNormalize(lcMul30(DataVertex.Normal, Transform)); + lcVector3 Normal = lcNormalize(lcMul(DataVertex.Normal, NormalTransform)); if (InvertNormals) Normal = -Normal; Index = AddTexturedVertex(Position, Normal, TexCoord, true); @@ -696,6 +697,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat { const lcArray& DataVertices = Data.mVertices; quint32 BaseIndex; + const lcMatrix33 NormalTransform = lcMatrix33Transpose(lcMatrix33(lcMatrix44Inverse(Transform))); if (!TextureMap) { @@ -709,7 +711,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat const lcMeshLoaderVertex& SrcVertex = DataVertices[SrcVertexIdx]; lcMeshLoaderVertex& DstVertex = mVertices.Add(); DstVertex.Position = lcMul31(SrcVertex.Position, Transform); - DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform)); + DstVertex.Normal = lcNormalize(lcMul(SrcVertex.Normal, NormalTransform)); if (InvertNormals) DstVertex.Normal = -DstVertex.Normal; DstVertex.NormalWeight = SrcVertex.NormalWeight; @@ -732,7 +734,7 @@ void lcMeshLoaderTypeData::AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeDat lcVector2 TexCoord = lcCalculateTexCoord(Position, TextureMap); DstVertex.Position = Position; - DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform)); + DstVertex.Normal = lcNormalize(lcMul(SrcVertex.Normal, NormalTransform)); if (InvertNormals) DstVertex.Normal = -DstVertex.Normal; DstVertex.NormalWeight = SrcVertex.NormalWeight; @@ -1240,7 +1242,7 @@ lcMesh* lcLibraryMeshData::CreateMesh() } else { - quint16 BaseVertex = BaseConditionalVertices[LodIdx]; + quint32 BaseVertex = BaseConditionalVertices[LodIdx]; for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.GetSize(); IndexIdx++) *Index++ = BaseVertex + SrcSection->mIndices[IndexIdx]; From 29f797c771c3dc4b0460484f35cabdf77c4f376f Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 20 Mar 2021 11:56:13 -0700 Subject: [PATCH 3/4] Hide conditional lines behind the points. --- resources/shaders/unlit_color_conditional_vs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/shaders/unlit_color_conditional_vs.glsl b/resources/shaders/unlit_color_conditional_vs.glsl index 61d3f860..3fa318f9 100644 --- a/resources/shaders/unlit_color_conditional_vs.glsl +++ b/resources/shaders/unlit_color_conditional_vs.glsl @@ -28,5 +28,5 @@ void main() if (Cross1 * Cross2 >= 0.0) gl_Position = Position; else - gl_Position = vec4(2.0, 2.0, 2.0, 1.0); + gl_Position = vec4(p1.x, p1.y, 2.0, 1.0); } From 177265d9f84faca9c1a8154d5794e32adf9e7a3a Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 20 Mar 2021 12:32:05 -0700 Subject: [PATCH 4/4] Fixed CLI crash. --- common/lc_context.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/lc_context.cpp b/common/lc_context.cpp index 16219aa4..7f3fb040 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -110,6 +110,9 @@ bool lcContext::InitializeRenderer() void lcContext::ShutdownRenderer() { + if (!mGlobalOffscreenContext) + return; + mGlobalOffscreenContext->MakeCurrent(); lcContext* Context = mGlobalOffscreenContext.get();