[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3948] contrib/py/scripts/addons/ io_mesh_xyz: 1. New: NURBS, mesh and meta balls can now be chosen as atoms

Clemens Barth barth at root-1.de
Sat Nov 10 17:35:52 CET 2012


Revision: 3948
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3948
Author:   blendphys
Date:     2012-11-10 16:35:51 +0000 (Sat, 10 Nov 2012)
Log Message:
-----------
1. New: NURBS, mesh and meta balls can now be chosen as atoms
   I also updated the Wiki page.
2. Code cleaning

Blendphys

Modified Paths:
--------------
    contrib/py/scripts/addons/io_mesh_xyz/__init__.py
    contrib/py/scripts/addons/io_mesh_xyz/export_xyz.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-11-10 16:34:53 UTC (rev 3947)
+++ contrib/py/scripts/addons/io_mesh_xyz/__init__.py	2012-11-10 16:35:51 UTC (rev 3948)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2011-12-18
-#  Last modified                 : 2012-11-09
+#  Last modified                 : 2012-11-10
 #
 #  Acknowledgements 
 #  ================
@@ -50,7 +50,7 @@
 }
 
 import bpy
-from bpy.types import Operator, Panel
+from bpy.types import Operator
 from bpy_extras.io_utils import ImportHelper, ExportHelper
 from bpy.props import (StringProperty,
                        BoolProperty,
@@ -80,9 +80,13 @@
     use_lamp = BoolProperty(
         name="Lamp", default=False,
         description = "Do you need a lamp?")
-    use_mesh = BoolProperty(
-        name = "Mesh balls", default=False,
-        description = "Use mesh balls instead of NURBS")
+    ball = EnumProperty(
+        name="Type of ball",
+        description="Choose ball",
+        items=(('0', "NURBS", "NURBS balls"),
+               ('1', "Mesh" , "Mesh balls"),
+               ('2', "Meta" , "Metaballs")),
+               default='0',) 
     mesh_azimuth = IntProperty(
         name = "Azimuth", default=32, min=1,
         description = "Number of sectors (azimuth)")
@@ -128,8 +132,10 @@
         row.prop(self, "use_lamp")
         row = layout.row()
         col = row.column()
-        col.prop(self, "use_mesh")
-        col = row.column(align=True)
+        col.prop(self, "ball")
+        row = layout.row()
+        row.active = (self.ball == "1")
+        col = row.column(align=True)        
         col.prop(self, "mesh_azimuth")
         col.prop(self, "mesh_zenith")
         row = layout.row()
@@ -171,7 +177,7 @@
 
         # Execute main routine
         import_xyz.import_xyz(
-                      self.use_mesh,
+                      self.ball,
                       self.mesh_azimuth,
                       self.mesh_zenith,
                       self.scale_ballradius,

Modified: contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py	2012-11-10 16:34:53 UTC (rev 3947)
+++ contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py	2012-11-10 16:35:51 UTC (rev 3948)
@@ -36,7 +36,7 @@
         if "Stick" in obj.name:
             continue
             
-        if obj.type not in {'MESH', 'SURFACE'}:
+        if obj.type not in {'MESH', 'SURFACE', 'META'}:
             continue 
        
         name = ""

Modified: contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-11-10 16:34:53 UTC (rev 3947)
+++ contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-11-10 16:35:51 UTC (rev 3948)
@@ -17,8 +17,7 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import os
-from math import pi, cos, sin, sqrt
+from math import pi, sqrt
 from mathutils import Vector, Matrix
 
 # -----------------------------------------------------------------------------
@@ -213,6 +212,7 @@
 def read_xyz_file(filepath_xyz,radiustype):
 
     number_frames = 0
+    total_number_atoms = 0
 
     # Open the file ...
     filepath_xyz_p = open(filepath_xyz, "r")
@@ -331,12 +331,11 @@
                 atoms_one_type = []
                 for atom in all_atoms:
                     if atom[1] == element:
-                        atoms_one_type.append(AtomProp(
-                                                           atom[0],
-                                                           atom[1],
-                                                           atom[2],
-                                                           atom[3],
-                                                           atom[4],[]))
+                        atoms_one_type.append(AtomProp(atom[0],
+                                                       atom[1],
+                                                       atom[2],
+                                                       atom[3],
+                                                       atom[4],[]))
                 structure.append(atoms_one_type)
 
             ALL_FRAMES.append(structure)
@@ -351,17 +350,17 @@
 # -----------------------------------------------------------------------------
 #                                                            The main routine
 
-def import_xyz(use_mesh,
-                      Ball_azimuth,
-                      Ball_zenith,
-                      Ball_radius_factor,
-                      radiustype,
-                      Ball_distance_factor,
-                      put_to_center, 
-                      put_to_center_all,
-                      use_camera,
-                      use_lamp,
-                      filepath_xyz):
+def import_xyz(Ball_type,
+               Ball_azimuth,
+               Ball_zenith,
+               Ball_radius_factor,
+               radiustype,
+               Ball_distance_factor,
+               put_to_center, 
+               put_to_center_all,
+               use_camera,
+               use_lamp,
+               filepath_xyz):
 
     # List of materials
     atom_material_list = []
@@ -621,18 +620,23 @@
                             layers=current_layers)
         else:
             # NURBS balls
-            if use_mesh == False:
+            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
-            else:
+            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.radius*Ball_radius_factor,) * 3
@@ -664,7 +668,6 @@
 def build_frames(frame_delta, frame_skip):
 
     scn = bpy.context.scene
-    current_layers = scn.layers
 
     # Introduce the basis for all elements that appear in the structure.     
     for element in STRUCTURE:



More information about the Bf-extensions-cvs mailing list