Skip to content

Commit

Permalink
fixed #20, supply init value for transducer in
Browse files Browse the repository at this point in the history
gmesh/compute-vertex-normals, add single vertex/face-normal accessors
for GMesh & BasicMesh
  • Loading branch information
postspectacular committed May 25, 2015
1 parent 780a6b1 commit 661dccf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions geom-types/src/basicmesh.org
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@
g/PNormalAccess
(face-normals
[_ force?] (if (seq (:fnormals _)) (:fnormals _) (if force? (:fnormals (g/compute-face-normals _)))))
(face-normal
[_ f] ((:fnormals _) f))
(vertex-normals
[_ force?] (if force? (err/unsupported!)))
(vertex-normal
[_ v] (err/unsupported!))
(compute-face-normals
[_]
(loop [fnorms (transient {}), faces (:faces _)]
Expand Down
20 changes: 12 additions & 8 deletions geom-types/src/gmesh.org
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,15 @@ located on the rotation axis.
(if (seq (:fnormals _))
(:fnormals _)
(if force? (:fnormals (g/compute-face-normals _)))))
(face-normal
[_ f] ((:fnormals _) f))
(vertex-normals
[_ force?]
(if (seq (:vnormals _))
(:vnormals _)
(if force? (:vnormals (g/compute-vertex-normals _)))))
(vertex-normal
[_ v] ((:vnormals _) v))
(compute-face-normals
[_]
(loop [norms (transient #{}), fnorms (transient {}), faces (:faces _)]
Expand All @@ -346,23 +350,23 @@ located on the rotation axis.
[norms n] (d/index! norms (apply gu/ortho-normal f))]
(recur norms (assoc! fnorms f n) (next faces)))
(assoc _
:normals (persistent! norms)
:fnormals (persistent! fnorms)))))
:normals (persistent! norms)
:fnormals (persistent! fnorms)))))
(compute-vertex-normals
[_]
(let [{:keys [vertices normals fnormals] :as this} (if (seq (:fnormals _)) _ (g/compute-face-normals _))
ntx (map #(get fnormals %))]
(loop [norms (transient normals), vnorms (transient (hash-map)), verts (keys vertices)]
(if verts
(let [v (first verts)
n (->> (g/vertex-faces this v)
(transduce ntx g/+)
(g/normalize))
[norms n] (d/index! norms n)]
[norms n] (->> (d/value-set :f vertices v)
(transduce ntx g/+ v/V3)
(g/normalize)
(d/index! norms))]
(recur norms (assoc! vnorms v n) (next verts)))
(assoc this
:normals (persistent! norms)
:vnormals (persistent! vnorms))))))
:normals (persistent! norms)
:vnormals (persistent! vnorms))))))
#+END_SRC

*** PGeomContainer
Expand Down

0 comments on commit 661dccf

Please sign in to comment.