Skip to content

Commit

Permalink
Camera: enhance find default camera
Browse files Browse the repository at this point in the history
  • Loading branch information
howetuft committed Aug 21, 2024
1 parent eb89b79 commit 8352f5d
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions Render/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def render(self, wait_for_completion=False, skip_meshing=False):

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

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

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

def _get_default_cam(self, renderer):
"""Build a default camera for rendering.
def _get_default_cam(renderer, project):
"""Build a default camera for rendering.
This function is a (private) subroutine of `render` method.
If GUI is up, the default camera is built from the ActiveView camera, ie
the camera from which objects are seen in FreeCAD viewport. Otherwise
(console mode), the camera is built from a hardcoded value, hosted in
DEFAULT_CAMERA_STRING constant.
"""
camstr = (
Gui.ActiveDocument.ActiveView.getCamera()
if App.GuiUp
else DEFAULT_CAMERA_STRING
)
try:
camsource = get_cam_from_coin_string(camstr)
except ValueError:
camsource = get_cam_from_coin_string(DEFAULT_CAMERA_STRING)
return renderer.get_camsource_string(camsource, project)
This function is a (private) subroutine of `render` method.
If GUI is up, the default camera is built from the ActiveView camera, ie
the camera from which objects are seen in FreeCAD viewport. Otherwise
(console mode), the camera is built from a hardcoded value, hosted in
DEFAULT_CAMERA_STRING constant.
"""
project = self.fpo
docname = project.Document.Name
if App.GuiUp:
App.setActiveDocument(docname)
camstr = Gui.ActiveDocument.ActiveView.getCamera()
else:
camstr = DEFAULT_CAMERA_STRING
try:
camsource = get_cam_from_coin_string(camstr)
except ValueError:
camsource = get_cam_from_coin_string(DEFAULT_CAMERA_STRING)
return renderer.get_camsource_string(camsource, project)


def _instantiate_template(template, objstrings, defaultcam):
Expand Down

0 comments on commit 8352f5d

Please sign in to comment.