Skip to content

Add materials to assemblies #1620

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

Open
adrianschneider94 opened this issue Jul 1, 2024 · 11 comments
Open

Add materials to assemblies #1620

adrianschneider94 opened this issue Jul 1, 2024 · 11 comments
Labels
enhancement New feature or request OCC feature Requires coding at OCC implementation level

Comments

@adrianschneider94
Copy link

As far as I can see, it's only possible to add colors so far.
That could be extended to handling materials by using XCAFDoc_Material for physical properties and XCAFDoc_VisMaterial for visualization.

I implemented a first working approach:
https://github.com/sangl-spezialtransformatoren/cadquery/tree/materials

The syntax is at the moment:

part = create_some_part()
assembly = Assembly()

copper = Material(
    name="Copper",
    base_color=Color(0.955, 0.637, 0.538, 1),
    density=8.9,
    metalness=1,
    roughness=0.1,
)

assembly.add(part, material=copper)

I wanted to use this issue as a discussion entrypoint, a pull request could follow later.

Links to OCCT documentation:

@adrianschneider94 adrianschneider94 added enhancement New feature or request OCC feature Requires coding at OCC implementation level labels Jul 1, 2024
@adam-urbanczyk
Copy link
Member

This would be interesting. What is your main use case?

@adrianschneider94
Copy link
Author

One is mass calculation, where the density is necessary. The other is, that you can export with the visualization settings, for example you can visualize metal nicely with gltf.

@Jopie01
Copy link

Jopie01 commented Jul 3, 2024

I'm also interested in this. Maybe it's also possible to add textures? My main case is that I'm creating a structure and want to create an (rendered, would it be possible?) image of it to be added to a printed document. Also the 3D model is exported for visualization in a viewer.

@lenianiva
Copy link
Contributor

This would be very useful for calculating load!

@adrianschneider94
Copy link
Author

adrianschneider94 commented Jul 4, 2024

@Jopie01 Textures should be possible, XCAFDoc_VisMaterialPBR has fields for that, but I don't know yet how those work.

@adam-urbanczyk
Copy link
Member

Alright, let's give it a try @adrianschneider94 ! I did take a look at your branch and AFAICT you did some reformatting/reordering of imports. I will kindly ask to revert this. Our README contains instructions regarding which black version to use. Please do not apply other formatting fixes.

Regarding the PR I see the following tasks. First two are MVP, the rest would be nice to have but can ba via other PRs.

  • Add the vocabulary type cq.Material
  • Update Assembly API
  • Update toCAF to write VisMaterial and Material
  • STEP export (?)
  • (de)serialization via pickle (?)

@adrianschneider94
Copy link
Author

adrianschneider94 commented Jul 4, 2024

Yes, so far I have not set up everything, just got everything working for my project.

Some points:

  1. I adapted the approach to keep all data in OCP objects using 'wrapped' attributes. But as for example XCAFDoc_VisMaterial.PbrMaterial() won't return a ref but a copy of the struct, I now think it's easier to define a python class holding the material properties and then apply them in toCAF(). What do you think about that?

  2. Exporting STEP and GLTF works out of the box (the other formats too I guess), but as far as I know, STEP does not have material properties, it will just take the base color as color.

  3. Regarding serialization: Is there already some approach in the library to serialization yet? I haven't seen it yet and even started to write own wrappers using pydantic. Would be great if that's already implemented.

@adam-urbanczyk
Copy link
Member

[I updated your comment with numbers to be able to refert to the points]

[I updated your comment with numbers to be able to refer to the points]

Alright, here are my answers

  1. I did no analyze in detail, but that approach sounds OK too
  2. Indeed GLTF should work via CAF regarding vis props. IDK about material props. STEP does not support vis props other than color, but maybe we could encode material props in some way
  3. Only serialization to CAF is there. No deserialization ATM. For unrelated reasons I want to (finally!) work on pickling. It should solve it.

Long story short, I’d propose to keep the scope small and for now “just” implement materials up to the CAF part.

@pddees
Copy link

pddees commented Mar 20, 2025

Has there been any movement on this? I'd also like to use this feature for loads, and generating geometries with nice textures

@adrianschneider94
Copy link
Author

Not yet, but I have this on my task list for the comming weeks.

@adrianschneider94
Copy link
Author

I created a pull request #1815.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OCC feature Requires coding at OCC implementation level
Projects
None yet
Development

No branches or pull requests

5 participants