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_bilinear_patch.py < prev    next >
Text File  |  2008-07-21  |  1KB  |  51 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 = "Bilinear 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.     bilinear_patches = mesh.create_bilinear_patches()
  16.     patch_selection = bilinear_patches.create_patch_selection()
  17.     patch_materials = bilinear_patches.create_patch_materials()
  18.     patch_points = bilinear_patches.create_patch_points()
  19.     Cs = bilinear_patches.writable_varying_data().create_array("Cs", "k3d::color")
  20.  
  21.     positions = [(-5, 0, 5), (5, 0, 5), (0, -5, -5), (0, 5, -5)]
  22.     for position in positions:
  23.         points.append(k3d.point3(position[0], position[1], position[2]))
  24.         point_selection.append(0.0)
  25.  
  26.     patch_selection.append(0)
  27.     patch_materials.append(None)
  28.  
  29.     patch_points.append(0)
  30.     patch_points.append(1)
  31.     patch_points.append(2)
  32.     patch_points.append(3)
  33.  
  34.     Cs.append(k3d.color(1, 0, 0))
  35.     Cs.append(k3d.color(0, 1, 0))
  36.     Cs.append(k3d.color(0, 0, 1))
  37.     Cs.append(k3d.color(1, 1, 1))
  38.  
  39.     mesh_instance = doc.new_node("MeshInstance")
  40.     mesh_instance.name = "Bilinear Patch Instance"
  41.     mesh_instance.gl_painter = doc.get_node("GL Default Painter")
  42.     mesh_instance.ri_painter = doc.get_node("RenderMan Default Painter")
  43.     doc.set_dependency(mesh_instance.get_property("input_mesh"), frozen_mesh.get_property("output_mesh"))
  44.  
  45.     doc.finish_change_set("Create Bilinear Patch")
  46.  
  47. except:
  48.     doc.cancel_change_set()
  49.     raise
  50.  
  51.