使用Lua导入.BVH运动数据/LUA表格,然后使用表格对.OBJ进行动画处理。

这是否可能,因为.BVH文件是文本驱动的,而.OBJ文件也是文本驱动的,我一直在研究这段代码,但似乎还是有些遗漏。

``` 将脚本导入到lua表中

--[[将.BVH(运动捕捉)文件解析为Lua表格式。

--]]

--有效的BVH变换令牌及它们--四元数序列等效物的列表。本地xform_tokens = {

}

Xrotation =“rx”,Yrotation =“ry”,Zrotation =“rz”,Xposition =“tx”,Yposition =“ty”,Zposition =“tz”

--主要功能

BVH2Table = function(bhvfilename)local bhvfile,linenumber,bvhtable,level_temp_info,line,rest,_ =0)

assert(io.open(bhvfilename)),0,{},{}

当时,读入文本文件的每一行使用repeat

linenumber = linenumber + 1 line = bhvfile:read(“*line”)--修剪行= line and string.gsub(string.gsub(line,“^ [\ t] *”,“”),“[ \ t \ n] * $”,“”)或nil--启用注释和while行

直到行或(行~ =“”且字符串.sub(line,1,1)~ =“#”)时,_,_,令牌= string.find(line或“”,“^(%u%l {}:]+)”)--其余部分的行,剥离_,_,rest = string.find(line或“”,“^ [%u%l {}:]+ [\ t](%a%d%s%c%p] *)”)

local function parse_error(err,...)

error(string.format(“%s:%d:%s”,bhvfilename,linenumber,string.format(err,unpack(arg))),

local function checktoken(ctoken)if ctoken ~ = token then

parse_error(“令牌%s预期,得到%s”,ctoken,token)bvhtable.root_segment = {}

end

local function read_joint_level(level)local level_temp_info = {rotation_seq = {},level = level} --存储动画帧解码时使用的信息表.insert(levels_temp_info,level_temp_info)级别旋转={} --每个动画帧一个

checktoken(“ {”)readline()while token ~ = “}”do

if token ==“OFFSET”then local ox,oy,oz

_,_,ox,oy,oz = string.find(rest,“[\ t] *( [ % - %+ $d] +)[\ t] +( [%-%+%d] +)[\ t] +( [ %-%+%d] +)“)

角度

table.insert(level_temp_info.rotation_seq,token)table.insert(level_temp_info.rotation_seq,0)

--“rx”,“ry”或“rz”-放置点

级别中的偏移量= vec4(ox,oy,oz)elseif token ==“CHANNELS”then

local _,e,channelcount = string.find(rest,“(【% d】+)[\ t] *”)for i = 1,channelcount do

当地chname-提取通道名称(例如“Xrotation”)_,e,chname = string.find(rest,“(%w +)[\ t] *”,e)当地令牌= xform_tokens [chname]或

parse_error(“未知通道类型%s”,chname或“(无)”)if string.sub(token,1,1)~ =“t”then - 忽略翻译令牌。

end elseif token ==“JOINT”or token ==“End”then

当地newlevel = {} level.segments = level.segments or {} - 确保我们有一个表格level.segments [(token ==“End”)and “EndSite”or rest] = newlevel - 新水平readline()read_joint_level(newlevel)

elseif token ~ =“}”then

parse_error(“非法/未知令牌'%s'”,token)readline()

end

--读取分层结构

readline()checktoken(“HIERARCHY”)readline()checktoken(“ROOT”)readline()read_joint_level(bvhtable.root_segment)readline()

  • 读取帧(将它们插入层次结构的正确位置)

checktoken(“MOTION”)readline()

checktoken(“Frames:”)_,_,bvhtable.framecount = string.find(rest,“(【% d】+)”)readline()

checktoken(“Frame”)_,_,bvhtable.frametime = string.find(rest,“(【% d。】+)”)readline()

对于fr = 1,bvhtable.framecount do if token或not line then parse_error(“期待

原文链接 https://stackoverflow.com/questions/6132749

点赞
stackoverflow用户427181
stackoverflow用户427181

抱歉,但您的问题似乎是如何将3D动画文件应用于3D模型文件。

答案是您不需要这样做,它们只是不同的文件格式,您可能正在问错问题。

2011-05-26 02:02:25
stackoverflow用户686008
stackoverflow用户686008

.obj 不支持动画,因此您无法将动画数据放入 .obj 文件中。

现在,如果您将 Lua 作为 3D 引擎的脚本语言,您可以加载 .bvh,然后将这些动作应用于在 3D 引擎中加载的 .obj 模型,但这更多是关于您的 3D 引擎而不是关于 Lua 的问题。

2011-05-26 17:42:30