我想知道是否可以從逗號分隔的文件導入Blender的姿態和位置數據(滾動/俯仰/偏航& xyz)?如何從csv文件導入xyz和滾動/俯仰/偏航到Blender?
我記錄了一輛小型遙控車的數據,我想表示它在3D世界中的運動。
我也有時間戳,所以如果有一種方法來動畫物體的運動,它會非常棒!
任何幫助將不勝感激!
最好的問候。
我想知道是否可以從逗號分隔的文件導入Blender的姿態和位置數據(滾動/俯仰/偏航& xyz)?如何從csv文件導入xyz和滾動/俯仰/偏航到Blender?
我記錄了一輛小型遙控車的數據,我想表示它在3D世界中的運動。
我也有時間戳,所以如果有一種方法來動畫物體的運動,它會非常棒!
任何幫助將不勝感激!
最好的問候。
對於攪拌機v2.62:
如果你有一個文件「positions.log」看起來像:
-8.691985196313894e-002; 4.119284642631801e-001; -5.832147659661263e-001
1.037146774956164e+000; 8.137243553005405e-002; -5.703274929662892e-001
-3.602584527944123e-001; 8.378614512537046e-001; 2.615265921163826e-001
6.266465707681335e-001; -1.128416901202341e+000; -1.664644365541639e+000
3.327523280880091e-001; 4.488553740582839e-001; -2.449449085462368e+000
-7.311567199869298e-001; -1.860587923723032e+000; -1.297179602213110e+000
-7.453603745688361e-003; 4.770473577895327e-001; -2.319515785100494e+000
1.935170866863264e-001; -2.010280476717868e+000; 3.748000986190077e-001
5.201529166915653e-001; 3.952972788761738e-001; 1.658581747430548e+000
4.719198263774027e-001; 1.526020825619557e+000; 3.187088567866725e-002
您可以在此攪拌器python腳本讀取它(注意縮進!)
import bpy
from mathutils import *
from math import *
from bpy.props import *
import os
import time
# Init
position_vector = []
# Open file
file = open("C:\\Work\\position.log", "r")
# Loop over line in file
for line in file:
# Split line at ";"
splittet_line = line.split(";")
# Append new postion
position_vector.append(
Vector((float(splittet_line[0]),
float(splittet_line[1]),
float(splittet_line[2]))))
# Close file
file.close()
# Get first selected object
selected_object = bpy.context.selected_objects[0]
# Get first selected object
for position in position_vector:
selected_object.location = position
這將讀取文件並相應地更新第一個選定對象的位置。前進的道路:你必須找出哪些是如何設置關鍵幀動畫...
輕微modifcation,利用csv模塊
import bpy
import csv
position_vectors = []
filepath = "C:\\Work\\position.log"
csvfile = open(filepath, 'r', newline='')
ofile = csv.reader(csvfile, delimiter=',')
for row in ofile:
position_vectors.append(tuple([float(i) for i in row]))
csvfile.close()
的這將讓您的積分進入攪拌機。注意csv.reader中的分隔符參數,相應地改變它。通過您的RC汽車的實例文件,我們可以提供更完整的解決方案。
考慮這條巨蟒片段添加到解決上述
obj = bpy.context.object
temporalScale=bpy.context.scene.render.fps
for lrt in locRotArray:
obj.location = (lrt[0], lrt[1], lrt[2])
# radians, and do you want XYZ, or ZYX?
obj.rotation_euler = (lrt[3], lrt[4], lrt[5])
time = lrt[6]*temporalScale
obj.keyframe_insert(data_path="location", frame=time)
obj.keyframe_insert(data_path="rotation_euler", frame=time)
我沒有測試它,但它可能會工作,並讓你開始。
以spice2xyzv文件作爲輸入文件。由「突變鮑勃」編寫的腳本似乎工作。
但是xyz速度數據是km/s而非歐拉角,我認爲,導入不適用於角度。
# Records are <jd> <x> <y> <z> <vel x> <vel y> <vel z>
# Time is a TDB Julian date
# Position in km
# Velocity in km/sec
2456921.49775 213928288.518 -446198013.001 -55595492.9135 6.9011736 15.130842 0.54325805
有沒有解決方案讓他們在攪拌機?我應該將速度角度轉換爲歐拉嗎?事實上可能嗎?
我使用這個腳本:
import bpy
from mathutils import *
from math import *
from bpy.props import *
import os
import time
# Init
position_vector = []
# Open file
file = open("D:\\spice2xyzv\\export.xyzv", "r")
obj = bpy.context.object
temporalScale=bpy.context.scene.render.fps
for line in file:
# Split line at ";"
print("line = %s" % line)
line = line.replace("\n","")
locRotArray = line.split(" ")
print("locRotArray = %s" % locRotArray)
#for lrt in locRotArray:
print(locRotArray[1])
obj.location = (float(locRotArray[1]), float(locRotArray[2]), float(locRotArray[3]))
# radians, and do you want XYZ, or ZYX?
obj.rotation_euler = (float(locRotArray[4]), float(locRotArray[5]), float(locRotArray[5]))
time = float(locRotArray[0])*temporalScale
print("time = %s" % time)
obj.keyframe_insert(data_path="location", frame=time)
obj.keyframe_insert(data_path="rotation_euler", frame=time)
什麼版本的Blender您使用的是? 2.4倍還是2.5倍? – 2012-04-19 21:45:37
最後一個,由於我急於在Google Earth中執行它,並且執行路由XML文件,這不是我想要的,但它是服務的。 – Rommel 2012-06-11 23:27:07