从自定义文件中读取几何数据的最快方法

时间:2011-08-11 17:20:02

标签: python caching animation export maxscript

我正在尝试为Houdini和3D Max创建自定义点缓存格式。我已设法使用自定义的ascii和xml文件在两个程序之间发送几何数据。该文件只是每帧动画的矢量列表。我基本上循环遍历文件中的向量,并在帧变化时设置Houdini和Max中的对象位置。问题是,如果每帧有超过500个向量,那么它开始变得太慢。我不知道是否有更有效的方法从文件中读取向量。

我目前正在使用Python和Maxscript,但我正在考虑转向使用C ++并使用自定义二进制文件,但不要认为这会产生很大的不同.Below是来自houdini的Python代码使用xml文件似乎更快一点而不是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>...
   .............

1 个答案:

答案 0 :(得分:0)

与maxscript相比,c ++非常快。

如果你问我这是唯一的出路。

我已经编写了几个与ascii \ xlm一起使用的导出器\导入器,无论是在maxscript还是c ++中,如果你想要速度,这就是c ++插件。 写入\ read作为二进制文件也会更快。

相关问题