tuned import 3d mesh

This commit is contained in:
Mario Voigt 2021-05-11 19:45:41 +02:00
parent 1a255addad
commit 3b4aa4405c
2 changed files with 64 additions and 56 deletions

View File

@ -5,10 +5,10 @@
<param name="tab" type="notebook"> <param name="tab" type="notebook">
<page name="common" gui-text="Model file"> <page name="common" gui-text="Model file">
<param name="input_choice" type="optiongroup" appearance="combo" gui-text="Input choice"> <param name="input_choice" type="optiongroup" appearance="combo" gui-text="Input choice">
<option value="default">Default object</option> <option value="default">Available default object</option>
<option value="custom">Custom input file</option> <option value="custom">Custom input file</option>
</param> </param>
<param name="obj" type="optiongroup" appearance="combo" gui-text="Objects"> <param name="obj" type="optiongroup" appearance="combo" gui-text="Available default objects">
<option value="cube">Cube</option> <option value="cube">Cube</option>
<option value="trunc_cube">Truncated Cube</option> <option value="trunc_cube">Truncated Cube</option>
<option value="snub_cube">Snub Cube</option> <option value="snub_cube">Snub Cube</option>
@ -25,74 +25,86 @@
<option value="snub_dodec">Snub Dodecahedron</option> <option value="snub_dodec">Snub Dodecahedron</option>
<option value="great_dodec">Great Dodecahedron</option> <option value="great_dodec">Great Dodecahedron</option>
<option value="great_stel_dodec">Great Stellated Dodecahedron</option> <option value="great_stel_dodec">Great Stellated Dodecahedron</option>
</param> </param>
<param name="spec_file" type="path" gui-text="Custom Input File" filetypes="obj,off,ply,stl" mode="file">great_rhombicuboct.obj</param> <param name="spec_file" type="path" gui-text="Custom input file" filetypes="obj,off,ply,stl" mode="file">/your/object/file.stl</param>
<param name="type" type="optiongroup" appearance="combo" gui-text="Object Type:"> <param name="type" type="optiongroup" appearance="combo" gui-text="Object Type:">
<option value="face">Face-Specified</option> <option value="face">Face-Specified</option>
<option value="edge">Edge-Specified</option></param> <option value="edge">Edge-Specified</option>
<param name="cw_wound" type="bool" gui-text="Clockwise wound object">false</param> </param>
</page> <param name="cw_wound" type="bool" gui-text="Clockwise wound object">false</param>
<page name="view" gui-text="View"> <param name="scl" type="float" min="0" max="10000" gui-text="Scaling factor:">100</param>
</page>
<page name="view" gui-text="View">
<param name="r1_ax" type="optiongroup" appearance="combo" gui-text="Rotate around:"> <param name="r1_ax" type="optiongroup" appearance="combo" gui-text="Rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r1_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r1_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
<param name="r2_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:"> <param name="r2_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r2_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r2_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
<param name="r3_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:"> <param name="r3_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r3_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r3_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
<param name="r4_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:"> <param name="r4_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r4_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r4_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
<param name="r5_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:"> <param name="r5_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r5_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r5_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
<param name="r6_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:"> <param name="r6_ax" type="optiongroup" appearance="combo" gui-text="Then rotate around:">
<option value="x">X-Axis</option> <option value="x">X-Axis</option>
<option value="y">Y-Axis</option> <option value="y">Y-Axis</option>
<option value="z">Z-Axis</option></param> <option value="z">Z-Axis</option>
<param name="r6_ang" type="float" min="-360" max="360" gui-text="Rotation (deg):">0</param> </param>
<param name="r6_ang" type="float" min="-360" max="360" appearance="full" gui-text="Rotation (deg):">0</param>
</page> </page>
<page name="style" gui-text="Style"> <page name="style" gui-text="Style">
<param name="scl" type="float" min="0" max="10000" gui-text="Scaling factor:">100</param> <hbox>
<param name="f_r" type="int" min="0" max="255" gui-text="Fill color, Red:">255</param> <vbox>
<param name="f_g" type="int" min="0" max="255" gui-text="Fill color, Green:">0</param> <param name="fill_color" type="color" gui-text="Fill color">1943148287</param>
<param name="f_b" type="int" min="0" max="255" gui-text="Fill color, Blue:">0</param> </vbox>
<param name="f_opac" type="int" min="0" max="100" gui-text="Fill opacity (%):">100</param> <separator/>
<param name="s_opac" type="int" min="0" max="100" gui-text="Stroke opacity (%):">100</param> <vbox>
<param name="th" type="float" min="0" max="100" gui-text="Stroke width (px):">2</param> <param name="s_opac" type="int" min="0" max="100" appearance="full" gui-text="Stroke opacity (%):">100</param>
<param name="shade" type="bool" gui-text="Shading">true</param> <param name="th" type="float" min="0" max="100" gui-text="Stroke width (px):">2</param>
<param name="lv_x" type="float" min="-100" max="100" gui-text="Light X:">1</param> <param name="shade" type="bool" gui-text="Shading" gui-description="Only works for 'Faces' in 'Show' option">true</param>
<param name="lv_y" type="float" min="-100" max="100" gui-text="Light Y:">1</param> <param name="lv_x" type="float" min="-100" max="100" appearance="full" gui-text="Light X:">1</param>
<param name="lv_z" type="float" min="-100" max="100" gui-text="Light Z:">-2</param> <param name="lv_y" type="float" min="-100" max="100" appearance="full" gui-text="Light Y:">1</param>
<param name="show" type="optiongroup" appearance="combo" gui-text="Show:"> <param name="lv_z" type="float" min="-100" max="100" appearance="full" gui-text="Light Z:">-2</param>
<option value="fce">Faces</option> <param name="show" type="optiongroup" appearance="combo" gui-text="Show:">
<option value="edg">Edges</option> <option value="fce">Faces</option>
<option value="vtx">Vertices</option> <option value="edg">Edges</option>
</param> <option value="vtx">Vertices</option>
<param name="back" type="bool" gui-text="Draw back-facing polygons">false</param> </param>
<param name="z_sort" type="optiongroup" appearance="combo" gui-text="Z-sort faces by:"> <param name="back" type="bool" gui-text="Draw back-facing polygons" gui-description="Only works for 'Faces' in 'Show' option and enabled 'Shading' option">false</param>
<option value="max">Maximum</option> <param name="z_sort" type="optiongroup" appearance="combo" gui-text="Z-sort faces by:">
<option value="min">Minimum</option> <option value="max">Maximum</option>
<option value="cent">Centroid</option></param> <option value="min">Minimum</option>
<option value="cent">Centroid</option>
</param>
</vbox>
</hbox>
</page> </page>
</param> </param>
<effect> <effect>
<object-type>all</object-type> <object-type>all</object-type>
<effects-menu> <effects-menu>
<submenu name="FabLab Chemnitz"> <submenu name="FabLab Chemnitz">
<submenu name="Import/Export/Transfer"/> <submenu name="Import/Export/Transfer" />
</submenu> </submenu>
</effects-menu> </effects-menu>
</effect> </effect>

View File

@ -51,15 +51,15 @@ Many settings for appearance, lighting, rotation, etc are available.
import os import os
from math import acos, cos, floor, pi, sin, sqrt from math import acos, cos, floor, pi, sin, sqrt
import inkex
from inkex.utils import pairwise
from inkex import Group, Circle
from inkex.paths import Move, Line
import numpy import numpy
import tempfile import tempfile
import openmesh as om import openmesh as om
import inkex
from inkex import Group, Circle, Color
from inkex.utils import pairwise
from inkex.paths import Move, Line
def draw_circle(r, cx, cy, width, fill, name, parent): def draw_circle(r, cx, cy, width, fill, name, parent):
"""Draw an SVG circle""" """Draw an SVG circle"""
@ -78,7 +78,7 @@ def draw_line(x1, y1, x2, y2, width, name, parent):
def draw_poly(pts, face, st, name, parent): def draw_poly(pts, face, st, name, parent):
"""Draw polygone""" """Draw polygone"""
style = {'stroke': '#000000', 'stroke-width': str(st.th), 'stroke-linejoin': st.linejoin, style = {'stroke': '#000000', 'stroke-width': str(st.th), 'stroke-linejoin': st.linejoin,
'stroke-opacity': st.s_opac, 'fill': st.fill, 'fill-opacity': st.f_opac} 'stroke-opacity': st.s_opac, 'fill': st.fill, 'fill-opacity': st.fill_opacity}
path = inkex.Path() path = inkex.Path()
for facet in face: for facet in face:
if not path: # for first point if not path: # for first point
@ -168,8 +168,8 @@ class Style(object): # container for style information
self.fill = '#ff0000' self.fill = '#ff0000'
self.col = '#000000' self.col = '#000000'
self.r = 2 self.r = 2
self.f_opac = str(options.f_opac / 100.0)
self.s_opac = str(options.s_opac / 100.0) self.s_opac = str(options.s_opac / 100.0)
self.fill_opacity = options.fill_color.alpha
self.linecap = 'round' self.linecap = 'round'
self.linejoin = 'round' self.linejoin = 'round'
@ -275,10 +275,7 @@ class Poly3D(inkex.GenerateExtension):
# STYLE SETTINGS # STYLE SETTINGS
pars.add_argument("--show", type=self.arg_method('gen')) pars.add_argument("--show", type=self.arg_method('gen'))
pars.add_argument("--shade", type=inkex.Boolean, default=True) pars.add_argument("--shade", type=inkex.Boolean, default=True)
pars.add_argument("--f_r", type=int, default=255) pars.add_argument("--fill_color", type=Color, default='1943148287', help="Fill color")
pars.add_argument("--f_g", type=int, default=0)
pars.add_argument("--f_b", type=int, default=0)
pars.add_argument("--f_opac", type=int, default=100)
pars.add_argument("--s_opac", type=int, default=100) pars.add_argument("--s_opac", type=int, default=100)
pars.add_argument("--th", type=float, default=2) pars.add_argument("--th", type=float, default=2)
pars.add_argument("--lv_x", type=float, default=1) pars.add_argument("--lv_x", type=float, default=1)
@ -347,7 +344,6 @@ class Poly3D(inkex.GenerateExtension):
"""Generate face""" """Generate face"""
so = self.options so = self.options
# colour tuple for the face fill # colour tuple for the face fill
fill_col = (so.f_r, so.f_g, so.f_b)
# unit light vector # unit light vector
lighting = normalise((so.lv_x, -so.lv_y, so.lv_z)) lighting = normalise((so.lv_x, -so.lv_y, so.lv_z))
# we have a face list # we have a face list
@ -368,7 +364,7 @@ class Poly3D(inkex.GenerateExtension):
z_list.append((z_sort_param, angle, norm, i)) z_list.append((z_sort_param, angle, norm, i))
z_list.sort(key=lambda x: x[0]) # sort by ascending sort parameter of the face z_list.sort(key=lambda x: x[0]) # sort by ascending sort parameter of the face
draw_faces(z_list, transformed_pts, obj, so.shade, fill_col, st, poly) draw_faces(z_list, transformed_pts, obj, so.shade, self.options.fill_color, st, poly)
else: # we cannot generate a list of faces from the edges without a lot of computation else: # we cannot generate a list of faces from the edges without a lot of computation
raise inkex.AbortExtension("Face data not found.") raise inkex.AbortExtension("Face data not found.")