Compare commits
24 Commits
2.9.0-alpha
...
2.9.1
| Author | SHA1 | Date | |
|---|---|---|---|
| f035111ffa | |||
| fa073f754f | |||
| 83919375f9 | |||
| defb11bc89 | |||
| 548b3ad352 | |||
| d2deecf099 | |||
| fbda0110cd | |||
| ba9ad9ac07 | |||
| d13db2b44a | |||
| 2c127c85f3 | |||
| cc099c0ff1 | |||
| 448ab70c3b | |||
| 020eba2727 | |||
| d8117e2c30 | |||
| 57a6d88e6b | |||
| 74cb3e5f85 | |||
| d0aeecc863 | |||
| 2803308c5e | |||
| 326f04f67d | |||
| 68972ba8f9 | |||
| 73a028b56f | |||
| 33890ef0ee | |||
| 53fe676ab6 | |||
| f027c7eca4 |
+90
-60
@@ -68,7 +68,10 @@ jobs:
|
||||
New-Item -Force "speckle-sharp-ci-tools/Installers/blender/$channel.yml" -ItemType File -Value "version: $semver"
|
||||
echo $semver
|
||||
python patch_version.py $semver
|
||||
speckle-sharp-ci-tools\InnoSetup\ISCC.exe speckle-sharp-ci-tools\blender.iss
|
||||
- run:
|
||||
name: Installer
|
||||
shell: cmd.exe #does not work in powershell
|
||||
command: speckle-sharp-ci-tools\InnoSetup\ISCC.exe speckle-sharp-ci-tools\blender.iss /Sbyparam=$p
|
||||
- when:
|
||||
condition: << parameters.installer >>
|
||||
steps:
|
||||
@@ -120,7 +123,7 @@ jobs:
|
||||
- when:
|
||||
condition:
|
||||
and:
|
||||
- << parameters.installer >>
|
||||
# - << parameters.installer >>
|
||||
- equal: [osx-x64, << parameters.runtime >>]
|
||||
steps:
|
||||
- run:
|
||||
@@ -182,33 +185,22 @@ jobs:
|
||||
paths:
|
||||
- speckle-sharp-ci-tools
|
||||
|
||||
deploy: # Uploads all installers found to S3
|
||||
docker:
|
||||
- image: cimg/base:2021.01
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: ./
|
||||
- run:
|
||||
name: List contents
|
||||
command: ls -R speckle-sharp-ci-tools/Installers
|
||||
- aws-s3/copy:
|
||||
arguments: "--recursive --endpoint=https://$SPACES_REGION.digitaloceanspaces.com --acl public-read"
|
||||
aws-access-key-id: SPACES_KEY
|
||||
aws-region: SPACES_REGION
|
||||
aws-secret-access-key: SPACES_SECRET
|
||||
from: '"speckle-sharp-ci-tools/Installers/"'
|
||||
to: s3://speckle-releases/installers/
|
||||
|
||||
deploy-manager2:
|
||||
deploy-connector-new:
|
||||
docker:
|
||||
- image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
parameters:
|
||||
slug:
|
||||
type: string
|
||||
file_slug:
|
||||
type: string
|
||||
os:
|
||||
type: string
|
||||
extension:
|
||||
type: string
|
||||
arch:
|
||||
type: string
|
||||
default: Any
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
@@ -221,7 +213,13 @@ jobs:
|
||||
command: |
|
||||
TAG=$(if [ "${CIRCLE_TAG}" ]; then echo $CIRCLE_TAG; else echo "0.0.0"; fi;)
|
||||
SEMVER=$(echo "$TAG" | sed -e 's/\/[a-zA-Z-]*//')
|
||||
/root/.dotnet/tools/Speckle.Manager.Feed deploy -s << parameters.slug >> -v ${SEMVER} -u https://releases.speckle.dev/installers/<< parameters.slug >>/<< parameters.slug >>-${SEMVER}.<< parameters.extension >> -o << parameters.os >> -f speckle-sharp-ci-tools/Installers/<< parameters.slug >>/<< parameters.slug >>-${SEMVER}.<< parameters.extension >>
|
||||
/root/.dotnet/tools/Speckle.Manager.Feed deploy \
|
||||
-s << parameters.slug >> \
|
||||
-v ${SEMVER} \
|
||||
-u https://releases.speckle.dev/installers/<< parameters.file_slug >>/<< parameters.file_slug >>-${SEMVER}.<< parameters.extension >> \
|
||||
-o << parameters.os >> \
|
||||
-a << parameters.arch >> \
|
||||
-f speckle-sharp-ci-tools/Installers/<< parameters.file_slug >>/<< parameters.file_slug >>-${SEMVER}.<< parameters.extension >>
|
||||
|
||||
workflows:
|
||||
build: # build the installers, but don't persist to workspace for deployment
|
||||
@@ -233,6 +231,7 @@ workflows:
|
||||
- main
|
||||
- /ci\/.*/
|
||||
- build-connector-win:
|
||||
name: Windows Build
|
||||
requires:
|
||||
- get-ci-tools
|
||||
filters:
|
||||
@@ -241,14 +240,17 @@ workflows:
|
||||
- main
|
||||
- /ci\/.*/
|
||||
- build-connector-mac:
|
||||
name: Mac ARM Build
|
||||
slug: blender-mac-arm
|
||||
runtime: osx-arm64
|
||||
requires:
|
||||
- get-ci-tools
|
||||
- build-connector-mac:
|
||||
name: Mac Intel Build
|
||||
slug: blender-mac-intel
|
||||
runtime: osx-x64
|
||||
requires:
|
||||
- get-ci-tools
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
- /ci\/.*/
|
||||
|
||||
deploy: # build installers and deploy
|
||||
jobs:
|
||||
- get-ci-tools:
|
||||
@@ -259,7 +261,7 @@ workflows:
|
||||
ignore: /.*/
|
||||
|
||||
- build-connector-win:
|
||||
name: build-deploy-connector-win
|
||||
name: Windows Build
|
||||
slug: blender
|
||||
installer: true
|
||||
requires:
|
||||
@@ -270,51 +272,79 @@ workflows:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
|
||||
# - build-connector-mac:
|
||||
# name: build-deploy-connector-mac-arm
|
||||
# slug: blender-mac-arm
|
||||
# runtime: osx-arm64
|
||||
# installer: true
|
||||
# requires:
|
||||
# - get-ci-tools
|
||||
# filters:
|
||||
# tags:
|
||||
# only: /^(all|mac)\/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
# branches:
|
||||
# ignore: /.*/
|
||||
|
||||
# - build-connector-mac:
|
||||
# name: build-deploy-connector-mac-intel
|
||||
# slug: blender-mac-intel
|
||||
# runtime: osx-x64
|
||||
# installer: true
|
||||
# requires:
|
||||
# - get-ci-tools
|
||||
# filters:
|
||||
# tags:
|
||||
# only: /^(all|mac)\/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
# branches:
|
||||
# ignore: /.*/
|
||||
|
||||
- deploy:
|
||||
- build-connector-mac:
|
||||
name: Mac ARM Build
|
||||
slug: blender-mac-arm
|
||||
runtime: osx-arm64
|
||||
installer: true
|
||||
requires:
|
||||
- get-ci-tools
|
||||
- build-deploy-connector-win
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
|
||||
- deploy-manager2:
|
||||
slug: blender
|
||||
os: Win
|
||||
extension: exe
|
||||
- build-connector-mac:
|
||||
name: Mac Intel Build
|
||||
slug: blender-mac-intel
|
||||
runtime: osx-x64
|
||||
installer: true
|
||||
requires:
|
||||
- get-ci-tools
|
||||
- deploy
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
|
||||
- deploy-connector-new:
|
||||
name: deploy-win
|
||||
slug: blender
|
||||
file_slug: blender
|
||||
os: Win
|
||||
extension: exe
|
||||
arch: Any
|
||||
requires:
|
||||
- Windows Build
|
||||
- Mac ARM Build
|
||||
- Mac Intel Build
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/ # For testing only! /ci\/.*/
|
||||
|
||||
- deploy-connector-new:
|
||||
name: deploy-mac-intel
|
||||
slug: blender
|
||||
file_slug: blender-mac-intel
|
||||
os: OSX
|
||||
arch: Intel
|
||||
extension: zip
|
||||
requires:
|
||||
- Windows Build
|
||||
- Mac ARM Build
|
||||
- Mac Intel Build
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/ # For testing only! /ci\/.*/
|
||||
|
||||
- deploy-connector-new:
|
||||
name: deploy-mac-arm
|
||||
slug: blender
|
||||
file_slug: blender-mac-arm
|
||||
os: OSX
|
||||
arch: Arm
|
||||
extension: zip
|
||||
requires:
|
||||
- Windows Build
|
||||
- Mac ARM Build
|
||||
- Mac Intel Build
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/ # For testing only! /ci\/.*/
|
||||
+2
-1
@@ -10,4 +10,5 @@ __pycache__/
|
||||
# dev
|
||||
.venv
|
||||
Installers/
|
||||
modules/
|
||||
modules/
|
||||
.tool-versions
|
||||
@@ -3,7 +3,7 @@
|
||||
Speckle | Blender
|
||||
</h1>
|
||||
<h3 align="center">
|
||||
Connector for Blender 2.92 & 2.93
|
||||
Connector for Blender
|
||||
</h3>
|
||||
<p align="center"><b>Speckle</b> is the data infrastructure for the AEC industry.</p><br/>
|
||||
|
||||
@@ -91,4 +91,4 @@ The Speckle Community hangs out on [the forum](https://discourse.speckle.works),
|
||||
Unless otherwise described, the code in this repository is licensed under the Apache-2.0 License. Please note that some modules, extensions or code herein might be otherwise licensed. This is indicated either in the root of the containing folder under a different license file, or in the respective file's header. If you have any questions, don't hesitate to get in touch with us via [email](mailto:hello@speckle.systems).
|
||||
|
||||
## Notes
|
||||
SpeckleBlender is written and maintained by [Tom Svilans](http://tomsvilans.com) ([Github](https://github.com/tsvilans)).
|
||||
Thanks to [Tom Svilans](http://tomsvilans.com) ([Github](https://github.com/tsvilans)) for the original v1 contribution!
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from typing import Union
|
||||
from bpy_speckle.convert.to_native import convert_to_native
|
||||
from specklepy.objects.base import Base
|
||||
|
||||
def get_speckle_subobjects(attr: dict | Base, scale: float, name: str) -> list:
|
||||
def get_speckle_subobjects(attr: Union[dict, Base], scale: float, name: str) -> list:
|
||||
subobjects = []
|
||||
keys = attr.keys() if isinstance(attr, dict) else attr.get_dynamic_member_names()
|
||||
for key in keys:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import math
|
||||
from typing import Union
|
||||
from bpy_speckle.functions import get_scale_length, _report
|
||||
import mathutils
|
||||
import bpy, bmesh, bpy_types
|
||||
@@ -38,7 +39,7 @@ def can_convert_to_native(speckle_object: Base) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def convert_to_native(speckle_object: Base, name: str = None) -> list | Object:
|
||||
def convert_to_native(speckle_object: Base, name: Optional[str] = None) -> Optional[Union[list, Object]]:
|
||||
speckle_type = type(speckle_object)
|
||||
speckle_name = (
|
||||
name
|
||||
@@ -63,6 +64,8 @@ def convert_to_native(speckle_object: Base, name: str = None) -> list | Object:
|
||||
# not making it hidden, so it will get added on send as i think it might be helpful? can reconsider
|
||||
converted = []
|
||||
for item in elements:
|
||||
if not isinstance(item, Base):
|
||||
continue
|
||||
item.parent_speckle_type = speckle_object.speckle_type
|
||||
blender_object = convert_to_native(item)
|
||||
if isinstance(blender_object, list):
|
||||
@@ -76,7 +79,7 @@ def convert_to_native(speckle_object: Base, name: str = None) -> list | Object:
|
||||
# convert breps
|
||||
if speckle_type is Brep:
|
||||
meshes = getattr(
|
||||
speckle_object, "displayValue", getattr(speckle_object, "displayMesh", None)
|
||||
speckle_object, "displayValue", getattr(speckle_object, "displayMesh", iter([]))
|
||||
)
|
||||
if material := getattr(speckle_object, "renderMaterial", getattr(speckle_object, "@renderMaterial", None),):
|
||||
for mesh in meshes:
|
||||
@@ -84,18 +87,19 @@ def convert_to_native(speckle_object: Base, name: str = None) -> list | Object:
|
||||
|
||||
return [convert_to_native(mesh) for mesh in meshes]
|
||||
|
||||
scale = 1.0
|
||||
if units := getattr(speckle_object, "units", None):
|
||||
scale = get_scale_length(units) / bpy.context.scene.unit_settings.scale_length
|
||||
# convert supported geometry
|
||||
if speckle_type is Mesh:
|
||||
if isinstance(speckle_object, Mesh):
|
||||
obj_data = mesh_to_native(speckle_object, name=speckle_name, scale=scale)
|
||||
elif speckle_type in SUPPORTED_CURVES:
|
||||
obj_data = icurve_to_native(speckle_object, name=speckle_name, scale=scale)
|
||||
elif speckle_type is Transform:
|
||||
elif isinstance(speckle_object, Transform):
|
||||
obj_data = transform_to_native(speckle_object, scale=scale)
|
||||
elif speckle_type is BlockDefinition:
|
||||
elif isinstance(speckle_object, BlockDefinition):
|
||||
obj_data = block_def_to_native(speckle_object, scale=scale)
|
||||
elif speckle_type is BlockInstance:
|
||||
elif isinstance(speckle_object, BlockInstance): # speckle_type is BlockInstance:
|
||||
obj_data = block_instance_to_native(speckle_object, scale=scale)
|
||||
else:
|
||||
_report(f"Unsupported type {speckle_type}")
|
||||
@@ -151,7 +155,7 @@ def mesh_to_native(speckle_mesh: Mesh, name: str, scale=1.0) -> bpy.types.Mesh:
|
||||
|
||||
return blender_mesh
|
||||
|
||||
def line_to_native(speckle_curve: Line, blender_curve: bpy.types.Curve, scale: float) -> bpy.types.Spline | None:
|
||||
def line_to_native(speckle_curve: Line, blender_curve: bpy.types.Curve, scale: float) -> Optional[bpy.types.Spline]:
|
||||
line = blender_curve.splines.new("POLY")
|
||||
line.points.add(1)
|
||||
|
||||
@@ -174,7 +178,7 @@ def line_to_native(speckle_curve: Line, blender_curve: bpy.types.Curve, scale: f
|
||||
return line
|
||||
|
||||
|
||||
def polyline_to_native(scurve: Polyline, bcurve: bpy.types.Curve, scale: float) -> bpy.types.Spline | None:
|
||||
def polyline_to_native(scurve: Polyline, bcurve: bpy.types.Curve, scale: float) -> Optional[bpy.types.Spline]:
|
||||
if value := scurve.value:
|
||||
N = len(value) // 3
|
||||
|
||||
@@ -198,7 +202,7 @@ def polyline_to_native(scurve: Polyline, bcurve: bpy.types.Curve, scale: float)
|
||||
return polyline
|
||||
|
||||
|
||||
def nurbs_to_native(scurve: Curve, bcurve: bpy.types.Curve, scale: float) -> bpy.types.Spline | None:
|
||||
def nurbs_to_native(scurve: Curve, bcurve: bpy.types.Curve, scale: float) -> Optional[bpy.types.Spline]:
|
||||
if points := scurve.points:
|
||||
N = len(points) // 3
|
||||
|
||||
@@ -227,7 +231,7 @@ def nurbs_to_native(scurve: Curve, bcurve: bpy.types.Curve, scale: float) -> bpy
|
||||
return nurbs
|
||||
|
||||
|
||||
def arc_to_native(rcurve: Arc, bcurve: bpy.types.Curve, scale: float) -> bpy.types.Spline | None:
|
||||
def arc_to_native(rcurve: Arc, bcurve: bpy.types.Curve, scale: float) -> Optional[bpy.types.Spline]:
|
||||
# TODO: improve Blender representation of arc
|
||||
|
||||
plane = rcurve.plane
|
||||
@@ -322,7 +326,7 @@ def icurve_to_native_spline(speckle_curve: Base, blender_curve: bpy.types.Curve,
|
||||
return arc_to_native(speckle_curve, blender_curve, scale)
|
||||
|
||||
|
||||
def icurve_to_native(speckle_curve: Base, name=None, scale=1.0) -> Curve | None:
|
||||
def icurve_to_native(speckle_curve: Base, name=None, scale=1.0) -> Optional[Curve]:
|
||||
curve_type = type(speckle_curve)
|
||||
if curve_type not in SUPPORTED_CURVES:
|
||||
_report(f"Unsupported curve type: {curve_type}")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Optional
|
||||
import bpy
|
||||
from bpy.types import MeshVertColor, MeshVertex, Object
|
||||
from bpy.types import Depsgraph, MeshVertColor, MeshVertex, Object
|
||||
from specklepy.objects.geometry import Mesh, Curve, Interval, Box, Point, Polyline
|
||||
from specklepy.objects.other import *
|
||||
from bpy_speckle.functions import _report
|
||||
@@ -14,7 +15,7 @@ UNITS = "m"
|
||||
CAN_CONVERT_TO_SPECKLE = ("MESH", "CURVE", "EMPTY")
|
||||
|
||||
|
||||
def convert_to_speckle(blender_object: Object, scale: float, units: str, desgraph=None) -> list | None:
|
||||
def convert_to_speckle(blender_object: Object, scale: float, units: str, desgraph: Optional[Depsgraph]) -> Optional[list]:
|
||||
global UNITS
|
||||
UNITS = units
|
||||
blender_type = blender_object.type
|
||||
@@ -100,7 +101,7 @@ def mesh_to_speckle(blender_object: Object, data: bpy.types.Mesh, scale=1.0) ->
|
||||
return [sm]
|
||||
|
||||
|
||||
def bezier_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name:str = None) -> Curve:
|
||||
def bezier_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name: Optional[str] = None) -> Curve:
|
||||
degree = 3
|
||||
closed = spline.use_cyclic_u
|
||||
|
||||
@@ -149,7 +150,7 @@ def bezier_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: floa
|
||||
)
|
||||
|
||||
|
||||
def nurbs_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name:str = None) -> Curve:
|
||||
def nurbs_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name: Optional[str] = None) -> Curve:
|
||||
knots = make_knots(spline)
|
||||
points = [tuple(matrix @ pt.co.xyz * scale) for pt in spline.points]
|
||||
degree = spline.order_u - 1
|
||||
@@ -175,7 +176,7 @@ def nurbs_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float
|
||||
)
|
||||
|
||||
|
||||
def poly_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name: str = None) -> Polyline:
|
||||
def poly_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float, name: Optional[str] = None) -> Polyline:
|
||||
points = [tuple(matrix @ pt.co.xyz * scale) for pt in spline.points]
|
||||
|
||||
length = spline.calc_length()
|
||||
@@ -192,7 +193,7 @@ def poly_to_speckle(matrix: List[float], spline: bpy.types.Spline, scale: float,
|
||||
)
|
||||
|
||||
|
||||
def icurve_to_speckle(blender_object: Object, data: bpy.types.Curve, scale=1.0) -> List[Base] | None:
|
||||
def icurve_to_speckle(blender_object: Object, data: bpy.types.Curve, scale=1.0) -> Optional[List[Base]]:
|
||||
UNITS = "m" if bpy.context.scene.unit_settings.system == "METRIC" else "ft"
|
||||
|
||||
if blender_object.type != "CURVE":
|
||||
@@ -221,7 +222,7 @@ def icurve_to_speckle(blender_object: Object, data: bpy.types.Curve, scale=1.0)
|
||||
return curves
|
||||
|
||||
|
||||
def ngons_to_speckle_polylines(blender_object: Object, data: bpy.types.Mesh, scale=1.0) -> List[Polyline] | None:
|
||||
def ngons_to_speckle_polylines(blender_object: Object, data: bpy.types.Mesh, scale=1.0) -> Optional[List[Polyline]]:
|
||||
UNITS = "m" if bpy.context.scene.unit_settings.system == "METRIC" else "ft"
|
||||
|
||||
if blender_object.type != "MESH":
|
||||
@@ -253,7 +254,7 @@ def ngons_to_speckle_polylines(blender_object: Object, data: bpy.types.Mesh, sca
|
||||
return polylines
|
||||
|
||||
|
||||
def material_to_speckle(blender_object: Object) -> RenderMaterial | None:
|
||||
def material_to_speckle(blender_object: Object) -> Optional[RenderMaterial]:
|
||||
"""Create and return a render material from a blender object"""
|
||||
if not getattr(blender_object.data, "materials", None):
|
||||
return None
|
||||
@@ -318,7 +319,7 @@ def block_instance_to_speckle(blender_instance: Object, scale=1.0):
|
||||
)
|
||||
|
||||
|
||||
def empty_to_speckle(blender_object: Object, scale=1.0) -> BlockInstance | None:
|
||||
def empty_to_speckle(blender_object: Object, scale=1.0) -> Optional[BlockInstance]:
|
||||
# probably an instance collection (block) so let's try it
|
||||
try:
|
||||
geo = blender_object.instance_collection.objects.items()
|
||||
|
||||
@@ -11,11 +11,10 @@ from bpy.props import (
|
||||
StringProperty,
|
||||
BoolProperty,
|
||||
)
|
||||
from bpy.types import Object
|
||||
from bpy.types import Context, Object
|
||||
from bpy_speckle.convert.to_native import can_convert_to_native, convert_to_native
|
||||
from bpy_speckle.convert.to_speckle import (
|
||||
convert_to_speckle,
|
||||
ngons_to_speckle_polylines,
|
||||
)
|
||||
from bpy_speckle.functions import (
|
||||
_check_speckle_client_user_stream,
|
||||
@@ -26,12 +25,13 @@ from bpy_speckle.convert import get_speckle_subobjects
|
||||
from bpy_speckle.clients import speckle_clients
|
||||
from bpy_speckle.operators.users import add_user_stream
|
||||
|
||||
from specklepy.api import operations
|
||||
from specklepy.api import operations, host_applications
|
||||
from specklepy.api.wrapper import StreamWrapper
|
||||
from specklepy.api.resources.stream import Stream
|
||||
from specklepy.transports.server import ServerTransport
|
||||
from specklepy.objects.geometry import *
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
def get_objects_collections(base: Base) -> Dict[str, list]:
|
||||
@@ -96,7 +96,47 @@ def get_objects_collections_recursive(base: Base, parent_col: bpy.types.Collecti
|
||||
return objects
|
||||
|
||||
|
||||
def bases_to_native(context: bpy.types.Context, collections: Dict[str, list], scale: float, stream_id: str, func: Callable = None):
|
||||
ObjectCallback = Optional[Callable[[bpy.types.Context, Object, Base], Object]]
|
||||
ReceiveCompleteCallback = Optional[Callable[[bpy.types.Context, Dict[str, Object]], None]]
|
||||
|
||||
def get_receive_funcs(context: Context, created_objects: Dict[str, Object]) -> tuple[ObjectCallback, ReceiveCompleteCallback]:
|
||||
"""
|
||||
Fetches the injected callback functions from user specified "Receive Script"
|
||||
"""
|
||||
|
||||
objectCallback: ObjectCallback = None
|
||||
receiveCompleteCallback: ReceiveCompleteCallback = None
|
||||
|
||||
if context.scene.speckle.receive_script in bpy.data.texts:
|
||||
mod = bpy.data.texts[context.scene.speckle.receive_script].as_module()
|
||||
if hasattr(mod, "execute_for_each"):
|
||||
objectCallback = mod.execute_for_each
|
||||
elif hasattr(mod, "execute"):
|
||||
objectCallback = lambda c, o, _ : mod.execute(c.scene, o)
|
||||
|
||||
if hasattr(mod, "execute_for_all"):
|
||||
receiveCompleteCallback = mod.execute_for_all
|
||||
|
||||
|
||||
progress = 0
|
||||
|
||||
def for_each_object(context: bpy.types.Context, obj: Object, base: Base) -> Object:
|
||||
nonlocal progress
|
||||
nonlocal created_objects
|
||||
nonlocal objectCallback
|
||||
|
||||
progress += 1 #TODO: Progress bar never reaches 100 because func is only called for convertible objects
|
||||
context.window_manager.progress_update(progress)
|
||||
created_objects[obj.name] = obj
|
||||
|
||||
if objectCallback:
|
||||
return objectCallback(context, obj, base)
|
||||
else:
|
||||
return obj
|
||||
|
||||
return (for_each_object, receiveCompleteCallback)
|
||||
|
||||
def bases_to_native(context: bpy.types.Context, collections: Dict[str, list], scale: float, stream_id: str, func: ObjectCallback = None):
|
||||
for col_name, objects in collections.items():
|
||||
col = bpy.data.collections[col_name]
|
||||
existing = get_existing_collection_objs(col)
|
||||
@@ -129,7 +169,14 @@ def bases_to_native(context: bpy.types.Context, collections: Dict[str, list], sc
|
||||
|
||||
|
||||
|
||||
def base_to_native(context: bpy.types.Context, base: Base, scale: float, stream_id: str, col: bpy.types.Collection, existing: Dict[str, Object], func: Callable = None):
|
||||
def base_to_native(context: bpy.types.Context,
|
||||
base: Base,
|
||||
scale: float,
|
||||
stream_id: str,
|
||||
col: bpy.types.Collection,
|
||||
existing: Dict[str, Object],
|
||||
func: ObjectCallback = None
|
||||
):
|
||||
new_objects = convert_to_native(base)
|
||||
if not isinstance(new_objects, list):
|
||||
new_objects = [new_objects]
|
||||
@@ -152,7 +199,7 @@ def base_to_native(context: bpy.types.Context, base: Base, scale: float, stream_
|
||||
Run injected function
|
||||
"""
|
||||
if func:
|
||||
new_object = func(context.scene, new_object)
|
||||
new_object = func(context, new_object, base) #this base object isn't the right one for hosted elements!
|
||||
|
||||
if (
|
||||
new_object is None
|
||||
@@ -232,7 +279,6 @@ def create_nested_hierarchy(base, hierarchy, objects):
|
||||
|
||||
return base
|
||||
|
||||
|
||||
class ReceiveStreamObjects(bpy.types.Operator):
|
||||
"""
|
||||
Receive stream objects
|
||||
@@ -312,10 +358,19 @@ class ReceiveStreamObjects(bpy.types.Operator):
|
||||
_report("No commits found. Probably an empty stream.")
|
||||
return {"CANCELLED"}
|
||||
|
||||
commit = branch.commits.items[int(bbranch.commit)]
|
||||
commit: Commit = branch.commits.items[int(bbranch.commit)]
|
||||
|
||||
transport = ServerTransport(stream.id, client)
|
||||
stream_data = operations.receive(commit.referencedObject, transport)
|
||||
|
||||
metrics.track(
|
||||
metrics.RECEIVE,
|
||||
getattr(transport, "account", None),
|
||||
custom_props={
|
||||
"sourceHostApp": host_applications.get_host_app_from_string(commit.sourceApplication).slug,
|
||||
"sourceHostAppVersion": commit.sourceApplication
|
||||
},
|
||||
)
|
||||
stream_data = operations._untracked_receive(commit.referencedObject, transport)
|
||||
client.commit.received(
|
||||
bstream.id,
|
||||
commit.id,
|
||||
@@ -337,8 +392,8 @@ class ReceiveStreamObjects(bpy.types.Operator):
|
||||
name = "{} [ {} @ {} ]".format(stream.name, branch.name, commit.id)
|
||||
col = create_collection(name)
|
||||
col.speckle.stream_id = stream.id
|
||||
col.speckle.name = stream.name
|
||||
col.speckle.units = stream_data.units
|
||||
col.speckle.units = stream_data.units or "m"
|
||||
|
||||
if col.name not in bpy.context.scene.collection.children:
|
||||
bpy.context.scene.collection.children.link(col)
|
||||
|
||||
@@ -351,35 +406,15 @@ class ReceiveStreamObjects(bpy.types.Operator):
|
||||
Set conversion scale from stream units
|
||||
"""
|
||||
scale = (
|
||||
get_scale_length(stream_data.units)
|
||||
get_scale_length(col.speckle.units)
|
||||
/ context.scene.unit_settings.scale_length
|
||||
)
|
||||
|
||||
"""
|
||||
Get script from text editor for injection
|
||||
"""
|
||||
userFunc = None
|
||||
if context.scene.speckle.receive_script in bpy.data.texts:
|
||||
mod = bpy.data.texts[context.scene.speckle.receive_script].as_module()
|
||||
if hasattr(mod, "execute"):
|
||||
userFunc = mod.execute
|
||||
|
||||
createdObjects:Dict[str, Object] = {}
|
||||
|
||||
progress = 0
|
||||
def func(scene, obj: Object):
|
||||
nonlocal progress
|
||||
nonlocal context
|
||||
nonlocal createdObjects
|
||||
|
||||
progress += 1 #TODO: Progress bar neverreaches 100 because func is only called for convertable objects
|
||||
context.window_manager.progress_update(progress)
|
||||
createdObjects[obj.name] = obj
|
||||
|
||||
if userFunc:
|
||||
return userFunc(scene, obj)
|
||||
else:
|
||||
return obj
|
||||
created_objects = {}
|
||||
(func, on_complete) = get_receive_funcs(context, created_objects)
|
||||
|
||||
|
||||
"""
|
||||
@@ -390,10 +425,14 @@ class ReceiveStreamObjects(bpy.types.Operator):
|
||||
|
||||
|
||||
if self.clean_meshes:
|
||||
self.clean_converted_meshes(context, createdObjects)
|
||||
self.clean_converted_meshes(context, created_objects)
|
||||
|
||||
if on_complete:
|
||||
on_complete(context, created_objects)
|
||||
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Generated
+379
-699
File diff suppressed because it is too large
Load Diff
+5
-2
@@ -2,12 +2,12 @@
|
||||
name = "speckle-blender"
|
||||
version = "2.0.0"
|
||||
description = "the Speckle 2.0 connector for Blender!"
|
||||
authors = ["izzy lyseggen <izzy.lyseggen@gmail.com>"]
|
||||
authors = ["izzy lyseggen <izzy.lyseggen@gmail.com>", "Gergő Jedlicska <gergo@jedlicska.com>"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.8, <4.0.0"
|
||||
specklepy = "^2.6.6"
|
||||
specklepy = "^2.9.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
devtools = "^0.6.1"
|
||||
@@ -16,6 +16,9 @@ fake-bpy-module-latest = "^20220401"
|
||||
black = "^21.12b0"
|
||||
pylint = "^2.12.2"
|
||||
|
||||
[tool.poetry.group.local_specklepy.dependencies]
|
||||
specklepy = {path = "../specklepy", develop = true}
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
Reference in New Issue
Block a user