Exemplo n.º 1
0
def create_default_painter(document):

    use_vbo = False
    try:
        if (os.environ['USE_VBO']):
            use_vbo = True
    except KeyError:
        pass

    if (not use_vbo):
        edge_painter = document.new_node("OpenGLEdgePainter")
        face_painter = document.new_node("OpenGLFacePainter")
    else:
        edge_painter = document.new_node("VBOEdgePainter")
        face_painter = document.new_node("VBOFacePainterFlatNormals")

        edge_painter.unselected_mesh_color = k3d.color(0, 0, 0)
        edge_painter.selected_mesh_color = k3d.color(1, 1, 1)
        edge_painter.selected_component_color = k3d.color(1, 0, 0)

        face_painter.unselected_mesh_color = k3d.color(0.8, 0.8, 0.8)
        face_painter.selected_mesh_color = k3d.color(0.8, 0.8, 0.8)
        face_painter.selected_component_color = k3d.color(1, 0, 0)

    nurbs_curve_painter = document.new_node("OpenGLNURBSCurvePainter")
    nurbs_patch_painter = document.new_node("OpenGLNURBSPatchPainter")

    painter = document.new_node("OpenGLMultiPainter")

    painter.create_property("k3d::gl::imesh_painter*", "edges", "Edges",
                            "Edge Painter")
    painter.create_property("k3d::gl::imesh_painter*", "faces", "Faces",
                            "Face Painter")
    painter.create_property("k3d::gl::imesh_painter*", "nurbs_curves",
                            "NURBS Curves", "NURBS Curve Painter")
    painter.create_property("k3d::gl::imesh_painter*", "nurbs_patches",
                            "NURBS Patches", "NURBS Patche Painter")

    painter.edges = edge_painter
    painter.faces = face_painter
    painter.nurbs_curves = nurbs_curve_painter
    painter.nurbs_patches = nurbs_patch_painter

    return painter
Exemplo n.º 2
0
#python

import k3d
k3d.check_node_environment(context, "MeshSourceScript")

# Perform required one-time setup to store geometric points in the mesh ...
points = context.output.create_points()
point_selection = context.output.create_point_selection()

# Construct a point group mesh primitive ...
particles = k3d.particle.create(context.output)

# Create an (optional) array to store per-group point widths
constantwidth = particles.constant_attributes().create("constantwidth",
                                                       "k3d::double_t")

# Create an (optional) array to store per-point point colors
Cs = particles.vertex_attributes().create("Cs", "k3d::color")

# Add some points ...
particles.material().append(None)
constantwidth.append(0.5)

for x in range(-5, 6):
    for z in range(-5, 6):
        particles.points().append(len(points))

        points.append(k3d.point3(x, 0, z))
        point_selection.append(0.0)
        Cs.append(k3d.color((x / 10.0) + 0.5, 1, (z / 10.0) + 0.5))
Exemplo n.º 3
0
#python

import k3d
import sys
import testing

document = k3d.new_document()

source = document.new_node("FrozenMesh")
mesh = 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 ]

attributes = primitive.attributes().create("uniform")
for i in range(len(array_types)):
	type = array_types[i]
	value = array_values[i]

	named_array = primitive.structure().create(type, type)
	named_array.append(value)
	named_array.append(value)

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

print repr(mesh)
sys.stdout.flush()
Exemplo n.º 4
0
#python

import k3d

Output = k3d.color(1, 0.5, 0.25)

Exemplo n.º 5
0
	# Create a custom attribute array to control the widths of particles ...
	constantwidth = particles.constant_attributes().create("constantwidth", "k3d::double_t")

	# 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")

	k3d.property.connect(context.document, frozen_mesh.get_property("output_mesh"), mesh_instance.get_property("input_mesh"))

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

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

except:
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"

create_property(test_container, "k3d::bool_t", True)
create_property(test_container, "k3d::color", k3d.color(1, 2, 3))
create_property(test_container, "k3d::double_t", 3.1415)
create_property(test_container, "k3d::filesystem::path", k3d.filesystem.generic_path("/foo/bar/baz"))
create_property(test_container, "k3d::gl::imesh_painter*", test_gl_mesh_painter)
create_property(test_container, "k3d::imaterial*", test_material)
create_property(test_container, "k3d::inode*", test_node)
create_property(test_container, "k3d::int32_t", 19700827)
create_property(test_container, "k3d::matrix4", k3d.scale3(1, 2, 3))
create_property(test_container, "k3d::normal3", k3d.normal3(1, 2, 3))
create_property(test_container, "k3d::point3", k3d.point3(1, 2, 3))
create_property(test_container, "k3d::point4", k3d.point4(1, 2, 3, 4))
create_property(test_container, "k3d::ri::imesh_painter*", test_ri_mesh_painter)
create_property(test_container, "k3d::ri::itexture*", test_ri_texture)
create_property(test_container, "k3d::string_t", "K-3D Rocks!")
create_property(test_container, "k3d::vector3", k3d.vector3(1, 2, 3))
Exemplo n.º 7
0
positions = [(-5, 5, 0), (5, 5, 0), (-5, -5, 0), (5, -5, 0)]

points = mesh.create_points()
point_selection = mesh.create_point_selection()

for position in positions:
	points.append(k3d.point3(position[0], position[1], position[2]))
	point_selection.append(0.0)

polyhedron = k3d.polyhedron.create(mesh)
polyhedron.shell_first_faces().append(0)
polyhedron.shell_face_counts().append(1)
polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)
polyhedron.face_first_loops().append(0)
polyhedron.face_loop_counts().append(1)
polyhedron.face_materials().append(None)
polyhedron.face_selections().append(0.0)
polyhedron.loop_first_edges().append(0)
polyhedron.edge_points().assign([0, 1, 2, 3])
polyhedron.clockwise_edges().assign([1, 2, 3, 0])
polyhedron.edge_selections().assign([0.0, 0.0, 0.0, 0.0])

Cs = polyhedron.face_varying_data().create("Cs", "k3d::color")
Cs.assign([k3d.color(1, 0, 0), k3d.color(0, 1, 0), k3d.color(0, 0, 1), k3d.color(1, 1, 1)])

modifier = document.new_node("GTSMeshArea")
document.set_dependency(modifier.get_property("input_mesh"), source.get_property("output_mesh"))

testing.mesh_area_comparison(modifier.area, 50.0)

Exemplo n.º 8
0
#python

import k3d
import testing

doc = k3d.new_document()
source = k3d.plugin.create("ColorSourceScript", doc)

if source.output_color != k3d.color(1, 0.5, 0.25):
	raise "unexpected output_color: " + str(source.output_color)

Exemplo n.º 9
0
structure_a = primitive_a.structure().create("indices", "k3d::uint_t")
test_unequal(mesh_a, mesh_b, "structure with missing array")

structure_b = primitive_b.structure().create("indices", "k3d::uint_t")
test_equal(mesh_a, mesh_b, "structure with matched arrays")

structure_a.append(5)
test_unequal(mesh_a, mesh_b, "mismatched structure arrays")

structure_b.append(5)
test_equal(mesh_a, mesh_b, "matched structure_arrays")

attributes_a = primitive_a.attributes().create("uniform")
test_unequal(mesh_a, mesh_b, "primitive with missing attributes")

attributes_b = primitive_b.attributes().create("uniform")
test_equal(mesh_a, mesh_b, "matched primitive attributes")

attribute_a = attributes_a.create("Cs", "k3d::color")
test_unequal(mesh_a, mesh_b, "missing attribute arrays")

attribute_b = attributes_b.create("Cs", "k3d::color")
test_equal(mesh_a, mesh_b, "matched attribute arrays")

attribute_a.append(k3d.color(1, 2, 3))
test_unequal(mesh_a, mesh_b, "mismatched attributes")

attribute_b.append(k3d.color(1, 2, 3))
test_equal(mesh_a, mesh_b, "matched attributes")
Exemplo n.º 10
0
	# Add a single curve to the primitive ...
	curves.periodic().append(False)
	curves.material().append(None)
	curves.curve_first_points().append(len(curves.curve_points()))
	curves.curve_point_counts().append(len(positions))
	curves.curve_selections().append(0.0)
	for i in range(len(positions)):
		curves.curve_points().append(i)

	# Assign some widths to the curve ...
	widths = [0.1, 0.8, 0.8, 0.1]
	for w in widths:
		width.append(w)

	# Assign colors to the curve vertices ...
	colors = [k3d.color(1, 0, 0), k3d.color(0, 1, 0), k3d.color(0, 0, 1), k3d.color(1, 1, 1)]
	for color in colors:
		Cs.append(color)

	# Connect the FrozenMesh to a MeshInstance to place it in the scene ...
	mesh_instance = k3d.plugin.create("MeshInstance", context.document)
	mesh_instance.name = "Linear Curve 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")

	k3d.property.connect(context.document, frozen_mesh.get_property("output_mesh"), mesh_instance.get_property("input_mesh"))

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

	context.document.finish_change_set("Create Linear Curve")
Exemplo n.º 11
0
#python

import k3d
import testing

setup = testing.setup_bitmap_source_test("BitmapSolid")
setup.source.color = k3d.color(1, 1, 0)

testing.require_similar_bitmap(setup.document, setup.source.get_property("output_bitmap"), "BitmapSolid", 0)

Exemplo n.º 12
0
curves = k3d.linear_curve.create(context.output)

# Create an (optional) array to store curve widths
constantwidth = curves.constant_attributes().create("constantwidth", "k3d::double_t")

# Create an (optional) array to store per-curve curve colors
Cs = curves.curve_attributes().create("Cs", "k3d::color")

# Add curves ...
curves.periodic().append(False)
curves.material().append(None)
constantwidth.append(0.5)

for j in range(5):
	curves.curve_first_points().append(len(curves.curve_points()))
	curves.curve_point_counts().append(3)
	curves.curve_selections().append(0.0)

	curves.curve_points().append(len(points) + 0)
	curves.curve_points().append(len(points) + 1)
	curves.curve_points().append(len(points) + 2)

	positions = [(0, 0, 5), (5, 0, 0), (0, 0, -5)]

	for position in positions:
		points.append(k3d.point3(position[0] + (j * 5), position[1], position[2]))
		point_selection.append(0.0)

	Cs.append(k3d.color(1, 1, j * 0.2))

Exemplo n.º 13
0
#python

import k3d
k3d.check_node_environment(locals(), "MeshModifierScript")

from random import seed, randint

Output.copy(Input)

seed(123)

colors = [ k3d.color(1, 0, 0), k3d.color(1, 1, 0), k3d.color(0, 1, 0), k3d.color(0, 1, 1), k3d.color(0, 0, 1), k3d.color(1, 0, 1), k3d.color(1, 1, 1)]

for prim_idx, const_primitive in enumerate(Input.primitives()):
	if const_primitive.type() == "polyhedron":
		polyhedron = k3d.polyhedron.validate(Output, Output.primitives()[prim_idx])
		if polyhedron:
			Cs = polyhedron.edge_attributes().create("Cs", "k3d::color")
			for i in range(len(polyhedron.edge_points())):
				Cs.append(colors[i % len(colors)])

Exemplo n.º 14
0
#python

import k3d

context.output = k3d.color(1, 0.5, 0.25)

Exemplo n.º 15
0
#python

import k3d
k3d.check_node_environment(context, "MeshSourceScript")

# Perform required one-time setup to store geometric points in the mesh ...
points = context.output.create_points()
point_selection = context.output.create_point_selection()

# Construct a point group mesh primitive ...
particles = k3d.particle.create(context.output)

# Create an (optional) array to store per-group point widths
constantwidth = particles.constant_attributes().create("constantwidth", "k3d::double_t")

# Create an (optional) array to store per-point point colors
Cs = particles.vertex_attributes().create("Cs", "k3d::color")

# Add some points ...
particles.material().append(None)
constantwidth.append(0.5)

for x in range(-5, 6):
	for z in range (-5, 6):
		particles.points().append(len(points))

		points.append(k3d.point3(x, 0, z))
		point_selection.append(0.0)
		Cs.append(k3d.color((x / 10.0) + 0.5, 1, (z / 10.0) + 0.5))

Exemplo n.º 16
0
        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():
    blobby.floats().append(i)

# Assign colors to each ellipsoid and segment ...
Cs.assign([
    k3d.color(1, 0, 0),
    k3d.color(0, 1, 0),
    k3d.color(0, 0, 1),
    k3d.color(1, 1, 0),
    k3d.color(1, 1, 1)
])

# Add the ellipsoids and segment together to produce a surface ...
blobby.operators().append(k3d.blobby.operator_type.ADD)
blobby.operator_first_operands().append(len(blobby.operands()))
blobby.operator_operand_counts().append(6)
blobby.operands().assign([5, 0, 1, 2, 3, 4])
Exemplo n.º 17
0
#python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("BlobbyEllipsoid", document)
source1.color = k3d.color(1, 0, 0)

modifier = k3d.plugin.create("BlobbyNegate", document)

k3d.property.connect(document, source1.get_property("output_mesh"), modifier.get_property("input_mesh"))


testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"), "mesh.modifier.BlobbyNegate", 5)

Exemplo n.º 18
0
#python

import k3d
import testing

doc = k3d.new_document()
source = doc.new_node("BitmapSolid")
source.color = k3d.color(1, 1, 0)

testing.image_comparison(doc, source.get_property("output_bitmap"),
                         "BitmapSolid", 0)
# python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("BlobbyEllipsoid", document)
source1.color = k3d.color(1, 0, 0)

source2 = k3d.plugin.create("BlobbySegment", document)
source2.color = k3d.color(1, 1, 0)

modifier = k3d.plugin.create("BlobbyMultiply", document)
k3d.property.create(modifier, "k3d::mesh*", "input_mesh1", "Input Mesh 1", "")
k3d.property.create(modifier, "k3d::mesh*", "input_mesh2", "Input Mesh 2", "")

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"))


testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"), "mesh.modifier.BlobbyMultiply", 5)
Exemplo n.º 20
0
#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)
	attribute_array.append(value)
Exemplo n.º 21
0
    Cs = polyhedron.uniform_data().create("Cs", "k3d::color")

    polyhedron.shell_first_faces().append(len(polyhedron.face_first_loops()))
    polyhedron.shell_face_counts().append(3)
    polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)

    # Create three faces in each polyhedron ...
    for j in range(3):
        # Each face has a single loop (its exterior boundary) ...
        polyhedron.face_first_loops().append(len(
            polyhedron.loop_first_edges()))
        polyhedron.face_loop_counts().append(1)
        polyhedron.face_materials().append(None)
        polyhedron.face_selections().append(0.0)

        Cs.append(k3d.color(1, j / 2.0, i / 1.0))

        polyhedron.loop_first_edges().append(len(polyhedron.edge_points()))

        # Each loop has four edges, each of which points to the next edge in clockwise-order ...
        polyhedron.clockwise_edges().append(len(polyhedron.edge_points()) + 1)
        polyhedron.clockwise_edges().append(len(polyhedron.edge_points()) + 2)
        polyhedron.clockwise_edges().append(len(polyhedron.edge_points()) + 3)
        polyhedron.clockwise_edges().append(len(polyhedron.edge_points()) + 0)

        # Each edge refers to its starting-point ...
        polyhedron.edge_points().append(len(points) + 0)
        polyhedron.edge_points().append(len(points) + 1)
        polyhedron.edge_points().append(len(points) + 2)
        polyhedron.edge_points().append(len(points) + 3)
Exemplo n.º 22
0
#python

import k3d
import testing

setup = testing.setup_bitmap_source_test("BitmapSolid")
setup.source.color = k3d.color(1, 1, 0)

testing.require_similar_bitmap(setup.document,
                               setup.source.get_property("output_bitmap"),
                               "BitmapSolid", 0)
Exemplo n.º 23
0
	# Create an (optional) array to store per-face colors ...
	Cs = polyhedron.face_attributes().create("Cs", "k3d::color")

	polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)

	# Create three faces in each polyhedron ...
	for j in range(3):
		# Each face has a single loop (its exterior boundary) ...
		polyhedron.face_shells().append(0)
		polyhedron.face_first_loops().append(len(polyhedron.loop_first_edges()))
		polyhedron.face_loop_counts().append(1)
		polyhedron.face_materials().append(None)
		polyhedron.face_selections().append(0.0)

		Cs.append(k3d.color(1, j / 2.0, i / 1.0))

		polyhedron.loop_first_edges().append(len(polyhedron.clockwise_edges()))

		# Each loop has four edges, each of which points to the next edge in clockwise-order ...
		polyhedron.clockwise_edges().append(len(polyhedron.clockwise_edges()) + 1)
		polyhedron.clockwise_edges().append(len(polyhedron.clockwise_edges()) + 1)
		polyhedron.clockwise_edges().append(len(polyhedron.clockwise_edges()) + 1)
		polyhedron.clockwise_edges().append(len(polyhedron.clockwise_edges()) - 3)

		polyhedron.edge_selections().append(0.0)
		polyhedron.edge_selections().append(0.0)
		polyhedron.edge_selections().append(0.0)
		polyhedron.edge_selections().append(0.0)

		# Each edge has a vertex that references a mesh point ...
Exemplo n.º 24
0
    constantwidth = particles.constant_attributes().create(
        "constantwidth", "k3d::double_t")

    # 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")

    k3d.property.connect(context.document,
                         frozen_mesh.get_property("output_mesh"),
                         mesh_instance.get_property("input_mesh"))

    # Make the MeshInstance visible to render engines ...
    k3d.node.show(context.document, mesh_instance)
Exemplo n.º 25
0
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))
color.append(k3d.color(0, 0, 1))
color.append(k3d.color(0, 0, 1))
Exemplo n.º 26
0
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)

# Assign colors to each ellipsoid and segment ...
Cs.assign([k3d.color(1, 0, 0), k3d.color(0, 1, 0), k3d.color(0, 0, 1), k3d.color(1, 1, 0), k3d.color(1, 1, 1)])

# Add the ellipsoids and segment together to produce a surface ...
blobby.operators().append(k3d.blobby.operator_type.ADD)
blobby.operator_first_operands().append(len(blobby.operands()))
blobby.operator_operand_counts().append(6)
blobby.operands().assign([5, 0, 1, 2, 3, 4])

Exemplo n.º 27
0
#python

import k3d
import testing

document = k3d.new_document()

source1 = k3d.plugin.create("BlobbyEllipsoid", document)
source1.color = k3d.color(1, 0, 0)

source2 = k3d.plugin.create("BlobbySegment", document)
source2.color = k3d.color(1, 1, 0)

modifier = k3d.plugin.create("BlobbySubtract", document)

k3d.property.connect(document, source1.get_property("output_mesh"),
                     modifier.get_property("input_a"))
k3d.property.connect(document, source2.get_property("output_mesh"),
                     modifier.get_property("input_b"))

testing.require_valid_mesh(document, modifier.get_property("output_mesh"))
testing.require_similar_mesh(document, modifier.get_property("output_mesh"),
                             "mesh.modifier.BlobbySubtract", 5)
Exemplo n.º 28
0
#python

import k3d
import testing

doc = k3d.new_document()
source = doc.new_node("ColorSourceScript")

if source.output_color != k3d.color(1, 0.5, 0.25):
    raise "unexpected output_color: " + str(source.output_color)
Exemplo n.º 29
0
        "Cs", "k3d::color")

    positions = [(-5, 0, 5), (5, 0, 5), (0, -5, -5), (0, 5, -5)]
    for position in positions:
        points.append(k3d.point3(position[0], position[1], position[2]))
        point_selection.append(0.0)

    patch_selection.append(0)
    patch_materials.append(None)

    patch_points.append(0)
    patch_points.append(1)
    patch_points.append(2)
    patch_points.append(3)

    Cs.append(k3d.color(1, 0, 0))
    Cs.append(k3d.color(0, 1, 0))
    Cs.append(k3d.color(0, 0, 1))
    Cs.append(k3d.color(1, 1, 1))

    mesh_instance = doc.new_node("MeshInstance")
    mesh_instance.name = "Bilinear Patch Instance"
    mesh_instance.gl_painter = doc.get_node("GL Default Painter")
    mesh_instance.ri_painter = doc.get_node("RenderMan Default Painter")
    doc.set_dependency(mesh_instance.get_property("input_mesh"),
                       frozen_mesh.get_property("output_mesh"))

    doc.finish_change_set("Create Bilinear Patch")

except:
    doc.cancel_change_set()
Exemplo n.º 30
0
test_material.name = "test_material"

test_gl_mesh_painter = document.new_node("OpenGLPointPainter")
test_gl_mesh_painter.name = "test_gl_mesh_painter"

test_ri_mesh_painter = document.new_node("RenderManLinearCurvePainter")
test_ri_mesh_painter.name = "test_ri_mesh_painter"

test_ri_texture = document.new_node("RenderManTextureMap")
test_ri_texture.name = "test_ri_texture"

test_node = document.new_node("Axes")
test_node.name = "test_node"

create_property(test_container, "k3d::bool_t", True)
create_property(test_container, "k3d::color", k3d.color(1, 2, 3))
create_property(test_container, "k3d::double_t", 3.1415)
create_property(test_container, "k3d::filesystem::path",
                k3d.filesystem.generic_path("/foo/bar/baz"))
create_property(test_container, "k3d::gl::imesh_painter*",
                test_gl_mesh_painter)
create_property(test_container, "k3d::imaterial*", test_material)
create_property(test_container, "k3d::inode*", test_node)
create_property(test_container, "k3d::int32_t", 19700827)
create_property(test_container, "k3d::matrix4", k3d.scale3(1, 2, 3))
create_property(test_container, "k3d::normal3", k3d.normal3(1, 2, 3))
create_property(test_container, "k3d::point3", k3d.point3(1, 2, 3))
create_property(test_container, "k3d::point4", k3d.point4(1, 2, 3, 4))
create_property(test_container, "k3d::ri::imesh_painter*",
                test_ri_mesh_painter)
create_property(test_container, "k3d::ri::itexture*", test_ri_texture)
Exemplo n.º 31
0
#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))

polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)

polyhedron.face_shells().append(0)
polyhedron.face_first_loops().append(len(polyhedron.loop_first_edges()))
polyhedron.face_loop_counts().append(1)
polyhedron.face_materials().append(None)
polyhedron.face_selections().append(0)

polyhedron.loop_first_edges().append(len(polyhedron.clockwise_edges()))

polyhedron.clockwise_edges().append(1)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(0)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(1, 0, 0))

polyhedron.clockwise_edges().append(2)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(1)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(0, 1, 0))

polyhedron.clockwise_edges().append(3)
polyhedron.edge_selections().append(0)
polyhedron.vertex_points().append(4)
polyhedron.vertex_selections().append(0)
Cs.append(k3d.color(0, 0, 1))

polyhedron.clockwise_edges().append(0)
polyhedron.edge_selections().append(0)
Exemplo n.º 33
0
# Create an array to store per-curve curve colors ...
Cs = curves.curve_attributes().create("Cs", "k3d::color")

# Add some curves ...
curves.periodic().append(False)
curves.material().append(None)
constantwidth.append(0.5)

for j in range(5):
    curves.curve_first_points().append(len(curves.curve_points()))
    curves.curve_point_counts().append(7)
    curves.curve_selections().append(0.0)

    curves.curve_points().append(len(points) + 0)
    curves.curve_points().append(len(points) + 1)
    curves.curve_points().append(len(points) + 2)
    curves.curve_points().append(len(points) + 3)
    curves.curve_points().append(len(points) + 4)
    curves.curve_points().append(len(points) + 5)
    curves.curve_points().append(len(points) + 6)

    positions = [(0, 0, 5), (-5, 0, 5), (-5, 0, 0), (0, 0, 0), (5, 0, 0),
                 (5, 0, -5), (0, 0, -5)]
    for position in positions:
        points.append(
            k3d.point3(position[0] + (j * 5), position[1], position[2]))
        point_selection.append(0.0)

    Cs.append(k3d.color(1, 1, j * 0.2))
Exemplo n.º 34
0
#python

import k3d
import testing

setup = testing.setup_bitmap_source_test("BitmapChecker")
setup.source.color1 = k3d.color(1, 1, 0)
setup.source.color2 = k3d.color(0, 0, 1)

testing.require_similar_bitmap(setup.document,
                               setup.source.get_property("output_bitmap"),
                               "BitmapChecker", 0)
Exemplo n.º 35
0
                                       "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]
Exemplo n.º 36
0
test_unequal(mesh_a, mesh_b, "structure with missing array")

array_b = structure_b.create("indices", "k3d::uint_t")
test_equal(mesh_a, mesh_b, "structure with matched arrays")

array_a.append(5)
test_unequal(mesh_a, mesh_b, "mismatched structure arrays")

array_b.append(5)
test_equal(mesh_a, mesh_b, "matched structure_arrays")

attributes_a = primitive_a.attributes().create("uniform")
test_unequal(mesh_a, mesh_b, "primitive with missing attributes")

attributes_b = primitive_b.attributes().create("uniform")
test_equal(mesh_a, mesh_b, "matched primitive attributes")

attribute_a = attributes_a.create("Cs", "k3d::color")
test_unequal(mesh_a, mesh_b, "missing attribute arrays")

attribute_b = attributes_b.create("Cs", "k3d::color")
test_equal(mesh_a, mesh_b, "matched attribute arrays")

attribute_a.append(k3d.color(1, 2, 3))
test_unequal(mesh_a, mesh_b, "mismatched attributes")

attribute_b.append(k3d.color(1, 2, 3))
test_equal(mesh_a, mesh_b, "matched attributes")