Page MenuHome

Fix T89017: PLY files from various programs are incompatible due to their exporters, and vertex-colored point clouds do not import color.
AbandonedPublic

Authored by Michael Prostka (MProstka) on Apr 21 2022, 5:05 PM.

Details

Summary

The PLY file parser has been expanded to cover a much larger range of known PLY oddities. In particular, J-Wildfire and Mandelbulb3D exports have their own irregularites and have been addressed. For vertex-colored point clouds, a new checkbox has been added to the File Requester.


The Python API call has a new optional Boolean parameter, use_verts(default=False).

bpy.ops.import_mesh.ply(filepath="", files=[], use_verts=False, directory="", filter_glob="*.ply")

Example usage for a point cloud:
obj = bpy.ops.import_mesh.ply(filepath="C:\\mb3d_mesh.ply", use_verts=True)

For backward compatibility, existing calls like:
obj = bpy.ops.import_mesh.ply(filepath="C:\\mb3d_mesh.ply")
are equivalent to calling the stock importer and shouldn't break existing scripts.

Diff Detail

Event Timeline

Michael Prostka (MProstka) requested review of this revision.Apr 21 2022, 5:05 PM
Michael Prostka (MProstka) created this revision.
Michael Prostka (MProstka) edited the summary of this revision. (Show Details)
Aras Pranckevicius (aras_p) requested changes to this revision.Apr 25 2022, 12:23 PM
Aras Pranckevicius (aras_p) added inline comments.
__init__.py
97

This looks like some debugging print. Is it needed?

import_ply.py
125

Minor: not sure if worth adding dates like "28 March 2022" to the comments.

293

It would be much easier to review if everything below would not change indentation, I guess, i.e.

# If attempting to load a point cloud file as mesh, import as verts instead and bail out
if self.use_verts:
    mesh = load_ply_verts(self, filepath, ply_name)
    return mesh

uvindices = colindices = None
# ...
300

I don't think MP Comment - below comments are left from stock importer comment is needed

521

Why specifically it's not a vertex color, but instead an attribute with this Col name?

Also I think some sort of "vertex/color handling" is being redone inside blender codebase as we speak (I've seen commits with some sort of "sculpt/vertex color unification" thingies happening just a week or two ago). Does that affect the choice of a custom attribute vs. vertex color by chance?

528

Not a python performance expert, but wondering: this is a loop over all the vertices. Would it make it faster to move a subexpression like newcolor.attributes['Col'] outside the loop, so that it would not have to search for that attribute, for each vertex, three times?

This revision now requires changes to proceed.Apr 25 2022, 12:23 PM

You have a good eye, Aras!

As regards line 521, it is indeed the new vertex/color handling going on inside the Sculpt Branch that requires this to be a custom attribute of type Vertex -> Color rather than the legacy Vertex Color which is Face Corner -> Byte Color.
For line 528, I agree performance can be improved. However, I deliberately ignored any performance improvements at the moment just to get it stable and well-tested. I haven’t seen an updated GsOC proposal from shkshk90, hopefully he hasn’t abandoned us! On the next round I’ll take another lap over the source and tighten up performance – that add_face() function is a real pig.

__init__.py: 97 - removed debug print statements
import_ply.py: 125 - comment updated
import_ply.py: 293 - fixed indentation and program logic
import_ply.py: 300 - comment removed

Code wise this looks good to me. But! I know nothing about either PLY nor Python. Might be a good idea to also ask for a review by some folks who wrote this code originally, like maybe @Campbell Barton (campbellbarton)

This revision is now accepted and ready to land.Apr 25 2022, 6:39 PM

Sage words, Aras, I will do so.

Campbell Barton (campbellbarton) requested changes to this revision.May 12 2022, 2:22 AM
Campbell Barton (campbellbarton) added inline comments.
__init__.py
110

For headings blender typically uses title caps, although I'm not sure why this is even necessary.

113–134

The patch description doesn't mention why this panel was added.
Unless it's essential I'd prefer user interface improvements be committed separately.

import_ply.py
22–24

This doesn't seem necessary.

126

Don't pass in self argument, pass in individual arguments instead. Using vertices can be returned instead of setting the operator property.

192

Prefer not to include these comments, such issues could be resolved in a cleanup pass - or suppressed.

283

I'd prefer not to pass in "self", as it's not clear which properties are used, also it's possible for the properties to be modified. Instead, pass in the arguments which are needed.

465

Again, no need to pass in self.

506–512

It seems unnecessarily convoluted to have the responsibility of object creation be different for vertex loading. load_ply can create the object in both cases.

518

The return value from this should be used instead of accessing it by name every time.

518–529

The this block does some odd things.

  • Access is a mesh which already has a variable assigned.
  • Uses the variable name newcolor for mesh data.
  • Excesses the color layer for each color channel.

... all these things can be changed a fairly easily.

521

No need for surrounding parenthesis.

534–537

Don't think it's necessary to include this because blender doesn't support per vertex UV coordinates (and isn't likely to).

541

Don't pass in self

This revision now requires changes to proceed.May 12 2022, 2:22 AM

Reminder to format subject and body of the patch to match our commit style so they can be used as the final commit message. Additional notes can be added below a ---.

See: https://wiki.blender.org/wiki/Style_Guide/Commit_Messages

Thank you! Revisions in progress.

Apologies to all, work and health have made it nearly impossible to progress at this time.

Hello,
i've been trying to do the same thing on another patch.

But as i got ahead, more and more questions pop up.

I've not found complete specification for .ply file about texture coordinates.

On the current exported uv are set for each vertex as "s" and "t" parameters, but i'm to found any file with this specs.
Moreover different program exports arbitrarely the color to vertex or faces.

Maybe a more comprehensive dataset to test is needed.