ArenaZ

Форк
0
/
GLModelManager.pas 
146 строк · 3.9 Кб
1
unit GLModelManager;
2

3
(*
4
 * Author : Blaise Bernier
5
 * Date   : 08/12/2003
6
 *
7
 ******************************************************************************
8
 * Description :
9
 *    The GLModelManager is a class that provides an easy way to manage
10
 *    models and master objects of proxies at runtime.  You just need to
11
 *    have the model filename and it will load it into the list or return
12
 *    the already existing model.
13
 *
14
 *
15
 *)
16

17
interface
18

19
uses GLScene, GLObjects, GLVectorFileObjects, SysUtils, Classes,
20
     GLFile3DS, GLFileOBJ;
21

22
type
23

24
   (****************************************
25
      TGLModelManager - class definition
26
   ****************************************)
27
   TGLModelManager = class
28
   private
29
      { Private fields }
30
      FMasterObject : TGLDummyCube;
31
      FModelList    : TStringList;
32
      FModelPath    : string;
33

34
      { Get/Set methods }
35
      procedure SetModelPath(const Value: String);
36
   public
37
      { Constructor / Destructor }
38
      constructor Create(AMaster : TGLDummyCube; APath : string); virtual;
39
      destructor Destroy; override;
40

41
      { Methods }
42
      function LoadModel(AFilename : string): TGLFreeForm;
43

44
      { Properties }
45
      property MasterObject : TGLDummyCube read FMasterObject;
46
      property ModelList : TStringList read FModelList;
47
      property Path : string read FModelPath write SetModelPath;
48
   end;
49

50

51
implementation
52

53
(****************************************
54
         { TGLModelManager }
55
****************************************)
56

57
(**********************************
58
   Name        : Create
59
   Description :
60
      This is the constructor.  It will create the list, assign the path to the
61
      models and the master object where the new models will be loaded.
62
*)
63
constructor TGLModelManager.Create(AMaster: TGLDummyCube; APath : string);
64
begin
65
   // Set the master object
66
   FMasterObject := AMaster;
67
   // Create the model list
68
   FModelList := TStringList.Create;
69
   FModelList.CaseSensitive := false;
70
   FModelList.Sorted := true;
71
   // Set the path to the models
72
   SetModelPath(APath);
73
end;
74

75
(**********************************
76
   Name        : Destroy
77
   Description :
78
      This is the destructor.  It will free all the loaded models.
79
*)
80
destructor TGLModelManager.Destroy;
81
var
82
   i : integer;
83
begin
84
   // Destroy every models
85
   for i:=0 to Pred(FModelList.Count) do
86
      FModelList.Objects[i].Destroy;
87
   // Destroy the list
88
   FModelList.Destroy;
89
   inherited;
90
end;
91

92
(**********************************
93
   Name        : LoadModel
94
   Description :
95
      It will load a new model if it's not in the list and then return the new
96
      freeform.  If it,s already in the list, it will return the existing
97
      freeform.
98
*)
99
function TGLModelManager.LoadModel(AFilename: string): TGLFreeForm;
100
var
101
   I           : integer;
102
   NewFreeForm : TGLFreeForm;
103
begin
104

105
   with FModelList do
106
   begin
107
      if Find(AFilename, I) then
108
         Result := TGLFreeForm(Objects[I])
109
      else
110
      begin
111
         NewFreeForm := TGLFreeForm(FMasterOBject.AddNewChild(TGLFreeForm));
112
         NewFreeForm.LoadFromFile(FModelPath + AFilename);
113
         FModelList.AddObject(AFilename,NewFreeForm);
114
         Result := NewFreeForm;
115
      end;
116
   end;
117

118
end;
119

120
(**********************************
121
   Name        : SetModelPath
122
   Description :
123
      It will change the path to the models and refresh the
124
      already existing freeforms
125
*)
126
procedure TGLModelManager.SetModelPath(const Value: String);
127
var
128
   Len : integer;
129
   i   : integer;
130
begin
131
   // Set the path
132
   FModelPath := Value;
133

134
   Len := Length(Value);
135

136
   // Correct it if there is no '\'
137
   if (Len > 0) then
138
      if (Value[Len - 1] <> '\') then
139
         FModelPath := Value + '\';
140

141
   // Reload the models
142
   for i := 0 to Pred(FModelList.Count) do
143
      TGLFreeForm(FModelList.Objects[i]).LoadFromFile(FModelPath + FModelList.Strings[i]);
144
end;
145

146
end.
147

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.