Compare commits

...

93 Commits

Author SHA1 Message Date
izzy lyseggen 409adda784 Merge pull request #77 from specklesystems/izzy/nulls-fix
fix(convert): nulls on receive
2022-01-03 17:11:40 +00:00
izzylys f5f1c6a8d0 fix(convert): handle list display val 2022-01-03 17:09:57 +00:00
izzylys 1eca91a030 chore: bump specklepy 2022-01-03 17:09:29 +00:00
izzy lyseggen 6b872f11d9 Merge pull request #75 from specklesystems/izzy/add-parent-type
feat(convert): add parent type to display meshes
2021-12-09 10:59:28 +00:00
izzy lyseggen fd3742b800 feat(convert): add parent type to display meshes
makes it easier to work w geo from places like revit
2021-12-09 10:58:22 +00:00
izzy lyseggen 870174a969 Merge pull request #73 from specklesystems/ci/fix-install-platform
ci: fix install platform
2021-12-07 16:26:58 +00:00
izzy lyseggen 2c6dfcb340 ci: grab py version to ensure all is working 2021-12-07 16:22:42 +00:00
izzy lyseggen 4d3eacbe52 ci: no need to persist now i think 2021-12-07 16:05:51 +00:00
izzy lyseggen df7d631b54 ci: bump to 3.9.2 2021-12-07 16:05:23 +00:00
izzy lyseggen 07ceb07058 ci: try ths install again! 2021-12-07 16:01:16 +00:00
izzy lyseggen 112bc56ded ci: remove install specklepy step 2021-12-07 15:54:59 +00:00
izzy lyseggen 88e2744e93 ci: test in win exe 2021-12-07 15:53:52 +00:00
izzy lyseggen ad1c201c79 Merge pull request #72 from specklesystems/ci/install-changes
ci: preinstall specklepy
2021-12-07 14:54:26 +00:00
Gergő Jedlicska e18569f738 (ci) wait for install 2021-12-07 15:18:03 +01:00
Gergő Jedlicska f7e563f500 (ci) new glob 2021-12-07 15:15:13 +01:00
Gergő Jedlicska 7e56c21395 (ci) what is attached? 2021-12-07 15:01:47 +01:00
Gergő Jedlicska 30b701ee27 Merge branch 'ci/install-changes' of github.com:specklesystems/speckle-blender into ci/install-changes 2021-12-07 14:48:50 +01:00
Gergő Jedlicska 3cdbc09fc0 (ci) update job order 2021-12-07 14:48:43 +01:00
Gergő Jedlicska 656e41f03c (ci) update job order 2021-12-07 14:41:09 +01:00
Gergő Jedlicska 7da26e44b6 Update config.yml
try with glob pattern
2021-12-07 14:27:30 +01:00
izzy lyseggen 830ba842e0 ci: remove unecessary steps 2021-12-07 13:01:31 +00:00
izzy lyseggen d38f990e75 ci: fix modules path 2021-12-07 12:42:51 +00:00
izzy lyseggen c01836806c ci: persist to workspace 2021-12-07 12:38:20 +00:00
izzy lyseggen bf416dd228 ci: remove pip upgrade step? 2021-12-07 12:28:48 +00:00
izzy lyseggen a2e2c489b4 ci: change branch filter 2021-12-07 12:17:12 +00:00
izzy lyseggen c40c2d7955 ci: add specklepy install step 2021-12-07 12:08:37 +00:00
izzy lyseggen b45aa0d6c1 chore: return specklepy V in patch script w no arg
should allow us to grab the version for manual specklepy install in the ci env
2021-12-07 12:07:27 +00:00
izzy lyseggen 667616b1fb Merge pull request #68 from specklesystems/izzy/bump-deps
chore: bump to specklepy 2.4.2
2021-11-30 11:56:52 +00:00
izzy lyseggen 87cb69090a chore: bump to specklepy 2.4.2
attempting to resolve Plugin activation error due to `typing_extensions` #67
2021-11-30 11:56:10 +00:00
izzy lyseggen 4a8a0ca6c7 Merge pull request #66 from specklesystems/jm/ngons
Ngon Support
2021-11-29 10:54:20 +00:00
izzy lyseggen 3c0d1eba65 style: remove old comment re face error
(was resolved in #35)
2021-11-29 10:52:02 +00:00
JR-Morgan 14aaf4f064 N-gon ToSpeckle should now work! 2021-11-25 16:54:35 +00:00
JR-Morgan 10bf3e3af5 Experimenting with n-gon sending 2021-11-25 13:55:18 +00:00
izzy lyseggen 936d573510 Merge pull request #63 from specklesystems/izzy/read-receipts
feat(streams): add read reciepts + update to specklepy 2.4
2021-11-15 11:17:33 +00:00
izzy lyseggen 1f886202ec feat(streams): add commit received call 2021-11-15 11:14:51 +00:00
izzy lyseggen 479e5b5b98 fix(streams): update stream transport constructor 2021-11-15 11:14:29 +00:00
izzy lyseggen bed1ecf2cc chore: update specklepy to 2.4 2021-11-15 11:02:35 +00:00
izzy lyseggen a6cbce977f ci: remove pip install specklepy step 2021-10-14 17:07:08 +01:00
izzy lyseggen 376a90c5cf Merge pull request #59 from specklesystems/izzy/texture-coords
feat(convert): texture coords out and material receive fix
2021-10-14 18:03:52 +02:00
izzy lyseggen b0f8dbd63e fix(ui): diff fix for hiding globals
this is acting kinda weird, but it's taking up too much time for me
and it works as is so whatever
2021-10-14 17:03:19 +01:00
izzy lyseggen 89a8232a47 chore: update specklepy 2021-10-14 16:23:15 +01:00
izzy lyseggen 985f23b015 fix(convert): temp fix for materials w no name/id 2021-10-14 16:22:35 +01:00
izzy lyseggen d15a480e64 feat(uvs): try adding active uv layer 2021-10-14 16:22:35 +01:00
izzy lyseggen b88af9ac08 chore: update specklepy to 2.3.4 2021-10-13 10:37:14 +01:00
izzy lyseggen b649e29bdc Merge pull request #58 from specklesystems/izzy/chores
chore: smol fixes
2021-10-12 17:24:44 +02:00
izzy lyseggen bf907519a8 fix(streams): hide globals branch
you can't receive it anyway so let's just not show it
closes 🌿 Reorder branches in default selection menu #55
2021-10-12 16:23:07 +01:00
izzy lyseggen aa8cab2f27 fix(users): ssl check 2021-10-12 15:53:43 +01:00
izzy lyseggen 5157dbcfde feat(metrics): set host app 2021-10-12 15:28:20 +01:00
izzy lyseggen d03f11c57d Merge pull request #57 from specklesystems/izzy/update-ci
adds patcher script to patch connector and specklepy versions in installer and in connector init
2021-10-12 16:20:57 +02:00
izzy lyseggen b1deb1bb1c chore: update specklepy 2021-10-12 15:18:48 +01:00
izzy lyseggen bdd2c5d0ea ci: move patching to py script 2021-10-12 15:17:13 +01:00
izzy lyseggen 6783d82e48 ci: patch installer as well 2021-10-12 15:11:03 +01:00
izzy lyseggen f1db69fce5 ci: patch version script 2021-10-12 12:54:20 +01:00
Matteo Cominetti d09908412d Create close-issue.yml 2021-10-02 17:09:39 +01:00
Matteo Cominetti e84163a600 Create open-issue.yml 2021-10-02 17:09:19 +01:00
izzy lyseggen 03a77759a1 docs: update readme to align with new format 2021-09-03 16:26:15 +01:00
izzy lyseggen 47258cb7a6 Merge pull request #51 from specklesystems/izzy/toggle-modifiers
feat(send): toggle applying modifiers
2021-08-13 12:28:25 +01:00
izzy lyseggen b216f95187 feat(send): toggle applying moddifiers 2021-08-13 12:27:05 +01:00
izzy lyseggen 695135b655 Merge pull request #50 from specklesystems/izzy/stream-by-url
feat(ui): add stream, branch, or commit by url
2021-08-11 09:59:26 +01:00
izzy lyseggen 5f7e47221c feat(ui): get commit and branch from url 2021-08-11 09:51:03 +01:00
izzy lyseggen 38ee1c6ef9 chore: update specklepy again 2021-08-11 09:50:19 +01:00
izzy lyseggen d8b3c49dee chore: upgrade specklepy version 2021-08-11 08:59:11 +01:00
izzy lyseggen dceec1b061 feat(ui): add stream from url 2021-08-10 17:44:14 +01:00
izzy lyseggen 2071c3f3b4 chore: update deps (for specklepy ^2.2.6) 2021-08-10 11:43:45 +01:00
izzy lyseggen d45419ba5e Merge pull request #49 from specklesystems/izzy/help-panel
feat(ui): help panel w links to docs, tuts, forum
2021-08-10 11:38:30 +01:00
izzy lyseggen 2c640b7272 feat(ui): help panel w links to docs, tuts, forum 2021-08-10 11:37:16 +01:00
izzy lyseggen c00635d093 Merge pull request #48 from specklesystems/izzy/receive-fixes
fix(cols): try catch linking children
2021-08-04 10:26:34 +01:00
izzy lyseggen a07d4f0a8e fix(cols): try catch linking children 2021-08-04 10:25:33 +01:00
izzy lyseggen 61e721716f Merge pull request #47 from specklesystems/izzy/receive-fixes
fix(receive): clear matrix and get mat name
2021-08-04 10:10:15 +01:00
izzy lyseggen 91d12b5a6c fix: remove devtools ref 2021-08-04 10:09:52 +01:00
izzy lyseggen f331846138 fix(receive): clear matrix and get mat name 2021-08-04 10:08:59 +01:00
izzy lyseggen d350887860 Merge pull request #46 from specklesystems/izzy/materials-again
fix(receive): adding and assigning materials
2021-07-30 11:17:48 +01:00
izzy lyseggen 8ad607a8e0 docs(readme): update info on materials 2021-07-30 11:12:46 +01:00
izzy lyseggen 13f242e47f fix(user): make sure default is first active 2021-07-29 16:35:32 +01:00
izzy lyseggen 9f55acd02d fix(mats): get both detached and attached by name 2021-07-28 18:03:59 +01:00
izzy lyseggen 476f947b68 Merge pull request #45 from specklesystems/izzy/gh-receive-bug
fix(receive): resolve bug when receiveing 🦗 CSO
2021-07-19 18:20:55 +01:00
izzy lyseggen f56dea0a35 fix(receive): resolve bug when receiveing 🦗 CSO 2021-07-19 18:19:15 +01:00
izzy lyseggen c8d6b3ebea Merge pull request #41 from specklesystems/izzy/grasshopper-fix
fix(receive): handle nested lists from grasshopper
2021-07-01 17:20:28 +01:00
izzy lyseggen b2e7a899f6 fix(receive): handle nested lists from grasshopper 2021-07-01 17:03:45 +01:00
izzy lyseggen ef0f7ef46f Merge pull request #39 from specklesystems/izzy/units-and-conversions
General fixes regarding units, curves, and props
2021-07-01 16:02:51 +01:00
izzy lyseggen 8799f52dfb refactor: bit more cleanup 2021-07-01 16:00:00 +01:00
izzy lyseggen 22c1fb4fb2 refactor(curve): clean up curve conversions 2021-07-01 15:59:37 +01:00
izzy lyseggen bce03f9e38 feat(convert): adjust unit and prop handling 2021-07-01 15:59:12 +01:00
izzy lyseggen dc1d1adefc Merge pull request #34 from specklesystems/izzy/conversions
feat(conversions): improvements for `from_speckle` conversions
2021-06-18 18:23:27 +01:00
izzy lyseggen 4de1f6ecc1 feat(conversions): clen up from speckle 2021-06-18 18:10:36 +01:00
izzy lyseggen 4eaea0cc51 fix(send): add blender as commit source app 2021-06-18 15:34:47 +01:00
izzy lyseggen ccf2996096 feat(converter): get mesh for unsupported objs 2021-06-17 18:49:19 +01:00
izzy lyseggen aa0a4d2f3b fix(conversions): arc and nurbs fixes 2021-06-17 18:30:48 +01:00
izzy lyseggen 48ef9420de fix(conversion): try catch for fails 2021-06-17 18:29:50 +01:00
izzy lyseggen 6c223dba33 fix(user): increase stream limit 2021-06-17 18:29:36 +01:00
izzy lyseggen b028b93da2 Merge pull request #32 from specklesystems/izzy/refactor
fix(receive): some prelim geometry fixes
2021-06-17 16:54:35 +01:00
izzy lyseggen f6132179b1 fix(receive): some temp geometry fixes
will need to investigate this a bit further... but want to put something out for now
2021-06-17 16:52:21 +01:00
izzy lyseggen 52f40400bf chore: lock file 2021-06-17 16:51:21 +01:00
24 changed files with 1610 additions and 538 deletions
+52 -32
View File
@@ -20,9 +20,25 @@ jobs:
- checkout
- attach_workspace:
at: ./
- run:
name: upgrade pip and install specklepy
command: python -m pip install --upgrade pip & python -m pip install --target=.\modules specklepy
- run:
name: Install specklepy with python 3.7
shell: powershell.exe
command: |
$pyarr=(python --version).split(' ')[1].split('.')
$pyver=($pyarr[0..1] -join '.')
echo "using python version:" $pyver
$specklepy=(python patch_version.py)
python -m pip install --target=./modules-$pyver specklepy==$specklepy
- run:
name: Install python 3.9 and specklepy
shell: powershell.exe
command: |
choco install python --version=3.9.2
$pyarr=(C:\Python39\python.exe --version).split(' ')[1].split('.')
$pyver=($pyarr[0..1] -join '.')
echo "using python version:" $pyver
$specklepy=(python patch_version.py)
C:\Python39\python.exe -m pip install --target=./modules-$pyver specklepy==$specklepy
- run:
name: Patch
shell: powershell.exe
@@ -36,12 +52,34 @@ jobs:
# only create the yml if we have a tag
New-Item -Force "speckle-sharp-ci-tools/Installers/blender/$channel.yml" -ItemType File -Value "version: $version"
echo $version
speckle-sharp-ci-tools\InnoSetup\ISCC.exe speckle-sharp-ci-tools\blender.iss /dAppVersion=$version
ls
python patch_version.py $version
speckle-sharp-ci-tools\InnoSetup\ISCC.exe speckle-sharp-ci-tools\blender.iss
- persist_to_workspace:
root: ./
paths:
- speckle-sharp-ci-tools/Installers
install-specklepy: # due to ujson dep, we need to match the py version to the install
docker:
- image: "cimg/python:<<parameters.tag>>"
parameters:
tag:
default: "3.9"
type: string
steps:
- checkout
- run:
name: upgrade pip and install specklepy
command: |
specklepyver=$(python patch_version.py)
echo installing specklepy $specklepyver
python -m pip install --target=./modules-<<parameters.tag>> specklepy==$specklepyver
- persist_to_workspace:
root: ./
paths:
- modules-*
get-ci-tools: # Clones our ci tools and persists them to the workspace
docker:
- image: cimg/base:2021.01
@@ -53,10 +91,6 @@ jobs:
root: ./
paths:
- speckle-sharp-ci-tools
- persist_to_workspace:
root: ./
paths:
- speckle-sharp-ci-tools
deploy: # Uploads all installers found to S3
docker:
@@ -76,41 +110,27 @@ jobs:
to: s3://speckle-releases/installers/
workflows:
build:
jobs:
- get-ci-tools:
filters:
branches:
only:
- main
- /ci\/.*/
- build-connector:
slug: blender
requires:
- get-ci-tools
filters:
branches:
only:
- main
- /ci\/.*/
deploy:
main:
jobs:
- get-ci-tools:
filters:
tags:
only: /[0-9]+(\.[0-9]+)*/
only: /.*/
branches:
ignore: /.*/ # For testing only! /ci\/.*/
only:
- main
- /ci\/.*/
- build-connector:
slug: blender
requires:
- get-ci-tools
filters:
tags:
only: /[0-9]+(\.[0-9]+)*/
only: /.*/
branches:
ignore: /.*/ # For testing only! /ci\/.*/
only:
- main
- /ci\/.*/
- deploy:
requires:
- get-ci-tools
+78
View File
@@ -0,0 +1,78 @@
name: Update issue Status
on:
issues:
types: [closed]
jobs:
update_issue:
runs-on: ubuntu-latest
steps:
- name: Get project data
env:
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
ORGANIZATION: specklesystems
PROJECT_NUMBER: 9
run: |
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectNext(number: $number) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo "$PROJECT_ID"
echo "$STATUS_FIELD_ID"
echo 'DONE_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .settings | fromjson | .options[] | select(.name== "Done") | .id' project_data.json) >> $GITHUB_ENV
echo "$DONE_ID"
- name: Add Issue to project #it's already in the project, but we do this to get its node id!
env:
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
item_id="$( gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation($project:ID!, $id:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $id}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f id=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Update Status
env:
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation($project:ID!, $status:ID!, $id:ID!, $value:String!) {
set_status: updateProjectNextItemField(
input: {
projectId: $project
itemId: $id
fieldId: $status
value: $value
}
) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f status=$STATUS_FIELD_ID -f id=$ITEM_ID -f value=${{ env.DONE_ID }}
+50
View File
@@ -0,0 +1,50 @@
name: Move new issues into Project
on:
issues:
types: [opened]
jobs:
track_issue:
runs-on: ubuntu-latest
steps:
- name: Get project data
env:
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
ORGANIZATION: specklesystems
PROJECT_NUMBER: 9
run: |
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectNext(number: $number) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
- name: Add Issue to project
env:
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
item_id="$( gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation($project:ID!, $id:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $id}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f id=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
+1
View File
@@ -5,6 +5,7 @@ __pycache__/
# editor
.vscode
.idea
# dev
.venv
+44 -16
View File
@@ -1,23 +1,51 @@
# SpeckleBlender 2.0
Speckle add-on for Blender 2.92
<h1 align="center">
<img src="https://user-images.githubusercontent.com/2679513/131189167-18ea5fe1-c578-47f6-9785-3748178e4312.png" width="150px"/><br/>
Speckle | Blender
</h1>
<h3 align="center">
Connector for Blender 2.92 & 2.93
</h3>
<p align="center"><b>Speckle</b> is the data infrastructure for the AEC industry.</p><br/>
[![Twitter Follow](https://img.shields.io/twitter/follow/SpeckleSystems?style=social)](https://twitter.com/SpeckleSystems) [![Community forum users](https://img.shields.io/discourse/users?server=https%3A%2F%2Fdiscourse.speckle.works&style=flat-square&logo=discourse&logoColor=white)](https://discourse.speckle.works) [![website](https://img.shields.io/badge/https://-speckle.systems-royalblue?style=flat-square)](https://speckle.systems) [![docs](https://img.shields.io/badge/docs-speckle.guide-orange?style=flat-square&logo=read-the-docs&logoColor=white)](https://speckle.guide/dev/)
<p align="center"><a href="https://twitter.com/SpeckleSystems"><img src="https://img.shields.io/twitter/follow/SpeckleSystems?style=social" alt="Twitter Follow"></a> <a href="https://speckle.community"><img src="https://img.shields.io/discourse/users?server=https%3A%2F%2Fspeckle.community&amp;style=flat-square&amp;logo=discourse&amp;logoColor=white" alt="Community forum users"></a> <a href="https://speckle.systems"><img src="https://img.shields.io/badge/https://-speckle.systems-royalblue?style=flat-square" alt="website"></a> <a href="https://speckle.guide/dev/"><img src="https://img.shields.io/badge/docs-speckle.guide-orange?style=flat-square&amp;logo=read-the-docs&amp;logoColor=white" alt="docs"></a></p>
<p align="center"><a href="https://github.com/specklesystems/speckle-blender/"><img src="https://circleci.com/gh/specklesystems/speckle-blender.svg?style=svg&amp;circle-token=76eabd350ea243575cbb258b746ed3f471f7ac29" alt="Speckle-Next"></a> </p>
## Introduction
# About Speckle
What is Speckle? Check our ![YouTube Video Views](https://img.shields.io/youtube/views/B9humiSpHzM?label=Speckle%20in%201%20minute%20video&style=social)
### Features
- **Object-based:** say goodbye to files! Speckle is the first object based platform for the AEC industry
- **Version control:** Speckle is the Git & Hub for geometry and BIM data
- **Collaboration:** share your designs collaborate with others
- **3D Viewer:** see your CAD and BIM models online, share and embed them anywhere
- **Interoperability:** get your CAD and BIM models into other software without exporting or importing
- **Real time:** get real time updates and notifications and changes
- **GraphQL API:** get what you need anywhere you want it
- **Webhooks:** the base for a automation and next-gen pipelines
- **Built for developers:** we are building Speckle with developers in mind and got tools for every stack
- **Built for the AEC industry:** Speckle connectors are plugins for the most common software used in the industry such as Revit, Rhino, Grasshopper, AutoCAD, Civil 3D, Excel, Unreal Engine, Unity, QGIS, Blender and more!
### Try Speckle now!
Give Speckle a try in no time by:
- [![speckle XYZ](https://img.shields.io/badge/https://-speckle.xyz-0069ff?style=flat-square&logo=hackthebox&logoColor=white)](https://speckle.xyz) ⇒ creating an account at our public server
- [![create a droplet](https://img.shields.io/badge/Create%20a%20Droplet-0069ff?style=flat-square&logo=digitalocean&logoColor=white)](https://marketplace.digitalocean.com/apps/speckle-server?refcode=947a2b5d7dc1) ⇒ deploying an instance in 1 click
### Resources
- [![Community forum users](https://img.shields.io/badge/community-forum-green?style=for-the-badge&logo=discourse&logoColor=white)](https://speckle.community) for help, feature requests or just to hang with other speckle enthusiasts, check out our community forum!
- [![website](https://img.shields.io/badge/tutorials-speckle.systems-royalblue?style=for-the-badge&logo=youtube)](https://speckle.systems) our tutorials portal is full of resources to get you started using Speckle
- [![docs](https://img.shields.io/badge/docs-speckle.guide-orange?style=for-the-badge&logo=read-the-docs&logoColor=white)](https://speckle.guide/user/blender.html) reference on almost any end-user and developer functionality
# Repo structure
The Speckle UI can be found in the 3d viewport toolbar (N), under the Speckle tab.
<!--
This repo holds Speckle's:
- Default [Code of Conduct](.github/CODE_OF_CONDUCT.md),
- Default [Contribution Guidelines](.github/CONTRIBUTING.md),
- README template (you're reading it now),
- Default [Issue Template](.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md),
- Default [Pull Request Template](.github/PULL_REQUEST_TEMPLATE/PR_TEMPLATE.md),
- OSS License (Apache 2.0)
Either copy paste the parts that are useful in existing repos, or use this as a base when creating a new repository.
-->
Head to the [**📚 documentation**](https://speckle.guide/user/blender.html) for more information.
## Disclaimer
This code is WIP and as such should be used with extreme caution on non-sensitive projects.
@@ -45,7 +73,7 @@ This code is WIP and as such should be used with extreme caution on non-sensitiv
## Custom properties
- **SpeckleBlender** will look for a `texture_coordinates` property and use that to create a UV layer for the imported object. These texture coordinates are a space-separated list of floats (`[u v u v u v etc...]`) that is encoded as a base64 blob. This is subject to change as **SpeckleBlender** develops.
- If a `material` property is found, **SpeckleBlender** will create a material named using the sub-property `material.name`. If a material with that name already exists in Blender, **SpeckleBlender** will just assign that existing material to the object. This allows geometry to be updated without having to re-assign and re-create materials.
- If a `renderMaterial` property is found, **SpeckleBlender** will create a material named using the sub-property `renderMaterial.name`. If a material with that name already exists in Blender, **SpeckleBlender** will just assign that existing material to the object. This allows geometry to be updated without having to re-assign and re-create materials.
- Vertex colors are supported. The `colors` list from Speckle meshes is translated to a vertex color layer.
- Speckle properties will be imported as custom properties on Blender objects. Nested dictionaries are expanded to individual properties by flattening their key hierarchy. I.e. `propA:{'propB': {'propC':10, 'propD':'foobar'}}` is flattened to `propA.propB.propC = 10` and `propA.propB.propD = "foobar"`.
+3
View File
@@ -54,6 +54,7 @@ Import SpeckleBlender classes
"""
from specklepy.api.client import SpeckleClient # , SpeckleCache
from specklepy.logging import metrics
from bpy_speckle.ui import *
from bpy_speckle.properties import *
@@ -94,6 +95,8 @@ def register():
for cls in speckle_classes:
register_class(cls)
metrics.set_host_app("Blender")
"""
Register all new properties
"""
+59 -37
View File
@@ -4,12 +4,12 @@ from mathutils import Matrix
from .from_speckle import *
from .to_speckle import *
from .util import *
from bpy_speckle.util import find_key_case_insensitive
from bpy_speckle.functions import _report
from bpy_speckle.functions import _report, get_scale_length
from specklepy.objects.geometry import *
from specklepy.objects.other import RenderMaterial
FROM_SPECKLE_SCHEMAS = {
Mesh: import_mesh,
Brep: import_brep,
@@ -21,17 +21,6 @@ FROM_SPECKLE_SCHEMAS = {
}
# FROM_SPECKLE = {
# "Mesh": import_mesh,
# "Brep": import_brep,
# "Curve": import_curve,
# "Line": import_curve,
# "Polyline": import_curve,
# "Polycurve":import_curve,
# "Arc":import_curve,
# }
TO_SPECKLE = {
"MESH": export_mesh,
"CURVE": export_curve,
@@ -60,13 +49,13 @@ def add_blender_material(smesh, blender_object) -> None:
if blender_object.data is None:
return
if not hasattr(smesh, "renderMaterial"):
if not hasattr(smesh, "renderMaterial") and not hasattr(smesh, "@renderMaterial"):
return
speckle_mat = smesh.renderMaterial
mat_name = getattr(speckle_mat, "name", None)
speckle_mat = getattr(smesh, "renderMaterial", None) or smesh["@renderMaterial"]
mat_name = getattr(speckle_mat, "name", None) or speckle_mat.__dict__.get("@name")
if not mat_name:
mat_name = speckle_mat.applicationId or speckle_mat.id
mat_name = speckle_mat.applicationId or speckle_mat.id or speckle_mat.get_id()
blender_mat = bpy.data.materials.get(mat_name)
if not blender_mat:
blender_mat = bpy.data.materials.new(mat_name)
@@ -146,7 +135,10 @@ def add_custom_properties(speckle_object, blender_object):
blender_object["_speckle_type"] = type(speckle_object).__name__
# blender_object['_speckle_name'] = "SpeckleObject"
ignore = ["_chunkable", "_units"]
ignore = ["_chunkable", "_units", "units"]
if hasattr(speckle_object, "applicationId"):
blender_object["applicationId"] = speckle_object.applicationId
for key in speckle_object.get_dynamic_member_names():
if key in ignore:
@@ -180,21 +172,32 @@ def dict_to_speckle_object(data):
def from_speckle_object(speckle_object, scale, name=None):
speckle_name = (
name
or getattr(speckle_object, "name", None)
or speckle_object.speckle_type + f" -- {speckle_object.id}"
)
units = getattr(speckle_object, "units", None)
if units:
scale = get_scale_length(units) / bpy.context.scene.unit_settings.scale_length
# try native conversion
if type(speckle_object) in FROM_SPECKLE_SCHEMAS.keys():
print("Got object type: {}".format(type(speckle_object)))
speckle_name = (
name
or getattr(speckle_object, "name", None)
or speckle_object.speckle_type + f" -- {speckle_object.id}"
)
obdata = FROM_SPECKLE_SCHEMAS[type(speckle_object)](
speckle_object, scale, speckle_name
)
try:
obdata = FROM_SPECKLE_SCHEMAS[type(speckle_object)](
speckle_object, scale, speckle_name
)
except Exception as e: # conversion error
_report(f"Error converting {speckle_object} \n{e}")
return None
if speckle_name in bpy.data.objects.keys():
blender_object = bpy.data.objects[speckle_name]
blender_object.data = obdata
blender_object.matrix_world = Matrix()
if hasattr(obdata, "materials"):
blender_object.data.materials.clear()
else:
@@ -205,13 +208,29 @@ def from_speckle_object(speckle_object, scale, name=None):
add_custom_properties(speckle_object, blender_object)
add_blender_material(speckle_object, blender_object)
set_transform(speckle_object, blender_object)
# TODO: transforms
# set_transform(speckle_object, blender_object)
return blender_object
else:
_report("Invalid input: {}".format(speckle_object))
return None
# try display mesh
display = getattr(
speckle_object, "displayMesh", getattr(speckle_object, "displayValue", None)
)
if display:
# add parent type here so we can use it as a blender custom prop
# not making it hidden, so it will get added on send as i think it might be helpful? can reconsider
if isinstance(display, list):
for item in display:
item.parent_speckle_type = speckle_object.speckle_type
from_speckle_object(item, scale)
else:
display.parent_speckle_type = speckle_object.speckle_type
return from_speckle_object(display, scale, speckle_name)
# return none if fail
_report("Invalid input: {}".format(speckle_object))
return None
def get_speckle_subobjects(attr, scale, name):
@@ -264,30 +283,33 @@ def get_blender_custom_properties(obj, max_depth=1000):
return obj
if hasattr(obj, "keys"):
d = {}
for key in obj.keys():
if key in ignored_keys or key.startswith("_"):
continue
d[key] = get_blender_custom_properties(obj[key], max_depth - 1)
return d
return {
key: get_blender_custom_properties(obj[key], max_depth - 1)
for key in obj.keys()
if key not in ignored_keys and not key.startswith("_")
}
elif isinstance(obj, (list, tuple, idprop.types.IDPropertyArray)):
return [get_blender_custom_properties(o, max_depth - 1) for o in obj]
else:
return obj
def to_speckle_object(blender_object, scale):
def to_speckle_object(blender_object, scale, desgraph=None):
blender_type = blender_object.type
speckle_objects = []
speckle_material = material_to_speckle(blender_object)
if blender_type in TO_SPECKLE.keys():
if desgraph:
blender_object = blender_object.evaluated_get(desgraph)
converted = TO_SPECKLE[blender_type](blender_object, blender_object.data, scale)
if isinstance(converted, list):
speckle_objects.extend([c for c in converted if c != None])
for so in speckle_objects:
so.properties = get_blender_custom_properties(blender_object)
so.applicationId = so.properties.pop("applicationId", None)
if speckle_material:
so["renderMaterial"] = speckle_material
+3 -1
View File
@@ -7,7 +7,9 @@ def import_brep(speckle_brep, scale, name=None):
if not name:
name = speckle_brep.geometryHash or speckle_brep.id
display = speckle_brep.displayMesh or speckle_brep.displayValue
display = getattr(
speckle_brep, "displayMesh", getattr(speckle_brep, "displayValue", None)
)
if display:
if name in bpy.data.meshes.keys():
mesh = bpy.data.meshes[name]
+9 -9
View File
@@ -1,6 +1,6 @@
import bpy, math
from bpy_speckle.util import find_key_case_insensitive
from mathutils import Vector, Quaternion
import mathutils
from specklepy.objects.geometry import *
CONVERT = {}
@@ -85,7 +85,7 @@ def import_nurbs_curve(scurve, bcurve, scale):
1,
)
if len(scurve.weights == len(nurbs.points)):
if len(scurve.weights) == len(nurbs.points):
for i, w in enumerate(scurve.weights):
nurbs.points[i].weight = w
@@ -109,7 +109,7 @@ def import_arc(rcurve, bcurve, scale):
return
origin = plane.origin
normal = Vector(plane.normal.value)
normal = mathutils.Vector([plane.normal.x, plane.normal.y, plane.normal.z])
xaxis = plane.xdir
yaxis = plane.ydir
@@ -118,20 +118,20 @@ def import_arc(rcurve, bcurve, scale):
startAngle = rcurve.startAngle
endAngle = rcurve.endAngle
startQuat = Quaternion(normal, startAngle)
endQuat = Quaternion(normal, endAngle)
startQuat = mathutils.Quaternion(normal, startAngle)
endQuat = mathutils.Quaternion(normal, endAngle)
"""
Get start and end vectors, centre point, angles, etc.
"""
r1 = Vector(plane.xdir.value)
r1 = mathutils.Vector([plane.xdir.x, plane.xdir.y, plane.xdir.z])
r1.rotate(startQuat)
r2 = Vector(plane.xdir.value)
r2 = mathutils.Vector([plane.xdir.x, plane.xdir.y, plane.xdir.z])
r2.rotate(endQuat)
c = Vector(plane.origin.value) * scale
c = mathutils.Vector([plane.origin.x, plane.origin.y, plane.origin.z]) * scale
spt = c + r1 * radius
ept = c + r2 * radius
@@ -149,7 +149,7 @@ def import_arc(rcurve, bcurve, scale):
Ndiv = max(int(math.floor(angle / 0.3)), 2)
step = angle / float(Ndiv)
stepQuat = Quaternion(normal, step)
stepQuat = mathutils.Quaternion(normal, step)
tan = math.tan(step / 2) * radius
arc.points.add(Ndiv + 1)
+12 -26
View File
@@ -1,5 +1,6 @@
import bpy, bmesh, struct
import base64
from bpy_speckle.functions import _report
def add_vertices(smesh, bmesh, scale=1.0):
@@ -24,32 +25,17 @@ def add_faces(smesh, bmesh, smooth=False):
if sfaces and len(sfaces) > 0:
i = 0
while i < len(sfaces):
if sfaces[i] == 0:
i += 1
f = bmesh.faces.new(
(
bmesh.verts[int(sfaces[i])],
bmesh.verts[int(sfaces[i + 1])],
bmesh.verts[int(sfaces[i + 2])],
)
)
n = sfaces[i]
if n < 3:
n += 3 # 0 -> 3, 1 -> 4
i += 1
try:
f = bmesh.faces.new([bmesh.verts[int(x)] for x in sfaces[i : i + n]])
f.smooth = smooth
i += 3
elif sfaces[i] == 1:
i += 1
f = bmesh.faces.new(
(
bmesh.verts[int(sfaces[i])],
bmesh.verts[int(sfaces[i + 1])],
bmesh.verts[int(sfaces[i + 2])],
bmesh.verts[int(sfaces[i + 3])],
)
)
f.smooth = smooth
i += 4
else:
print("Invalid face length.\n" + str(sfaces[i]))
break
except Exception as e:
_report(f"Failed to create face for mesh {smesh.id} \n{e}")
i += n
bmesh.faces.ensure_lookup_table()
bmesh.verts.index_update()
@@ -149,7 +135,7 @@ def import_mesh(speckle_mesh, scale=1.0, name=None):
if not name:
name = speckle_mesh.geometryHash or speckle_mesh.id
if name in bpy.data.meshes.keys() and False:
if name in bpy.data.meshes.keys():
mesh = bpy.data.meshes[name]
else:
mesh = bpy.data.meshes.new(name=name)
+99 -101
View File
@@ -2,8 +2,100 @@ import bpy, bmesh, struct
from specklepy.objects.geometry import Curve, Interval, Box, Polyline
from bpy_speckle.convert.to_speckle.mesh import export_mesh
UNITS = "m"
def bezier_to_speckle(matrix, spline, scale, name=None):
degree = 3
closed = spline.use_cyclic_u
points = []
for i, bp in enumerate(spline.bezier_points):
if i > 0:
points.append(tuple(matrix @ bp.handle_left * scale))
points.append(tuple(matrix @ bp.co * scale))
if i < len(spline.bezier_points) - 1:
points.append(tuple(matrix @ bp.handle_right * scale))
if closed:
points.append(tuple(matrix @ spline.bezier_points[-1].handle_right * scale))
points.append(tuple(matrix @ spline.bezier_points[0].handle_left * scale))
points.append(tuple(matrix @ spline.bezier_points[0].co * scale))
num_points = len(points)
knot_count = num_points + degree - 1
knots = [0] * knot_count
for i in range(1, len(knots)):
knots[i] = i // 3
length = spline.calc_length()
domain = Interval(start=0, end=length, totalChildrenCount=0)
return Curve(
name=name,
degree=degree,
closed=spline.use_cyclic_u,
periodic=spline.use_cyclic_u,
points=list(sum(points, ())), # magic (flatten list of tuples)
weights=[1] * num_points,
knots=knots,
rational=False,
area=0,
volume=0,
length=length,
domain=domain,
units=UNITS,
bbox=Box(area=0.0, volume=0.0),
)
def nurbs_to_speckle(matrix, spline, scale, name=None):
knots = makeknots(spline)
# print("knots: {}".format(knots))
points = [tuple(matrix @ pt.co.xyz * scale) for pt in spline.points]
degree = spline.order_u - 1
length = spline.calc_length()
domain = Interval(start=0, end=length, totalChildrenCount=0)
return Curve(
name=name,
degree=degree,
closed=spline.use_cyclic_u,
periodic=spline.use_cyclic_u,
points=list(sum(points, ())), # magic (flatten list of tuples)
weights=[pt.weight for pt in spline.points],
knots=knots,
rational=False,
area=0,
volume=0,
length=length,
domain=domain,
units=UNITS,
bbox=Box(area=0.0, volume=0.0),
)
def poly_to_speckle(matrix, spline, scale, name=None):
points = [tuple(matrix @ pt.co.xyz * scale) for pt in spline.points]
length = spline.calc_length()
domain = Interval(start=0, end=length, totalChildrenCount=0)
return Polyline(
name=name,
closed=spline.use_cyclic_u,
value=list(sum(points, ())), # magic (flatten list of tuples)
length=length,
domain=domain,
bbox=Box(area=0.0, volume=0.0),
area=0,
units=UNITS,
)
def export_curve(blender_object, data, scale=1.0):
UNITS = "m" if bpy.context.scene.unit_settings.system == "METRIC" else "ft"
if blender_object.type != "CURVE":
return None
@@ -18,115 +110,22 @@ def export_curve(blender_object, data, scale=1.0):
mesh = export_mesh(blender_object, blender_object.to_mesh(), scale)
curves.extend(mesh)
unit_system = bpy.context.scene.unit_settings.system
for spline in data.splines:
if spline.type == "BEZIER":
degree = 3
closed = spline.use_cyclic_u
points = []
for i, bp in enumerate(spline.bezier_points):
if i > 0:
points.append(tuple(mat @ bp.handle_left * scale))
points.append(tuple(mat @ bp.co * scale))
if i < len(spline.bezier_points) - 1:
points.append(tuple(mat @ bp.handle_right * scale))
if closed:
points.append(
tuple(mat @ spline.bezier_points[-1].handle_right * scale)
)
points.append(tuple(mat @ spline.bezier_points[0].handle_left * scale))
points.append(tuple(mat @ spline.bezier_points[0].co * scale))
num_points = len(points)
knot_count = num_points + degree - 1
knots = [0] * knot_count
for i in range(1, len(knots), 1):
knots[i] = i // 3
length = spline.calc_length()
domain = Interval(
start=0, end=length, totalChildrenCount=0, applicationId="Blender"
)
bezier = Curve(
degree=degree,
closed=spline.use_cyclic_u,
periodic=spline.use_cyclic_u,
points=list(sum(points, ())), # magic (flatten list of tuples)
weights=[1] * num_points,
knots=knots,
rational=False,
area=0,
volume=0,
length=length,
domain=domain,
units="m" if unit_system == "METRIC" else "ft",
bbox=Box(area=0.0, volume=0.0),
applicationId="Blender",
)
curves.append(bezier)
curves.append(bezier_to_speckle(mat, spline, scale, blender_object.name))
elif spline.type == "NURBS":
knots = makeknots(spline)
# print("knots: {}".format(knots))
points = [tuple(mat @ pt.co.xyz * scale) for pt in spline.points]
degree = spline.order_u - 1
length = spline.calc_length()
domain = Interval(
start=0, end=length, totalChildrenCount=0, applicationId="Blender"
)
nurbs = Curve(
name=blender_object.name,
degree=degree,
closed=spline.use_cyclic_u,
periodic=spline.use_cyclic_u,
points=list(sum(points, ())), # magic (flatten list of tuples)
weights=[pt.weight for pt in spline.points],
knots=knots,
rational=False,
area=0,
volume=0,
length=length,
domain=domain,
units="m" if unit_system == "METRIC" else "ft",
bbox=Box(area=0.0, volume=0.0),
applicationId="Blender",
)
curves.append(nurbs)
curves.append(nurbs_to_speckle(mat, spline, scale, blender_object.name))
elif spline.type == "POLY":
points = [tuple(mat @ pt.co.xyz * scale) for pt in spline.points]
length = spline.calc_length()
domain = Interval(
start=0, end=length, totalChildrenCount=0, applicationId="Blender"
)
poly = Polyline(
name=blender_object.name,
closed=spline.use_cyclic_u,
value=list(sum(points, ())), # magic (flatten list of tuples)
length=length,
domain=domain,
bbox=Box(area=0.0, volume=0.0),
area=0,
units="m" if unit_system == "METRIC" else "ft",
applicationId="Blender",
)
curves.append(poly)
curves.append(poly_to_speckle(mat, spline, scale, blender_object.name))
return curves
def export_ngons_as_polylines(blender_object, data, scale=1.0):
UNITS = "m" if bpy.context.scene.unit_settings.system == "METRIC" else "ft"
if blender_object.type != "MESH":
return None
@@ -139,7 +138,7 @@ def export_ngons_as_polylines(blender_object, data, scale=1.0):
for v in poly.vertices:
value.extend(mat @ verts[v].co * scale)
domain = Interval(start=0, end=1, applicationId="Blender")
domain = Interval(start=0, end=1)
poly = Polyline(
name="{}_{}".format(blender_object.name, i),
closed=True,
@@ -148,8 +147,7 @@ def export_ngons_as_polylines(blender_object, data, scale=1.0):
domain=domain,
bbox=Box(area=0.0, volume=0.0),
area=0,
units="m" if unit_system == "METRIC" else "ft",
applicationId="Blender",
units=UNITS,
)
polylines.append(poly)
+9 -6
View File
@@ -14,8 +14,6 @@ def export_mesh(blender_object, data, scale=1.0):
verts = [tuple(mat @ x.co * scale) for x in data.vertices]
# TODO: add n-gon support, using tessfaces for now
# faces = [x.vertices for x in data.loop_triangles]
faces = [p.vertices for p in data.polygons]
unit_system = bpy.context.scene.unit_settings.system
@@ -24,18 +22,23 @@ def export_mesh(blender_object, data, scale=1.0):
vertices=list(sum(verts, ())),
faces=[],
colors=[],
textureCoordinates=[],
units="m" if unit_system == "METRIC" else "ft",
bbox=Box(area=0.0, volume=0.0),
applicationId="Blender",
)
if data.uv_layers.active:
for vt in data.uv_layers.active.data:
sm.textureCoordinates.extend([vt.uv.x, vt.uv.y])
for f in faces:
if len(f) == 3:
n = len(f)
if n == 3:
sm.faces.append(0)
elif len(f) == 4:
elif n == 4:
sm.faces.append(1)
else:
continue
sm.faces.append(n)
sm.faces.extend(f)
return [sm]
-2
View File
@@ -1,6 +1,4 @@
from specklepy.api.client import SpeckleClient
import requests
from bpy_speckle.clients import speckle_clients
"""
+13 -1
View File
@@ -17,12 +17,14 @@ from .streams import (
)
from .streams import (
UpdateGlobal,
AddStreamFromURL,
CreateStream,
CopyStreamId,
CopyCommitId,
CopyBranchName,
)
from .commit import DeleteCommit
from .misc import OpenSpeckleGuide, OpenSpeckleTutorials, OpenSpeckleForum
operator_classes = [
LoadUsers,
@@ -49,5 +51,15 @@ operator_classes.extend(
)
operator_classes.extend(
[ViewStreamDataApi, DeleteStream, SelectOrphanObjects, UpdateGlobal, CreateStream,]
[
ViewStreamDataApi,
DeleteStream,
SelectOrphanObjects,
UpdateGlobal,
AddStreamFromURL,
CreateStream,
OpenSpeckleGuide,
OpenSpeckleTutorials,
OpenSpeckleForum,
]
)
+35
View File
@@ -0,0 +1,35 @@
import bpy
import webbrowser
class OpenSpeckleGuide(bpy.types.Operator):
bl_idname = "speckle.open_speckle_guide"
bl_label = "Speckle Guide"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Browse the documentation on the Speckle Guide"
def execute(self, context):
webbrowser.open("https://speckle.guide/user/blender.html")
return {"FINISHED"}
class OpenSpeckleTutorials(bpy.types.Operator):
bl_idname = "speckle.open_speckle_tutorials"
bl_label = "Tutorials Portal"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Visit our tutorials portal for learning resources"
def execute(self, context):
webbrowser.open("https://speckle.systems/tutorials/")
return {"FINISHED"}
class OpenSpeckleForum(bpy.types.Operator):
bl_idname = "speckle.open_speckle_forum"
bl_label = "Community Forum"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Ask questions and join the discussion on our community forum"
def execute(self, context):
webbrowser.open("https://speckle.community/")
return {"FINISHED"}
+4 -4
View File
@@ -110,7 +110,7 @@ class DeleteObject(bpy.types.Operator):
for x in res["resource"]["objects"]
if x["_id"] == active.speckle.object_id
]
if existing == None:
if existing is None:
return {"CANCELLED"}
# print("Existing: %s" % SpeckleResource.to_json_pretty(existing))
new_objects = [
@@ -177,7 +177,7 @@ class UploadNgonsAsPolylines(bpy.types.Operator):
res = client.objects.create([polyline])
print(res)
if res == None:
if res is None:
_report(client.me)
continue
placeholders.extend(res)
@@ -185,7 +185,7 @@ class UploadNgonsAsPolylines(bpy.types.Operator):
# polyline['_id'] = res['_id']
# placeholders.append({'type':'Placeholder', '_id':res['_id']})
if len(placeholders) < 1:
if not placeholders:
return {"CANCELLED"}
# Get list of existing objects in stream and append new object to list
@@ -247,7 +247,7 @@ class UploadObject(bpy.types.Operator):
sm = to_speckle_object(active, scale)
placeholders = client.objects.create([sm])
if placeholders == None:
if placeholders is None:
return {"CANCELLED"}
sstream = client.streams.get(stream.id)
+204 -60
View File
@@ -1,8 +1,10 @@
"""
Stream operators
"""
from itertools import chain
from typing import Dict
import bpy, bmesh, os
from specklepy.api.models import Commit
import webbrowser
from bpy.props import (
StringProperty,
@@ -11,7 +13,6 @@ from bpy.props import (
CollectionProperty,
EnumProperty,
)
from bpy_speckle.functions import (
_check_speckle_client_user_stream,
_create_stream,
@@ -23,21 +24,25 @@ from bpy_speckle.convert.to_speckle import export_ngons_as_polylines
from bpy_speckle.convert import from_speckle_object
from bpy_speckle.clients import speckle_clients
from bpy_speckle.operators.users import add_user_stream
from specklepy.api import operations
from specklepy.api.credentials import StreamWrapper
from specklepy.api.resources.stream import Stream
from specklepy.transports.server import ServerTransport
from specklepy.objects import Base
from specklepy.objects.geometry import *
from specklepy.logging.exceptions import SpeckleException
def get_objects_collections(base):
def get_objects_collections(base) -> Dict:
"""Create collections based on the dynamic members on a root commit object"""
collections = {}
for name in base.get_dynamic_member_names():
value = base[name]
if isinstance(value, list):
col = create_collection(name)
collections[name] = [item for item in value if isinstance(item, Base)]
collections[name] = get_objects_nested_lists(value, col)
if isinstance(value, Base):
col = create_collection(name)
collections[name] = get_objects_collections_recursive(value, col)
@@ -45,8 +50,37 @@ def get_objects_collections(base):
return collections
def get_objects_collections_recursive(base, parent_col=None):
def get_objects_nested_lists(items, parent_col=None) -> List:
"""For handling the weird nested lists that come from Grasshopper"""
objects = []
if isinstance(items[0], list):
items = list(chain.from_iterable(items))
objects.extend(get_objects_nested_lists(items, parent_col))
else:
objects = [
get_objects_collections_recursive(item, parent_col)
for item in items
if isinstance(item, Base)
]
return objects
def get_objects_collections_recursive(base, parent_col=None) -> List:
"""Recursively create collections based on the dynamic members on nested `Base` objects within the root commit object"""
# if it's a convertable (registered) class and not just a plain `Base`, return the object itself
object_type = Base.get_registered_type(base.speckle_type)
if (
(object_type and object_type != Base)
or hasattr(base, "displayMesh")
or hasattr(base, "displayValue")
):
return [base]
# if it's an unknown type, try to drill further down to find convertable objects
objects = []
for name in base.get_dynamic_member_names():
value = base[name]
if isinstance(value, list):
@@ -54,8 +88,10 @@ def get_objects_collections_recursive(base, parent_col=None):
if isinstance(item, Base):
objects.append(item)
if isinstance(value, Base):
col = create_collection(name)
parent_col.children.link(col)
col = parent_col.children.get(name)
if not parent_col.children.get(name):
col = create_collection(name)
parent_col.children.link(col)
objects.append({name: get_objects_collections_recursive(value, col)})
return objects
@@ -70,60 +106,71 @@ def bases_to_native(context, collections, scale, stream_id, func=None):
elif isinstance(objects, list):
for obj in objects:
if isinstance(obj, dict):
bases_to_native(context, obj, scale, stream_id)
bases_to_native(context, obj, scale, stream_id, func)
elif isinstance(obj, list):
for item in obj:
if isinstance(item, dict):
bases_to_native(context, item, scale, stream_id, func)
elif isinstance(item, Base):
base_to_native(
context, item, scale, stream_id, col, existing, func
)
elif isinstance(obj, Base):
base_to_native(context, obj, scale, stream_id, col, existing, func)
else:
new_objects = [from_speckle_object(obj, scale)]
_report(
f"Something went wrong when receiving collection: {col_name}"
)
if hasattr(obj, "properties") and obj.properties is not None:
new_objects.extend(
get_speckle_subobjects(obj.properties, scale, obj.id)
)
elif isinstance(obj, dict) and "properties" in obj.keys():
new_objects.extend(
get_speckle_subobjects(obj["properties"], scale, obj["id"])
)
"""
Set object Speckle settings
"""
for new_object in new_objects:
if new_object is None:
continue
"""
Run injected function
"""
if func:
new_object = func(context.scene, new_object)
if (
new_object is None
): # Make sure that the injected function returned an object
new_obj = new_object
_report(
"Script '{}' returned None.".format(func.__module__)
)
continue
new_object.speckle.stream_id = stream_id
new_object.speckle.send_or_receive = "receive"
if new_object.speckle.object_id in existing.keys():
name = existing[new_object.speckle.object_id].name
existing[new_object.speckle.object_id].name = (
name + "__deleted"
)
new_object.name = name
col.objects.unlink(existing[new_object.speckle.object_id])
if new_object.name not in col.objects:
col.objects.link(new_object)
bpy.context.view_layer.update()
if context.area:
context.area.tag_redraw()
def base_to_native(context, base, scale, stream_id, col, existing, func=None):
new_objects = [from_speckle_object(base, scale)]
if hasattr(base, "properties") and base.properties is not None:
new_objects.extend(get_speckle_subobjects(base.properties, scale, base.id))
elif isinstance(base, dict) and "properties" in base.keys():
new_objects.extend(
get_speckle_subobjects(base["properties"], scale, base["id"])
)
"""
Set object Speckle settings
"""
for new_object in new_objects:
if new_object is None:
continue
"""
Run injected function
"""
if func:
new_object = func(context.scene, new_object)
if (
new_object is None
): # Make sure that the injected function returned an object
new_obj = new_object
_report("Script '{}' returned None.".format(func.__module__))
continue
new_object.speckle.stream_id = stream_id
new_object.speckle.send_or_receive = "receive"
if new_object.speckle.object_id in existing.keys():
name = existing[new_object.speckle.object_id].name
existing[new_object.speckle.object_id].name = name + "__deleted"
new_object.name = name
col.objects.unlink(existing[new_object.speckle.object_id])
if new_object.name not in col.objects:
col.objects.link(new_object)
def create_collection(name, clear_collection=True):
if name in bpy.data.collections:
col = bpy.data.collections[name]
@@ -222,8 +269,14 @@ class ReceiveStreamObjects(bpy.types.Operator):
commit = branch.commits.items[int(bbranch.commit)]
transport = ServerTransport(client, stream.id)
transport = ServerTransport(stream.id, client)
stream_data = operations.receive(commit.referencedObject, transport)
client.commit.received(
bstream.id,
commit.id,
source_application="blender",
message="received commit from Speckle Blender",
)
"""
Create or get Collection for stream objects
@@ -234,7 +287,6 @@ class ReceiveStreamObjects(bpy.types.Operator):
return {"CANCELLED"}
name = "{} [ {} @ {} ]".format(stream.name, branch.name, commit.id)
col = create_collection(name)
col.speckle.stream_id = stream.id
col.speckle.name = stream.name
@@ -243,8 +295,10 @@ class ReceiveStreamObjects(bpy.types.Operator):
bpy.context.scene.collection.children.link(col)
for child_col in collections.keys():
col.children.link(bpy.data.collections[child_col])
try:
col.children.link(bpy.data.collections[child_col])
except:
pass
"""
Set conversion scale from stream units
"""
@@ -280,6 +334,7 @@ class SendStreamObjects(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
bl_description = "Send selected objects to active stream"
apply_modifiers: BoolProperty(name="Apply modifiers", default=True)
commit_message: StringProperty(
name="Message",
default="Pushed elements from Blender.",
@@ -289,6 +344,7 @@ class SendStreamObjects(bpy.types.Operator):
layout = self.layout
col = layout.column()
col.prop(self, "commit_message")
col.prop(self, "apply_modifiers")
def invoke(self, context, event):
wm = context.window_manager
@@ -361,7 +417,13 @@ class SendStreamObjects(bpy.types.Operator):
if ngons:
converted = export_ngons_as_polylines(obj, scale)
else:
converted = to_speckle_object(obj, scale)
converted = to_speckle_object(
obj,
scale,
bpy.context.evaluated_depsgraph_get()
if self.apply_modifiers
else None,
)
if not converted:
continue
@@ -378,14 +440,18 @@ class SendStreamObjects(bpy.types.Operator):
hierarchy = get_collection_hierarchy(collection)
create_nested_hierarchy(base, hierarchy, objects)
transport = ServerTransport(client, stream.id)
transport = ServerTransport(stream.id, client)
obj_id = operations.send(base, [transport])
obj_id = operations.send(
base,
[transport],
)
client.commit.create(
stream.id,
obj_id,
branch.name,
message=self.commit_message,
source_application="blender",
)
bpy.ops.speckle.load_user_streams()
@@ -415,6 +481,84 @@ class ViewStreamDataApi(bpy.types.Operator):
return {"CANCELLED"}
class AddStreamFromURL(bpy.types.Operator):
"""
Add / select a stream using its url
"""
bl_idname = "speckle.add_stream_from_url"
bl_label = "Add stream from URL"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Add an existing stream by providing its URL"
stream_url: StringProperty(
name="Stream URL", default="https://speckle.xyz/streams/3073b96e86"
)
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop(self, "stream_url")
def invoke(self, context, event):
wm = context.window_manager
if len(context.scene.speckle.users) > 0:
return wm.invoke_props_dialog(self)
return {"CANCELLED"}
def execute(self, context):
speckle = context.scene.speckle
wrapper = StreamWrapper(self.stream_url)
user_index = next(
(i for i, u in enumerate(speckle.users) if wrapper.host in u.server_url),
None,
)
if user_index is None:
return {"CANCELLED"}
speckle.active_user = str(user_index)
user = speckle.users[user_index]
client = speckle_clients[user_index]
stream = client.stream.get(wrapper.stream_id)
if not isinstance(stream, Stream):
raise SpeckleException("Could not get the requested stream")
index, b_stream = next(
((i, s) for i, s in enumerate(user.streams) if s.id == stream.id),
(None, None),
)
if index is None:
add_user_stream(user, stream)
user.active_stream, b_stream = next(
(i, s) for i, s in enumerate(user.streams) if s.id == stream.id
)
else:
user.active_stream = index
if wrapper.branch_name:
b_index = b_stream.branches.find(wrapper.branch_name)
b_stream.branch = str(b_index if b_index != -1 else 0)
elif wrapper.commit_id:
commit = client.commit.get(wrapper.stream_id, wrapper.commit_id)
if isinstance(commit, Commit):
b_index = b_stream.branches.find(commit.branchName)
if b_index == -1:
b_index = 0
b_stream.branch = str(b_index)
c_index = b_stream.branches[b_index].commits.find(commit.id)
b_stream.branches[b_index].commit = str(c_index if c_index != -1 else 0)
# Update view layer
context.view_layer.update()
if context.area:
context.area.tag_redraw()
return {"FINISHED"}
class CreateStream(bpy.types.Operator):
"""
Create new stream
+40 -32
View File
@@ -49,12 +49,17 @@ class LoadUsers(bpy.types.Operator):
user.company = profile.userInfo.company or ""
user.authToken = profile.token
try:
client = SpeckleClient(host=profile.serverInfo.url, use_ssl=True)
client = SpeckleClient(
host=profile.serverInfo.url,
use_ssl="https" in profile.serverInfo.url,
)
client.authenticate(user.authToken)
speckle_clients.append(client)
except Exception as ex:
_report(ex)
users.remove(len(users) - 1)
if profile.isDefault:
context.scene.speckle.active_user = str(len(users) - 1)
context.scene.speckle.active_user_index = int(context.scene.speckle.active_user)
bpy.ops.speckle.load_user_streams()
@@ -65,6 +70,38 @@ class LoadUsers(bpy.types.Operator):
return {"FINISHED"}
def add_user_stream(user, stream):
s = user.streams.add()
s.name = stream.name
s.id = stream.id
s.description = stream.description
if not stream.branches:
return
# branches = [branch for branch in stream.branches.items if branch.name != "globals"]
for b in stream.branches.items:
branch = s.branches.add()
branch.name = b.name
if not b.commits:
continue
for c in b.commits.items:
commit = branch.commits.add()
commit.id = commit.name = c.id
commit.message = c.message
commit.author_name = c.authorName
commit.author_id = c.authorId
commit.created_at = c.createdAt
commit.source_application = str(c.sourceApplication)
if hasattr(s, "baseProperties"):
s.units = stream.baseProperties.units
else:
s.units = "Meters"
class LoadUserStreams(bpy.types.Operator):
"""
Load all available streams for active user user
@@ -83,7 +120,7 @@ class LoadUserStreams(bpy.types.Operator):
client = speckle_clients[int(context.scene.speckle.active_user)]
try:
streams = client.stream.list()
streams = client.stream.list(stream_limit=20)
except Exception as e:
_report("Failed to retrieve streams: {}".format(e))
return
@@ -93,40 +130,11 @@ class LoadUserStreams(bpy.types.Operator):
user.streams.clear()
streams = sorted(streams, key=lambda x: x.name, reverse=False)
default_units = "Meters"
for s in streams:
stream = user.streams.add()
stream.name = s.name
stream.id = s.id
stream.description = s.description
sstream = client.stream.get(id=s.id)
if not sstream.branches:
continue
for b in sstream.branches.items:
branch = stream.branches.add()
branch.name = b.name
if not b.commits:
continue
for c in b.commits.items:
commit = branch.commits.add()
commit.id = c.id
commit.message = c.message
commit.author_name = c.authorName
commit.author_id = c.authorId
commit.created_at = c.createdAt
commit.source_application = str(c.sourceApplication)
if hasattr(s, "baseProperties"):
stream.units = s.baseProperties.units
else:
stream.units = default_units
add_user_stream(user, sstream)
bpy.context.view_layer.update()
+2 -1
View File
@@ -48,10 +48,11 @@ class SpeckleBranchObject(bpy.types.PropertyGroup):
class SpeckleStreamObject(bpy.types.PropertyGroup):
def get_branches(self, context):
if len(self.branches) > 0:
if self.branches:
return [
(str(i), branch.name, branch.name, i)
for i, branch in enumerate(self.branches)
if branch.name != "globals"
]
return [("0", "<none>", "<none>", 0)]
+2 -1
View File
@@ -5,6 +5,7 @@ from .view3d import (
VIEW3D_PT_SpeckleUser,
VIEW3D_PT_SpeckleStreams,
VIEW3D_PT_SpeckleActiveStream,
VIEW3D_PT_SpeckleHelp,
)
ui_classes = [
@@ -13,5 +14,5 @@ ui_classes = [
VIEW3D_PT_SpeckleActiveStream,
VIEW3D_UL_SpeckleUsers,
VIEW3D_UL_SpeckleStreams,
# OBJECT_PT_speckle,
VIEW3D_PT_SpeckleHelp,
]
+23 -1
View File
@@ -144,11 +144,11 @@ class VIEW3D_PT_SpeckleStreams(bpy.types.Panel):
col.label(text="No stream data.")
else:
user = speckle.users[int(speckle.active_user)]
# col.label(text="Streams")
col.template_list(
"VIEW3D_UL_SpeckleStreams", "", user, "streams", user, "active_stream"
)
row = col.row(align=True)
row.operator("speckle.add_stream_from_url", text="", icon="URL")
row.operator("speckle.create_stream", text="", icon="ADD")
row.operator("speckle.delete_stream", text="", icon="REMOVE")
row.operator("speckle.load_user_streams", text="", icon="FILE_REFRESH")
@@ -253,3 +253,25 @@ class VIEW3D_PT_SpeckleActiveStream(bpy.types.Panel):
area.separator()
col.separator()
col.operator("speckle.view_stream_data_api", text="Open Stream in Web")
class VIEW3D_PT_SpeckleHelp(bpy.types.Panel):
"""
Speckle Help UI panel in the 3d viewport
"""
bl_space_type = "VIEW_3D"
bl_region_type = Region
bl_category = "Speckle"
bl_context = "objectmode"
bl_label = "Help"
def draw(self, context):
layout = self.layout
col = layout.column()
col.operator("speckle.open_speckle_guide")
col.separator()
col.operator("speckle.open_speckle_tutorials")
col.separator()
col.operator("speckle.open_speckle_forum")
+66
View File
@@ -0,0 +1,66 @@
import re
import sys
def patch_connector(tag):
"""Patches the connector version within the connector init file"""
bpy_file = "bpy_speckle/__init__.py"
tag = tag.split(".")
with open(bpy_file, "r") as file:
lines = file.readlines()
for (index, line) in enumerate(lines):
if '"version":' in line:
lines[index] = f' "version": ({tag[0]}, {tag[1]}, {tag[2]}),\n'
print(f"Patched connector version number in {bpy_file}")
break
with open(bpy_file, "w") as file:
file.writelines(lines)
def patch_installer(tag):
"""Patches the installer with the correct connector version and specklepy version"""
iss_file = "speckle-sharp-ci-tools/blender.iss"
py_tag = get_specklepy_version()
with open(iss_file, "r") as file:
lines = file.readlines()
lines.insert(11, f'#define SpecklepyVersion "{py_tag}"\n')
lines.insert(11, f'#define AppVersion "{tag}"\n')
with open(iss_file, "w") as file:
file.writelines(lines)
print(f"Patched installer with connector v{tag} and specklepy v{py_tag}")
def get_specklepy_version():
"""Get version of specklepy to install from the pyproject.toml"""
version = "2.3.3"
with open("pyproject.toml", "r") as f:
lines = [line for line in f if line.startswith("specklepy = ")]
if not lines:
raise Exception("Could not find specklepy in pyproject.toml")
match = re.search(r"[0-9]+(\.[0-9]+)*", lines[0])
if match:
version = match[0]
return version
def main():
if len(sys.argv) < 2:
print(get_specklepy_version())
return
tag = sys.argv[1]
if not re.match(r"[0-9]+(\.[0-9]+)*$", tag):
raise ValueError(f"Invalid tag provided: {tag}")
print(f"Patching version: {tag}")
patch_connector(tag)
patch_installer(tag)
if __name__ == "__main__":
main()
Generated
+799 -207
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -7,13 +7,15 @@ license = "Apache-2.0"
[tool.poetry.dependencies]
python = ">=3.7,<3.8"
specklepy = "^2.2.2"
specklepy = "^2.5.1"
[tool.poetry.dev-dependencies]
devtools = "^0.6.1"
numpy = "^1.20.2"
bpy = "^2.82.1"
bpy-build = "^2.1.0"
black = "^21.12b0"
pylint = "^2.12.2"
[build-system]
requires = ["poetry-core>=1.0.0"]