From 80973b8353363bded87ed640254988587f0642d5 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Wed, 10 Jan 2024 04:30:35 +0100 Subject: [PATCH] Tuning: added `set_managedmaterials_options` to .addonpart --- .../AddonPartFileFormat.cpp | 60 ++++++++++++------- .../AddonPartFileFormat.h | 2 + source/main/utils/GenericFileFormat.h | 1 + 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp b/source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp index 74d47033b9..4d9cc528cc 100644 --- a/source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp +++ b/source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp @@ -63,33 +63,37 @@ std::shared_ptr AddonPartUtility::TransformToRigDefModule(Cach while (!m_context->endOfFile()) { - // (ignore 'addonpart_*' directives) - if (m_context->isTokKeyword() && m_context->getTokKeyword().find("addonpart_") != std::string::npos) - { - m_context->seekNextLine(); - continue; - } - // Evaluate block - else if (m_context->isTokKeyword()) + if (m_context->isTokKeyword()) { - keyword = Parser::IdentifyKeyword(m_context->getTokKeyword()); - if (keyword == Keyword::MANAGEDMATERIALS || - keyword == Keyword::PROPS || - keyword == Keyword::FLEXBODIES) + // (ignore 'addonpart_*' directives) + if (m_context->getTokKeyword().find("addonpart_") == std::string::npos) { - block = keyword; - m_context->seekNextLine(); - continue; // !! go to next line + keyword = Parser::IdentifyKeyword(m_context->getTokKeyword()); + switch (keyword) + { + // Handle blocks (data start on next line) + case Keyword::MANAGEDMATERIALS: + case Keyword::PROPS: + case Keyword::FLEXBODIES: + block = keyword; + break; + + // Handle directives (data are on the same line) + case Keyword::SET_MANAGEDMATERIALS_OPTIONS: + this->ProcessDirectiveSetManagedMaterialsOptions(); + break; + } } } - - // Process data in block - switch (block) + else if (block != Keyword::INVALID && !m_context->isTokComment() && !m_context->isTokLineBreak()) { - case Keyword::MANAGEDMATERIALS: this->ProcessManagedMaterial(); break; - case Keyword::PROPS: this->ProcessProp(); break; - case Keyword::FLEXBODIES: this->ProcessFlexbody(); break; - default: break; + switch (block) + { + case Keyword::MANAGEDMATERIALS: this->ProcessManagedMaterial(); break; + case Keyword::PROPS: this->ProcessProp(); break; + case Keyword::FLEXBODIES: this->ProcessFlexbody(); break; + default: break; + } } m_context->seekNextLine(); @@ -195,9 +199,21 @@ void AddonPartUtility::ProcessManagedMaterial() if (n > 3) def.specular_map = m_context->getTokString(3); if (n > 4) def.damaged_diffuse_map = m_context->getTokString(4); + // Options: + def.options = m_managedmaterials_options; + m_module->managedmaterials.push_back(def); } +void AddonPartUtility::ProcessDirectiveSetManagedMaterialsOptions() +{ + int n = m_context->countLineArgs(); + if (n > 1) + { + m_managedmaterials_options.double_sided = m_context->getTokBool(1); + } +} + void AddonPartUtility::ProcessProp() { RigDef::Prop def; diff --git a/source/main/resources/addonpart_fileformat/AddonPartFileFormat.h b/source/main/resources/addonpart_fileformat/AddonPartFileFormat.h index 317c6d4cc1..95184d81f7 100644 --- a/source/main/resources/addonpart_fileformat/AddonPartFileFormat.h +++ b/source/main/resources/addonpart_fileformat/AddonPartFileFormat.h @@ -55,6 +55,7 @@ class AddonPartUtility private: // Helpers of `TransformToRigDefModule()`, they expect `m_context` to be in position: void ProcessManagedMaterial(); + void ProcessDirectiveSetManagedMaterialsOptions(); void ProcessProp(); void ProcessFlexbody(); void ProcessTweakWheel(); @@ -72,6 +73,7 @@ class AddonPartUtility CacheEntryPtr m_addonpart_entry; // TransformToRigDefModule() state: std::shared_ptr m_module; + RigDef::ManagedMaterialsOptions m_managedmaterials_options; // ResolveUnwantedAndTweakedElements() state: TuneupDefPtr m_tuneup; }; diff --git a/source/main/utils/GenericFileFormat.h b/source/main/utils/GenericFileFormat.h index 036b9aca1a..375a6dcb8d 100644 --- a/source/main/utils/GenericFileFormat.h +++ b/source/main/utils/GenericFileFormat.h @@ -122,6 +122,7 @@ struct GenericDocContext: public RefCountingObject bool isTokBool(int offset = 0) const { return tokenType(offset) == TokenType::BOOL; } bool isTokKeyword(int offset = 0) const { return tokenType(offset) == TokenType::KEYWORD; } bool isTokComment(int offset = 0) const { return tokenType(offset) == TokenType::COMMENT; } + bool isTokLineBreak(int offset = 0) const { return tokenType(offset) == TokenType::LINEBREAK; } // Editing functions: