Guest User

IcoSphere

a guest
Nov 17th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.33 KB | None | 0 0
  1. Paste both, and lib_icosphere is the one you want. It only takes one arg, the amount of subdivisions you want (how many times you cut each triangle in half). You have to put a number in, at the very least 0. Has to be a whole number. Gives you a list of points centered around 0,0,0, so you need to move all the points to wherever you want them. Something like .parse_tag[<[loc_where_i_want_them].add[<[parse_value]>]>]
  2.  
  3. Also, it's small, so you'll also probably wanna multiply each point's length so that the sphere is bigger.
  4.  
  5. lib_icosphere:
  6.     type: procedure
  7.     debug: false
  8.     definitions: subdivisions
  9.     script:
  10.        #Save a reference to points so we can see if we've
  11.         #already included it or not
  12.         - define lookup <map>
  13.        - define phi <element[1].add[<element[5].sqrt>].div[2]>
  14.        - define verts:->:<location[-1,<[phi]>,0].normalize>
  15.        - define verts:->:<location[1,<[phi]>,0].normalize>
  16.        - define verts:->:<location[-1,-<[phi]>,0].normalize>
  17.        - define verts:->:<location[1,-<[phi]>,0].normalize>
  18.        - define verts:->:<location[0,-1,<[phi]>].normalize>
  19.        - define verts:->:<location[0,1,<[phi]>].normalize>
  20.        - define verts:->:<location[0,-1,-<[phi]>].normalize>
  21.        - define verts:->:<location[0,1,-<[phi]>].normalize>
  22.        - define verts:->:<location[<[phi]>,0,-1].normalize>
  23.        - define verts:->:<location[<[phi]>,0,1].normalize>
  24.        - define verts:->:<location[-<[phi]>,0,-1].normalize>
  25.        - define verts:->:<location[-<[phi]>,0,1].normalize>
  26.        - define faces:->:<list[1|12|6]>
  27.        - define faces:->:<list[1|6|2]>
  28.        - define faces:->:<list[1|2|8]>
  29.        - define faces:->:<list[1|8|11]>
  30.        - define faces:->:<list[1|11|12]>
  31.        - define faces:->:<list[2|6|10]>
  32.        - define faces:->:<list[6|12|5]>
  33.        - define faces:->:<list[12|11|3]>
  34.        - define faces:->:<list[11|8|7]>
  35.        - define faces:->:<list[8|2|9]>
  36.        - define faces:->:<list[4|10|5]>
  37.        - define faces:->:<list[4|5|3]>
  38.        - define faces:->:<list[5|3|7]>
  39.        - define faces:->:<list[4|7|9]>
  40.        - define faces:->:<list[4|9|10]>
  41.        - define faces:->:<list[5|10|6]>
  42.        - define faces:->:<list[3|5|12]>
  43.        - define faces:->:<list[7|3|11]>
  44.        - define faces:->:<list[9|7|8]>
  45.        - define faces:->:<list[10|9|2]>
  46.         - repeat <[subdivisions]>:
  47.            - define face_subdivisions <list>
  48.             - foreach <[faces]> as:triangle:
  49.                 - definemap args:
  50.                     index1: <[triangle].get[1]>
  51.                     index2: <[triangle].get[2]>
  52.                     lookup: <[lookup]>
  53.                     vertices: <[verts]>
  54.                - define res <[args].proc[lib_core_subdivide_triangle]>
  55.                 - if <[res].object_type.equals[Element]>:
  56.                    - debug log <[args]>
  57.                    - debug log <[res]>
  58.                    - stop
  59.                 - define verts  <[res.vertices]>
  60.                - define lookup <[res.lookup]>
  61.                - define v1     <[res.index]>
  62.                 - definemap args:
  63.                     index1: <[triangle].get[2]>
  64.                     index2: <[triangle].get[3]>
  65.                     lookup: <[lookup]>
  66.                     vertices: <[verts]>
  67.                - define res <[args].proc[lib_core_subdivide_triangle]>
  68.                - define verts  <[res.vertices]>
  69.                - define lookup <[res.lookup]>
  70.                - define v2     <[res.index]>
  71.                 - definemap args:
  72.                     index1: <[triangle].get[3]>
  73.                     index2: <[triangle].get[1]>
  74.                     lookup: <[lookup]>
  75.                     vertices: <[verts]>
  76.                - define res <[args].proc[lib_core_subdivide_triangle]>
  77.                - define verts  <[res.vertices]>
  78.                - define lookup <[res.lookup]>
  79.                - define v3     <[res.index]>
  80.                - define face_subdivisions:->:<location[<[triangle].get[1]>,<[v1]>,<[v3]>]>
  81.                - define face_subdivisions:->:<location[<[triangle].get[2]>,<[v2]>,<[v1]>]>
  82.                - define face_subdivisions:->:<location[<[triangle].get[3]>,<[v3]>,<[v2]>]>
  83.                - define face_subdivisions:->:<location[<[v1]>,<[v2]>,<[v3]>]>
  84.            - define faces:->:<[face_subdivisions]>
  85.        - determine <[verts]>
  86. lib_core_subdivide_triangle:
  87.     type: procedure
  88.     debug: false
  89.     definitions: args
  90.     script:
  91.        - define i1 <[args.index1].min[<[args.index2]>]>
  92.        - define i2 <[args.index1].max[<[args.index2]>]>
  93.        - define key <[i1]>_<[i2]>
  94.        - determine <map.with[vertices].as[<[args.vertices]>].with[lookup].as[<[args.lookup]>].with[index].as[<[args.lookup.<[key]>]>]> if:<[args.lookup.<[key]>].exists>
  95.        - define v1 <[args.vertices].get[<[i1]>]>
  96.        - define v2 <[args.vertices].get[<[i2]>]>
  97.        - define x <[v1].x.add[<[v2].x>].mul[0.5]>
  98.        - define y <[v1].y.add[<[v2].y>].mul[0.5]>
  99.        - define z <[v1].z.add[<[v2].z>].mul[0.5]>
  100.        - define middle <[v1].with_x[<[x]>].with_y[<[y]>].with_z[<[z]>]>
  101.        - define args.vertices:->:<[middle].normalize>
  102.        - define args.lookup.<[key]>:<[args.vertices].size>
  103.        - determine <map.with[vertices].as[<[args.vertices]>].with[lookup].as[<[args.lookup]>].with[index].as[<[args.lookup.<[key]>]>]>
Advertisement
Add Comment
Please, Sign In to add comment