Skip to content

Commit 24d0120

Browse files
author
Snowdaw
committed
Update v1.0.1
1 parent 1505cff commit 24d0120

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ This allows users to create constructive solid geometry from within Blender usin
55
![](images/SD5_Demo.png)
66

77
# How to use
8-
Download the zip in the releases tab [here](https://github.com/Snowdaw/SD5/releases/tag/v1.0) and install the addon in Blender.
8+
Download the zip in the releases tab [here](https://github.com/Snowdaw/SD5/releases/) and install the addon in Blender.
99

1010
Open Blender and go to the scripting tab and create a new script with a name starting with "SD5_". This is to allow the handler to automatically execute the script in the post depsgraph handler.
1111

1212
The quick way is to now put the following in the script:
1313
```
14-
import SD5.utils as sd5
14+
import sd5
1515
1616
s = sd5.sphere(2)
1717
sd5.name = "SD5_Demo"
@@ -23,7 +23,7 @@ The better way would be to first add three empties to the scene.
2323
I will call them "C_Sphere", "C_Box" and "Bounds".
2424
Then put the following in the script:
2525
```
26-
import SD5.utils as sd5
26+
import sd5
2727
2828
# Add a new sphere and box
2929
s = sd5.sphere(1)

__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
@persistent
1313
def sd5_handler(scene, depsgraph):
14-
if bpy.context.mode != "OBJECT":
15-
return
16-
14+
1715
sd5_texts = []
1816
for sd5_text in bpy.data.texts:
1917
if sd5_text.name.startswith("SD5_"):
@@ -42,7 +40,10 @@ def sd5_handler(scene, depsgraph):
4240

4341
if temp_obj == None:
4442
temp_obj = bpy.data.objects.new(sd5_name, temp_mesh)
45-
bpy.data.collections["Collection"].objects.link(temp_obj)
43+
if not bpy.data.collections.get("SD5"):
44+
sd5_collection = bpy.data.collections.new("SD5")
45+
bpy.data.scenes["Scene"].collection.children.link(sd5_collection)
46+
bpy.data.collections["SD5"].objects.link(temp_obj)
4647

4748
temp_mesh.from_pydata(sd5_mesh[0], [], sd5_mesh[1], shade_flat=False)
4849
temp_obj.data = temp_mesh

sd5.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import bpy
2+
from libfive.stdlib import *
3+
4+
def set_control(s, control_name):
5+
control = bpy.data.objects.get(control_name)
6+
s = s.move(control.location)
7+
s = s.rotate_x(control.rotation_euler[0], control.location)
8+
s = s.rotate_y(-control.rotation_euler[1], control.location)
9+
s = s.rotate_z(control.rotation_euler[2], control.location)
10+
s = s.scale_xyz(control.scale, control.location)
11+
return s
12+
13+
def mesh_from_bounds(s, res, bounds_name):
14+
b = bpy.data.objects.get(bounds_name).scale
15+
bl = bpy.data.objects.get(bounds_name).location
16+
s = s.optimized()
17+
s = s.get_mesh(xyz_min=[-b[0]+bl[0],-b[1]+bl[1],-b[2]+bl[2]],
18+
xyz_max=[b[0]+bl[0],b[1]+bl[1],b[2]+bl[2]],
19+
resolution=res)
20+
return s
21+
22+
def shape_on_curve(s, curve_mesh_name, blend=0.5, resize=1):
23+
c = bpy.data.objects.get(curve_mesh_name)
24+
depsgraph = bpy.context.evaluated_depsgraph_get()
25+
c = c.evaluated_get(depsgraph)
26+
attr = c.data.attributes
27+
cs = emptiness()
28+
for index in range(len(c.data.vertices)):
29+
size = attr['size'].data[index].value * resize
30+
position = attr['position'].data[index].vector
31+
rotation = attr['rotation'].data[index].vector
32+
cs_tmp = s.move(position)
33+
cs_tmp = cs_tmp.rotate_x(rotation[0], position)
34+
cs_tmp = cs_tmp.rotate_y(-rotation[1], position)
35+
cs_tmp = cs_tmp.rotate_z(rotation[2], position)
36+
cs_tmp = cs_tmp.scale_xyz([size,size,size], position)
37+
cs = blend(cs, cs_tmp, blend)
38+
return cs

0 commit comments

Comments
 (0)