Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClemens Barth <barth@root-1.de>2013-03-22 21:11:59 +0400
committerClemens Barth <barth@root-1.de>2013-03-22 21:11:59 +0400
commite2b78f3c87e18c3ce4609672e950b1dd54ed5f62 (patch)
tree47f502899c309939bec6f3889615b5fbbaa628fc /io_mesh_pdb
parent9babded72771d04e1a6b82dd30c7182608396578 (diff)
Code cleanup: the code in the main function for drawing the atoms (balls) has
been removed and put into a separate function. Blendphys.
Diffstat (limited to 'io_mesh_pdb')
-rw-r--r--io_mesh_pdb/import_pdb.py132
1 files changed, 73 insertions, 59 deletions
diff --git a/io_mesh_pdb/import_pdb.py b/io_mesh_pdb/import_pdb.py
index 364d9a4d..42efa319 100644
--- a/io_mesh_pdb/import_pdb.py
+++ b/io_mesh_pdb/import_pdb.py
@@ -621,6 +621,74 @@ def camera_light_source(use_camera,
bpy.context.scene.world.light_settings.ao_factor = 0.2
+# Function, which draws the atoms of one type (balls). this is one
+# dupliverts structure then.
+# Return: the dupliverts structure
+def draw_atoms_one_type(draw_all_atoms_type,
+ Ball_type,
+ Ball_radius_factor,
+ object_center_vec):
+
+ # Create first the vertices composed of the coordinates of all
+ # atoms of one type
+ atom_vertices = []
+ for atom in draw_all_atoms_type:
+ # In fact, the object is created in the World's origin.
+ # This is why 'object_center_vec' is substracted. At the end
+ # the whole object is translated back to 'object_center_vec'.
+ atom_vertices.append(atom[2] - object_center_vec)
+
+ # Build the mesh
+ atom_mesh = bpy.data.meshes.new("Mesh_"+atom[0])
+ atom_mesh.from_pydata(atom_vertices, [], [])
+ atom_mesh.update()
+ new_atom_mesh = bpy.data.objects.new(atom[0], atom_mesh)
+ bpy.context.scene.objects.link(new_atom_mesh)
+
+ # Now, build a representative sphere (atom).
+ current_layers = bpy.context.scene.layers
+
+ if atom[0] == "Vacancy":
+ bpy.ops.mesh.primitive_cube_add(
+ view_align=False, enter_editmode=False,
+ location=(0.0, 0.0, 0.0),
+ rotation=(0.0, 0.0, 0.0),
+ layers=current_layers)
+ else:
+ # NURBS balls
+ if Ball_type == "0":
+ bpy.ops.surface.primitive_nurbs_surface_sphere_add(
+ view_align=False, enter_editmode=False,
+ location=(0,0,0), rotation=(0.0, 0.0, 0.0),
+ layers=current_layers)
+ # UV balls
+ elif Ball_type == "1":
+ bpy.ops.mesh.primitive_uv_sphere_add(
+ segments=Ball_azimuth, ring_count=Ball_zenith,
+ size=1, view_align=False, enter_editmode=False,
+ location=(0,0,0), rotation=(0, 0, 0),
+ layers=current_layers)
+ # Meta balls
+ elif Ball_type == "2":
+ bpy.ops.object.metaball_add(type='BALL', view_align=False,
+ enter_editmode=False, location=(0, 0, 0),
+ rotation=(0, 0, 0), layers=current_layers)
+
+ ball = bpy.context.scene.objects.active
+ ball.scale = (atom[3]*Ball_radius_factor,) * 3
+
+ if atom[0] == "Vacancy":
+ ball.name = "Cube_"+atom[0]
+ else:
+ ball.name = "Ball_"+atom[0]
+ ball.active_material = atom[1]
+ ball.parent = new_atom_mesh
+ new_atom_mesh.dupli_type = 'VERTS'
+ # The object is back translated to 'object_center_vec'.
+ new_atom_mesh.location = object_center_vec
+
+ return new_atom_mesh
+
# -----------------------------------------------------------------------------
# The main routine
@@ -813,70 +881,16 @@ def import_pdb(Ball_type,
# ------------------------------------------------------------------------
# DRAWING THE ATOMS
- # This is the number of all atoms which are put into the scene.
bpy.ops.object.select_all(action='DESELECT')
# For each list of atoms of ONE type (e.g. Hydrogen)
for draw_all_atoms_type in draw_all_atoms:
- # Create first the vertices composed of the coordinates of all
- # atoms of one type
- atom_vertices = []
- for atom in draw_all_atoms_type:
- # In fact, the object is created in the World's origin.
- # This is why 'object_center_vec' is substracted. At the end
- # the whole object is translated back to 'object_center_vec'.
- atom_vertices.append(atom[2] - object_center_vec)
-
- # Build the mesh
- atom_mesh = bpy.data.meshes.new("Mesh_"+atom[0])
- atom_mesh.from_pydata(atom_vertices, [], [])
- atom_mesh.update()
- new_atom_mesh = bpy.data.objects.new(atom[0], atom_mesh)
- bpy.context.scene.objects.link(new_atom_mesh)
-
- # Now, build a representative sphere (atom)
- current_layers=bpy.context.scene.layers
-
- if atom[0] == "Vacancy":
- bpy.ops.mesh.primitive_cube_add(
- view_align=False, enter_editmode=False,
- location=(0.0, 0.0, 0.0),
- rotation=(0.0, 0.0, 0.0),
- layers=current_layers)
- else:
- # NURBS balls
- if Ball_type == "0":
- bpy.ops.surface.primitive_nurbs_surface_sphere_add(
- view_align=False, enter_editmode=False,
- location=(0,0,0), rotation=(0.0, 0.0, 0.0),
- layers=current_layers)
- # UV balls
- elif Ball_type == "1":
- bpy.ops.mesh.primitive_uv_sphere_add(
- segments=Ball_azimuth, ring_count=Ball_zenith,
- size=1, view_align=False, enter_editmode=False,
- location=(0,0,0), rotation=(0, 0, 0),
- layers=current_layers)
- # Meta balls
- elif Ball_type == "2":
- bpy.ops.object.metaball_add(type='BALL', view_align=False,
- enter_editmode=False, location=(0, 0, 0),
- rotation=(0, 0, 0), layers=current_layers)
-
- ball = bpy.context.scene.objects.active
- ball.scale = (atom[3]*Ball_radius_factor,) * 3
-
- if atom[0] == "Vacancy":
- ball.name = "Cube_"+atom[0]
- else:
- ball.name = "Ball_"+atom[0]
- ball.active_material = atom[1]
- ball.parent = new_atom_mesh
- new_atom_mesh.dupli_type = 'VERTS'
- # The object is back translated to 'object_center_vec'.
- new_atom_mesh.location = object_center_vec
- atom_object_list.append(new_atom_mesh)
+ atom_mesh = draw_atoms_one_type(draw_all_atoms_type,
+ Ball_type,
+ Ball_radius_factor,
+ object_center_vec)
+ atom_object_list.append(atom_mesh)
# ------------------------------------------------------------------------
# DRAWING THE STICKS: skin and subdivision modifier