RavEngine
Loading...
Searching...
No Matches
blending_job.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_ANIMATION_RUNTIME_BLENDING_JOB_H_
29#define OZZ_OZZ_ANIMATION_RUNTIME_BLENDING_JOB_H_
30
31#include "ozz/animation/runtime/export.h"
32#include "ozz/base/maths/simd_math.h"
33#include "ozz/base/span.h"
34
35namespace ozz {
36
37// Forward declaration of math structures.
38namespace math {
39struct SoaTransform;
40}
41
42namespace animation {
43
44// ozz::animation::BlendingJob is in charge of blending (mixing) multiple poses
45// (the result of a sampled animation) according to their respective weight,
46// into one output pose.
47// The number of transforms/joints blended by the job is defined by the number
48// of transforms of the rest pose (note that this is a SoA format). This means
49// that all buffers must be at least as big as the rest pose buffer.
50// Partial animation blending is supported through optional joint weights that
51// can be specified with layers joint_weights buffer. Unspecified joint weights
52// are considered as a unit weight of 1.f, allowing to mix full and partial
53// blend operations in a single pass.
54// The job does not owned any buffers (input/output) and will thus not delete
55// them during job's destruction.
56struct OZZ_ANIMATION_DLL BlendingJob {
57 // Default constructor, initializes default values.
59
60 // Validates job parameters.
61 // Returns true for a valid job, false otherwise:
62 // -if layer range is not valid (can be empty though).
63 // -if additive layer range is not valid (can be empty though).
64 // -if any layer is not valid.
65 // -if output range is not valid.
66 // -if any buffer (including layers' content : transform, joint weights...) is
67 // smaller than the rest pose buffer.
68 // -if the threshold value is less than or equal to 0.f.
69 bool Validate() const;
70
71 // Runs job's blending task.
72 // The job is validated before any operation is performed, see Validate() for
73 // more details.
74 // Returns false if *this job is not valid.
75 bool Run() const;
76
77 // Defines a layer of blending input data (local space transforms) and
78 // parameters (weights).
79 struct OZZ_ANIMATION_DLL Layer {
80 // Default constructor, initializes default values.
81 Layer();
82
83 // Blending weight of this layer. Negative values are considered as 0.
84 // Normalization is performed during the blending stage so weight can be in
85 // any range, even though range [0:1] is optimal.
86 float weight;
87
88 // The range [begin,end[ of input layer posture. This buffer expect to store
89 // local space transforms, that are usually outputted from a sampling job.
90 // This range must be at least as big as the rest pose buffer, even though
91 // only the number of transforms defined by the rest pose buffer will be
92 // processed.
94
95 // Optional range [begin,end[ of blending weight for each joint in this
96 // layer.
97 // If both pointers are nullptr (default case) then per joint weight
98 // blending is disabled. A valid range is defined as being at least as big
99 // as the rest pose buffer, even though only the number of transforms
100 // defined by the rest pose buffer will be processed. When a layer doesn't
101 // specifies per joint weights, then it is implicitly considered as
102 // being 1.f. This default value is a reference value for the normalization
103 // process, which implies that the range of values for joint weights should
104 // be [0,1]. Negative weight values are considered as 0, but positive ones
105 // aren't clamped because they could exceed 1.f if all layers contains valid
106 // joint weights.
107 span<const math::SimdFloat4> joint_weights;
108 };
109
110 // The job blends the rest pose to the output when the accumulated weight of
111 // all layers is less than this threshold value.
112 // Must be greater than 0.f.
113 float threshold;
114
115 // Job input layers, can be empty or nullptr.
116 // The range of layers that must be blended.
117 span<const Layer> layers;
118
119 // Job input additive layers, can be empty or nullptr.
120 // The range of layers that must be added to the output.
121 span<const Layer> additive_layers;
122
123 // The skeleton rest pose. The size of this buffer defines the number of
124 // transforms to blend. This is the reference because this buffer is defined
125 // by the skeleton that all the animations belongs to.
126 // It is used when the accumulated weight for a bone on all layers is
127 // less than the threshold value, in order to fall back on valid transforms.
129
130 // Job output.
131 // The range of output transforms to be filled with blended layer
132 // transforms during job execution.
133 // Must be at least as big as the rest pose buffer, but only the number of
134 // transforms defined by the rest pose buffer size will be processed.
136};
137} // namespace animation
138} // namespace ozz
139#endif // OZZ_OZZ_ANIMATION_RUNTIME_BLENDING_JOB_H_
Definition blending_job.h:79
Definition blending_job.h:56
Definition span.h:37