dcowden / cadquery

CadQuery-- a parametric cad script framework
Other
431 stars 56 forks source link

add Color property for solid objects #105

Closed easyw closed 5 years ago

easyw commented 8 years ago

It would be useful to add Color property for solid objects and keep color for all functions (e.g. union cut etc.) thanks

hyOzd commented 8 years ago

I was going to create an issue for "exporting STEP with colors". Since I know we are both here for the same thing I thought I would just add this here : ) Yeah we want to export colorfuls STEPs from cadquery.

jmwright commented 8 years ago

@easyw and @hyOzd - Thanks for the ideas. The CadQuery module for FreeCAD allows you to specify the color and transparency for an object when it's rendered. However, it sounds like you are both saying that you want the color to be embedded as an intrensic part of a solid. My thinking is that the color property would only matter when exporting the solid (STLs/STEPs with color), or displaying it (in FreeCAD). Are these the only use cases you both see for it?

On the surface this doesn't sound too bad, but operations that result in multiple solids (split), or operations on compound solids might get a little interesting. I'd need to research it a bit.

hyOzd commented 8 years ago

Let me correct; I myself only care for colors when exporting or displaying. But it would be nice to be able to fuse parts, and conserve the colors of different faces. Like freecad does;

freecad_fuse

I know this has some limitations. For example refine shape operation of FreeCAD can merge different colored faces;

freecad_fuse2

But I think such glitches should be expected. User can avoid them by carefully designing the part, cutting before fusing for example;

after_cutfuse

easyw commented 8 years ago

@jmwright and @hyOzd we are using cadquery to generate a parametric lib of ICs models for kicad... may be you could also consider to merge hyOzd fork that seems to have some enhancement... https://github.com/hyOzd/cadquery thank you Maurice

hyOzd commented 8 years ago

@easyw Sorry for confusion. I guess you have seen some of my earlier notes somewhere : ) My repository is already merged to upstream. You should be able to run my scripts with the latest version of cadquery.

dcowden commented 8 years ago

Stl doesn't support color, at least in a standard way. Amf and step do. On Aug 8, 2015 11:23 PM, "Jeremy Wright" notifications@github.com wrote:

@easyw https://github.com/easyw and @hyOzd https://github.com/hyOzd - Thanks for the ideas. The CadQuery module for FreeCAD allows you to specify the color and transparency for an object when it's rendered. However, it sounds like you are both saying that you want the color to be embedded as an intrensic part of a solid. My thinking is that the color property would only matter when exporting the solid (STLs/STEPs with color), or displaying it (in FreeCAD). Are these the only use cases you both see for it?

On the surface this doesn't sound too bad, but operations that result in multiple solids (split), or operations on compound solids might get a little interesting. I'd need to research it a bit.

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-129100145.

easyw commented 8 years ago

@dcowden also vrml does support color...

@hyOzd thanks ... you are right ... it does work with cadquery-freecad-module 0.1.8 :)

dcowden commented 8 years ago

is vrml a commonly needed export?

One of CQ's missions has always been to make it easier to create models that are higher quality and more re-usable than the current world-- STEP supports this goal directly. I'd favor adding color to STEP first for this reason.

On Sun, Aug 9, 2015 at 1:13 PM, easyw notifications@github.com wrote:

@dcowden https://github.com/dcowden also vrml does support color...

@hyOzd https://github.com/hyOzd thanks ... you are right ... it does work with cadquery-freecad-module 0.1.8 :)

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-129217808.

easyw commented 8 years ago

@dcowden me and @hyOzd are doing a repository for kicad, generating 3D parametric models kicad would need vrml models for its internal 3d-viewer, and STEP AP214 models for MCAD exchanges FC can export in VRML with colors, so STEP with colors would be the first and maybe the only needed target. For the moment I've done some python libs/functions to manage the objects generated by hyOzd script, to export STEP and VRML models, appropriate to the kicad environment. https://github.com/KiCad/kicad-library/issues/186 thank you for your nice framework Maurice

dcowden commented 8 years ago

that's awesome! i'm glad to hear its helpful!

On Sun, Aug 9, 2015 at 4:22 PM, easyw notifications@github.com wrote:

@dcowden https://github.com/dcowden me and @hyOzd https://github.com/hyOzd are doing a repository for kicad, generating 3D parametric models kicad would need vrml models for its internal 3d-viewer, and STEP AP214 models for MCAD exchanges FC can export in VRML with colors, so STEP with colors would be the first and maybe the only needed target. For the moment I've done some python libs/functions to manage the objects generated by hyOzd script, to export STEP and VRML models, appropriate to the kicad environment. KiCad/kicad-library#186 https://github.com/KiCad/kicad-library/issues/186 thank you for your nice framework Maurice

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-129234542.

hyOzd commented 8 years ago

I have created an X3D exporter for freecad objects which I used in my generator scripts. It's here. As you can see it's rather primitive, but it works. VRML and X3D are very similar specifications. Actually X3D is the standard replacing VRML. I have already spent some time in the specification documentation. So I can lend a hand for VRML/X3D export if you are interested.

By the way I agree with @dcowden. I would love to see colorful STEP export first.

hyOzd commented 8 years ago

Here is a snippet I've created to export a simple cadquery object to STEP (with color), using FreeCADs GUI module (inspired by @easyw's export scripts). Thought you would be interested.

Note that this looks too much like a hack. I'm creating all the GUI of FreeCAD hidden. And I'm not calling the main event loop, which is required for a qt application to perform. This works now, but may not work in the future. I wouldn't count on such implementation. I wouldn't put this code in cadquery. Maybe as a utility/helper module, until a better option is implemented.

dcowden commented 8 years ago

I see. Why does something like this not work to export step ( much simpler ): (not tested, i only have access to email ATM )

import cadquery as cq

box = cq.Workplane("XY").box(10,10,10) box.exportStep( box , fileName)

This method uses the underlying freecad implementation. For more control, you can use something like this:

from cadquery import exporters exporters.exportShape(box, ExportTypes.STEP, fileLikeObject, 0.1 )

the source is here: https://github.com/dcowden/cadquery/blob/master/cadquery/freecad_impl/exporters.py:

​it contains code to export to SVG, STEP, AMF, and STL. ( as per other discussions, i think FreeCAD's implementation of STL export should be replaced with our own so we can control the tolerance of the tessellation.

looking at it, i think the code in Shape should always delegate to the exporters routines-- that way the user can control the tessellation and other stuff.

On Tue, Aug 11, 2015 at 1:45 AM, Hasan Yavuz ÖZDERYA < notifications@github.com> wrote:

Here https://gist.github.com/hyOzd/0d75fc98cccfae92a641 is a snippet I've created to export a simple cadquery object to STEP (with color), using FreeCADs GUI module (inspired by @easyw https://github.com/easyw's export scripts). Thought you would be interested.

Note that this looks too much like a hack. I'm creating all the GUI of FreeCAD hidden. And I'm not calling the main event loop, which is required for a qt application to perform. This works now, but may not work in the future. I wouldn't count on such implementation. I wouldn't put this code in cadquery. Maybe as a utility/helper module, until a better option is implemented.

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-129712425.

hyOzd commented 8 years ago

AFAIK STEP exported this way -Shape.exportStep()- won't have color.

My example was very simple. It's possible to color different faces of shape to a different color this way. That requires access to ViewObject attribute which is not provided by FreeCAD module but FreeCADGui module.

dcowden commented 8 years ago

ah i see-- your sample creates color ok, gotcha.

On Tue, Aug 11, 2015 at 7:35 AM, Hasan Yavuz ÖZDERYA < notifications@github.com> wrote:

AFAIK STEP exported this way -Shape.exportStep()- won't have color.

My example was very simple. It's possible to color different faces of shape to a different color this way. That requires access to ViewObject attribute which is not provided by FreeCAD module but FreeCADGui module.

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-129846465.

jmwright commented 8 years ago

@hyOzd @easyw and @dcowden - I'm not ignoring these conversations, I've just had almost no time for CadQuery this week. I will likely tackle issue #85 first, and then circle back to this. I do see it being a challenge though because of the FreeCAD View boiler plate code that @hyOzd mentioned. We'll have to figure out a way to get around having to do that.

Please keep in mind that I'm also trying to round out our test suite (and fixing the bugs that brings to light) to set us up to take even more great contributions from the community. I'm spread pretty thin, so it could be awhile before I can get to this.

dcowden commented 8 years ago

no problem, thanks for weighing in!

On Wed, Aug 12, 2015 at 10:48 PM, Jeremy Wright notifications@github.com wrote:

@hyOzd https://github.com/hyOzd @easyw https://github.com/easyw and @dcowden https://github.com/dcowden - I'm not ignoring these conversations, I've just had almost no time for CadQuery this week. I will likely tackle issue #85 https://github.com/dcowden/cadquery/issues/85 first, and then circle back to this. I do see it being a challenge though because of the FreeCAD View boiler plate code that @hyOzd https://github.com/hyOzd mentioned. We'll have to figure out a way to get around having to do that.

Please keep in mind that I'm also trying to round out our test suite (and fixing the bugs that brings to light) to set us up to take even more great contributions from the community. I'm spread pretty thin, so it could be awhile before I can get to this.

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/105#issuecomment-130512068.

iromero91 commented 5 years ago

Is there a chance this could sneak into the CQ 2.0 cycle? It would be really nice to incorporate CQ into Kicad without having freecad in the middle...

jmwright commented 5 years ago

@iromero91 It's hard to say. It depends on the resources available, and everybody is pretty busy right now. Maybe once we get past the summer the team can re-evaluate where we're at and the resources we have.

+1 on incorporating CQ into KiCAD without FreeCAD in the mix.

adam-urbanczyk commented 5 years ago

@iromero91 what is the exact use case? Would it be something like:

1) define individual shapes and their materials/colors, 2) assembly into a compound solid, 3) export to e.g. STEP?

Or is it something more involved with colors per face within individual solids?

iromero91 commented 5 years ago

As described above, to generate models that have multiple colors (representing multiple materials) for use in kicad pcb assemblies, as Kicad can read step files natively now. And yes for simplicity we can assume it is a compound of single color solids, at most you could make a fuse operation preserve the face colors.

adam-urbanczyk commented 5 years ago

OK clear. I'd rather focus on the solid only case (i.e. without fuse op).

BTW: there might be some useful info on adding attributes to subshapes here: https://www.opencascade.com/content/shape-integer-attribute-using-ocaf

dcowden commented 5 years ago

This has been closed in favor of the CQ 2.0 implemention at https://github.com/cadquery/cadquery