Skip to content

Commit

Permalink
Tuning: added set_managedmaterials_options to .addonpart
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Jan 11, 2024
1 parent 4b51b17 commit 80973b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
60 changes: 38 additions & 22 deletions source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,37 @@ std::shared_ptr<Document::Module> 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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -72,6 +73,7 @@ class AddonPartUtility
CacheEntryPtr m_addonpart_entry;
// TransformToRigDefModule() state:
std::shared_ptr<RigDef::Document::Module> m_module;
RigDef::ManagedMaterialsOptions m_managedmaterials_options;
// ResolveUnwantedAndTweakedElements() state:
TuneupDefPtr m_tuneup;
};
Expand Down
1 change: 1 addition & 0 deletions source/main/utils/GenericFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct GenericDocContext: public RefCountingObject<GenericDocContext>
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:

Expand Down

0 comments on commit 80973b8

Please sign in to comment.