mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 18:09:46 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
35e3d80f35
111 changed files with 935 additions and 664 deletions
|
|
@ -5,6 +5,9 @@ local INT_BEZIER = animation.INT_BEZIER
|
|||
|
||||
local bezier_interpolation = animation.maths.bezier_interpolation
|
||||
|
||||
local register_track = __skeleton and __skeleton.register_track
|
||||
local NATIVE_GROUP_VALUES = 32
|
||||
|
||||
local patterns = {}
|
||||
local exclude_patters = {
|
||||
"end",
|
||||
|
|
@ -120,7 +123,8 @@ local env = {
|
|||
end
|
||||
end
|
||||
end,
|
||||
dump = debug.print
|
||||
dump = debug.print,
|
||||
apply_track = __skeleton and __skeleton.apply_track,
|
||||
}
|
||||
|
||||
local math_funcs = {
|
||||
|
|
@ -275,6 +279,108 @@ local function codegen_rig_target(raw_track, context)
|
|||
return code .. " end"
|
||||
end
|
||||
|
||||
|
||||
local function codegen_native_rig_target(raw_track, context, track_name)
|
||||
if not register_track or not track_name then
|
||||
return nil
|
||||
end
|
||||
local axis_indices = {X=1, Y=2, Z=3}
|
||||
local rotation_order = raw_track.rotation_order or "XYZ"
|
||||
local code = ""
|
||||
local groups = 0
|
||||
local group = {layout = {}, code = "", values = 0}
|
||||
|
||||
local function flush()
|
||||
if #group.layout > 0 then
|
||||
local id = register_track(track_name .. "#" .. groups, group.layout)
|
||||
groups = groups + 1
|
||||
local names = {}
|
||||
for i = 1, group.values do
|
||||
names[i] = "v" .. i
|
||||
end
|
||||
local declare = #names > 0 and ("\n local " .. table.concat(names, ", ")) or ""
|
||||
local args = #names > 0 and (", " .. table.concat(names, ", ")) or ""
|
||||
code = code .. "\n do" .. declare .. group.code
|
||||
.. string.format(" apply_track(target.eid, %d%s)\n end\n", id, args)
|
||||
else
|
||||
code = code .. group.code
|
||||
end
|
||||
group = {layout = {}, code = "", values = 0}
|
||||
end
|
||||
|
||||
for bone, lineset in pairs(raw_track.linesets) do
|
||||
if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then
|
||||
goto continue
|
||||
end
|
||||
local lineset_code = codegen_track(
|
||||
raw_track, lineset, context.memoised, context.keysets, false)
|
||||
local exported = {}
|
||||
local entry = {name = bone}
|
||||
if lineset.target_type == "bone" then
|
||||
local channels = {
|
||||
[animation.CH_TRANSLATE] = {},
|
||||
[animation.CH_ROTATE] = {},
|
||||
[animation.CH_SCALE] = {},
|
||||
}
|
||||
for i, line in ipairs(lineset.lines) do
|
||||
local by_axis = channels[line.channel]
|
||||
if by_axis and type(line.axis) == "number" then
|
||||
by_axis[line.axis] = i
|
||||
end
|
||||
end
|
||||
local function export(i)
|
||||
table.insert(exported, i)
|
||||
return #exported
|
||||
end
|
||||
local function vector(by_axis)
|
||||
if not (by_axis[1] or by_axis[2] or by_axis[3]) then
|
||||
return nil
|
||||
end
|
||||
local v = {0, 0, 0}
|
||||
for axis = 1, 3 do
|
||||
if by_axis[axis] then v[axis] = export(by_axis[axis]) end
|
||||
end
|
||||
return v
|
||||
end
|
||||
entry.t = vector(channels[animation.CH_TRANSLATE])
|
||||
local rotation = channels[animation.CH_ROTATE]
|
||||
for i = 1, 3 do
|
||||
local axis = axis_indices[rotation_order[i]]
|
||||
if rotation[axis] then
|
||||
entry.r = entry.r or {}
|
||||
table.insert(entry.r, axis - 1)
|
||||
table.insert(entry.r, export(rotation[axis]))
|
||||
end
|
||||
end
|
||||
entry.s = vector(channels[animation.CH_SCALE])
|
||||
end
|
||||
if group.values + #exported > NATIVE_GROUP_VALUES then
|
||||
flush()
|
||||
end
|
||||
local offset = group.values
|
||||
local exports = ""
|
||||
for k, line in ipairs(exported) do
|
||||
exports = exports .. string.format("\n v%d = l%d", offset + k, line)
|
||||
end
|
||||
for _, v in pairs({t = entry.t, s = entry.s}) do
|
||||
for axis = 1, 3 do
|
||||
if v[axis] > 0 then v[axis] = v[axis] + offset end
|
||||
end
|
||||
end
|
||||
for i = 2, #(entry.r or {}), 2 do
|
||||
entry.r[i] = entry.r[i] + offset
|
||||
end
|
||||
group.values = offset + #exported
|
||||
group.code = group.code .. "\n do" .. lineset_code .. exports .. "\n end\n"
|
||||
if entry.t or entry.r or entry.s then
|
||||
table.insert(group.layout, entry)
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
flush()
|
||||
return "\n if target.__native_rig then" .. code
|
||||
end
|
||||
|
||||
local function codegen_object_target(raw_track, context)
|
||||
local code = " local dst = mat4.idt()\n"
|
||||
local lineset = raw_track.linesets[""]
|
||||
|
|
@ -331,7 +437,12 @@ function internals.compile_animation_track(raw_track, track_name)
|
|||
), "<curve>", "t", env)()
|
||||
end
|
||||
|
||||
code = code .. codegen_rig_target(raw_track, context)
|
||||
local native = codegen_native_rig_target(raw_track, context, track_name)
|
||||
local rig = codegen_rig_target(raw_track, context)
|
||||
if native then
|
||||
rig = native .. " elseif" .. rig:sub(5)
|
||||
end
|
||||
code = code .. rig
|
||||
code = code .. codegen_object_target(raw_track, context)
|
||||
code = code .. codegen_camera_target(raw_track, context)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue