Skip to content

Commit f2e22bc

Browse files
Added tests for materials
1 parent 4967786 commit f2e22bc

File tree

5 files changed

+615
-17
lines changed

5 files changed

+615
-17
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
@@ -404,10 +404,9 @@ def toVTKAssy(
404404
actor.GetProperty().SetMetallic(element.material.pbr.metallic)
405405
actor.GetProperty().SetRoughness(element.material.pbr.roughness)
406406
actor.GetProperty().SetBaseIOR(element.material.pbr.refraction_index)
407-
if element.material.pbr.emissive_factor:
408-
actor.GetProperty().SetEmissiveFactor(
409-
*element.material.pbr.emissive_factor.rgb()
410-
)
407+
actor.GetProperty().SetEmissiveFactor(
408+
*element.material.pbr.emissive_factor.rgb()
409+
)
411410

412411
rv.AddPart(actor)
413412

@@ -481,10 +480,9 @@ def toVTK(
481480
actor.GetProperty().SetMetallic(element.material.pbr.metallic)
482481
actor.GetProperty().SetRoughness(element.material.pbr.roughness)
483482
actor.GetProperty().SetBaseIOR(element.material.pbr.refraction_index)
484-
if element.material.pbr.emissive_factor:
485-
actor.GetProperty().SetEmissiveFactor(
486-
*element.material.pbr.emissive_factor.rgb()
487-
)
483+
actor.GetProperty().SetEmissiveFactor(
484+
*element.material.pbr.emissive_factor.rgb()
485+
)
488486

489487
renderer.AddActor(actor)
490488

@@ -537,10 +535,9 @@ def toJSON(
537535
"roughness": element.material.pbr.roughness,
538536
"refraction_index": element.material.pbr.refraction_index,
539537
}
540-
if element.material.pbr.emissive_factor:
541-
val["material"]["pbr"][
542-
"emissive_factor"
543-
] = element.material.pbr.emissive_factor.rgba()
538+
val["material"]["pbr"][
539+
"emissive_factor"
540+
] = element.material.pbr.emissive_factor.rgba()
544541

545542
rv.append(val)
546543

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)