[Render_3D] Separated the crop and transparent options

This commit is contained in:
Salvador E. Tropea 2022-11-01 13:36:05 -03:00
parent 3400dcca70
commit 06f5fc12f4
6 changed files with 41 additions and 28 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- New output:
- `populate` to create step-by-step assembly instructions
With support for `pcbdraw` and `render_3d`.
- generic filters: options to filter by PCB side
- Diff:
- Option to compare only the first schematic page. (See #319)
@ -29,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Render_3D:
- Option to render only some components (like in PcbDraw)
- Option to auto-crop the resulting PNG
- Option to make transparent the background
- Option to highlight components
- SVG:
- Option to control the *SVG precision* (units scale)

View File

@ -3093,10 +3093,8 @@ Notes:
- **`view`**: [string='top'] [top,bottom,front,rear,right,left,z,Z,y,Y,x,X] Point of view.
- **`zoom`**: [number=0] Zoom steps. Use positive to enlarge, get closer, and negative to reduce.
Same result as using the mouse wheel in the 3D viewer.
- `auto_crop`: [boolean=false] When enabled the image will be post-processed to make the background transparent and then remove the
empty space around the image. In this mode the `background1` and `background2` colors are ignored.
- `auto_crop_color`: [string='#ff70b7'] Color used for the chroma key. Adjust it if some regions of the board becomes transparent.
- `auto_crop_fuzz`: [number=15] [0,100] Chroma key tolerance (percent). Bigger values will remove more pixels.
- `auto_crop`: [boolean=false] When enabled the image will be post-processed to remove the empty space around the image.
In this mode the `background2` is changed to be the same as `background1`.
- `background1`: [string='#66667F'] First color for the background gradient.
- `background2`: [string='#CCCCE5'] Second color for the background gradient.
- `board`: [string='#332B16'] Color for the board without copper or solder mask.
@ -3122,6 +3120,10 @@ Notes:
- `solder_mask`: [string='#208b47'] Color for the solder mask.
- `solder_paste`: [string='#808080'] Color for the solder paste.
- `subtract_mask_from_silk`: [boolean=true] Clip silkscreen at solder mask edges (KiCad 6).
- `transparent_background`: [boolean=false] When enabled the image will be post-processed to make the background transparent.
In this mode the `background1` and `background2` colors are ignored.
- `transparent_background_color`: [string='#00ff00'] Color used for the chroma key. Adjust it if some regions of the board becomes transparent.
- `transparent_background_fuzz`: [number=15] [0,100] Chroma key tolerance (percent). Bigger values will remove more pixels.
- `variant`: [string=''] Board variant to apply.
- *wait_ray_tracing*: Alias for wait_render.
- `wait_render`: [number=-600] How many seconds we must wait before capturing the render (ray tracing or normal).

View File

@ -1829,13 +1829,9 @@ outputs:
type: 'render_3d'
dir: 'Example/render_3d_dir'
options:
# [boolean=false] When enabled the image will be post-processed to make the background transparent and then remove the
# empty space around the image. In this mode the `background1` and `background2` colors are ignored
# [boolean=false] When enabled the image will be post-processed to remove the empty space around the image.
# In this mode the `background2` is changed to be the same as `background1`
auto_crop: false
# [string='#ff70b7'] Color used for the chroma key. Adjust it if some regions of the board becomes transparent
auto_crop_color: '#ff70b7'
# [number=15] [0,100] Chroma key tolerance (percent). Bigger values will remove more pixels
auto_crop_fuzz: 15
# [string='#66667F'] First color for the background gradient
background1: '#66667F'
# [string='#CCCCE5'] Second color for the background gradient
@ -1910,6 +1906,13 @@ outputs:
solder_paste: '#808080'
# [boolean=true] Clip silkscreen at solder mask edges (KiCad 6)
subtract_mask_from_silk: true
# [boolean=false] When enabled the image will be post-processed to make the background transparent.
# In this mode the `background1` and `background2` colors are ignored
transparent_background: false
# [string='#00ff00'] Color used for the chroma key. Adjust it if some regions of the board becomes transparent
transparent_background_color: '#00ff00'
# [number=15] [0,100] Chroma key tolerance (percent). Bigger values will remove more pixels
transparent_background_fuzz: 15
# [string=''] Board variant to apply
variant: ''
# [string='top'] [top,bottom,front,rear,right,left,z,Z,y,Y,x,X] Point of view

View File

@ -38,7 +38,7 @@ Shape {
material DEF RED-01 Material {
ambientIntensity 0.494
diffuseColor 1.0 0.0 0.0
specularColor 0.047 0.055 0.109
specularColor 0.5 0.0 0.0
emissiveColor 0.0 0.0 0.0
transparency 0.5
shininess 0.25

View File

@ -131,11 +131,14 @@ class Render3DOptions(Base3DOptions):
self.highlight_on_top = False
""" Highlight over the component (not under) """
self.auto_crop = False
""" When enabled the image will be post-processed to make the background transparent and then remove the
empty space around the image. In this mode the `background1` and `background2` colors are ignored """
self.auto_crop_color = "#ff70b7"
""" When enabled the image will be post-processed to remove the empty space around the image.
In this mode the `background2` is changed to be the same as `background1` """
self.transparent_background = False
""" When enabled the image will be post-processed to make the background transparent.
In this mode the `background1` and `background2` colors are ignored """
self.transparent_background_color = "#00ff00"
""" Color used for the chroma key. Adjust it if some regions of the board becomes transparent """
self.auto_crop_fuzz = 15
self.transparent_background_fuzz = 15
""" [0,100] Chroma key tolerance (percent). Bigger values will remove more pixels """
super().__init__()
self._expand_ext = 'png'
@ -178,7 +181,7 @@ class Render3DOptions(Base3DOptions):
self.copper = "#"+color
break
super().config(parent)
self.validate_colors(list(self._colors.keys())+['auto_crop_color'])
self.validate_colors(list(self._colors.keys())+['transparent_background_color'])
view = self._views.get(self.view, None)
if view is not None:
self.view = view
@ -279,8 +282,13 @@ class Render3DOptions(Base3DOptions):
"Please upgrade KiCad to 6.0.2 or newer")
exit(MISSING_TOOL)
command = self.ensure_tool('KiAuto')
if self.auto_crop:
self.background1 = self.background2 = self.auto_crop_color
if self.transparent_background:
# Use the chroma key color
self.background1 = self.background2 = self.transparent_background_color
convert_command = self.ensure_tool('ImageMagick')
elif self.auto_crop:
# Avoid a gradient
self.background2 = self.background1
convert_command = self.ensure_tool('ImageMagick')
# Base command with overwrite
cmd = [command, '--rec_w', str(self.width+2), '--rec_h', str(self.height+85),
@ -308,11 +316,10 @@ class Render3DOptions(Base3DOptions):
if os.path.isfile(video_name):
os.remove(video_name)
if self.auto_crop:
_run_command([convert_command, output, '-fuzz', str(self.auto_crop_fuzz)+'%', '-transparent',
self.color_str_to_rgb(self.auto_crop_color), output])
# Don't ask me why I need 2 passes
_run_command([convert_command, output, '-trim', '+repage', output])
_run_command([convert_command, output, '-trim', '+repage', output])
_run_command([convert_command, output, '-trim', '+repage', '-trim', '+repage', output])
if self.transparent_background:
_run_command([convert_command, output, '-fuzz', str(self.transparent_background_fuzz)+'%', '-transparent',
self.color_str_to_rgb(self.transparent_background_color), output])
@output_class

View File

@ -55,12 +55,11 @@ outputs:
orthographic: true
zoom: 4
ray_tracing: true
# DAF1FF
background1: "#DAF1FF"
background2: "#DAF1FF"
# auto_crop: true
# auto_crop_color: "#00FF00"
# auto_crop_fuzz: 15
auto_crop: true
# transparent_background: true
# transparent_background_color: "#00FF00"
# transparent_background_fuzz: 15
- name: Populate