Skip to content

Commit d542cfd

Browse files
Added tests for materials
1 parent 36308a6 commit d542cfd

File tree

6 files changed

+615
-18
lines changed

6 files changed

+615
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ out1.3mf
3838
out2.3mf
3939
out3.3mf
4040
orig.dxf
41+
box.brep
42+
sketch.dxf
43+
material_test*

cadquery/occ_impl/assembly.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@ def toVTKAssy(
398398
actor.GetProperty().SetMetallic(element.material.pbr.metallic)
399399
actor.GetProperty().SetRoughness(element.material.pbr.roughness)
400400
actor.GetProperty().SetBaseIOR(element.material.pbr.refraction_index)
401-
if element.material.pbr.emissive_factor:
402-
actor.GetProperty().SetEmissiveFactor(
403-
*element.material.pbr.emissive_factor.rgb()
404-
)
401+
actor.GetProperty().SetEmissiveFactor(
402+
*element.material.pbr.emissive_factor.rgb()
403+
)
405404

406405
rv.AddPart(actor)
407406

@@ -475,10 +474,9 @@ def toVTK(
475474
actor.GetProperty().SetMetallic(element.material.pbr.metallic)
476475
actor.GetProperty().SetRoughness(element.material.pbr.roughness)
477476
actor.GetProperty().SetBaseIOR(element.material.pbr.refraction_index)
478-
if element.material.pbr.emissive_factor:
479-
actor.GetProperty().SetEmissiveFactor(
480-
*element.material.pbr.emissive_factor.rgb()
481-
)
477+
actor.GetProperty().SetEmissiveFactor(
478+
*element.material.pbr.emissive_factor.rgb()
479+
)
482480

483481
renderer.AddActor(actor)
484482

@@ -531,10 +529,9 @@ def toJSON(
531529
"roughness": element.material.pbr.roughness,
532530
"refraction_index": element.material.pbr.refraction_index,
533531
}
534-
if element.material.pbr.emissive_factor:
535-
val["material"]["pbr"][
536-
"emissive_factor"
537-
] = element.material.pbr.emissive_factor.rgba()
532+
val["material"]["pbr"][
533+
"emissive_factor"
534+
] = element.material.pbr.emissive_factor.rgba()
538535

539536
rv.append(val)
540537

cadquery/occ_impl/exporters/assembly.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
)
4141
from ..geom import Location
4242
from ..shapes import Shape, Compound
43-
from ..assembly import Color
4443

4544

4645
class ExportModes:

examples/Ex027_Materials.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@
6969
assy.add(cube.translate((30, 0, 0)), name="glass_cube", material=glass_material)
7070
assy.add(cube.translate((45, 0, 0)), name="gold_cube", material=gold_material)
7171

72-
# Export as OBJ and GLTF to showcase materials
73-
assy.export("materials.step") # STEP format
74-
exportStepMeta(assy, "materials_meta.step") # STEP format with metadata
75-
assy.export("materials.glb") # GLTF format (binary) with PBR materials
72+
# Different formats support different material properties:
73+
# - STEP: Only supports colors and basic material properties like density
74+
# - OBJ: Supports common materials (ambient, diffuse, specular etc.)
75+
# - GLTF: Full support for PBR materials
76+
#
77+
# The best representation can be achieved with gltf:
78+
# assy.export("materials.glb")
7679

7780
# Show the assembly in the UI
7881
show_object(assy)

tests/test_assembly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
exportVTKJS,
1717
exportVRML,
1818
)
19-
from cadquery.occ_impl.assembly import toJSON, toCAF, toFusedCAF, color_to_occt
19+
from cadquery.occ_impl.assembly import toJSON, toCAF, toFusedCAF
2020
from cadquery.occ_impl.shapes import Face, box, cone
2121

2222
from OCP.gp import gp_XYZ

0 commit comments

Comments
 (0)