Skip to content

Commit

Permalink
Update v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowdaw committed Dec 5, 2024
1 parent 1505cff commit 24d0120
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ This allows users to create constructive solid geometry from within Blender usin
![](images/SD5_Demo.png)

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

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.

The quick way is to now put the following in the script:
```
import SD5.utils as sd5
import sd5
s = sd5.sphere(2)
sd5.name = "SD5_Demo"
Expand All @@ -23,7 +23,7 @@ The better way would be to first add three empties to the scene.
I will call them "C_Sphere", "C_Box" and "Bounds".
Then put the following in the script:
```
import SD5.utils as sd5
import sd5
# Add a new sphere and box
s = sd5.sphere(1)
Expand Down
9 changes: 5 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

@persistent
def sd5_handler(scene, depsgraph):
if bpy.context.mode != "OBJECT":
return


sd5_texts = []
for sd5_text in bpy.data.texts:
if sd5_text.name.startswith("SD5_"):
Expand Down Expand Up @@ -42,7 +40,10 @@ def sd5_handler(scene, depsgraph):

if temp_obj == None:
temp_obj = bpy.data.objects.new(sd5_name, temp_mesh)
bpy.data.collections["Collection"].objects.link(temp_obj)
if not bpy.data.collections.get("SD5"):
sd5_collection = bpy.data.collections.new("SD5")
bpy.data.scenes["Scene"].collection.children.link(sd5_collection)
bpy.data.collections["SD5"].objects.link(temp_obj)

temp_mesh.from_pydata(sd5_mesh[0], [], sd5_mesh[1], shade_flat=False)
temp_obj.data = temp_mesh
Expand Down
38 changes: 38 additions & 0 deletions sd5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import bpy
from libfive.stdlib import *

def set_control(s, control_name):
control = bpy.data.objects.get(control_name)
s = s.move(control.location)
s = s.rotate_x(control.rotation_euler[0], control.location)
s = s.rotate_y(-control.rotation_euler[1], control.location)
s = s.rotate_z(control.rotation_euler[2], control.location)
s = s.scale_xyz(control.scale, control.location)
return s

def mesh_from_bounds(s, res, bounds_name):
b = bpy.data.objects.get(bounds_name).scale
bl = bpy.data.objects.get(bounds_name).location
s = s.optimized()
s = s.get_mesh(xyz_min=[-b[0]+bl[0],-b[1]+bl[1],-b[2]+bl[2]],
xyz_max=[b[0]+bl[0],b[1]+bl[1],b[2]+bl[2]],
resolution=res)
return s

def shape_on_curve(s, curve_mesh_name, blend=0.5, resize=1):
c = bpy.data.objects.get(curve_mesh_name)
depsgraph = bpy.context.evaluated_depsgraph_get()
c = c.evaluated_get(depsgraph)
attr = c.data.attributes
cs = emptiness()
for index in range(len(c.data.vertices)):
size = attr['size'].data[index].value * resize
position = attr['position'].data[index].vector
rotation = attr['rotation'].data[index].vector
cs_tmp = s.move(position)
cs_tmp = cs_tmp.rotate_x(rotation[0], position)
cs_tmp = cs_tmp.rotate_y(-rotation[1], position)
cs_tmp = cs_tmp.rotate_z(rotation[2], position)
cs_tmp = cs_tmp.scale_xyz([size,size,size], position)
cs = blend(cs, cs_tmp, blend)
return cs

0 comments on commit 24d0120

Please sign in to comment.