Spine Runtime for Delphi移植笔记(八) - spinedata_Delphi教程_网络编程_码蚁之家_www.codes51.com
返回首页
专题
网络编程
ASP教程 .NET教程 PHP教程 JSP教程 C#教程 Java教程 Delphi教程 VB教程 C/C++教程 Android开发 IOS开发 Windows Phone开发 Python教程 Ruby教程 移动开发 其他编程教程
网页制作
HTML教程 CSS教程 Dreamweaver教程 FrontPages教程 Javascript教程 web前端
数据库
SqlServer MySql Oracle Access DB2 SQLite 其他数据库
图形设计
photoshop教程 Fireworks教程 CorelDraw教程 Illustrator教程 AutoCad教程 FLASH教程
操作系统
Windows xp教程 Windows 7教程 Windows 8教程 Windows 2003教程 Windows Server 2008教程 Linux教程 Windows 10
网站运营
建站经验 SEO优化 站长心得 网赚技巧 网站推广 站长故事
手机学院
手机速递 安卓教程 iphone教程 手机评测 手机技巧 手机知识 手机应用 手机游戏 手机导购
网店宝典
开店指导 开店经验 网店装修 网店推广 网店seo 网购技巧
软件教程
办公软件 系统工具 媒体工具 压缩工具 图文处理 文件管理
范文之家
自我介绍 自我鉴定 写作模板 合同范本 工作总结 贺词祝福语 演讲致辞 思想汇报 入党申请书 实习报告 心得体会 工作计划 简历模板 工作报告 导游词 评语寄语 口号大全 策划书范文
信息工程
软件工程 企业开发 系统运维 软件测试
移民之家
移民动态 移民政策 移民百科 移民生活 技术移民 投资移民
知识大全
母婴 数码 摄影 装修 美文 常识 时尚 婚嫁 美食 养生 旅游 兴趣 职场 教育 文学 健康
问答大全
电脑网络 手机数码 QQ专区 生活 游戏 体育运动 娱乐明星 休闲爱好 文化艺术 社会民生 教育科学 健康医疗 商业理财 情感家庭 地区问题 其他
编程问答
IOS Android .NET Java C/C++ Delphi VC/MFC 其他语言 PHP MSSQL MYSQL Oracle 其他数据库 Web开发 Windows Linux 硬件/嵌入开发 网络通信 移动开发 云计算 企业IT 游戏开发
笑话大全
幽默笑话 爱情笑话 成人笑话 校园笑话 爆笑笑话 综合笑话 古代笑话 现代笑话 国外笑话

Spine Runtime for Delphi移植笔记(八) - spinedata

来源:互联网  时间:2017/8/2 6:51:41

////////////////////////////////////////////////////////////////////////////////
//Generic delphi runtime v3.6 for Spine animation tool                        //
//Runtime port by cjk (hzi1980@163.com)                                       //
////////////////////////////////////////////////////////////////////////////////unit spine.data;

interfaceuses
  System.Classes, System.SysUtils, System.Generics.Collections,
  spine.types, spine.classes,
  spine.core.skin, spine.core.animation;

type
  TSkeletonData = class;
  TBoneData = class;
  TSlotData = class;
  TEventData = class;
  TAnimationStateData = class;
  TIkConstraintData = class;
  TTransformConstraintData = class;
  TPathConstraintData = class;

  TSkeletonData = class(TObject)
  private
    FPathConstraintDatas: TObjectList<TPathConstraintData>;
    FIkConstraintDatas: TObjectList<TIkConstraintData>;
    FTransformConstraintDatas: TObjectList<TTransformConstraintData>;
    FEventDatas: TObjectList<TEventData>;
    FBoneDatas: TObjectList<TBoneData>;
    FSkins: TObjectList<TSpineSkin>;
    FSlotDatas: TObjectList<TSlotData>;
    FAnimations: TObjectList<TSpineAnimation>;
  public
    Name: string;
    DefaultSkin: TSpineSkin;
    Width, Height: Single;
    Version: string;
    Hash: string;
    ImagesPath: string;
    FPS: Single;
    property BoneDatas: TObjectList<TBoneData> read FBoneDatas;
    property SlotDatas: TObjectList<TSlotData> read FSlotDatas;
    property Skins: TObjectList<TSpineSkin> read FSkins;
    property EventDatas: TObjectList<TEventData> read FEventDatas;
    property Animations: TObjectList<TSpineAnimation> read FAnimations;
    property IkConstraintDatas: TObjectList<TIkConstraintData> read FIkConstraintDatas;
    property TransformConstraintDatas: TObjectList<TTransformConstraintData> read FTransformConstraintDatas;
    property PathConstraintDatas: TObjectList<TPathConstraintData> read FPathConstraintDatas;
  publicconstructorCreate;
    destructorDestroy; override;

    function FindBone(const ABoneDataName: string): TBoneData;
    function FindBoneIndex(const ABoneDataName: string): Integer;
    function FindSlot(const ASlotDataName: string): TSlotData;
    function FindSlotIndex(const ASlotDataName: string): Integer;
    function FindSkin(const ASkinName: string): TSpineSkin;
    function FintEvent(const AEventDataName: string): TEventData;
    function FindAnimation(const AAnimationName: string): TSpineAnimation;
    function FindIkConstraint(const AConstraintDataName: string): TIkConstraintData;
    function FindTransformConstraint(const AConstraintDataName: string): TTransformConstraintData;
    function FindPathConstraint(const AConstraintDataName: string): TPathConstraintData;
    function FindPathConstraintIndex(const AConstraintDataName: string): Integer;
  end;

  TBoneData = class(TObject)
  private
    FIndex: Integer;
    FName: string;
    FParent: TBoneData;
  public
    Length: Single;
    X, Y, Rotation, ScaleX, ScaleY, ShearX, ShearY: Single;
    TransformMode: TTransformMode;
    property Index: Integer read FIndex;
    property Name: stringread FName;
    property Parent: TBoneData read FParent;
  publicconstructorCreate(const AIndex: Integer; const AName: string; const AParent: TBoneData);
  end;

  TSlotData = class(TObject)
  private
    FIndex: Integer;
    FName: string;
    FBoneData: TBoneData;
  public
    R, G, B, A, R2, G2, B2: Single;
    HasSecondColor: Boolean;
    AttachmentName: string;
    BlendMode: TBlendMode;
    property Index: Integer read FIndex;
    property Name: stringread FName;
    property BoneData: TBoneData read FBoneData;
  publicconstructorCreate(const AIndex: Integer; const AName: string; const ABoneData: TBoneData);
  end;

  TEventData = class(TObject)
  private
    FName: string;
  public
    IntValue: Integer;
    FloatValue: Single;
    StringValue: string;
    property Name: stringread FName;
  publicconstructorCreate(const AName: string);
  end;

  TAnimationPair = record
    A1: TSpineAnimation;
    A2: TSpineAnimation;
  end;
  TAnimationStateData = class(TObject)
  private
    FSkeletonData: TSkeletonData;
    FAnimationToMixTime: TDictionary<TAnimationPair, Single>;
  public
    DefaultMix: Single;
    property SkeletonData: TSkeletonData read FSkeletonData;
  publicconstructorCreate(const ASkeletonData: TSkeletonData);
    destructorDestroy; override;

    procedure SetMix(const AFromName, AToName: string; const ADuration: Single); overload;
    procedure SetMix(const AFrom, ATo: TSpineAnimation; const ADuration: Single); overload;
    function GetMix(const AFrom, ATo: TSpineAnimation): Single;
  end;

  TIkConstraintData = class(TObject)
  private
    FName: string;
    FBoneDatas: TList<TBoneData>;
  public
    Order: Integer;
    Mix: Single;
    BendDirection: Integer;
    Target: TBoneData;
    property Name: stringread FName;
    property BoneDatas: TList<TBoneData> read FBoneDatas;
  publicconstructorCreate(const AName: string);
    destructorDestroy; override;
  end;

  TTransformConstraintData = class(TObject)
  private
    FName: string;
    FBoneDatas: TList<TBoneData>;
  public
    Order: Integer;
    Target: TBoneData;
    RotateMix, TranslateMix, ScaleMix, ShearMix: Single;
    OffsetRotation, OffsetX, OffsetY, OffsetScaleX, OffsetScaleY, OffsetShearY: Single;
    Relative, Local: Boolean;
    property Name: stringread FName;
    property BoneDatas: TList<TBoneData> read FBoneDatas;
  publicconstructorCreate(const AName: string);
    destructorDestroy; override;
  end;

  TPathConstraintData = class(TObject)
  private
    FName: string;
    FBoneDatas: TList<TBoneData>;
  public
    Order: Integer;
    Relative: Boolean;
    Local: Boolean;
    Target: TSlotData;
    PositionMode: TPositionMode;
    SpacingMode: TSpacingMode;
    RotateMode: TRotateMode;
    OffsetRotation, Position, Spacing, RotateMix, TranslateMix: Single;
    property Name: stringread FName;
    property BoneDatas: TList<TBoneData> read FBoneDatas;
  publicconstructorCreate(const AName: string);
    destructorDestroy; override;
  end;

implementation{ TSkeletonData }constructor TSkeletonData.Create;
begininheritedCreate;
  FPathConstraintDatas:= TObjectList<TPathConstraintData>.Create;
  FIkConstraintDatas:= TObjectList<TIkConstraintData>.Create;
  FTransformConstraintDatas:= TObjectList<TTransformConstraintData>.Create;
  FEventDatas:= TObjectList<TEventData>.Create;
  FBoneDatas:= TObjectList<TBoneData>.Create;
  FSkins:= TObjectList<TSpineSkin>.Create;
  FSlotDatas:= TObjectList<TSlotData>.Create;
  FAnimations:= TObjectList<TSpineAnimation>.Create;
end;

destructor TSkeletonData.Destroy;
begin
  FPathConstraintDatas.Free;
  FIkConstraintDatas.Free;
  FTransformConstraintDatas.Free;
  FEventDatas.Free;
  FBoneDatas.Free;
  FSkins.Free;
  FSlotDatas.Free;
  FAnimations.Free;
  inherited;
end;

function TSkeletonData.FindBone(const ABoneDataName: string): TBoneData;
var
  i: Integer;
begin
  result:= nil;
  if ABoneDataName.Trim.IsEmpty thenraise Exception.Create('boneDataName cannot be null.');
  for i:= 0to FBoneDatas.Count -1dobeginif FBoneDatas.Items[i].Name = ABoneDataName then
      exit(FBoneDatas.Items[i]);
  end;
end;

function TSkeletonData.FindBoneIndex(const ABoneDataName: string): Integer;
var
  i: Integer;
begin
  result:= -1;
  if ABoneDataName.Trim.IsEmpty thenraise Exception.Create('boneDataName cannot be null.');
  for i:= 0to FBoneDatas.Count -1dobeginif FBoneDatas.Items[i].Name = ABoneDataName then
      exit(i);
  end;
end;

function TSkeletonData.FindSkin(const ASkinName: string): TSpineSkin;
var
  lSkin: TSpineSkin;
begin
  result:= nil;
  if ASkinName.Trim.IsEmpty thenraise Exception.Create('skinName cannot be null.');
  for lSkin in FSkins doif lSkin.Name = ASkinName then
      exit(lSkin);
end;

function TSkeletonData.FindSlot(const ASlotDataName: string): TSlotData;
var
  i: Integer;
begin
  result:= nil;
  if ASlotDataName.Trim.IsEmpty thenraise Exception.Create('slotDataName cannot be null.');
  for i:= 0to FSlotDatas.Count -1dobeginif FSlotDatas.Items[i].Name = ASlotDataName then
      exit(FSlotDatas.Items[i]);
  end;
end;

function TSkeletonData.FindSlotIndex(const ASlotDataName: string): Integer;
var
  i: Integer;
begin
  result:= -1;
  if ASlotDataName.Trim.IsEmpty thenraise Exception.Create('slotDataName cannot be null.');
  for i:= 0to FSlotDatas.Count -1dobeginif FSlotDatas.Items[i].Name = ASlotDataName then
      exit(i);
  end;
end;

function TSkeletonData.FintEvent(const AEventDataName: string): TEventData;
var
  lData: TEventData;
begin
  result:= nil;
  if AEventDataName.Trim.IsEmpty thenraise Exception.Create('eventDataName cannot be null.');
  for lData in FEventDatas doif lData.Name = AEventDataName then
      exit(lData);
end;

function TSkeletonData.FindAnimation(const AAnimationName: string): TSpineAnimation;
var
  i: Integer;
begin
  result:= nil;
  if AAnimationName.Trim.IsEmpty thenraise Exception.Create('animationName cannot be null.');
  for i:= 0to FAnimations.Count -1dobeginif FAnimations.Items[i].Name = AAnimationName then
      exit(FAnimations.Items[i]);
  end;
end;

function TSkeletonData.FindIkConstraint(
  const AConstraintDataName: string): TIkConstraintData;
var
  i: Integer;
begin
  result:= nil;
  if AConstraintDataName.Trim.IsEmpty thenraise Exception.Create('constraintDataName cannot be null.');
  for i:= 0to FIkConstraintDatas.Count -1dobeginif FIkConstraintDatas.Items[i].Name = AConstraintDataName then
      exit(FIkConstraintDatas.Items[i]);
  end;
end;

function TSkeletonData.FindPathConstraint(
  const AConstraintDataName: string): TPathConstraintData;
var
  i: Integer;
begin
  result:= nil;
  if AConstraintDataName.Trim.IsEmpty thenraise Exception.Create('constraintDataName cannot be null.');
  for i:= 0to FPathConstraintDatas.Count -1dobeginif FPathConstraintDatas.Items[i].Name = AConstraintDataName then
      exit(FPathConstraintDatas.Items[i]);
  end;
end;

function TSkeletonData.FindPathConstraintIndex(
  const AConstraintDataName: string): Integer;
var
  i: Integer;
begin
  result:= -1;
  if AConstraintDataName.Trim.IsEmpty thenraise Exception.Create('constraintDataName cannot be null.');
  for i:= 0to FIkConstraintDatas.Count -1dobeginif FIkConstraintDatas.Items[i].Name = AConstraintDataName then
      exit(i);
  end;
end;

function TSkeletonData.FindTransformConstraint(
  const AConstraintDataName: string): TTransformConstraintData;
var
  i: Integer;
begin
  result:= nil;
  if AConstraintDataName.Trim.IsEmpty thenraise Exception.Create('constraintDataName cannot be null.');
  for i:= 0to FTransformConstraintDatas.Count -1dobeginif FTransformConstraintDatas.Items[i].Name = AConstraintDataName then
      exit(FTransformConstraintDatas.Items[i]);
  end;
end;

{ TBoneData }constructor TBoneData.Create(const AIndex: Integer; const AName: string;
  const AParent: TBoneData);
begininheritedCreate;
  if AIndex < 0thenraise Exception.Create('index must be >= 0.');
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  FIndex:= AIndex;
  FName:= AName;
  FParent:= AParent;
  ScaleX:= 1;
  ScaleY:= 1;
  TransformMode:= TTransformMode.tmNormal;
end;

{ TSlotData }constructor TSlotData.Create(const AIndex: Integer; const AName: string;
  const ABoneData: TBoneData);
begininheritedCreate;
  if AIndex < 0thenraise Exception.Create('index must be >= 0.');
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  ifnot Assigned(ABoneData) thenraise Exception.Create('boneData cannot be null.');
  FIndex:= AIndex;
  FName:= AName;
  FBoneData:= ABoneData;
  R:= 1; G:= 1; B:= 1; A:= 1;
  R2:= 0; G2:= 0; B2:= 0;
  HasSecondColor:= False;
end;

{ TEventData }constructor TEventData.Create(const AName: string);
begininheritedCreate;
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  FName:= AName;
end;

{ TAnimationStateData }constructor TAnimationStateData.Create(const ASkeletonData: TSkeletonData);
begininheritedCreate;
  ifnot Assigned(ASkeletonData) thenraise Exception.Create('skeletonData cannot be null.');
  FAnimationToMixTime:= TDictionary<TAnimationPair, Single>.Create;
    FSkeletonData:= ASkeletonData;
end;

destructor TAnimationStateData.Destroy;
begin
  FAnimationToMixTime.Free;
  inherited;
end;

procedure TAnimationStateData.SetMix(const AFromName, AToName: string;
  const ADuration: Single);
var
  lFrom, lTo: TSpineAnimation;
begin
  lFrom:= FSkeletonData.FindAnimation(AFromName);
  ifnot Assigned(lFrom) thenraise Exception.CreateFmt('Animation not found: %s',[AFromName]);
  lTo:= FSkeletonData.FindAnimation(AToName);
  ifnot Assigned(lTo) thenraise Exception.CreateFmt('Animation not found: %s',[AToName]);
  SetMix(lFrom, lTo, ADuration);
end;

procedure TAnimationStateData.SetMix(const AFrom, ATo: TSpineAnimation;
  const ADuration: Single);
var
  lKey: TAnimationPair;
beginifnot Assigned(AFrom) thenraise Exception.Create('from animation cannot be null.');
  ifnot Assigned(ATo) thenraise Exception.Create('to animation cannot be null.');
    lKey.A1:= AFrom;
  lKey.A2:= ATo;
  FAnimationToMixTime.AddOrSetValue(lKey, ADuration);
end;

function TAnimationStateData.GetMix(const AFrom, ATo: TSpineAnimation): Single;
var
  lKey: TAnimationPair;
beginifnot Assigned(AFrom) thenraise Exception.Create('from animation cannot be null.');
  ifnot Assigned(ATo) thenraise Exception.Create('to animation cannot be null.');
    lKey.A1:= AFrom;
  lKey.A2:= ATo;
  ifnot FAnimationToMixTime.TryGetValue(lKey, result) then
    result:= DefaultMix;
end;

{ TIkConstraintData }constructor TIkConstraintData.Create(const AName: string);
begininheritedCreate;
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  FName:= AName;
  FBoneDatas:= TList<TBoneData>.Create;
end;

destructor TIkConstraintData.Destroy;
begin
  FBoneDatas.Free;
  inherited;
end;

{ TTransformConstraintData }constructor TTransformConstraintData.Create(const AName: string);
begininheritedCreate;
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  FName:= AName;
  FBoneDatas:= TList<TBoneData>.Create;
end;

destructor TTransformConstraintData.Destroy;
begin
  FBoneDatas.Free;
  inherited;
end;

{ TPathConstraintData }constructor TPathConstraintData.Create(const AName: string);
begininheritedCreate;
  if AName.Trim.IsEmpty thenraise Exception.Create('name cannot be null.');
  FName:= AName;
  FBoneDatas:= TList<TBoneData>.Create;
end;

destructor TPathConstraintData.Destroy;
begin
  FBoneDatas.Free;
  inherited;
end;

end.

各种数据


上一篇Spine Runtime for Delphi移植笔记(六) - spinecoreskeletonbinary
下一篇[笔记] Delphi 1021 Tokyo 安装使用笔记
明星图片
相关文章
《 Spine Runtime for Delphi移植笔记(八) - spinedata》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)