注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Sonny

Hakuna Matata …………

 
 
 

日志

 
 
关于我

……要相信生活是美好的,幸福会到来的。…… QQ 20646620

网易考拉推荐
GACHA精选

RealFlow 脚本控制一篇  

2011-03-01 17:29:12|  分类: RealFlow |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
#还没弄明白先放这慢慢弄了。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
    pass

#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
    pass

#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
    pass

#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
    pass

#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
    pass

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#--------------------------------------------------
# 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

  评论这张
 
阅读(1193)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017