How to use the k3d.plugin.create function in k3d

To help you get started, we’ve selected a few k3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github K-3D / k3d / tests / testing.py View on Github external
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
github K-3D / k3d / tests / mesh / mesh.modifier.CGALBoolean.cubes.py View on Github external
#python

import k3d
import testing

document = k3d.new_document()

small_cube = k3d.plugin.create("PolyCube", document)
small_cube.width = 2.5
small_cube.depth = 2.5
small_cube.height = 7.5
big_cube = k3d.plugin.create("PolyCube", document)

cgal_boolean = k3d.plugin.create("CGALBoolean", document)
cgal_boolean.type = "difference"
cgal_boolean.create_property("k3d::mesh*", "input_1", "Input 1", "")
cgal_boolean.create_property("k3d::mesh*", "input_2", "Input 2", "")

k3d.property.connect(document, big_cube.get_property("output_mesh"), cgal_boolean.get_property("input_1"))
k3d.property.connect(document, small_cube.get_property("output_mesh"), cgal_boolean.get_property("input_2"))


testing.require_valid_mesh(document, cgal_boolean.get_property("output_mesh"))
testing.require_similar_mesh(document, cgal_boolean.get_property("output_mesh"), "mesh.modifier.CGALBoolean.cubes", 1)
github K-3D / k3d / tests / python / node_selection.py View on Github external
#python

import k3d

doc = k3d.new_document()

node_selection = k3d.plugin.create("NodeSelection", doc)

node1 = k3d.plugin.create("FrozenMesh", doc)
node2 = k3d.plugin.create("FrozenMesh", doc)
node3 = k3d.plugin.create("FrozenMesh", doc)

node1.name="n1"
node2.name="n2"
node3.name="n3"

node_selection.select(node3, 0.5)
if node_selection.selection_weight(node3) != 0.5:
	raise Exception("incorrect node selection_weight")

node_selection.select(node1, 1.0)
node_selection.select(node2, 1.0)

selected_nodes = node_selection.selected_nodes()
github K-3D / k3d / tests / mesh / mesh.modifier.MergeMesh.generic.py View on Github external
document = k3d.new_document()

source1= k3d.plugin.create("PolyCube", document)
source1.width = 2.0
source1.height = 2.0
source1.depth = 2.0

source2 = k3d.plugin.create("PolyCube", document)
source2.width = 4.0
source2.height = 4.0
source2.depth = 4.0

modifier1 = k3d.plugin.create("PointsToParticles", document)
modifier1.width = 2.0

modifier2 = k3d.plugin.create("PointsToParticles", document)
modifier2.width = 3.0

k3d.property.connect(document, source1.get_property("output_mesh"), modifier1.get_property("input_mesh"))
k3d.property.connect(document, source2.get_property("output_mesh"), modifier2.get_property("input_mesh"))

merge_mesh = k3d.plugin.create("MergeMesh", document)
merge_mesh.create_property("k3d::mesh*", "input_mesh1", "Input Mesh 1", "")
merge_mesh.create_property("k3d::mesh*", "input_mesh2", "Input Mesh 2", "")

k3d.property.connect(document, modifier1.get_property("output_mesh"), merge_mesh.get_property("input_mesh1"))
k3d.property.connect(document, modifier2.get_property("output_mesh"), merge_mesh.get_property("input_mesh2"))

testing.require_valid_mesh(document, merge_mesh.get_property("output_mesh"))
testing.require_similar_mesh(document, merge_mesh.get_property("output_mesh"), "mesh.modifier.MergeMesh.generic", 2)
github K-3D / k3d / tests / other / document.serialization.properties.py View on Github external
#python

import k3d
import testing

def create_property(node, type, value):
	property = k3d.property.create(node, type, type, "", "")
	property.set_value(value)

document = k3d.new_document()
test_container = k3d.plugin.create("Null", document)
test_container.name = "test_container"

test_material = k3d.plugin.create("MultiMaterial", document)
test_material.name = "test_material"

test_gl_mesh_painter = k3d.plugin.create("OpenGLPointPainter", document)
test_gl_mesh_painter.name = "test_gl_mesh_painter"

test_ri_mesh_painter = k3d.plugin.create("RenderManLinearCurvePainter", document)
test_ri_mesh_painter.name = "test_ri_mesh_painter"

test_ri_texture = k3d.plugin.create("RenderManTextureMap", document)
test_ri_texture.name = "test_ri_texture"

test_node = k3d.plugin.create("Axes", document)
test_node.name = "test_node"
github K-3D / k3d / tests / offscreen / offscreen.OpenGLFramebufferCameraToBitmap.py View on Github external
#python

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

camera = testing.create_camera(doc)
render_engine = testing.create_opengl_engine(doc)

camera_to_bitmap = k3d.plugin.create("OpenGLFramebufferCameraToBitmap", 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.OpenGLFramebufferCameraToBitmap", 0.009)
github K-3D / k3d / tests / mesh / mesh.modifier.MorphPoints.py View on Github external
#python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("PolyCone", document)
source2 = k3d.plugin.create("PolySphere", document)
source3 = k3d.plugin.create("PolyCube", document)
modifier = k3d.plugin.create("MorphPoints", document)

modifier.create_property("k3d::mesh*", "input1", "input1", "input1")
modifier.create_property("k3d::mesh*", "input2", "input2", "input2")
modifier.create_property("k3d::double_t", "amount1", "amount1", "amount1")
modifier.create_property("k3d::double_t", "amount2", "amount2", "amount2")

k3d.property.connect(document, source1.get_property("output_mesh"), modifier.get_property("input_mesh"))
k3d.property.connect(document, source2.get_property("output_mesh"), modifier.get_property("input1"))
k3d.property.connect(document, source3.get_property("output_mesh"), modifier.get_property("input2"))

selection = k3d.geometry.selection.create(0)
point_selection = k3d.geometry.point_selection.create(selection, 1)

modifier.mesh_selection = selection
github K-3D / k3d / share / scripts / create_particles.py View on Github external
# Create a custom attribute array to store color values for each particle ...
	Cs = particles.vertex_attributes().create("Cs", "k3d::color")

	# Add particles to the primitive ...
	particles.material().append(None)
	for i in range(particle_count):
		particles.points().append(i)
	
	constantwidth.append(0.5)

	# Assign a random color to each particle ...
	for i in range(particle_count):
		Cs.append(k3d.color(uniform(0, 1), uniform(0, 1), uniform(0, 1)))

	# Connect the FrozenMesh to a MeshInstance to place it in the scene ...
	mesh_instance = k3d.plugin.create("MeshInstance", context.document)
	mesh_instance.name = "Particle Instance"
	mesh_instance.gl_painter = k3d.node.lookup_one(context.document, "GL Default Painter")
	mesh_instance.ri_painter = k3d.node.lookup_one(context.document, "RenderMan Default Painter")

	context.document.set_dependency(mesh_instance.get_property("input_mesh"), frozen_mesh.get_property("output_mesh"))

	# Make the MeshInstance visible to render engines ...
	k3d.node.show(context.document, mesh_instance)

	context.document.finish_change_set("Create Point Group")

except:
	context.document.cancel_change_set()
	raise
github K-3D / k3d / docs / wiki / make-wiki-docs-primitives.py View on Github external
primitive_type.create(mesh)

	need_points = False
	primitive = mesh.primitives()[0]
	for table_name in primitive.structure().keys():
		table = primitive.structure()[table_name]
		for array_name in table.keys():
			array = table[array_name]
			if array.get_metadata_value("k3d:domain") == "k3d:point-indices":
				need_points = True

	if need_points:
		mesh.create_points()
		mesh.create_point_selection()

	writer = k3d.plugin.create("GraphVizMeshWriter", document)
	document.set_dependency(writer.get_property("input_mesh"), source.get_property("output_mesh"))
	article.write(writer.output_string)

	k3d.close_document(document)

	article.write("\n")
	article.write("""\n""")