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,74 @@
|
||||
--!strict
|
||||
--!native
|
||||
-- model/gltf/Pack: the byte loops of glTF accessors: strided / column-padded elements into tightly packed Scene
|
||||
-- accessor data (gather), the reverse for writing (scatter), and sparse substitution. Callers check every range
|
||||
-- first (offsets, strides and counts against the buffer lengths); nothing here throws.
|
||||
local Pack = {}
|
||||
|
||||
local bcopy, readu8, readu16, readu32 = buffer.copy, buffer.readu8, buffer.readu16, buffer.readu32
|
||||
|
||||
-- gather(dst, src, off, count, elem, stride, cols, colBytes, colStride): element i starts at off + i * stride; an element is
|
||||
-- cols columns of colBytes bytes, colStride apart (glTF pads matrix columns to 4 bytes); dst gets them packed (elem =
|
||||
-- cols * colBytes bytes each)
|
||||
function Pack.gather(dst: buffer, src: buffer, off: number, count: number, elem: number, stride: number, cols: number, colBytes: number, colStride: number)
|
||||
if cols == 1 or colBytes == colStride then
|
||||
if stride == elem then
|
||||
bcopy(dst, 0, src, off, count * elem)
|
||||
return
|
||||
end
|
||||
for i = 0, count - 1 do
|
||||
bcopy(dst, i * elem, src, off + i * stride, elem)
|
||||
end
|
||||
return
|
||||
end
|
||||
for i = 0, count - 1 do
|
||||
local s = off + i * stride
|
||||
local d = i * elem
|
||||
for c = 0, cols - 1 do
|
||||
bcopy(dst, d + c * colBytes, src, s + c * colStride, colBytes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- scatter(dst, at, src, count, elem, stride, cols, colBytes, colStride): the reverse of gather (dst zero-filled)
|
||||
function Pack.scatter(dst: buffer, at: number, src: buffer, count: number, elem: number, stride: number, cols: number, colBytes: number, colStride: number)
|
||||
if cols == 1 or colBytes == colStride then
|
||||
if stride == elem then
|
||||
bcopy(dst, at, src, 0, count * elem)
|
||||
return
|
||||
end
|
||||
for i = 0, count - 1 do
|
||||
bcopy(dst, at + i * stride, src, i * elem, elem)
|
||||
end
|
||||
return
|
||||
end
|
||||
for i = 0, count - 1 do
|
||||
local d = at + i * stride
|
||||
local s = i * elem
|
||||
for c = 0, cols - 1 do
|
||||
bcopy(dst, d + c * colStride, src, s + c * colBytes, colBytes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- sparse(dst, count, elem, idx, idxOff, idxSize, values, valOff, n) -> false when an index is out of range: element
|
||||
-- idx[k] of dst becomes value k (values packed, elem bytes each)
|
||||
function Pack.sparse(dst: buffer, count: number, elem: number, idx: buffer, idxOff: number, idxSize: number, values: buffer, valOff: number, n: number): boolean
|
||||
for k = 0, n - 1 do
|
||||
local i
|
||||
if idxSize == 1 then
|
||||
i = readu8(idx, idxOff + k)
|
||||
elseif idxSize == 2 then
|
||||
i = readu16(idx, idxOff + k * 2)
|
||||
else
|
||||
i = readu32(idx, idxOff + k * 4)
|
||||
end
|
||||
if i >= count then
|
||||
return false
|
||||
end
|
||||
bcopy(dst, i * elem, values, valOff + k * elem, elem)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return Pack
|
||||
Reference in new issue
Block a user