home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / scripts / scripted_plugins / boolean_sculpt_tool.py < prev    next >
Encoding:
Python Source  |  2008-04-22  |  2.3 KB  |  52 lines

  1. #python
  2.  
  3. # k3d:plugin-class="document"
  4. # k3d:plugin-type="NullOutputScript"
  5. # k3d:plugin-name="BooleanSculptor"
  6. # k3d:plugin-description="Sculpt a mesh with a tool, using boolean operations"
  7.  
  8. import k3d
  9.  
  10. def reset_mesh(FrozenMesh):
  11.   storage_node = k3d.dynamic_cast(FrozenMesh, "imesh_storage")
  12.   storage_node.clear_mesh()
  13.   pipeline_trigger = FrozenMesh.output_mesh # make sure the frozen mesh is really reset
  14.  
  15. doc = Node.document()
  16.  
  17. if not Node.has_property("sculpted_mesh"):
  18.   Node.create_property("k3d::mesh*", "sculpted_mesh", "Sculpted Mesh", "The mesh that will be sculpted")
  19. if not Node.has_property("sculpt_tool"):
  20.   Node.create_property("k3d::mesh*", "sculpt_tool", "Sculpt Tool", "The mesh that will be used as tool")
  21.  
  22. modifier = doc.get_node("CGALBoolean")
  23. frozen_mesh_1 = doc.get_node("FrozenMesh")
  24. frozen_mesh_2 = doc.get_node("FrozenMesh 2")
  25. if not doc.has_node("CGALBoolean"): 
  26.   if k3d.is_solid(Node.sculpted_mesh) and k3d.is_solid(Node.sculpt_tool):
  27.     modifier = doc.new_node("CGALBoolean")
  28.     modifier.create_property("k3d::mesh*", "input_1", "Input 1", "")
  29.     modifier.create_property("k3d::mesh*", "input_2", "Input 2", "")
  30.     modifier.type = "difference"
  31.     
  32.     frozen_mesh_1 = doc.new_node("FrozenMesh")
  33.     frozen_mesh_2 = doc.new_node("FrozenMesh")
  34.     
  35.     doc.set_dependency(frozen_mesh_2.get_property("input_mesh"), modifier.get_property("output_mesh"))
  36.     doc.set_dependency(modifier.get_property("input_1"), frozen_mesh_1.get_property("output_mesh"))
  37.     
  38.     doc.set_dependency(modifier.get_property("input_2"), Node.get_property("sculpt_tool"))
  39.     instance = Document.new_node("MeshInstance")
  40.     doc.set_dependency(instance.get_property("input_mesh"), modifier.get_property("output_mesh"))
  41.     instance.gl_painter = doc.get_node("GL Default Painter")
  42.     
  43.     doc.set_dependency(frozen_mesh_1.get_property("input_mesh"), Node.get_property("sculpted_mesh"))
  44.     reset_mesh(frozen_mesh_1)
  45.     doc.set_dependency(frozen_mesh_1.get_property("input_mesh"), frozen_mesh_2.get_property("output_mesh"))
  46.   
  47. doc.set_dependency(modifier.get_property("input_2"), Node.get_property("sculpt_tool"))
  48.  
  49. if not k3d.is_uninitialized(modifier.output_mesh):
  50.   reset_mesh(frozen_mesh_2)
  51.   if (k3d.validate(frozen_mesh_2.output_mesh) and not k3d.is_uninitialized(frozen_mesh_2.output_mesh) and k3d.is_solid(frozen_mesh_2.output_mesh)):
  52.     reset_mesh(frozen_mesh_1)