GLS.MaterialScript.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. //
  2. // The multimedia graphics platform GLScene https://github.com/glscene
  3. //
  4. unit GLS.MaterialScript;
  5. (* Material Script Batch loader for TGLMaterialLibrary for runtime. *)
  6. interface
  7. {$I GLScene.inc}
  8. uses
  9. System.SysUtils,
  10. System.Classes,
  11. VCL.StdCtrls,
  12. GLS.VectorTypes,
  13. GLS.Texture,
  14. GLS.TextureFormat,
  15. GLS.Graphics,
  16. GLS.Utils,
  17. GLS.Color,
  18. GLS.Coordinates,
  19. GLS.Material,
  20. GLS.State;
  21. type
  22. TGLShaderItem = class(TCollectionItem)
  23. private
  24. FShader: TGLShader;
  25. FName: string;
  26. procedure SetShader(const Value: TGLShader);
  27. procedure SetName(const Value: string);
  28. protected
  29. function GetDisplayName: string; override;
  30. public
  31. constructor Create(Collection: TCollection); override;
  32. destructor Destroy; override;
  33. procedure Assign(Source: TPersistent); override;
  34. published
  35. property Shader: TGLShader read FShader write SetShader;
  36. property Name: string read FName write SetName;
  37. end;
  38. TGLShaderItems = class(TOwnedCollection)
  39. private
  40. procedure SetItems(Index: Integer; const Val: TGLShaderItem);
  41. function GetItems(Index: Integer): TGLShaderItem;
  42. public
  43. constructor Create(AOwner: TPersistent);
  44. property Items[Index: Integer]: TGLShaderItem read GetItems
  45. write SetItems; default;
  46. end;
  47. TGLMaterialLibraryItem = class(TCollectionItem)
  48. private
  49. FMaterialLibrary: TGLMaterialLibrary;
  50. FName: string;
  51. procedure SetMaterialLibrary(const Value: TGLMaterialLibrary);
  52. procedure SetName(const Value: string);
  53. protected
  54. function GetDisplayName: string; override;
  55. public
  56. constructor Create(Collection: TCollection); override;
  57. destructor Destroy; override;
  58. procedure Assign(Source: TPersistent); override;
  59. published
  60. property MaterialLibrary: TGLMaterialLibrary read FMaterialLibrary
  61. write SetMaterialLibrary;
  62. property Name: string read FName write SetName;
  63. end;
  64. TGLMaterialLibraryItems = class(TOwnedCollection)
  65. private
  66. procedure SetItems(Index: Integer; const Val: TGLMaterialLibraryItem);
  67. function GetItems(Index: Integer): TGLMaterialLibraryItem;
  68. public
  69. constructor Create(AOwner: TPersistent);
  70. property Items[Index: Integer]: TGLMaterialLibraryItem read GetItems
  71. write SetItems; default;
  72. end;
  73. TGLMaterialScripter = class(TComponent)
  74. private
  75. FShaderItems: TGLShaderItems;
  76. FMaterialLibraryItems: TGLMaterialLibraryItems;
  77. FAppend: Boolean;
  78. FOverwrite: Boolean;
  79. FScript: TStrings;
  80. FMemo: TMemo;
  81. FMaterialLibrary: TGLMaterialLibrary;
  82. Count: Longint;
  83. Infini: Longint;
  84. Done: Boolean;
  85. NewMat: TGLLibMaterial;
  86. TmpCoords: TGLCoordinates;
  87. TmpColor: TGLColor;
  88. TmpCoords4: TGLCoordinates4;
  89. TmpStr: string;
  90. procedure SeTGLShaderItems(const Value: TGLShaderItems);
  91. procedure SeTGLMaterialLibraryItems(const Value: TGLMaterialLibraryItems);
  92. procedure SetAppend(const Value: Boolean);
  93. procedure SetOverwrite(const Value: Boolean);
  94. procedure SetScript(const Value: TStrings);
  95. procedure SetMaterialLibrary(const Value: TGLMaterialLibrary);
  96. procedure SetMemo(const Value: TMemo);
  97. // error checking
  98. procedure CheckError;
  99. function ClassExists(arguement: string): Boolean;
  100. function CheckRepeatDone: Boolean;
  101. // extraction functions
  102. function ExtractValue: string;
  103. procedure ExtractCoords3;
  104. procedure ExtractCoords4;
  105. procedure ExtractColors;
  106. function DeleteSpaces(Value: string): string;
  107. function SubstrExists(substr: string): Boolean;
  108. function ValueExists(Value: string): Boolean;
  109. // these are our viable scripts
  110. procedure ZMaterial;
  111. // internally called scripts for value extraction
  112. procedure XMaterial;
  113. procedure XName;
  114. procedure XShader;
  115. procedure XTexture2Name;
  116. procedure XTextureOffset;
  117. procedure XTextureScale;
  118. procedure XTexture;
  119. procedure XCompression;
  120. procedure XEnvColor;
  121. procedure XFilteringQuality;
  122. procedure XImageAlpha;
  123. procedure XImageBrightness;
  124. procedure XImageClass;
  125. procedure XImageGamma;
  126. procedure XMagFilter;
  127. procedure XMappingMode;
  128. procedure XMappingSCoordinates;
  129. procedure XMappingTCoordinates;
  130. procedure XMinFilter;
  131. procedure XNormalMapScale;
  132. procedure XTextureFormat;
  133. procedure XTextureMode;
  134. procedure XTextureWrap;
  135. procedure XBlendingMode;
  136. procedure XPolygonMode;
  137. procedure XFacingCulling;
  138. procedure XLibMaterialName;
  139. procedure XMaterialOptions;
  140. procedure XMaterialLibrary;
  141. procedure XBackProperties;
  142. procedure XBackAmbient;
  143. procedure XBackDiffuse;
  144. procedure XBackEmission;
  145. procedure XBackShininess;
  146. procedure XBackSpecular;
  147. procedure XFrontProperties;
  148. procedure XFrontAmbient;
  149. procedure XFrontDiffuse;
  150. procedure XFrontEmission;
  151. procedure XFrontShininess;
  152. procedure XFrontSpecular;
  153. procedure XPersistantImage;
  154. procedure XBlankImage;
  155. procedure XPictureFileName;
  156. procedure XPicturePX;
  157. procedure XPictureNX;
  158. procedure XPicturePY;
  159. procedure XPictureNY;
  160. procedure XPicturePZ;
  161. procedure XPictureNZ;
  162. protected
  163. procedure Notification(AComponent: TComponent;
  164. Operation: TOperation); override;
  165. public
  166. property DebugMemo: TMemo read FMemo write SetMemo;
  167. constructor Create(AOwner: TComponent); override;
  168. destructor Destroy; override;
  169. procedure CompileScript;
  170. published
  171. property Script: TStrings read FScript write SetScript;
  172. property MaterialLibrary: TGLMaterialLibrary read FMaterialLibrary
  173. write SetMaterialLibrary;
  174. property Shaders: TGLShaderItems read FShaderItems write SeTGLShaderItems;
  175. property MaterialLibraries: TGLMaterialLibraryItems
  176. read FMaterialLibraryItems write SeTGLMaterialLibraryItems;
  177. property AppendToMaterialLibrary: Boolean read FAppend write SetAppend;
  178. property OverwriteToMaterialLibrary: Boolean read FOverwrite
  179. write SetOverwrite;
  180. end;
  181. // ----------------------------------------------------------------------
  182. implementation
  183. // ----------------------------------------------------------------------
  184. procedure TGLShaderItem.SetShader(const Value: TGLShader);
  185. begin
  186. if Assigned(Value) then
  187. begin
  188. FShader := Value;
  189. FName := FShader.Name;
  190. end;
  191. end;
  192. procedure TGLShaderItem.Assign(Source: TPersistent);
  193. begin
  194. if Source is TGLShaderItem then
  195. begin
  196. FShader := TGLShaderItem(Source).FShader;
  197. end;
  198. inherited Destroy;
  199. end;
  200. constructor TGLShaderItem.Create(Collection: TCollection);
  201. begin
  202. inherited Create(Collection);
  203. FName := 'Shader';
  204. end;
  205. destructor TGLShaderItem.Destroy;
  206. begin
  207. inherited Destroy;
  208. end;
  209. function TGLShaderItem.GetDisplayName: String;
  210. begin
  211. if FName = '' then
  212. Result := 'Shader'
  213. else
  214. Result := FName;
  215. end;
  216. // ------------------------
  217. // TGLShaderItems
  218. // ------------------------
  219. constructor TGLShaderItems.Create(AOwner: TPersistent);
  220. begin
  221. inherited Create(AOwner, TGLShaderItem);
  222. end;
  223. function TGLShaderItems.GetItems(Index: Integer): TGLShaderItem;
  224. begin
  225. Result := TGLShaderItem(inherited Items[index]);
  226. end;
  227. procedure TGLShaderItems.SetItems(Index: Integer; const Val: TGLShaderItem);
  228. begin
  229. inherited Items[index] := Val;
  230. end;
  231. procedure TGLMaterialScripter.SeTGLShaderItems(const Value: TGLShaderItems);
  232. begin
  233. FShaderItems.Assign(Value);
  234. end;
  235. procedure TGLShaderItem.SetName(const Value: String);
  236. begin
  237. FName := Value;
  238. end;
  239. procedure TGLMaterialScripter.CompileScript;
  240. begin
  241. Done := False;
  242. NewMat := nil;
  243. Count := 0;
  244. Infini := 0;
  245. TmpCoords := nil;
  246. TmpCoords4 := nil;
  247. TmpColor := nil;
  248. TmpStr := '';
  249. repeat
  250. inc(Count);
  251. if pos('{', FScript.Strings[Count]) > 0 then
  252. begin
  253. if SubstrExists('material') then
  254. ZMaterial;
  255. end;
  256. CheckError;
  257. until CheckRepeatDone;
  258. end;
  259. procedure TGLMaterialScripter.SetMaterialLibrary(const Value
  260. : TGLMaterialLibrary);
  261. begin
  262. if FMaterialLibrary <> nil then
  263. FMaterialLibrary.RemoveFreeNotification(Self);
  264. FMaterialLibrary := Value;
  265. if FMaterialLibrary <> nil then
  266. FMaterialLibrary.FreeNotification(Self);
  267. end;
  268. procedure TGLMaterialScripter.SetMemo(const Value: TMemo);
  269. begin
  270. if FMemo <> nil then
  271. FMemo.RemoveFreeNotification(Self);
  272. FMemo := Value;
  273. if FMemo <> nil then
  274. FMemo.FreeNotification(Self);
  275. end;
  276. procedure TGLMaterialScripter.SetScript(const Value: TStrings);
  277. begin
  278. if Assigned(Value) then
  279. FScript.Assign(Value);
  280. end;
  281. procedure TGLMaterialScripter.CheckError;
  282. begin
  283. if Count >= FScript.Count then
  284. Done := True;
  285. if Done then
  286. raise Exception.Create('User Error : No closing "}"');
  287. inc(Infini);
  288. if Infini > 1280000 then
  289. begin
  290. raise Exception.Create('Internal Error : Infinate Loop');
  291. Done := True;
  292. exit;
  293. end;
  294. end;
  295. function TGLMaterialScripter.CheckRepeatDone: Boolean;
  296. begin
  297. CheckRepeatDone := False;
  298. if pos('}', FScript.Strings[Count]) > 0 then
  299. begin
  300. CheckRepeatDone := True;
  301. inc(Count);
  302. end;
  303. if Done then
  304. CheckRepeatDone := True;
  305. end;
  306. function TGLMaterialScripter.ClassExists(arguement: string): Boolean;
  307. var
  308. Temp: string;
  309. i: word;
  310. begin
  311. ClassExists := False;
  312. if (pos(UpperCase(arguement), UpperCase(FScript.Strings[Count])) > 0) and
  313. // check if there is an arguement
  314. (pos('=', FScript.Strings[Count]) > pos(UpperCase(arguement),
  315. UpperCase(FScript.Strings[Count]))) and // check if it is before '='
  316. (pos('=', FScript.Strings[Count]) > 0) then // check if there even is a '='
  317. begin
  318. Temp := FScript.Strings[Count];
  319. for i := 0 to length(Temp) do
  320. if pos(' ', Temp) = 1 then
  321. delete(Temp, 1, 1);
  322. if pos(UpperCase(arguement), UpperCase(Temp)) = 1 then
  323. if (Temp[length(arguement) + 1] = ' ') or
  324. (Temp[length(arguement) + 1] = '=') then
  325. begin
  326. ClassExists := True;
  327. if Assigned(FMemo) then
  328. FMemo.Lines.Add('Stage is at : ' + arguement);
  329. end;
  330. end;
  331. end;
  332. function TGLMaterialScripter.SubstrExists(substr: string): Boolean;
  333. begin
  334. if pos(UpperCase(substr), UpperCase(FScript.Strings[Count])) > 0 then
  335. Result := True
  336. else
  337. Result := False;
  338. end;
  339. constructor TGLMaterialScripter.Create(AOwner: TComponent);
  340. begin
  341. inherited Create(AOwner);
  342. FScript := TStringList.Create;
  343. FShaderItems := TGLShaderItems.Create(Self);
  344. FMaterialLibraryItems := TGLMaterialLibraryItems.Create(Self);
  345. FAppend := True;
  346. FOverwrite := False;
  347. end;
  348. function TGLMaterialScripter.DeleteSpaces(Value: string): string;
  349. var
  350. i: byte;
  351. begin
  352. Result := Value;
  353. for i := 0 to length(Result) do
  354. if pos(' ', Result) > 0 then
  355. delete(Result, pos(' ', Result), 1);
  356. end;
  357. destructor TGLMaterialScripter.Destroy;
  358. begin
  359. FShaderItems.Free;
  360. FMaterialLibraryItems.Free;
  361. FScript.Free;
  362. inherited Destroy;
  363. end;
  364. procedure TGLMaterialScripter.ExtractColors;
  365. var
  366. Val: string;
  367. begin
  368. Val := ExtractValue;
  369. if pos('(', Val) > 0 then
  370. begin
  371. TmpColor.Alpha := GLStrToFloatDef(copy(Val, pos('(', Val) + 1,
  372. pos(';', Val) - 2));
  373. delete(Val, 1, pos(';', Val));
  374. TmpColor.Red := GLStrToFloatDef(copy(Val, 1, pos(';', Val) - 1));
  375. delete(Val, 1, pos(';', Val));
  376. TmpColor.Green := GLStrToFloatDef(copy(Val, 1, pos(';', Val) - 1));
  377. delete(Val, 1, pos(';', Val));
  378. TmpColor.Blue := GLStrToFloatDef(copy(Val, 1, pos(')', Val) - 1));
  379. end;
  380. end;
  381. procedure TGLMaterialScripter.ExtractCoords3;
  382. var
  383. Val: string;
  384. begin
  385. Val := ExtractValue;
  386. if pos('(', Val) > 0 then
  387. begin
  388. TmpCoords.X := GLStrToFloatDef(copy(Val, pos('(', Val) + 1,
  389. pos(';', Val) - 2));
  390. delete(Val, 1, pos(';', Val));
  391. TmpCoords.Y := GLStrToFloatDef(copy(Val, 1, pos(';', Val) - 1));
  392. delete(Val, 1, pos(';', Val));
  393. TmpCoords.Z := GLStrToFloatDef(copy(Val, 1, pos(')', Val) - 1));
  394. end;
  395. end;
  396. procedure TGLMaterialScripter.ExtractCoords4;
  397. var
  398. Val: string;
  399. begin
  400. Val := ExtractValue;
  401. if pos('(', Val) > 0 then
  402. begin
  403. TmpCoords4.W := GLStrToFloatDef(copy(Val, pos('(', Val) + 1,
  404. pos(';', Val) - 2));
  405. delete(Val, 1, pos(';', Val));
  406. TmpCoords4.X := GLStrToFloatDef(copy(Val, 1, pos(';', Val) - 1));
  407. delete(Val, 1, pos(';', Val));
  408. TmpCoords4.Y := GLStrToFloatDef(copy(Val, 1, pos(';', Val) - 1));
  409. delete(Val, 1, pos(';', Val));
  410. TmpCoords4.Z := GLStrToFloatDef(copy(Val, 1, pos(')', Val) - 1));
  411. end;
  412. end;
  413. function TGLMaterialScripter.ExtractValue: string;
  414. begin
  415. ExtractValue := copy(FScript.Strings[Count], pos('=', FScript.Strings[Count])
  416. + 1, length(FScript.Strings[Count]) - pos('=', FScript.Strings[Count]));
  417. end;
  418. procedure TGLMaterialScripter.XPersistantImage;
  419. begin
  420. if ClassExists('file') then
  421. begin
  422. if (ExtractValue <> '') and (fileexists(ExtractValue)) then
  423. begin
  424. with NewMat.Material.Texture.Image as TGLPersistentImage do
  425. LoadFromFile(ExtractValue);
  426. NewMat.Material.Texture.Disabled := False;
  427. if Assigned(FMemo) then
  428. FMemo.Lines.Add('File loaded : ' + ExtractValue);
  429. end;
  430. end;
  431. end;
  432. procedure TGLMaterialScripter.XBlankImage;
  433. begin
  434. if ClassExists('file') then
  435. begin
  436. if (ExtractValue <> '') and (fileexists(ExtractValue)) then
  437. begin
  438. with NewMat.Material.Texture.Image as TGLBlankImage do
  439. // heres the difference
  440. LoadFromFile(ExtractValue);
  441. NewMat.Material.Texture.Disabled := False;
  442. if Assigned(FMemo) then
  443. FMemo.Lines.Add('File loaded : ' + ExtractValue);
  444. end;
  445. end;
  446. end;
  447. procedure TGLMaterialScripter.XPictureFileName;
  448. begin
  449. if ClassExists('picturefilename') then
  450. with NewMat.Material.Texture.Image as TGLPicFileImage do
  451. if fileexists(ExtractValue) then
  452. begin
  453. picturefilename := ExtractValue;
  454. NewMat.Material.Texture.Disabled := False;
  455. end;
  456. end;
  457. procedure TGLMaterialScripter.XPictureNX;
  458. begin
  459. if ClassExists('picturenx') then
  460. if fileexists(ExtractValue) then
  461. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  462. Picture[cmtNX].LoadFromFile(ExtractValue);
  463. end;
  464. procedure TGLMaterialScripter.XPictureNY;
  465. begin
  466. if ClassExists('pictureny') then
  467. if fileexists(ExtractValue) then
  468. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  469. Picture[cmtNY].LoadFromFile(ExtractValue);
  470. end;
  471. procedure TGLMaterialScripter.XPictureNZ;
  472. begin
  473. if ClassExists('picturenz') then
  474. if fileexists(ExtractValue) then
  475. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  476. Picture[cmtNZ].LoadFromFile(ExtractValue);
  477. end;
  478. procedure TGLMaterialScripter.XPicturePX;
  479. begin
  480. if ClassExists('picturepx') then
  481. if fileexists(ExtractValue) then
  482. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  483. Picture[cmtPX].LoadFromFile(ExtractValue);
  484. end;
  485. procedure TGLMaterialScripter.XPicturePY;
  486. begin
  487. if ClassExists('picturepy') then
  488. if fileexists(ExtractValue) then
  489. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  490. Picture[cmtPY].LoadFromFile(ExtractValue);
  491. end;
  492. procedure TGLMaterialScripter.XPicturePZ;
  493. begin
  494. if ClassExists('picturepz') then
  495. if fileexists(ExtractValue) then
  496. with NewMat.Material.Texture.Image as TGLCubeMapImage do
  497. Picture[cmtPZ].LoadFromFile(ExtractValue);
  498. end;
  499. function TGLMaterialScripter.ValueExists(Value: string): Boolean;
  500. begin
  501. if UpperCase(TmpStr) = UpperCase(Value) then
  502. Result := True
  503. else
  504. Result := False;
  505. end;
  506. procedure TGLMaterialScripter.XMaterialLibrary;
  507. var
  508. i: word;
  509. begin
  510. if ClassExists('materiallibrary') then
  511. if MaterialLibraries.Count > 0 then
  512. for i := 0 to MaterialLibraries.Count - 1 do
  513. if Assigned(MaterialLibraries.Items[i].MaterialLibrary) then
  514. if UpperCase(MaterialLibraries.Items[i].MaterialLibrary.Name)
  515. = UpperCase(ExtractValue) then
  516. NewMat.Material.MaterialLibrary := MaterialLibraries.Items[i]
  517. .MaterialLibrary;
  518. end;
  519. procedure TGLMaterialScripter.XShader;
  520. var
  521. i: word;
  522. begin
  523. if ClassExists('shader') then
  524. if Shaders.Count > 0 then
  525. for i := 0 to Shaders.Count - 1 do
  526. if Assigned(Shaders.Items[i].Shader) then
  527. if UpperCase(Shaders.Items[i].Shader.Name) = UpperCase(ExtractValue)
  528. then
  529. NewMat.Shader := Shaders.Items[i].Shader;
  530. end;
  531. procedure TGLMaterialScripter.ZMaterial;
  532. var
  533. i: byte;
  534. exists: Boolean;
  535. begin
  536. if Assigned(FMaterialLibrary) then
  537. begin
  538. NewMat := FMaterialLibrary.Materials.Add;
  539. repeat
  540. inc(Count);
  541. XMaterial;
  542. if pos('{', FScript.Strings[Count]) > 0 then
  543. for i := 0 to 2 do
  544. // need repair : something went wrong, and now we have to check 3 times over :/
  545. begin
  546. XTexture;
  547. XBackProperties;
  548. XFrontProperties;
  549. end;
  550. CheckError;
  551. until CheckRepeatDone;
  552. // now we use append and overwrite settings to find out what is what
  553. TmpStr := NewMat.Name;
  554. delete(TmpStr, 1, 3); // removes the "TAG" not to confuse the system
  555. exists := False;
  556. if FMaterialLibrary.Materials.Count > 0 then
  557. for i := 0 to FMaterialLibrary.Materials.Count - 1 do
  558. if TmpStr = FMaterialLibrary.Materials.Items[i].Name then
  559. exists := True;
  560. if exists then // does exist
  561. begin
  562. if FOverwrite then
  563. begin
  564. FMaterialLibrary.Materials.delete
  565. (FMaterialLibrary.LibMaterialByName(TmpStr).Index);
  566. NewMat.Name := TmpStr;
  567. end
  568. else if FAppend then
  569. begin
  570. NewMat.Free;
  571. end;
  572. end
  573. else // doesn't exist
  574. begin
  575. NewMat.Name := TmpStr;
  576. if not FAppend then
  577. NewMat.Free;
  578. end;
  579. end;
  580. end;
  581. /// ////////////////////////
  582. // extraction procedures //
  583. /// ////////////////////////
  584. procedure TGLMaterialScripter.XBackAmbient;
  585. begin
  586. if ClassExists('ambient') then
  587. begin
  588. TmpColor := NewMat.Material.BackProperties.Ambient;
  589. ExtractColors;
  590. NewMat.Material.BackProperties.Ambient := TmpColor;
  591. end;
  592. end;
  593. procedure TGLMaterialScripter.XBackDiffuse;
  594. begin
  595. if ClassExists('diffuse') then
  596. begin
  597. TmpColor := NewMat.Material.BackProperties.Diffuse;
  598. ExtractColors;
  599. NewMat.Material.BackProperties.Diffuse := TmpColor;
  600. end;
  601. end;
  602. procedure TGLMaterialScripter.XBackEmission;
  603. begin
  604. if ClassExists('emission') then
  605. begin
  606. TmpColor := NewMat.Material.BackProperties.Emission;
  607. ExtractColors;
  608. NewMat.Material.BackProperties.Emission := TmpColor;
  609. end;
  610. end;
  611. procedure TGLMaterialScripter.XBackShininess;
  612. begin
  613. if ClassExists('shininess') then
  614. if ExtractValue <> '' then
  615. NewMat.Material.BackProperties.Shininess := strtoint(ExtractValue);
  616. end;
  617. procedure TGLMaterialScripter.XBackSpecular;
  618. begin
  619. if ClassExists('specular') then
  620. begin
  621. TmpColor := NewMat.Material.BackProperties.Specular;
  622. ExtractColors;
  623. NewMat.Material.BackProperties.Specular := TmpColor;
  624. end;
  625. end;
  626. procedure TGLMaterialScripter.XBlendingMode;
  627. begin
  628. if ClassExists('blendingmode') then
  629. begin
  630. TmpStr := ExtractValue;
  631. if ValueExists('bmOpaque') then
  632. NewMat.Material.BlendingMode := bmOpaque;
  633. if ValueExists('bmTransparency') then
  634. NewMat.Material.BlendingMode := bmTransparency;
  635. if ValueExists('bmAdditive') then
  636. NewMat.Material.BlendingMode := bmAdditive;
  637. if ValueExists('bmAlphaTest100') then
  638. NewMat.Material.BlendingMode := bmAlphaTest100;
  639. if ValueExists('bmAlphaTest50') then
  640. NewMat.Material.BlendingMode := bmAlphaTest50;
  641. end;
  642. end;
  643. procedure TGLMaterialScripter.XPolygonMode;
  644. begin
  645. if ClassExists('polygonmode') then
  646. begin
  647. TmpStr := ExtractValue;
  648. if ValueExists('pmFill') then
  649. NewMat.Material.PolygonMode := pmFill;
  650. if ValueExists('pmLines') then
  651. NewMat.Material.PolygonMode := pmLines;
  652. if ValueExists('pmPoints') then
  653. NewMat.Material.PolygonMode := pmPoints;
  654. end;
  655. end;
  656. procedure TGLMaterialScripter.XCompression;
  657. begin
  658. if ClassExists('compression') then
  659. begin
  660. TmpStr := ExtractValue;
  661. if ValueExists('tcDefault') then
  662. NewMat.Material.Texture.Compression := tcDefault;
  663. if ValueExists('tcHighQuality') then
  664. NewMat.Material.Texture.Compression := tcHighQuality;
  665. if ValueExists('tcHighSpeed') then
  666. NewMat.Material.Texture.Compression := tcHighSpeed;
  667. if ValueExists('tcNone') then
  668. NewMat.Material.Texture.Compression := tcNone;
  669. if ValueExists('tcStandard') then
  670. NewMat.Material.Texture.Compression := tcStandard;
  671. end;
  672. end;
  673. procedure TGLMaterialScripter.XEnvColor;
  674. begin
  675. if ClassExists('envcolor') then
  676. begin
  677. TmpColor := NewMat.Material.Texture.EnvColor;
  678. ExtractColors;
  679. NewMat.Material.Texture.EnvColor := TmpColor;
  680. end;
  681. end;
  682. procedure TGLMaterialScripter.XFacingCulling;
  683. begin
  684. if ClassExists('faceculling') then
  685. begin
  686. TmpStr := ExtractValue;
  687. if ValueExists('fcBufferDefault') then
  688. NewMat.Material.FaceCulling := fcBufferDefault;
  689. if ValueExists('fcCull') then
  690. NewMat.Material.FaceCulling := fcCull;
  691. if ValueExists('fcNoCull') then
  692. NewMat.Material.FaceCulling := fcNoCull;
  693. end;
  694. end;
  695. procedure TGLMaterialScripter.XFilteringQuality;
  696. begin
  697. if ClassExists('filteringquality') then
  698. begin
  699. TmpStr := ExtractValue;
  700. if ValueExists('tfIsotropic') then
  701. NewMat.Material.Texture.FilteringQuality := tfIsotropic;
  702. if ValueExists('tfAnisotropic') then
  703. NewMat.Material.Texture.FilteringQuality := tfAnisotropic;
  704. end;
  705. end;
  706. procedure TGLMaterialScripter.XFrontAmbient;
  707. begin
  708. if ClassExists('ambient') then
  709. begin
  710. TmpColor := NewMat.Material.frontProperties.Ambient;
  711. ExtractColors;
  712. NewMat.Material.frontProperties.Ambient := TmpColor;
  713. end;
  714. end;
  715. procedure TGLMaterialScripter.XFrontDiffuse;
  716. begin
  717. if ClassExists('diffuse') then
  718. begin
  719. TmpColor := NewMat.Material.frontProperties.Diffuse;
  720. ExtractColors;
  721. NewMat.Material.frontProperties.Diffuse := TmpColor;
  722. end;
  723. end;
  724. procedure TGLMaterialScripter.XFrontEmission;
  725. begin
  726. if ClassExists('emission') then
  727. begin
  728. TmpColor := NewMat.Material.frontProperties.Emission;
  729. ExtractColors;
  730. NewMat.Material.frontProperties.Emission := TmpColor;
  731. end;
  732. end;
  733. procedure TGLMaterialScripter.XFrontShininess;
  734. begin
  735. if ClassExists('shininess') then
  736. if ExtractValue <> '' then
  737. NewMat.Material.frontProperties.Shininess := strtoint(ExtractValue);
  738. end;
  739. procedure TGLMaterialScripter.XFrontSpecular;
  740. begin
  741. if ClassExists('specular') then
  742. begin
  743. TmpColor := NewMat.Material.frontProperties.Specular;
  744. ExtractColors;
  745. NewMat.Material.frontProperties.Specular := TmpColor;
  746. end;
  747. end;
  748. procedure TGLMaterialScripter.XImageAlpha;
  749. begin
  750. if ClassExists('imagealpha') then
  751. begin
  752. TmpStr := ExtractValue;
  753. if ValueExists('tiaDefault') then
  754. NewMat.Material.Texture.ImageAlpha := tiaDefault;
  755. if ValueExists('tiaInverseLuminance') then
  756. NewMat.Material.Texture.ImageAlpha := tiaInverseLuminance;
  757. if ValueExists('tiaInverseLuminanceSqrt') then
  758. NewMat.Material.Texture.ImageAlpha := tiaInverseLuminanceSqrt;
  759. if ValueExists('tiaLuminance') then
  760. NewMat.Material.Texture.ImageAlpha := tiaLuminance;
  761. if ValueExists('tiaLuminanceSqrt') then
  762. NewMat.Material.Texture.ImageAlpha := tiaLuminanceSqrt;
  763. if ValueExists('tiaOpaque') then
  764. NewMat.Material.Texture.ImageAlpha := tiaOpaque;
  765. if ValueExists('tiaSuperBlackTransparent') then
  766. NewMat.Material.Texture.ImageAlpha := tiaSuperBlackTransparent;
  767. if ValueExists('tiaTopLeftPointColorTransparent') then
  768. NewMat.Material.Texture.ImageAlpha := tiaTopLeftPointColorTransparent;
  769. if ValueExists('tiaAlphaFromIntensity') then
  770. NewMat.Material.Texture.ImageAlpha := tiaAlphaFromIntensity;
  771. end;
  772. end;
  773. procedure TGLMaterialScripter.XImageBrightness;
  774. begin
  775. if ClassExists('imagebrightness') then
  776. if ExtractValue <> '' then
  777. NewMat.Material.Texture.ImageBrightness := GLStrToFloatDef(ExtractValue);
  778. end;
  779. procedure TGLMaterialScripter.XImageGamma;
  780. begin
  781. if ClassExists('imagegamma') then
  782. if ExtractValue <> '' then
  783. NewMat.Material.Texture.ImageGamma := GLStrToFloatDef(ExtractValue);
  784. end;
  785. procedure TGLMaterialScripter.XLibMaterialName;
  786. begin
  787. if ClassExists('libmaterialname') then
  788. NewMat.Material.LibMaterialName := ExtractValue;
  789. end;
  790. procedure TGLMaterialScripter.XMagFilter;
  791. begin
  792. if ClassExists('magfilter') then
  793. begin
  794. TmpStr := ExtractValue;
  795. if ValueExists('maLinear') then
  796. NewMat.Material.Texture.MagFilter := maLinear;
  797. if ValueExists('maNearest') then
  798. NewMat.Material.Texture.MagFilter := maNearest;
  799. end;
  800. end;
  801. procedure TGLMaterialScripter.XMappingMode;
  802. begin
  803. if ClassExists('mappingmode') then
  804. begin
  805. TmpStr := ExtractValue;
  806. if ValueExists('tmmUser') then
  807. NewMat.Material.Texture.MappingMode := tmmUser;
  808. if ValueExists('tmmCubeMapCamera') then
  809. NewMat.Material.Texture.MappingMode := tmmCubeMapCamera;
  810. if ValueExists('tmmCubeMapLight0') then
  811. NewMat.Material.Texture.MappingMode := tmmCubeMapLight0;
  812. if ValueExists('tmmCubeMapNormal') then
  813. NewMat.Material.Texture.MappingMode := tmmCubeMapNormal;
  814. if ValueExists('tmmCubeMapReflection') then
  815. NewMat.Material.Texture.MappingMode := tmmCubeMapReflection;
  816. if ValueExists('tmmEyeLinear') then
  817. NewMat.Material.Texture.MappingMode := tmmEyeLinear;
  818. if ValueExists('tmmObjectLinear') then
  819. NewMat.Material.Texture.MappingMode := tmmObjectLinear;
  820. if ValueExists('tmmSphere') then
  821. NewMat.Material.Texture.MappingMode := tmmSphere;
  822. end;
  823. end;
  824. procedure TGLMaterialScripter.XMappingSCoordinates;
  825. begin
  826. if ClassExists('mappingscoordinates') then
  827. begin
  828. TmpCoords4 := NewMat.Material.Texture.MappingSCoordinates;
  829. ExtractCoords4;
  830. NewMat.Material.Texture.MappingSCoordinates := TmpCoords4;
  831. end;
  832. end;
  833. procedure TGLMaterialScripter.XMappingTCoordinates;
  834. begin
  835. if ClassExists('mappingtcoordinates') then
  836. begin
  837. TmpCoords4 := NewMat.Material.Texture.MappingTCoordinates;
  838. ExtractCoords4;
  839. NewMat.Material.Texture.MappingTCoordinates := TmpCoords4;
  840. end;
  841. end;
  842. procedure TGLMaterialScripter.XMaterialOptions;
  843. var
  844. a, b: Boolean;
  845. begin
  846. if ClassExists('materialoptions') then
  847. begin
  848. a := False;
  849. b := False;
  850. TmpStr := ExtractValue;
  851. if UpperCase(copy(TmpStr, pos('[', TmpStr) + 1, pos(',', TmpStr) - 2))
  852. = UpperCase('True') then
  853. a := True
  854. else if UpperCase(copy(TmpStr, pos('[', TmpStr) + 1, pos(',', TmpStr) - 2))
  855. = UpperCase('False') then
  856. a := False;
  857. delete(TmpStr, 1, pos(',', TmpStr));
  858. if UpperCase(copy(TmpStr, 1, pos(']', TmpStr) - 1)) = UpperCase('True') then
  859. b := True
  860. else if UpperCase(copy(TmpStr, 1, pos(']', TmpStr) - 1)) = UpperCase('False')
  861. then
  862. b := False;
  863. if a then
  864. NewMat.Material.MaterialOptions := NewMat.Material.MaterialOptions +
  865. [moIgnoreFog];
  866. if b then
  867. NewMat.Material.MaterialOptions := NewMat.Material.MaterialOptions +
  868. [moNoLighting];
  869. end;
  870. end;
  871. procedure TGLMaterialScripter.XMinFilter;
  872. begin
  873. if ClassExists('minfilter') then
  874. begin
  875. TmpStr := ExtractValue;
  876. if ValueExists('miLinearMipmapLinear') then
  877. NewMat.Material.Texture.MinFilter := miLinearMipmapLinear;
  878. if ValueExists('miLinearMipmapNearest') then
  879. NewMat.Material.Texture.MinFilter := miLinearMipmapNearest;
  880. if ValueExists('miNearest') then
  881. NewMat.Material.Texture.MinFilter := miNearest;
  882. if ValueExists('miNearestMipmapLinear') then
  883. NewMat.Material.Texture.MinFilter := miNearestMipmapLinear;
  884. if ValueExists('miNearestMipmapNearest') then
  885. NewMat.Material.Texture.MinFilter := miNearestMipmapNearest;
  886. if ValueExists('miLinear') then
  887. NewMat.Material.Texture.MinFilter := miLinear;
  888. end;
  889. end;
  890. procedure TGLMaterialScripter.XName;
  891. begin
  892. if ClassExists('name') then
  893. NewMat.Name := 'TAG' + ExtractValue;
  894. // we gonna use for appending and such, quick fix style
  895. end;
  896. procedure TGLMaterialScripter.XNormalMapScale;
  897. begin
  898. if ClassExists('normalmapscale') then
  899. if ExtractValue <> '' then
  900. NewMat.Material.Texture.NormalMapScale := GLStrToFloatDef(ExtractValue);
  901. end;
  902. procedure TGLMaterialScripter.XTexture2Name;
  903. begin
  904. if ClassExists('texture2name') then
  905. NewMat.Texture2Name := ExtractValue;
  906. end;
  907. procedure TGLMaterialScripter.XTextureFormat;
  908. begin
  909. if ClassExists('textureformat') then
  910. begin
  911. TmpStr := ExtractValue;
  912. if ValueExists('tfDefault') then
  913. NewMat.Material.Texture.TextureFormat := tfDefault;
  914. if ValueExists('tfIntensity') then
  915. NewMat.Material.Texture.TextureFormat := tfIntensity;
  916. if ValueExists('tfLuminance') then
  917. NewMat.Material.Texture.TextureFormat := tfLuminance;
  918. if ValueExists('tfLuminanceAlpha') then
  919. NewMat.Material.Texture.TextureFormat := tfLuminanceAlpha;
  920. if ValueExists('tfNormalMap') then
  921. NewMat.Material.Texture.TextureFormat := tfNormalMap;
  922. if ValueExists('tfRGB') then
  923. NewMat.Material.Texture.TextureFormat := tfRGB;
  924. if ValueExists('tfRGB16') then
  925. NewMat.Material.Texture.TextureFormat := tfRGB16;
  926. if ValueExists('tfRGBA') then
  927. NewMat.Material.Texture.TextureFormat := tfRGBA;
  928. if ValueExists('tfRGBA16') then
  929. NewMat.Material.Texture.TextureFormat := tfRGBA16;
  930. if ValueExists('tfAlpha') then
  931. NewMat.Material.Texture.TextureFormat := tfAlpha;
  932. end;
  933. end;
  934. procedure TGLMaterialScripter.XTextureMode;
  935. begin
  936. if ClassExists('texturemode') then
  937. begin
  938. TmpStr := ExtractValue;
  939. if ValueExists('tmDecal') then
  940. NewMat.Material.Texture.TextureMode := tmDecal;
  941. if ValueExists('tmModulate') then
  942. NewMat.Material.Texture.TextureMode := tmModulate;
  943. if ValueExists('tmReplace') then
  944. NewMat.Material.Texture.TextureMode := tmReplace;
  945. if ValueExists('tmBlend') then
  946. NewMat.Material.Texture.TextureMode := tmBlend;
  947. end;
  948. end;
  949. procedure TGLMaterialScripter.XTextureOffset;
  950. begin
  951. if ClassExists('textureoffset') then
  952. // i hate this, delphi doesn't allow var object reference for procs
  953. begin
  954. TmpCoords := NewMat.TextureOffset;
  955. ExtractCoords3;
  956. NewMat.TextureOffset := TmpCoords;
  957. end;
  958. end;
  959. procedure TGLMaterialScripter.XTextureScale;
  960. begin
  961. if ClassExists('texturescale') then
  962. begin
  963. TmpCoords := NewMat.TextureScale;
  964. ExtractCoords3;
  965. NewMat.TextureScale := TmpCoords;
  966. end;
  967. end;
  968. procedure TGLMaterialScripter.XTextureWrap;
  969. begin
  970. if ClassExists('texturewrap') then
  971. begin
  972. TmpStr := ExtractValue;
  973. if ValueExists('twBoth') then
  974. NewMat.Material.Texture.TextureWrap := twBoth;
  975. if ValueExists('twHorizontal') then
  976. NewMat.Material.Texture.TextureWrap := twHorizontal;
  977. if ValueExists('twNone') then
  978. NewMat.Material.Texture.TextureWrap := twNone;
  979. if ValueExists('twVertical') then
  980. NewMat.Material.Texture.TextureWrap := twVertical;
  981. end;
  982. end;
  983. /// ////////////////////////////////////
  984. // sub routines : substr{arguements} //
  985. /// ////////////////////////////////////
  986. procedure TGLMaterialScripter.XTexture;
  987. begin
  988. if SubstrExists('texture') then
  989. begin
  990. if Assigned(FMemo) then
  991. FMemo.Lines.Add('texture');
  992. repeat
  993. inc(Count);
  994. XCompression;
  995. XEnvColor;
  996. XFilteringQuality;
  997. XImageAlpha;
  998. XImageBrightness;
  999. XImageClass;
  1000. XImageGamma;
  1001. XMagFilter;
  1002. XMappingMode;
  1003. XMappingSCoordinates;
  1004. XMappingTCoordinates;
  1005. XMinFilter;
  1006. XNormalMapScale;
  1007. XTextureFormat;
  1008. XTextureMode;
  1009. XTextureWrap;
  1010. CheckError;
  1011. until CheckRepeatDone;
  1012. end;
  1013. end;
  1014. procedure TGLMaterialScripter.XMaterial;
  1015. begin
  1016. XName;
  1017. XShader;
  1018. XTexture2Name;
  1019. XTextureOffset;
  1020. XTextureScale;
  1021. XMaterialOptions;
  1022. XLibMaterialName;
  1023. XBlendingMode;
  1024. XPolygonMode;
  1025. XFacingCulling;
  1026. XMaterialLibrary;
  1027. end;
  1028. procedure TGLMaterialScripter.XFrontProperties;
  1029. begin
  1030. if SubstrExists('frontProperties') then
  1031. begin
  1032. if Assigned(FMemo) then
  1033. FMemo.Lines.Add('frontproperties');
  1034. repeat
  1035. inc(Count);
  1036. XFrontAmbient;
  1037. XFrontDiffuse;
  1038. XFrontEmission;
  1039. XFrontShininess;
  1040. XFrontSpecular;
  1041. CheckError;
  1042. until CheckRepeatDone;
  1043. end;
  1044. end;
  1045. procedure TGLMaterialScripter.XImageClass;
  1046. // reckon this will be most difficult to get right
  1047. begin
  1048. if ClassExists('imageclassname') then
  1049. begin
  1050. TmpStr := ExtractValue;
  1051. TmpStr := DeleteSpaces(TmpStr);
  1052. if ValueExists('persistentimage{') then
  1053. repeat
  1054. inc(Count);
  1055. NewMat.Material.Texture.ImageClassName := TGLPersistentImage.ClassName;
  1056. XPersistantImage;
  1057. CheckError;
  1058. until CheckRepeatDone;
  1059. if ValueExists('blankimage{') then
  1060. repeat
  1061. inc(Count);
  1062. NewMat.Material.Texture.ImageClassName := TGLBlankImage.ClassName;
  1063. XBlankImage;
  1064. CheckError;
  1065. until CheckRepeatDone;
  1066. if ValueExists('picfileimage{') then // picturefilename
  1067. repeat
  1068. inc(Count);
  1069. NewMat.Material.Texture.ImageClassName := TGLPicFileImage.ClassName;
  1070. XPictureFileName;
  1071. CheckError;
  1072. until CheckRepeatDone;
  1073. if ValueExists('cubemapimage{') then // px, nx, py, ny, pz, nz
  1074. repeat
  1075. inc(Count);
  1076. NewMat.Material.Texture.ImageClassName := TGLCubeMapImage.ClassName;
  1077. XPicturePX;
  1078. XPictureNX;
  1079. XPicturePY;
  1080. XPictureNY;
  1081. XPicturePZ;
  1082. XPictureNZ;
  1083. NewMat.Material.Texture.Disabled := False;
  1084. CheckError;
  1085. until CheckRepeatDone;
  1086. // procedural noise not supported by GLS.Texture yet
  1087. end;
  1088. end;
  1089. procedure TGLMaterialScripter.XBackProperties;
  1090. begin
  1091. if SubstrExists('BackProperties') then
  1092. begin
  1093. if Assigned(FMemo) then
  1094. FMemo.Lines.Add('backproperties');
  1095. repeat
  1096. inc(Count);
  1097. XBackAmbient;
  1098. XBackDiffuse;
  1099. XBackEmission;
  1100. XBackShininess;
  1101. XBackSpecular;
  1102. CheckError;
  1103. until CheckRepeatDone;
  1104. end;
  1105. end;
  1106. (* ****************************************
  1107. TGLMaterialLibraryItems
  1108. **************************************** *)
  1109. constructor TGLMaterialLibraryItems.Create(AOwner: TPersistent);
  1110. begin
  1111. inherited Create(AOwner, TGLMaterialLibraryItem);
  1112. end;
  1113. function TGLMaterialLibraryItems.GetItems(Index: Integer)
  1114. : TGLMaterialLibraryItem;
  1115. begin
  1116. Result := TGLMaterialLibraryItem(inherited Items[index]);
  1117. end;
  1118. procedure TGLMaterialLibraryItems.SetItems(Index: Integer;
  1119. const Val: TGLMaterialLibraryItem);
  1120. begin
  1121. inherited Items[index] := Val;
  1122. end;
  1123. (* ****************************************
  1124. TGLMaterialLibraryItem
  1125. **************************************** *)
  1126. procedure TGLMaterialLibraryItem.Assign(Source: TPersistent);
  1127. begin
  1128. if Source is TGLMaterialLibraryItem then
  1129. begin
  1130. FMaterialLibrary := TGLMaterialLibraryItem(Source).FMaterialLibrary;
  1131. end;
  1132. inherited Destroy;
  1133. end;
  1134. constructor TGLMaterialLibraryItem.Create(Collection: TCollection);
  1135. begin
  1136. inherited Create(Collection);
  1137. FName := 'MaterialLibrary';
  1138. end;
  1139. destructor TGLMaterialLibraryItem.Destroy;
  1140. begin
  1141. inherited Destroy;
  1142. end;
  1143. function TGLMaterialLibraryItem.GetDisplayName: String;
  1144. begin
  1145. if FName = '' then
  1146. Result := 'MaterialLibrary'
  1147. else
  1148. Result := FName;
  1149. end;
  1150. procedure TGLMaterialLibraryItem.SetMaterialLibrary
  1151. (const Value: TGLMaterialLibrary);
  1152. begin
  1153. if Assigned(Value) then
  1154. begin
  1155. FMaterialLibrary := Value;
  1156. FName := FMaterialLibrary.Name;
  1157. end;
  1158. end;
  1159. procedure TGLMaterialLibraryItem.SetName(const Value: String);
  1160. begin
  1161. FName := Value;
  1162. end;
  1163. procedure TGLMaterialScripter.SeTGLMaterialLibraryItems
  1164. (const Value: TGLMaterialLibraryItems);
  1165. begin
  1166. FMaterialLibraryItems.Assign(Value);
  1167. end;
  1168. procedure TGLMaterialScripter.SetAppend(const Value: Boolean);
  1169. begin
  1170. FAppend := Value;
  1171. end;
  1172. procedure TGLMaterialScripter.SetOverwrite(const Value: Boolean);
  1173. begin
  1174. FOverwrite := Value;
  1175. end;
  1176. procedure TGLMaterialScripter.Notification(AComponent: TComponent;
  1177. Operation: TOperation);
  1178. begin
  1179. inherited;
  1180. if Operation = opRemove then
  1181. begin
  1182. if AComponent = FMaterialLibrary then
  1183. FMaterialLibrary := nil
  1184. else if AComponent = FMemo then
  1185. FMemo := nil;
  1186. end;
  1187. end;
  1188. end.