FmMaterialEditor.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // The graphics rendering engine GLScene http://glscene.org
  3. //
  4. unit FmMaterialEditor;
  5. (* Editor window for a material (with preview) *)
  6. interface
  7. {$I GLScene.inc}
  8. uses
  9. Winapi.Windows,
  10. System.Classes,
  11. System.TypInfo,
  12. VCL.Forms,
  13. VCL.ComCtrls,
  14. VCL.StdCtrls,
  15. VCL.Controls,
  16. VCL.Buttons,
  17. GLS.SceneViewer,
  18. GLS.State,
  19. GLS.Material,
  20. GLS.Texture,
  21. FRMaterialPreview,
  22. FRColorEditor,
  23. FRFaceEditor,
  24. FRTextureEdit;
  25. type
  26. TGLMaterialEditorForm = class(TForm)
  27. PageControl1: TPageControl;
  28. TSFront: TTabSheet;
  29. TSBack: TTabSheet;
  30. TSTexture: TTabSheet;
  31. FEFront: TRFaceEditor;
  32. FEBack: TRFaceEditor;
  33. GroupBox1: TGroupBox;
  34. MPPreview: TRMaterialPreview;
  35. BBOk: TBitBtn;
  36. BBCancel: TBitBtn;
  37. RTextureEdit: TRTextureEdit;
  38. CBBlending: TComboBox;
  39. Label1: TLabel;
  40. Label2: TLabel;
  41. CBPolygonMode: TComboBox;
  42. procedure OnMaterialChanged(Sender: TObject);
  43. public
  44. constructor Create(AOwner: TComponent); override;
  45. function Execute(AMaterial: TGLMaterial): Boolean;
  46. end;
  47. function GLMaterialEditorForm: TGLMaterialEditorForm;
  48. procedure ReleaseMaterialEditorForm;
  49. //----------------------------------------------
  50. implementation
  51. //----------------------------------------------
  52. {$R *.dfm}
  53. var
  54. vGLMaterialEditorForm: TGLMaterialEditorForm;
  55. function GLMaterialEditorForm: TGLMaterialEditorForm;
  56. begin
  57. if not Assigned(vGLMaterialEditorForm) then
  58. vGLMaterialEditorForm := TGLMaterialEditorForm.Create(nil);
  59. Result := vGLMaterialEditorForm;
  60. end;
  61. procedure ReleaseMaterialEditorForm;
  62. begin
  63. if Assigned(vGLMaterialEditorForm) then
  64. begin
  65. vGLMaterialEditorForm.Free;
  66. vGLMaterialEditorForm := nil;
  67. end;
  68. end;
  69. constructor TGLMaterialEditorForm.Create(AOwner: TComponent);
  70. var
  71. I: Integer;
  72. begin
  73. inherited;
  74. for i := 0 to Integer(High(TGLBlendingMode)) do
  75. CBBlending.Items.Add(GetEnumName(TypeInfo(TGLBlendingMode), i));
  76. for i := 0 to Integer(High(TGLPolygonMode)) do
  77. CBPolygonMode.Items.Add(GetEnumName(TypeInfo(TGLPolygonMode), i));
  78. FEFront.OnChange := OnMaterialChanged;
  79. FEBack.OnChange := OnMaterialChanged;
  80. RTextureEdit.OnChange := OnMaterialChanged;
  81. end;
  82. function TGLMaterialEditorForm.Execute(AMaterial: TGLMaterial): Boolean;
  83. begin
  84. with AMaterial.GetActualPrimaryMaterial do
  85. begin
  86. FEFront.FaceProperties := FrontProperties;
  87. FEBack.FaceProperties := BackProperties;
  88. RTextureEdit.Texture := Texture;
  89. CBPolygonMode.ItemIndex:=Integer(PolygonMode);
  90. CBBlending.ItemIndex := Integer(BlendingMode);
  91. end;
  92. MPPreview.Material := AMaterial;
  93. Result := (ShowModal = mrOk);
  94. if Result then
  95. with AMaterial.GetActualPrimaryMaterial do
  96. begin
  97. FrontProperties := FEFront.FaceProperties;
  98. BackProperties := FEBack.FaceProperties;
  99. Texture := RTextureEdit.Texture;
  100. BlendingMode := TGLBlendingMode(CBBlending.ItemIndex);
  101. PolygonMode := TGLPolygonMode(CBPolygonMode.ItemIndex);
  102. end;
  103. end;
  104. procedure TGLMaterialEditorForm.OnMaterialChanged(Sender: TObject);
  105. begin
  106. with MPPreview.Material do
  107. begin
  108. FrontProperties := FEFront.FaceProperties;
  109. BackProperties := FEBack.FaceProperties;
  110. Texture := RTextureEdit.Texture;
  111. BlendingMode := TGLBlendingMode(CBBlending.ItemIndex);
  112. PolygonMode := TGLPolygonMode(CBPolygonMode.ItemIndex);
  113. end;
  114. MPPreview.GLSceneViewer.Invalidate;
  115. end;
  116. // ------------------------------------------------------------------
  117. initialization
  118. // ------------------------------------------------------------------
  119. finalization
  120. ReleaseMaterialEditorForm;
  121. end.