[Bf-extensions-cvs] [8a1a8c89] master: Fix: objects (atoms) can be again replaced by other special designed objects (F centers).

Clemens Barth noreply at git.blender.org
Tue Mar 19 18:48:09 CET 2019


Commit: 8a1a8c89a530f815f37481ece63f2b52f8ab6b82
Author: Clemens Barth
Date:   Tue Mar 19 18:46:48 2019 +0100
Branches: master
https://developer.blender.org/rBAC8a1a8c89a530f815f37481ece63f2b52f8ab6b82

Fix: objects (atoms) can be again replaced by other special designed objects (F centers).

===================================================================

M	io_atomblend_utilities/__init__.py
M	io_atomblend_utilities/io_atomblend_utilities.py

===================================================================

diff --git a/io_atomblend_utilities/__init__.py b/io_atomblend_utilities/__init__.py
index 224164da..6ef8d34d 100644
--- a/io_atomblend_utilities/__init__.py
+++ b/io_atomblend_utilities/__init__.py
@@ -216,10 +216,9 @@ class PanelProperties(bpy.types.PropertyGroup):
         name="Special",
         description="Choose a special atom shape.",
         items=(('0',"None", "Use no special shape."),
-               ('1',"Halo cloud", "Replace with a halo cloud"),
-               ('2',"F2+ center", "Replace with a F2+ center"),
-               ('3',"F+ center", "Replace with a F+ center"),
-               ('4',"F0 center", "Replace with a F0 center")),
+               ('1',"F2+ center", "Replace with a F2+ center"),
+               ('2',"F+ center", "Replace with a F+ center"),
+               ('3',"F0 center", "Replace with a F0 center")),
                default='0',)
     action_type: EnumProperty(
         name="",
diff --git a/io_atomblend_utilities/io_atomblend_utilities.py b/io_atomblend_utilities/io_atomblend_utilities.py
index 7a20c5cb..9b1cb9a7 100644
--- a/io_atomblend_utilities/io_atomblend_utilities.py
+++ b/io_atomblend_utilities/io_atomblend_utilities.py
@@ -364,57 +364,10 @@ def modify_objects(action_type,
             # If the atom shape shall not be changed, then:
             if scn.replace_objs == '0':
                 atom.active_material = new_material
-                return {'FINISHED'}
+                #return {'FINISHED'}
             # If the atom shape shall change, then:
             else:
-                new_atom = draw_obj(scn.replace_objs, atom)
-                new_atom.active_material = new_material
-                new_atom.parent = atom.parent
-
-                if "_repl" not in atom.name:
-                    new_atom.name = atom.name + "_repl"
-                else:
-                    new_atom.name = atom.name
-
-        # Note the collection where the old object was placed into.
-        coll_old_atom_all = atom.users_collection
-        if len(coll_old_atom_all) > 0:
-            coll_old_atom = coll_old_atom_all[0]
-        else:
-            coll_old_atom = bpy.context.scene.collection
-
-        # Note the collection where the new object was placed into.
-        coll_new_atom_past_all = new_atom.users_collection
-        if len(coll_new_atom_past_all) > 0:
-            coll_new_atom_past = coll_new_atom_past_all[0]
-        else:
-            coll_new_atom_past = bpy.context.scene.collection
-
-        # If it is not the same collection then ...
-        if coll_new_atom_past != coll_old_atom:
-            # Put the new object into the collection of the old object and ...
-            coll_old_atom.objects.link(new_atom)
-            # ... unlink the new atom from its original collection.
-            coll_new_atom_past.objects.unlink(new_atom)
-        
-        # If it is the representative object of a duplivert structure then 
-        # hide the new object
-        if new_atom.parent != None:
-            new_atom.hide_set(True)
-
-        # Deselect everything
-        bpy.ops.object.select_all(action='DESELECT')
-        # Make the old atom visible.
-        atom.hide_set(True)
-        # Select the old atom.
-        atom.select_set(True)
-        # Remove the parent if necessary.
-        atom.parent = None
-        # Unlink the old object from the collection.
-        coll_old_atom.objects.unlink(atom)
-        # Delete the old atom
-        bpy.ops.object.delete()
-        del(atom)
+                new_atom = draw_obj(scn.replace_objs, atom, new_material)
 
     # Default shapes and colors for atoms
     if action_type == "ATOM_DEFAULT_OBJ" and "STICK" not in atom.name.upper():
@@ -511,34 +464,24 @@ def draw_obj_material(material_type, material):
         material_new = bpy.data.materials.new(material.name + "_normal")
     if material_type == '2': # Transparent
         material_new = bpy.data.materials.new(material.name + "_transparent")
-        material_new.use_transparency = True
-        material_new.transparency_method = 'Z_TRANSPARENCY'
-        material_new.alpha = 1.3
-        material_new.raytrace_transparency.fresnel = 1.6
-        material_new.raytrace_transparency.fresnel_factor = 1.6
+        material_new.metallic = 0.8
+        material_new.specular_intensity = 0.5
+        material_new.roughness = 0.3
+        material_new.blend_method = 'ADD'
+        material_new.show_transparent_back = False
     if material_type == '3': # Reflecting
         material_new = bpy.data.materials.new(material.name + "_reflecting")
-        material_new.raytrace_mirror.use = True
-        material_new.raytrace_mirror.reflect_factor = 0.6
-        material_new.raytrace_mirror.fresnel = 0.0
-        material_new.raytrace_mirror.fresnel_factor = 1.250
-        material_new.raytrace_mirror.depth = 2
-        material_new.raytrace_mirror.distance = 0.0
-        material_new.raytrace_mirror.gloss_factor = 1.0
+        material_new.metallic = 0.5
+        material_new.specular_intensity = 0.5
+        material_new.roughness = 0.0
+        material_new.blend_method = 'OPAQUE'
     if material_type == '4': # Transparent + reflecting
         material_new = bpy.data.materials.new(material.name + "_trans+refl")
-        material_new.use_transparency = True
-        material_new.transparency_method = 'Z_TRANSPARENCY'
-        material_new.alpha = 1.3
-        material_new.raytrace_transparency.fresnel = 1.6
-        material_new.raytrace_transparency.fresnel_factor = 1.6
-        material_new.raytrace_mirror.use = True
-        material_new.raytrace_mirror.reflect_factor = 0.6
-        material_new.raytrace_mirror.fresnel = 0.0
-        material_new.raytrace_mirror.fresnel_factor = 1.250
-        material_new.raytrace_mirror.depth = 2
-        material_new.raytrace_mirror.distance = 0.0
-        material_new.raytrace_mirror.gloss_factor = 1.0
+        material_new.metallic = 0.3
+        material_new.specular_intensity = 0.5
+        material_new.roughness = 0.3
+        material_new.blend_method = 'ADD'
+        material_new.show_transparent_back = False
 
     # Always, when the material is changed, a new name is created. Note that
     # this makes sense: Imagine, an other object uses the same material as the
@@ -559,8 +502,20 @@ def draw_obj_material(material_type, material):
     return material_new
 
 
+# Get the collection of an object.
+def get_collection_object(obj):
+    
+    coll_all = obj.users_collection
+    if len(coll_all) > 0:
+        coll = coll_all[0]
+    else:
+        coll = bpy.context.scene.collection
+
+    return coll
+    
+
 # Draw an object (e.g. cube, sphere, cylinder, ...)
-def draw_obj(atom_shape, atom):
+def draw_obj(atom_shape, atom, new_material):
 
     # No change
     if atom_shape == '0':
@@ -667,33 +622,57 @@ def draw_obj(atom_shape, atom):
     new_atom.name = atom.name + "_tmp"
     new_atom.select_set(True)
 
+    new_atom.active_material = new_material
+    new_atom.parent = atom.parent
+
+    if "_repl" not in atom.name:
+        new_atom.name = atom.name + "_repl"
+    else:
+        new_atom.name = atom.name
+
+    # Note the collection where the old object was placed into.
+    coll_old_atom = get_collection_object(atom)
+    
+    # Note the collection where the new object was placed into.
+    coll_new_atom_past = get_collection_object(new_atom)
+    
+    # If it is not the same collection then ...
+    if coll_new_atom_past != coll_old_atom:
+        # Put the new object into the collection of the old object and ...
+        coll_old_atom.objects.link(new_atom)
+        # ... unlink the new atom from its original collection.
+        coll_new_atom_past.objects.unlink(new_atom)
+    
+    # If it is the representative object of a duplivert structure then 
+    # hide the new object
+    if new_atom.parent != None:
+        new_atom.hide_set(True)
+    
+    # Deselect everything
+    bpy.ops.object.select_all(action='DESELECT')
+    # Make the old atom visible.
+    atom.hide_set(True)
+    # Select the old atom.
+    atom.select_set(True)
+    # Remove the parent if necessary.
+    atom.parent = None
+    # Unlink the old object from the collection.
+    coll_old_atom.objects.unlink(atom)
+    # Delete the old atom
+    bpy.ops.object.delete()
+    del(atom)
+
     return new_atom
 
 
 # Draw a special object (e.g. halo, etc. ...)
 def draw_obj_special(atom_shape, atom):
 
-    # Halo cloud
-    if atom_shape == '1':
-        # Build one mesh point
-        new_mesh = bpy.data.meshes.new("Mesh_"+atom.name)
-        new_mesh.from_pydata([Vector((0.0,0.0,0.0))], [], [])
-        new_mesh.update()
-        new_atom = bpy.data.objects.new(atom.name + "_sep", new_mesh)
-        bpy.context.collection.objects.link(new_atom)
-        new_atom.location = atom.location
-        material_new = bpy.data.materials.new(atom.active_material.name + "_sep")
-        material_new.name = atom.name + "_halo"
-        material_new.diffuse_color = atom.active_material.diffuse_color
-        material_new.type = 'HALO'
-        material_new.halo.size = atom.scale[0]*1.5
-        material_new.halo.hardness = 25
-        material_new.halo.add = 0.0
-        new_atom.active_material = material_new
-        new_atom.name = atom.name
-        new_atom.select_set(True)
+    # Note the collection where 'atom' is placed into.
+    coll_atom = get_collection_object(atom)
+
     # F2+ center
-    if atom_shape == '2':
+    if atom_shape == '1':
         # Create first a cube
         bpy.ops.mesh.primitive_cube_add(view_align=False,
                                         enter_editmode=False,
@@ -706,26 +685,39 @@ def draw_obj_special(atom_shape, atom):
         # New material for this cube
         material_cube = bpy.data.materials.new(atom.name + "_F2+-center")
         material_cube.diffuse_color = [0.8, 0.0, 0.0, 1.0]
-        material_cube.use_transparency = True
-        material_cube.transparency_method = 'Z_TRANSPARENCY'
-        material_cube.alpha = 1.0
-        material_cube.raytrace_transparency.fresnel = 1.6
-        material_cube.raytrace_transparency.fresnel_factor = 1.1
+        material_cube.metallic = 0.8
+        material_cube.specular_intensity = 0.5
+        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list