Skip to content

Commit

Permalink
reorganized color settings, they are all in settings.colors now
Browse files Browse the repository at this point in the history
  • Loading branch information
jimy-byerley committed Sep 8, 2024
1 parent d89d327 commit 0344398
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 97 deletions.
24 changes: 15 additions & 9 deletions docs/reference/primitives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -75,8 +75,8 @@ Primitives types
.. autoproperty:: direction

.. image:: /screenshots/primitives-segment.png

.. autoclass:: ArcCentered
.. autoclass:: Circle

.. autoproperty:: center

Expand All @@ -86,9 +86,9 @@ Primitives types

.. automethod:: tangent

.. image:: /screenshots/primitives-arccentered.png
.. image:: /screenshots/primitives-circle.png

.. autoclass:: ArcThrough
.. autoclass:: ArcCentered

.. autoproperty:: center

Expand All @@ -98,9 +98,9 @@ Primitives types

.. automethod:: tangent

.. image:: /screenshots/primitives-arcthrough.png
.. autoclass:: Circle
.. image:: /screenshots/primitives-arccentered.png

.. autoclass:: ArcThrough

.. autoproperty:: center

Expand All @@ -110,7 +110,7 @@ Primitives types

.. automethod:: tangent

.. image:: /screenshots/primitives-circle.png
.. image:: /screenshots/primitives-arcthrough.png

.. autoclass:: ArcTangent

Expand All @@ -124,6 +124,12 @@ Primitives types

.. image:: /screenshots/primitives-arctangent.png

.. autoclass:: Ellipsis

.. autoproperty:: axis

.. image:: /screenshots/primitives-ellipsis.png

.. autoclass:: TangentEllipsis

.. autoproperty:: center
Expand Down
2 changes: 1 addition & 1 deletion examples/birfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from madcad import *
settings.primitives['curve_resolution'] = ('rad', 0.2)
settings.resolution = ('rad', 0.2)

nballs = 6
rball = 6/2
Expand Down
4 changes: 2 additions & 2 deletions examples/compound-planetary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/differential-asymetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/differential-symetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/double-universal-joint.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 3 additions & 3 deletions examples/elliptic-gearbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/universal-joint.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
23 changes: 11 additions & 12 deletions madcad/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions madcad/gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions madcad/kinematic/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)



Expand Down
7 changes: 5 additions & 2 deletions madcad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 0344398

Please sign in to comment.