I was able to create the mesh for this game object (kinda) but when it renders to the scene it looks terrible. I think my triangles vector is off. Why is it hot pink?
(defn dodeca-verts
[n]
(let [golden-ratio (/ (+ 1 (Mathf/Sqrt 5)) 2)
phi (* golden-ratio n)
ihp (/ n golden-ratio)
vertices [[(+ phi) 0 (+ ihp)]
[(+ n) (+ n) (+ n)]
[0 (+ ihp) (+ phi)]
[0 (- ihp) (+ phi)]
[(- n) (- n) (+ n)]
[(- phi) 0 (+ ihp)]
[(- n) (+ n) (+ n)]
[(- ihp) (+ phi) 0]
[(+ ihp) (+ phi) 0]
[(+ n) (+ n) (- n)]
[(+ phi) 0 (- ihp)]
[(+ n) (- n) (- n)]
[0 (- ihp) (- phi)]
[0 (+ ihp) (- phi)]
[(- n) (+ n) (- n)]
[(- phi) 0 (- ihp)]
[(- n) (- n) (- n)]
[(- ihp) (- phi) 0]
[(+ ihp) (- phi) 0]
[(+ n) (- n) (+ n)]]]
(mapv #(mapv (partial * phi) %) vertices)))
(defn dodeca-tris
[]
[0 2 1 0 3 2 0 4 3 0 5 4 0 18 5
0 19 18 19 17 16 18 16 6 18 6 5 6 16 15
6 15 8 6 8 7 8 15 14 8 14 10 8 10 9
14 11 10 14 12 11 14 13 12 14 15 13 13 15 16
13 16 17 13 17 18 13 18 19 13 19 12 0 12 19
0 11 12 0 1 11 1 10 11 1 9 10 1 2 9
2 8 9 2 7 8 2 3 7 3 6 7 3 5 6 3 4 5])
(defn create-dodecahedron-mesh [radius]
(let [mesh (Mesh.)
vertices (->> (dodeca-verts radius)
(mapv (fn [[x y z]] (Vector3. x y z)))
(into-array Vector3))
triangles (into-array Int32 (dodeca-tris))]
(.SetVertices mesh vertices)
(.SetTriangles mesh triangles 0)
(.RecalculateNormals mesh)
(.RecalculateBounds mesh)
mesh))
(defn start []
(let [dodecahedron-mesh (create-dodecahedron-mesh 1)
board (GameObject.)]
(.AddComponent board MeshFilter)
(.AddComponent board MeshRenderer)
(-> board
(.GetComponent MeshFilter)
(.set_mesh dodecahedron-mesh))
(arc/instantiate board)))fixed the triangles vector, but she's still hawt pank
(defn dodeca-tris
[]
[0 1 2 2 3 0 3 19 0 3 18 19 18 3 4
4 17 18 17 16 18 18 16 12 18 12 11 12 10 11
10 12 9 9 12 13 9 13 8 8 13 7 7 13 14
7 14 6 14 5 6 15 5 14 15 14 13 13 12 15
12 16 15 15 16 17 17 4 15 4 5 15 5 4 3
3 2 5 2 6 5 6 2 7 7 2 1 1 8 7
8 1 9 9 1 10 10 1 0 0 11 10 11 0 18
18 0 19])