-
Notifications
You must be signed in to change notification settings - Fork 316
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
Accessor.to_dict requires values to be floats #2334
Comments
Note that the max = from_union([lambda x: from_list(from_float, x), from_none], obj.get("max"))
def from_float(x):
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x) …whereas the result["max"] = from_union([lambda x: from_list(to_float, x), from_none], self.max)
def to_float(x):
assert isinstance(x, float)
return x |
Hello, There are many issue in your code :
Here is a working code example
For the original bug: |
I very much appreciate your feedback. I'm not new to programming, but I'm new to programming Python, so your feedback about cached functions and keyword arguments is useful. I have two follow-on questions (unrelated to the bug) if you have the time:
|
The function has a decorator for caching (See https://github.com/KhronosGroup/glTF-Blender-IO/blob/295bbf7eda4c3de5429a01a0d919f42d90aaf5f9/addons/io_scene_gltf2/blender/exp/accessors.py#L22C1-L22C8) The cache decorator definition is here :
To be able to cache correctly, we have to get the parameter always in the same order, so no named parameter |
Fixed by 1dabfa9 |
Describe the bug
The Accessor class can be created using integer values, intended to be stored as UnsignedByte, but attempting to convert it to JSON fails because of this line calling
to_float
instead offrom_float
(or some sort offrom_number
):result["max"] = from_union([lambda x: from_list(to_float, x), from_none], self.max)
To Reproduce
The following (simplified) code from an extension is intended to create an animation where the values are boolean values, stored as
UnsignedByte
. This hook code runs without issue:However, when the glTF tries to be serialized to include this animation, it errors out with:
Changing the values from
[0, 1, 0]
to[0.0, 1.0, 0.0]
and the component type toFloat
fixes the problem, but stores undesired data.Expected behavior
An accessor for integer values should be possible.
Version
macOS 4.1.1
The text was updated successfully, but these errors were encountered: