How to use the k3d.point3 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 / mesh / mesh.modifier.LeastSquaresPlot.py View on Github external
#python

import k3d
import testing

setup = testing.setup_mesh_modifier_test("FrozenMesh", "LeastSquaresPlot")

mesh = setup.source.create_mesh()

positions = [(-5, 1, 3), (4, 2, 4), (3, 3, -5), (-4, 4, -3)]

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)

k3d.property.create(setup.modifier, "k3d::string_t","function_1", "Function 1", "Function 1")
k3d.property.create(setup.modifier, "k3d::string_t","function_2", "Function 2", "Function 2")
k3d.property.create(setup.modifier, "k3d::string_t","function_3", "Function 3", "Function 3")

setup.modifier.function_1 = "u^2"
setup.modifier.function_2 = "sin(v)"
setup.modifier.function_3 = "u*v"

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.source.LeastSquaresPlot", 4096)
github K-3D / k3d / tests / mesh / mesh.modifier.TriangulateFaces.vertex.py View on Github external
import k3d
import testing

setup = testing.setup_mesh_modifier_test("FrozenMesh", "TriangulateFaces")

mesh = setup.source.create_mesh()

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

polyhedron = k3d.polyhedron.create(mesh)
Cs = polyhedron.vertex_attributes().create("Cs", "k3d::color")

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

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)
github K-3D / k3d / share / scripts / MeshSourceScript / blobby.py View on Github external
#python

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

blobby = k3d.blobby.create(context.output)
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_list():
		blobby.floats().append(i)

# Add a segment to the blobby ...
blobby.primitives().append(k3d.blobby.primitive_type.SEGMENT)
github K-3D / k3d / share / scripts / scripted_plugins / create_trim_curve.py View on Github external
for i in range(segments):
  trim_curve_point_weights.append(weight)
  trim_curve_point_weights.append(1)
#trim_curve_point_weights.append(weight)

#control points
X = k3d.point3(1, 0, 0)
Y = k3d.point3(0, 1, 0)

trim_points.append(math.cos(start_angle) * k3d.point2(0.75, 0.5) + math.sin(start_angle) * k3d.point2(0.5, 0.75))
for i in range(segments):
  a0 = start_angle + (theta * (i))
  a2 = start_angle + (theta * (i + 1))

  p0 = k3d.point3(math.cos(a0) * X + math.sin(a0) * Y)
  p2 = k3d.point3(math.cos(a2) * X + math.sin(a2) * Y)

  t0 = k3d.point3(-math.sin(a0) * X + math.cos(a0) * Y)
  t2 = k3d.point3(-math.sin(a2) * X + math.cos(a2) * Y)

  p1 = k3d.point3(0, 0, 0)
  k3d.intersect_lines(p0, k3d.to_vector3(t0), p2, k3d.to_vector3(t2), p1)

  trim_points.append(k3d.point2(0.25*p1[0] + 0.5, 0.25*p1[1] + 0.5))
  trim_points.append(k3d.point2(0.25*p2[0] + 0.5, 0.25*p2[1] + 0.5))

for i in range(len(trim_points)):
  trim_point_selection.append(0)

for i in range(2*segments):
  trim_curve_points.append(i)
trim_curve_points.append(0)
github K-3D / k3d / share / scripts / create_linear_curve.py View on Github external
import k3d

context.document.start_change_set()
try:
	# Create a FrozenMesh node to act as a mesh source ...
	frozen_mesh = k3d.plugin.create("FrozenMesh", context.document)
	frozen_mesh.name = "Linear Curve"

	# Create a mesh ...
	mesh = frozen_mesh.create_mesh()

	# Add geometric points to the mesh ...
	points = mesh.create_points()
	point_selection = mesh.create_point_selection()

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

	# Create a linear curve primitive ...
	curves = k3d.linear_curve.create(mesh)

	# Create a custom attribute array to control the width of the curve ...
	width = curves.vertex_attributes().create("width", "k3d::double_t")

	# Create a custom attribute array to store color values at each curve vertex ...
	Cs = curves.vertex_attributes().create("Cs", "k3d::color")

	# Add a single curve to the primitive ...
	curves.periodic().append(False)
	curves.material().append(None)
github K-3D / k3d / share / scripts / MeshSourceScript / linear_curves.py View on Github external
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))
github K-3D / k3d / share / scripts / create_cubic_curve.py View on Github external
import k3d

context.document.start_change_set()
try:
	# Create a FrozenMesh node to act as a mesh source ...
	frozen_mesh = k3d.plugin.create("FrozenMesh", context.document)
	frozen_mesh.name = "Cubic Curve"

	# Create a mesh ...
	mesh = frozen_mesh.create_mesh()

	# Add geometric points to the mesh ...
	points = mesh.create_points()
	point_selection = mesh.create_point_selection()

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

	# Create a cubic curve primitive ...
	curves = k3d.cubic_curve.create(mesh)

	# Create a custom attribute array to control the width of the curve ...
	width = curves.constant_attributes().create("constantwidth", "k3d::double_t")

	# Create a custom attribute array to store color values at each curve vertex ...
	Cs = curves.vertex_attributes().create("Cs", "k3d::color")

	# Add a single curve to the primitive ...
	curves.periodic().append(False)
	curves.material().append(None)
github K-3D / k3d / share / scripts / scripted_plugins / create_trim_curve.py View on Github external
trim_curve_point_weights.append(1)
for i in range(segments):
  trim_curve_point_weights.append(weight)
  trim_curve_point_weights.append(1)
#trim_curve_point_weights.append(weight)

#control points
X = k3d.point3(1, 0, 0)
Y = k3d.point3(0, 1, 0)

trim_points.append(math.cos(start_angle) * k3d.point2(0.75, 0.5) + math.sin(start_angle) * k3d.point2(0.5, 0.75))
for i in range(segments):
  a0 = start_angle + (theta * (i))
  a2 = start_angle + (theta * (i + 1))

  p0 = k3d.point3(math.cos(a0) * X + math.sin(a0) * Y)
  p2 = k3d.point3(math.cos(a2) * X + math.sin(a2) * Y)

  t0 = k3d.point3(-math.sin(a0) * X + math.cos(a0) * Y)
  t2 = k3d.point3(-math.sin(a2) * X + math.cos(a2) * Y)

  p1 = k3d.point3(0, 0, 0)
  k3d.intersect_lines(p0, k3d.to_vector3(t0), p2, k3d.to_vector3(t2), p1)

  trim_points.append(k3d.point2(0.25*p1[0] + 0.5, 0.25*p1[1] + 0.5))
  trim_points.append(k3d.point2(0.25*p2[0] + 0.5, 0.25*p2[1] + 0.5))

for i in range(len(trim_points)):
  trim_point_selection.append(0)

for i in range(2*segments):
  trim_curve_points.append(i)
github K-3D / k3d / share / scripts / MeshSourceScript / bicubic_patches.py View on Github external
# We will create two identical bicubic patches ...
for i in range(2):
	patches.patch_selections().append(0)
	patches.patch_materials().append(None)

	for j in range(16):
		patches.patch_points().append(len(points) + j)

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

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

	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))
github K-3D / k3d / modules / scripting / mesh_source_script.py View on Github external
#python

import k3d

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

points = Output.create_points()
point_selection = Output.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(Output)
polyhedron.shell_types().append(k3d.polyhedron.shell_type.POLYGONS)
polyhedron.face_shells().append(0)
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.clockwise_edges().assign([1, 2, 3, 0])
polyhedron.edge_selections().assign([0, 0, 0, 0])
polyhedron.vertex_points().assign([0, 1, 2, 3])
polyhedron.vertex_selections().assign([0, 0, 0, 0])