| 1 |
{ |
| 2 |
Copyright 2007-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Loading MD3 (used by Quake3 and derivatives like Tremulous) format. |
| 17 |
Loads wit skin and animations. |
| 18 |
|
| 19 |
References: |
| 20 |
- Format spec: http://icculus.org/homepages/phaethon/q3a/formats/md3format.html |
| 21 |
- Another format spec: https://mino-git.github.io/rtcw-wet-blender-model-tools/md3.html |
| 22 |
- One sample implementation: https://github.com/edems96/MD3-Model---Animation-Viewer/tree/master/src |
| 23 |
} |
| 24 |
unit X3DLoadInternalMD3; |
| 25 |
|
| 26 |
{$I castleconf.inc} |
| 27 |
|
| 28 |
interface |
| 29 |
|
| 30 |
implementation |
| 31 |
|
| 32 |
uses SysUtils, Classes, Generics.Collections, |
| 33 |
CastleUtils, CastleClassUtils, CastleVectors, X3DNodes, X3DLoad, |
| 34 |
CastleInternalNodeInterpolator, CastleQuaternions, |
| 35 |
CastleFilesUtils, CastleStringUtils, CastleBoxes, X3DLoadInternalUtils, |
| 36 |
X3DCameraUtils, CastleDownload, CastleUriUtils, CastleLog; |
| 37 |
|
| 38 |
type |
| 39 |
EInvalidMD3 = class(Exception); |
| 40 |
|
| 41 |
const |
| 42 |
GoodIdent: AnsiString = 'IDP3'; |
| 43 |
|
| 44 |
{$I x3dloadinternalmd3_structs.inc} |
| 45 |
{$I x3dloadinternalmd3_surface.inc} |
| 46 |
{$I x3dloadinternalmd3_animation.inc} |
| 47 |
{$I x3dloadinternalmd3_converter.inc} |
| 48 |
|
| 49 |
function LoadMD3(const Stream: TStream; const BaseUrl: String): TX3DRootNode; |
| 50 |
var |
| 51 |
Md3: TMD3Converter; |
| 52 |
begin |
| 53 |
Md3 := TMD3Converter.Create(Stream, BaseUrl); |
| 54 |
try |
| 55 |
Result := Md3.ToX3D; |
| 56 |
finally FreeAndNil(Md3) end; |
| 57 |
end; |
| 58 |
|
| 59 |
var |
| 60 |
ModelFormat: TModelFormat; |
| 61 |
initialization |
| 62 |
ModelFormat := TModelFormat.Create; |
| 63 |
ModelFormat.OnLoad := {$ifdef FPC}@{$endif} LoadMD3; |
| 64 |
ModelFormat.OnLoadForceMemoryStream := true; |
| 65 |
ModelFormat.MimeTypes.Add('application/x-md3'); |
| 66 |
ModelFormat.FileFilterName := 'Quake 3 engine models (*.md3)'; |
| 67 |
ModelFormat.Extensions.Add('.md3'); |
| 68 |
RegisterModelFormat(ModelFormat); |
| 69 |
end. |