Files
JiboOs/docs/rendering/animation/KeysLoader.js
2026-03-16 13:53:01 +02:00

129 lines
6.1 KiB
JavaScript

/**
* Nested Keys File Loading.
*
* Given a keys file url, load the file and then recursively
* composite into it any keys files it points to (somewhat like macro expansion).
* @return {String} The result of the compositing operation with all reference layers removed.
* @name jibo.rendering.animation.KeysLoader#innerNestedLoad
* @param {String} url Path nanme of the keys file to be loaded
* @param {Callback} complete Callback to call when the load is completed.
* @param {String} [parentId] The layer ID of the referencing frame.
* @param {String} [refBase] The directory that the asset references are with respect to.
* @private
*/
/**
* Convert keyframes referencing texture, pixi and audio information into assetpack style references if necessary.
*
* The motivation:
* Consider a reference layer in a skill's animation that references an animDB keys file.
* Compositing will pull in the layers from the animDB keys file, but any asset references (textures, audio, pixi)
* in those layers will be relative to the animDB root. If the paths to those assets are not converted to
* asset-pack style references (while we know their provenance) we will not be able to distinguish later on
* whether those references are relative to the animDB or to the local skill.
*
* @param {Keyframes} frames the keyframes object whose asset references will be modified.
* @param {string} assetPack the assetPack that the containing file is in.
*/
/**
* Convert a non-asset pack reference into an asset-pack one.
* @param assetPack
* @param filepath
* @returns {string}
*/
/**
* Find all references in a keys file, returning them in reverse-order.
* @name jibo.rendering.animation.KeysLoader#getKeyFileReferences
* @param {Keyframes} frames A keyframes structure containing reference layers.
* @param {String} refBase The directory containing the file from whence the given keyframes were loaded.
* @returns {Array} An array of objects describing references to other keys files,
* each object has these properties:
* `url`: the url of the file being referenced,
* `parentId`: the layerID of the parent,
* `holdFinalPose`: whether the final frame of the referenced layer is held until the next reference (or end),
* `containerDuration`: the duration of the file that contains this reference.
* `layerNumber`: the ordinal layer number of the reference,
* `atEnd`: a boolean that is true if this is the last reference in the layer.
* `nextRefStart`: where the next reference frame is, or Infinity if there are no further references.
* `timeOffset`: the timepoint at which it is to be inserted in the referencing layer.
* @private
*/
/**
* Place num in a leading-zero-padded field of the given size
* @param {number} num Number to pad
* @param {number} size Size of final field
* @returns {string}
*/
/**
* Return a full URL for the referenced keys file based on
* the reference mode (by name or by file).
* @param {any} keyframe the keyframe containing the reference.
* @param {string} refBase directory of the file in which the reference is occurring.
* @returns {object} object.url containing the fully resolved path to referenced file and
* object.refBase containing the parent directory of the referencer.
* @method jibo.rendering.animation.KeysLoader#getReferencedUrl
* @private
*/
/**
* Find any "HOLD_SAFE" events in referenced layers and remove them (by renaming them).
* @name jibo.rendering.animation.KeysLoader#removeHoldSafesInReferences
* @param {Keyframes} frames keyframes to be cleaned.
* @private
*/
/**
* Strip out any reference-type layers from the keyframes.
* @name jibo.rendering.animation.KeysLoader#removeReferenceLayers
* @param {Keyframes} keyframes keyframes structure containing reference layers.
* @private
*/
/**
* Shift the layer's validFrom, validUpto and validHoldAfter properties and
* shift the timepoint of all the keyframes within each of the given layers by the given time offset ("validFrom").
* The validFrom and validUpto parameters are in "referencing" layer coordinates.
* @name jibo.rendering.animation.KeysLoader#timeshift
* @param {Keyframes} frames the layers containing the keyframes to be shifted.
* @param {number} validFrom the beginning of the valid region.
* @param {number} validUpto the ending of valid region, or Infinity for unlimited.
* @param {number} holdAfter the timepoint after which the pose does not change (i.e. it remains fixed at that timepoint).
* @private
*/
/**
* Insert all the layers of toBeInsertedKeyframes into existingKeyframes at the given layer number.
* Insert them last-first in order to preserve their original ordering at the designated layer.
* @name jibo.rendering.animation.KeysLoader#composite
* @param {Number} layerNumber the layer number in which the keyframes are to be inserted.
* @param {Keyframes} existingKeyframes the existing keyframes into which the layers will be inserted.
* @param {Keyframes} toBeInsertedKeyframes the source of the keyframes to be inserted.
* @private
*/
/**
* Modifies the layer ids to prefixed by the referencing layer's id (delimited by "-")
* and suffixed with the layer number (delimited by '.').
* @name jibo.rendering.animation.KeysLoader#fixLayerIds
* @param {Keyframes} frames the set of layers to be modified.
* @param {string} prefix the string with which to prefix each layer id.
* @private
*/
/**
* Was this layer produced from a keyframes reference?
* @name jibo.rendering.animation.KeysLoader#isReferencedLayer
* @param {any} layer the layer to be checked
* @returns {boolean}
* @private
*/
/**
// * Return true if frame being referenced already exists in hierarchy.
// * @param frames
// * @param prefix
// */