Skip to content

Commit

Permalink
Specklepy 2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan committed Sep 8, 2023
1 parent d7ac6c0 commit 319cbf8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 254 deletions.
4 changes: 2 additions & 2 deletions bpy_speckle/blender_commit_object_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bpy.types import Object, Collection, ID
from specklepy.objects.base import Base
from bpy_speckle.functions import _report
from bpy_speckle.specklepy_extras.commit_object_builder import CommitObjectBuilder, ROOT
from specklepy.objects.graph_traversal.commit_object_builder import CommitObjectBuilder, ROOT
from specklepy.objects import Base
from specklepy.objects.other import Collection as SCollection
from attrs import define
Expand Down Expand Up @@ -79,7 +79,7 @@ def build_commit_object(self, root_commit_object: Base) -> None:
# Create all collections
root_col = self.ensure_collection(bpy.context.scene.collection)
root_col.collectionType = "Scene Collection"
for col in bpy.context.scene.collection.children_recursive:
for col in bpy.context.scene.collection.children_recursive: #type: ignore
self.ensure_collection(col)

objects_to_build = set(self.converted.values())
Expand Down
5 changes: 4 additions & 1 deletion bpy_speckle/convert/to_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,15 @@ def view_to_native(speckle_view, name: str, scale: float) -> bpy.types.Object:
native_cam = bpy.data.cameras.new(name=name)
native_cam.lens = 18 # 90° horizontal fov

if not hasattr(speckle_view, "origin"):
raise ConversionSkippedException("2D views not supported")

cam_obj = create_new_object(native_cam, name)

scale_factor = get_scale_factor(speckle_view, scale)
tx = (speckle_view.origin.x * scale_factor)
ty = (speckle_view.origin.y * scale_factor)
tz = (speckle_view.origin.z * scale_factor) #TODO: do these need to be scaled?
tz = (speckle_view.origin.z * scale_factor)

forward = MVector((speckle_view.forwardDirection.x, speckle_view.forwardDirection.y, speckle_view.forwardDirection.z))
up = MVector((speckle_view.upDirection.x, speckle_view.upDirection.y, speckle_view.upDirection.z))
Expand Down
2 changes: 1 addition & 1 deletion bpy_speckle/convert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bpy_speckle.functions import _report
from bpy.types import Material, Object, Collection as BCollection, Node, ShaderNodeVertexColor

from bpy_speckle.specklepy_extras.traversal import TraversalContext
from specklepy.objects.graph_traversal.traversal import TraversalContext

class ConversionSkippedException(Exception):
pass
Expand Down
48 changes: 8 additions & 40 deletions bpy_speckle/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,20 @@
from specklepy.objects.base import Base
from bpy_speckle.convert.constants import ELEMENTS_PROPERTY_ALIASES

from bpy_speckle.specklepy_extras.traversal import GraphTraversal, TraversalRule
from specklepy.objects.graph_traversal.traversal import GraphTraversal, TraversalRule
from specklepy.objects.units import get_scale_factor_to_meters, get_units_from_string

"""
Speckle functions
"""

UNIT_SCALE = {
"meters": 1.0,
"centimeters": 0.01,
"millimeters": 0.001,
"inches": 0.0254,
"feet": 0.3048,
"kilometers": 1000.0,
"mm": 0.001,
"cm": 0.01,
"m": 1.0,
"km": 1000.0,
"in": 0.0254,
"ft": 0.3048,
"yd": 0.9144,
"mi": 1609.340,
"us_ft": 1200.0 / 3937.0
}

"""
Utility functions
"""


def _report(msg):
def _report(msg: object) -> None:
"""
Function for printing messages to the console
"""
print("SpeckleBlender: {}".format(msg))


def get_scale_length(units: str) -> float:
if units.lower() in UNIT_SCALE.keys():
return UNIT_SCALE[units]
_report("Units <{}> are not supported.".format(units))
return 1.0


"""
Client, user, and stream functions
"""
"""Returns a scalar to convert distance values from one unit system to meters"""
return get_scale_factor_to_meters(get_units_from_string(units))


def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) -> GraphTraversal:
Expand All @@ -57,13 +25,13 @@ def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) ->

ignore_rule = TraversalRule(
[
lambda o: "Objects.Structural.Results" in o.speckle_type, #Sadly, this one is nessasary to avoid double conversion...
lambda o: "Objects.Structural.Results" in o.speckle_type, #Sadly, this one is necessary to avoid double conversion...
lambda o: "Objects.BuiltElements.Revit.Parameter" in o.speckle_type, #This one is just for traversal performance of revit commits
],
lambda _: [],
)

convertable_rule = TraversalRule(
convertible_rule = TraversalRule(
[can_convert_to_native],
lambda _: ELEMENTS_PROPERTY_ALIASES,
)
Expand All @@ -74,4 +42,4 @@ def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) ->
lambda o: o.get_member_names(), #TODO: avoid deprecated members
)

return GraphTraversal([ignore_rule, convertable_rule, default_rule])
return GraphTraversal([ignore_rule, convertible_rule, default_rule])
83 changes: 0 additions & 83 deletions bpy_speckle/specklepy_extras/commit_object_builder.py

This file was deleted.

122 changes: 0 additions & 122 deletions bpy_speckle/specklepy_extras/traversal.py

This file was deleted.

9 changes: 5 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"

[tool.poetry.dependencies]
python = ">=3.8, <4.0.0"
specklepy = "^2.16.0"
specklepy = "^2.16.1"
attrs = "^23.1.0"

# [tool.poetry.group.local_specklepy.dependencies]
Expand Down

0 comments on commit 319cbf8

Please sign in to comment.