-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport-hulls.lisp
82 lines (77 loc) · 4.92 KB
/
export-hulls.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(in-package #:org.shirakumo.fraf.convex-covering)
(defun export-hulls (hulls file &key (colors (make-color-generator))
alpha
(highlight NIL))
(org.shirakumo.fraf.wavefront:serialize
(append (loop for hull across hulls
for i from 0
for color = (if colors
(funcall colors i)
(color<-faces (etypecase hull
(hull (hull-global-faces hull))
(convex-hull (faces hull)))))
for name = (format NIL "patch~a" i)
for mtl = (apply #'make-instance 'org.shirakumo.fraf.wavefront:material
:name name
:diffuse-factor color
(when (and alpha (not (= alpha 1)))
(list :transmission-factor (- 1 alpha))))
for mesh = (make-instance 'org.shirakumo.fraf.wavefront:mesh
:name name
:vertex-data (etypecase hull
(hull (hull-vertices hull))
(convex-hull (vertices hull)))
:index-data (etypecase hull
(hull (hull-facets hull))
(convex-hull (faces hull)))
:attributes '(:position)
:material mtl)
collect mesh)
(when highlight
(let ((bad (make-instance 'org.shirakumo.fraf.wavefront:material
:name "bad"
:diffuse-factor #(0.7 0.2 0.2)))
(good (make-instance 'org.shirakumo.fraf.wavefront:material
:name "good"
:diffuse-factor #(0.2 0.7 0.2)))
(boundary (make-instance 'org.shirakumo.fraf.wavefront:material
:name "boundary"
:diffuse-factor #(0.7 0.7 0.2)))
;;
(patch-edge (make-instance 'org.shirakumo.fraf.wavefront:material
:name "patch-edge"
:diffuse-factor #(0.7 0.7 0.7)))
(facet (make-instance 'org.shirakumo.fraf.wavefront:material
:name "facet"
:diffuse-factor #(0.2 0.2 0.2)))
(facet-normal (make-instance 'org.shirakumo.fraf.wavefront:material
:name "facet-normal"
:diffuse-factor #(0.2 0.2 0.7)))
;;
(face-normal (make-instance 'org.shirakumo.fraf.wavefront:material
:name "face-normal"
:diffuse-factor #(0.2 0.7 0.7)))
(face-edge (make-instance 'org.shirakumo.fraf.wavefront:material
:name "face-edge"
:diffuse-factor #(0.7 0.7 1.0)))
(annotation-count 0))
(loop with hull = (patch-hull highlight)
for (vertex . kind) in (remove :face-centroid (hull-annotations hull) :key #'cdr)
for (color offset sample-count)
= (multiple-value-list
(ecase kind
(:bad (values bad .1 16))
(:good (values good .1 16))
(:boundary-edge (values boundary .01 16))
(:patch-edge (values patch-edge .01 16))
(:facet-edge (values facet .01 16))
(:facet-normal (values facet-normal .005 16))
(:facet-centroid (values facet-normal .05 16))
(:face-normal (values face-normal .008 16))
(:face-centroid (values face-normal .05 16))
(:bad-normal (values bad .1 16))
(:face-edge (values face-edge .005 16))))
:for name = (format NIL "annotation~A" (incf annotation-count))
:collect (debug-cube vertex name color :offset offset)))))
file :if-exists :supersede)
hulls)