[Bf-extensions-cvs] [c00916b2] master: The addon gets updated for Eevee/Cycles - part 2: we now use a sphere as a 'point' light source. In material properties, the sphere has the node called 'Emission'. Note that the light source as well as a camera can be **optionally** chosen, they are not set by default.

Clemens Barth noreply at git.blender.org
Sat Jan 15 12:44:24 CET 2022


Commit: c00916b26b08cb5701974ffddadc6aba6c1e00f0
Author: Clemens Barth
Date:   Sat Jan 15 12:40:30 2022 +0100
Branches: master
https://developer.blender.org/rBAc00916b26b08cb5701974ffddadc6aba6c1e00f0

The addon gets updated for Eevee/Cycles - part 2: we now use a sphere
as a 'point' light source. In material properties, the sphere has the
node called 'Emission'. Note that the light source as well as a camera
can be **optionally** chosen, they are not set by default.

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

M	io_mesh_atomic/pdb_import.py
M	io_mesh_atomic/xyz_import.py

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

diff --git a/io_mesh_atomic/pdb_import.py b/io_mesh_atomic/pdb_import.py
index 87404a89..28f75b12 100644
--- a/io_mesh_atomic/pdb_import.py
+++ b/io_mesh_atomic/pdb_import.py
@@ -367,6 +367,7 @@ def read_pdb_file_sticks(filepath_pdb, use_sticks_bonds, all_atoms):
     split_list = line.split(' ')
 
     # Go to the first entry
+    # DO NOT CHANGE 'CONECT', read below.
     if "CONECT" not in split_list[0]:
         for line in filepath_pdb_p:
             split_list = line.split(' ')
@@ -388,7 +389,7 @@ def read_pdb_file_sticks(filepath_pdb, use_sticks_bonds, all_atoms):
 
         # Note 2019-03-16: in a PDB file the identifier for sticks is called
         # 'CONECT' and NOT 'CONNECT'! Please leave this as is, otherwise the
-        # sticks are NOT correctly loaded.
+        # sticks are NOT correctly imported.
 
         # The strings of the atom numbers do have a clear position in the file
         # (From 7 to 12, from 13 to 18 and so on.) and one needs to consider
@@ -618,30 +619,53 @@ def camera_light_source(use_camera,
 
         # This is the distance from the object measured in terms of %
         # of the camera distance. It is set onto 50% (1/2) distance.
-        light_dl = sqrt(object_size) * 15 * 0.5
+        lamp_dl = sqrt(object_size) * 15 * 0.5
         # This is a factor to which extend the lamp shall go to the right
         # (from the camera  point of view).
-        light_dy_right = light_dl * (3.0/4.0)
+        lamp_dy_right = lamp_dl * (3.0/4.0)
 
         # Create x, y and z for the lamp.
-        object_light_vec = Vector((light_dl,light_dy_right,light_dl))
-        light_xyz_vec = object_center_vec + object_light_vec
-
-        # Create the lamp
-        light_data = bpy.data.lights.new(name="A_light", type="SUN")
-        light_data.distance = 500.0
-        light_data.energy = 3.0
-        lamp = bpy.data.objects.new("A_light", light_data)
-        lamp.location = light_xyz_vec
-        bpy.context.collection.objects.link(lamp)
+        object_lamp_vec = Vector((lamp_dl,lamp_dy_right,lamp_dl))
+        lamp_xyz_vec = object_center_vec + object_lamp_vec
+
+        # As a lamp we use a ball.
+        bpy.ops.mesh.primitive_uv_sphere_add(
+                        segments=64,
+                        ring_count=64,
+                        align='WORLD',
+                        enter_editmode=False,
+                        location=lamp_xyz_vec,
+                        rotation=(0, 0, 0))
+        lamp = bpy.context.view_layer.objects.active
+        # We put an 'A_' just that the lamp appears first in the outliner
+        # tree
+        lamp.name = "A_lamp"
+
+        # We now determine the emission strength of the lamp. Note that the
+        # intensity depends on 1/r^2. For this we use a value of 5000.0 at a
+        # distance of 58 (58x58 = 3364.0). This value was determined only once
+        # in the Blender viewport
+        length = lamp_xyz_vec.length
+        strength = 5000.0 * ( (length * length) / (58.0 * 58.0) )
+
+        # Now, we create the material
+        lamp_material = bpy.data.materials.new(lamp.name)
+        lamp_material.use_nodes = True
+        # Create the emission Node.
+        material_output = lamp_material.node_tree.nodes.get('Material Output')
+        emission = lamp_material.node_tree.nodes.new('ShaderNodeEmission')
+        # Emission and strength values
+        emission.inputs['Strength'].default_value = strength
+        emission.inputs['Color'].default_value = (1.0, 1.0, 1.0, 1.0)
+        # The new material into the tree and link the material of the object
+        # with the new material.
+        lamp_material.node_tree.links.new(material_output.inputs[0], emission.outputs[0])
+        lamp.active_material = lamp_material
 
         # Some settings for the World: a bit ambient occlusion
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
         bpy.context.scene.world.light_settings.ao_factor = 0.1
-        # Some properties for cycles
-        lamp.data.use_nodes = True
-        lmp_P_BSDF = lamp.data.node_tree.nodes['Emission']
-        lmp_P_BSDF.inputs['Strength'].default_value = 5
+
 
 
 # Function, which draws the atoms of one type (balls). This is one
diff --git a/io_mesh_atomic/xyz_import.py b/io_mesh_atomic/xyz_import.py
index c54ef8ef..96bf7913 100644
--- a/io_mesh_atomic/xyz_import.py
+++ b/io_mesh_atomic/xyz_import.py
@@ -422,30 +422,52 @@ def camera_light_source(use_camera,
 
         # This is the distance from the object measured in terms of %
         # of the camera distance. It is set onto 50% (1/2) distance.
-        light_dl = sqrt(object_size) * 15 * 0.5
+        lamp_dl = sqrt(object_size) * 15 * 0.5
         # This is a factor to which extend the lamp shall go to the right
         # (from the camera  point of view).
-        light_dy_right = light_dl * (3.0/4.0)
+        lamp_dy_right = lamp_dl * (3.0/4.0)
 
         # Create x, y and z for the lamp.
-        object_light_vec = Vector((light_dl,light_dy_right,light_dl))
-        light_xyz_vec = object_center_vec + object_light_vec
-
-        # Create the lamp
-        light_data = bpy.data.lights.new(name="A_light", type="SUN")
-        light_data.distance = 500.0
-        light_data.energy = 3.0
-        lamp = bpy.data.objects.new("A_light", light_data)
-        lamp.location = light_xyz_vec
-        bpy.context.collection.objects.link(lamp)
+        object_lamp_vec = Vector((lamp_dl,lamp_dy_right,lamp_dl))
+        lamp_xyz_vec = object_center_vec + object_lamp_vec
+
+        # As a lamp we use a ball.
+        bpy.ops.mesh.primitive_uv_sphere_add(
+                        segments=64,
+                        ring_count=64,
+                        align='WORLD',
+                        enter_editmode=False,
+                        location=lamp_xyz_vec,
+                        rotation=(0, 0, 0))
+        lamp = bpy.context.view_layer.objects.active
+        # We put an 'A_' just that the lamp appears first in the outliner
+        # tree
+        lamp.name = "A_lamp"
+
+        # We now determine the emission strength of the lamp. Note that the
+        # intensity depends on 1/r^2. For this we use a value of 5000.0 at a
+        # distance of 58 (58x58 = 3364.0). This value was determined only once
+        # in the Blender viewport
+        length = lamp_xyz_vec.length
+        strength = 5000.0 * ( (length * length) / (58.0 * 58.0) )
+
+        # Now, we create the material
+        lamp_material = bpy.data.materials.new(lamp.name)
+        lamp_material.use_nodes = True
+        # Create the emission Node.
+        material_output = lamp_material.node_tree.nodes.get('Material Output')
+        emission = lamp_material.node_tree.nodes.new('ShaderNodeEmission')
+        # Emission and strength values
+        emission.inputs['Strength'].default_value = strength
+        emission.inputs['Color'].default_value = (1.0, 1.0, 1.0, 1.0)
+        # The new material into the tree and link the material of the object
+        # with the new material.
+        lamp_material.node_tree.links.new(material_output.inputs[0], emission.outputs[0])
+        lamp.active_material = lamp_material
 
         # Some settings for the World: a bit ambient occlusion
         bpy.context.scene.world.light_settings.use_ambient_occlusion = True
-        bpy.context.scene.world.light_settings.ao_factor = 0.2
-        # Some properties for cycles
-        lamp.data.use_nodes = True
-        lmp_P_BSDF = lamp.data.node_tree.nodes['Emission']
-        lmp_P_BSDF.inputs['Strength'].default_value = 5
+        bpy.context.scene.world.light_settings.ao_factor = 0.1
 
 # -----------------------------------------------------------------------------
 #                                                            The main routine



More information about the Bf-extensions-cvs mailing list