Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从自定义文件读取几何图形数据的最快方法_Python_Caching_Animation_Export_Maxscript - Fatal编程技术网

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

Python 从自定义文件读取几何图形数据的最快方法,python,caching,animation,export,maxscript,Python,Caching,Animation,Export,Maxscript,我正在尝试为Houdini和3D Max创建自定义点缓存格式。我已使用自定义ascii和xml文件在两个程序之间发送几何数据。该文件只是动画每一帧的向量列表。我基本上是循环通过文件中的向量,并在帧发生变化时设置对象在Houdini和Max中的位置。问题是,如果每一帧有超过500个向量,那么它开始变得太慢。我不知道是否有更有效的方法从文件中读取向量 我目前使用Python和Max脚本,但我考虑移动到C++并使用自定义二进制文件,但不认为这会有很大的不同。下面是胡迪尼的Python代码,使用的XML

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

我目前使用Python和Max脚本,但我考虑移动到C++并使用自定义二进制文件,但不认为这会有很大的不同。下面是胡迪尼的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>...
   .............

与maxscript相比,c++速度非常快

如果你问我,那是唯一的出路

<>我已经编写了几个与ASCII \xLM一起工作的出口商进口商,在Max和C++中,以及C++插件,如果你想要速度,这是一条路。 同时,以二进制形式写入\读取使其速度更快