#--------------------------------------------------
# Function: onSimulationBegin
# 功能:开始模拟
#--------------------------------------------------
def onSimulationBegin():
# 定义 开始模型
def gui():
# 定义 一个小浮动窗口
scene.setGlobalVariableValue("problem", False)
# 场景.设置全局变量值(problem 和 False)
scene.setGlobalVariableValue("first", True)
# 场景.设置全局变量值(first 和 True)
def problem1(node):
# 定义 problem(节点)
if len(node) != 1:
# 如果 len(节点)!=1
scene.setGlobalVariableValue("problem", True)
# 场景.设置全局变量值(problem 和 True)
msg.show( ALERT_TYPE_CRITICAL, "Select 1 node!" )
# 列出来.显示(指定类型选择一个节点)
scene.message("You have to select one and only one node")
# 场景.提示信息(你必须选择一个节点)
def problem2():
# 定义 变量值2
if node1 == node2:
# 如果 节点1 == 节点2
scene.setGlobalVariableValue("problem", True)
msg.show( ALERT_TYPE_CRITICAL, "source and dest cannot be the same!!" )
scene.message("You have selected same emitter (source and dest) twice.")
msg = GUIMessageDialog.new()
dialog = GUINodesPickerDialog.new()
msg.show( ALERT_TYPE_INFORMATION, "Select source emitter" )
node1 = dialog.show( TYPE_EMITTER )
problem1(node1)
problem = scene.getGlobalVariableValue("problem")
if not problem :
msg.show( ALERT_TYPE_INFORMATION, "Select dest emitter" )
node2 = dialog.show( TYPE_EMITTER )
problem1(node2)
problem2()
problem = scene.getGlobalVariableValue("problem")
if not problem :
msg.show( ALERT_TYPE_INFORMATION, "Select marking object" )
node3 = dialog.show( TYPE_OBJECT )
problem1(node3)
problem2()
problem = scene.getGlobalVariableValue("problem")
if not problem :
form = GUIFormDialog.new()
options = [ "plane equation", "sphere radius" ]
form.addListField( "Type", options, 0 )
form.addBoolField( "save settings", True )
show = form.show()
if ( show == GUI_DIALOG_ACCEPTED ):
Type = form.getFieldValue("Type")
saves = form.getFieldValue("save settings")
scene.setGlobalVariableValue("Type", Type)
if not saves:
scene.setGlobalVariableValue("first", False)
elif ( show == GUI_DIALOG_REJECTED ):
scene.setGlobalVariableValue("problem", True)
scene.message("Dialog Rejected, skipping script")
emit = node1[0]
emit2 = node2[0]
obj = node3[0]
scene.setGlobalVariableValue("emit", emit)
scene.setGlobalVariableValue("emit2", emit2)
scene.setGlobalVariableValue("obj", obj)
def gui2():
form = GUIFormDialog.new()
form.addStringField( "source emitt", str(scene.getGlobalVariableValue("emit").getName()) )
form.addStringField( "dest emitt", str(scene.getGlobalVariableValue("emit2").getName()) )
form.addStringField( "marking mesh", str(scene.getGlobalVariableValue("obj").getName()) )
options = [ "plane equation", "sphere radius" ]
form.addListField( "Type", options, scene.getGlobalVariableValue("Type") )
form.addBoolField( "forget settings", False )
show = form.show()
if ( show == GUI_DIALOG_ACCEPTED ):
emit = form.getFieldValue("source emitt")
emit2 = form.getFieldValue("dest emitt")
obj = scene.getObject( str(form.getFieldValue("marking mesh") ) )
Type = form.getFieldValue("Type")
forget = form.getFieldValue("forget settings")
if not emit:
scene.setGlobalVariableValue("problem", problem=True)
else:
scene.setGlobalVariableValue("source emitt", emit)
if not emit2:
scene.setGlobalVariableValue("problem", problem=True)
else:
scene.setGlobalVariableValue("dest emitt", emit2)
if not obj:
scene.setGlobalVariableValue("problem", problem=True)
else:
scene.setGlobalVariableValue("obj", obj)
scene.setGlobalVariableValue("Type", Type)
if forget:
scene.setGlobalVariableValue("first", False)
elif ( show == GUI_DIALOG_REJECTED ):
scene.setGlobalVariableValue("problem", True)
scene.message("Dialog Rejected, skipping script")
def nogui():
emit = scene.getEmitter("Linear01")
emit2 = scene.getEmitter("Object01")
obj = scene.getObject("Cube03")
scene.setGlobalVariableValue("emit", emit)
scene.setGlobalVariableValue("emit2", emit2)
scene.setGlobalVariableValue("obj", obj)
if scene.getGlobalVariableValue("first") == None:
gui()
elif not scene.getGlobalVariableValue("first"):
gui()
else:
gui2()
problem = scene.getGlobalVariableValue("problem")
if problem:
msg = GUIMessageDialog.new()
msg.show( ALERT_TYPE_CRITICAL, "there was a problem so script will not work" )
scene.message("script is turned off because of error")
scene.message("--------")
pass
#--------------------------------------------------
# Function: onSimulationStep
# 功能:模拟设置
#--------------------------------------------------
def onSimulationStep():
# in case of better precision, but code of "def onSimulationFrame" here
pass
#--------------------------------------------------
# Function: onSimulationFrame
# 功能:模拟帧数
#--------------------------------------------------
def onSimulationFrame():
problem = scene.getGlobalVariableValue("problem")
if not problem :
emit = scene.getGlobalVariableValue("emit")
emit2 = scene.getGlobalVariableValue("emit2")
obj = scene.getGlobalVariableValue("obj")
Type = scene.getGlobalVariableValue("Type")
if not problem and Type == 0 :
for i in emit.getParticles():
p = i.getPosition()
v = i.getVelocity()
test = 0
for f in obj.getFaces():
indices = f.getIndices()
vpos = obj.getVertices()[indices[0]].getPosition()
n = f.getNormal()
d = -(n*vpos)
if ((n * p)+d) >0:
test = test + 1
if not test :
emit.removeParticle(i.getId())
emit2.addParticle(p, v) #comment out if You don't want new particles to be crated
if not problem and Type == 1 :
opos = obj.getParameter("Position")
rad = obj.getParameter("Scale").getY()
for i in emit.getParticles():
p = i.getPosition()
v = i.getVelocity()
if opos.distance(p) < rad/2:
emit.removeParticle(i.getId())
emit2.addParticle(p, v) #comment out if You don't want new particles to be created
pass
#--------------------------------------------------
# Function: onSimulationEnd
# 功能:模拟结束之后
#--------------------------------------------------
def onSimulationEnd():
pass
#--------------------------------------------------
# Function: onChangeToFrame
# 功能:指定帧数上的变化
#--------------------------------------------------
def onChangeToFrame():
pass
评论