1 #pragma once 2 3 #include "irender.h" 4 #include "iundo.h" 5 #include "mapfile.h" 6 #include "selectable.h" 7 #include "shaderlib.h" 8 9 #include "math/Vector3.h" 10 #include "math/matrix.h" 11 #include "generic/referencecounted.h" 12 13 #include "FaceTexDef.h" 14 #include "FaceShader.h" 15 #include "PlanePoints.h" 16 #include "FacePlane.h" 17 18 const double GRID_MIN = 0.125; 19 20 typedef double (*QuantiseFunc) (double f); 21 22 class FaceObserver 23 { 24 public: ~FaceObserver()25 virtual ~FaceObserver () 26 { 27 } 28 virtual void planeChanged () = 0; 29 virtual void connectivityChanged () = 0; 30 virtual void shaderChanged () = 0; 31 virtual void evaluateTransform () = 0; 32 }; 33 34 class Face: public OpenGLRenderable, public Undoable, public FaceShaderObserver 35 { 36 std::size_t m_refcount; 37 38 class SavedState: public UndoMemento 39 { 40 public: 41 FacePlane::SavedState m_planeState; 42 FaceTexdef::SavedState m_texdefState; 43 FaceShader::SavedState m_shaderState; 44 SavedState(const Face & face)45 SavedState (const Face& face) : 46 m_planeState(face.getPlane()), m_texdefState(face.getTexdef()), m_shaderState(face.getShader()) 47 { 48 } 49 exportState(Face & face)50 void exportState (Face& face) const 51 { 52 m_planeState.exportState(face.getPlane()); 53 m_shaderState.exportState(face.getShader()); 54 m_texdefState.exportState(face.getTexdef()); 55 } 56 }; 57 58 public: 59 static QuantiseFunc m_quantise; 60 61 PlanePoints m_move_planepts; 62 PlanePoints m_move_planeptsTransformed; 63 private: 64 FacePlane m_plane; 65 FacePlane m_planeTransformed; 66 FaceShader m_shader; 67 FaceTexdef m_texdef; 68 TextureProjection m_texdefTransformed; 69 70 Winding m_winding; 71 Vector3 m_centroid; 72 73 FaceObserver* m_observer; 74 UndoObserver* m_undoable_observer; 75 MapFile* m_map; 76 77 // assignment not supported 78 Face& operator= (const Face& other); 79 // copy-construction not supported 80 Face (const Face& other); 81 82 public: 83 84 Face (FaceObserver* observer); 85 Face (const Vector3& p0, const Vector3& p1, const Vector3& p2, const std::string& shader, 86 const TextureProjection& projection, FaceObserver* observer); 87 Face (const Face& other, FaceObserver* observer); 88 ~Face (); 89 void planeChanged (); 90 91 void realiseShader (); 92 void unrealiseShader (); 93 94 void instanceAttach (MapFile* map); 95 void instanceDetach (MapFile* map); 96 97 void render (RenderStateFlags state) const; 98 99 void undoSave (); 100 101 // undoable 102 UndoMemento* exportState () const; 103 void importState (const UndoMemento* data); 104 105 void IncRef (); 106 void DecRef (); 107 108 void flipWinding (); 109 110 bool intersectVolume (const VolumeTest& volume, const Matrix4& localToWorld) const; 111 112 void render (Renderer& renderer, const Matrix4& localToWorld) const; 113 114 void transform (const Matrix4& matrix, bool mirror); 115 116 void assign_planepts (const PlanePoints planepts); 117 118 /// \brief Reverts the transformable state of the brush to identity. 119 void revertTransform (); 120 void freezeTransform (); 121 122 void update_move_planepts_vertex (std::size_t index, PlanePoints planePoints); 123 124 void snapto (float snap); 125 126 void testSelect (SelectionTest& test, SelectionIntersection& best); 127 128 void testSelect_centroid (SelectionTest& test, SelectionIntersection& best); 129 130 void shaderChanged (); 131 132 const std::string& GetShader () const; 133 void SetShader (const std::string& name); 134 135 void revertTexdef (); 136 void texdefChanged (); 137 138 void GetTexdef (TextureProjection& projection) const; 139 void SetTexdef (const TextureProjection& projection); 140 141 void GetFlags (ContentsFlagsValue& flags) const; 142 143 ContentsFlagsValue GetFlags () const; 144 145 /** @sa ContentsFlagsValue_assignMasked */ 146 void SetFlags (const ContentsFlagsValue& flags); 147 148 void ShiftTexdef (float s, float t); 149 150 void ScaleTexdef (float s, float t); 151 152 void RotateTexdef (float angle); 153 154 void FitTexture (float s_repeat, float t_repeat); 155 156 void flipTexture(unsigned int flipAxis); 157 158 void EmitTextureCoordinates (); 159 160 const Vector3& centroid () const; 161 162 void construct_centroid (); 163 164 const Winding& getWinding () const; 165 Winding& getWinding (); 166 167 const Plane3& plane3 () const; 168 FacePlane& getPlane (); 169 const FacePlane& getPlane () const; 170 FaceTexdef& getTexdef (); 171 const FaceTexdef& getTexdef () const; 172 FaceShader& getShader (); 173 const FaceShader& getShader () const; 174 175 bool isDetail () const; 176 void setDetail (bool detail); 177 178 bool contributes () const; 179 bool is_bounded () const; 180 }; // class Face 181 182 typedef SmartPointer<Face> FaceSmartPointer; 183 typedef std::vector<FaceSmartPointer> Faces; 184