def create_camera(document): camera_view = k3d.plugin.create("ViewMatrix", document) camera_view.position = k3d.translate3(k3d.vector3(-10, -15, 10)) camera_view.look = k3d.identity3() camera_view.up = k3d.translate3(k3d.vector3(0, 0, 20)) camera = k3d.plugin.create("Camera", document) k3d.property.connect(document, camera_view.get_property("output_matrix"), camera.get_property("input_matrix")) return camera
def create_camera(document): camera_view = document.new_node("ViewMatrix") camera_view.position = k3d.translate3(k3d.vector3(-10, -15, 10)) camera_view.look = k3d.identity3() camera_view.up = k3d.translate3(k3d.vector3(0, 0, 20)) camera = document.new_node("Camera") document.set_dependency(camera.get_property("input_matrix"), camera_view.get_property("output_matrix")) return camera
def mesh_modifier_benchmark( benchmarkPluginName, maxSize=15, properties={"input_matrix": k3d.translate3(k3d.vector3(0, 0, 1))}): current_count = [1, 1, 1] runsPerBenchmark = 10 append = True for k in range(maxSize): try: benchmark_mesh = benchmarkMesh(current_count) run_mesh_modifier_benchmark(benchmarkPluginName, benchmark_mesh, runsPerBenchmark, properties, append, k == 0) current_count[k % 3] *= 2 except: break
#python import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a teapot mesh primitive ... teapot = k3d.teapot.create(context.output) color = teapot.surface_attributes().create("Cs", "k3d::color") # Add three teapots ... teapot.matrices().append(k3d.translate3(k3d.vector3(-7, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(1, 0, 0)) teapot.matrices().append(k3d.translate3(k3d.vector3(0, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(0, 1, 0)) teapot.matrices().append(k3d.translate3(k3d.vector3(7, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(0, 0, 1))
def mesh_modifier_benchmark(benchmarkPluginName, maxSize = 15, properties = {"input_matrix" : k3d.translate3(k3d.vector3(0, 0, 1))}): current_count = [1,1,1] runsPerBenchmark = 10 append = True for k in range(maxSize): try: benchmark_mesh = benchmarkMesh(current_count) run_mesh_modifier_benchmark(benchmarkPluginName, benchmark_mesh, runsPerBenchmark, properties, append, k == 0) current_count[k % 3] *= 2 except: break
#python import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a cube mesh primitive ... cubes = context.output.primitives().create("cube") matrices = cubes.topology().create("matrices", "k3d::matrix4") materials = cubes.topology().create("materials", "k3d::imaterial*") uniform = cubes.attributes().create("uniform") color = uniform.create("Cs", "k3d::color") # Add three cubes ... matrices.append(k3d.translate3(k3d.vector3(-7, 0, 0))) materials.append(None) color.append(k3d.color(1, 0, 0)) matrices.append(k3d.translate3(k3d.vector3(0, 0, 0))) materials.append(None) color.append(k3d.color(0, 1, 0)) matrices.append(k3d.translate3(k3d.vector3(7, 0, 0))) materials.append(None) color.append(k3d.color(0, 0, 1)) print repr(context.output)
#python from math import radians import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a sphere mesh primitive ... sphere = k3d.sphere.create(context.output) color = sphere.parameter_attributes().create("Cs", "k3d::color") # Add two spheres ... sphere.matrices().append(k3d.translate3(k3d.vector3(-3, 0, 0))) sphere.materials().append(None) sphere.radii().append(2) sphere.z_min().append(-1) sphere.z_max().append(1) sphere.sweep_angles().append(radians(360)) sphere.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) sphere.matrices().append(k3d.translate3(k3d.vector3(3, 0, 0))) sphere.materials().append(None) sphere.radii().append(2) sphere.z_min().append(-1) sphere.z_max().append(1) sphere.sweep_angles().append(radians(360)) sphere.selections().append(0)
#python from math import radians import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a sphere mesh primitive ... hyperboloid = k3d.hyperboloid.create(context.output) color = hyperboloid.parameter_attributes().create("Cs", "k3d::color") # Add two hyperboloids ... hyperboloid.matrices().append(k3d.translate3(k3d.vector3(-5, 0, 0))) hyperboloid.materials().append(None) hyperboloid.start_points().append(k3d.point3(-2, 2, 2)) hyperboloid.end_points().append(k3d.point3(2, 2, -2)) hyperboloid.sweep_angles().append(radians(360)) hyperboloid.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) hyperboloid.matrices().append(k3d.translate3(k3d.vector3(5, 0, 0))) hyperboloid.materials().append(None) hyperboloid.start_points().append(k3d.point3(-2, 2, 2)) hyperboloid.end_points().append(k3d.point3(2, 2, -2)) hyperboloid.sweep_angles().append(radians(360)) hyperboloid.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0))
#python import k3d import testing document = k3d.new_document() time_source = k3d.plugin.create("TimeSource", document) instance = k3d.plugin.create("MeshInstance", document) transform = k3d.plugin.create("FrozenMatrix", document) track = k3d.plugin.create("AnimationTrackDoubleMatrix4", document) interpolator = k3d.plugin.create("InterpolatorDoubleMatrix4Linear", document) track.interpolator = interpolator transform.matrix = k3d.translate3(3, 0, 0) time = k3d.get_time(document) k3d.property.connect(document, track.get_property("output_value"), instance.get_property("input_matrix")) k3d.property.connect(document, transform.get_property("output_matrix"), track.get_property("value_input")) k3d.property.connect(document, time_source.get_property("time"), track.get_property("time_input")) time.set_value(0.0) transform.matrix = k3d.translate3(0, 0, 0) track.keyframe() time.set_value(4.0) transform.matrix = k3d.translate3(2, 0, 0) track.keyframe() time.set_value(2.0)
#python import k3d import testing setup = testing.setup_mesh_source_test("CUDAPolyGridAndTransformPoints") setup.source.input_matrix = k3d.translate3(k3d.vector3(0, 0, 1)) testing.mesh_comparison_to_reference(setup.document, setup.source.get_property("output_mesh"), "mesh.source.PolyGridAndTransformPoints", 1)
#python import k3d import testing document = k3d.new_document() time_source = k3d.plugin.create("TimeSource", document) instance = k3d.plugin.create("MeshInstance", document) transform = k3d.plugin.create("FrozenMatrix", document) track = k3d.plugin.create("AnimationTrackDoubleMatrix4", document) interpolator = k3d.plugin.create("InterpolatorDoubleMatrix4Linear", document) track.interpolator = interpolator transform.matrix = k3d.translate3(3, 0, 0) time = k3d.get_time(document) k3d.property.connect(document, track.get_property("output_value"), instance.get_property("input_matrix")) k3d.property.connect(document, transform.get_property("output_matrix"), track.get_property("value_input")) k3d.property.connect(document, time_source.get_property("time"), track.get_property("time_input")) time.set_value(0.0) transform.matrix = k3d.translate3(0, 0, 0) track.keyframe() time.set_value(4.0) transform.matrix = k3d.translate3(2, 0, 0) track.keyframe() time.set_value(2.0) position = k3d.world_position(instance) reference = k3d.point3(1, 0, 0)
blobby = k3d.blobby.create(mesh) # Create a custom attribute array to assign color values to each blobby primitive ... Cs = blobby.vertex_attributes().create("Cs", "k3d::color") # Add four ellipsoid primitives to the blobby ... blobby.materials().append(None) blobby.first_primitives().append(len(blobby.primitives())) blobby.primitive_counts().append(4) ellipsoids = [(-1, 0, 1), (1, 0, 1), (1, 0, -1), (-1, 0, -1)] for center in ellipsoids: blobby.primitives().append(k3d.blobby.primitive_type.ELLIPSOID) blobby.primitive_first_floats().append(len(blobby.floats())) blobby.primitive_float_counts().append(16) for i in (k3d.translate3(center) * k3d.scale3(1.7, 1, 1.7)).column_major_values(): blobby.floats().append(i) # Assign a color to each primitive ... Cs.assign([k3d.color(1, 0, 0), k3d.color(0, 1, 0), k3d.color(0, 0, 1), k3d.color(1, 1, 1)]) # Add a single operator to the blobby to add all four primitives together ... blobby.first_operators().append(len(blobby.operators())) blobby.operator_counts().append(1) blobby.operators().append(k3d.blobby.operator_type.ADD) blobby.operator_first_operands().append(len(blobby.operands())) blobby.operator_operand_counts().append(5) blobby.operands().assign([5, 0, 1, 2, 3]) # Operand count, followed by the index of each primitive to add # Connect the FrozenMesh to a MeshInstance to place it in the scene ... mesh_instance = k3d.plugin.create("MeshInstance", context.document)
#python from math import radians import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a sphere mesh primitive ... paraboloids = k3d.paraboloid.create(context.output) color = paraboloids.parameter_attributes().create("Cs", "k3d::color") # Add two paraboloids ... paraboloids.matrices().append(k3d.translate3(k3d.vector3(-5, 0, 0))) paraboloids.materials().append(None) paraboloids.radii().append(3) paraboloids.z_min().append(0) paraboloids.z_max().append(6) paraboloids.sweep_angles().append(radians(360)) paraboloids.selections().append(0.0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) paraboloids.matrices().append(k3d.translate3(k3d.vector3(5, 0, 0))) paraboloids.materials().append(None) paraboloids.radii().append(3) paraboloids.z_min().append(0) paraboloids.z_max().append(6) paraboloids.sweep_angles().append(radians(360)) paraboloids.selections().append(0.0)
# python from math import radians import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a sphere mesh primitive ... hyperboloid = k3d.hyperboloid.create(context.output) color = hyperboloid.parameter_attributes().create("Cs", "k3d::color") # Add two hyperboloids ... hyperboloid.matrices().append(k3d.translate3(k3d.vector3(-5, 0, 0))) hyperboloid.materials().append(None) hyperboloid.start_points().append(k3d.point3(-2, 2, 2)) hyperboloid.end_points().append(k3d.point3(2, 2, -2)) hyperboloid.sweep_angles().append(radians(360)) hyperboloid.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) hyperboloid.matrices().append(k3d.translate3(k3d.vector3(5, 0, 0))) hyperboloid.materials().append(None) hyperboloid.start_points().append(k3d.point3(-2, 2, 2)) hyperboloid.end_points().append(k3d.point3(2, 2, -2)) hyperboloid.sweep_angles().append(radians(360)) hyperboloid.selections().append(0) color.append(k3d.color(1, 0, 0))
#python import k3d k3d.check_node_environment(locals(), "MeshSourceScript") # Construct a cube mesh primitive ... cubes = Output.primitives().create("cube") matrices = cubes.topology().create("matrices", "k3d::matrix4") materials = cubes.topology().create("materials", "k3d::imaterial*") uniform = cubes.attributes().create("uniform") color = uniform.create("Cs", "k3d::color") # Add three cubes ... matrices.append(k3d.translate3(k3d.vector3(-7, 0, 0))) materials.append(None) color.append(k3d.color(1, 0, 0)) matrices.append(k3d.translate3(k3d.vector3(0, 0, 0))) materials.append(None) color.append(k3d.color(0, 1, 0)) matrices.append(k3d.translate3(k3d.vector3(7, 0, 0))) materials.append(None) color.append(k3d.color(0, 0, 1)) print repr(Output)
#python from math import radians import k3d k3d.check_node_environment(locals(), "MeshSourceScript") # Construct a sphere mesh primitive ... sphere = k3d.sphere.create(Output) color = sphere.varying_data().create("Cs", "k3d::color") # Add two spheres ... sphere.matrices().append(k3d.translate3(k3d.vector3(-3, 0, 0))) sphere.materials().append(None) sphere.radii().append(2) sphere.z_min().append(-1) sphere.z_max().append(1) sphere.sweep_angles().append(radians(360)) sphere.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) sphere.matrices().append(k3d.translate3(k3d.vector3(3, 0, 0))) sphere.materials().append(None) sphere.radii().append(2) sphere.z_min().append(-1) sphere.z_max().append(1) sphere.sweep_angles().append(radians(360)) sphere.selections().append(0)
Cs = blobby.parameter_attributes().create("Cs", "k3d::color") # Add four ellipsoids to the blobby ... ellipsoids = [k3d.point3(-1, 0, 1), k3d.point3(1, 0, 1), k3d.point3(1, 0, -1), k3d.point3(-1, 0, -1)] blobby.first_primitives().append(len(blobby.primitives())) blobby.primitive_counts().append(len(ellipsoids) + 1) blobby.first_operators().append(len(blobby.operators())) blobby.operator_counts().append(1) blobby.materials().append(k3d.node.lookup_one(context.document, "Material")) for center in ellipsoids: blobby.primitives().append(k3d.blobby.primitive_type.ELLIPSOID) blobby.primitive_first_floats().append(len(blobby.floats())) blobby.primitive_float_counts().append(16) for i in (k3d.translate3(center[0], center[1], center[2]) * k3d.scale3(1)).column_major_values(): blobby.floats().append(i) # Add a segment to the blobby ... blobby.primitives().append(k3d.blobby.primitive_type.SEGMENT) blobby.primitive_first_floats().append(len(blobby.floats())) blobby.primitive_float_counts().append(23) blobby.floats().append(-1) blobby.floats().append(0) blobby.floats().append(0) blobby.floats().append(1) blobby.floats().append(0) blobby.floats().append(0) blobby.floats().append(1) for i in k3d.identity3().column_major_values(): blobby.floats().append(i)
#python from math import radians import k3d k3d.check_node_environment(locals(), "MeshSourceScript") # Construct a sphere mesh primitive ... cylinder = k3d.cylinder.create(Output) color = cylinder.varying_data().create("Cs", "k3d::color") # Add two cylinders ... cylinder.matrices().append(k3d.translate3(k3d.vector3(-3, 0, 0))) cylinder.materials().append(None) cylinder.radii().append(2) cylinder.z_min().append(-5) cylinder.z_max().append(5) cylinder.sweep_angles().append(radians(360)) cylinder.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) cylinder.matrices().append(k3d.translate3(k3d.vector3(3, 0, 0))) cylinder.materials().append(None) cylinder.radii().append(2) cylinder.z_min().append(-5) cylinder.z_max().append(5) cylinder.sweep_angles().append(radians(360)) cylinder.selections().append(0)
#python import k3d import testing document = k3d.new_document() instance = k3d.plugin.create("MeshInstance", document) transform = k3d.plugin.create("FrozenMatrix", document) transform.matrix = k3d.translate3(1, 0, 0) k3d.property.connect(document, transform.get_property("output_matrix"), instance.get_property("input_matrix")) position = k3d.world_position(instance) reference = k3d.point3(1, 0, 0) if position != reference: raise Exception("Position differs from expected value, expected: " + str(reference) + ", result: " + str(position))
#python from math import radians import k3d k3d.check_node_environment(context, "MeshSourceScript") # Construct a sphere mesh primitive ... disk = k3d.disk.create(context.output) color = disk.parameter_attributes().create("Cs", "k3d::color") # Add two disks ... disk.matrices().append(k3d.translate3(k3d.vector3(-5, 0, 0))) disk.materials().append(None) disk.heights().append(0) disk.radii().append(4) disk.sweep_angles().append(radians(360)) disk.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 1, 0)) color.append(k3d.color(1, 1, 0)) disk.matrices().append(k3d.translate3(k3d.vector3(5, 0, 0))) disk.materials().append(None) disk.heights().append(0) disk.radii().append(4) disk.sweep_angles().append(radians(360)) disk.selections().append(0) color.append(k3d.color(1, 0, 0)) color.append(k3d.color(1, 0, 0))
k3d.point3(1, 0, 1), k3d.point3(1, 0, -1), k3d.point3(-1, 0, -1) ] blobby.first_primitives().append(len(blobby.primitives())) blobby.primitive_counts().append(len(ellipsoids) + 1) blobby.first_operators().append(len(blobby.operators())) blobby.operator_counts().append(1) blobby.materials().append(Document.get_node("Material")) for center in ellipsoids: blobby.primitives().append(k3d.blobby.primitive_type.ELLIPSOID) blobby.primitive_first_floats().append(len(blobby.floats())) blobby.primitive_float_counts().append(16) for i in (k3d.translate3(center[0], center[1], center[2]) * k3d.scale3(1)).column_major_list(): blobby.floats().append(i) # Add a segment to the blobby ... blobby.primitives().append(k3d.blobby.primitive_type.SEGMENT) blobby.primitive_first_floats().append(len(blobby.floats())) blobby.primitive_float_counts().append(23) blobby.floats().append(-1) blobby.floats().append(0) blobby.floats().append(0) blobby.floats().append(1) blobby.floats().append(0) blobby.floats().append(0) blobby.floats().append(1) for i in k3d.identity3().column_major_list():
#python import k3d import testing setup = testing.setup_mesh_source_test("CUDAPolyGridAndTransformPoints") setup.source.input_matrix = k3d.translate3(k3d.vector3(0, 0, 1)) testing.require_valid_mesh(setup.document, setup.source.get_property("output_mesh")) testing.require_similar_mesh(setup.document, setup.source.get_property("output_mesh"), "mesh.source.PolyGridAndTransformPoints", 1)
#python import k3d k3d.check_node_environment(locals(), "MeshSourceScript") # Construct a teapot mesh primitive ... teapot = k3d.teapot.create(Output) color = teapot.uniform_data().create("Cs", "k3d::color") # Add three teapots ... teapot.matrices().append(k3d.translate3(k3d.vector3(-7, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(1, 0, 0)) teapot.matrices().append(k3d.translate3(k3d.vector3(0, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(0, 1, 0)) teapot.matrices().append(k3d.translate3(k3d.vector3(7, 0, 0))) teapot.materials().append(None) teapot.selections().append(0.0) color.append(k3d.color(0, 0, 1))
#python import k3d import testing setup = testing.setup_mesh_modifier_test("PolyCube", "CUDATransformPoints") selection = k3d.geometry.selection.create(0) selection.points = k3d.geometry.point_selection.uniform(selection, 1) setup.modifier.mesh_selection = selection setup.modifier.input_matrix = k3d.translate3(k3d.vector3(0, 0, 1)) testing.require_valid_mesh(setup.document, setup.modifier.get_property("output_mesh")) testing.require_similar_mesh(setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.TransformPoints", 1)
#python import k3d import testing setup = testing.setup_mesh_modifier_test("PolyCube", "TransformPoints") selection = k3d.mesh_selection.deselect_all() selection.points = k3d.mesh_selection.component_select_all() setup.modifier.mesh_selection = selection setup.modifier.input_matrix = k3d.translate3(k3d.vector3(0, 0, 1)) testing.mesh_comparison_to_reference( setup.document, setup.modifier.get_property("output_mesh"), "mesh.modifier.TransformPoints", 1)
operator_operand_counts = blobbies.create_operator_operand_counts() operands = blobbies.create_operands() ellipsoids = [k3d.point3(-1, 0, 1), k3d.point3(1, 0, 1), k3d.point3(1, 0, -1), k3d.point3(-1, 0, -1)] first_primitives.append(len(primitives)) primitive_counts.append(len(ellipsoids) + 1) first_operators.append(len(operators)) operator_counts.append(1) materials.append(k3d.dynamic_cast(Document.get_node("Material"), "imaterial")) for center in ellipsoids: primitives.append(k3d.primitive_type.ellipsoid) primitive_first_floats.append(len(floats)) primitive_float_counts.append(16) for i in (k3d.translate3(center) * k3d.scale3(1, 1, 1)).column_major_list(): floats.append(i) primitives.append(k3d.primitive_type.segment) primitive_first_floats.append(len(floats)) primitive_float_counts.append(23) floats.append(-1) floats.append(0) floats.append(0) floats.append(1) floats.append(0) floats.append(0) floats.append(1) for i in k3d.identity3().column_major_list(): floats.append(i)