How to use k3d - 10 common examples

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.NurbsExtractPatchCurve.py View on Github external
#python

import testing
import k3d

setup = testing.setup_mesh_modifier_test("NurbsCylinder","NurbsExtractPatchCurve")

setup.modifier.mesh_selection = k3d.geometry.selection.create(1)
setup.modifier.parameter = 0.5
setup.modifier.extract_v_curve = True

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.NurbsExtractPatchCurve", 2, ["Darwin-i386"])
github K-3D / k3d / tests / mesh / mesh.modifier.CalculateNormals.2.py View on Github external
#python

import k3d
import testing
import math

setup = testing.setup_mesh_modifier_test("PolyCube", "CalculateNormals")
setup.modifier.mesh_selection = k3d.geometry.selection.create(1)
setup.modifier.max_angle = math.radians(91.0)
setup.modifier.face = True
setup.modifier.varying = True
setup.modifier.vertex = True
setup.modifier.face_array = "Nu"
setup.modifier.varying_array = "Nf"
setup.modifier.vertex_array = "Nv"


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.CalculateNormals.2", 1)
github K-3D / k3d / tests / mesh / mesh.modifier.NurbsCurveInsertKnot.py View on Github external
#python

import testing
import k3d

setup = testing.setup_mesh_modifier_test("NurbsCircle", "NurbsCurveInsertKnot")

setup.modifier.u_value = 0.1

selection = k3d.geometry.selection.create(0)
curve_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.CURVE)
k3d.geometry.primitive_selection.append(curve_selection, 0, 10000, 1)
setup.modifier.mesh_selection = selection

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.NurbsCurveInsertKnot", 2, ["Darwin-i386"])
github K-3D / k3d / tests / mesh / mesh.modifier.MoveFirstEdge.py View on Github external
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("PolyCube", "MoveFirstEdge")

selection = k3d.geometry.selection.create(0)
face_selection = k3d.geometry.primitive_selection.create(selection)
face_selection.primitive_begin().append(0)
face_selection.primitive_end().append(1)
face_selection.primitive_selection_type().append(k3d.selection.type.FACE)
face_selection.primitive_first_range().append(0)
face_selection.primitive_range_count().append(1)
face_selection.index_begin().append(0)
face_selection.index_end().append(3)
face_selection.weight().append(1)

setup.modifier.mesh_selection = selection
setup.modifier.distance = 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.MoveFirstEdge", 1)
github K-3D / k3d / tests / mesh / mesh.modifier.SubdivideFaces.Midpoints.py View on Github external
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("K3DMeshReader", "SubdivideFaces")

# load a mesh that has multiple polyhedra, triangles, quads, n-sided polygons and holes. (i.e. a mesh from hell)
setup.source.file = k3d.filesystem.generic_path(testing.source_path() + "/meshes/polyhedron.hole.k3d")
setup.source.center = False
setup.source.scale_to_size = False

# select some faces, distributed along polyhedra
selection = k3d.geometry.selection.create(0)
face_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.FACE)
k3d.geometry.primitive_selection.append(face_selection, 0, 6, 0)
k3d.geometry.primitive_selection.append(face_selection, 6, 7, 1)
k3d.geometry.primitive_selection.append(face_selection, 7, 8, 0)
k3d.geometry.primitive_selection.append(face_selection, 8, 9, 1)
k3d.geometry.primitive_selection.append(face_selection, 9, 13, 0)
k3d.geometry.primitive_selection.append(face_selection, 13, 15, 1)
k3d.geometry.primitive_selection.append(face_selection, 15, 16, 0)
k3d.geometry.primitive_selection.append(face_selection, 16, 17, 1)
k3d.geometry.primitive_selection.append(face_selection, 17, 19, 0)
k3d.geometry.primitive_selection.append(face_selection, 19, 20, 1)
k3d.geometry.primitive_selection.append(face_selection, 20, 23, 0)

setup.modifier.mesh_selection = selection
setup.modifier.subdivision_type = "midpoints"
github K-3D / k3d / tests / mesh / mesh.selection.all.py View on Github external
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("PolyGrid", "ScalePoints")

setup.source.rows = 1
setup.source.columns = 1

mesh_selection = k3d.geometry.selection.create(1.0)
setup.modifier.mesh_selection = mesh_selection
setup.modifier.x = 2

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.selection.all", 1)
github K-3D / k3d / tests / mesh / mesh.modifier.NurbsCloseCurve1.py View on Github external
#python

import testing
import k3d

setup = testing.setup_mesh_modifier_test("NurbsCurve", "NurbsCloseCurve")

setup.modifier.keep_ends = True

selection = k3d.geometry.selection.create(0)
curve_selection = k3d.geometry.primitive_selection.create(selection, k3d.selection.type.CURVE)
k3d.geometry.primitive_selection.append(curve_selection, 0, 10000, 1)
setup.modifier.mesh_selection = selection


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.NurbsCloseCurve1", 1)
github K-3D / k3d / tests / mesh / mesh.modifier.NurbsCreateCap.py View on Github external
#python

import testing
import k3d

setup = testing.setup_mesh_modifier_test("NurbsCircle","NurbsCreateCap")

setup.modifier.mesh_selection = k3d.geometry.selection.create(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.NurbsCreateCap", 1, ["Darwin-i386"])
github K-3D / k3d / tests / mesh / mesh.serialization.py View on Github external
#python

import k3d
import sys
import testing

setup = testing.setup_mesh_writer_test(["FrozenMesh", "K3DMeshWriter"], "K3DMeshReader", "mesh.serialization.k3d")

mesh = setup.source.create_mesh()
primitive = mesh.primitives().create("test")

array_types = [ "k3d::bool_t", "k3d::color", "k3d::double_t", "k3d::imaterial*", "k3d::inode*", "k3d::int16_t", "k3d::int32_t", "k3d::int64_t", "k3d::int8_t", "k3d::matrix4", "k3d::normal3", "k3d::point2", "k3d::point3", "k3d::point4", "k3d::string_t", "k3d::texture3", "k3d::uint16_t", "k3d::uint32_t", "k3d::uint64_t", "k3d::uint8_t", "k3d::vector2", "k3d::vector3", "k3d::uint_t" ]
array_values = [ True, k3d.color(1, 2, 3), 1.0, None, None, 1, 2, 3, 4, k3d.identity3(), k3d.normal3(1, 2, 3), k3d.point2(1, 2), k3d.point3(1, 2, 3), k3d.point4(1, 2, 3, 4), "A String", k3d.texture3(1, 2, 3), 1, 2, 3, 4, k3d.vector2(1, 2), k3d.vector3(1, 2, 3), 7 ]

structure = primitive.structure().create("generic")
attributes = primitive.attributes().create("generic")

for i in range(len(array_types)):
	type = array_types[i]
	value = array_values[i]

	structure_array = structure.create(type, type)
	structure_array.append(value)
	structure_array.append(value)
	structure_array.append(value)

	attribute_array = attributes.create(type, type)
	attribute_array.append(value)
	attribute_array.append(value)