Skip to content
Snippets Groups Projects
Select Git revision
  • d48d8b47a453eacf8de3f83d18a4c23d84a3d470
  • master default protected
  • enxhi_issue460_remove_TOAR-I_access
  • michael_issue459_preprocess_german_stations
  • sh_pollutants
  • develop protected
  • release_v2.4.0
  • michael_issue450_feat_load-ifs-data
  • lukas_issue457_feat_set-config-paths-as-parameter
  • lukas_issue454_feat_use-toar-statistics-api-v2
  • lukas_issue453_refac_advanced-retry-strategy
  • lukas_issue452_bug_update-proj-version
  • lukas_issue449_refac_load-era5-data-from-toar-db
  • lukas_issue451_feat_robust-apriori-estimate-for-short-timeseries
  • lukas_issue448_feat_load-model-from-path
  • lukas_issue447_feat_store-and-load-local-clim-apriori-data
  • lukas_issue445_feat_data-insight-plot-monthly-distribution
  • lukas_issue442_feat_bias-free-evaluation
  • lukas_issue444_feat_choose-interp-method-cams
  • 414-include-crps-analysis-and-other-ens-verif-methods-or-plots
  • lukas_issue384_feat_aqw-data-handler
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.0 protected
  • v2.1.0 protected
  • Kleinert_etal_2022_initial_submission
  • v2.0.0 protected
  • v1.5.0 protected
  • v1.4.0 protected
  • v1.3.0 protected
  • v1.2.1 protected
  • v1.2.0 protected
  • v1.1.0 protected
  • IntelliO3-ts-v1.0_R1-submit
  • v1.0.0 protected
  • v0.12.2 protected
  • v0.12.1 protected
  • v0.12.0 protected
  • v0.11.0 protected
  • v0.10.0 protected
  • IntelliO3-ts-v1.0_initial-submit
41 results

data_preparation.py

Blame
  • spray_movie_temporal_camera_1.py 6.41 KiB
    import bpy
    
    from mathutils import Vector
    
    bpy.ops.object.delete(use_global=False)
    
    bpy.data.objects['Lamp'].select = True
    bpy.ops.object.delete(use_global=False)
    bpy.context.scene.render.engine = 'CYCLES'
    
    mat = bpy.data.materials.new('BWG')
    mat.use_nodes = True
    
    nodes = {
    'Texture Coordinate': ['ShaderNodeTexCoord', (-220.0, 510.0)],
    'Image Texture': ['ShaderNodeTexImage', (-20.0, 510.0)],
    'Emission': ['ShaderNodeEmission', (190.0, 450.0)],
    'Material Output': ['ShaderNodeOutputMaterial', (400.0, 450.0)]
    }
    
    for k, v in nodes.items():
        location = Vector(v[1])
        if not k in mat.node_tree.nodes:
            cur_node = mat.node_tree.nodes.new(v[0])
            cur_node.location = location
        else:
            mat.node_tree.nodes[k].location = location
    
    link00 = ['Texture Coordinate','Generated','Image Texture','Vector']
    link01 = ['Image Texture','Color','Emission','Color']
    link02 = ['Emission','Emission','Material Output','Surface']
    
    links = [link00, link01, link02]
    for link in links:
        from_node = mat.node_tree.nodes[link[0]]
        output_socket = from_node.outputs[link[1]]
        to_node = mat.node_tree.nodes[link[2]]
        input_socket = to_node.inputs[link[3]]
        mat.node_tree.links.new(output_socket, input_socket)
    
    mat.node_tree.nodes["Emission"].inputs['Strength'].default_value = 3.0
    
    img = bpy.data.images.load('back.png')
    mat.node_tree.nodes['Image Texture'].image = img
    
    bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
    plane = bpy.data.objects['Plane']
    bpy.ops.object.shade_smooth()
    plane.location[0] = 1
    plane.location[1] = 4
    plane.location[2] = 0
    plane.rotation_euler[0] = 1.5708
    plane.rotation_euler[1] = 0
    plane.rotation_euler[2] = 0
    
    plane.scale[0] = 7
    plane.scale[1] = 5
    plane.scale[2] = 1
    
    plane.data.materials.append(mat)
    plane.select = False
    
    camera = bpy.data.objects['Camera']
    camera.select = True
    camera.location[0] = 4.0
    camera.location[1] = -5.4
    camera.location[2] = 1.0
    camera.rotation_euler[0] = 1.39626
    camera.rotation_euler[1] = 0.0
    camera.rotation_euler[2] = 0.258553
    camera.select = False
    
    bpy.ops.object.lamp_add(type='SUN', view_align=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
    sun = bpy.data.objects['Sun']
    sun.location[0] = 0
    sun.location[1] = -5
    sun.location[2] = 4
    sun.rotation_euler[0] = 0.911987
    sun.rotation_euler[1] = -0.259932
    sun.rotation_euler[2] = 0
    sun.select = False
    
    mat = bpy.data.materials.new('Injector')
    mat.use_nodes = True
    
    nodes = {
    'Diffuse BSDF': ['ShaderNodeBsdfDiffuse', (-220.0, 510.0)],
    'Material Output': ['ShaderNodeOutputMaterial', (-20.0, 510.0)],
    }
    
    for k, v in nodes.items():
        location = Vector(v[1])
        if not k in mat.node_tree.nodes:
            cur_node = mat.node_tree.nodes.new(v[0])
            cur_node.location = location
        else:
            mat.node_tree.nodes[k].location = location
    
    from_node = mat.node_tree.nodes['Diffuse BSDF']
    output_socket = from_node.outputs['BSDF']
    to_node = mat.node_tree.nodes['Material Output']
    input_socket = to_node.inputs['Surface']
    mat.node_tree.links.new(output_socket, input_socket)
    
    mat.node_tree.nodes["Diffuse BSDF"].inputs['Color'].default_value = (0.024,0,0.8,1)
    
    mat = bpy.data.materials.new('Fluid')
    mat.use_nodes = True
    
    nodes = {
    'Glass BSDF': ['ShaderNodeBsdfGlass', (-220.0, 510.0)],
    'Material Output': ['ShaderNodeOutputMaterial', (-20.0, 510.0)],
    }
    
    for k, v in nodes.items():
        location = Vector(v[1])
        if not k in mat.node_tree.nodes:
            cur_node = mat.node_tree.nodes.new(v[0])
            cur_node.location = location
        else:
            mat.node_tree.nodes[k].location = location
    
    from_node = mat.node_tree.nodes['Glass BSDF']
    output_socket = from_node.outputs['BSDF']
    to_node = mat.node_tree.nodes['Material Output']
    input_socket = to_node.inputs['Surface']
    mat.node_tree.links.new(output_socket, input_socket)
    
    mat.node_tree.nodes["Glass BSDF"].inputs['Color'].default_value = (1,1,1,1)
    mat.node_tree.nodes["Glass BSDF"].inputs['IOR'].default_value = 1.333
    
    bpy.context.scene.render.resolution_percentage = 100
    
    path = bpy.data.curves.new('NurbsPath', 'CURVE')
    pathOb = bpy.data.objects.new('NurbsPath', path)
    pathOb.location = (0,0,0)
    bpy.context.scene.objects.link(pathOb)
    
    # Set path data
    path.dimensions = '3D'
    path.use_path = True
    path.use_path_follow = True
    path.path_duration = 100
    
    # Animate path
    path.eval_time = 0
    path.keyframe_insert(data_path="eval_time", frame=0)
    path.eval_time = 100
    path.keyframe_insert(data_path="eval_time", frame=100)    
    
    # Add a spline to path
    spline = path.splines.new('NURBS')
    spline.use_cyclic_u = False
    spline.use_endpoint_u = False
    
    # Add points to spline
    pointTable = [(4.0,-5.4, 1.0,100),(4.0,-5.4, 1.0,100),(2.9,-3.4, 0.9,10),(2.7,-2.4, 0.9,10),(2.7,-1.4, 1.0,100),(2.7,-1.4, 1.0,100)]
    nPoints = len(pointTable)
    spline.points.add(nPoints-1)
    for n in range(nPoints):
        spline.points[n].co = pointTable[n]
    
    bpy.data.objects["NurbsPath"].hide = True
    camera = bpy.data.objects['Camera']
    camera.select = True
    camera.location[0] = 0.0
    camera.location[1] = 0.0
    camera.location[2] = 0.0
    camera.rotation_euler[2] = -0.1
    
    # Add follow path constraint to monkey
    cns = camera.constraints.new('FOLLOW_PATH')
    cns.target = pathOb
    cns.use_curve_follow = True
    cns.use_curve_radius = True
    cns.use_fixed_location = False
    cns.forward_axis = 'FORWARD_Y'
    cns.up_axis = 'UP_Z'
    
    for i in range(900,1391):
        fnin = ("F_We3000_%4.4d.stl" % i)
        spname = ("F_We3000_%4.4d.stl" % i)
        obname = ("F We3000 %4.4d" % i)
        spdir = ("")
        fnout = ("pics_camera/F_We3000_%4.4d.png" % i)
        j=i
        if (j-671 < 81):
            bpy.context.scene.frame_current = j-671
        else:
            bpy.context.scene.frame_current = 80
        bpy.ops.import_mesh.stl(filepath=fnin, filter_glob="*.stl", files=[{"name":spname, "name":spname}], directory=spdir)
        spray = bpy.data.objects[obname]
        bpy.ops.object.shade_smooth()
        spray.scale[0] = 0.6
        spray.scale[1] = 0.6
        spray.scale[2] = 0.6
        spray.rotation_euler[0] = 1.5708
        spray.location[0] = 2.7
        spray.location[1] = -0.0
        spray.location[2] = 0.1
        spray.data.materials.append(mat)
        spray.select = False
        bpy.context.scene.render.filepath = fnout
        bpy.ops.render.render(write_still = True)
        spray.select = True
        bpy.ops.object.delete(use_global=False)