Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black is the new white? #727

Closed
benlaurie opened this issue Oct 5, 2024 · 6 comments
Closed

Black is the new white? #727

benlaurie opened this issue Oct 5, 2024 · 6 comments

Comments

@benlaurie
Copy link

Pure white objects display as black, at least on my Mac!

from build123d import Axis, Compound, Cone, Location, MM, Plane, Vector, extrude, add
from ocp_vscode import show

THICKNESS = 2 * MM

CONE_HEIGHT = 3 * MM
CONE_FLAT = 2 * MM
CONE_BASE = 6 * MM  # radius
CONE_TOP = 12 * MM  # radius

def cone(where: Vector, direction: Vector) -> Compound:
    rot = Location(Plane(where + direction.normalized() * (CONE_HEIGHT / 2 - THICKNESS / 2), z_dir=direction))
    c = Cone(CONE_BASE, CONE_TOP, CONE_HEIGHT, rotation=rot)
    print(c.show_topology())
    f = c.faces().sort_by(Axis(where, direction))[-1]
    f = extrude(f, THICKNESS)
    c += f
    return c, f


c1, f1 = cone(Vector(1, 1, 0), Vector(1, 1, 1))
c1.color = (1, 1, 1)
f1.color = (.99, .99, .99)
show(c1, f1)

Apologies for the slightly elaborate example, it was code I had to hand. c1 displays black and f1 white.

@gumyr
Copy link
Owner

gumyr commented Oct 6, 2024

This is actually a bug in ocp_vscode. When c1.color = (1,1,1) is executed a tuple is assigned to the color attribute which should be of class Color. The viewer accepts a tuple and does conversion to a color (black) as shown here:
image

However, the correct way to assign a color in build123d is: c1.color = Color(1, 1, 1) which results in:
image

Should build123d raise a warning that the user isn't using color correctly if an object of type Color isn't assigned to color?

@benlaurie
Copy link
Author

If I use Color, everything renders as white...

@benlaurie
Copy link
Author

Ah - apparently that's what happens if you do Color(tuple) - you have to do Color(*tuple).

It might be helpful to issue a warning if that's not too painful.

@benlaurie
Copy link
Author

benlaurie commented Oct 6, 2024

Or just turn it into a Color automatically?

@bernhard-42
Copy link
Collaborator

In ocp_vscode the internal Color class imported from ocp-tessellate differentiates between int and float:
(1.0, 1.0, 1.0) is white because rgb floats work on the 0.0 to 1.0 scale.
(1,1,1) is nearly black, because rgb ints work on the 0 to 255 scale.

The build123d Color class treats them as the same.

If you just use the tuples, the internal Color class is used.

@gumyr
Copy link
Owner

gumyr commented Oct 7, 2024

Ah - apparently that's what happens if you do Color(tuple) - you have to do Color(*tuple).

It might be helpful to issue a warning if that's not too painful.

I've added a tuple as a valid input to the Color class.

@gumyr gumyr closed this as completed Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants