Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. # Operator to Start the simulation
  2. class createSphereOpe(bpy.types.Operator):
  3. """Generate spheres"""
  4. bl_idname = "object.simple_operator"
  5. bl_label = "Generate"
  6.  
  7. @classmethod
  8. def poll(cls, context) :
  9. return context.object.mode == 'OBJECT'
  10.  
  11. def execute(self, context):
  12. # Variable to calculate the time
  13. simTime = time()
  14.  
  15. # Get the needed variables
  16. simPara = bpy.context.scene.simulationPara
  17. objs = bpy.context.scene.objects
  18.  
  19. if not simPara.autoSeed :
  20. seed(simPara.seed)
  21.  
  22.  
  23. # # Delete any exist results
  24. bpy.ops.object.select_all(action='DESELECT')
  25.  
  26. if objs.get("DistResult") :
  27. objs["DistResult"].select = True
  28. if objs.get("DistDomain") :
  29. objs["DistDomain"].select = True
  30.  
  31. bpy.ops.object.delete()
  32.  
  33. # Create the domain
  34. if simPara.typeOfDomain == "CUBE" :
  35. # Cube :
  36. domain = Cube(simPara.cubeDomainSide)
  37.  
  38. elif simPara.typeOfDomain == 'SHPERE' :
  39. # Sphere :
  40. domain = Sphere(simPara.sphereDomainRadius)
  41.  
  42. elif simPara.typeOfDomain == 'CYLINDER' :
  43. # Cylinder :
  44. domain = Cylinder(simPara.cylinderDomainRadius, simPara.cylinderDomainHeight)
  45.  
  46. # Draw the domain
  47. drawMeshes(domain, (Vector((0, 0, 0)),))
  48.  
  49. bpy.context.object.name = "DistDomain"
  50. bpy.context.object.draw_type = 'WIRE'
  51.  
  52. # Create an object to hold the meshes
  53. bpy.ops.object.add(type="MESH", enter_editmode=True)
  54. bpy.context.object.name = 'DistResult'
  55.  
  56. if simPara.typeOfMesh == 'SHPERE' :
  57. # Sphere :
  58. mesh = Sphere(simPara.sizeOfSphere)
  59.  
  60. elif simPara.typeOfMesh == ' EllIPSOID ' :
  61. # Ellipsoid :
  62. #mesh = Sphere(simPara.sizeOfSphere)
  63. mesh = Ellipsoid(simPara.size_aOfEllipsoid, simPara.size_bOfEllipsoid, simPara.size_cOfEllipsoid)
  64.  
  65.  
  66. if simPara.typeOfSimulation == "GRID" :
  67. simulation = gridDistribute(mesh, domain)
  68. elif simPara.typeOfSimulation == "RANDOM" :
  69. simulation = randomDistribute(mesh, simPara.number, simPara.maxSearchTry, domain, simPara.collDomain, simPara.collMesh)
  70. elif simPara.typeOfSimulation == "HEX" :
  71. simulation = hexDistribute(mesh, domain, simPara.collDomain)
  72. locations = simulation.search()
  73. simulation.drawMeshes(locations, simPara.resolutionSphere)
  74. # Return to object mode
  75. bpy.ops.object.editmode_toggle()
  76.  
  77. # Smooth the faces
  78. bpy.ops.object.shade_smooth()
  79.  
  80. # Show how many spheres created
  81. self.report({'INFO'}, str(len(locations)) + " " + simPara.typeOfMesh + " created in " + str(round(time()-simTime,4))+ " Second")
  82.  
  83. return {'FINISHED'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement