(n)certainties

GSAPP-Fall 2012

(n)certainties header image 3

MagmaticContengencies

1. Realflow to Rhino exporter

#############################################################################
script written by Mengna Miao, Carson Russell, Ezio Blasetti, Farzin Lotfijam
script version Dec. 4, 2012
#############################################################################

#paste it in realflow script deamon & replace the name of the emitter
#export particle information every frame

#————————————————–
# Function: onSimulationBegin
# This function is called by the simulation engine
# when the simulation begins.
#————————————————–

def onSimulationBegin():
scene.setGlobalVariableValue(“ticker”, 0)

#————————————————–
# Function: onSimulationResume
# This function is called by the simulation engine
# when the simulation resumes.
#————————————————–

def onSimulationResume():
pass

#————————————————–
# Function: onSimulationStop
# This function is called by the simulation engine
# when the simulation stops.
#————————————————–

def onSimulationStop():
pass

#————————————————–
# Function: onSimulationFrame
# This function is called by the simulation engine
# when the simulation starts the computation of the.
# next frame.
#————————————————–

def onSimulationFrame( frame ):

ticker = scene.getGlobalVariableValue(“ticker”)
tickerString = str(ticker)

pl = open(“/poslava” + tickerString + “.txt”, ‘w’)
vl = open(“/vellava” + tickerString + “.txt”, ‘w’)
tl = open(“/templava” + tickerString + “.txt”, ‘w’)

allParticles =lava.getParticles()
for particle in allParticles :
Vel = particle.getVelocity()
Pos = particle.getPosition()

xPOS = str(Pos.getX())
yPOS = str(Pos.getY())
zPOS = str(Pos.getZ())

xVEL = str(Vel.getX())
yVEL = str(Vel.getY())
zVEL = str(Vel.getZ())

TEMP = str(particle.getTemperature())

pl.write(xPOS + “,” + yPOS + “,” + zPOS + “#”)
vl.write(xVEL + “,” + yVEL + “,” + yVEL + “#”)
tl.write(TEMP + “#”)

######
pi = open(“/posice” + tickerString + “.txt”, ‘w’)
vi = open(“/velice” + tickerString + “.txt”, ‘w’)
ti = open(“/tempice” + tickerString + “.txt”, ‘w’)

allParticles =solid.getParticles()
for particle in allParticles :
Vel = particle.getVelocity()
Pos = particle.getPosition()

xPOS = str(Pos.getX())
yPOS = str(Pos.getY())
zPOS = str(Pos.getZ())

xVEL = str(Vel.getX())
yVEL = str(Vel.getY())
zVEL = str(Vel.getZ())

TEMP = str(particle.getTemperature())

pi.write(xPOS + “,” + yPOS + “,” + zPOS + “#”)
vi.write(xVEL + “,” + yVEL + “,” + yVEL + “#”)
ti.write(TEMP + “#”)

######
pli = open(“/posliq” + tickerString + “.txt”, ‘w’)
vli = open(“/velliq” + tickerString + “.txt”, ‘w’)
tli = open(“/templiq” + tickerString + “.txt”, ‘w’)

allParticles =liquid.getParticles()
for particle in allParticles :
Vel = particle.getVelocity()
Pos = particle.getPosition()

xPOS = str(Pos.getX())
yPOS = str(Pos.getY())
zPOS = str(Pos.getZ())

xVEL = str(Vel.getX())
yVEL = str(Vel.getY())
zVEL = str(Vel.getZ())

TEMP = str(particle.getTemperature())

pli.write(xPOS + “,” + yPOS + “,” + zPOS + “#”)
vli.write(xVEL + “,” + yVEL + “,” + yVEL + “#”)
tli.write(TEMP + “#”)

######
pg = open(“/posgas” + tickerString + “.txt”, ‘w’)
vg = open(“/velgas” + tickerString + “.txt”, ‘w’)
tg = open(“/tempgas” + tickerString + “.txt”, ‘w’)

allParticles =gas.getParticles()
for particle in allParticles :
Vel = particle.getVelocity()
Pos = particle.getPosition()

xPOS = str(Pos.getX())
yPOS = str(Pos.getY())
zPOS = str(Pos.getZ())

xVEL = str(Vel.getX())
yVEL = str(Vel.getY())
zVEL = str(Vel.getZ())

TEMP = str(particle.getTemperature())

pg.write(xPOS + “,” + yPOS + “,” + zPOS + “#”)
vg.write(xVEL + “,” + yVEL + “,” + yVEL + “#”)
tg.write(TEMP + “#”)

ticker+=1
scene.setGlobalVariableValue(“ticker”, ticker)

#————————————————–
# Function: applyForceToEmitter
# This function is called by the simulation engine
# when external forces should be applied to the
# particles in the emitter.
#————————————————–

def applyForceToEmitter( emitter ):
pass

#————————————————–
# Function: applyForceToBody
# This function is called by the simulation engine
# when external forces should be applied to the body.
#————————————————–

def applyForceToBody( body ):
pass

#————————————————–
# Function: applyForceToMultiBody
# This function is called by the simulation engine
# when external forces should be applied to the body.
#————————————————–

def applyForceToMultiBody( multiBody ):
pass

#————————————————–
# Function: applyForceToMist
# This function is called by the simulation engine
# when external forces should be applied to the mist.
#————————————————–

def applyForceToMist( mist ):
pass

#————————————————–
# Function: applyForceToGridFluid
# This function is called by the simulation engine
# when external forces should be applied to the grid fluid.
#————————————————–

def applyForceToGridFluid( gridFluid ):
pass

#————————————————–
# Function: removeParticles
# This function is called by the simulation engine
# when it is safe to remove particles.
#————————————————–

def removeParticles( emitter ):
pass

2. Realflow to Rhino importer

#############################################################################
script written by Mengna Miao, Carson Russell, Ezio Blasetti, Farzin Lotfijam
script version Dec. 4, 2012
#############################################################################

#paste it in python for Rhino & set your layers, ticker, scale factor(divide)

import rhinoscriptsyntax as rs

#import format: #x,y,z#x,y,z#x,y,z#

ticker=”38″

divide=20

#replace file name
fP = open(‘/poslava’+ticker+’.txt’, ‘r’)
fV = open(‘/vellava’+ticker+’.txt’, ‘r’)
fT = open(‘/templava’+ticker+’.txt’, ‘r’)

starts=[]
ends=[]
#r=0.01

#read file
for numberP in fP:
separateP=numberP.split(“#”)

for numberV in fV:
separateV=numberV.split(“#”)

for numberT in fT:
separateT=numberT.split(“#”)

#create points and lines
for i in range (len(separateP)):
start=separateP[i]
sphere=rs.AddPoint(start)
tem=float(separateT[i])
end=rs.PointAdd(start,separateV[i])
vector=rs.VectorCreate(end,start)
vector=rs.VectorDivide(vector,divide)
end=rs.VectorAdd(start,vector)
line=rs.AddLine(start,end)

#assign layer (create layers before running)
if tem>1440:
rs.ObjectLayer(line, “1500-1440”)
rs.ObjectLayer(sphere, “1500-1440 p”)
elif tem1400:
rs.ObjectLayer(line, “1440-1400”)
rs.ObjectLayer(sphere, “1440-1400 p”)
elif tem1300:
rs.ObjectLayer(line, “1400-1300”)
rs.ObjectLayer(sphere, “1400-1300 p”)
elif tem1200:
rs.ObjectLayer(line, “1300-1200”)
rs.ObjectLayer(sphere, “1300-1200 p”)
elif tem1100:
rs.ObjectLayer(line, “1200-1100”)
rs.ObjectLayer(sphere, “1200-1100 p”)
elif tem1000:
rs.ObjectLayer(line, “1100-1000”)
rs.ObjectLayer(sphere, “1100-1000 p”)
elif tem900:
rs.ObjectLayer(line, “1000-900”)
rs.ObjectLayer(sphere, “1000-900 p”)
elif tem800:
rs.ObjectLayer(line, “900-800”)
rs.ObjectLayer(sphere, “900-800 p”)
elif tem700:
rs.ObjectLayer(line, “800-700”)
rs.ObjectLayer(sphere, “800-700 p”)
elif tem600:
rs.ObjectLayer(line, “700-600”)
rs.ObjectLayer(sphere, “700-600 p”)
elif tem500:
rs.ObjectLayer(line, “600-500”)
rs.ObjectLayer(sphere, “600-500 p”)
elif tem400:
rs.ObjectLayer(line, “500-400”)
rs.ObjectLayer(sphere, “500-400 p”)
else:
rs.ObjectLayer(line, “400”)
rs.ObjectLayer(sphere, “400 p”)

3. Water Spray in Rhino

#############################################################################
script written by Ezio Blasetti
script version Dec. 4, 2012
#############################################################################

import rhinoscriptsyntax as rs

def MeshVtxCloseEnoughVtxs(mesh, index, threshold):
returnlist = []
vtxs = rs.MeshVertices(mesh)
for i in range(len(vtxs)):
if i!=index:
dist = rs.Distance(vtxs[index],vtxs[i])
if dist <threshold:
returnlist.append(i)
return returnlist

def Main():
strMesh = rs.GetObject(“select the mesh to navigate”,32)
vtxRadious = rs.GetReal(“please type the radious for the vtx neighborhood”, 1)
arrStrAttr = rs.GetObjects(“select the attractors”,1)
attrRadious = rs.GetReal(“please type the radious for the attractor”, 9.7)

arrAttr = []
for i in range(len(arrStrAttr)):
arrAttr.append( rs.PointCoordinates(arrStrAttr[i]) )

arrPoints = rs.MeshVertices (strMesh)

for i in range(len(arrPoints)):
arrPt0 = arrPoints[i]
indexAttr = rs.PointArrayClosestPoint(arrAttr,arrPt0)
arrClosestAttr = arrAttr[indexAttr]
distfromVtx2ClosestAttr = rs.Distance(arrPt0, arrClosestAttr)
if distfromVtx2ClosestAttr< attrRadious:
#arrneighborsIndex = MeshVtxAdjacentVtxs (strMesh, i)
arrneighborsIndex = MeshVtxCloseEnoughVtxs(strMesh, i, vtxRadious)
arrNeighbors = []
for j in range( len(arrneighborsIndex)):
arrNeighbors.append( arrPoints[arrneighborsIndex[j]] )
if len(arrNeighbors)>-1 :
index = rs.PointArrayClosestPoint(arrNeighbors,arrClosestAttr)
arrPt1 = arrNeighbors[index]
rs.AddLine(arrPt0,arrPt1)
Main()