PLY: import/export custom vertex attributes (#108948) #114320

Merged
Aras Pranckevicius merged 3 commits from aras_p/blender:ply_custom_attributes into main 2023-10-31 14:08:04 +01:00

Implements #108948 - support for custom point domain attributes for PLY import and export. Notes:

  • Custom attributes are always represented as scalar floats. PLY itself has some data types that blender can't fully represent, e.g. double or uint32, or some that fit into a float just fine but blender does not have them as separate types (e.g. int16).
  • When importing, any PLY vertex attribute that is not one of "standard" names (position, normal, etc.) gets turned into a custom attribute.
  • For exporting, more complex custom attributes (e.g. 2D/3D floats, quaternions, colors) get turned into several PLY attributes, with "_x" like suffix.

Custom attribute import/export is on by default in the UI.

Implements #108948 - support for custom point domain attributes for PLY import and export. Notes: - Custom attributes are always represented as scalar floats. PLY itself has some data types that blender can't fully represent, e.g. double or uint32, or some that fit into a float just fine but blender does not have them as separate types (e.g. int16). - When importing, any PLY vertex attribute that is not one of "standard" names (position, normal, etc.) gets turned into a custom attribute. - For exporting, more complex custom attributes (e.g. 2D/3D floats, quaternions, colors) get turned into several PLY attributes, with "_x" like suffix. Custom attribute import/export is on by default in the UI.
Aras Pranckevicius added 1 commit 2023-10-31 12:21:49 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
7812728d69
PLY: import/export custom vertex attributes (#108948)
Implements #108948 - support for custom point domain attributes
for PLY import and export. Notes:

- Custom attributes are always represented as scalar floats. PLY
  itself has some data types that blender can't fully represent, e.g.
  double or uint32, or some that fit into a float just fine but
  blender does not have them as separate types (e.g. int16).
- When importing, any PLY vertex attribute that is not one of
  "standard" names (position, normal, etc.) gets turned into a custom
  attribute.
- For exporting, more complex custom attributes (e.g. 2D/3D floats,
  quaternions, colors) get turned into several PLY attributes,
  with "_x" like suffix.

Custom attribute import/export is on by default in the UI.
Author
Member

@blender-bot build

@blender-bot build
Aras Pranckevicius added the
Interest
Import Export
label 2023-10-31 12:25:51 +01:00
Aras Pranckevicius added this to the Pipeline, Assets & IO project 2023-10-31 12:25:56 +01:00
Aras Pranckevicius requested review from Hans Goudey 2023-10-31 12:28:31 +01:00
Hans Goudey requested changes 2023-10-31 12:41:31 +01:00
Hans Goudey left a comment
Member

Looks pretty straightforward, I just have some cleanup comments and suggestions about the attribute API.

Looks pretty straightforward, I just have some cleanup comments and suggestions about the attribute API.
@ -150,0 +163,4 @@
return true;
}
const GVArraySpan attribute = *mesh->attributes().lookup(
Member

Looks like the attribute API could handle some of these conversions itself, if you thought that simplified things:

    const VArray<float> attribute = *attributes.lookup<float>(attribute_id, ATTR_DOMAIN_POINT);
    PlyCustomAttribute attr;
    attr.data.resize(attribute.size());
    attribute.materialize(attr.data);

It's a bit unfortunate to have to implement all the others here, but I don't have a simple better way to do that right now. We have all these conversions implemented as multi-functions (SeparateQuaternionFunction for example), but setting up a field evaluation here is probably a bit too complex for here.

Looks like the attribute API could handle some of these conversions itself, if you thought that simplified things: ``` const VArray<float> attribute = *attributes.lookup<float>(attribute_id, ATTR_DOMAIN_POINT); PlyCustomAttribute attr; attr.data.resize(attribute.size()); attribute.materialize(attr.data); ``` It's a bit unfortunate to have to implement all the others here, but I don't have a simple better way to do that right now. We have all these conversions implemented as multi-functions (`SeparateQuaternionFunction` for example), but setting up a field evaluation here is probably a bit too complex for here.
Author
Member

Hmm that would make the "scalar to scalar" paths slightly simpler, but would still not address the "vectors/quats/colors need to be split into multiple scalars" complexity, which is the main issue here. I'll just probably leave it as is.

Hmm that would make the "scalar to scalar" paths slightly simpler, but would still not address the "vectors/quats/colors need to be split into multiple scalars" complexity, which is the main issue here. I'll just probably leave it as is.
Member

That's fine too

That's fine too
aras_p marked this conversation as resolved
@ -150,0 +165,4 @@
const GVArraySpan attribute = *mesh->attributes().lookup(
attribute_id, meta_data.domain, meta_data.data_type);
if (attribute.is_empty()) {
Member

This check could happen once at the beginning of the function

This check could happen once at the beginning of the function
aras_p marked this conversation as resolved
@ -150,0 +224,4 @@
r_attributes.append(attr_y);
} break;
case CD_PROP_FLOAT3: {
PlyCustomAttribute attr_x, attr_y, attr_z;
Member

Giving PlyCustomAttribute a name and size constructor (or just using the default constructor?) would remove some of these extra boilerplate lines

Giving `PlyCustomAttribute` a name and size constructor (or just using the default constructor?) would remove some of these extra boilerplate lines
aras_p marked this conversation as resolved
@ -252,2 +252,4 @@
}
Vector<int64_t> custom_attr_indices;
for (int64_t prop_idx = 0, n_props = element.properties.size(); prop_idx < n_props; ++prop_idx) {
Member
  for (const int64_t prop_idx : element.properties.index_range()) {
``` for (const int64_t prop_idx : element.properties.index_range()) { ```
aras_p marked this conversation as resolved
@ -331,1 +345,4 @@
}
/* Custom attributes */
for (int64_t ci = 0; ci < custom_attr_indices.size(); ++ci) {
Member
    for (const int64_t ci : custom_attr_indices.index_range()) {
``` for (const int64_t ci : custom_attr_indices.index_range()) { ```
aras_p marked this conversation as resolved
@ -103,0 +103,4 @@
/* Custom attributes */
if (params.import_attributes && !data.vertex_custom_attr.is_empty()) {
for (const PlyCustomAttribute &attr : data.vertex_custom_attr) {
bke::SpanAttributeWriter<float> attr_writer =
Member

Slightly simpler use of the attribute API here:

      attributes.add<float>(attr.name,
                            ATTR_DOMAIN_POINT,
                            bke::AttributeInitVArray(VArray<float>::ForSpan(attr.data)));
Slightly simpler use of the attribute API here: ``` attributes.add<float>(attr.name, ATTR_DOMAIN_POINT, bke::AttributeInitVArray(VArray<float>::ForSpan(attr.data))); ```
aras_p marked this conversation as resolved
@ -17,1 +17,4 @@
struct PlyCustomAttribute {
std::string name;
Vector<float> data; /* Any custom PLY attributes are converted to floats. */
Member

I'd go with Array here, since it doesn't need to be resized. reinitialize can be used instead of resize

I'd go with `Array` here, since it doesn't need to be resized. `reinitialize` can be used instead of `resize`
aras_p marked this conversation as resolved
Aras Pranckevicius added 1 commit 2023-10-31 13:18:27 +01:00
Aras Pranckevicius requested review from Hans Goudey 2023-10-31 13:33:33 +01:00
Hans Goudey approved these changes 2023-10-31 13:52:50 +01:00
@ -150,0 +204,4 @@
}
r_attributes.append(attr_x);
r_attributes.append(attr_y);
} break;
Member

Style guide mentions that break goes inside the braces for each case. Also worth double checking proper clang format is applied after too

Style guide mentions that `break` goes inside the braces for each case. Also worth double checking proper clang format is applied after too
Author
Member

That's the curious bit! I had them in separate lines, but make format put them in there. Maybe my clang is too old or smth? I'll check.

That's the curious bit! I had them in separate lines, but `make format` put them in there. Maybe my clang is too old or smth? I'll check.
Member

You sure you didn't have them after (outside of) the braces?

You sure you didn't have them after (outside of) the braces?
Author
Member

Aaaah! Ok. I should learn to read properly :)

Aaaah! Ok. I should learn to read properly :)
aras_p marked this conversation as resolved
Aras Pranckevicius added 1 commit 2023-10-31 14:05:38 +01:00
Aras Pranckevicius merged commit 0eb6aef3b0 into main 2023-10-31 14:08:04 +01:00
Aras Pranckevicius deleted branch ply_custom_attributes 2023-10-31 14:08:06 +01: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
2 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#114320
No description provided.