cadquery
cadquery copied to clipboard
Add materials to assemblies
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:
- https://dev.opencascade.org/doc/refman/html/class_x_c_a_f_doc___material.html
- https://dev.opencascade.org/doc/refman/html/class_x_c_a_f_doc___vis_material.html
This would be interesting. What is your main use case?
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.
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.
This would be very useful for calculating load!
@Jopie01 Textures should be possible, XCAFDoc_VisMaterialPBR has fields for that, but I don't know yet how those work.
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 (?)
Yes, so far I have not set up everything, just got everything working for my project.
Some points:
-
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 intoCAF(). What do you think about that? -
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.
-
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.
[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
- I did no analyze in detail, but that approach sounds OK too
- 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
- 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.
Has there been any movement on this? I'd also like to use this feature for loads, and generating geometries with nice textures
Not yet, but I have this on my task list for the comming weeks.
I created a pull request #1815.