@@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1111</editor-fold> */
1212
1313#include < vsg/animation/CameraAnimation.h>
14+ #include < vsg/animation/TransformSampler.h>
1415#include < vsg/app/Camera.h>
1516#include < vsg/io/Logger.h>
1617#include < vsg/io/Options.h>
@@ -35,28 +36,46 @@ CameraAnimation::CameraAnimation(ref_ptr<Object> in_object, const Path& in_filen
3536 {
3637 for (auto sampler : animation->samplers )
3738 {
38- if (auto ts = sampler.cast <TransformSampler >())
39+ if (auto cs = sampler.cast <CameraSampler >())
3940 {
40- transformSampler = ts ;
41+ cameraSampler = cs ;
4142 break ;
4243 }
4344 }
4445 }
45- else if ((transformSampler = read_object.cast <TransformSampler >()))
46+ else if ((cameraSampler = read_object.cast <CameraSampler >()))
4647 {
4748 animation = Animation::create ();
48- animation->samplers .push_back (transformSampler);
49+ animation->samplers .push_back (cameraSampler);
50+ }
51+ else if (auto ts = read_object.cast <TransformSampler>())
52+ {
53+ auto tkf = ts->keyframes ;
54+
55+ // convert TransformSampler to CameraSampler
56+ cameraSampler = CameraSampler::create ();
57+ cameraSampler->name = ts->name ;
58+ auto & ckf = cameraSampler->keyframes = CameraKeyframes::create ();
59+
60+ ckf->positions = tkf->positions ;
61+ ckf->rotations = tkf->rotations ;
62+
63+ animation = Animation::create ();
64+ animation->samplers .push_back (cameraSampler);
4965 }
5066 else if (auto keyframes = read_object.cast <TransformKeyframes>())
5167 {
52- transformSampler = TransformSampler::create ();
53- transformSampler->keyframes = keyframes;
68+ cameraSampler = CameraSampler::create ();
69+ auto & ckf = cameraSampler->keyframes = CameraKeyframes::create ();
70+
71+ ckf->positions = keyframes->positions ;
72+ ckf->rotations = keyframes->rotations ;
5473
5574 animation = Animation::create ();
56- animation->samplers .push_back (transformSampler );
75+ animation->samplers .push_back (cameraSampler );
5776 }
5877 }
59- if (object && transformSampler) transformSampler ->object = object;
78+ if (object && cameraSampler) cameraSampler ->object = object;
6079 }
6180 else
6281 {
@@ -74,10 +93,10 @@ CameraAnimation::CameraAnimation(ref_ptr<Object> in_object, ref_ptr<Animation> i
7493 {
7594 for (auto & sampler : animation->samplers )
7695 {
77- if (auto ts = sampler.cast <TransformSampler >())
96+ if (auto ts = sampler.cast <CameraSampler >())
7897 {
79- transformSampler = ts;
80- transformSampler ->object = object;
98+ cameraSampler = ts;
99+ cameraSampler ->object = object;
81100 break ;
82101 }
83102 }
@@ -86,33 +105,33 @@ CameraAnimation::CameraAnimation(ref_ptr<Object> in_object, ref_ptr<Animation> i
86105
87106void CameraAnimation::apply (Camera& camera)
88107{
89- if (transformSampler )
108+ if (cameraSampler )
90109 {
91- auto & keyframes = transformSampler ->keyframes ;
92- if (!keyframes) keyframes = TransformKeyframes ::create ();
110+ auto & keyframes = cameraSampler ->keyframes ;
111+ if (!keyframes) keyframes = CameraKeyframes ::create ();
93112
94113 dvec3 position, scale;
95114 dquat orientation;
96115 auto matrix = camera.viewMatrix ->inverse ();
97116 if (decompose (matrix, position, orientation, scale))
98117 {
99- keyframes->add (simulationTime - startTime, position, orientation, scale );
118+ keyframes->add (simulationTime - startTime, position, orientation);
100119 }
101120 }
102121}
103122
104123void CameraAnimation::apply (MatrixTransform& transform)
105124{
106- if (transformSampler )
125+ if (cameraSampler )
107126 {
108- auto & keyframes = transformSampler ->keyframes ;
109- if (!keyframes) keyframes = TransformKeyframes ::create ();
127+ auto & keyframes = cameraSampler ->keyframes ;
128+ if (!keyframes) keyframes = CameraKeyframes ::create ();
110129
111130 dvec3 position, scale;
112131 dquat orientation;
113132 if (decompose (transform.matrix , position, orientation, scale))
114133 {
115- keyframes->add (simulationTime - startTime, position, orientation, scale );
134+ keyframes->add (simulationTime - startTime, position, orientation);
116135 }
117136 }
118137}
@@ -137,21 +156,21 @@ void CameraAnimation::record()
137156 {
138157 animation = Animation::create ();
139158 }
140- if (!transformSampler )
159+ if (!cameraSampler )
141160 {
142- transformSampler = TransformSampler ::create ();
143- transformSampler ->object = object;
161+ cameraSampler = CameraSampler ::create ();
162+ cameraSampler ->object = object;
144163
145- animation->samplers .push_back (transformSampler );
164+ animation->samplers .push_back (cameraSampler );
146165 }
147166
148- if (transformSampler ->keyframes )
167+ if (cameraSampler ->keyframes )
149168 {
150- transformSampler ->keyframes ->clear ();
169+ cameraSampler ->keyframes ->clear ();
151170 }
152171 else
153172 {
154- transformSampler ->keyframes = TransformKeyframes ::create ();
173+ cameraSampler ->keyframes = CameraKeyframes ::create ();
155174 }
156175}
157176
0 commit comments