Attributes: Add 2D integer vector attribute type #106677

Merged
Hans Goudey merged 13 commits from HooglyBoogly/blender:attributes-int2 into main 2023-04-14 16:08:17 +02:00
Member

This type will be used to store mesh edges in #106638, but it could
be used for anything else too. This commit adds support for:

  • The new type in the Python API
  • Editing the type in the edit mode "Attribute Set" operator
  • Rendering the type in EEVEE and Cycles for all geometry types
  • Geomtry nodes attribute interpolation and mixing
  • Viewing the type in the spreadsheet and using row filters

The attribute uses the blender::int2 type in most code, and
the vec2i DNA type in C code when necessary. The enum names
are based on INT32_2D for consistency with INT8 and INT32.

This type will be used to store mesh edges in #106638, but it could be used for anything else too. This commit adds support for: - The new type in the Python API - Editing the type in the edit mode "Attribute Set" operator - Rendering the type in EEVEE and Cycles for all geometry types - Geomtry nodes attribute interpolation and mixing - Viewing the type in the spreadsheet and using row filters The attribute uses the `blender::int2` type in most code, and the `vec2i` DNA type in C code when necessary. The enum names are based on `INT32_2D` for consistency with `INT8` and `INT32`.
Hans Goudey added 1 commit 2023-04-07 17:51:53 +02:00
a8dabbbebc Attributes: Add 2D integer vector attribute type
This type will be used to store mesh edges in #106638, but it could
be used for anything else too. This commit adds support for:
- The new type in the Python API
- Editing the type in the edit mode "Attribute Set" operator
- Rendering the type in EEVEE and Cycles for all geometry types
- Geomtry nodes attribute interpolation and mixing
- Viewing the type in the spreadsheet and using row filters
Hans Goudey added this to the Nodes & Physics project 2023-04-07 17:52:14 +02:00
Hans Goudey added the
Module
Nodes & Physics
Interest
Modeling
labels 2023-04-07 17:52:27 +02:00
Hans Goudey requested review from Jacques Lucke 2023-04-07 17:52:35 +02:00
Hans Goudey added this to the 3.6 LTS milestone 2023-04-07 17:52:40 +02:00
Member

Generally looks good, but please merge main again.

Generally looks good, but please merge `main` again.
Hans Goudey added 2 commits 2023-04-10 19:31:19 +02:00
Jacques Lucke requested changes 2023-04-11 13:21:23 +02:00
@ -123,1 +129,4 @@
template<> inline int2 mix3(const float3 &weights, const int2 &v0, const int2 &v1, const int2 &v2)
{
return weights.x * v0 + weights.y * v1 + weights.z * v2;
Member

Please check if this does the right thing. VSCode indicates that this might call an operator*(int a, int2 b). Same in mix4.

Please check if this does the right thing. VSCode indicates that this might call an `operator*(int a, int2 b)`. Same in `mix4`.
Author
Member

A cast to float2 solves this, I'm not sure there's much better to do here.

A cast to `float2` solves this, I'm not sure there's much better to do here.
@ -159,1 +175,4 @@
static bool int2_to_bool(const int2 &a)
{
return a.x > 0 && a.y > 0;
Member

This behavior is quite different compared to e.g. float2_to_bool or byte_color_to_bool. Not exactly sure what to do here, but needs some thought.

This behavior is quite different compared to e.g. `float2_to_bool` or `byte_color_to_bool`. Not exactly sure what to do here, but needs some thought.
Author
Member

Ah, right, I forgot to mention that. Not sure what's best here either. Our int_to_bool and float_to_bool implementations use value > 0 currently. I find it strange (and probably wrong?) that our vector to boolean conversions use is_zero instead. It seems like that was overlooked when we made the initial change to value > 0 in the first place. Do you remember that any better than me?

Ah, right, I forgot to mention that. Not sure what's best here either. Our `int_to_bool` and `float_to_bool` implementations use `value > 0` currently. I find it strange (and probably wrong?) that our vector to boolean conversions use `is_zero` instead. It seems like that was overlooked when we made the initial change to `value > 0` in the first place. Do you remember that any better than me?
Member

We might have overlooked it, but also also not obvious how the > 0 behavior can apply to more-dimensional data. Comparing to zero might be the only reasonable thing (and is likely also the fastest).

We might have overlooked it, but also also not obvious how the `> 0` behavior can apply to more-dimensional data. Comparing to zero might be the only reasonable thing (and is likely also the fastest).
@ -160,0 +183,4 @@
}
static int int2_to_int(const int2 &a)
{
return float2_to_int(int2_to_float2(a));
Member

Should be possible to compute the average without resorting to floats.

Should be possible to compute the average without resorting to floats.
Author
Member

Took a bit of research, it's surprisingly subtle! I took the std::midpoint implementation from C++20, which avoids overflow for all integral types.

Took a bit of research, it's surprisingly subtle! I took the `std::midpoint` implementation from C++20, which avoids overflow for all integral types.
Hans Goudey added 2 commits 2023-04-13 03:33:05 +02:00
Jesse Yurkovich reviewed 2023-04-14 00:13:11 +02:00
@ -160,0 +183,4 @@
}
static int int2_to_int(const int2 &a)
{
return (a.x + a.y) / 2;

This form is susceptible to overflow. You can borrow the implementation of std::midpoint (c++20 only) in the meantime: https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00146_source.html#l00214

This form is susceptible to overflow. You can borrow the implementation of `std::midpoint` (c++20 only) in the meantime: https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00146_source.html#l00214
deadpin marked this conversation as resolved
Hans Goudey added 2 commits 2023-04-14 03:55:54 +02:00
Hans Goudey added 1 commit 2023-04-14 03:56:55 +02:00
Hans Goudey requested review from Jacques Lucke 2023-04-14 03:57:04 +02:00
Jacques Lucke requested changes 2023-04-14 10:45:36 +02:00
@ -197,0 +209,4 @@
inline int2 mix4(
const float4 &weights, const int2 &v0, const int2 &v1, const int2 &v2, const int2 &v3)
{
return weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3;
Member

Probably needs the same fix with converting to float2 as above.

Probably needs the same fix with converting to `float2` as above.
HooglyBoogly marked this conversation as resolved
@ -1895,2 +1895,2 @@
/* 46: CD_HAIRMAPPING */ /* UNUSED */
{-1, "", 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 46: CD_PROP_INT32_2D */
{sizeof(vec2i), "vec2i", 1, N_("Int2"), nullptr, nullptr, nullptr, nullptr, nullptr},
Member

Also use Int 2D or something similar as name instead of Int2.

Also use `Int 2D` or something similar as name instead of `Int2`.
HooglyBoogly marked this conversation as resolved
@ -159,1 +175,4 @@
static bool int2_to_bool(const int2 &a)
{
return math::is_zero(a);
Member

There should be a !

There should be a `!`
HooglyBoogly marked this conversation as resolved
@ -160,0 +191,4 @@
}
static float int2_to_float(const int2 &a)
{
return float2_to_float(int2_to_float2(a));
Member

can also call float2 directly instead of int2_to_float2

can also call `float2` directly instead of `int2_to_float2`
HooglyBoogly marked this conversation as resolved
Hans Goudey added 5 commits 2023-04-14 14:37:26 +02:00
Hans Goudey requested review from Jacques Lucke 2023-04-14 14:41:42 +02:00
Jacques Lucke approved these changes 2023-04-14 15:33:45 +02:00
Hans Goudey merged commit 988f23cec3 into main 2023-04-14 16:08:17 +02:00
Hans Goudey deleted branch attributes-int2 2023-04-14 16:08:18 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106677
No description provided.