0
我試圖爲Houdini和3D Max創建自定義點緩存格式。我設法使用自定義ascii和xml文件在兩個程序之間發送幾何數據。該文件只是每個動畫幀的矢量列表。我基本上是循環遍歷文件中的矢量,並在框架更改時設置Houdini和Max中的對象位置。問題是,如果每幀有超過500個矢量,那麼它開始變得太慢。我不知道是否有更有效的方法從文件中讀取矢量。從定製文件中讀取幾何數據的最快方法
我目前正在使用Python和Maxscript,但我正在考慮轉移到C++和使用自定義二進制文件,但不認爲這會造成很大的區別。下面是從houdini使用xml文件,這似乎是一個小的Python代碼比ascii文件更快。
import os
import xml.etree.ElementTree
#XML file
if hou.frame() == 1:
filePath = os.path.abspath("F:\My Documents\Work\University\Year 3\Final Majour Project\Output_Test.xml")
xmlFile = xml.etree.ElementTree.parse(filePath)
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
# Add code to modify the contents of geo.
def moveObjectDef():
sceneTime = int(hou.frame()) #Current frame time
frameTag = xmlFile.findall('frame')
frameValue = frameTag[sceneTime].get('currentFrame')
frame = int(frameValue.rstrip('f'))
objectTag = xmlFile.findall('frame/object')
objectVertAmount = objectTag[frame].get('vertcount')
vertsTagList = list(objectTag[frame].getiterator('verts'))
for v in range(int(objectVertAmount)): #Looping through vert list
vert = eval(vertsTagList[v].text)
hou.node('/obj/geo1/newop1').geometry().points()[v].setPosition([vert[0],vert[2],vert[1]]) #Setting point poistion
moveObjectDef()
xml文檔佈局
<?xml version="1.0"?>
<root>
<frame currentFrame="0f">
<object transform="(matrix3 [1,0,0] [0,1,0] [0,0,1] [-74.0923,-1.78125,0])" vertcount="482">
<verts>[-74.0923,-1.78125,25.9382]</verts>
<verts>[-74.0923,3.27904,25.4398]</verts>...
.............