home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / scripts / MeshSourceScript / polyhedra.py < prev    next >
Encoding:
Text File  |  2008-10-03  |  2.3 KB  |  68 lines

  1. #python
  2.  
  3. import k3d
  4. k3d.check_node_environment(locals(), "MeshSourceScript")
  5.  
  6. # Perform required one-time setup to store geometric points in the mesh ...
  7. points = Output.create_points()
  8. point_selection = Output.create_point_selection()
  9.  
  10. # Perform required one-time setup to store polyhedra in the mesh ...
  11. polyhedra = Output.create_polyhedra()
  12. first_faces = polyhedra.create_first_faces()
  13. face_counts = polyhedra.create_face_counts()
  14. types = polyhedra.create_types()
  15. face_first_loops = polyhedra.create_face_first_loops()
  16. face_loop_counts = polyhedra.create_face_loop_counts()
  17. face_materials = polyhedra.create_face_materials()
  18. face_selection = polyhedra.create_face_selection()
  19. loop_first_edges = polyhedra.create_loop_first_edges()
  20. edge_points = polyhedra.create_edge_points()
  21. clockwise_edges = polyhedra.create_clockwise_edges()
  22. edge_selection = polyhedra.create_edge_selection()
  23.  
  24. # Create an (optional) array to store uniform (per-face) colors ...
  25. Cs = polyhedra.writable_uniform_data().create("Cs", "k3d::color")
  26.  
  27. # Create two polyhedra ...
  28. for i in range(2):
  29.     first_faces.append(len(face_first_loops))
  30.     face_counts.append(2)
  31.     types.append(k3d.polyhedron_type.polygons)
  32.  
  33.     # Create three faces in each polyhedron ...
  34.     for j in range(3):
  35.         # Each face has a single loop (its exterior boundary) ...
  36.         face_first_loops.append(len(loop_first_edges))
  37.         face_loop_counts.append(1)
  38.         face_materials.append(None)
  39.         face_selection.append(0.0)
  40.  
  41.         Cs.append(k3d.color(1, j / 2.0, i / 1.0))
  42.  
  43.         loop_first_edges.append(len(edge_points))
  44.  
  45.         # Each loop has four edges, each of which points to the next edge in clockwise-order ...
  46.         clockwise_edges.append(len(edge_points) + 1)
  47.         clockwise_edges.append(len(edge_points) + 2)
  48.         clockwise_edges.append(len(edge_points) + 3)
  49.         clockwise_edges.append(len(edge_points) + 0)
  50.  
  51.         # Each edge refers to its starting-point ...
  52.         edge_points.append(len(points) + 0)
  53.         edge_points.append(len(points) + 1)
  54.         edge_points.append(len(points) + 2)
  55.         edge_points.append(len(points) + 3)
  56.  
  57.         edge_selection.append(0.0)
  58.         edge_selection.append(0.0)
  59.         edge_selection.append(0.0)
  60.         edge_selection.append(0.0)
  61.  
  62.         positions = [(-5, 0, 5), (5, 0, 5), (5, 0, -5), (-5, 0, -5)]
  63.  
  64.         for position in positions:
  65.             points.append(k3d.point3(position[0] + (j * 11.0), position[1] + (i * -11.0), position[2]))
  66.             point_selection.append(0.0)
  67.  
  68.