Skip to content

Commit

Permalink
Merge pull request #441 from howetuft/dev
Browse files Browse the repository at this point in the history
A2P + Default Camera
  • Loading branch information
howetuft authored Aug 21, 2024
2 parents c0a17d7 + 8352f5d commit a745841
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 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
13 changes: 8 additions & 5 deletions Render/renderables.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,16 @@ def open_subdoc(*args):
os.path.basename(org_path),
)
)
# Remove before copying
debug(
"Object",
name,
f"A2P - Copying texture '{org_path}' -> '{dst_path}'",
)
# Copy to main doc transient dir (NB: replace if exists)
try:
os.remove(dst_path)
except FileNotFoundError:
shutil.copyfile(org_path, dst_path)
except shutil.SameFileError:
pass
# Copy to main doc transient dir
shutil.copyfile(org_path, dst_path)

debug("Object", name, f"A2P - Leaving '{subdoc.Name}'")
return [r for r in rends if r.mesh.count_facets]
Expand Down

0 comments on commit a745841

Please sign in to comment.