diff options
Diffstat (limited to 'io_mesh_atomic/xyz_import.py')
-rw-r--r-- | io_mesh_atomic/xyz_import.py | 56 |
1 files changed, 39 insertions, 17 deletions
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 |