glTF importer/exporter: fix ortho camera fram import/export

This commit is contained in:
Julien Duroure 2022-10-21 18:45:23 +02:00
parent cd2d9df925
commit 8a2443844d
3 changed files with 16 additions and 6 deletions

View File

@ -4,7 +4,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (3, 4, 38),
"version": (3, 4, 39),
'blender': (3, 3, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -58,8 +58,16 @@ def __gather_orthographic(blender_camera, export_settings):
znear=None
)
orthographic.xmag = blender_camera.ortho_scale
orthographic.ymag = blender_camera.ortho_scale
_render = bpy.context.scene.render
scene_x = _render.resolution_x * _render.pixel_aspect_x
scene_y = _render.resolution_y * _render.pixel_aspect_y
scene_square = max(scene_x, scene_y)
del _render
# `Camera().ortho_scale` (and also FOV FTR) maps to the maximum of either image width or image height— This is the box that gets shown from camera view with the checkbox `.show_sensor = True`.
orthographic.xmag = blender_camera.ortho_scale * (scene_x / scene_square) / 2
orthographic.ymag = blender_camera.ortho_scale * (scene_y / scene_square) / 2
orthographic.znear = blender_camera.clip_start
orthographic.zfar = blender_camera.clip_end
@ -79,9 +87,11 @@ def __gather_perspective(blender_camera, export_settings):
znear=None
)
width = bpy.context.scene.render.pixel_aspect_x * bpy.context.scene.render.resolution_x
height = bpy.context.scene.render.pixel_aspect_y * bpy.context.scene.render.resolution_y
_render = bpy.context.scene.render
width = _render.pixel_aspect_x * _render.resolution_x
height = _render.pixel_aspect_y * _render.resolution_y
perspective.aspect_ratio = width / height
del _render
if width >= height:
if blender_camera.sensor_fit != 'VERTICAL':

View File

@ -28,7 +28,7 @@ class BlenderCamera():
if pycamera.type == "orthographic":
cam.type = "ORTHO"
# TODO: xmag/ymag
cam.ortho_scale = max(pycamera.orthographic.xmag, pycamera.orthographic.ymag) * 2
cam.clip_start = pycamera.orthographic.znear
cam.clip_end = pycamera.orthographic.zfar