Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Operator to Start the simulation
- class createSphereOpe(bpy.types.Operator):
- """Generate spheres"""
- bl_idname = "object.simple_operator"
- bl_label = "Generate"
- @classmethod
- def poll(cls, context) :
- return context.object.mode == 'OBJECT'
- def execute(self, context):
- # Variable to calculate the time
- simTime = time()
- # Get the needed variables
- simPara = bpy.context.scene.simulationPara
- objs = bpy.context.scene.objects
- if not simPara.autoSeed :
- seed(simPara.seed)
- # # Delete any exist results
- bpy.ops.object.select_all(action='DESELECT')
- if objs.get("DistResult") :
- objs["DistResult"].select = True
- if objs.get("DistDomain") :
- objs["DistDomain"].select = True
- bpy.ops.object.delete()
- # Create the domain
- if simPara.typeOfDomain == "CUBE" :
- # Cube :
- domain = Cube(simPara.cubeDomainSide)
- elif simPara.typeOfDomain == 'SHPERE' :
- # Sphere :
- domain = Sphere(simPara.sphereDomainRadius)
- elif simPara.typeOfDomain == 'CYLINDER' :
- # Cylinder :
- domain = Cylinder(simPara.cylinderDomainRadius, simPara.cylinderDomainHeight)
- # Draw the domain
- drawMeshes(domain, (Vector((0, 0, 0)),))
- bpy.context.object.name = "DistDomain"
- bpy.context.object.draw_type = 'WIRE'
- # Create an object to hold the meshes
- bpy.ops.object.add(type="MESH", enter_editmode=True)
- bpy.context.object.name = 'DistResult'
- if simPara.typeOfMesh == 'SHPERE' :
- # Sphere :
- mesh = Sphere(simPara.sizeOfSphere)
- elif simPara.typeOfMesh == ' EllIPSOID ' :
- # Ellipsoid :
- #mesh = Sphere(simPara.sizeOfSphere)
- mesh = Ellipsoid(simPara.size_aOfEllipsoid, simPara.size_bOfEllipsoid, simPara.size_cOfEllipsoid)
- if simPara.typeOfSimulation == "GRID" :
- simulation = gridDistribute(mesh, domain)
- elif simPara.typeOfSimulation == "RANDOM" :
- simulation = randomDistribute(mesh, simPara.number, simPara.maxSearchTry, domain, simPara.collDomain, simPara.collMesh)
- elif simPara.typeOfSimulation == "HEX" :
- simulation = hexDistribute(mesh, domain, simPara.collDomain)
- locations = simulation.search()
- simulation.drawMeshes(locations, simPara.resolutionSphere)
- # Return to object mode
- bpy.ops.object.editmode_toggle()
- # Smooth the faces
- bpy.ops.object.shade_smooth()
- # Show how many spheres created
- self.report({'INFO'}, str(len(locations)) + " " + simPara.typeOfMesh + " created in " + str(round(time()-simTime,4))+ " Second")
- return {'FINISHED'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement