home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / scripts / create_bicubic_patch.py < prev    next >
Text File  |  2008-07-21  |  2KB  |  56 lines

  1. #python
  2.  
  3. import k3d
  4.  
  5. doc = Document
  6. doc.start_change_set()
  7. try:
  8.     frozen_mesh = doc.new_node("FrozenMesh")
  9.     frozen_mesh.name = "Bicubic Patch"
  10.  
  11.     mesh = k3d.dynamic_cast(frozen_mesh, "imesh_storage").reset_mesh()
  12.  
  13.     points = mesh.create_points()
  14.     point_selection = mesh.create_point_selection()
  15.     bicubic_patches = mesh.create_bicubic_patches()
  16.     patch_selection = bicubic_patches.create_patch_selection()
  17.     patch_materials = bicubic_patches.create_patch_materials()
  18.     patch_points = bicubic_patches.create_patch_points()
  19.     Cs = bicubic_patches.writable_varying_data().create_array("Cs", "k3d::color")
  20.  
  21.     positions = [
  22.         (-5, -5, 0), (-2, -5, 2), (2, -5, -2), (5, -5, 0),
  23.         (-5, -2, 2), (-2, -2, 5), (2, -2, -5), (5, -2, -2),
  24.         (-5, 2, 2), (-2, 2, 5), (2, 2, -5), (5, 2, -2),
  25.         (-5, 5, 0), (-2, 5, 2), (2, 5, -2), (5, 5, 0)
  26.         ]
  27.  
  28.     for position in positions:
  29.         points.append(k3d.point3(position[0], position[2], -position[1]))
  30.         point_selection.append(0)
  31.  
  32.     patch_selection.append(0)
  33.     patch_materials.append(None)
  34.  
  35.     for i in range(16):
  36.         patch_points.append(i)
  37.  
  38.     Cs.append(k3d.color(1, 0, 0))
  39.     Cs.append(k3d.color(0, 1, 0))
  40.     Cs.append(k3d.color(0, 0, 1))
  41.     Cs.append(k3d.color(1, 1, 1))
  42.  
  43.     mesh_instance = doc.new_node("MeshInstance")
  44.     mesh_instance.name = "Bicubic Patch Instance"
  45.     mesh_instance.gl_painter = doc.get_node("GL Default Painter")
  46.     mesh_instance.ri_painter = doc.get_node("RenderMan Default Painter")
  47.  
  48.     doc.set_dependency(mesh_instance.get_property("input_mesh"), frozen_mesh.get_property("output_mesh"))
  49.  
  50.     doc.finish_change_set("Create Bicubic Patch")
  51.  
  52. except:
  53.     doc.cancel_change_set()
  54.     raise
  55.  
  56.