rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings
This commit is contained in:
1 parent
2956576d7f
commit
22ddcd78fa
941 files changed
+3364
-3364
No files matched your search
@@ -0,0 +1,109 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- model/robloxmesh/Write: a flat record (model/robloxmesh/Parse's shape) to a version 2.00 or 4.00 FileMesh. 2.00:
|
||||
-- header, 36- or 40-byte vertices (40 when col is set), faces. 4.00: the 24-byte header, 40-byte vertices, skinning
|
||||
-- (when there are bones), faces, LOD offsets, bones, the bone name table, subsets. Never throws.
|
||||
local Parse = require("@rosetta/model/robloxmesh/Parse")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
local Write = {}
|
||||
|
||||
local function vertex(w: Bytes.Writer, r: Parse.Record, i: number, colors: boolean)
|
||||
local p = w:reserve(if colors then 40 else 36)
|
||||
local b = w.buf
|
||||
buffer.copy(b, p, r.pos, i * 12, 12)
|
||||
buffer.copy(b, p + 12, r.nrm, i * 12, 12)
|
||||
buffer.copy(b, p + 24, r.uv, i * 8, 8)
|
||||
if r.tan then
|
||||
buffer.copy(b, p + 32, r.tan, i * 4, 4)
|
||||
else
|
||||
buffer.writeu32(b, p + 32, 0x7F810000) -- (0, 0, -1, 1)
|
||||
end
|
||||
if colors then
|
||||
if r.col then
|
||||
buffer.copy(b, p + 36, r.col, i * 4, 4)
|
||||
else
|
||||
buffer.writeu32(b, p + 36, 0xFFFFFFFF)
|
||||
end
|
||||
end
|
||||
w.pos = p + (if colors then 40 else 36)
|
||||
end
|
||||
|
||||
-- write(r, version) -> buffer ("2.00" | "4.00")
|
||||
function Write.write(r: Parse.Record, version: string): buffer
|
||||
local nv, nf = r.numVerts, r.numFaces
|
||||
local w = Bytes.writer(64 + nv * 48 + nf * 12)
|
||||
w:string("version " .. version .. "\n")
|
||||
if version == "2.00" then
|
||||
local colors = r.col ~= nil
|
||||
w:u16le(12)
|
||||
w:u8(if colors then 40 else 36)
|
||||
w:u8(12)
|
||||
w:u32le(nv)
|
||||
w:u32le(nf)
|
||||
for i = 0, nv - 1 do
|
||||
vertex(w, r, i, colors)
|
||||
end
|
||||
w:bytes(r.faces, 0, nf * 12)
|
||||
return w:finish()
|
||||
end
|
||||
-- 4.00
|
||||
local names = {}
|
||||
local nameAt = {}
|
||||
local size = 0
|
||||
for i, bone in r.bones do
|
||||
nameAt[i] = size
|
||||
table.insert(names, bone.name .. "\0")
|
||||
size += #bone.name + 1
|
||||
end
|
||||
local nb = #r.bones
|
||||
w:u16le(24)
|
||||
w:u16le(r.lodType)
|
||||
w:u32le(nv)
|
||||
w:u32le(nf)
|
||||
w:u16le(#r.lods)
|
||||
w:u16le(nb)
|
||||
w:u32le(size)
|
||||
w:u16le(#r.subsets)
|
||||
w:u8(r.highQualityLods)
|
||||
w:u8(0)
|
||||
for i = 0, nv - 1 do
|
||||
vertex(w, r, i, true)
|
||||
end
|
||||
if nb > 0 then
|
||||
local env = r.env
|
||||
if env then
|
||||
w:bytes(env, 0, nv * 8)
|
||||
else
|
||||
w:fill(0, nv * 8)
|
||||
end
|
||||
end
|
||||
w:bytes(r.faces, 0, nf * 12)
|
||||
for _, o in r.lods do
|
||||
w:u32le(o)
|
||||
end
|
||||
for i, bone in r.bones do
|
||||
w:u32le(nameAt[i])
|
||||
w:u16le(if bone.parent then bone.parent else 0xFFFF)
|
||||
w:u16le(bone.lodParent)
|
||||
w:f32le(bone.culling)
|
||||
for k = 1, 12 do
|
||||
w:f32le(bone.cf[k] or 0)
|
||||
end
|
||||
end
|
||||
w:string(table.concat(names))
|
||||
for _, s in r.subsets do
|
||||
w:u32le(s.facesBegin)
|
||||
w:u32le(s.facesLength)
|
||||
w:u32le(s.vertsBegin)
|
||||
w:u32le(s.vertsLength)
|
||||
w:u32le(#s.bones)
|
||||
for k = 1, 26 do
|
||||
w:u16le(s.bones[k] or 0xFFFF)
|
||||
end
|
||||
end
|
||||
return w:finish()
|
||||
end
|
||||
|
||||
return Write
|
||||
Reference in new issue
Block a user