[Bf-extensions-cvs] [8a244384] master: glTF importer/exporter: fix ortho camera fram import/export
Julien Duroure
noreply at git.blender.org
Fri Oct 21 18:50:28 CEST 2022
Commit: 8a2443844daf7bd32b3aafac53370966f2d330f4
Author: Julien Duroure
Date: Fri Oct 21 18:45:23 2022 +0200
Branches: master
https://developer.blender.org/rBA8a2443844daf7bd32b3aafac53370966f2d330f4
glTF importer/exporter: fix ortho camera fram import/export
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
M io_scene_gltf2/blender/imp/gltf2_blender_camera.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index d06b8b08..2c61a9ed 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -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',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
index cee3cb06..d169db34 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
@@ -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':
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
index 6a580e03..9ee78946 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
@@ -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
More information about the Bf-extensions-cvs
mailing list