Torque3D Documentation / _generateds / forestBrushElement.cpp

forestBrushElement.cpp

Engine/source/forest/editor/forestBrushElement.cpp

More...

Public Functions

ConsoleDocClass(ForestBrush , "@brief Container class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ForestBrushElements\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleDocClass(ForestBrushElement , "@brief Represents <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> type of <a href="/coding/class/classforestitem/">ForestItem</a> and parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> how it is placed" " when painting with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classforestbrush/">ForestBrush</a> that contains <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n\n</a>" "@ingroup <a href="/coding/class/classforest/">Forest</a>" )
DefineEngineMethod(ForestBrush , containsItemData , bool , (const char *obj) , "( ForestItemData obj )" )

Detailed Description

Public Functions

ConsoleDocClass(ForestBrush , "@brief Container class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ForestBrushElements\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )

ConsoleDocClass(ForestBrushElement , "@brief Represents <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> type of <a href="/coding/class/classforestitem/">ForestItem</a> and parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> how it is placed" " when painting with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classforestbrush/">ForestBrush</a> that contains <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n\n</a>" "@ingroup <a href="/coding/class/classforest/">Forest</a>" )

DefineEngineMethod(ForestBrush , containsItemData , bool , (const char *obj) , "( ForestItemData obj )" )

IMPLEMENT_CONOBJECT(ForestBrush )

IMPLEMENT_CONOBJECT(ForestBrushElement )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "forest/editor/forestBrushElement.h"
 26
 27#include "console/engineAPI.h"
 28#include "forest/forestItem.h"
 29
 30
 31//-------------------------------------------------------------------------
 32// ForestBrushElement
 33//-------------------------------------------------------------------------
 34
 35IMPLEMENT_CONOBJECT( ForestBrushElement );
 36
 37ConsoleDocClass( ForestBrushElement,
 38   "@brief Represents a type of ForestItem and parameters for how it is placed"
 39   " when painting with a ForestBrush that contains it.\n\n"
 40   "@ingroup Forest"
 41);
 42
 43ForestBrushElement::ForestBrushElement()
 44: mData( NULL ),
 45  mProbability( 1 ),
 46  mRotationRange( 360 ),
 47  mScaleMin( 1 ),
 48  mScaleMax( 1 ),
 49  mScaleExponent( 1 ),
 50  mSinkMin( 0.0f ),
 51  mSinkMax( 0.0f ),
 52  mSinkRadius( 1 ),
 53  mSlopeMin( 0.0f ),
 54  mSlopeMax( 90.0f ),
 55  mElevationMin( -10000.0f ),
 56  mElevationMax( 10000.0f ) 
 57{
 58}
 59
 60
 61void ForestBrushElement::initPersistFields()
 62{   
 63   Parent::initPersistFields();
 64
 65   addGroup( "ForestBrushElement" );
 66
 67      addField( "forestItemData", TYPEID< ForestItemData >(), Offset( mData, ForestBrushElement ), 
 68         "The type of ForestItem this element holds placement parameters for." );
 69
 70      addField( "probability",   TypeF32, Offset( mProbability, ForestBrushElement ),
 71         "The probability that this element will be created during an editor brush stroke "
 72         "is the sum of all element probabilities in the brush divided by the probability "
 73         "of this element." );
 74
 75      addField( "rotationRange",   TypeF32, Offset( mRotationRange, ForestBrushElement ),
 76         "The max rotation in degrees that items will be placed." );
 77
 78      addField( "scaleMin",   TypeF32, Offset( mScaleMin, ForestBrushElement ),
 79         "The minimum random size for each item." );
 80
 81      addField( "scaleMax",   TypeF32, Offset( mScaleMax, ForestBrushElement ),
 82         "The maximum random size of each item." );
 83
 84      addField( "scaleExponent",   TypeF32, Offset( mScaleExponent, ForestBrushElement ),
 85         "An exponent used to bias between the minimum and maximum random sizes." );
 86
 87      addField( "sinkMin",   TypeF32, Offset( mSinkMin, ForestBrushElement ),
 88         "Min variation in the sink radius." );
 89
 90      addField( "sinkMax",   TypeF32, Offset( mSinkMax, ForestBrushElement ),
 91         "Max variation in the sink radius." );
 92
 93      addField( "sinkRadius",   TypeF32, Offset( mSinkRadius, ForestBrushElement ),
 94         "This is the radius used to calculate how much to sink the trunk at "
 95         "its base and is used to sink the tree into the ground when its on a slope." );
 96
 97      addField( "slopeMin",   TypeF32, Offset( mSlopeMin, ForestBrushElement ),
 98         "The min surface slope in degrees this item will be placed on." );
 99
100      addField( "slopeMax",   TypeF32, Offset( mSlopeMax, ForestBrushElement ),
101         "The max surface slope in degrees this item will be placed on." );
102
103      addField( "elevationMin",   TypeF32, Offset( mElevationMin, ForestBrushElement ),
104         "The min world space elevation this item will be placed." );
105
106      addField( "elevationMax",   TypeF32, Offset( mElevationMax, ForestBrushElement ),
107         "The max world space elevation this item will be placed." );
108
109   endGroup( "ForestBrushElement" );      
110}
111
112
113//-------------------------------------------------------------------------
114// ForestBrushElementSet
115//-------------------------------------------------------------------------
116
117SimObjectPtr<SimGroup> ForestBrush::smGroup = NULL;
118
119IMPLEMENT_CONOBJECT( ForestBrush );
120
121ConsoleDocClass( ForestBrush,
122   "@brief Container class for ForestBrushElements\n\n"
123   "Editor use only.\n\n"
124   "@internal"
125);
126
127ForestBrush::ForestBrush()
128{
129
130}
131
132bool ForestBrush::onAdd()
133{
134   if ( !Parent::onAdd() )
135      return false;
136
137   getGroup()->addObject( this );
138
139   return true;
140}
141
142void ForestBrush::addObject( SimObject *inObj )
143{
144   ForestBrushElement *ele = dynamic_cast<ForestBrushElement*>( inObj );
145   if ( !ele )
146      return;
147
148   //if ( containsItemData( ele->mData ) )
149   //   return;
150
151   Parent::addObject( inObj );
152}
153
154SimGroup* ForestBrush::getGroup()
155{   
156   if ( !smGroup )
157   {
158      SimGroup *dummy;
159      if ( Sim::findObject( "ForestBrushGroup", dummy ) )
160      {
161         smGroup = dummy;
162         return smGroup;
163      }
164
165      smGroup = new SimGroup;
166      smGroup->assignName( "ForestBrushGroup" );
167      smGroup->registerObject();
168      Sim::getRootGroup()->addObject( smGroup );
169   }
170
171   return smGroup;
172}
173
174bool ForestBrush::containsItemData( const ForestItemData *inData )
175{
176   SimObjectList::iterator iter = mObjectList.begin();
177   for ( ; iter != mObjectList.end(); iter++ )
178   {
179      ForestBrushElement *pElement = dynamic_cast<ForestBrushElement*>(*iter);
180
181      if ( !pElement )
182         continue;
183
184      if ( pElement->mData == inData )
185         return true;
186   }   
187
188   return false;
189}
190
191DefineEngineMethod( ForestBrush, containsItemData, bool, ( const char * obj ), , "( ForestItemData obj )" )
192{
193   ForestItemData *data = NULL;
194   if ( !Sim::findObject( obj, data ) )
195   {
196      Con::warnf( "ForestBrush::containsItemData - invalid object passed" );
197      return false;
198   }
199
200   return object->containsItemData( data );
201}
202