Skip to content

Buffer interpolators

Andreas Plesch edited this page Jan 11, 2022 · 25 revisions

Buffer interpolators

Introduction

x3dom extends the standard interpolators with an option to use a binary data file, the buffer. This extension is based on how gltf uses binary data, and in fact the gltf inline function takes advantage of this extension. A few addtional fields for the interpolator nodes facilitate.

Summary

The buffer field defines the url to the binary data file. Accessor field nodes define key and keyValue pointers into the buffer and an additional offset for a view into the buffer. They also define size and data type for key and keyValue.

Here a glTF explanation of the terms: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#binary-data-storage

Example

<coordinateinterpolator id="ci1" DEF='smdimport_1-GEOMETRY-COORD-INTERP' buffer="interpolatorBuffer.bin" duration="1">
    <bufferaccessor buffertype="SAMPLER_INPUT" view="0" byteoffset="0" count="25" components="1" componenttype="5126"></bufferaccessor>
    <bufferaccessor buffertype="SAMPLER_OUTPUT" view="1" byteoffset="0" count="118800" components="3" componenttype="5126"></bufferaccessor>
    <bufferview byteoffset="1425700"></bufferview>
    <bufferview byteoffset="1425800"></bufferview>
</coordinateinterpolator>

Converting from regular to buffer Interpolator data

Using a binary buffer for data storage has the advantage of loading large data sets quickly and smaller downloads. A single buffer file can contain data of all interpolator data sets. A conversion utility would take a xml scene, extract all interpolator nodes, write out binary floats for the first key, record the first byte offset, write out binary floats for the first keyValues, record the byte offset, and continue to the rest of the interpolators. The written file is the buffer file. Then two BufferView nodes are created for each interpolator with its byte offsets for key and keyValue data. Then input and output BufferAccessor nodes are created with 0 byte offsets relative to the corresponding view.

New fields

SFString buffer ""

The url to the binary file, that contains the binary buffer data. [ could be MFString to be consistent with Urls in x3d which have fallback options ]. Binary data are expected in little endian byte order.

SFFloat duration 1

Specifies the duration of the complete sequence. In glTF key values are time stamps whereas in x3d key values are typically fractions between 0 and 1. The duration value is used to normalize input key data by division.

MFNode accessors []

A list of BufferAccessor nodes. One of bufferType "SAMPLER_INPUT" is intended for the key, and one of bufferType "SAMPLER_OUTPUT" for the keyValue. Both nodes are required. Other bufferTypes are ignored.

  • SFNode BufferAccessor

    The node has these fields:

    SFString bufferType ""

    Specifies if the accessor’s elements are scalars, vectors, or matrices, or sampler input or output. Use "SAMPLER_INPUT" for key, and "SAMPLER_OUTPUT" for keyValue. Other values may be used for binary buffer storage of geometry or other nodes. Due to glTF standards, SAMPLER_INPUT values (keys) will be divided by the value of the duration field of the interpolator (see above).

    SFInt32 view 0

    The related buffer view. Index into the related array of bufferViews.

    SFInt32 byteOffset 0

    The buffer byteOffset. The offset from the beginning of the referenced view in bytes.

    SFInt32 componentType 5126

    The buffer component type. The type of numerical representation of elements as GL enum. Allowed values:

      5120 BYTE
    
      5121 UNSIGNED_BYTE
    
      5122 SHORT
    
      5123 UNSIGNED_SHORT
    
      5125 UNSIGNED_INT
    
      5126 FLOAT
    

    SFBool normalized false

    Attribute normalization. If true, integer values will be normalized to [0,1] or [-1,1] based on their representation range.

    SFInt32 count 0

    The buffer element count. The count times the number of elements defined by the components field is used to determine the size of the data in the buffer.

    SFInt32 components 0

    The buffer components. The number of elements per value. 1 for scalar, 3 for 3d vectors, for example.

    SFInt32 byteStride 0

    The buffer byteStride. not used.

MFNode views []

A list of BufferView nodes. Each nodes defines a byte offsets into the binary buffer.

  • SFNode BufferView

    The node has these fields:

    SFInt32 target 34962

    The hint representing the intended GPU buffer type as GL enum to use with this buffer view. Allowed values:

      34962 ARRAY_BUFFER
    
      34963 ELEMENT_ARRAY_BUFFER
    

    SFInt32 byteOffset 0

    The offset into the buffer in bytes.

    SFInt32 byteStride 0

    The stride, in bytes, between vertex attributes. Not used for interpolator. Always assumes tightly packed.

    SFInt32 byteLength 0

    The length of the bufferView in bytes. Not used.