Skip to content

different render results from blender GUI and bpy script (load gltf model) #81

@wangsen1312

Description

@wangsen1312

I have load the gltf model and try to render it, but bpy script seems not working!

Render Code:

import bpy
import bmesh
import mathutils
from math import radians
import numpy as np

cam_data = bpy.data.cameras.new('camera')
cam_data.sensor_height = 32
cam_data.sensor_width = 32
cam_data.lens = 35
cam = bpy.data.objects.new('camera', cam_data)
bpy.context.collection.objects.link(cam)
bpy.context.scene.camera = cam
cam.location       = (1, 0, 0)
cam.rotation_mode  = 'ZXY'
cam.rotation_euler = (0, radians(90), radians(90))
# This is camera parent for rotation
org_obj                = bpy.data.objects.new("RotCenter", None)
org_obj.location       = (0, 0, 0)
org_obj.rotation_euler = (0, 0, 0)
bpy.context.collection.objects.link(org_obj)
cam.parent = org_obj
# apply euler to camera
azimuth = 7.81525986082
altitude = 29.2191726248
yaw = 0.0
org_obj.rotation_euler = (radians(-yaw),
                          radians(-altitude),
                          radians(-azimuth))
cam.location       = (1.75* 0.72636316495, 0, 0)

light_data_1 = bpy.data.lights.new('light', type='POINT')
light_1 = bpy.data.objects.new('light', light_data_1)
bpy.context.collection.objects.link(light_1)
light_1.location = mathutils.Vector((3.75, 0, 0)) #* data_param[cur_id][3]

#light_data_2 = bpy.data.lights.new('light', type='AREA')
#light_2 = bpy.data.objects.new('light', light_data_2)
#bpy.context.collection.objects.link(light_2)
#light_2.location       = (0, 2, 2)
#light_2.rotation_mode  = 'ZXY'
#light_2.rotation_euler = (-radians(45), 0, radians(90))
#light_2.data.energy = 0.7

light_data_3 = bpy.data.lights.new('light', type='SUN')
light_3 = bpy.data.objects.new('light', light_data_3)
bpy.context.collection.objects.link(light_3)
light_3.location = mathutils.Vector((5, 5, 5))

bpy.ops.object.select_pattern(pattern="Cube")
bpy.ops.object.delete()

file_paths = r'model.gltf'
bpy.ops.import_scene.gltf(filepath=file_paths)


cur_id = 0
render_location = r"Test2_%02d.png"%(cur_id)
print(f"Rendering to {render_location}")

#bpy.context.scene.world.light_settings.use_ambient_occlusion = True
#bpy.context.scene.world.light_settings.ao_factor = 0.5
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.resolution_x = 256
bpy.context.scene.render.resolution_y = 256
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.render.engine = 'CYCLES'
# filepath
bpy.context.scene.render.filepath = render_location

bpy.ops.render.render(write_still=True)
print(f"Completed: Rendering to {render_location}")

The model is attached:
model.zip

bpy render results:
bpy_results

blender GUI:
render

I have tried on Windows and Ubuntu, the bpy results are the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions