Your browser does not support the video tag.
def tetrahedron(center, size): height = (size*math.sqrt(3))/2 constant = (size*math.sqrt(3))/3 a = [center[0]+constant, center[1], center[2]] b = [center[0]-(constant/2), center[1], center[2]-(size/2)] c = [center[0]-(constant/2), center[1], center[2]+(size/2)] d = [center[0], center[1]+height, center[2]] return [a,b,c,d]
def distort(data): data.sort(key = lambda x: x[1]) for vert in data: amp = random.uniform(0.5,1.5) vert[0] += amp*math.sin(vert[1]) return data
args = sys.stdin.readline() if args: arg = args.split() pixels = float(arg[0]) num = int(arg[1]) center = list(arg[2]) size = float(arg[3]) seed = list(arg[4]) radius = float(arg[5]) freq = float(arg[6]) amp = float(arg[7]) #generate sierpinski tetra = tetrahedron(center,size) verts = sierpinski(tetra,seed,num) distorted = distort(verts,freq,amp) #dynamic data: positional, color, then constant radius print('Points "P" [\n') for pnt in distorted: print(' %f %f %f\n' % (pnt[0],pnt[1],pnt[2])) print(']\n"constantwidth"[%f]\n' % (radius)) #Add color primvar print('"varying color cs" [\n') for pnt in distorted: r = uniform(0.0, 1.0) g = uniform(0.0, 1.0) b = uniform(0.0, 1.0) print(' %f %f %f\n' % (r,g,b)) print(']\n') sys.stdout.write('\377') sys.stdout.flush() # wait for the next set of inputs args = sys.stdin.readline()
import random import math import sys from sierpinski_arnold import getBounds def halfstep(p1, p2): # turn items to floats fp1 = [] fp2 = [] for n in p1: fp1.append(float(n)) for n in p2: fp2.append(float(n)) # average each point at each coord x = (fp1[0] + fp2[0])/2 y = (fp1[1] + fp2[1])/2 z = (fp1[2] + fp2[2])/2 return [x,y,z] #------------------------------------------------------------- def pickpnt(pnts): return random.choice(pnts) #------------------------------------------------------------- def tetrahedron(center, size): #build tetrahedron around center based on size #lines of symmetry are size*sqrt(3)/2 for equilateral triangle #A pnt [center+(size*sqrt(3)/3), 0, center] #B pnt [center-(size*sqrt(3)/6), 0, center-(size/2)] #C pnt [center-(size*sqrt(3)/6), 0, center+(size/2)] #D pnt [0, size, 0] height = (size*math.sqrt(3))/2 constant = (size*math.sqrt(3))/3 a = [center[0]+constant, center[1], center[2]] b = [center[0]-(constant/2), center[1], center[2]-(size/2)] c = [center[0]-(constant/2), center[1], center[2]+(size/2)] d = [center[0], center[1]+height, center[2]] return [a,b,c,d] #-------------------------------------------------------------- def sierpinski(verts, seed, num): data = [] for n in range(num): vert = pickpnt(verts) seed = halfstep(vert, seed) data.append(seed) return data #-------------------------------------------------------------- # sort pnts by y value, then distort x value with sine function def distort(data): data.sort(key = lambda x: x[1]) for vert in data: amp = random.uniform(0.5,1.5) vert[0] += amp*math.sin(vert[1]) return data
import sierpinski as sier def sierpinski_mel(data_path, num): center = [0,0,0] size = 2 tetra = sier.tetrahedron(center,size) seed = [0,0.5,0] data = sier.sierpinski(tetra, seed, num) #Open a data file (mel) f = open(data_path, 'w') f.write('particle \n') for pnt in data: f.write(' -p %f %f %f\n' % (pnt[0],pnt[1],pnt[2])) f.write('; \n') f.close() if __name__ == '__main__': sierpinski_mel('destination/test.mel', 1000)
import sierpinski as sier from sierpinski_arnold import getBounds from random import uniform def sierpinski_rman(data_path, num): #generate tetrahedron center = [0,0,0] size = 2 tetra = sier.tetrahedron(center,size) seed = [0,0.5,0] verts = sier.sierpinski(tetra, seed, num) distorted = sier.distort(verts) #------------------------------------------ #write rib bounds = getBounds(distorted) width = 0.01 #Open a data file (rib) f = open(data_path, 'w') #dynamic data: bounding box, positional, color, then constant width f.write('#bbox: {} {} {} {} {} {} \n'.format(*bounds)) f.write('Points "P" [\n') for pnt in distorted: f.write(' %f %f %f\n' % (pnt[0],pnt[1],pnt[2])) f.write(']\n"constantwidth"[%f]\n' % (width)) #Add color primvar f.write('"varying color cs" [\n') for pnt in distorted: r = uniform(0.0, 1.0) g = uniform(0.0, 1.0) b = uniform(0.0, 1.0) f.write(' %f %f %f\n' % (r,g,b)) f.write(']\n') f.close() if __name__ == '__main__': sierpinski_rman('destination/test.rib', 10000)
import time import sierpinski as sier def getBounds(verts): minx = min(verts, key=lambda x: x[0]) miny = min(verts, key=lambda x: x[1]) minz = min(verts, key=lambda x: x[2]) maxx = max(verts, key=lambda x: x[0]) maxy = max(verts, key=lambda x: x[1]) maxz = max(verts, key=lambda x: x[2]) bounds = [minx[0], miny[1], minz[2], maxx[0], maxy[1], maxz[2]] return bounds def sierpinski_arnold(data_path, num): center = [0,0,0] size = 2 tetra = sier.tetrahedron(center,size) seed = [0,0.5,0] data = sier.sierpinski(tetra, seed, num) verts = sier.distort(data) #------------------------------------------ now = time.strftime("%Y %m %d %H:%M") num_pnts = len(verts) bounds = getBounds(verts) radii = 0.01 rgb = [1,1,1] #Open a data file (arnold) f = open(data_path, 'w') f.write('### exported: %s\n' %(now)) f.write('### user: jkengl20\n') f.write('### bounds: {} {} {} {} {} {} \n'.format(*bounds)) #header junk f.write('### fps: 24.000000\n### render_layer: defaultRenderLayer\n### frame: 1.000000\npoints\n{\n name sierpinskiShape1\n visibility 255\n receive_shadows on\n self_shadows on\n matrix\n 1 0 0 0 \n 0 1 0 0 \n 0 0 1 0 \n 0 0 0 1 \n opaque on \n matte off \n mode "disk"\n min_pixel_width 0\n step_size 0\n declare rgbPP uniform RGB\n id 2669626448\n') #dynamic data: positional, radii, then color f.write(' points %i 1 VECTOR\n' % (num_pnts)) for pnt in verts: f.write(' %f %f %f\n' % (pnt[0],pnt[1],pnt[2])) f.write(' radius %i 1 FLOAT\n' % (num_pnts)) for pnt in verts: f.write(' %f\n' % (radii)) f.write(' rgbPP %i 1 RGB\n' % (num_pnts)) for pnt in verts: f.write(' %f %f %f\n' % (rgb[0],rgb[1],rgb[2])) f.write('} \n') f.close() if __name__ == '__main__': sierpinski_arnold('destination/test.ass', 10000)
import random import math import sys def halfstep(p1, p2): # turn items to floats fp1 = [] fp2 = [] for n in p1: fp1.append(float(n)) for n in p2: fp2.append(float(n)) # average each point at each coord x = (fp1[0] + fp2[0])/2 y = (fp1[1] + fp2[1])/2 z = (fp1[2] + fp2[2])/2 return [x,y,z] #------------------------------------------------------------- def pickpnt(pnts): return random.choice(pnts) #------------------------------------------------------------- def tetrahedron(center, size): #build tetrahedron around center based on size #lines of symmetry are size*sqrt(3)/2 for equilateral triangle #A pnt [center+(size*sqrt(3)/3), 0, center] #B pnt [center-(size*sqrt(3)/6), 0, center-(size/2)] #C pnt [center-(size*sqrt(3)/6), 0, center+(size/2)] #D pnt [0, size, 0] height = (size*math.sqrt(3))/2 constant = (size*math.sqrt(3))/3 a = [center[0]+constant, center[1], center[2]] b = [center[0]-(constant/2), center[1], center[2]-(size/2)] c = [center[0]-(constant/2), center[1], center[2]+(size/2)] d = [center[0], center[1]+height, center[2]] return [a,b,c,d] #-------------------------------------------------------------- def sierpinski(verts, seed, num): data = [] for n in range(num): vert = pickpnt(verts) seed = halfstep(vert, seed) data.append(seed) return data #-------------------------------------------------------------- # sort pnts by y value, then distort x value with sine function def distort(data, freq, amp): data.sort(key = lambda x: x[1]) for vert in data: vert[0] += amp*math.sin(freq*vert[1]) return data #-------------------------------------------------------------- #set up inputs from UI and write .rib by calling on functions above args = sys.stdin.readline() if args: arg = args.split() pixels = float(arg[0]) num = int(arg[1]) center = list(arg[2]) size = float(arg[3]) seed = list(arg[4]) radius = float(arg[5]) freq = float(arg[6]) amp = float(arg[7]) #generate sierpinski tetra = tetrahedron(center,size) verts = sierpinski(tetra,seed,num) distorted = distort(verts,freq,amp) #dynamic data: positional, color, then constant radius print('Points "P" [\n') for pnt in distorted: print(' %f %f %f\n' % (pnt[0],pnt[1],pnt[2])) print(']\n"constantwidth"[%f]\n' % (radius)) #Add color primvar print('"varying color cs" [\n') for pnt in distorted: r = uniform(0.0, 1.0) g = uniform(0.0, 1.0) b = uniform(0.0, 1.0) print(' %f %f %f\n' % (r,g,b)) print(']\n') sys.stdout.write('\377') sys.stdout.flush() # wait for the next set of inputs args = sys.stdin.readline()
rman "-version 1" { Declare param {int sierpinski_num} { label "Number of Points" subtype slider range {10 10000000 1000} description "No description." } Declare param {color sierpinski_center} { label "Center" description "Center point of the tetrahedron" } Declare param {float sierpinski_size} { label "Size" subtype slider range {0.005 20.0} description "Length of tetrahedron sides" } Declare param {color sierpinski_seed} { label "Seed Point" description "Starting seed point for sierpinski" } Declare param {float sierpinski_radius} { label "Radius" subtype slider range {0.005 20.0} description "Per point radius, constant" } Declare param {float sierpinski_freq} { label "Frequency" subtype slider range {0 100 1} description "Frequency of sine distortion" } Declare param {float sierpinski_amp} { label "Amplitude" subtype slider range {0 50 1} description "Amplitude of sine distortion" } # The Collection and NodeOptions blocks enable a Pre-Shape MEL script # to be assigned to "RenderMan Controls->Geometric Settings" panel. Collection sierpinski_OptionalGeometricSettings { param sierpinski_num { default 10 state optional } param sierpinski_center { default {0 0 0} state optional } param sierpinski_size { default 0.005 state optional } param sierpinski_seed { default {0 0.5 0} state optional } param sierpinski_radius { default 0.005 state optional } param sierpinski_freq { default 5 state optional } param sierpinski_amp { default 1 state optional } } NodeOptions {kGeometric kParticle} { reference Collection optionalGeometricSettings reference Collection sierpinski_OptionalGeometricSettings } }
// Generated by Cutter v7.8.1 // Cutter software by Malcolm Kesson (all rights reserved). global proc sierpinskiUI() { string $selected[] = `ls -sl`; int $i; for($i = 0; $i < size($selected); $i++ ) { string $shp[] = `listRelatives -shapes $selected[$i]`; // To add the UI implemented by this proc to the "Geometric // Settings" panel use the following mel commands, // select rmanSettings; // sierpinskiUI; // where "rmanSettings" might be rmanSettings1, rmanSettings2 etc. if(`nodeType $selected[$i]` == "RenderMan") $shp[0] = $selected[$i]; string $shapeName = $shp[0]; string $attr = `rmanGetAttrName "preShapeScript"`; // "Connect" to the mel script that calls // Pixar's custom Ri mel procedures. rmanAddAttr $shapeName $attr "sierpinskiRI"; $attr = `rmanGetAttrName "sierpinski_num"`; rmanAddAttr $shapeName $attr "10000"; $attr = `rmanGetAttrName "sierpinski_center"`; rmanAddAttr $shapeName $attr "{0 0 0}"; $attr = `rmanGetAttrName "sierpinski_size"`; rmanAddAttr $shapeName $attr "2"; $attr = `rmanGetAttrName "sierpinski_seed"`; rmanAddAttr $shapeName $attr "{0 0.5 0}"; $attr = `rmanGetAttrName "sierpinski_radius"`; rmanAddAttr $shapeName $attr "0.01"; $attr = `rmanGetAttrName "sierpinski_freq"`; rmanAddAttr $shapeName $attr "5"; $attr = `rmanGetAttrName "sierpinski_amp"`; rmanAddAttr $shapeName $attr "1"; } }
// Generated by Cutter v7.8.1 // Cutter software by Malcolm Kesson (all rights reserved). global proc sierpinskiRI() { // Get the name of the shape node string $shapeNode = `rman ctxGetObject`; string $parents[] = `listRelatives -parent $shapeNode`; string $tformNode = $parents[0]; // The node may hava a number in its name that we can use // to set the random number generator int $nodeNumber = `match "[0-9]+" $shapeNode`; if($nodeNumber != "") { seed(int($nodeNumber)); } // Bounding box... float $bb_width = `getAttr ($shapeNode + ".boundingBoxSizeX")`; float $bb_height = `getAttr ($shapeNode + ".boundingBoxSizeY")`; float $bb_depth = `getAttr ($shapeNode + ".boundingBoxSizeZ")`; string $attr; $attr = `rmanGetAttrName "sierpinski_num"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; int $sierpinski_num = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_center"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; vector $sierpinski_center = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_size"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; float $sierpinski_size = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_seed"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; vector $sierpinski_seed = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_radius"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; float $sierpinski_radius = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_freq"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; float $sierpinski_freq = `getAttr $attr`; $attr = `rmanGetAttrName "sierpinski_amp"`; $attr = `rmanGetFullSharedGeometricAttrName $shapeNode $attr`; float $sierpinski_amp = `getAttr $attr`; // Use of Pixar's custom RenderMan Studio procedures begins here. string $cmd; if(`about -win64`) $cmd = "\nProcedural \"RunProgram\" [\"python C:/Users/jmken/Documents/maya/scripts/sierpinski_helper.py\" "; else $cmd = "\nProcedural \"RunProgram\" [\"C:/Users/jmken/Documents/maya/scripts/sierpinski_helper.py\" "; $cmd += "\" " + $sierpinski_num; $cmd += " " + $sierpinski_center; $cmd += " " + $sierpinski_size; $cmd += " " + $sierpinski_seed; $cmd += " " + $sierpinski_radius; $cmd += " " + $sierpinski_freq; $cmd += " " + $sierpinski_amp + "\"] [-100 100 -100 100 -100 100]"; print($cmd + "\n"); RiArchiveRecord("structure", $cmd); // Make the proxy object inactive RiAttribute "visibility" "int camera" 0; RiAttribute "visibility" "int indirect" 0; RiAttribute "visibility" "int transmission" 0; } //__________________________________________________________ // A utility to create a rib path for an archive to be saved // in the project directories "data" folder. global proc string getArchivePath(string $nodename) { string $projpath = `workspace -q -rootDirectory`; string $datapath = $projpath + "data/"; string $scenename = `file -q -sceneName -shortName`; int $frame = `currentTime -q`; string $fstr = "0" + $frame; if($frame < 10) $fstr = "000" + $frame; else if($frame < 100) $fstr = "00" + $frame; $ribpath = $datapath + $nodename + "." + $fstr + ".rib"; return $ribpath; }