[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4410] trunk/py/scripts/addons/ io_mesh_pdb/import_pdb.py: Code cleanup: the code in the main function for drawing the atoms (balls) has
Clemens Barth
barth at root-1.de
Fri Mar 22 18:11:59 CET 2013
Revision: 4410
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4410
Author: blendphys
Date: 2013-03-22 17:11:59 +0000 (Fri, 22 Mar 2013)
Log Message:
-----------
Code cleanup: the code in the main function for drawing the atoms (balls) has
been removed and put into a separate function.
Blendphys.
Modified Paths:
--------------
trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
Modified: trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2013-03-22 17:11:09 UTC (rev 4409)
+++ trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2013-03-22 17:11:59 UTC (rev 4410)
@@ -621,6 +621,74 @@
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,71 +881,17 @@
# ------------------------------------------------------------------------
# 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)
+ atom_mesh = draw_atoms_one_type(draw_all_atoms_type,
+ Ball_type,
+ Ball_radius_factor,
+ object_center_vec)
+ atom_object_list.append(atom_mesh)
- # 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)
-
# ------------------------------------------------------------------------
# DRAWING THE STICKS: skin and subdivision modifier
More information about the Bf-extensions-cvs
mailing list