first commit

This commit is contained in:
2026-06-22 11:49:35 +02:00
commit d805f2ba86
619 changed files with 126873 additions and 0 deletions

View File

@ -0,0 +1,114 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NMOTION__
#define __NMOTION__
#include "motion/quaternion_channel.h"
#include "motion/motion_channel.h"
#include "core/path_kdtree.h"
#include "container/nlist.h"
#include "memory/nshared_ptr.h"
#include "memory/nauto_ptr.h"
namespace GS {
namespace Automation { class Player; }
namespace Core {
/*!
@short Motion.
A motion holds together a group of channels.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class Motion : public SharedObject
{
friend class Automation::Player;
protected:
struct SDataPoint
{
Time t;
Variant data;
};
ArrayList <SDataPoint *> data_point; ///< data per point.
AutoList <MotionChannel *> channel_list;
bool use_quaternion;
QuaternionChannel quaternion;
public:
NPLACEMENT_NEW(Motion)
String name;
AutoPtr <PathKdtree> quadtree;
/// Clone a motion, optionally specify the range to clone.
void Clone(const Motion &, const TimeRange &, bool enforce_loop);
/// Sample time from position
bool GetClosestPoint(const Vector4 &p, Vector4 &closest, float *closest_t = 0);
void EvaluateData(const Time &t, Variant &sample);
void EvaluatePosition(const Time &t, Vector4 &sample, Curve::LoopMode loop_mode = Curve::Reset);
void EvaluateRotation(const Time &t, Vector4 &sample, Curve::LoopMode loop_mode = Curve::Reset);
/// Get transformation channels.
void GetTransformationChannels(MotionChannel *t[3], MotionChannel *r[3], MotionChannel *s[3]);
bool HasKey(const TimeRange &t) const;
void MoveKey(const TimeRange &t, const Time &offset) const;
void DeleteKey(const TimeRange &t);
/// Add a new channel controlling a given property to the motion.
MotionChannel *AddChannel(MotionChannel::Type);
/// Add several channels at once.
void AddChannels(uint channel_count);
const AutoList <MotionChannel *> &GetChannelList() const { return channel_list; }
const QuaternionChannel &GetQuaternion() const { return quaternion; }
QuaternionChannel &GetQuaternion() { return quaternion; }
bool GetUseQuaternion() const;
void SetUseQuaternion(bool use) { use_quaternion = use; }
MotionChannel *GetChannel(MotionChannel::Type) const;
MotionChannel *GetChannel(uint index) const;
/// Return the motion duration.
Time GetDuration() const;
/// Return the motion time range.
TimeRange GetTimeRange() const;
/// Return the memory footprint in bytes of the channel.
size_t MemoryFootPrint() const;
/*!
@short Optimize motion.
Remove keys influencing output below a given threshold.
@note This function calls Optimize() for all of the motion channels.
*/
uint Optimize(float threshold = DefaultCurveOptimizationThreshold);
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag();
~Motion() {
ArrayListDeleteAllPtr(SDataPoint *, data_point)
}
};
} // Core
} // GS
#endif // __NMOTION__

View File

@ -0,0 +1,63 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __MOTION_AUTOMATION_SOURCE__
#define __MOTION_AUTOMATION_SOURCE__
#include "automation/automation_source.h"
namespace GS {
namespace Core { class Motion; }
namespace Automation {
struct SourceGroup;
using Core::Motion;
/*!
@short Motion based automation source.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class MotionSource : public Source
{
friend class Player;
protected:
SourceGroup *group;
bool active;
Motion *motion;
Curve::LoopMode loop_mode;
Time loop_start, loop_end;
public:
/// Set loop mode.
virtual void SetLoopMode(Curve::LoopMode loop = Curve::Reset) { loop_mode = loop; }
/// Set loop point.
virtual void SetLoop(const Time &start = Time::Inf, const Time &end = Time::Inf)
{
loop_start = start;
loop_end = end;
}
void Evaluate(Player &);
bool EvaluateRotation(Quaternion &);
/// Is motion done.
bool IsDone() const;
MotionSource(Motion *, SourceGroup * = 0);
};
} // Automation
} // GS
#endif // __MOTION_AUTOMATION_SOURCE__

View File

@ -0,0 +1,76 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __MOTION_CHANNEL__
#define __MOTION_CHANNEL__
#include "geometry/curve.h"
namespace GS {
namespace Core {
/*!
@short Motion channel object.
This class extends the curve class holding together a set of key frames and
able to evaluate the underlying curve object at a specific position.
A channel should be used on a specific value declared by the enumeration
Type.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
struct MotionChannel : public Curve
{
enum Type
{
NoType = 0,
Undf = 0,
// Transformation block.
XPos, YPos, ZPos,
XRot, YRot, ZRot,
XScl, YScl, ZScl,
XPiv, YPiv, ZPiv,
//
RDif, GDif, BDif,
RSpc, GSpc, BSpc,
DiffuseIntensity, SpecularIntensity,
ConeAngle, EdgeAngle,
Alpha,
ZoomFactor,
Range,
FogStart, FogEnd,
RFog, GFog, BFog,
Last
};
Type type;
/// Return the channel memory footprint.
size_t MemoryFootPrint() const { return Curve::MemoryFootPrint() + sizeof(MotionChannel); }
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag() const;
MotionChannel();
~MotionChannel();
};
} // Core
} // GS
#endif // __MOTION_CHANNEL__

View File

@ -0,0 +1,76 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NQUATERNIONCHANNEL__
#define __NQUATERNIONCHANNEL__
#include "geometry/curve.h"
#include "math/quaternion.h"
#include "container/narray.h"
namespace GS {
static const float DefaultChannelOptimizationThresholdQuaternion = 0.01f;
/// Quaternion key.
struct QuaternionKey
{
Time t;
Quaternion q;
QuaternionKey(const Time &_t, const Quaternion &_q) : t(_t), q(_q) {}
QuaternionKey() { q.Set(); }
};
/*!
@short Quaternion channel.
This class hold a set of quaternion keys and can interpolate inside the set
to determine a particular quaternion at a given time.
@author Emmanuel Julien (ejulien@gsworks.fr)
*/
class QuaternionChannel
{
private:
ArrayList <QuaternionKey *> keys;
uint PerformChannelOptimize(uint count, QuaternionKey *src, QuaternionKey *dst, float threshold);
public:
const ArrayList <QuaternionKey *> &GetKeys() const { return keys; }
TimeRange GetTimeRange() const;
Time GetDuration() const { return GetTimeRange().valueRange(); }
/// Insert a key, sort by time.
bool Insert(const QuaternionKey &key);
/// Evaluate channel.
void Evaluate(Time t, Quaternion &q, Curve::LoopMode loop = Curve::Constant, Time loop_start = Time::Inf, Time loop_end = Time::Inf) const;
/// Optimize channel.
uint Optimize(float threshold = DefaultChannelOptimizationThresholdQuaternion);
/// Delete all keys in channel.
void Clear();
/// Return the memory usage for the channel.
size_t MemoryFootPrint() const { return size_t(keys.GetCount()) * sizeof(QuaternionKey) + sizeof(QuaternionChannel); }
bool FromMetaTag(NML::Tag &);
NML::Tag *AsMetaTag();
QuaternionChannel();
~QuaternionChannel();
};
} // GS
#endif // __NQUATERNIONCHANNEL__

View File

@ -0,0 +1,46 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __NMOTIONSET__
#define __NMOTIONSET__
#include "motion/motion.h"
#include "container/nmap.h"
namespace GS {
namespace Core {
/// A motion set holds a reference to several motions.
struct SceneMotion
{
String name;
struct ItemMotion
{
uint uid;
SharedPtr <Motion> motion;
};
AutoList <ItemMotion *> item_motions;
void Clone(const SceneMotion &src, const TimeRange &range, bool enforce_loop);
Motion *GetItemMotion(uint uid, bool create_if_missing = false);
TimeRange GetTimeRange() const;
Time GetDuration() const { return GetTimeRange().valueRange(); }
bool FromMetaTag(NML::Tag &, const Map <uint, uint> *uid_map = 0);
NML::Tag *AsMetaTag();
};
} // Core
} // GS
#endif // __NMOTIONSET__

View File

@ -0,0 +1,30 @@
/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#ifndef __SCENEMOTIONCONTAINER__
#define __SCENEMOTIONCONTAINER__
#include "motion/scene_motion.h"
namespace GS {
namespace Core {
/// Container for scene motions (3D/2D).
struct SceneMotionContainer
{
AutoList <SceneMotion *> motions;
bool FromMetaTag(NML::Tag &, const Map <uint, uint> *uid_map = 0);
NML::Tag *AsMetaTag() const;
};
} // Core
} // GS
#endif // __NMOTIONSETCONTAINER__