[Bf-extensions-cvs] [a08602a5] master: 1. Fix: rotation of the camera around its own axis (xyz importer) 2. Add: some properties of the ligth source are set for cycles (xyz importer) 3. Add: some material properties are set for cycles (panel utilities)

Clemens Barth noreply at git.blender.org
Wed Mar 20 22:14:00 CET 2019


Commit: a08602a56e701b4c1faad15383c687e840dda1ab
Author: Clemens Barth
Date:   Wed Mar 20 22:12:27 2019 +0100
Branches: master
https://developer.blender.org/rBACa08602a56e701b4c1faad15383c687e840dda1ab

1. Fix: rotation of the camera around its own axis (xyz importer)
2. Add: some properties of the ligth source are set for cycles (xyz importer)
3. Add: some material properties are set for cycles (panel utilities)

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

M	io_atomblend_utilities/io_atomblend_utilities.py
M	io_mesh_xyz/import_xyz.py

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

diff --git a/io_atomblend_utilities/io_atomblend_utilities.py b/io_atomblend_utilities/io_atomblend_utilities.py
index 3b788c1b..5e85c0c8 100644
--- a/io_atomblend_utilities/io_atomblend_utilities.py
+++ b/io_atomblend_utilities/io_atomblend_utilities.py
@@ -453,12 +453,26 @@ def draw_obj_material(material_type, material):
         material_new.roughness = 0.3
         material_new.blend_method = 'ADD'
         material_new.show_transparent_back = False
+        # Some properties for cycles
+        material_new.use_nodes = True
+        mat_P_BSDF = material_new.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.1
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.2
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.9
+        mat_P_BSDF.inputs['IOR'].default_value = 0.8
     if material_type == '3': # Reflecting
         material_new = bpy.data.materials.new(material.name + "_reflecting")
         material_new.metallic = 0.5
         material_new.specular_intensity = 0.5
         material_new.roughness = 0.0
         material_new.blend_method = 'OPAQUE'
+        # Some properties for cycles
+        material_new.use_nodes = True
+        mat_P_BSDF = material_new.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.95
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.1
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.0
+        mat_P_BSDF.inputs['IOR'].default_value = 1.0
     if material_type == '4': # Transparent + reflecting
         material_new = bpy.data.materials.new(material.name + "_trans+refl")
         material_new.metallic = 0.3
@@ -466,7 +480,14 @@ def draw_obj_material(material_type, material):
         material_new.roughness = 0.3
         material_new.blend_method = 'ADD'
         material_new.show_transparent_back = False
-
+        # Some properties for cycles
+        material_new.use_nodes = True
+        mat_P_BSDF = material_new.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.5
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.2
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.5
+        mat_P_BSDF.inputs['IOR'].default_value = 0.8
+        
     # 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
     # selected one. After changing the material of the selected object the old
@@ -691,17 +712,28 @@ def draw_obj_special(atom_shape, atom):
         material_cube.roughness = 0.3
         material_cube.blend_method = 'ADD'
         material_cube.show_transparent_back = True
+        # Some properties for cycles
+        material_cube.use_nodes = True
+        mat_P_BSDF = material_cube.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.1
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.2
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.9
+        mat_P_BSDF.inputs['IOR'].default_value = 0.8
         cube.active_material = material_cube
         # Put a nice point lamp inside the defect
         lamp_data = bpy.data.lights.new(name=atom.name + "_F2+_lamp", 
                                         type="POINT")
         lamp_data.distance = atom.scale[0] * 2.0
-        lamp_data.energy = 8.0
+        lamp_data.energy = 1.0
         lamp_data.color = (0.8, 0.8, 0.8)
         lamp = bpy.data.objects.new(atom.name + "_F2+_lamp", lamp_data)
         lamp.location = Vector((0.0, 0.0, 0.0))
         bpy.context.collection.objects.link(lamp)
         lamp.parent = cube
+        # 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 = 2000
         # The new 'atom' is the F2+ defect
         new_atom = cube
         
@@ -744,6 +776,13 @@ def draw_obj_special(atom_shape, atom):
         material_cube.roughness = 0.3
         material_cube.blend_method = 'ADD'
         material_cube.show_transparent_back = True
+        # Some properties for cycles
+        material_cube.use_nodes = True
+        mat_P_BSDF = material_cube.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.1
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.2
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.9
+        mat_P_BSDF.inputs['IOR'].default_value = 0.8
         cube.active_material = material_cube
         # Create now an electron
         scale = atom.scale / 10.0
@@ -769,12 +808,16 @@ def draw_obj_special(atom_shape, atom):
         lamp_data = bpy.data.lights.new(name=atom.name + "_F+_lamp", 
                                         type="POINT")
         lamp_data.distance = atom.scale[0] * 2.0
-        lamp_data.energy = 8.0
+        lamp_data.energy = 1.0
         lamp_data.color = (0.8, 0.8, 0.8)
         lamp = bpy.data.objects.new(atom.name + "_F+_lamp", lamp_data)
         lamp.location = Vector((scale[0]*1.5, 0.0, 0.0))
         bpy.context.collection.objects.link(lamp)
         lamp.parent = cube
+        # 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 = 2000
         # The new 'atom' is the F+ defect complex + lamp
         new_atom = cube
 
@@ -820,6 +863,13 @@ def draw_obj_special(atom_shape, atom):
         material_cube.roughness = 0.83
         material_cube.blend_method = 'ADD'
         material_cube.show_transparent_back = True
+        # Some properties for cycles
+        material_cube.use_nodes = True
+        mat_P_BSDF = material_cube.node_tree.nodes['Principled BSDF']
+        mat_P_BSDF.inputs['Metallic'].default_value = 0.1
+        mat_P_BSDF.inputs['Roughness'].default_value = 0.2
+        mat_P_BSDF.inputs['Transmission'].default_value = 0.9
+        mat_P_BSDF.inputs['IOR'].default_value = 0.8
         cube.active_material = material_cube
         # Create now two electrons
         scale = atom.scale / 10.0
@@ -870,6 +920,13 @@ def draw_obj_special(atom_shape, atom):
         lamp2.location = Vector((-scale[0]*1.5, 0.0, 0.0))
         bpy.context.collection.objects.link(lamp2)
         lamp2.parent = cube
+        # Some properties for cycles
+        lamp1.data.use_nodes = True
+        lamp2.data.use_nodes = True
+        lmp1_P_BSDF = lamp1.data.node_tree.nodes['Emission']
+        lmp2_P_BSDF = lamp1.data.node_tree.nodes['Emission']
+        lmp1_P_BSDF.inputs['Strength'].default_value = 200
+        lmp2_P_BSDF.inputs['Strength'].default_value = 200
         # The new 'atom' is the F0 defect complex + lamps
         new_atom = cube
 
diff --git a/io_mesh_xyz/import_xyz.py b/io_mesh_xyz/import_xyz.py
index 368f12c6..94391c8f 100644
--- a/io_mesh_xyz/import_xyz.py
+++ b/io_mesh_xyz/import_xyz.py
@@ -348,6 +348,25 @@ def read_xyz_file(filepath_xyz,radiustype):
     return total_number_atoms
 
 
+# Rotate an object.
+def rotate_object(rot_mat, obj):
+
+    bpy.ops.object.select_all(action='DESELECT')
+    obj.select_set(True)
+
+    # Decompose world_matrix's components, and from them assemble 4x4 matrices.
+    orig_loc, orig_rot, orig_scale = obj.matrix_world.decompose()
+
+    orig_loc_mat   = Matrix.Translation(orig_loc)
+    orig_rot_mat   = orig_rot.to_matrix().to_4x4()
+    orig_scale_mat = (Matrix.Scale(orig_scale[0],4,(1,0,0)) @ 
+                      Matrix.Scale(orig_scale[1],4,(0,1,0)) @ 
+                      Matrix.Scale(orig_scale[2],4,(0,0,1)))
+
+    # Assemble the new matrix.
+    obj.matrix_world = orig_loc_mat @ rot_mat @ orig_rot_mat @ orig_scale_mat 
+
+
 # Function, which puts a camera and light source into the 3D scene
 def camera_light_source(use_camera,
                         use_light,
@@ -393,19 +412,10 @@ def camera_light_source(use_camera,
         bpy.ops.object.select_all(action='DESELECT')
         camera.select_set(True)
         
-        # This will be done at some point ...
-        #
-        #bpy.ops.transform.rotate(value=(90.0*2*pi/360.0),
-        #                         axis=object_camera_vec,
-        #                         orient_matrix=camera.rotation_euler,
-        #                         constraint_axis=(False, False, False),
-        #                         orient_type='GLOBAL',
-        #                         mirror=False, proportional='DISABLED',
-        #                         proportional_edit_falloff='SMOOTH',
-        #                         proportional_size=1, snap=False,
-        #                         snap_target='CLOSEST', snap_point=(0, 0, 0),
-        #                         snap_align=False, snap_normal=(0, 0, 0),
-        #                         release_confirm=False)
+        # Rotate the camera around its axis 'object_camera_vec' by 90° such 
+        # that we have a nice camera view onto the object.
+        matrix_rotation = Matrix.Rotation(90/360*2*pi, 4, object_camera_vec)
+        rotate_object(matrix_rotation, camera)
 
     # Here a lamp is put into the scene, if chosen.
     if use_light == True:
@@ -432,6 +442,10 @@ def camera_light_source(use_camera,
         # 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
 
 # -----------------------------------------------------------------------------
 #                                                            The main routine



More information about the Bf-extensions-cvs mailing list