home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 2 / PCNET_CD_2006_10_2.iso / apps / k3d-all-in-one-setup-0.5.14.0.exe / k3d-setup-0.5.14.0.exe / share / scripts / create_square.py < prev    next >
Encoding:
Python Source  |  2006-01-24  |  1.2 KB  |  48 lines

  1. #python
  2.  
  3. doc = Document
  4. doc.start_change_set()
  5. try:
  6.     material = doc.new_node("RenderManMaterial")
  7.     material.name = "Square Material"
  8.     material.color = (1, 1, 1)
  9.     frozen_mesh = doc.new_node("FrozenMesh")
  10.  
  11.     frozen_mesh.name = "Square"
  12.  
  13.     mesh = frozen_mesh.new_mesh()
  14.  
  15.     positions = ((-5, 0, 5), (5, 0, 5), (5, 0, -5), (-5, 0, -5))
  16.     points = []
  17.     for position in positions:
  18.         points.append(mesh.new_point(position))
  19.  
  20.     polyhedron = mesh.new_polyhedron()
  21.     edges = []
  22.     for point in points:
  23.         edges.append(polyhedron.new_edge(point))
  24.  
  25.     for i in range(len(edges)):
  26.         edges[i].face_clockwise = edges[(i+1)%len(edges)]
  27.  
  28.     face = polyhedron.new_face(edges[0])
  29.     face.material = material
  30.  
  31. #    face.uniform_data.set_color("Cs", (1, 0, 0))
  32.  
  33.     points[0].vertex_data.set_color("Cs", (1, 0, 0))
  34.     points[1].vertex_data.set_color("Cs", (0, 1, 0))
  35.     points[2].vertex_data.set_color("Cs", (0, 0, 1))
  36.     points[3].vertex_data.set_color("Cs", (1, 1, 1))
  37.  
  38.     mesh_instance = doc.new_node("MeshInstance")
  39.     mesh_instance.name = "Square Instance"
  40.     doc.set_dependency(mesh_instance.get_property("input_mesh"), frozen_mesh.get_property("output_mesh"))
  41.  
  42.     doc.finish_change_set("Create Square")
  43.  
  44. except:
  45.     doc.cancel_change_set()
  46.     raise
  47.  
  48.