def _add_object(obj: core.MeshChromeMaterial): # --- Create node-based material mat = bpy.data.materials.new("Chrome") mat.use_nodes = True tree = mat.node_tree tree.remove(tree.nodes["Principled BSDF"]) # remove the default shader # --- Specify nodes LW = tree.nodes.new("ShaderNodeLayerWeight") LW.inputs[0].default_value = 0.7 CR = tree.nodes.new("ShaderNodeValToRGB") CR.color_ramp.elements[0].position = 0.9 CR.color_ramp.elements[1].position = 1 CR.color_ramp.elements[1].color = (0, 0, 0, 1) GLO = tree.nodes.new("ShaderNodeBsdfGlossy") # --- link nodes tree.links.new(LW.outputs[1], CR.inputs["Fac"]) tree.links.new(CR.outputs["Color"], GLO.inputs["Color"]) tree.links.new(GLO.outputs[0], tree.nodes["Material Output"].inputs["Surface"]) setters = { "color": core.AttributeSetter(CR.color_ramp.elements[0], "color"), "roughness": core.AttributeSetter(GLO.inputs[1], "default_value") } return mat, setters
def _add_object(obj: core.Cube): bpy.ops.mesh.primitive_cube_add() cube = bpy.context.active_object return cube, { 'position': core.AttributeSetter(cube, 'location'), 'quaternion': core.AttributeSetter(cube, 'rotation_quaternion'), 'scale': core.AttributeSetter(cube, 'scale'), 'material': core.AttributeSetter(cube, 'active_material') }
def _add_object(obj: core.Sphere): bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=5) bpy.ops.object.shade_smooth() cube = bpy.context.active_object return cube, { 'position': core.AttributeSetter(cube, 'location'), 'quaternion': core.AttributeSetter(cube, 'rotation_quaternion'), 'scale': core.AttributeSetter(cube, 'scale'), 'material': core.AttributeSetter(cube, 'active_material') }
def _add_object(obj: core.PrincipledBSDFMaterial): mat = bpy.data.materials.new(obj.uid) mat.use_nodes = True bsdf_node = mat.node_tree.nodes["Principled BSDF"] setters = { "color": core.AttributeSetter(bsdf_node.inputs["Base Color"], "default_value"), "roughness": core.AttributeSetter(bsdf_node.inputs["Roughness"], "default_value"), "metallic": core.AttributeSetter(bsdf_node.inputs["Metallic"], "default_value"), "specular": core.AttributeSetter(bsdf_node.inputs["Specular"], "default_value"), "specular_tint": core.AttributeSetter(bsdf_node.inputs["Specular Tint"], "default_value"), "ior": core.AttributeSetter(bsdf_node.inputs["IOR"], "default_value"), "transmission": core.AttributeSetter(bsdf_node.inputs["Transmission"], "default_value"), "transmission_roughness": core.AttributeSetter(bsdf_node.inputs["Transmission Roughness"], "default_value"), "emission": core.AttributeSetter(bsdf_node.inputs["Emission"], "default_value"), } return mat, setters
def _add_object(obj: core.OrthographicCamera): camera = bpy.data.cameras.new(obj.uid) camera.type = 'ORTHO' camera_obj = bpy.data.objects.new(obj.uid, camera) setters = { 'position': core.AttributeSetter(camera_obj, 'location'), 'quaternion': core.AttributeSetter(camera_obj, 'rotation_quaternion'), 'scale': core.AttributeSetter(camera_obj, 'scale'), 'orthographic_scale': core.AttributeSetter(camera, 'ortho_scale') } return camera_obj, setters
def _add_object(obj: core.PointLight): area = bpy.data.lights.new(obj.uid, "POINT") area_obj = bpy.data.objects.new(obj.uid, area) setters = { "position": core.AttributeSetter(area_obj, "location"), "quaternion": core.AttributeSetter(area_obj, "rotation_quaternion"), "scale": core.AttributeSetter(area_obj, "scale"), "color": core.AttributeSetter(area, "color"), "intensity": core.AttributeSetter(area, "energy") } return area_obj, setters
def _add_object(obj: core.DirectionalLight): sun = bpy.data.lights.new(obj.uid, "SUN") sun_obj = bpy.data.objects.new(obj.uid, sun) setters = { "position": core.AttributeSetter(sun_obj, "location"), "quaternion": core.AttributeSetter(sun_obj, "rotation_quaternion"), "scale": core.AttributeSetter(sun_obj, "scale"), "color": core.AttributeSetter(sun, "color"), "intensity": core.AttributeSetter(sun, "energy") } return sun_obj, setters
def _add_object(obj: core.FlatMaterial): # --- Create node-based material mat = bpy.data.materials.new('Holdout') mat.use_nodes = True tree = mat.node_tree tree.nodes.remove( tree.nodes['Principled BSDF']) # remove the default shader output_node = tree.nodes['Material Output'] # This material is constructed from three different shaders: # 1. if holdout=False then emission_node is responsible for giving the object a uniform color # 2. if holdout=True, then the holdout_node is responsible for making the object transparent # 3. if indirect_visibility=False then transparent_node makes the node invisible for indirect # effects such as shadows or reflections light_path_node = tree.nodes.new(type="ShaderNodeLightPath") holdout_node = tree.nodes.new(type="ShaderNodeHoldout") transparent_node = tree.nodes.new(type="ShaderNodeBsdfTransparent") holdout_mix_node = tree.nodes.new(type="ShaderNodeMixShader") indirect_mix_node = tree.nodes.new(type="ShaderNodeMixShader") overall_mix_node = tree.nodes.new(type="ShaderNodeMixShader") emission_node = tree.nodes.new(type="ShaderNodeEmission") tree.links.new(transparent_node.outputs['BSDF'], indirect_mix_node.inputs[1]) tree.links.new(emission_node.outputs['Emission'], indirect_mix_node.inputs[2]) tree.links.new(emission_node.outputs['Emission'], holdout_mix_node.inputs[1]) tree.links.new(holdout_node.outputs['Holdout'], holdout_mix_node.inputs[2]) tree.links.new(light_path_node.outputs['Is Camera Ray'], overall_mix_node.inputs['Fac']) tree.links.new(indirect_mix_node.outputs['Shader'], overall_mix_node.inputs[1]) tree.links.new(holdout_mix_node.outputs['Shader'], overall_mix_node.inputs[2]) tree.links.new(overall_mix_node.outputs['Shader'], output_node.inputs['Surface']) return mat, { 'color': core.AttributeSetter(emission_node.inputs['Color'], 'default_value'), 'holdout': core.AttributeSetter(holdout_mix_node.inputs['Fac'], 'default_value'), 'indirect_visibility': core.AttributeSetter(indirect_mix_node.inputs['Fac'], 'default_value'), }
def _add_object(obj: core.PerspectiveCamera): camera = bpy.data.cameras.new(obj.uid) camera.type = "PERSP" camera_obj = bpy.data.objects.new(obj.uid, camera) setters = { "position": core.AttributeSetter(camera_obj, "location"), "quaternion": core.AttributeSetter(camera_obj, "rotation_quaternion"), "scale": core.AttributeSetter(camera_obj, "scale"), "focal_length": core.AttributeSetter(camera, "lens"), "sensor_width": core.AttributeSetter(camera, "sensor_width") } return camera_obj, setters
def _add_object(obj: core.FileBasedObject): # TODO: support other file-formats bpy.ops.import_scene.obj(filepath=str(obj.render_filename), axis_forward=obj.front, axis_up=obj.up) assert len(bpy.context.selected_objects) == 1 blender_obj = bpy.context.selected_objects[0] setters = { "position": core.AttributeSetter(blender_obj, "location"), "quaternion": core.AttributeSetter(blender_obj, "rotation_quaternion"), "scale": core.AttributeSetter(blender_obj, "scale"), "material": core.AttributeSetter(blender_obj, "active_material") } return blender_obj, setters
def _add_scene(obj: core.Scene): blender_scene = bpy.context.scene setters = { "frame_start": core.AttributeSetter(blender_scene, "frame_start"), "frame_end": core.AttributeSetter(blender_scene, "frame_end"), "frame_rate": core.AttributeSetter(blender_scene.render, "fps"), "resolution": core.AttributeSetter(blender_scene.render, ["resolution_x", "resolution_y"]), "camera": core.AttributeSetter(blender_scene, "camera") } return blender_scene, setters
def _add_object(obj: core.RectAreaLight): area = bpy.data.lights.new(obj.uid, "AREA") area_obj = bpy.data.objects.new(obj.uid, area) setters = { "position": core.AttributeSetter(area_obj, "location"), "quaternion": core.AttributeSetter(area_obj, "rotation_quaternion"), "scale": core.AttributeSetter(area_obj, "scale"), "color": core.AttributeSetter(area, "color"), "intensity": core.AttributeSetter(area, "energy"), "width": core.AttributeSetter(area, "size"), "height": core.AttributeSetter(area, "size_y") } return area_obj, setters