#python import k3d k3d.check_node_environment(context, "OpenGLPainterScript") from OpenGL.GL import * points = context.mesh.points() if points: glPushAttrib(GL_ALL_ATTRIB_BITS) glDisable(GL_LIGHTING) glEnable(GL_POINT_SMOOTH) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE) glPointSize(3) glColor3d(1, 1, 1) glBegin(GL_POINTS) for point in points: glVertex3d(point[0], point[1], point[2]) glEnd() glPointSize(7) glColor3d(0.05, 0.05, 1) glBegin(GL_POINTS) for point in points:
#python import k3d k3d.check_node_environment(locals(), "MeshModifierScript") from math import fmod from cgkit.noise import vsnoise time = Node.time gravity = Node.gravity z1 = Node.z1 z2 = Node.z2 dz = z2 - z1 Output.copy(Input) points = Output.points() for i in range(len(points)): point = points[i] wiggle = 10 * vsnoise((point[0], point[1], point[2]), time / 2) point[0] += wiggle.x point[1] += wiggle.y point[2] += wiggle.z point[2] = fmod((point[2] + (time * gravity) - z1), dz) + z1 points[i] = point
#python import k3d k3d.check_node_environment(locals(), "MeshSourceScript") blobby = k3d.blobby.create(Output) Cs = blobby.varying_data().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(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 ...
#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() # Perform required one-time setup to store cubic curves in the mesh ... curves = k3d.cubic_curve.create(context.output) # Create an array to store constant curve widths ... constantwidth = curves.constant_attributes().create("constantwidth", "k3d::double_t") # 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)
#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))
#python # Sample RenderEngineScript input # # Use the following context variables for rendering: # # "context.document" - a reference to the owning document. # "context.node" - a reference to the owning node. # "context.visible_nodes" - the collection of nodes that should be # rendered, if possible. # "context.output_image" - path to the user-selected output file. # "context.view_image" - boolean indicating whether the output should # be displayed after rendering is complete. # This trivial example "renders" the document by writing # the name of each visible node to a text file. The set of # visible nodes is chosen by the user at runtime via the # "Visible Nodes" property. import k3d k3d.check_node_environment(locals(), "RenderEngineScript") output = open(str(context.output_image), "w") for node in context.visible_nodes: output.write(node.name + "\n") output.close()
#python # Load this script into a RenderManScript node to create # what is either a Tribble or a really bad-hair-day ... import k3d k3d.check_node_environment(context, "RenderManScript") import sys import ri from ri import * from random import * from cgtypes import vec3 from noise import vsnoise from sl import mix message = """You're probably trying to run this script manually, which won't work - this script is meant to be loaded into a RenderManScript node, where it will be run at render-time. Use the Create > RenderMan > RenderManScript menu item to create the node, then load this file into its Script property.""" if not context.has_key("archive"): k3d.ui.error_message(message) raise # Redirect output to our RIB archive ri._ribout = open(str(context.archive), "w") body_size = 5 lumpyness = 1 hair_length = 2 hair_count = 10000
#python import k3d k3d.check_node_environment(locals(), "RenderEngineScript") graph = """ digraph G { node [ shape="box" style="filled" color="black" fillcolor="white" ]; """ for node in Document.nodes(): graph += str(node.__hash__()) graph += "[\n" graph += "label=\"" + node.name + "\"\n" graph += "URL=\"http://www.k-3d.org/wiki/" + node.factory().name + "\"\n" graph += "]\n" for node in Document.nodes(): for prop in node.properties(): if prop.type == "k3d::inode*": referenced_node = prop.internal_value if referenced_node: graph += str(referenced_node.__hash__()) + "->" + str( node.__hash__()) graph += "[\n" graph += "style=dotted\n" graph += "label=\"" + prop.name + "\"\n"
#python import k3d k3d.check_node_environment(locals(), "MeshPainterScript") from OpenGL.GL import * points = Mesh.points() if points: glPushAttrib(GL_ALL_ATTRIB_BITS) glDisable(GL_LIGHTING) glEnable(GL_POINT_SMOOTH) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE) glPointSize(3) glColor3d(1, 1, 1) glBegin(GL_POINTS) for point in points: glVertex3d(point[0], point[1], point[2]) glEnd() glPointSize(7) glColor3d(0.05, 0.05, 1) glBegin(GL_POINTS) for point in points:
#python # Load this script into a K-3D RenderManScript object to create # what is either a Tribble or a really bad-hair-day ... import k3d k3d.check_node_environment(locals(), "RenderManScript") import sys import ri from ri import * from random import * from cgtypes import vec3 from noise import vsnoise from sl import mix message = """You're probably trying to run this script manually, which won't work - this script is meant to be loaded into a RenderManScript node, where it will be run at render-time. Use the Create > RenderMan > RenderManScript menu item to create the node, then load this file into its Script property.""" try: Archive except: k3d.ui.error_message(message) raise # Redirect output to our RIB archive ri._ribout = open(Archive, "w") body_size = 5 lumpyness = 1