From 59e8583ee48b25fc117fad05ed2ee5e6d01f9bce Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 16 Apr 2016 20:35:16 +0000 Subject: [PATCH] Optimized flexible axle generation. --- common/lc_synth.cpp | 126 ++++++++++++++++++++++++-------------------- common/lc_synth.h | 2 +- 2 files changed, 70 insertions(+), 58 deletions(-) diff --git a/common/lc_synth.cpp b/common/lc_synth.cpp index 342f863a..ac193c78 100644 --- a/common/lc_synth.cpp +++ b/common/lc_synth.cpp @@ -2,6 +2,7 @@ #include "lc_synth.h" #include "lc_library.h" #include "lc_application.h" +#include "lc_file.h" #include "pieceinf.h" void lcSynthInit() @@ -25,13 +26,13 @@ void lcSynthInit() { "71951", LC_SYNTH_PIECE_RIBBED_HOSE, 143.75f, 22 }, // Technic Ribbed Hose 8L { "71986", LC_SYNTH_PIECE_RIBBED_HOSE, 212.50f, 33 }, // Technic Ribbed Hose 11L { "43675", LC_SYNTH_PIECE_RIBBED_HOSE, 375.00f, 58 }, // Technic Ribbed Hose 19L - { "32580", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 60.00f, 15 }, // Technic Axle Flexible 7 - { "32199", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 140.00f, 35 }, // Technic Axle Flexible 11 - { "55709", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 140.00f, 35 }, // Technic Axle Flexible 11 - { "32200", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 160.00f, 40 }, // Technic Axle Flexible 12 - { "32201", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 200.00f, 50 }, // Technic Axle Flexible 14 - { "32202", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 240.00f, 60 }, // Technic Axle Flexible 16 - { "32235", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 300.00f, 75 }, // Technic Axle Flexible 19 + { "32580", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 120.00f, 15 }, // Technic Axle Flexible 7 + { "32199", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 200.00f, 35 }, // Technic Axle Flexible 11 + { "55709", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 200.00f, 35 }, // Technic Axle Flexible 11 + { "32200", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 220.00f, 40 }, // Technic Axle Flexible 12 + { "32201", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 260.00f, 50 }, // Technic Axle Flexible 14 + { "32202", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 300.00f, 60 }, // Technic Axle Flexible 16 + { "32235", LC_SYNTH_PIECE_FLEXIBLE_AXLE, 360.00f, 75 }, // Technic Axle Flexible 19 { "76384", LC_SYNTH_PIECE_STRING_BRAIDED, 200.00f, 46 }, // String Braided 11L with End Studs { "75924", LC_SYNTH_PIECE_STRING_BRAIDED, 400.00f, 96 }, // String Braided 21L with End Studs { "572C02", LC_SYNTH_PIECE_STRING_BRAIDED, 800.00f, 196 } // String Braided 41L with End Studs @@ -66,8 +67,9 @@ lcSynthInfo::lcSynthInfo(lcSynthType Type, float Length, int NumSections) break; case LC_SYNTH_PIECE_FLEXIBLE_AXLE: - EdgeSectionLength = 0.0f; + EdgeSectionLength = 30.0f; MidSectionLength = 4.0f; + mRigidEdges = true; break; case LC_SYNTH_PIECE_STRING_BRAIDED: @@ -117,8 +119,6 @@ void lcSynthInfo::GetDefaultControlPoints(lcArray& ControlP ControlPoints[1].Scale = Scale; } -#include "lc_file.h" - void lcSynthInfo::CalculateSections(const lcArray& ControlPoints, lcArray& Sections, void (*SectionCallback)(const lcVector3& CurvePoint, int SegmentIndex, float t, void* Param), void* CallbackParam) const { float SectionLength = 0.0f; @@ -270,7 +270,7 @@ void lcSynthInfo::AddRibbedHoseParts(lcMemFile& File, const lcArray& } } -void lcSynthInfo::AddFlexibleAxleParts(lcMemFile& File, const lcArray& Sections) const +void lcSynthInfo::AddFlexibleAxleParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const { char Line[256]; const int NumEdgeParts = 6; @@ -307,51 +307,6 @@ void lcSynthInfo::AddFlexibleAxleParts(lcMemFile& File, const lcArrayPosition = lcMul31(SectionVertices[VertexIdx], Sections[SectionIdx]); + VertexBuffer++; + } + } + + int BaseLinesVertex = BaseVertex; + + for (int SectionIdx = 1; SectionIdx < Sections.GetSize() - 1; SectionIdx++) + { + for (int VertexIdx = 0; VertexIdx < 16; VertexIdx++) + { + if (VertexIdx % 4) + { + *IndexBuffer++ = BaseLinesVertex; + *IndexBuffer++ = BaseLinesVertex + 16; + } + BaseLinesVertex++; + } + } + + MeshData.AddIndices(LC_MESHDATA_SHARED, LC_MESH_TRIANGLES, 0, 6 * 16 * (Sections.GetSize() - 2), &IndexBuffer); + + for (int SectionIdx = 1; SectionIdx < Sections.GetSize() - 1; SectionIdx++) + { + for (int VertexIdx = 0; VertexIdx < 16; VertexIdx++) + { + int Vertex1 = BaseVertex + VertexIdx; + int Vertex2 = BaseVertex + (VertexIdx + 1) % 16; + + *IndexBuffer++ = Vertex1; + *IndexBuffer++ = Vertex2; + *IndexBuffer++ = Vertex1 + 16; + *IndexBuffer++ = Vertex2; + *IndexBuffer++ = Vertex2 + 16; + *IndexBuffer++ = Vertex1 + 16; + } + BaseVertex += 16; + } } void lcSynthInfo::AddStringBraidedParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const @@ -506,7 +518,7 @@ lcMesh* lcSynthInfo::CreateMesh(const lcArray& ControlPoint break; case LC_SYNTH_PIECE_FLEXIBLE_AXLE: - AddFlexibleAxleParts(File, Sections); + AddFlexibleAxleParts(File, MeshData, Sections); break; case LC_SYNTH_PIECE_STRING_BRAIDED: diff --git a/common/lc_synth.h b/common/lc_synth.h index 549b7614..0375ab3a 100644 --- a/common/lc_synth.h +++ b/common/lc_synth.h @@ -31,7 +31,7 @@ public: protected: void CalculateSections(const lcArray& ControlPoints, lcArray& Sections, void(*SectionCallback)(const lcVector3& CurvePoint, int SegmentIndex, float t, void* Param), void* CallbackParam) const; void AddRibbedHoseParts(lcMemFile& File, const lcArray& Sections) const; - void AddFlexibleAxleParts(lcMemFile& File, const lcArray& Sections) const; + void AddFlexibleAxleParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const; void AddStringBraidedParts(lcMemFile& File, lcLibraryMeshData& MeshData, const lcArray& Sections) const; lcSynthType mType;