GXS.FileDAE.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Graphic Scene Engine, http://glscene.org
  3. //
  4. {
  5. Quake2 MD2 vector file format implementation.
  6. }
  7. unit GXS.FileDAE;
  8. interface
  9. {$I Stage.Defines.inc}
  10. uses
  11. System.Classes,
  12. System.SysUtils,
  13. FMX.DAE.Importer,
  14. FMX.DAE.Model,
  15. GXS.VectorFileObjects,
  16. GXS.ApplicationFileIO;
  17. type
  18. // TgxFileDAE
  19. //
  20. { The DAE vector file (COLLADA actor file).
  21. Stores a set of "frames" describing the different postures of the actor,
  22. it may be animated by TgxActor. The "Skin" must be loaded indepentendly
  23. (the whole mesh uses a single texture bitmap). }
  24. TgxFileDAE = class(TgxVectorFile)
  25. public
  26. class function Capabilities : TDataFileCapabilities; override;
  27. procedure LoadFromStream(aStream : TStream); override;
  28. end;
  29. // ------------------------------------------------------------------
  30. // ------------------------------------------------------------------
  31. // ------------------------------------------------------------------
  32. implementation
  33. // ------------------
  34. // ------------------ TgxDAEVectorFile ------------------
  35. // ------------------
  36. // Capabilities
  37. //
  38. class function TgxFileDAE.Capabilities : TDataFileCapabilities;
  39. begin
  40. Result:=[dfcRead];
  41. end;
  42. // LoadFromStream
  43. //
  44. procedure TgxFileDAE.LoadFromStream(aStream : TStream);
  45. var
  46. i, j : Integer;
  47. DAEFile : TgxFileDAE;
  48. mesh : TgxMorphableMeshObject;
  49. faceGroup : TgxFGIndexTexCoordList;
  50. morphTarget : TgxMeshMorphTarget;
  51. begin
  52. { TODO : E2035 Not enough actual parameters }
  53. (*DAEFile:=TgxFileDAE.Create();*)
  54. DAEFile.LoadFromStream(aStream);
  55. try
  56. // retrieve mesh data
  57. mesh:=TgxMorphableMeshObject.CreateOwned(Owner.MeshObjects);
  58. with mesh, DAEFile do begin
  59. Mode:=momFaceGroups;
  60. faceGroup:=TgxFGIndexTexCoordList.CreateOwned(FaceGroups);
  61. with faceGroup do begin
  62. MaterialName:='';
  63. { TODO : E2003 Undeclared identifier: 'iTriangles' }
  64. (*
  65. VertexIndices.Capacity:=iTriangles*3;
  66. TexCoords.Capacity:=iTriangles*3;
  67. // copy the face list
  68. for i:=0 to iTriangles-1 do with IndexList[i] do begin
  69. Add(a, a_s, -a_t);
  70. Add(b, b_s, -b_t);
  71. Add(c, c_s, -c_t);
  72. end;
  73. *)
  74. end;
  75. // retrieve frames data (morph targets)
  76. { TODO : E2003 Undeclared identifier: 'iFrames' }
  77. (*
  78. for i:=0 to iFrames-1 do begin
  79. morphTarget:=TgxMeshMorphTarget.CreateOwned(MorphTargets);
  80. with morphTarget do begin
  81. Name:='Frame'+IntToStr(i);
  82. Vertices.Capacity:=iVertices;
  83. for j:=0 to iVertices-1 do
  84. Vertices.Add(VertexList[i][j]);
  85. BuildNormals(faceGroup.VertexIndices, momTriangles);
  86. end;
  87. end;
  88. *)
  89. end;
  90. if GetOwner is TgxActor then with TgxActor(GetOwner).Animations do begin
  91. Clear;
  92. { TODO : E2003 Undeclared identifier: 'frameNames' }
  93. (*
  94. with DAEFile do for i:=0 to frameNames.Count-1 do with Add do begin
  95. Name:=frameNames[i];
  96. Reference:=aarMorph;
  97. StartFrame:=Integer(frameNames.Objects[i]);
  98. if i<frameNames.Count-1 then
  99. EndFrame:=Integer(frameNames.Objects[i+1])-1
  100. else EndFrame:=iFrames-1;
  101. end;
  102. *)
  103. end;
  104. if mesh.MorphTargets.Count>0 then
  105. mesh.MorphTo(0);
  106. finally
  107. DAEFile.Free;
  108. end;
  109. end;
  110. // ------------------------------------------------------------------
  111. // ------------------------------------------------------------------
  112. // ------------------------------------------------------------------
  113. initialization
  114. // ------------------------------------------------------------------
  115. // ------------------------------------------------------------------
  116. // ------------------------------------------------------------------
  117. RegisterVectorFileFormat('dae', 'COLLADA model files', TgxFileDAE);
  118. end.