Cafu Engine
PlantDescription.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_TREE_DESCRIPTION_HPP_INCLUDED
8 #define CAFU_TREE_DESCRIPTION_HPP_INCLUDED
9 
10 #include "Templates/Array.hpp"
11 #include <string>
12 
13 
14 class TextParserT;
15 class MaterialT;
16 namespace MatSys { class RenderMaterialT; }
17 
18 
19 /// Contains a plant description that has all the information needed to create a plant.
20 /// Using a random seed for plant creation this description is used as a template that
21 /// is randomly modified to create multiple different plants from the same plant description.
22 /// The plant description is loaded from a file and always associated with this file.
24 {
25  /// This struct describes a "profile".
26  /// Examples include how the radius of a branch changes from its root to its tip,
27  /// or how child branches are angled from the own root to the tip.
28  struct ProfileT
29  {
30  /// Contains different types of profiles that together with a parameter build up
31  /// a ProfileT object.
32  enum ProfileTypeT { Linear, LinearDroop, InvLinear, InvLinearRamp, ConstantAvg, Round };
33 
34  ProfileTypeT ProfileType; ///< The type of this profile.
35  float Parameter; ///< The floating point parameter describing the profile.
36 
37 
38  /// Constructor: Creates a new profile.
39  /// @param ProfileType_ The type of this profile.
40  /// @param Parameter_ The parameter used with this profile.
41  ProfileT(ProfileTypeT ProfileType_=Linear, float Parameter_=0.0);
42 
43  /// According to this profile, this function computes the "transition value" between two values.
44  /// @param p Relative position at which the transition value is computed (must be 0.0<=p<=1.0).
45  /// @param Value0 "left" Value (p=0.0).
46  /// @param Value1 "right" Value (p=1.0).
47  /// @return Transition value at position p.
48  float Compute(float p, float Value0, float Value1) const;
49  };
50 
51 
52  /// This struct contains a description for an individual branch level.
54  {
55  float Length0; ///< Our length (in % of global size), when we are attached at the root ( 0%) of our parent branch
56  float Length1; ///< Our length (in % of global size), when we are attached at the tip (100%) of our parent branch
57  float LengthV; ///< Variance of our length (in % of global size)
58  ProfileT LengthProfile; ///< Transition function from Length0 to Length1 across our "point of attachment" at our parent
59 
60  float StartAngle0; ///< Our start angle at the parent, when we are attached at the root ( 0%) of our parent branch
61  float StartAngle1; ///< Our start angle at the parent, when we are attached at the tip (100%) of our parent branch
62  float StartAngleV; ///< Variance of our start angle at the parent
63  ProfileT StartAngleProfile; ///< Transition function from StartAngle0 to StartAngle1 across our "point of attachment" at our parent
64 
65  float Radius0; ///< Our radius (at our root, in % of global size), when we are attached at the root ( 0%) of our parent branch
66  float Radius1; ///< Our radius (at our root, in % of global size), when we are attached at the tip (100%) of our parent branch
67  float RadiusV; ///< Variance of our radius (at our root, in % of global size)
68  ProfileT RadiusProfile; ///< Transition function from Radius0 to Radius1 across our "point of attachment" at our parent
69 
70  unsigned long NrOfSegments; ///< Number of segments of this parent
71  unsigned long CrossSectionsResolution; ///< Number of vertices of the cross-sections of the branches of this level
72  ProfileT AngleProfile_Segments; ///< Angle profile across segments (together with Gravity, this rules the shape along the length)
73  ProfileT RadiusProfile_Segments; ///< Radius profile across segments ("thickness" along the length)
74 
75  float FirstChild; ///< Min. distance (in %) of our children (sub-branches or leaves) from our root
76  float LastChild; ///< Max. distance (in %) of our children (sub-branches or leaves) from our root
77  float NrOfChildren; ///< Number of our children per unit length (???)
78  };
79 
80 
81  // ************
82  // Global
83  // ************
84 
85  const std::string FileName; ///< Name of the file this plant description is stored in.
86  unsigned long RandomSeed; ///< Seed for the random number generator.
87  float Size; ///< Height in meters (or any other arbitrary unit).
88  float SizeV; ///< Variance of the height in meters (or any other arbitrary unit).
89  MaterialT* BarkMat; ///< Material used for the bark of this tree.
90  MatSys::RenderMaterialT* BarkRenderMat; ///< Render material used for the bark of this tree.
91 
92 
93  // ************
94  // Branches
95  // ************
96 
97  ArrayT<BranchLevelDescriptionT> BranchLevelDescriptions; ///< The list of branch level descriptions.
98 
99 
100  // ************
101  // Leaves
102  // ************
103 
104  // Dies koennte auch in 'BranchLevelDescriptionT' untergebracht sein; dann koennte *jeder* Ast Leaves haben!
105  float Distance0; ///< Radial distance (in m) of leaf attachment point from parent branch, when attached at parents root ( 0%).
106  float Distance1; ///< Radial distance (in m) of leaf attachment point from parent branch, when attached at parents tip (100%).
107  float DistanceV; ///< Variance of the radial distance (in meters).
108  ProfileT DistanceProfile; ///< Transition function from Distance0 to Distance1 across our "point of attachment" at the parent.
109 
110  ArrayT<MaterialT*> LeafMats; ///< Materials of all leaves.
111  ArrayT<MatSys::RenderMaterialT*> LeafRenderMats; ///< Render materials of all leaves.
112  float LeafSize; ///< The size of the leaf polygons relative to (in % of) 'Size'.
113 
114 
115  /// Constructor. Creates an "empty" tree description.
116  /// Those who really want to can use this constructor to fill-in the PlantDescriptionT fields programmatically
117  /// (instead of using any of the other constructors, which is preferred).
118  /// @param FileName_ The dummy file name of this plant description.
119  PlantDescriptionT(const std::string& FileName_) : FileName(FileName_), BarkRenderMat(NULL) {}
120 
121  /// Destructor.
123 
124  /// Constructor: Creates a tree description from a text parser.
125  /// @param TP The text parser containing the data to create this tree description from.
126  /// @param FileName_ The name of the file this plant description is created from.
127  PlantDescriptionT(TextParserT& TP, const std::string& FileName_);
128 };
129 
130 #endif
float StartAngle1
Our start angle at the parent, when we are attached at the tip (100%) of our parent branch...
Definition: PlantDescription.hpp:61
float Distance0
Radial distance (in m) of leaf attachment point from parent branch, when attached at parents root ( 0...
Definition: PlantDescription.hpp:105
This class represents a surface render material.
Definition: RenderMaterial.hpp:25
ProfileT RadiusProfile_Segments
Radius profile across segments ("thickness" along the length)
Definition: PlantDescription.hpp:73
ProfileT AngleProfile_Segments
Angle profile across segments (together with Gravity, this rules the shape along the length) ...
Definition: PlantDescription.hpp:72
This struct describes a "profile".
Definition: PlantDescription.hpp:28
float StartAngleV
Variance of our start angle at the parent.
Definition: PlantDescription.hpp:62
float DistanceV
Variance of the radial distance (in meters).
Definition: PlantDescription.hpp:107
ProfileT DistanceProfile
Transition function from Distance0 to Distance1 across our "point of attachment" at the parent...
Definition: PlantDescription.hpp:108
float Length1
Our length (in % of global size), when we are attached at the tip (100%) of our parent branch...
Definition: PlantDescription.hpp:56
float Distance1
Radial distance (in m) of leaf attachment point from parent branch, when attached at parents tip (100...
Definition: PlantDescription.hpp:106
MatSys::RenderMaterialT * BarkRenderMat
Render material used for the bark of this tree.
Definition: PlantDescription.hpp:90
unsigned long RandomSeed
Seed for the random number generator.
Definition: PlantDescription.hpp:86
MaterialT * BarkMat
Material used for the bark of this tree.
Definition: PlantDescription.hpp:89
float StartAngle0
Our start angle at the parent, when we are attached at the root ( 0%) of our parent branch...
Definition: PlantDescription.hpp:60
ProfileT(ProfileTypeT ProfileType_=Linear, float Parameter_=0.0)
Constructor: Creates a new profile.
Definition: PlantDescription.cpp:17
ProfileTypeT ProfileType
The type of this profile.
Definition: PlantDescription.hpp:34
PlantDescriptionT(const std::string &FileName_)
Constructor.
Definition: PlantDescription.hpp:119
Contains a plant description that has all the information needed to create a plant.
Definition: PlantDescription.hpp:23
ArrayT< BranchLevelDescriptionT > BranchLevelDescriptions
The list of branch level descriptions.
Definition: PlantDescription.hpp:97
This class represents a surface material ("A datastructural representation of a scripts material def...
Definition: Material.hpp:22
ProfileTypeT
Contains different types of profiles that together with a parameter build up a ProfileT object...
Definition: PlantDescription.hpp:32
float LastChild
Max. distance (in %) of our children (sub-branches or leaves) from our root.
Definition: PlantDescription.hpp:76
float Length0
Our length (in % of global size), when we are attached at the root ( 0%) of our parent branch...
Definition: PlantDescription.hpp:55
float Radius1
Our radius (at our root, in % of global size), when we are attached at the tip (100%) of our parent b...
Definition: PlantDescription.hpp:66
float FirstChild
Min. distance (in %) of our children (sub-branches or leaves) from our root.
Definition: PlantDescription.hpp:75
const std::string FileName
Name of the file this plant description is stored in.
Definition: PlantDescription.hpp:85
float LeafSize
The size of the leaf polygons relative to (in % of) 'Size'.
Definition: PlantDescription.hpp:112
ProfileT LengthProfile
Transition function from Length0 to Length1 across our "point of attachment" at our parent...
Definition: PlantDescription.hpp:58
float RadiusV
Variance of our radius (at our root, in % of global size)
Definition: PlantDescription.hpp:67
unsigned long NrOfSegments
Number of segments of this parent.
Definition: PlantDescription.hpp:70
This struct contains a description for an individual branch level.
Definition: PlantDescription.hpp:53
float Parameter
The floating point parameter describing the profile.
Definition: PlantDescription.hpp:35
ProfileT RadiusProfile
Transition function from Radius0 to Radius1 across our "point of attachment" at our parent...
Definition: PlantDescription.hpp:68
float Compute(float p, float Value0, float Value1) const
According to this profile, this function computes the "transition value" between two values...
Definition: PlantDescription.cpp:22
float SizeV
Variance of the height in meters (or any other arbitrary unit).
Definition: PlantDescription.hpp:88
float Size
Height in meters (or any other arbitrary unit).
Definition: PlantDescription.hpp:87
float Radius0
Our radius (at our root, in % of global size), when we are attached at the root ( 0%) of our parent b...
Definition: PlantDescription.hpp:65
ProfileT StartAngleProfile
Transition function from StartAngle0 to StartAngle1 across our "point of attachment" at our parent...
Definition: PlantDescription.hpp:63
unsigned long CrossSectionsResolution
Number of vertices of the cross-sections of the branches of this level.
Definition: PlantDescription.hpp:71
float NrOfChildren
Number of our children per unit length (???)
Definition: PlantDescription.hpp:77
ArrayT< MatSys::RenderMaterialT * > LeafRenderMats
Render materials of all leaves.
Definition: PlantDescription.hpp:111
ArrayT< MaterialT * > LeafMats
Materials of all leaves.
Definition: PlantDescription.hpp:110
float LengthV
Variance of our length (in % of global size)
Definition: PlantDescription.hpp:57
~PlantDescriptionT()
Destructor.
Definition: PlantDescription.cpp:359
Definition: Renderer.hpp:16
This is a class for parsing text.
Definition: TextParser.hpp:21