You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/assy.rst
+126-1Lines changed: 126 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -879,7 +879,131 @@ Where:
879
879
show_object(assy)
880
880
881
881
882
-
Assembly colors
882
+
Materials
883
+
----------------
884
+
885
+
Materials can be assigned to objects in an assembly to define their visual
886
+
and physical properties. CadQuery supports three types of material representations:
887
+
888
+
1. Simple Color Material
889
+
2. PBR (Physically Based Rendering) Material - the modern standard for material definition
890
+
3. Common (Legacy) Material - legacy material representation in OCCT
891
+
892
+
A material can have multiple representations defined simultaneously - color,
893
+
common, and PBR properties can all be specified for the same material.
894
+
The appropriate representation will be used based on the export format.
895
+
This allows you to define a material once and have it work well across
896
+
different export formats. For example:
897
+
898
+
.. code-block:: python
899
+
900
+
# Material with all three representations
901
+
gold_material = cq.Material(
902
+
name="Gold",
903
+
description="A golden material with multiple representations",
904
+
density=19300, # kg/m³
905
+
# Simple color for basic visualization
906
+
color=cq.Color(1.0, 0.8, 0.0, 1.0),
907
+
# PBR material for modern physically-based rendering
908
+
pbr=cq.PbrMaterial(
909
+
base_color=cq.Color(1.0, 0.8, 0.0, 1.0),
910
+
metallic=1.0,
911
+
roughness=0.2,
912
+
refraction_index=1.0,
913
+
),
914
+
# Legacy common material for backward compatibility
915
+
common=cq.CommonMaterial(
916
+
ambient_color=cq.Color(0.2, 0.2, 0.0, 1.0),
917
+
diffuse_color=cq.Color(0.8, 0.8, 0.0, 1.0),
918
+
specular_color=cq.Color(1.0, 1.0, 0.0, 1.0),
919
+
emissive_color=cq.Color(0.0, 0.0, 0.0, 1.0),
920
+
shininess=0.9,
921
+
transparency=0.0,
922
+
),
923
+
)
924
+
925
+
When this material is exported:
926
+
927
+
- STEP files will use the simple color representation
928
+
- GLTF/GLB files will use the PBR properties
929
+
930
+
Material Types
931
+
=============
932
+
933
+
Simple Color Material
934
+
~~~~~~~~~~~~~~~~~~~
935
+
936
+
The simplest form of material definition includes just a name,
937
+
description, density, and color:
938
+
939
+
.. code-block:: python
940
+
941
+
material = cq.Material(
942
+
name="Red Plastic",
943
+
description="A simple red plastic material",
944
+
density=1200, # kg/m³
945
+
color=cq.Color(1.0, 0.0, 0.0, 1.0), # Red with full opacity
946
+
)
947
+
948
+
PBR Material
949
+
~~~~~~~~~~~
950
+
951
+
PBR (Physically Based Rendering) materials provide physically accurate material representation and are the recommended way to define materials in CadQuery:
952
+
953
+
.. code-block:: python
954
+
955
+
material = cq.Material(
956
+
name="Clear Glass",
957
+
description="A transparent glass material",
958
+
density=2500, # kg/m³
959
+
pbr=cq.PbrMaterial(
960
+
base_color=cq.Color(0.9, 0.9, 0.9, 0.3), # Base color with transparency
961
+
metallic=0.0, # 0.0 for non-metals, 1.0 for metals
962
+
roughness=0.1, # 0.0 for smooth, 1.0 for rough
963
+
refraction_index=1.5, # Must be between 1.0 and 3.0
0 commit comments