[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3471] contrib/py/scripts/addons/ io_mesh_xyz:

Clemens Barth barth at root-1.de
Thu Jun 7 20:24:22 CEST 2012


Revision: 3471
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3471
Author:   blendphys
Date:     2012-06-07 18:24:21 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------

New option: The structure (atoms, molecule, cluster, surface, etc.) is put 
into the center of the world 3D scene - (!) for all frames in the xyz file.

Blendphys.

Modified Paths:
--------------
    contrib/py/scripts/addons/io_mesh_xyz/__init__.py
    contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py

Modified: contrib/py/scripts/addons/io_mesh_xyz/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/__init__.py	2012-06-07 07:05:12 UTC (rev 3470)
+++ contrib/py/scripts/addons/io_mesh_xyz/__init__.py	2012-06-07 18:24:21 UTC (rev 3471)
@@ -25,7 +25,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2011-12-18
-#  Last modified                 : 2012-03-22
+#  Last modified                 : 2012-06-07
 #
 #  Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon,
 #  dairin0d, PKHG, Valter, etc
@@ -210,9 +210,11 @@
         name = "Distances", default=1.0, min=0.0,
         description = "Scale factor for all distances")
     use_center = BoolProperty(
-        name = "Object to origin", default=False,
-        description = "Shall the object first put into the global origin "
-        "before applying the offsets on the left?")
+        name = "Object to origin (first frames)", default=False,
+        description = "Put the object into the global origin, the first frame only")           
+    use_center_all = BoolProperty(
+        name = "Object to origin (all frames)", default=True,
+        description = "Put the object into the global origin, all frames") 
     atomradius = EnumProperty(
         name="Type of radius",
         description="Choose type of atom radius",
@@ -736,8 +738,11 @@
                ('2', "van der Waals", "Use van der Waals radius")),
                default='0',)            
     use_center = BoolProperty(
-        name = "Object to origin", default=True,
-        description = "Put the object into the global origin")           
+        name = "Object to origin (first frames)", default=False,
+        description = "Put the object into the global origin, the first frame only")           
+    use_center_all = BoolProperty(
+        name = "Object to origin (all frames)", default=True,
+        description = "Put the object into the global origin, all frames") 
     datafile = StringProperty(
         name = "", description="Path to your custom data file",
         maxlen = 256, default = "", subtype='FILE_PATH')    
@@ -762,6 +767,8 @@
         row = layout.row()
         row.prop(self, "use_center")
         row = layout.row()
+        row.prop(self, "use_center_all")
+        row = layout.row()
         row.prop(self, "atomradius")
         row = layout.row()
         row.prop(bpy.context.scene, "use_panel")
@@ -786,6 +793,7 @@
                       self.atomradius,
                       self.scale_distances,
                       self.use_center,
+                      self.use_center_all,
                       self.use_camera,
                       self.use_lamp,
                       self.datafile)
@@ -799,6 +807,7 @@
         scn.atomradius = self.atomradius
         scn.scale_distances = self.scale_distances
         scn.use_center = self.use_center
+        scn.use_center_all = self.use_center_all
         scn.use_camera = self.use_camera
         scn.use_lamp = self.use_lamp
         scn.datafile = self.datafile              

Modified: contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-06-07 07:05:12 UTC (rev 3470)
+++ contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-06-07 18:24:21 UTC (rev 3471)
@@ -539,6 +539,7 @@
                       radiustype,
                       Ball_distance_factor,
                       put_to_center, 
+                      put_to_center_all,
                       use_camera,
                       use_lamp,
                       path_datafile):
@@ -597,11 +598,12 @@
     # TRANSLATION OF THE STRUCTURE TO THE ORIGIN
 
     # It may happen that the structure in a XYZ file already has an offset
-    # If chosen, the structure is first put into the center of the scene
-    # (the offset is substracted).
 
-    if put_to_center == True:
 
+    # If chosen, the structure is put into the center of the scene
+    # (only the first frame).
+    if put_to_center == True and put_to_center_all == False:
+
         sum_vec = Vector((0.0,0.0,0.0))
 
         # Sum of all atom coordinates
@@ -615,7 +617,29 @@
         for atoms_of_one_type in first_frame:
             for atom in atoms_of_one_type:
                 atom.location -= sum_vec
-    
+
+    # If chosen, the structure is put into the center of the scene
+    # (all frames).
+    if put_to_center_all == True:
+
+        # For all frames
+        for frame in ALL_FRAMES: 
+
+            sum_vec = Vector((0.0,0.0,0.0))
+
+            # Sum of all atom coordinates
+            for atoms_of_one_type in frame:
+                sum_vec = sum([atom.location for atom in atoms_of_one_type], sum_vec)
+
+            # Then the average is taken
+            sum_vec = sum_vec / Number_of_total_atoms
+
+            # After, for each atom the center of gravity is substracted
+            for atoms_of_one_type in frame:
+                for atom in atoms_of_one_type:
+                    atom.location -= sum_vec
+
+   
     # ------------------------------------------------------------------------
     # SCALING
 



More information about the Bf-extensions-cvs mailing list