Skip to content

Commit

Permalink
Add support for Pointcloud objects (#68)
Browse files Browse the repository at this point in the history
* Fixes PolylineCurve name, fixes default Rhino material name, shows type of unsupported object

* Adds basic support for Pointcloud objects

* Small cleanup in pointcloud.py

Co-authored-by: Tom Svilans <[email protected]>
  • Loading branch information
tsvilans and Tom Svilans authored Mar 17, 2020
1 parent 9f96e64 commit ea588dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions import_3dm/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .views import handle_views
from .groups import handle_groups
from .instances import import_instance_reference, handle_instance_definitions, populate_instance_definitions
from .pointcloud import import_pointcloud

'''
Dictionary mapping between the Rhino file types and importer functions
Expand All @@ -40,6 +41,7 @@
r3d.ObjectType.Extrusion : import_render_mesh,
r3d.ObjectType.Mesh : import_render_mesh,
r3d.ObjectType.Curve : import_curve,
r3d.ObjectType.PointSet: import_pointcloud,
#r3d.ObjectType.InstanceReference : import_instance_reference
}

Expand Down
42 changes: 42 additions & 0 deletions import_3dm/converters/pointcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# MIT License

# Copyright (c) 2018-2019 Nathan Letwory, Joel Putnam, Tom Svilans, Lukas Fertig

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import rhino3dm as r3d
from . import utils


def import_pointcloud(context, ob, name, scale, options):

og = ob.Geometry
oa = ob.Attributes

# add points as mesh vertices

# The following line crashes. Seems rhino3dm does not like iterating over pointclouds.
#vertices = [(p.X * scale, p.Y * scale, p.Z * scale) for p in og]

vertices = [(og[v].X * scale, og[v].Y * scale, og[v].Z * scale) for v in range(og.Count)]

pointcloud = context.blend_data.meshes.new(name=name)
pointcloud.from_pydata(vertices, [], [])

return pointcloud

0 comments on commit ea588dc

Please sign in to comment.