|
| 1 | +/** |
| 2 | + * Copyright(c) Live2D Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Use of this source code is governed by the Live2D Open Software license |
| 5 | + * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include "CubismFramework.hpp" |
| 11 | +#include "Id/CubismId.hpp" |
| 12 | +#include "Type/csmVector.hpp" |
| 13 | + |
| 14 | +namespace Live2D { namespace Cubism { namespace Framework { |
| 15 | + |
| 16 | +class CubismMotionQueueManager; |
| 17 | +class CubismMotionQueueEntry; |
| 18 | +class CubismModel; |
| 19 | + |
| 20 | +/** |
| 21 | + * Abstract base class for motions.<br> |
| 22 | + * Handles the management of motion playback through the MotionQueueManager. |
| 23 | + */ |
| 24 | +class ACubismMotion |
| 25 | +{ |
| 26 | +public: |
| 27 | + typedef void (*BeganMotionCallback)(ACubismMotion* self); |
| 28 | + typedef void (*FinishedMotionCallback)(ACubismMotion* self); |
| 29 | + /** |
| 30 | + * Destroys the instance. |
| 31 | + * |
| 32 | + * @param motion instance to destroy |
| 33 | + */ |
| 34 | + static void Delete(ACubismMotion* motion); |
| 35 | + |
| 36 | + /** |
| 37 | + * Constructor |
| 38 | + */ |
| 39 | + ACubismMotion(); |
| 40 | + |
| 41 | + /** |
| 42 | + * Updates the model parameters. |
| 43 | + * |
| 44 | + * @param model model to update |
| 45 | + * @param motionQueueEntry motion managed by the CubismMotionQueueManager |
| 46 | + * @param userTimeSeconds current time in seconds |
| 47 | + */ |
| 48 | + void UpdateParameters(CubismModel* model, CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds); |
| 49 | + |
| 50 | + /** |
| 51 | + * Sets up to start the playback of the motion. |
| 52 | + * |
| 53 | + * @param motionQueueEntry motion managed by the CubismMotionQueueManager |
| 54 | + * @param userTimeSeconds total playback time in seconds |
| 55 | + */ |
| 56 | + void SetupMotionQueueEntry(CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds); |
| 57 | + |
| 58 | + /** |
| 59 | + * Sets the number of seconds for the motion to complete fading in. |
| 60 | + * |
| 61 | + * @param fadeInSeconds number of seconds for the fade-in to complete |
| 62 | + */ |
| 63 | + void SetFadeInTime(csmFloat32 fadeInSeconds); |
| 64 | + |
| 65 | + /** |
| 66 | + * Sets the number of seconds for the motion to complete fading out. |
| 67 | + * |
| 68 | + * @param fadeOutSeconds number of seconds for the fade-out to complete |
| 69 | + */ |
| 70 | + void SetFadeOutTime(csmFloat32 fadeOutSeconds); |
| 71 | + |
| 72 | + /** |
| 73 | + * Returns the number of seconds for the motion to complete fading out. |
| 74 | + * |
| 75 | + * @return number of seconds for the fade-out to complete |
| 76 | + */ |
| 77 | + csmFloat32 GetFadeOutTime() const; |
| 78 | + |
| 79 | + /** |
| 80 | + * Returns the number of seconds for the motion to complete fading in. |
| 81 | + * |
| 82 | + * @return number of seconds for the fade-in to complete |
| 83 | + */ |
| 84 | + csmFloat32 GetFadeInTime() const; |
| 85 | + |
| 86 | + /** |
| 87 | + * Sets the weight during the application of the motion. |
| 88 | + * |
| 89 | + * @param weight weight during the application of the motion (0.0-1.0) |
| 90 | + */ |
| 91 | + void SetWeight(csmFloat32 weight); |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns the weight during the application of the motion. |
| 95 | + * |
| 96 | + * @return weight during the application of the motion (0.0-1.0) |
| 97 | + */ |
| 98 | + csmFloat32 GetWeight() const; |
| 99 | + |
| 100 | + /** |
| 101 | + * Returns the length of the motion. |
| 102 | + * |
| 103 | + * @return length of the motion in seconds<br> |
| 104 | + * -1 if the motion is looping. |
| 105 | + * |
| 106 | + * @note When a positive value is returned, the motion ends at the obtained time.<br> |
| 107 | + * When -1 is returned, the motion is looping and does not end. |
| 108 | + */ |
| 109 | + virtual csmFloat32 GetDuration(); |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns the length of one loop of the looping motion. |
| 113 | + * |
| 114 | + * @return length of one loop of the looping motion in seconds<br> |
| 115 | + * Same value as GetDuration() if the motion is not looping. |
| 116 | + * |
| 117 | + * @note Returns -1 if the length of one loop of the looping motion cannot be determined. |
| 118 | + */ |
| 119 | + virtual csmFloat32 GetLoopDuration(); |
| 120 | + |
| 121 | + |
| 122 | + /** |
| 123 | + * Sets the number of seconds to start the motion playback. |
| 124 | + * |
| 125 | + * @param offsetSeconds number of seconds to start the motion playback |
| 126 | + */ |
| 127 | + void SetOffsetTime(csmFloat32 offsetSeconds); |
| 128 | + |
| 129 | + /** |
| 130 | + * Sets whether the motion should loop. |
| 131 | + * |
| 132 | + * @param loop true to set the motion to loop |
| 133 | + */ |
| 134 | + void SetLoop(csmBool loop); |
| 135 | + |
| 136 | + /** |
| 137 | + * Checks whether the motion is set to loop. |
| 138 | + * |
| 139 | + * @return true if the motion is set to loop; otherwise false. |
| 140 | + */ |
| 141 | + csmBool GetLoop() const; |
| 142 | + |
| 143 | + /** |
| 144 | + * Sets whether to perform fade-in for looping motion. |
| 145 | + * |
| 146 | + * @param loopFadeIn true to perform fade-in for looping motion |
| 147 | + */ |
| 148 | + void SetLoopFadeIn(csmBool loopFadeIn); |
| 149 | + |
| 150 | + /** |
| 151 | + * Checks the setting for fade-in of looping motion. |
| 152 | + * |
| 153 | + * @return true if fade-in for looping motion is set; otherwise false. |
| 154 | + */ |
| 155 | + csmBool GetLoopFadeIn() const; |
| 156 | + |
| 157 | + /** |
| 158 | + * Returns the triggered user data events. |
| 159 | + * |
| 160 | + * @param beforeCheckTimeSeconds previous playback time in seconds |
| 161 | + * @param motionTimeSeconds current playback time in seconds |
| 162 | + * |
| 163 | + * @return instance of the collection of triggered user data events |
| 164 | + * |
| 165 | + * @note The input times should be in seconds, with the motion timing set to zero. |
| 166 | + */ |
| 167 | + virtual const csmVector<const csmString*>& GetFiredEvent(csmFloat32 beforeCheckTimeSeconds, |
| 168 | + csmFloat32 motionTimeSeconds); |
| 169 | + |
| 170 | + /** |
| 171 | + * Sets the motion playback completion callback. |
| 172 | + * |
| 173 | + * Not called in the following cases: |
| 174 | + * 1. When the motion being played is set as "loop" |
| 175 | + * 2. When NULL is set as the callback |
| 176 | + * |
| 177 | + * @param onBeganMotionHandler Motion playback start callback function |
| 178 | + */ |
| 179 | + void SetBeganMotionHandler(BeganMotionCallback onBeganMotionHandler); |
| 180 | + |
| 181 | + /** |
| 182 | + * Sets the motion playback start callback. |
| 183 | + * |
| 184 | + * @return Set motion playback start callback function. NULL if no function is set. |
| 185 | + */ |
| 186 | + BeganMotionCallback GetBeganMotionHandler() const; |
| 187 | + |
| 188 | + /** |
| 189 | + * Sets the user-defined data. |
| 190 | + * |
| 191 | + * @param onBeganMotionCustomData User-defined data |
| 192 | + */ |
| 193 | + void SetBeganMotionCustomData(void* onBeganMotionCustomData); |
| 194 | + |
| 195 | + /** |
| 196 | + * Returns the user-defined data. |
| 197 | + * |
| 198 | + * @return Set user-defined data. |
| 199 | + */ |
| 200 | + void* GetBeganMotionCustomData() const; |
| 201 | + |
| 202 | + /** |
| 203 | + * Sets the motion playback start callback. |
| 204 | + * |
| 205 | + * Not called in the following cases: |
| 206 | + * 1. When the motion being played is set as "loop" |
| 207 | + * 2. When NULL is set as the callback |
| 208 | + * |
| 209 | + * @param onBeganMotionHandler Motion playback start callback function |
| 210 | + * @param onBeganMotionCustomData User-defined data |
| 211 | + */ |
| 212 | + void SetBeganMotionHandlerAndMotionCustomData(BeganMotionCallback onBeganMotionHandler, void* onBeganMotionCustomData); |
| 213 | + |
| 214 | + /** |
| 215 | + * Sets the callback function for when motion playback ends. |
| 216 | + * |
| 217 | + * @param onFinishedMotionHandler callback function for when motion playback ends |
| 218 | + * |
| 219 | + * @note The callback function is called at the timing of setting the IsFinished flag.<br> |
| 220 | + * Not called in the following states: |
| 221 | + * 1. When the playing motion is a loop motion |
| 222 | + * 2. When the callback function is not set |
| 223 | + */ |
| 224 | + void SetFinishedMotionHandler(FinishedMotionCallback onFinishedMotionHandler); |
| 225 | + |
| 226 | + /** |
| 227 | + * Returns the callback function for when motion playback ends. |
| 228 | + * |
| 229 | + * @return set callback function for when motion playback ends |
| 230 | + */ |
| 231 | + FinishedMotionCallback GetFinishedMotionHandler(); |
| 232 | + |
| 233 | + /** |
| 234 | + * Sets the user-defined data. |
| 235 | + * |
| 236 | + * @param onFinishedMotionCustomData User-defined data |
| 237 | + */ |
| 238 | + void SetFinishedMotionCustomData(void* onFinishedMotionCustomData); |
| 239 | + |
| 240 | + /** |
| 241 | + * Returns the user-defined data. |
| 242 | + * |
| 243 | + * @return Set user-defined data. |
| 244 | + */ |
| 245 | + void* GetFinishedMotionCustomData(); |
| 246 | + |
| 247 | + /** |
| 248 | + * Sets the motion playback completion callback. |
| 249 | + * |
| 250 | + * Called when the IsFinished flag is set. |
| 251 | + * Not called in the following cases: |
| 252 | + * 1. When the motion being played is set as "loop" |
| 253 | + * 2. When NULL is set as the callback |
| 254 | + * |
| 255 | + * @param onFinishedMotionHandler Motion playback completion callback function |
| 256 | + * @param onFinishedMotionCustomData User-defined data |
| 257 | + */ |
| 258 | + void SetFinishedMotionHandlerAndMotionCustomData(FinishedMotionCallback onFinishedMotionHandler, void* onFinishedMotionCustomData); |
| 259 | + |
| 260 | + /** |
| 261 | + * Checks whether there is an opacity curve. |
| 262 | + * |
| 263 | + * @return true if the key exists; otherwise false. |
| 264 | + */ |
| 265 | + virtual csmBool IsExistModelOpacity() const; |
| 266 | + |
| 267 | + /** |
| 268 | + * Returns the index of the opacity curve. |
| 269 | + * |
| 270 | + * @return index of the opacity curve on success |
| 271 | + */ |
| 272 | + virtual csmInt32 GetModelOpacityIndex() const; |
| 273 | + |
| 274 | + /** |
| 275 | + * Returns the ID of the opacity. |
| 276 | + * |
| 277 | + * @return ID of the opacity on success |
| 278 | + */ |
| 279 | + virtual CubismIdHandle GetModelOpacityId(csmInt32 index); |
| 280 | + |
| 281 | + /** |
| 282 | + * Updates the fade weight of the motion. |
| 283 | + * |
| 284 | + * @param motionQueueEntry motion managed by the CubismMotionQueueManager |
| 285 | + * @param userTimeSeconds cumulative delta time in seconds |
| 286 | + * |
| 287 | + * @return true if the fade weight of the motion is updated; otherwise false. |
| 288 | + */ |
| 289 | + csmFloat32 UpdateFadeWeight(CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds); |
| 290 | + |
| 291 | +private: |
| 292 | + // Prevention of copy Constructor |
| 293 | + ACubismMotion(const ACubismMotion&); |
| 294 | + ACubismMotion& operator=(const ACubismMotion&); |
| 295 | + |
| 296 | +protected: |
| 297 | + virtual ~ACubismMotion(); |
| 298 | + |
| 299 | + virtual csmFloat32 GetModelOpacityValue() const; |
| 300 | + |
| 301 | + virtual void DoUpdateParameters(CubismModel* model, csmFloat32 userTimeSeconds, csmFloat32 weight, CubismMotionQueueEntry* motionQueueEntry) = 0; |
| 302 | + |
| 303 | + void AdjustEndTime(CubismMotionQueueEntry* motionQueueEntry); |
| 304 | + |
| 305 | + csmFloat32 _fadeInSeconds; |
| 306 | + csmFloat32 _fadeOutSeconds; |
| 307 | + csmFloat32 _weight; |
| 308 | + csmFloat32 _offsetSeconds; |
| 309 | + csmBool _isLoop; |
| 310 | + csmBool _isLoopFadeIn; |
| 311 | + csmBool _previousLoopState; |
| 312 | + |
| 313 | + csmVector<const csmString*> _firedEventValues; |
| 314 | + |
| 315 | + BeganMotionCallback _onBeganMotion; |
| 316 | + void* _onBeganMotionCustomData; |
| 317 | + FinishedMotionCallback _onFinishedMotion; |
| 318 | + void* _onFinishedMotionCustomData; |
| 319 | +}; |
| 320 | + |
| 321 | +}}} |
0 commit comments