Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def require_similar_mesh(document, input_mesh, base_mesh_name, ulps_threshold, custom_platforms = []):
mesh_name = base_mesh_name + ".reference"
platform_id = str(platform.system()) + "-" + str(platform.machine())
for custom_platform in custom_platforms:
if custom_platform == platform_id:
mesh_name = mesh_name + "." + platform_id
break
output_path = k3d.filesystem.generic_path(binary_path() + "/meshes/" + mesh_name + ".k3d")
reference_path = k3d.filesystem.generic_path(source_path() + "/meshes/" + mesh_name + ".k3d")
difference_path = k3d.filesystem.generic_path(binary_path() + "/meshes/differences/" + mesh_name + ".html")
output = k3d.plugin.create("K3DMeshWriter", document)
output.file = output_path
k3d.property.connect(document, input_mesh, output.get_property("input_mesh"))
reference = k3d.plugin.create("K3DMeshReader", document)
reference.center = False
reference.scale_to_size = False
reference.material = k3d.node.lookup_one(document, "Material")
reference.file = reference_path
if not os.path.exists(str(reference_path)):
raise Exception("missing reference file: " + str(reference_path))
result = k3d.difference.accumulator()
k3d.difference.test(input_mesh.internal_value(), reference.output_mesh, result)
dart_measurement("exact_count", result.exact_count())
dart_measurement("exact_min", result.exact_min())
dart_measurement("exact_max", result.exact_max())
def setup_bitmap_test(nodes):
if len(nodes) < 1:
raise Exception("Bitmap test requires at least one node.")
class result_object:
pass
result = result_object
result.document = k3d.new_document()
result.nodes = []
for node in nodes:
result.nodes.append(k3d.plugin.create(node, result.document))
if len(result.nodes) > 1:
k3d.property.connect(result.document, result.nodes[-2].get_property("output_bitmap"), result.nodes[-1].get_property("input_bitmap"))
result.source = result.nodes[0]
if len(nodes) == 3:
result.modifier = result.nodes[1]
if len(nodes) > 1:
result.sink = result.nodes[-1]
return result
#python
import k3d
doc = k3d.new_document()
axes = k3d.plugin.create("Axes", doc)
axes.axes = True
axes.xyplane = False
# Confirm that setting a property dependency works ...
k3d.property.connect(doc, axes.get_property("axes"), axes.get_property("xyplane"));
if axes.get_property("xyplane").internal_value() != False:
raise "incorrect internal value"
if axes.get_property("xyplane").pipeline_value() != True:
raise "incorrect pipeline value"
# Confirm that removing a property dependency works ...
k3d.property.disconnect(doc, axes.get_property("xyplane"))
if axes.get_property("xyplane").pipeline_value() != False:
raise "incorrect pipeline value"
merge_mesh = k3d.plugin.create("MergeMesh", document)
modifier = k3d.plugin.create("NurbsAddTrimCurve", document)
extract_trim = k3d.plugin.create("NurbsExtractTrimCurves", document)
merge_mesh.create_property("k3d::mesh*", "input_mesh1", "Input Mesh 1", "")
merge_mesh.create_property("k3d::mesh*", "input_mesh2", "Input Mesh 2", "")
modifier.mesh_selection = k3d.geometry.selection.create(1)
modifier.offset_u = 0.5
modifier.offset_v = 0.5
modifier.delete_curve = True
extract_trim.mesh_selection = k3d.geometry.selection.create(1)
k3d.property.connect(document, patch.get_property("output_mesh"), merge_mesh.get_property("input_mesh1"))
k3d.property.connect(document, curve.get_property("output_mesh"), merge_mesh.get_property("input_mesh2"))
k3d.property.connect(document, merge_mesh.get_property("output_mesh"), modifier.get_property("input_mesh"))
k3d.property.connect(document, modifier.get_property("output_mesh"), extract_trim.get_property("input_mesh"))
testing.require_valid_mesh(document, extract_trim.get_property("output_mesh"))
testing.require_similar_mesh(document, extract_trim.get_property("output_mesh"), "mesh.modifier.NurbsExtractTrimCurves", 10)
k3d.property.create(modifier, "k3d::mesh*", "input_mesh1", "Input Mesh 1", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh2", "Input Mesh 2", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh3", "Input Mesh 3", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh4", "Input Mesh 4", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh5", "Input Mesh 5", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh6", "Input Mesh 6", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh7", "Input Mesh 7", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh8", "Input Mesh 8", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh9", "Input Mesh 9", "")
k3d.property.connect(document, source1.get_property("output_mesh"), modifier.get_property("input_mesh1"))
k3d.property.connect(document, source2.get_property("output_mesh"), modifier.get_property("input_mesh2"))
k3d.property.connect(document, source3.get_property("output_mesh"), modifier.get_property("input_mesh3"))
k3d.property.connect(document, source4.get_property("output_mesh"), modifier.get_property("input_mesh4"))
k3d.property.connect(document, source5.get_property("output_mesh"), modifier.get_property("input_mesh5"))
k3d.property.connect(document, source6.get_property("output_mesh"), modifier.get_property("input_mesh6"))
k3d.property.connect(document, source7.get_property("output_mesh"), modifier.get_property("input_mesh7"))
k3d.property.connect(document, source8.get_property("output_mesh"), modifier.get_property("input_mesh8"))
k3d.property.connect(document, source9.get_property("output_mesh"), modifier.get_property("input_mesh9"))
testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"), "mesh.modifier.MergeMesh", 32, ["Darwin-i386"])
import k3d
import testing
doc = k3d.new_document()
axes = k3d.plugin.create("Axes", doc)
axes.xyplane = False
material = k3d.plugin.create("RenderManMaterial", doc)
torus = k3d.plugin.create("Torus", doc)
torus.material = material
mesh_instance = k3d.plugin.create("MeshInstance", doc)
mesh_instance.gl_painter = k3d.plugin.create("OpenGLTorusPainter", doc)
k3d.property.connect(doc, torus.get_property("output_mesh"), mesh_instance.get_property("input_mesh"))
camera = testing.create_camera(doc)
render_engine = testing.create_opengl_engine(doc)
camera_to_bitmap = k3d.plugin.create("GLXCameraToBitmap", doc)
camera_to_bitmap.camera = camera
camera_to_bitmap.render_engine = render_engine
testing.require_similar_bitmap(doc, camera_to_bitmap.get_property("output_bitmap"), "offscreen.GLXCameraToBitmap", 0.009)
#python
import k3d
# Setup a simple pipeline ...
doc = k3d.new_document()
source = k3d.plugin.create("PolyCube", doc)
modifier = k3d.plugin.create("ScalePoints", doc)
k3d.property.connect(doc, source.get_property("output_mesh"), modifier.get_property("input_mesh"))
# Create a profiler ...
profiler = k3d.plugin.create("PipelineProfiler", doc)
# At this point the profiler should be empty ...
if len(profiler.records) != 0:
raise Exception("expected zero profile records")
# Force execution of the pipeline ...
modifier.output_mesh
# At this point we expect the profiler to contain two records (one for the source and one for the modifier) ...
if len(profiler.records) != 2:
raise Exception("expected two profile records")
# See what we've got ...
torus = k3d.plugin.create("PolyTorus", document)
torus.u_segments = 8
torus.v_segments = 4
first_boolean = k3d.plugin.create("CGALBoolean", document)
first_boolean.type = "difference"
first_boolean.create_property("k3d::mesh*", "input_1", "Input 1", "")
first_boolean.create_property("k3d::mesh*", "input_2", "Input 2", "")
second_boolean = k3d.plugin.create("CGALBoolean", document)
second_boolean.type = "reverse_difference"
second_boolean.create_property("k3d::mesh*", "input_1", "Input 1", "")
second_boolean.create_property("k3d::mesh*", "input_2", "Input 2", "")
k3d.property.connect(document, big_cylinder.get_property("output_mesh"), first_boolean.get_property("input_1"))
k3d.property.connect(document, small_cylinder.get_property("output_mesh"), first_boolean.get_property("input_2"))
k3d.property.connect(document, torus.get_property("output_mesh"), second_boolean.get_property("input_1"))
k3d.property.connect(document, first_boolean.get_property("output_mesh"), second_boolean.get_property("input_2"))
testing.require_valid_mesh(document, second_boolean.get_property("output_mesh"))
testing.require_similar_mesh(document, second_boolean.get_property("output_mesh"), "mesh.modifier.CGALBoolean.cylinders", 1)