mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-25 09:33:50 +00:00
Adding a basic rule-based terrain painting implementation.
http://www.garagegames.com/community/resources/view/17145
This commit is contained in:
parent
79fd610301
commit
25efdb4a06
10 changed files with 769 additions and 0 deletions
|
|
@ -2933,3 +2933,74 @@ ConsoleMethod( TerrainEditor, setSlopeLimitMaxAngle, F32, 3, 3, 0)
|
|||
object->mSlopeMaxAngle = angle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void TerrainEditor::autoMaterialLayer( F32 mMinHeight, F32 mMaxHeight, F32 mMinSlope, F32 mMaxSlope )
|
||||
{
|
||||
if (!mActiveTerrain)
|
||||
return;
|
||||
|
||||
S32 mat = getPaintMaterialIndex();
|
||||
if (mat == -1)
|
||||
return;
|
||||
|
||||
mUndoSel = new Selection;
|
||||
|
||||
U32 terrBlocks = mActiveTerrain->getBlockSize();
|
||||
for (U32 y = 0; y < terrBlocks; y++)
|
||||
{
|
||||
for (U32 x = 0; x < terrBlocks; x++)
|
||||
{
|
||||
// get info
|
||||
GridPoint gp;
|
||||
gp.terrainBlock = mActiveTerrain;
|
||||
gp.gridPos.set(x, y);
|
||||
|
||||
GridInfo gi;
|
||||
getGridInfo(gp, gi);
|
||||
|
||||
if (gi.mMaterial == mat)
|
||||
continue;
|
||||
|
||||
Point3F wp;
|
||||
gridToWorld(gp, wp);
|
||||
|
||||
if (!(wp.z >= mMinHeight && wp.z <= mMaxHeight))
|
||||
continue;
|
||||
|
||||
// transform wp to object space
|
||||
Point3F op;
|
||||
mActiveTerrain->getWorldTransform().mulP(wp, &op);
|
||||
|
||||
Point3F norm;
|
||||
mActiveTerrain->getNormal(Point2F(op.x, op.y), &norm, true);
|
||||
|
||||
if (mMinSlope > 0)
|
||||
if (norm.z > mSin(mDegToRad(90.0f - mMinSlope)))
|
||||
continue;
|
||||
|
||||
if (mMaxSlope < 90)
|
||||
if (norm.z < mSin(mDegToRad(90.0f - mMaxSlope)))
|
||||
continue;
|
||||
|
||||
gi.mMaterialChanged = true;
|
||||
mUndoSel->add(gi);
|
||||
gi.mMaterial = mat;
|
||||
setGridInfo(gi);
|
||||
}
|
||||
}
|
||||
|
||||
if(mUndoSel->size())
|
||||
submitUndo( mUndoSel );
|
||||
else
|
||||
delete mUndoSel;
|
||||
|
||||
mUndoSel = 0;
|
||||
|
||||
scheduleMaterialUpdate();
|
||||
}
|
||||
|
||||
ConsoleMethod( TerrainEditor, autoMaterialLayer, void, 6, 6, "(float minHeight, float maxHeight, float minSlope, float maxSlope)")
|
||||
{
|
||||
object->autoMaterialLayer( dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]), dAtof(argv[5]) );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,8 @@ class TerrainEditor : public EditTSCtrl
|
|||
void submitMaterialUndo( String actionName );
|
||||
void onMaterialUndo( TerrainBlock *terr );
|
||||
|
||||
void autoMaterialLayer(F32, F32, F32, F32);
|
||||
|
||||
private:
|
||||
|
||||
typedef EditTSCtrl Parent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue