I just started using Blender and am really confused about how to render images. When importing the .obj and .tga (texture map), Blender should render the images with the same RGB value shown in the .tga (texture map). There should not be any additive lighting. When I deleted all the lighting and Blender rendered black images. How can I achieve this? I have upload the code and the data. Thanks in advance for the help!
from pathlib import Path
import bpy
import numpy as np
import json
world = bpy.data.worlds['World']
world.use_nodes = True
bg = world.node_tree.nodes['Background']
bg.inputs[0].default_value[:3] = (0., 0., 0.)
bg.inputs[1].default_value = 0.
def delete_object_iteration(obj_name):
for x in range(1, 15):
obj = bpy.context.scene.objects.get(obj_name + '.' + str(x).zfill(3))
obj_ini = bpy.context.scene.objects.get(obj_name)
if obj_ini is not None:
bpy.data.objects.remove(obj_ini, do_unlink=True)
if obj is not None:
bpy.data.objects.remove(obj, do_unlink=True)
delete_object_iteration("Bip01")
delete_object_iteration("Bip01 Footsteps")
if len(bpy.data.materials.keys()) > 1:
for i, material in enumerate(bpy.data.materials):
if i > 0:
bpy.data.materials.remove(material, do_unlink=True)
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
avatar_path = '/home/tiantian/Desktop/question/Female_Adult_03/Export/Female_Adult_03.fbx'
bpy.ops.import_scene.fbx(filepath=str(avatar_path))
# Fix paths to textures
for im in bpy.data.images:
print(im.filepath)
im.filepath = im.filepath.replace('../../../../../temp/Humans/with_opacity_version/f003/textures', '../Textures')
# Workaround: make opacity texture fully transparent
bpy.data.materials['f003_opacity'].blend_method = 'CLIP'
bpy.data.materials['f003_opacity'].alpha_threshold = 1
# remove default light
bpy.ops.object.select_by_type(type='LIGHT')
bpy.ops.object.delete(use_global=False)
context = bpy.context
scene = bpy.context.scene
render = bpy.context.scene.render
RESOLUTION = 512
render.resolution_x = RESOLUTION
render.resolution_y = RESOLUTION
render.resolution_percentage = 100
render.film_transparent = True
scene.use_nodes = True
nodes = bpy.context.scene.node_tree.nodes
links = bpy.context.scene.node_tree.links
scene.display_settings.display_device = 'None'
# Clear default nodes
for n in nodes:
nodes.remove(n)
render_layers = nodes.new('CompositorNodeRLayers')
# Create depth output nodes
depth_file_output = nodes.new(type="CompositorNodeOutputFile")
depth_file_output.label = 'Depth Output'
depth_file_output.base_path = ''
depth_file_output.file_slots[0].use_node_format = True
depth_file_output.format.file_format = 'OPEN_EXR'
links.new(render_layers.outputs['Depth'], depth_file_output.inputs[0])
albedo_file_output = nodes.new(type="CompositorNodeOutputFile")
albedo_file_output.label = 'Albedo Output'
albedo_file_output.base_path = ''
albedo_file_output.file_slots[0].use_node_format = True
albedo_file_output.format.file_format = 'OPEN_EXR'
albedo_file_output.format.color_mode = 'RGB'
links.new(render_layers.outputs['Image'], albedo_file_output.inputs[0])
xx = 0
# - camera
cam = scene.objects['Camera']
cam.location = (xx, -np.sqrt(3**2-xx**2), 0)
cam_constraint = cam.constraints.new(type='TRACK_TO')
cam_constraint.track_axis = 'TRACK_NEGATIVE_Z'
cam_constraint.up_axis = 'UP_Y'
cam_empty = bpy.data.objects.new("Empty", None)
cam_empty.location = (0, 0, 0.9)
cam.parent = cam_empty
scene.collection.objects.link(cam_empty)
context.view_layer.objects.active = cam_empty
cam_constraint.target = cam_empty
render_file_path = "/home/tiantian/Desktop/question/material0"
albedo_file_output.file_slots[0].path = render_file_path + "_albedo_"
bpy.ops.render.render(write_still=True)
```