Cafu Engine
FaceNode.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_SCENEGRAPH_FACENODE_HPP_INCLUDED
8 #define CAFU_SCENEGRAPH_FACENODE_HPP_INCLUDED
9 
10 #include "Node.hpp"
11 #include "MaterialSystem/Mesh.hpp"
12 #include "Math3D/Polygon.hpp"
13 
14 namespace MatSys
15 {
16  class RenderMaterialT;
17 }
18 
19 class MaterialT;
20 struct FaceT;
21 
22 
23 namespace cf
24 {
25  namespace SceneGraph
26  {
27  class FaceNodeT : public GenericNodeT
28  {
29  public:
30 
31  struct TexInfoT
32  {
33  Vector3fT U;
34  Vector3fT V;
35  float OffsetU;
36  float OffsetV;
37  };
38 
40  {
41  unsigned short LightMapNr; ///< In welcher LightMap liegt unsere Teil-LightMap?
42  unsigned short PosS; ///< S-Position unserer Teil-LightMap innerhalb der LightMap.
43  unsigned short PosT; ///< T-Position unserer Teil-LightMap innerhalb der LightMap.
44  unsigned short SizeS; ///< S-Größe unserer Teil-LightMap.
45  unsigned short SizeT; ///< T-Größe unserer Teil-LightMap.
46  };
47 
48  struct SHLMapInfoT
49  {
50  unsigned short SHLMapNr; ///< In welcher SHLMap liegt unsere Teil-SHLMap?
51  unsigned short PosS; ///< S-Position unserer Teil-SHLMap innerhalb der SHLMap.
52  unsigned short PosT; ///< T-Position unserer Teil-SHLMap innerhalb der SHLMap.
53  unsigned short SizeS; ///< S-Größe unserer Teil-SHLMap.
54  unsigned short SizeT; ///< T-Größe unserer Teil-SHLMap.
55  };
56 
57 
58  /// The constructor for creating an "empty" face.
59  /// Needed e.g. by the named constructor CreateFromFile_cw() below.
60  FaceNodeT(LightMapManT& LMM, SHLMapManT& SMM);
61 
62  /// Constructor for creating a FaceNodeT from components.
63  /// This is currently only needed by the LoadWorld.cpp and LeakDetection.cpp files of the CaBSP tool.
64  FaceNodeT(LightMapManT& LMM, SHLMapManT& SMM, const Polygon3T<double>& Poly_, MaterialT* Material_, const TexInfoT& TI_);
65 
66  /// The copy constructor.
67  FaceNodeT(const FaceNodeT& Other);
68 
69  /// Named constructor.
70  static FaceNodeT* CreateFromFile_cw(std::istream& InFile, aux::PoolT& Pool, LightMapManT& LMM, SHLMapManT& SMM);
71 
72  /// The destructor.
73  ~FaceNodeT();
74 
75  void InitRenderMeshesAndMats(const ArrayT<Vector3dT>& SharedVertices, const float LightMapPatchSize);
76 
77  /// Returns the DrawIndices. For CaBSP.
78  ArrayT<unsigned long>& GetDrawIndices() { return DrawIndices; }
79 
80  /// Returns the LightMapMan. For CaBSP.
81  LightMapManT& GetLightMapMan() const { return LightMapMan; }
82 
83  /// Returns the SHLMapMan. For CaBSP.
84  SHLMapManT& GetSHLMapMan() const { return SHLMapMan; }
85 
86  /// Determines the lightmap color of this face near position Pos.
87  /// @returns true if the lightmap color could be determined and written into the Red, Green and Blue parameters.
88  bool GetLightmapColorNearPosition(const Vector3dT& Pos, Vector3fT& LightMapColor, const float LightMapPatchSize) const;
89 
90  // The NodeT interface.
91  void WriteTo(std::ostream& OutFile, aux::PoolT& Pool) const;
93 
94  // void InitDrawing();
95  bool IsOpaque() const;
96  void DrawAmbientContrib(const Vector3dT& ViewerPos) const;
97  void DrawStencilShadowVolumes(const Vector3dT& LightPos, const float LightRadius) const;
98  void DrawLightSourceContrib(const Vector3dT& ViewerPos, const Vector3dT& LightPos) const;
99  void DrawTranslucentContrib(const Vector3dT& ViewerPos) const;
100 
101  void InitDefaultLightMaps(const float LightMapPatchSize);
102  void CreatePatchMeshes(ArrayT<PatchMeshT>& PatchMeshes, ArrayT< ArrayT< ArrayT<Vector3dT> > >& SampleCoords, const float LightMapPatchSize) const;
103  void BackToLightMap(const PatchMeshT& PatchMesh, const float LightMapPatchSize);
104 
105 
106  // TODO: The stuff below should actually be protected or private rather than public.
107  // However, it used to be in the obsolete FaceT struct that I used earlier, and a lot of Code (CaBSP, CaLight etc.)
108  // still accesses our members directly. Should of course change that...
109  public:
110 
111  static const double ROUND_EPSILON; ///< The maximum amount that is allowed for geometry-related rounding errors.
112 
113  Polygon3T<double> Polygon;
114  MaterialT* Material; ///< The material that is assigned to this face. The pointer points into the MaterialManager-maintained list.
115  TexInfoT TI;
116  LightMapInfoT LightMapInfo;
117  SHLMapInfoT SHLMapInfo;
118 
119 
120  private:
121 
122  //void Init(); ///< Helper method for the constructors.
123  //void Clean(); ///< Helper method for the destructor. Also called at the begin of Init().
124 
125  void operator = (const FaceNodeT&); ///< Use of the Assignment Operator is not allowed.
126 
127  LightMapManT& LightMapMan;
128  SHLMapManT& SHLMapMan;
129 
130  BoundingBox3T<double> BB; // TODO!!! This was in DrawableMapT, need to setup after ctor is complete!!!!!!!!!!!!!!!!!
131  ArrayT<unsigned long> DrawIndices; // TODO!!! This was in MapT... !!!!!!!!!!!!!!!!!
132  MatSys::MeshT Mesh; // TODO!!! This was in DrawableMapT, need to setup after ctor is complete!!!!!!!!!!!!!!!!!
133  MatSys::RenderMaterialT* RenderMat; // TODO!!! This was in DrawableMapT, need to setup after ctor is complete!!!!!!!!!!!!!!!!!
134  };
135  }
136 }
137 
138 #endif
MaterialT * Material
The material that is assigned to this face. The pointer points into the MaterialManager-maintained li...
Definition: FaceNode.hpp:114
unsigned short PosT
T-Position unserer Teil-LightMap innerhalb der LightMap.
Definition: FaceNode.hpp:43
This class manages lightmaps, e.g. by "allocating" rectangular areas in larger bitmaps.
Definition: LightMapMan.hpp:25
This class represents a surface render material.
Definition: RenderMaterial.hpp:25
unsigned short SizeT
T-Größe unserer Teil-LightMap.
Definition: FaceNode.hpp:45
void InitDefaultLightMaps(const float LightMapPatchSize)
If this NodeT uses lightmaps, this methods initializes default (full-bright) lightmaps for it at the ...
Definition: FaceNode.cpp:664
LightMapManT & GetLightMapMan() const
Returns the LightMapMan. For CaBSP.
Definition: FaceNode.hpp:81
unsigned short LightMapNr
In welcher LightMap liegt unsere Teil-LightMap?
Definition: FaceNode.hpp:41
Definition: _aux.hpp:111
Definition: FaceNode.hpp:27
This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps...
Definition: SHLMapMan.hpp:25
ArrayT< unsigned long > & GetDrawIndices()
Returns the DrawIndices. For CaBSP.
Definition: FaceNode.hpp:78
unsigned short PosS
S-Position unserer Teil-LightMap innerhalb der LightMap.
Definition: FaceNode.hpp:42
void DrawAmbientContrib(const Vector3dT &ViewerPos) const
Draws the contents of this scene node.
Definition: FaceNode.cpp:566
Definition: FaceNode.hpp:39
~FaceNodeT()
The destructor.
Definition: FaceNode.cpp:205
unsigned short SizeS
S-Größe unserer Teil-SHLMap.
Definition: FaceNode.hpp:53
Definition: PatchMesh.hpp:33
This class represents a surface material ("A datastructural representation of a scripts material def...
Definition: Material.hpp:22
unsigned short PosS
S-Position unserer Teil-SHLMap innerhalb der SHLMap.
Definition: FaceNode.hpp:51
static FaceNodeT * CreateFromFile_cw(std::istream &InFile, aux::PoolT &Pool, LightMapManT &LMM, SHLMapManT &SMM)
Named constructor.
Definition: FaceNode.cpp:78
void CreatePatchMeshes(ArrayT< PatchMeshT > &PatchMeshes, ArrayT< ArrayT< ArrayT< Vector3dT > > > &SampleCoords, const float LightMapPatchSize) const
Creates the patch meshes for this NodeT for the purpose of radiosity computations (CaLight)...
Definition: FaceNode.cpp:727
void BackToLightMap(const PatchMeshT &PatchMesh, const float LightMapPatchSize)
Takes the patches of the given patch mesh back into the lightmap of this node.
Definition: FaceNode.cpp:870
static const double ROUND_EPSILON
The maximum amount that is allowed for geometry-related rounding errors.
Definition: FaceNode.hpp:111
unsigned short SHLMapNr
In welcher SHLMap liegt unsere Teil-SHLMap?
Definition: FaceNode.hpp:50
FaceNodeT(LightMapManT &LMM, SHLMapManT &SMM)
The constructor for creating an "empty" face.
Definition: FaceNode.cpp:26
unsigned short SizeT
T-Größe unserer Teil-SHLMap.
Definition: FaceNode.hpp:54
Definition: FaceNode.hpp:48
SHLMapManT & GetSHLMapMan() const
Returns the SHLMapMan. For CaBSP.
Definition: FaceNode.hpp:84
bool IsOpaque() const
TODO / FIXME: This method is a hot-fix for getting the render order with translucent Bezier Patches r...
Definition: FaceNode.cpp:560
bool GetLightmapColorNearPosition(const Vector3dT &Pos, Vector3fT &LightMapColor, const float LightMapPatchSize) const
Determines the lightmap color of this face near position Pos.
Definition: FaceNode.cpp:412
unsigned short SizeS
S-Größe unserer Teil-LightMap.
Definition: FaceNode.hpp:44
const BoundingBox3T< double > & GetBoundingBox() const
Returns the bounding box of the contents of this scene node.
Definition: FaceNode.cpp:554
Definition: FaceNode.hpp:31
unsigned short PosT
T-Position unserer Teil-SHLMap innerhalb der SHLMap.
Definition: FaceNode.hpp:52
Definition: Renderer.hpp:16
This class represents a polygonal mesh.
Definition: Mesh.hpp:45
Definition: Node.hpp:35