Pre-processing raw tracks¶
Once you have created a raw track list and an allocator instance, you can optionally pre-process them.
Pre-processing gives explicit control over raw data modification. When compressing, ACL will never modify the raw data. This is ideal because it ensures that none of the inputs are modified and the whole process is deterministic and repeatable. However, sometimes this can lead to sub-optimal compression. In particular, under certain conditions, ACL may not be able to reach the raw data values when attempting to optimize things. As a result, more precision than otherwise necessary might be retained.
As such, it is recommended that the raw data be pre-processed before compression. This can be done at any point before compression (e.g. after FBX import).
Various pre-process actions can be performed in bulk or individually, see pre_process_actions for details.
Pre-processing actions can be lossy or lossless. See pre_process_actions and pre_process_precision_policy for details.
With extended samples, pre_process_track_list(..) changes only the sample values. The sample interpolators do not change.
When pre-processing transform tracks, selecting the right runtime transform type is important: select the one that your game engine uses to compose transforms. Use the same transform_runtime_type, custom_transform_adapter, and transform_metric for pre-processing and compression. They have the same defaults as in the compression settings.
Pre-processing uses the transform space of the track array. With an additive clip, set transform_base to the base that you give to compression: pre-processing then measures the error with the base.
#include <acl/compression/pre_process.h>
using namespace acl;
pre_process_settings_t settings;
settings.actions = pre_process_actions::recommended;
settings.precision_policy = pre_process_precision_policy::lossy;
// Optional: use the same runtime transform type as compression
// settings.transform_runtime_type = transform_runtime_type_t::vqvf;
// Optional: use the same base as compression
// settings.transform_base = transform_base;
pre_process_track_list(allocator, settings, transform_tracks);
Identity rotations¶
Because of float precision, a rotation quaternion can have a W component of exactly 1.0 (or -1.0) and small non-zero X, Y, and Z components. Such a quaternion has a rotation axis but no rotation around that axis.
The sanitize_identity_rotations action sets the X, Y, and Z components of each such rotation to 0.0 and keeps the sign of W. It is part of the recommended actions. It is lossy: with the lossless policy, it does nothing. With the lossy policy, a track changes only when the error stays within its precision. The action runs after normalize_rotations and before the other actions. Thus, sanitize_constant_tracks and sanitize_default_tracks see the new rotations.
Transform type conversion¶
The convert_transform_type action converts transform tracks into the type of settings.transform_type (vqvf, vqsf, or vqf). It is not part of the recommended actions, because it changes the type of the compressed tracks. Compression never changes the type of the raw tracks.
The three types hold more and more scale information: vqf has no scale, vqsf has a uniform scale, and vqvf has a 3D scale.
- A promotion (for example
vqf->vqsf, orvqsf->vqvf) always succeeds and is lossless. When the source has no scale, each new scale is the identity of the additive format: 0.0 withadditive1, 1.0 otherwise. - A demotion to
vqfremoves the scale. It happens only when no track needs its scale. With the lossless policy, each scale sample must be exactly the identity. With the lossy policy, the error must stay within the precision of each track when its scale becomes the identity. - A demotion from
vqvftovqsfmakes each scale uniform. It happens only when no track needs a non-uniform scale. With the lossless policy, the X, Y, and Z components of each scale sample must be exactly equal. With the lossy policy, the error must stay within the precision of each track when its scale becomes the mean of its X, Y, and Z components.
When a track needs its scale, the tracks keep their type.
This action runs last. Thus, with the lossy policy, sanitize_constant_tracks and sanitize_default_tracks run first.
A typed track array (for example track_array_vqvf) cannot change its type. To convert, give pre_process_track_list(..) a track_array. With a typed track array, the action returns an error when the type must change.
// Compress the clips without scale as VQ tracks
pre_process_settings_t settings;
settings.actions = pre_process_actions::recommended | pre_process_actions::convert_transform_type;
settings.precision_policy = pre_process_precision_policy::lossy;
settings.transform_type = track_type8::vqf;
track_array transform_tracks = std::move(raw_vqv_tracks);
pre_process_track_list(allocator, settings, transform_tracks);
// transform_tracks.get_track_type() is now vqf if no track needs its scale
See pre_process.h for API and other usage details.