33 */
44module dash.components.animation ;
55import dash.core.properties ;
6- import dash.components.component ;
6+ import dash.components;
77import dash.utility;
88
99import derelict.assimp3.assimp;
10- import gl3n.linalg;
1110import std.string : fromStringz;
1211import std.conv : to;
1312
13+ mixin ( registerComponents! () );
14+
1415/**
1516 * Animation object which handles all animation specific to the gameobject
1617 */
1718class Animation : Component
1819{
1920private :
2021 // / Asset animation that the gameobject is animating based off of
21- AssetAnimation _animationData;
22+ @ignore
23+ AnimationData _animationData;
2224 // / Current animation out of all the animations in the asset animation
25+ @ignore
2326 int _currentAnim;
2427 // / Current time of the animation
28+ @ignore
2529 float _currentAnimTime;
2630 // / Bone transforms for the current pose
27- mat4[] _currBoneTransforms;
31+ @ignore
32+ mat4f[] _currBoneTransforms;
2833 // / If the gameobject should be animating
34+ @ignore
2935 bool _animating;
3036
3137 // / Animation to return to if _animateOnce is true
38+ @ignore
3239 int _returnAnimation;
3340 // / If the animation is animating once, then returning to _returnAnimation
41+ @ignore
3442 bool _animateOnce;
3543
3644public :
3745 // / Bone transforms for the current pose (Passed to the shader)
3846 mixin ( Property! _currBoneTransforms );
3947
48+ this ()
49+ {
50+ _currentAnim = 0 ;
51+ _currentAnimTime = 0.0f ;
52+ _animating = true ;
53+ }
54+
4055 /**
4156 * Create animation object based on asset animation
4257 */
43- this ( AssetAnimation assetAnimation )
58+ this ( AnimationData assetAnimation )
4459 {
45- _currentAnim = 0 ;
46- _currentAnimTime = 0.0f ;
60+ this ();
4761 _animationData = assetAnimation;
48- _animating = true ;
4962 }
5063
5164 /**
@@ -107,7 +120,7 @@ public:
107120 _currentAnimTime = startAnimTime;
108121 }
109122 else
110- logWarning ( " Could not change to new animation, the animation did not exist." );
123+ warning ( " Could not change to new animation, the animation did not exist." );
111124 }
112125 /**
113126 * Runs an animation once, then returns
@@ -122,7 +135,7 @@ public:
122135 _currentAnimTime = 0 ;
123136 }
124137 else
125- logWarning ( " Could not change to new animation, the animation did not exist." );
138+ warning ( " Could not change to new animation, the animation did not exist." );
126139 }
127140
128141 /**
@@ -137,7 +150,7 @@ public:
137150/**
138151 * Stores the animation skeleton/bones, stores the animations poses, and makes this information accessible to gameobjects
139152 */
140- class AssetAnimation
153+ class AnimationData : Asset
141154{
142155private :
143156 // / List of animations, containing all of the information specific to each
@@ -165,8 +178,10 @@ public:
165178 * mesh = Assimp mesh/bone object
166179 * nodeHierarchy = Hierarchy of bones/filler nodes used for the animation
167180 */
168- this ( const (aiAnimation** ) animations, int numAnimations, const (aiMesh* ) mesh, const (aiNode* ) nodeHierarchy )
181+ this ( Resource res, const (aiAnimation** ) animations, int numAnimations, const (aiMesh* ) mesh, const (aiNode* ) nodeHierarchy )
169182 {
183+ super ( res );
184+
170185 for ( int i = 0 ; i < nodeHierarchy.mNumChildren; i++ )
171186 {
172187 string name = nodeHierarchy.mChildren[ i ].mName.data.ptr.fromStringz().to! string ;
@@ -307,17 +322,17 @@ public:
307322 *
308323 * Returns: The boneTransforms, returned to the gameobject animation component
309324 */
310- mat4 [] getTransformsAtTime ( int animationNumber, float time )
325+ mat4f [] getTransformsAtTime ( int animationNumber, float time )
311326 {
312- mat4 [] boneTransforms = new mat4 [ _numberOfBones ];
327+ mat4f [] boneTransforms = new mat4f [ _numberOfBones ];
313328
314329 // Check shader/model
315330 for ( int i = 0 ; i < _numberOfBones; i++ )
316331 {
317- boneTransforms[ i ] = mat4 .identity;
332+ boneTransforms[ i ] = mat4f .identity;
318333 }
319334
320- fillTransforms( animationSet[ animationNumber ].bonePoses, boneTransforms, boneHierarchy, time, mat4 .identity );
335+ fillTransforms( animationSet[ animationNumber ].bonePoses, boneTransforms, boneHierarchy, time, mat4f .identity );
321336
322337 return boneTransforms;
323338 }
@@ -330,18 +345,18 @@ public:
330345 * time = The animations current time
331346 * parentTransform = The parents transform (which effects this bone)
332347 */
333- void fillTransforms ( BonePose[] bonePoses, mat4 [] transforms, Bone bone, float time, mat4 parentTransform )
348+ void fillTransforms ( BonePose[] bonePoses, mat4f [] transforms, Bone bone, float time, mat4f parentTransform )
334349 {
335350 BonePose bonePose = bonePoses[ bone.boneNumber ];
336- mat4 finalTransform;
351+ mat4f finalTransform;
337352 if ( bonePose.positionKeys.length == 0 && bonePose.rotationKeys.length == 0 && bonePose.scaleKeys.length == 0 )
338353 {
339354 finalTransform = parentTransform * bone.nodeOffset;
340355 transforms[ bone.boneNumber ] = finalTransform * bone.offset;
341356 }
342357 else
343358 {
344- mat4 boneTransform = mat4 .identity;
359+ mat4f boneTransform = mat4f .identity;
345360
346361 if ( bonePose.positionKeys.length > cast (int )time )
347362 {
@@ -351,7 +366,7 @@ public:
351366 }
352367 if ( bonePose.rotationKeys.length > cast (int )time )
353368 {
354- boneTransform = boneTransform * bonePose.rotationKeys[ cast (int )time ].to_matrix ! ( 4 , 4 ) ;
369+ boneTransform = boneTransform * bonePose.rotationKeys[ cast (int )time ].toMatrix ! 4 ;
355370 }
356371 if ( bonePose.scaleKeys.length > cast (int )time )
357372 {
@@ -372,21 +387,21 @@ public:
372387 }
373388
374389 /**
375- * Converts a aiVectorKey[] to vec3 [].
390+ * Converts a aiVectorKey[] to vec3f [].
376391 *
377392 * Params:
378393 * quaternions = aiVectorKey[] to be converted
379394 * numKeys = Number of keys in vector array
380395 *
381396 * Returns: The vectors in vector[] format
382397 */
383- vec3 [] convertVectorArray ( const (aiVectorKey* ) vectors, int numKeys )
398+ vec3f [] convertVectorArray ( const (aiVectorKey* ) vectors, int numKeys )
384399 {
385- vec3 [] keys ;
400+ vec3f [] keys ;
386401 for ( int i = 0 ; i < numKeys; i++ )
387402 {
388403 aiVector3D vector = vectors[ i ].mValue;
389- keys ~= vec3 ( vector.x, vector.y, vector.z );
404+ keys ~= vec3f ( vector.x, vector.y, vector.z );
390405 }
391406
392407 return keys ;
@@ -400,13 +415,13 @@ public:
400415 *
401416 * Returns: The quaternions in quat[] format
402417 */
403- quat [] convertQuat ( const (aiQuatKey* ) quaternions, int numKeys )
418+ quatf [] convertQuat ( const (aiQuatKey* ) quaternions, int numKeys )
404419 {
405- quat [] keys ;
420+ quatf [] keys ;
406421 for ( int i = 0 ; i < numKeys; i++ )
407422 {
408423 aiQuatKey quaternion = quaternions[ i ];
409- keys ~= quat ( quaternion.mValue.w, quaternion.mValue.x, quaternion.mValue.y, quaternion.mValue.z );
424+ keys ~= quatf ( quaternion.mValue.w, quaternion.mValue.x, quaternion.mValue.y, quaternion.mValue.z );
410425 }
411426
412427 return keys ;
@@ -419,9 +434,9 @@ public:
419434 *
420435 * Returns: The matrix in mat4 format
421436 */
422- mat4 convertAIMatrix ( aiMatrix4x4 aiMatrix )
437+ mat4f convertAIMatrix ( aiMatrix4x4 aiMatrix )
423438 {
424- mat4 matrix = mat4 .identity;
439+ mat4f matrix = mat4f .identity;
425440
426441 matrix[0 ][0 ] = aiMatrix.a1;
427442 matrix[0 ][1 ] = aiMatrix.a2;
@@ -446,7 +461,7 @@ public:
446461 /**
447462 * Shutdown the animation bone/pose data
448463 */
449- void shutdown ()
464+ override void shutdown ()
450465 {
451466
452467 }
@@ -465,9 +480,9 @@ public:
465480 */
466481 class BonePose
467482 {
468- vec3 [] positionKeys;
469- quat [] rotationKeys;
470- vec3 [] scaleKeys;
483+ vec3f [] positionKeys;
484+ quatf [] rotationKeys;
485+ vec3f [] scaleKeys;
471486 }
472487 /**
473488 * A bone in the animation, storing everything it needs
@@ -484,7 +499,7 @@ public:
484499 int boneNumber;
485500 Bone[] children;
486501
487- mat4 offset;
488- mat4 nodeOffset;
502+ mat4f offset;
503+ mat4f nodeOffset;
489504 }
490505}
0 commit comments