-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(ns torus-pattern | ||
"Creates a torus pattern with random colored materials." | ||
(:import bpy | ||
math)) | ||
|
||
(def object (-> bpy/ops .-object)) | ||
(def materials (-> bpy/data .-materials)) | ||
(def mesh (-> bpy/ops .-mesh)) | ||
|
||
|
||
(defn clear-mesh-objects [] | ||
(.select-all object ** :action "DESELECT") | ||
(.select-by-type object ** :type "MESH") | ||
(.delete object)) | ||
|
||
(clear-mesh-objects) | ||
|
||
(defn create-random-material [] | ||
(let [mat (.new materials ** :name "RandomMaterial") | ||
_ (set! (.-use-nodes mat) true) | ||
bsdf (aget (-> mat .-node-tree .-nodes) "Principled BSDF")] | ||
|
||
(set! (-> bsdf .-inputs (aget "Base Color") .-default-value) | ||
[(rand) (rand) (rand) 1]) | ||
mat)) | ||
|
||
(defn create-torus [radius tube-radius location segments] | ||
(let [_ (.primitive-torus-add mesh ** | ||
:major-radius radius | ||
:minor-radius tube-radius | ||
:location location | ||
:major-segments segments | ||
:minor-segments segments) | ||
obj (-> bpy/context .-object) | ||
material (create-random-material)] | ||
(-> obj .-data .-materials (.append material)))) | ||
|
||
#_(create-torus 5, 5, [0 0 0] 48) | ||
|
||
(defn create-pattern [{:keys [layers-num radius tube-radius] | ||
:or {layers-num 2 | ||
radius 2 | ||
tube-radius 0.2}}] | ||
(let [angle-step (/ math/pi 4)] | ||
(dotimes [i layers-num] | ||
(let [layer-radius (* radius (inc i)) | ||
objects-num (* 12 (inc i))] | ||
(dotimes [j objects-num] | ||
(let [angle (* j angle-step) | ||
x (* layer-radius (math/cos angle)) | ||
y (* layer-radius (math/sin angle)) | ||
z (* i 0.5)] | ||
(create-torus (/ radius 2) tube-radius [x y z] 48))))))) | ||
|
||
(create-pattern {:layers-num 5}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters