【问题标题】:rotation from csv file in maxscript从maxscript中的csv文件旋转
【发布时间】:2015-11-07 09:42:52
【问题描述】:

希望有更好的 maxscript 知识的人可以帮助解决这个问题。 我有一个 csv 文件驱动 3dsmax 中一些虚拟助手的位置。我遇到的问题是让每个虚拟对象都有一个从 csv 文件驱动的本地旋转。这是我的 csv 文件中的一个示例(实际文件有数百个点):

0,  975.4222,   2181.8731,  0,  267,    360,    75,

第 1 到第 4 列命名该点并将其定位到 x y 和 z 坐标。列 5 6 和 7 表示围绕 x y z 的每个点的旋转值。这就是我挣扎的地方。如果我使用随机值运行我的代码,那么脚本将失败。但是,如果第 5 列的所有值都相同,并且第 6 列和第 7 列的值也相同,则脚本将运行,但每个虚拟对象将具有相同的旋转(显然)。我知道我一定做错了什么。任何帮助将非常感激。我目前的代码如下:

    -- open the file as text, read mode
f = openFile "c:\\Testtocsv003c.csv" mode:"rt"

prefabPoint = dummy name:"dummy"

-- if it opened successfully (exists, etc)...
if f != undefined do
(
    while not eof f do
    (
        -- Read a line from the file
        l = readline f
        -- turn that line into an array of strings using commas as delimiters
        lf = filterString l ","
        if (lf[1]!=undefined ) do
        (
            newPoint = instance prefabPoint
            newPoint.name = lf[1]
            x = lf[2] as float -- bracketed number reads column position from text file
            y = lf[3] as float -- bracketed number reads column position from text file
            z = lf[4] as float -- bracketed number reads column position from text file
            xRot = lf[5] as float
            yRot = lf[6] as float
            zRot = lf[7] as float   

            newPoint.pos = [x,y,z] 
            --creates point objects at xyz coordinates from text file. To offset by distance for example change to : [100*x,100*y,100*z]


            rotate newPoint (eulerangles xRot yRot zRot) --rotates point 

        )
    )
    close f
    delete prefabPoint
)

谢谢大家。哦,如果格式错误,对不起。这是我的第一篇文章。

保罗

【问题讨论】:

    标签: csv rotation 3dsmax maxscript


    【解决方案1】:

    这确实应该在评论中,但我没有足够的声誉。

    无论如何,我刚刚使用 500 个带有随机生成转换的虚拟对象成功运行了您的代码,并且运行良好。所以听起来这可能是内存问题,可能与打开的文件有关——我曾经写过一个脚本,打开一个文件来读取/写入值,当我在文件打开时进行操作时,我得到了一些奇怪的结果.所以这是我的建议:

    1. 将文件中的所有值读入一个数组,然后在实例化虚拟节点之前关闭文件。

    2. 包装您的操作并关闭撤消堆栈。这有时有助于在执行大量操作时解决内存问题:

    
        with undo off (
            if (lf[1]!=undefined ) do
            (
              -- create instances of dummy nodes here ...
            )
        )
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2014-02-17
      • 2018-10-04
      • 2015-11-10
      • 2011-11-23
      • 2012-10-05
      • 2023-04-01
      • 2018-09-14
      • 2020-10-22
      • 1970-01-01
      相关资源
      最近更新 更多