Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[al] Add support for default rgba values and color threshold for exporting #2250

Conversation

csyshing
Copy link
Collaborator

@csyshing csyshing commented Apr 6, 2022

This PR mainly contains two features for exporting:

  • Default RGBA value (RGB = 0.18, A =1.0) so that the value is always meaningful
  • Optionally accept color "threshold", the UI is also extended to support custom precision to allow displaying high precision of floating point numbers, defaults to 1e-5 which should be enough for color.

@seando-adsk seando-adsk added the al Related to AnimalLogic plugin label Apr 29, 2022
MString& code,
float value,
int precision,
const std::string& controller,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be nicer to pass as MString, other parameters are passed using that type (except prefix for some reason). It gets converted to a MString in the function anwyay. Other wise the parameters would now take all three of: const char*, MString and std::string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

float value,
int precision,
const char* controller,
bool state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below, in generateFloatGlobals, you receive this as enableState, which I think is a better name that "state". It makes the purpose of the parameter clearer. I would change it here to be the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const float& defVal,
int defPre,
const char* defController,
bool defState)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I'd rename defState to enableState.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -387,6 +410,9 @@ class PluginTranslatorOptions
MString defString; ///< default string value
std::vector<MString> enumStrings; ///< the text values for the enums
OptionType type; ///< the type of the option
int precision { 1 };
std::string controller {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: I'd use a MString instead of std::string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}
}

/// \brief Test exporting mesh with color threshold value and compaction 1 (basic level)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment does not match: claims test uses compaction 1 (basic level), but the test uses 3.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

static constexpr const char* const kMeshDefaultColourRGB = "Default RGB"; ///< default rgb values
static constexpr const char* const kMeshDefaultColourA = "Default Alpha"; ///< default alpha values
static constexpr const char* const kCustomColourThreshold
= "Custom Colour Threshold"; ///< default alpha values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment here and on the next does not corresponds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// check for per-vertex assignment
std::vector<uint32_t> indicesMap;
indicesMap.resize(numPoints, -1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using -1 here but 0xFFFFFFFF below. I would be clearfer if they were both the same. (Also, passing a negative value to initialize an unsigned integer without a cast might trigger a warning on some compilers and we generally have the warning-as-error compiler option turned on.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to check against the visited index, it is less memory friendly but more robust, let me know if that looks better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the AL plugin, if you feel the change would impact performance, you can revert it. The callers are from data you control, if you feel confident the index are always valid by construction, feel free to remove the check, but I'd advise to do profiling first to verify if it really is a bottleneck.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the changes in DiffPrimVar.cpp.
I have to admit that it was a copy-n-paste from guessColourSetInterpolationTypeExtensive() and the code has been used in production for a long time, I would keep it untouched in that case.

indicesMap.resize(numPoints, -1);
for (uint32_t pntInx = 0, n = pointIndices.length(); pntInx < n; ++pntInx) {
auto index = pointIndices[pntInx];
auto lastIndex = indicesMap[index];
Copy link
Collaborator

@pierrebai-adsk pierrebai-adsk May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For robustness reason, I would suggest verifying that the index is within the indicesMap size, in case of data corruption. Just resize the indicesMap to the new-found size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@pierrebai-adsk pierrebai-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a few small improvements suggested.

pierrebai-adsk
pierrebai-adsk previously approved these changes May 3, 2022
@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label May 10, 2022
@seando-adsk seando-adsk merged commit c376709 into Autodesk:dev May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
al Related to AnimalLogic plugin ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants