Issue #1336 resolved

more Data operations

Kyle McLamb
created an issue

So I was recently using the Data API to implement the glTF format and while I was asking questions slime mentioned he wasn't sure what methods he wanted to add so I figured I would write down what would be handy for me in particular.

  • a way to allocate a chunk of generic data, in bytes. I don't really care what is inside the chunk, because I'm going to use it with the FFI anyways and I can memset/memcpy myself.

  • a way to present a "slice" of data to function that wants a Data object. A slice would be the same as its parent Data, except that it can start in the middle of its parent and end sooner than its parent does. glTF is a great example of how this would be practically useful: images, vertex data, etc are all embedded in the same binary file, and it would be much cheaper to load everything, then pass around offsets, then to work around the fact that 1 buffer == 1 "file" as it is now.

  • I don't think I need a realloc() equivalent, although it seems like somebody might. /shrug

  • This is only semi-related to Data, but while glTF supports interleaved data most exporters prefer

 X X X
 Y Y Y
 Z Z Z

over

 X Y Z
 X Y Z
 X Y Z

afaict mesh:setVertices() can only understand format 2 here, which means I need to make a new buffer and manually translate it to support format 1.

and that's it~ I've only implemented meshes/mesh attributes, which leaves out animations/vertex skinning etc. but I still think this is a good real-world example as is

Comments (2)

  1. Alex Szpakowski

    afaict mesh:setVertices() can only understand format 2 here, which means I need to make a new buffer and manually translate it to support format 1.

    For non-interleaved attributes you can create a Mesh per attribute, and use positionMesh:attachAttribute to hook them up so drawing the position mesh pulls from the others.

  2. Alex Szpakowski

    Add love.data module.

    • Moved love.math.compress / decompress / decode / encode / hash to love.data.
    • Changed love.data.compress/decompress to take the format argument first instead of second.
    • Added love.data.newDataView. Returns a read-only subsection of an existing Data object.
    • Added love.data.newByteData. Mostly useful in combination with LuaJIT's FFI as it has no extra methods currently.
    • Added implementations of Lua 5.3's data packing APIs: love.data.packString / packData / unpack / getPackedSize.

    Resolves issue #1336. Resolves issue #1331.

    → <<cset 7dbb0d39b01e>>

  3. Log in to comment