Cafu Engine
Node.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_NODE_INTERFACE_HPP_INCLUDED
8 #define CAFU_SCENEGRAPH_NODE_INTERFACE_HPP_INCLUDED
9 
10 #include "Math3D/BoundingBox.hpp"
11 #include "Math3D/Vector3.hpp"
12 #include "PatchMesh.hpp"
13 
14 #include <fstream>
15 
16 
17 class PlantDescrManT;
18 class TerrainT;
19 class ModelManagerT;
20 
21 
22 namespace cf
23 {
24  namespace SceneGraph
25  {
26  namespace aux
27  {
28  class PoolT;
29  }
30 
31  class LightMapManT;
32  class SHLMapManT;
33 
34 
36  {
37  public:
38 
39  /// Reads a GenericNodeT from InFile.
40  static GenericNodeT* CreateFromFile_cw(std::istream& InFile, aux::PoolT& Pool,
41  LightMapManT& LMM, SHLMapManT& SMM, PlantDescrManT& PDM, const ArrayT<const TerrainT*>& ShTe, ModelManagerT& ModelMan);
42 
43  /// The virtual destructor, so that derived classes can safely be deleted via a GenericNodeT (base class) pointer.
44  virtual ~GenericNodeT() { }
45 
46  virtual void WriteTo(std::ostream& OutFile, aux::PoolT& Pool) const
47  {
48  }
49 
50  /// Returns the bounding box of the contents of this scene node.
51  virtual const BoundingBox3T<double>& GetBoundingBox() const
52  {
53  static BoundingBox3T<double> BB;
54 
55  return BB;
56  }
57 
58 
59  // virtual void InitDrawing()
60  // {
61  // }
62 
63  /// TODO / FIXME:
64  /// This method is a hot-fix for getting the render order with translucent Bezier Patches right.
65  /// It should be removed again and the whole system should be replaced with something as in the Q3 renderer!
66  virtual bool IsOpaque() const
67  {
68  return true;
69  }
70 
71  /// Draws the contents of this scene node.
72  /// @param ViewerPos Position of the viewer.
73  virtual void DrawAmbientContrib(const Vector3dT& ViewerPos) const
74  {
75  }
76 
77  // TODO: The signatures of all these Draw...() methods are highly questionable:
78  // The parameters (ViewerPos, LightPos, LightRadius) are also (in parallel) set in the MatSys::Renderer,
79  // LightRadius is given to this method but not to DrawLightSourceContrib, etc.
80  // See the implementation in BspTreeNode.cpp for why this is problematic.
81  // ===> The problem is probably best solved with the strategy mentioned above: Use something as in the Q3 renderer!
82  virtual void DrawStencilShadowVolumes(const Vector3dT& LightPos, const float LightRadius) const
83  {
84  }
85 
86  virtual void DrawLightSourceContrib(const Vector3dT& ViewerPos, const Vector3dT& LightPos) const
87  {
88  }
89 
90  virtual void DrawTranslucentContrib(const Vector3dT& ViewerPos) const
91  {
92  }
93 
94 
95  /// If this NodeT uses lightmaps, this methods initializes default (full-bright) lightmaps for it at the proper size.
96  /// This method is intended to be called by CaBSP, after it is completely done with changing the geometry of the node
97  /// (the implementation would be part of the nodes constructor otherwise).
98  /// The method may or may not use the LightMapManT for its purposes, the caller should not care.
99  virtual void InitDefaultLightMaps(const float LightMapPatchSize)
100  {
101  }
102 
103  /// Creates the patch meshes for this NodeT for the purpose of radiosity computations (CaLight).
104  /// The created patch meshes are just appended to the PatchMeshes array, i.e. the PatchMeshes array is not cleared by this function.
105  /// The origins of the patches are chosen so that self-intersections due to rounding errors are impossible or at least unlikely.
106  ///
107  /// @param PatchMeshes The array the created patch meshes are appended to. The array is not initially cleared by this function.
108  /// @param SampleCoords For each patch of each appended patch mesh, an array of sample coordinates is appended by this function.
109  /// The minimum number of samples returned per patch is normally one, namely the one identical to the patches coordinate.
110  /// NOTE: There may be NO SAMPLES AT ALL for a patch if InsideFace==false for that patch, so the caller must not make any assumptions.
111  /// The calling code may use that for example for computing initial sunlight information.
112  /// The array is not initially cleared by this function.
113  /// @param LightMapPatchSize The size of the lightmap patches.
114  virtual void CreatePatchMeshes(ArrayT<PatchMeshT>& PatchMeshes, ArrayT< ArrayT< ArrayT<Vector3dT> > >& SampleCoords, const float LightMapPatchSize) const
115  {
116  }
117 
118  /// Takes the patches of the given patch mesh back into the lightmap of this node.
119  virtual void BackToLightMap(const PatchMeshT& PatchMesh, const float LightMapPatchSize)
120  {
121  }
122  };
123  }
124 }
125 
126 #endif
virtual void DrawAmbientContrib(const Vector3dT &ViewerPos) const
Draws the contents of this scene node.
Definition: Node.hpp:73
This class manages lightmaps, e.g. by "allocating" rectangular areas in larger bitmaps.
Definition: LightMapMan.hpp:25
This class represents terrains, offering methods for LoD rendering and collision detection.
Definition: Terrain.hpp:17
Definition: _aux.hpp:111
This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps...
Definition: SHLMapMan.hpp:25
The plant description manager holds and manages all plant descriptions so they can be shared with mul...
Definition: PlantDescrMan.hpp:19
virtual void InitDefaultLightMaps(const float LightMapPatchSize)
If this NodeT uses lightmaps, this methods initializes default (full-bright) lightmaps for it at the ...
Definition: Node.hpp:99
Definition: PatchMesh.hpp:33
static GenericNodeT * CreateFromFile_cw(std::istream &InFile, aux::PoolT &Pool, LightMapManT &LMM, SHLMapManT &SMM, PlantDescrManT &PDM, const ArrayT< const TerrainT * > &ShTe, ModelManagerT &ModelMan)
Reads a GenericNodeT from InFile.
Definition: Node.cpp:19
virtual ~GenericNodeT()
The virtual destructor, so that derived classes can safely be deleted via a GenericNodeT (base class)...
Definition: Node.hpp:44
virtual void BackToLightMap(const PatchMeshT &PatchMesh, const float LightMapPatchSize)
Takes the patches of the given patch mesh back into the lightmap of this node.
Definition: Node.hpp:119
virtual const BoundingBox3T< double > & GetBoundingBox() const
Returns the bounding box of the contents of this scene node.
Definition: Node.hpp:51
virtual bool IsOpaque() const
TODO / FIXME: This method is a hot-fix for getting the render order with translucent Bezier Patches r...
Definition: Node.hpp:66
This class is used for managing model instances.
Definition: ModelManager.hpp:31
Definition: Renderer.hpp:16
Definition: Node.hpp:35
virtual 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: Node.hpp:114