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_point_group.py < prev    next >
Text File  |  2008-07-27  |  2KB  |  53 lines

  1. #python
  2.  
  3. import k3d
  4. from random import uniform
  5.  
  6. doc = Document
  7. doc.start_change_set()
  8. try:
  9.     frozen_mesh = doc.new_node("FrozenMesh")
  10.     frozen_mesh.name = "Point Group"
  11.  
  12.     mesh = k3d.dynamic_cast(frozen_mesh, "imesh_storage").reset_mesh()
  13.  
  14.     count = 100
  15.     size = 10
  16.  
  17.     points = mesh.create_points()
  18.     Cs = mesh.writable_vertex_data().create_array("Cs", "k3d::color")
  19.     point_selection = mesh.create_point_selection()
  20.     point_groups = mesh.create_point_groups()
  21.     first_points = point_groups.create_first_points()
  22.     point_counts = point_groups.create_point_counts()
  23.     materials = point_groups.create_materials()
  24.     constantwidth = point_groups.writable_constant_data().create_array("constantwidth", "k3d::double_t")
  25.     group_points = point_groups.create_points()
  26.  
  27.     for i in range(count):
  28.         points.append(k3d.point3(uniform(-size, size), uniform(-size, size), uniform(-size, size)))
  29.         point_selection.append(0.0)
  30.         Cs.append(k3d.color(uniform(0, 1), uniform(0, 1), uniform(0, 1)))
  31.  
  32.     first_points.append(len(group_points))
  33.     point_counts.append(len(points))
  34.     materials.append(None)
  35.     constantwidth.append(0.2)
  36.  
  37.     for i in range(len(points)):
  38.         group_points.append(i)
  39.  
  40.     
  41.     mesh_instance = doc.new_node("MeshInstance")
  42.     mesh_instance.name = "Point Group Instance"
  43.     mesh_instance.gl_painter = doc.get_node("GL Default Painter")
  44.     mesh_instance.ri_painter = doc.get_node("RenderMan Default Painter")
  45.     doc.set_dependency(mesh_instance.get_property("input_mesh"), frozen_mesh.get_property("output_mesh"))
  46.  
  47.     doc.finish_change_set("Create Point Group")
  48.  
  49. except:
  50.     doc.cancel_change_set()
  51.     raise
  52.  
  53.