0

I am new to blender and trying to render this file. Trying to render using script gives a very different result (everything purple) as compared to what I see in Blender GUI. What am I doing wrong?

Here is the script I am using

import os
import bpy

bpy.ops.wm.open_mainfile(filepath="materials.blend")

VIEWS = 1 RESOLUTION = 200 RESULTS_PATH = '.' DEPTH_SCALE = 1.4 COLOR_DEPTH = 8 FORMAT = 'PNG' RANDOM_VIEWS = True UPPER_VIEWS = True CIRCLE_FIXED_START = (.3, 0, 0)

fp = bpy.path.abspath(f"//{RESULTS_PATH}") if not os.path.exists(fp): os.makedirs(fp)

Render Optimizations

bpy.context.scene.render.use_persistent_data = True

Set up rendering of depth map.

bpy.context.scene.use_nodes = True tree = bpy.context.scene.node_tree links = tree.links

Add passes for additionally dumping albedo and normals.

bpy.context.scene.view_layers["RenderLayer"].use_pass_normal = True

bpy.context.scene.render.image_settings.file_format = str(FORMAT) bpy.context.scene.render.image_settings.color_depth = str(COLOR_DEPTH)

Background

bpy.context.scene.render.dither_intensity = 0.0 bpy.context.scene.render.film_transparent = True

Create collection for objects not to render with background

objs = [ob for ob in bpy.context.scene.objects if ob.type in ('EMPTY') and 'Empty' in ob.name] bpy.ops.object.delete({"selected_objects": objs})

def parent_obj_to_camera(b_camera): origin = (0, 0, 0) b_empty = bpy.data.objects.new("Empty", None) b_empty.location = origin b_camera.parent = b_empty # setup parenting

scn = bpy.context.scene
scn.collection.objects.link(b_empty)
bpy.context.view_layer.objects.active = b_empty
# scn.objects.active = b_empty
return b_empty

scene = bpy.context.scene scene.render.resolution_x = RESOLUTION scene.render.resolution_y = RESOLUTION scene.render.resolution_percentage = 100

cam = scene.objects['Camera'] cam.location = (0, 4.0, 0.5) cam_constraint = cam.constraints.new(type='TRACK_TO') cam_constraint.track_axis = 'TRACK_NEGATIVE_Z' cam_constraint.up_axis = 'UP_Y' b_empty = parent_obj_to_camera(cam) cam_constraint.target = b_empty

b_empty.rotation_euler = CIRCLE_FIXED_START scene.render.image_settings.file_format = FORMAT scene.render.filepath = fp + '/r_0' bpy.ops.render.render(write_still=True) # render still

Output of blender --background --python script.py

enter image description here

Screenshot of Blender GUI

enter image description here

kampta
  • 101
  • 1
  • 1
    Looks like you don't have any HDRI map for the World shader. Use one. – Carlo Jan 12 '21 at 21:41
  • @Carlo - Why do I need a world shader? I am not concerned with background or anything, it is the material of the spheres that is not getting rendered – kampta Jan 12 '21 at 22:43
  • 1
    You are using a script to render the scene, so all the scenes settings are applied, world shader included. I don't see any line of codes changing that. Who set up the file used a world shader with a texture that you are missing. The file is "forest.exr". You can just get rid of the shader if you don't need it, but if you don't, it will use what is currently defined. – Carlo Jan 12 '21 at 22:52
  • @Carlo - Got it. Thanks a lot. This was very helpful – kampta Jan 12 '21 at 22:58
  • I'm glad it was useful. – Carlo Jan 12 '21 at 23:03

0 Answers0