diff --git a/docs/reference/primitives.rst b/docs/reference/primitives.rst index d7baae54..4196c5f5 100644 --- a/docs/reference/primitives.rst +++ b/docs/reference/primitives.rst @@ -36,7 +36,7 @@ Specification priority order: 1. Optional argument ``resolution`` passed to ``primitive.mesh()`` or to ``web()`` or ``wire()`` 2. Optional attribute ``resolution`` of the primitive object - 3. Value of ``settings.primitives['curve_resolution']`` at bake time. + 3. Value of ``settings.resolution`` at bake time. Specification format: @@ -75,8 +75,8 @@ Primitives types .. autoproperty:: direction .. image:: /screenshots/primitives-segment.png - -.. autoclass:: ArcCentered + +.. autoclass:: Circle .. autoproperty:: center @@ -86,9 +86,9 @@ Primitives types .. automethod:: tangent - .. image:: /screenshots/primitives-arccentered.png + .. image:: /screenshots/primitives-circle.png -.. autoclass:: ArcThrough +.. autoclass:: ArcCentered .. autoproperty:: center @@ -98,9 +98,9 @@ Primitives types .. automethod:: tangent - .. image:: /screenshots/primitives-arcthrough.png - -.. autoclass:: Circle + .. image:: /screenshots/primitives-arccentered.png + +.. autoclass:: ArcThrough .. autoproperty:: center @@ -110,7 +110,7 @@ Primitives types .. automethod:: tangent - .. image:: /screenshots/primitives-circle.png + .. image:: /screenshots/primitives-arcthrough.png .. autoclass:: ArcTangent @@ -124,6 +124,12 @@ Primitives types .. image:: /screenshots/primitives-arctangent.png +.. autoclass:: Ellipsis + + .. autoproperty:: axis + + .. image:: /screenshots/primitives-ellipsis.png + .. autoclass:: TangentEllipsis .. autoproperty:: center diff --git a/examples/birfield.py b/examples/birfield.py index 9aa7749d..d02876e0 100644 --- a/examples/birfield.py +++ b/examples/birfield.py @@ -1,5 +1,5 @@ from madcad import * -settings.primitives['curve_resolution'] = ('rad', 0.2) +settings.resolution = ('rad', 0.2) nballs = 6 rball = 6/2 diff --git a/examples/compound-planetary.py b/examples/compound-planetary.py index b4c781d6..62ba9e14 100644 --- a/examples/compound-planetary.py +++ b/examples/compound-planetary.py @@ -42,8 +42,8 @@ def spurgear(step, teeth, height, **kwargs): color_gear = vec3(0.2, 0.3, 0.4) -#settings.primitives['curve_resolution'] = ('sqradm', 0.4) -settings.primitives['curve_resolution'] = ('sqradm', 0.8) +#settings.resolution = ('sqradm', 0.4) +settings.resolution = ('sqradm', 0.8) ## determine teeth number targeting the desired ratio #target = 1/160 diff --git a/examples/differential-asymetric.py b/examples/differential-asymetric.py index 3b076c5c..ee2a406f 100644 --- a/examples/differential-asymetric.py +++ b/examples/differential-asymetric.py @@ -38,7 +38,7 @@ def bolt(a, b, dscrew, washera=False, washerb=False): -settings.primitives['curve_resolution'] = ('sqradm', 0.5) +settings.resolution = ('sqradm', 0.5) transmiter_angle = pi/6 transmiter_z = 8 diff --git a/examples/differential-symetric.py b/examples/differential-symetric.py index 059118a7..1292e014 100644 --- a/examples/differential-symetric.py +++ b/examples/differential-symetric.py @@ -31,9 +31,9 @@ def bolt(a, b, dscrew, washera=False, washerb=False): ) # the discretisation paremeter can be set high for exportation, or small for quick computations -#settings.primitives['curve_resolution'] = ('rad', 0.105) -#settings.primitives['curve_resolution'] = ('rad', 0.19456) -settings.primitives['curve_resolution'] = ('sqradm', 0.5) +#settings.resolution = ('rad', 0.105) +#settings.resolution = ('rad', 0.19456) +settings.resolution = ('sqradm', 0.5) # parameters of the mechanism to design transmiter_angle = pi/6 diff --git a/examples/double-universal-joint.py b/examples/double-universal-joint.py index afc9f384..8011b616 100644 --- a/examples/double-universal-joint.py +++ b/examples/double-universal-joint.py @@ -1,7 +1,7 @@ from madcad import * from madcad.joints import * from itertools import accumulate -settings.primitives['curve_resolution'] = ('rad', 0.1) +settings.resolution = ('rad', 0.1) # profile separating the bottom and top part allowing them to move around each other and using the maximum volume for the part robustness def cardan_sphereprofile(maxangle=0.5): diff --git a/examples/elliptic-gearbox.py b/examples/elliptic-gearbox.py index cdc99a59..b481cd1a 100644 --- a/examples/elliptic-gearbox.py +++ b/examples/elliptic-gearbox.py @@ -3,9 +3,9 @@ from madcad.joints import * from functools import reduce import operator -#settings.primitives['curve_resolution'] = ('rad', 0.2) -#settings.primitives['curve_resolution'] = ('sqradm', 0.2) -settings.primitives['curve_resolution'] = ('sqradm', 0.8) +#settings.resolution = ('rad', 0.2) +#settings.resolution = ('sqradm', 0.2) +settings.resolution = ('sqradm', 0.8) def ellipsis_perimeter(a, b): return Circle(Axis(O,Z), a).mesh(resolution=('div', 128)).transform(scaledir(X, b/a)).length() diff --git a/examples/universal-joint.py b/examples/universal-joint.py index 1f0a2807..2c1afc27 100644 --- a/examples/universal-joint.py +++ b/examples/universal-joint.py @@ -1,7 +1,7 @@ from madcad import * from madcad.joints import * from itertools import accumulate -settings.primitives['curve_resolution'] = ('rad', 0.1) +settings.resolution = ('rad', 0.1) # profile separating the bottom and top part allowing them to move around each other and using the maximum volume for the part robustness def cardan_sphereprofile(maxangle=0.5): diff --git a/madcad/displays.py b/madcad/displays.py index 7bdfecee..47f3a812 100644 --- a/madcad/displays.py +++ b/madcad/displays.py @@ -32,7 +32,7 @@ def __init__(self, scene, position, size=10, color=None): self.position = fvec3(position) self.size = size self.selected = False - self.color = fvec3(color or settings.display['line_color']) + self.color = fvec3(color or settings.colors['line']) def load(scene): img = Image.open(resourcedir+'/textures/point.png') @@ -98,7 +98,7 @@ def __init__(self, scene, axis, interval=None, color=None, pose=fmat4(1)): self.origin = fvec3(axis[0]) self.direction = fvec3(axis[1]) self.interval = interval - self.color = fvec3(color or settings.display['line_color']) + self.color = fvec3(color or settings.colors['line']) self.selected = False self.box = Box(center=self.origin, width=fvec3(0)) @@ -162,7 +162,7 @@ def npboundingbox(points): class AnnotationDisplay(Display): def __init__(self, scene, points, color): - self.color = fvec3(color or settings.display['annotation_color']) + self.color = fvec3(color or settings.color['annotation']) self.selected = False self.box = npboundingbox(points) # load shader @@ -248,12 +248,11 @@ def __init__(self, scene, positions, normals, faces, lines, idents, color=None): self.box = npboundingbox(positions) self.options = scene.options - s = settings.display - color = fvec3(color or s['solid_color']) - line = ( (length(s['line_color']) + dot(color-s['solid_color'], s['line_color']-s['solid_color'])) + color = fvec3(color or settings.colors['surface']) + line = ( (length(settings.colors['line']) + dot(color-settings.colors['surface'], settings.colors['line']-settings.colors['surface'])) * normalize(color + 1e-6) ) #if length(s['line_color']) > length(color) - reflect = normalize(color + 1e-6) * s['solid_reflectivity'] + reflect = normalize(color + 1e-6) * settings.display['solid_reflectivity'] self.vertices = Vertices(scene.ctx, positions, idents) self.disp_faces = FacesDisplay(scene, self.vertices, normals, faces, color=color, reflect=reflect, layer=0) @@ -300,7 +299,7 @@ class WebDisplay(Display): def __init__(self, scene, positions, lines, points, idents, color=None): self.box = npboundingbox(positions) self.options = scene.options - color = color or settings.display['line_color'] + color = color or settings.colors['line'] self.vertices = Vertices(scene.ctx, positions, idents) self.disp_edges = LinesDisplay(scene, self.vertices, lines, color=color, alpha=1, layer=-2e-6) self.disp_groups = PointsDisplay(scene, self.vertices, points, layer=-3e-6) @@ -556,7 +555,7 @@ def identify(self, view): class PointsDisplay: def __init__(self, scene, vertices, indices=None, color=None, ptsize=3, layer=0): - self.color = fvec4(color or settings.display['point_color'], 1) + self.color = fvec4(color or settings.colors['point'], 1) self.select_color = fvec4(settings.display['select_color_line'], 1) self.ptsize = ptsize self.layer = layer @@ -643,7 +642,7 @@ def load(scene): self.shader, self.va = scene.resource('viewgrid', load) self.unit = unit self.center = fvec3(center or 0) - self.color = fvec4(color) if color else fvec4(settings.display['point_color'],1) + self.color = fvec4(color) if color else fvec4(settings.colors['point'],1) self.contrast = contrast def render(self, view): @@ -670,8 +669,8 @@ def stack(self, scene): class SplineDisplay(Display): ''' display for spline curve, with handles around''' def __init__(self, scene, handles, curve, color=None): - self.color = color or fvec4(settings.display['line_color'], 1) - self.color_handles = fvec4(settings.display['annotation_color'], 0.6) + self.color = color or fvec4(settings.colors['line'], 1) + self.color_handles = fvec4(settings.color['annotation'], 0.6) self.box = npboundingbox(handles) ctx = scene.ctx self.vb_handles = ctx.buffer(handles) diff --git a/madcad/gear.py b/madcad/gear.py index 5d886a77..39d07098 100644 --- a/madcad/gear.py +++ b/madcad/gear.py @@ -53,8 +53,6 @@ -color_gear = vec3(0.2, 0.3, 0.4) - def rackprofile(step, height=None, offset=0, asymetry=None, alpha=radians(20), resolution=None) -> Wire: ''' Generate a 1-period tooth profile for a rack @@ -848,7 +846,7 @@ def samecircle(c1, c2): mesh = exterior + top + bottom + hub else: mesh = exterior + top + structure + bottom + hub - return mesh.finish() + return mesh.finish() .option(color=settings.colors['gear']) @cachefunc def gear( @@ -1328,7 +1326,7 @@ def straight_bevel_gear( t_max = acos(cos(gamma_f) / cos_b) / sin_b middle_tooth = 0.5 * (involute(t_max, 0) + involute(-t_max, phase_diff)) phase = anglebt(X, middle_tooth * v) - return all_teeth.transform(angleAxis(-phase, Z)) + return all_teeth.transform(angleAxis(-phase, Z)) .option(color=settings.colors['gear']) def helical_bevel_gear( step:float, @@ -1487,7 +1485,7 @@ def get_body_points(rho, z, angle): involute = lambda t, t0: spherical_involute(gamma_b, t0, t) t_max = acos(cos(gamma_f) / cos_b) / sin_b middle_tooth = 0.5 * (involute(t_max, 0) + involute(-t_max, phase_diff)) - return all_teeth.transform(quat(X, middle_tooth * v)) + return all_teeth.transform(quat(X, middle_tooth * v)) .option(color=settings.colors['gear']) def _get_intersection(A: vec3, B: vec3, C: vec3, D: vec3) -> float: """ @@ -1530,7 +1528,7 @@ def _get_intersection(A: vec3, B: vec3, C: vec3, D: vec3) -> float: def matrix4placement(z:int, shaft_angle:float) -> mat4x4: """ Return a matrix of transformation given initial state (Z is the initial axis of revolution). - This matrix is helpful when you want to place filet gears. + This matrix is helpful when you want to place bevel gears. Parameters: diff --git a/madcad/kinematic/displays.py b/madcad/kinematic/displays.py index 3c971841..1200849a 100644 --- a/madcad/kinematic/displays.py +++ b/madcad/kinematic/displays.py @@ -583,7 +583,7 @@ def __call__(self, view): def kinematic_toolcenter(toolcenter): ''' create a scheme for drawing the toolcenter in kinematic manipulation ''' - color = settings.display['annotation_color'] + color = settings.colors['annotation'] angle = 2 radius = 60 size = 3 @@ -635,10 +635,10 @@ def kinematic_scheme(joints) -> '(Scheme, index)': return scheme, {v: k for k, v in index.items()} -kinematic_color_names = ['annotation_color', 'schematics_color'] +kinematic_color_names = ['annotation', 'schematic'] def kinematic_color(i): ''' return the scheme color vector for solid `i` in a kinematic ''' - return fvec4(settings.display[kinematic_color_names[i%2]], 1) + return fvec4(settings.colors[kinematic_color_names[i%2]], 1) diff --git a/madcad/primitives.py b/madcad/primitives.py index 86f8c8ac..05cbe90f 100644 --- a/madcad/primitives.py +++ b/madcad/primitives.py @@ -27,7 +27,7 @@ def fit(self) -> err**2 as float: 1. Optional argument `resolution` passed to `primitive.mesh()` or to `web()` or `wire()` 2. Optional attribute `resolution` of the primitive object - 3. Value of `settings.primitives['curve_resolution']` at bake time. + 3. Value of `settings.resolution` at bake time. Specification format: @@ -55,13 +55,16 @@ def isprimitive(obj): ''' Return True if obj match the signature for primitives ''' return hasattr(obj, 'mesh') and hasattr(obj, 'slvvars') +# aliases, for those who like them Vector = Point = vec3 class Axis(object): ''' Mimic the behavior of a tuple, but with the primitive signature. ''' __slots__ = ('origin', 'direction', 'interval') - def __init__(self, origin, direction, interval=None): + def __init__(self, origin, direction=None, interval=None): + if direction is None: + origin, direction = vec3(0), origin self.origin, self.direction = origin, direction self.interval = interval diff --git a/madcad/scheme.py b/madcad/scheme.py index fa50e032..33e1246a 100644 --- a/madcad/scheme.py +++ b/madcad/scheme.py @@ -86,7 +86,7 @@ def __init__(self, vertices=None, spaces=None, primitives=None, **kwargs): self.primitives = primitives or {} # list of indices for each shader self.components = [] # displayables associated to spaces # for creation: last vertex inserted - self.current = {'color':fvec4(settings.display['annotation_color'],1), 'flags':0, 'layer':0, 'space':world, 'shader':'line', 'track':0, 'normal':fvec3(0)} + self.current = {'color':fvec4(settings.colors['annotation'],1), 'flags':0, 'layer':0, 'space':world, 'shader':'line', 'track':0, 'normal':fvec3(0)} self.continuous = False self.set(**kwargs) @@ -558,7 +558,7 @@ def mesh_placement(mesh) -> '(pos,normal)': def note_floating(position, text, align=(0,0)): ''' place a floating note at given position ''' - return Displayable(TextDisplay, position, text, align=align, color=settings.display['annotation_color'], size=settings.display['view_font_size']) + return Displayable(TextDisplay, position, text, align=align, color=settings.colors['annotation'], size=settings.display['view_font_size']) def note_leading(placement, offset=None, text='here'): @@ -574,7 +574,7 @@ def note_leading(placement, offset=None, text='here'): elif not isinstance(offset, vec3): raise TypeError('offset must be scalar or vector') - color = settings.display['annotation_color'] + color = settings.colors['annotation'] sch = Scheme(color=fvec4(color,0.7)) sch.add([origin, origin+offset], shader='line', space=world) x,y,z = dirbase(normalize(vec3(offset))) @@ -607,7 +607,7 @@ def note_distance(a, b, offset=0, project=None, d=None, tol=None, text=None, sid elif tol: text = '{d:.4g} ± {tol}' else: text = '{d:.4g}' text = text.format(d=d, tol=tol) - color = settings.display['annotation_color'] + color = settings.colors['annotation'] # convert input vectors x = dirbase(project, b-a)[0] z = project if side else -project @@ -699,7 +699,7 @@ def note_angle(a0, a1, offset=0, d=None, tol=None, text=None, unit='deg', side=F elif tol: text = '{d:.4g}{unit} ± {tol}' else: text = '{d:.4g}{unit}' text = text.format(d=d, tol=tol, unit=unit) - color = settings.display['annotation_color'] + color = settings.colors['annotation'] # arc center if o1 == o0: center = o0 else: center = o0 + unproject(project(o1-o0, x1), d0) @@ -766,7 +766,7 @@ def note_radius(mesh, offset=None, d=None, tol=None, text=None, propagate=2): arrowplace = place + noproject(offset, normal) note = note_leading((arrowplace,normal), offset=project(offset, normal), text=text or 'R {:.4g}'.format(radius)) - color = settings.display['annotation_color'] + color = settings.colors['annotation'] note.set(shader='line', layer=1e-4, color=fvec4(color,0.3), space=world) note.add([place, arrowplace]) return note @@ -1039,7 +1039,7 @@ def note_label(placement, offset=None, text='!', style='rect'): elif not isinstance(offset, vec3): raise TypeError('offset must be scalar or vector') - color = settings.display['annotation_color'] + color = settings.colors['annotation'] x,_,z = dirbase(normalize(offset)) sch = Scheme() sch.set(color=fvec4(color,0.7)) @@ -1081,7 +1081,7 @@ def note_iso(p, offset, type, text, refs=(), label=None): #scheme = None #def __init__(self, scene, matrix, color=None): - #if not color: color = settings.display['annotation_color'] + #if not color: color = settings.colors['annotation'] #if not self.scheme: #type(self).scheme = sch = Scheme(layer=1e-4) @@ -1115,7 +1115,7 @@ def note_iso(p, offset, type, text, refs=(), label=None): #yield from self.disp.stack(scene) def note_base(matrix, color=None, labels=('X', 'Y', 'Z'), name=None, size=0.4): - if not color: color = settings.display['annotation_color'] + if not color: color = settings.colors['annotation'] if not name: name = '' if not labels: labels = [None]*3 @@ -1155,7 +1155,7 @@ def note_base(matrix, color=None, labels=('X', 'Y', 'Z'), name=None, size=0.4): return sch def note_rotation(quaternion, color=None, size=0.4): - if not color: color = settings.display['annotation_color'] + if not color: color = settings.colors['annotation'] direction = vec3(glm.axis(quaternion)) angle = glm.angle(quaternion) diff --git a/madcad/settings.py b/madcad/settings.py index caf5fbba..02b68d17 100644 --- a/madcad/settings.py +++ b/madcad/settings.py @@ -12,9 +12,9 @@ import sys, os, yaml from os.path import dirname, exists - +# settings for all Display objects and for the scene rendering display = { - 'field_of_view': pi/6, + 'field_of_view': pi/6, # camera field of view for scene views 'view_font_size': 8, # font size for annotations 'joint_size': 50, # maximum pixel size of joints 'sharp_angle': pi/6, # above this threshold angles between mesh triangles are considered sharp, below they are rendered softened @@ -24,20 +24,47 @@ 'select_color_line': fvec3(0.5, 1, 0.6), # color for selected lines 'highlight_color': fvec3(0.1, 0.2, 0.2), - 'solid_color': fvec3(0.2, 0.2, 0.2), # surface color of meshes 'solid_color_front': 1., # surface intensity for portions of surface parallel to the view direction 'solid_color_side': 0.2, # surface intensity for portions of surface orthogonal to the view direction 'solid_reflectivity': 4, # intensity of surface reflections 'solid_reflect': 'skybox-white.png', # skybox texture for reflects - 'line_color': fvec3(0.9, 0.9, 0.9), # wire color - 'point_color': fvec3(0.9, 0.9, 0.9), # points color - 'schematics_color': fvec3(0.3, 0.8, 1), 'line_width': 1.0, # pixel width of edges, may work or not depending on openGL implementation - 'annotation_color': fvec3(0.2, 0.7, 1), 'system_theme': True, # adapt madcad colors to the current desktop theme } +# theme colors for objects in the scene +colors = { + # display elements + + # mesh surface + 'surface': fvec3(0.2, 0.2, 0.2), + # mesh and primitives lines + 'line': fvec3(0.9, 0.9, 0.9), + # mesh and primitives points + 'point': fvec3(0.9, 0.9, 0.9), + # annotations like dimensions and constraints + 'annotation': fvec3(0.2, 0.7, 1), + # schematics like kinematic schemes + 'schematic': fvec3(0.3, 0.8, 1), + + # color for standard parts + + # screws and nults + 'bolt': fvec3(0.2), + # gears and transmission parts + 'gear': fvec3(0.2, 0.3, 0.4), + # bearing and guiding parts + 'bearing': fvec3(0.5,0.4,0.35), + 'bearing_cage': fvec3(0.3,0.2,0), + # deformable parts like springs + 'spring': fvec3(0.2), + # circulating elements like balls in bearings + 'circulating': fvec3(0,0.1,0.2), + } + +# initial settings for a scene, each scene will duplicate this and will be able to modify them at runtime +# this dictionnary represent the initial settings of the user scene = { 'projection': 'Perspective', @@ -62,9 +89,8 @@ 'snap_dist': 10, # pixel distance to click items } -primitives = { - 'curve_resolution': ['rad', pi/16], # angle maximal pour discretisation des courbes - } +resolution = ['rad', pi/16] # maximum angle for discretizing curves, see `curve_resolution()` + # get configuration directory depending on OS if sys.platform == 'win32': @@ -75,7 +101,7 @@ configdir = home+'/.config' config = configdir+'/madcad/pymadcad.yaml' -settings = {'display':display, 'scene':scene, 'controls':controls, 'primitives':primitives} +settings = {'display':display, 'scene':scene, 'controls':controls, 'resolution':resolution} def install(): @@ -121,7 +147,7 @@ def curve_resolution(length, angle, param=None): :length: is the curvilign length of the curve :angle: is the integral of the absolute curvature (total rotation angle) ''' - kind, prec = param or primitives['curve_resolution'] + kind, prec = param or resolution if kind == 'div': res = prec elif kind == 'm': @@ -162,11 +188,13 @@ def qtc(role): 'background_color': qtc(palette.Base), 'select_color_face': selection * 0.05, 'select_color_line': selection * 1.1, - 'line_color': qtc(palette.Text), - 'point_color': qtc(palette.Text), - 'solid_color': mix(qtc(palette.Text), qtc(palette.Window), 0.7), - 'schematics_color': mix(qtc(palette.Text)*normalize(qtc(palette.LinkVisited)+0.01), qtc(palette.LinkVisited), 0.5), - 'annotation_color': mix(qtc(palette.Text)*normalize(qtc(palette.Link)+0.01), qtc(palette.Link), 0.5), + }) + colors.update({ + 'line': qtc(palette.Text), + 'point': qtc(palette.Text), + 'surface': mix(qtc(palette.Text), qtc(palette.Window), 0.7), + 'schematic': mix(qtc(palette.Text)*normalize(qtc(palette.LinkVisited)+0.01), qtc(palette.LinkVisited), 0.5), + 'annotation': mix(qtc(palette.Text)*normalize(qtc(palette.Link)+0.01), qtc(palette.Link), 0.5), }) diff --git a/madcad/standard.py b/madcad/standard.py index 1a845b62..161b0039 100644 --- a/madcad/standard.py +++ b/madcad/standard.py @@ -99,8 +99,6 @@ def stceil(x, precision=0.1): # --------- screw stuff ----------------------- -bolt_color = vec3(0.2) - @cachefunc def screw(d, length, filet_length=None, head='SH', drive=None, detail=False): ''' Create a standard screw using the given drive and head shapes @@ -155,7 +153,7 @@ def screw(d, length, filet_length=None, head='SH', drive=None, detail=False): vec3(r*0.8, 0, -length), vec3(0, 0, -length), ]) .segmented()) - screw = (body + head).finish().option(color=bolt_color) + screw = (body + head).finish().option(color=settings.colors['bolt']) return Solid(part=screw, axis=axis) def screwdrive_torx(d): @@ -376,7 +374,7 @@ def hexnut(d, w, h): nut = intersection(base, ext) chamfer(nut, nut.frontiers(4,5) + nut.frontiers(0,5), width=d*0.1) - nut.finish().option(color=bolt_color) + nut.finish().option(color=settings.colors['bolt']) return Solid( part=nut, bottom=Axis(-0.5*h*Z, -Z, interval=(0,h)), @@ -449,7 +447,7 @@ def washer(d, e=None, h=None) -> Mesh: if h is None: h = d*0.1 return Solid( - part=thicken(revolution(web([e/2*X, d/2*X])), h).option(color=bolt_color), + part=thicken(revolution(web([e/2*X, d/2*X])), h).option(color=settings.colors['bolt']), top=Axis(h*Z, Z, interval=(0,h)), bottom=Axis(O, -Z, interval=(0,h)), ) @@ -910,10 +908,6 @@ def bearing_spec(code): elif re.match(r'[\d\.]+x[\d\.]+x[\d\.]+', code): return tuple(float(d) for d in re.split('x')) -bearing_color = vec3(0.5,0.4,0.35) -bearing_cage_color = vec3(0.3,0.2,0) -bearing_circulating_color = vec3(0,0.1,0.2) - def bearing_ball(dint, dext=None, h=None, sealing=False, detail=False) -> Solid: # convenient variables @@ -950,7 +944,7 @@ def bearing_ball(dint, dext=None, h=None, sealing=False, detail=False) -> Solid: exterior += wire(ArcCentered((rb*X,-Y), vec3(rext-e, 0, -hr), vec3(rext-e, 0, hr))) interior.close() exterior.close() - part = revolution(web([exterior, interior]), axis) .option(color=bearing_color) + part = revolution(web([exterior, interior]), axis) .option(color=settings.colors['bearing']) nb = int(0.7 * pi*rb/rr) # number of balls that can fit in balls = repeat(icosphere(rb*X, rr), nb, angleAxis(radians(360)/nb, Z)) .option(color=vec3(0,0.1,0.2)) @@ -973,7 +967,7 @@ def bearing_ball(dint, dext=None, h=None, sealing=False, detail=False) -> Solid: cage = thicken( surf + surf.transform(mat3(1,1,-1)) .flip(), - c) .option(color=bearing_cage_color) + c) .option(color=settings.colors['bearing_cage']) # asemble return Solid(part=part, cage=cage, balls=balls, axis=axis) @@ -995,7 +989,7 @@ def bearing_ball(dint, dext=None, h=None, sealing=False, detail=False) -> Solid: ) return Solid( part=revolution(web([exterior, interior]), axis) - .option(color=bearing_color), + .option(color=settings.colors['bearing']), axis=axis) @@ -1071,7 +1065,7 @@ def bearing_roller(dint, dext=None, h=None, contact=0, hint=None, hext=None, det part = revolution(web([ exterior, interior, - ]).flip(), axis) .option(color=bearing_color) + ]).flip(), axis) .option(color=settings.colors['bearing']) # create conic rollers roller = revolution(Segment(mix(p1,p3,0.05), mix(p3,p1,0.05)), angled) @@ -1083,7 +1077,7 @@ def bearing_roller(dint, dext=None, h=None, contact=0, hint=None, hext=None, det # number of rollers that can fit in nb = int(pi*(rint+rext) / (2.5*distance_pa(p1,angled))) rollers = repeat(roller, nb, rotatearound(2*pi/nb, axis)) - rollers.option(color=bearing_circulating_color) + rollers.option(color=settings.colors['circulating']) # roller cage p6 = mix(p4,p3,0.6) - e*angled[1] @@ -1095,7 +1089,7 @@ def bearing_roller(dint, dext=None, h=None, contact=0, hint=None, hext=None, det filet(cage_profile, [1], radius=c) cage = revolution(cage_profile, axis) cage = pierce(cage, inflate(rollers, 0.5*c), False) - cage = thicken(cage, c) .option(color=bearing_cage_color) + cage = thicken(cage, c) .option(color=settings.colors['bearing_cage']) # assemble return Solid(part=part, cage=cage, rollers=rollers, axis=axis) @@ -1107,7 +1101,7 @@ def bearing_roller(dint, dext=None, h=None, contact=0, hint=None, hext=None, det part=revolution( (exterior + interior) .close() .flip(), axis, - ) .option(color=bearing_color), + ) .option(color=settings.colors['bearing']), axis=axis) @@ -1147,12 +1141,12 @@ def bearing_thrust(dint, dext, h, detail=False) -> Solid: bot += wire(ArcCentered((rb*X,-Y), vec3(rb-hr, 0, -w+e), vec3(rb+hr, 0, -w+e))) top.close() bot.close() - part = revolution(web([top, bot]), axis) .option(color=bearing_color) + part = revolution(web([top, bot]), axis) .option(color=settings.colors['bearing']) # number of balls to place nb = int(0.8 * pi*rb/rr) balls = repeat(icosphere(rb*X, rr), nb, angleAxis(radians(360)/nb, Z)) - balls.option(color=bearing_circulating_color) + balls.option(color=settings.colors['circulating']) # cage cage_profile = Wire([ @@ -1165,7 +1159,7 @@ def bearing_thrust(dint, dext, h, detail=False) -> Solid: cage_surf = revolution(cage_profile, axis) cage_surf = pierce(cage_surf, inflate(balls, 0.2*c), False) - cage = thicken(cage_surf, c) .option(color=bearing_cage_color) + cage = thicken(cage_surf, c) .option(color=settings.colors['bearing_cage']) # assemble return Solid(part=part, cage=cage, balls=balls, axis=axis) @@ -1187,7 +1181,7 @@ def bearing_thrust(dint, dext, h, detail=False) -> Solid: ) return Solid( - part=revolution(web([top, bot]), axis) .option(color=bearing_color), + part=revolution(web([top, bot]), axis) .option(color=settings.colors['bearing']), axis=axis) @@ -1231,7 +1225,7 @@ def slidebearing(dint, h=None, thickness=None, shoulder=None, opened=False) -> S axis = Axis(O,Z, interval=(-h,0)) shape = revolution(profile, axis, 1.98*pi if opened else 2*pi) - part = thicken(shape, thickness) .option(color=bearing_color) + part = thicken(shape, thickness) .option(color=settings.colors['bearing']) line = ( select(part, vec3(-rint,0,-h), stopangle(pi/2)) + select(part, vec3(dint,dint,-h), stopangle(pi/2)) ) diff --git a/tests/test_bevelgear.py b/tests/test_bevelgear.py index 5a9b2fe8..423496ff 100644 --- a/tests/test_bevelgear.py +++ b/tests/test_bevelgear.py @@ -1,10 +1,9 @@ #!/usr/bin/python3 from madcad.gear import * -from madcad.mesh import edgekey, facekeyo from madcad.kinematic import Solid from madcad import settings -settings.primitives['curve_resolution'] = ('rad', 0.1) +settings.resolution = ('rad', 0.1) # Colors class bcolors: diff --git a/tests/test_gear.py b/tests/test_gear.py index 4967725d..dc8a0d36 100644 --- a/tests/test_gear.py +++ b/tests/test_gear.py @@ -1,9 +1,8 @@ from madcad.gear import * -from madcad.mesh import edgekey, facekeyo from madcad.kinematic import Solid import madcad -madcad.settings.primitives['curve_resolution'] = ('rad', 0.1) +madcad.settings.resolution = ('rad', 0.1) # Colors class bcolors: diff --git a/tests/test_gearprofile.py b/tests/test_gearprofile.py index 72c28e5f..c756e95a 100644 --- a/tests/test_gearprofile.py +++ b/tests/test_gearprofile.py @@ -1,7 +1,7 @@ from madcad import * from madcad import gear -settings.primitives['curve_resolution'] = ('rad', 0.05) +settings.resolution = ('rad', 0.05) axis = (vec3(0),vec3(0,0,1))