guiMaterialPreview.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Original header:
  23. // GuiMaterialPreview Control for Material Editor Written by Travis Vroman of Gaslight Studios
  24. // Updated 2-14-09
  25. // Portions based off Constructor viewport code.
  26. #ifndef _GUIMATERIALPREVIEW_H_
  27. #define _GUIMATERIALPREVIEW_H_
  28. #include "assets/ShapeAsset.h"
  29. #include "gui/3d/guiTSControl.h"
  30. #include "ts/tsShapeInstance.h"
  31. class LightInfo;
  32. class GuiMaterialPreview : public GuiTSCtrl
  33. {
  34. private:
  35. typedef GuiTSCtrl Parent;
  36. protected:
  37. enum MouseState
  38. {
  39. None,
  40. Rotating,
  41. Zooming,
  42. Panning,
  43. MovingLight
  44. };
  45. MouseState mMouseState;
  46. DECLARE_SHAPEASSET_REFACTOR(GuiMaterialPreview, Model)
  47. DECLARE_SHAPEASSET_REFACTOR(GuiMaterialPreview, MountedModel)
  48. TSShapeInstance* mModelInstance;
  49. TSShapeInstance* mMountedModelInstance;
  50. U32 mSkinTag;
  51. // For Camera Panning.
  52. F32 mTransStep; //*** Amount of translation with each mouse move
  53. F32 mTranMult; //*** With a modifier, how much faster to translate
  54. // For light translation.
  55. F32 mLightTransStep;
  56. F32 mLightTranMult;
  57. Point3F mCameraPos;
  58. MatrixF mCameraMatrix;
  59. EulerF mCameraRot;
  60. Point3F mOrbitPos;
  61. Point3F mOrbitRelPos;
  62. Point3F mCameraTransform;
  63. TSThread * runThread;
  64. S32 lastRenderTime;
  65. Point2I mLastMousePoint;
  66. LightInfo* mFakeSun;
  67. void renderSunDirection() const;
  68. public:
  69. bool onWake() override;
  70. void onMouseEnter(const GuiEvent &event) override;
  71. void onMouseLeave(const GuiEvent &event) override;
  72. void onMouseDown(const GuiEvent &event) override;
  73. void onMouseUp(const GuiEvent &event) override;
  74. void onMouseDragged(const GuiEvent &event) override;
  75. void onRightMouseDown(const GuiEvent &event) override;
  76. void onRightMouseUp(const GuiEvent &event) override;
  77. void onRightMouseDragged(const GuiEvent &event) override;
  78. bool onMouseWheelUp(const GuiEvent &event) override;
  79. bool onMouseWheelDown(const GuiEvent &event) override;
  80. void onMiddleMouseUp(const GuiEvent &event) override;
  81. void onMiddleMouseDown(const GuiEvent &event) override;
  82. void onMiddleMouseDragged(const GuiEvent &event) override;
  83. // For Camera Panning.
  84. void setTranslate(S32 modifier, F32 xstep, F32 ystep);
  85. // For Light Translation.
  86. void setLightTranslate(S32 modifier, F32 xstep, F32 ystep);
  87. // For changing the light color.
  88. void setLightColor( F32 r, F32 g, F32 b );
  89. // For changing the ambient light color.
  90. void setAmbientLightColor( F32 r, F32 g, F32 b );
  91. void setObjectModel(const char * modelName);
  92. void deleteModel();
  93. void resetViewport();
  94. void setOrbitDistance(F32 distance);
  95. bool processCameraQuery(CameraQuery *query) override;
  96. void renderWorld(const RectI &updateRect) override;
  97. DECLARE_CONOBJECT(GuiMaterialPreview);
  98. DECLARE_CATEGORY( "Gui Editor" );
  99. GuiMaterialPreview();
  100. ~GuiMaterialPreview();
  101. private:
  102. F32 mMaxOrbitDist;
  103. F32 mMinOrbitDist;
  104. F32 mOrbitDist;
  105. };
  106. #endif