blenderpy icon indicating copy to clipboard operation
blenderpy copied to clipboard

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

Open wangsen1312 opened this issue 4 years ago • 3 comments
trafficstars

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.

wangsen1312 avatar Feb 27 '21 06:02 wangsen1312

I just loaded your exact script into the Blender "Scripting" GUI (without doing anything else) and got the following:

Test2_00

Can you further explain what you expect to see here?

TylerGubala avatar Mar 04 '21 23:03 TylerGubala

@TylerGubala Thank you for you response I think the correct render results should like below:

model

If you can use blender import the model and alt +z render it, you can see the results looks like above.

wangsen1312 avatar Mar 05 '21 03:03 wangsen1312

But that's not what you said, you said that when running the script in Blender GUI you were seeing the correct result.

But it looks like you are not running the script, but rather that you are pressing the render button.

I think you need to ask on Stack Exchange about how to render the result you want using Python, because bpy seems to create the same result as Blender, all things (your script) considered equal.

On Thu, Mar 4, 2021, 10:48 PM wangsen1312 [email protected] wrote:

@TylerGubala https://github.com/TylerGubala Thank you for you response I think the correct render results should like below:

[image: model] https://user-images.githubusercontent.com/11545246/110064676-d1fc3f80-7d2a-11eb-840a-d6fdec7d413b.png

If you can use blender import the model and alt +z render it, you can see the results looks like above.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TylerGubala/blenderpy/issues/81#issuecomment-791131661, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFLEYR7IGSSY2TS3UXDEDR3TCBIBTANCNFSM4YJTQ47Q .

TylerGubala avatar Mar 05 '21 05:03 TylerGubala