Skip to content

Commit

Permalink
Merge pull request #101 from Wakoma/generic_rendering
Browse files Browse the repository at this point in the history
Generic Rendering
  • Loading branch information
jmwright authored Nov 7, 2024
2 parents b8cb743 + 2aab495 commit c334972
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 336 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ jobs:
./generate_static.py
- name: Generate example docs
run: |
cadorchestrator generate '["NUC10i5FNH", "Raspberry_Pi_4B", "Raspberry_Pi_4B"]'
uses: coactions/setup-xvfb@v1
with:
run: cadorchestrator --headless generate "[\"NUC10i5FNH\", \"Raspberry_Pi_4B\", \"Raspberry_Pi_4B\"]"

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand Down
16 changes: 11 additions & 5 deletions mechanical/assembly_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from nimble_build_system.cad.shelf import create_shelf_for

assembly_definition_file = "../build/assembly-def.yaml"

render_destination = os.path.join(os.getcwd(), "renders")

class PartDefinition:
"""
Expand Down Expand Up @@ -70,15 +70,21 @@ def generate(self) -> cq.Assembly:
"""
Generate the assembly.
"""
# Make sure that the render destination exists
os.makedirs(render_destination, exist_ok=True)

assembly = cq.Assembly()
for part in self._parts:
if part.device:
# This is a shelf and we load it directly rather than from an STEP.
shelf_obj = create_shelf_for(part.device)
cq_part = shelf_obj.generate_assembly_model()
# generate all render pngs for this shelf
# commented out as this doesnt work yet
# self_obj.generate_renders()

# Create the shelf that will go in the assembly
cq_part = shelf_obj.generate_assembly_model(
shelf_obj.renders["assembled"]["render_options"])

# Generate all render pngs for this shelf
shelf_obj.generate_renders(base_path=render_destination)
else:
cq_part = cq.importers.importStep(part.step_file)
for tag in part.tags:
Expand Down
33 changes: 33 additions & 0 deletions nimble_build_system/cad/renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pylint: disable=too-few-public-methods
#pylint: disable=unused-import

import cadquery as cq
import cadquery_png_plugin.plugin # This activates the PNG plugin for CadQuery
from cq_annotate.callouts import add_assembly_lines

def generate_render(model=None, image_format="png", file_path=None, render_options=None):
"""
Generates a render of an assembly.
parameters:
model (cadquery.Assembly): The assembly to render
image_format (str): The format of the image to render (png, svg, gltf, etc)
file_path (str): The path to save the rendered image to
render_options (dict): A dictionary of options to pass to the render function for
things like which view to render,etc
returns:
None
"""

# Check to see if we are dealing with a single part or an assembly
if isinstance(model, cq.Assembly):
# Handle assembly annotation
if render_options["annotate"]:
add_assembly_lines(model)

# Handle the varioius image formats separately
if image_format == "png":
model.exportPNG(options=render_options, file_path=file_path)
else:
print("Unknown image format")
Loading

0 comments on commit c334972

Please sign in to comment.