Skip to content

Commit 8352f5d

Browse files
committed
Camera: enhance find default camera
1 parent eb89b79 commit 8352f5d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Render/project.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def render(self, wait_for_completion=False, skip_meshing=False):
474474

475475
# Build a default camera, to be used if no camera is present in the
476476
# scene
477-
defaultcam = _get_default_cam(renderer, self.fpo)
477+
defaultcam = self._get_default_cam(renderer)
478478

479479
# Get objects rendering strings (including lights, cameras...)
480480
objstrings = self._get_objstrings(renderer)
@@ -659,26 +659,27 @@ def _get_rendering_params(self):
659659

660660
return Params(prefix, output, width, height, batch, spp, denoise)
661661

662+
def _get_default_cam(self, renderer):
663+
"""Build a default camera for rendering.
662664
663-
def _get_default_cam(renderer, project):
664-
"""Build a default camera for rendering.
665-
666-
This function is a (private) subroutine of `render` method.
667-
If GUI is up, the default camera is built from the ActiveView camera, ie
668-
the camera from which objects are seen in FreeCAD viewport. Otherwise
669-
(console mode), the camera is built from a hardcoded value, hosted in
670-
DEFAULT_CAMERA_STRING constant.
671-
"""
672-
camstr = (
673-
Gui.ActiveDocument.ActiveView.getCamera()
674-
if App.GuiUp
675-
else DEFAULT_CAMERA_STRING
676-
)
677-
try:
678-
camsource = get_cam_from_coin_string(camstr)
679-
except ValueError:
680-
camsource = get_cam_from_coin_string(DEFAULT_CAMERA_STRING)
681-
return renderer.get_camsource_string(camsource, project)
665+
This function is a (private) subroutine of `render` method.
666+
If GUI is up, the default camera is built from the ActiveView camera, ie
667+
the camera from which objects are seen in FreeCAD viewport. Otherwise
668+
(console mode), the camera is built from a hardcoded value, hosted in
669+
DEFAULT_CAMERA_STRING constant.
670+
"""
671+
project = self.fpo
672+
docname = project.Document.Name
673+
if App.GuiUp:
674+
App.setActiveDocument(docname)
675+
camstr = Gui.ActiveDocument.ActiveView.getCamera()
676+
else:
677+
camstr = DEFAULT_CAMERA_STRING
678+
try:
679+
camsource = get_cam_from_coin_string(camstr)
680+
except ValueError:
681+
camsource = get_cam_from_coin_string(DEFAULT_CAMERA_STRING)
682+
return renderer.get_camsource_string(camsource, project)
682683

683684

684685
def _instantiate_template(template, objstrings, defaultcam):

0 commit comments

Comments
 (0)