TGEA 1.7 port of twSurfaceReference
by Taylor Petrick · 06/18/2008 (8:10 am) · 20 comments
Download Code File
This resource allows you to add all the functionality of the twSurfaceRefrence to TGEA 1.7's foliage replicator. To start with, download the attached zip file containing the code files. Open your compiler and add the files to your project. They should go in the /T3D/fx folder.
Now, for the code changes.
1. Add this to the top of fxFoliageReplicator.cpp:
2. After
3. Add the following lines to the initPersistFields() function:
4. After
5. After
6. After
7. Alright, now open up fxFoliageReplicator.h. After
8. After
9. After
10. Next, open up \console\sim.h. After
11. Then, open \console\sim.cpp. After
12. Open \console\simManager.cpp. After
13. Ok, thats all for source changes. Recompile to make sure that no errors occur, then move onto the scripts changes.
Script Changes
1. Open game\tools\missiodeditor\gui\objectBuilderGui.ed.gui. Right before
2. Open game\tools\missiodeditor\scripts\editors\creator.ed.cs. After
3. Open game\common\clientScripts\missiondownload.cs. After
Alright, thats all the script changes. To use the twSurfaceRefrence:
1. Add to your mission like any other object. Examples of a twSurfaceRefence mission
object and a modified fxFoliageReplicator object are contained in the file 'samples.txt'
in the twSurfaceReference_tgea.zip file.
2. Set up your reference surface:
Place the SurfaceReference object over the precise surface that you want to
reference later for your grass. Select a type from the SurfaceType drop-down menu.
3. Place your foliage:
14a. Place a modified fxFoilageReplicator object in an appropriate location. Make sure that there
is some surface texture the same as you referenced in step 13 above. Select the same
SurfaceType from the drop down menu. Hit 'Apply'.
14b. To make sure your grass does NOT appear on a given referenced surface, then check the
'SurfaceExclusionMode' box. Hit 'Apply'.
If you have any issues, post them here.
This resource allows you to add all the functionality of the twSurfaceRefrence to TGEA 1.7's foliage replicator. To start with, download the attached zip file containing the code files. Open your compiler and add the files to your project. They should go in the /T3D/fx folder.
Now, for the code changes.
1. Add this to the top of fxFoliageReplicator.cpp:
#include "twSurfaceReference.h"
2. After
//------------------------------------------------------------------------------ // // Trig Table Lookups. // //------------------------------------------------------------------------------ const F32 PeriodLen = (F32) 2.0f * (F32) M_PI; const F32 PeriodLenMinus = (F32) (2.0f * M_PI) - 0.01f; //------------------------------------------------------------------------------ // // Class: fxFoliageRenderList // //------------------------------------------------------------------------------add
bool fxFoliageReplicator::GetTerrainTextures(float distance, Point3F& pt, U8 *alphas)
{
RayInfo rInfo;
if (gClientContainer.castRay(pt, Point3F(pt.x, pt.y, pt.z - distance ), TerrainObjectType, &rInfo))
{
U32 CollisionType = rInfo.object->getTypeMask();
if (CollisionType & TerrainObjectType)
{
TerrainBlock* ter = static_cast<TerrainBlock*>(rInfo.object);
Point2I gPos;
const MatrixF & mat = ter->getTransform();
Point3F origin;
mat.getColumn(3, &origin);
F32 squareSize = (F32) ter->getSquareSize();
F32 halfSquareSize = squareSize / 2;
float x = (pt.x - origin.x + halfSquareSize) / squareSize;
float y = (pt.y - origin.y + halfSquareSize) / squareSize;
ter->getMaterialAlpha(Point2I(x,y), alphas);
return true;
}
}
return false;
}3. Add the following lines to the initPersistFields() function:
addField( "SurfaceExclusionMode", TypeBool, Offset( mFieldData.mSurfaceExclusionMode, fxFoliageReplicator ) ); addField( "SurfaceType", TypeEnum, Offset(mFieldData.mTheSurface, fxFoliageReplicator ), 1, &gSurfaceTypeTable );
4. After
if ((CollisionType & WaterObjectType) && !mFieldData.mAllowWaterSurface && !gClientContainer.castRay( FoliageStart, FoliageEnd, FXFOLIAGEREPLICATOR_NOWATER_COLLISION_MASK, &RayEvent)) continue;add
if ((twSurfaceReference::ESurfaceType)mFieldData.mTheSurface) // if we are checking for specific surfaces and not just 'any'
{
if ( BaseSurfaces[(twSurfaceReference::ESurfaceType)mFieldData.mTheSurface].isAvailable)
{
CollisionResult = false;
U8 alphas[TerrainBlock::MaterialGroups];
// Checks if the new position is over a blended terrain texture (a 'surface' ) that is *exactly* the same as the surface where
// the specified SurfaceReference marker was placed.
if (GetTerrainTextures(4000.0f, FoliageStart, alphas))
{
bool skip = mFieldData.mSurfaceExclusionMode;
for (int i=0; i < TerrainBlock::MaterialGroups; i++)
{
if (alphas[ i] != BaseSurfaces[(twSurfaceReference::ESurfaceType)mFieldData.mTheSurface].alphas[ i])
{
skip = !mFieldData.mSurfaceExclusionMode; // even one non-match means this is not the same surface
break;
}
}
if (skip) continue; // don't place grass here
}
}
}5. After
stream->write(mFieldData.mPlaceAreaColour);add
stream->writeFlag(mFieldData.mSurfaceExclusionMode); // allow/disallow toggle stream->write( mFieldData.mTheSurface ); // the surface reference
6. After
stream->read(&mFieldData.mPlaceAreaColour);add
mFieldData.mSurfaceExclusionMode = stream->readFlag(); // Allow/Disallow toggle stream->read( &mFieldData.mTheSurface); // the surface reference
7. Alright, now open up fxFoliageReplicator.h. After
U32 mFoliageRetries;add
bool mSurfaceExclusionMode; // if 1 then allow, if 0 then disallow U32 mTheSurface;
8. After
mFoliageRetries = 100;add
mSurfaceExclusionMode = false; mTheSurface = (U32)twSurfaceReference::eAny;
9. After
fxFoliageReplicator(); ~fxFoliageReplicator();add
bool GetTerrainTextures(float,Point3F&, U8 *);
10. Next, open up \console\sim.h. After
DeclareNamedSet(sgMissionLightingFilterSet);add
DeclareNamedSet(twSurfaceSet)
11. Then, open \console\sim.cpp. After
ImplementNamedSet(sgMissionLightingFilterSet)add [codeImplementNamedSet(twSurfaceSet)[/code]
12. Open \console\simManager.cpp. After
InstantiateNamedSet(sgMissionLightingFilterSet);add
InstantiateNamedSet(twSurfaceSet);.
13. Ok, thats all for source changes. Recompile to make sure that no errors occur, then move onto the scripts changes.
Script Changes
1. Open game\tools\missiodeditor\gui\objectBuilderGui.ed.gui. Right before
function ObjectBuilderGui::buildfxFoliageReplicator(%this)add
function ObjectBuilderGui::buildtwSurfaceReference(%this)
{
%this.className = "twSurfaceReference";
%this.process();
}2. Open game\tools\missiodeditor\scripts\editors\creator.ed.cs. After
%Environment_Item[17] = "MegaTerrain";add
%Environment_Item[18] = "twSurfaceReference";.
3. Open game\common\clientScripts\missiondownload.cs. After
onPhase2Complete();add
StartSurfaceReferencer();
Alright, thats all the script changes. To use the twSurfaceRefrence:
1. Add to your mission like any other object. Examples of a twSurfaceRefence mission
object and a modified fxFoliageReplicator object are contained in the file 'samples.txt'
in the twSurfaceReference_tgea.zip file.
2. Set up your reference surface:
Place the SurfaceReference object over the precise surface that you want to
reference later for your grass. Select a type from the SurfaceType drop-down menu.
3. Place your foliage:
14a. Place a modified fxFoilageReplicator object in an appropriate location. Make sure that there
is some surface texture the same as you referenced in step 13 above. Select the same
SurfaceType from the drop down menu. Hit 'Apply'.
14b. To make sure your grass does NOT appear on a given referenced surface, then check the
'SurfaceExclusionMode' box. Hit 'Apply'.
If you have any issues, post them here.
About the author
Recent Blogs
• N-PAL and My Lack of Updates• TGEA PhysX: Part 6
• TGEA PhysX: Part 5
• TGEA PhysX: Part 4
• TGEA 1.8.1 PhysX - Part 3
#2
06/18/2008 (2:25 am)
O wow.... very kewl
#3
06/18/2008 (8:34 am)
Thanks! It also works with the ShapeReplicator. Just repeat the fxFoliageReplicator parts in the respecitve parts of the shape replicator. I've also managed to get it working with the TGEA 1.7 version of the fxTreeReplicator. At the moment, I'm working on getting into the Ground Cover class. GC is a lot different, though, so it will be more that a simple copy-paste port.
#4
06/18/2008 (1:35 pm)
Cool resource... I was wondering if it were possible to do this...
#5
06/19/2008 (8:51 am)
That is really useful. Nice work.
#6
06/19/2008 (2:50 pm)
Thanks Joseph and Steve!
#7
06/20/2008 (10:28 am)
Oh awesome. Thank you!
#8
06/21/2008 (5:31 am)
No problem Gareth!
#9
07/08/2008 (12:07 pm)
This is pretty cool. Will be adding it to my codebase.
#10
07/15/2008 (9:29 am)
Just like to post this. I ported my codebase from 1.7 to 1.7.1 last week, and for some reason the surface reference wasn't doing anything. It turns out that I forgot to put "StartSurfaceReferencer();" in the correct file. This is essential, so if its not working and your sure you've done everything else correctly, check to make sure that function is called.
#12
07/17/2008 (7:07 am)
Nice. I was planning on porting it to GroundCover myself, but never had the time. Thanks for sharing Leslie.
#13
mTheSurface = (U32)twSurfaceReference::eAny;
twSurfaceReference is not a class or namespace array
08/12/2008 (9:36 am)
i have a problem it says that :mTheSurface = (U32)twSurfaceReference::eAny;
twSurfaceReference is not a class or namespace array
#14
08/12/2008 (9:39 am)
and eAny is a undeclared identifier :(
#15
08/13/2008 (12:57 am)
Make sure you have added the twSurfaceRefrence files to your project. That error means it cannot find twSurfaceRefrence.
#16
08/21/2008 (7:42 am)
hi Itla: I guess you should adjust your include sequence, #include "T3D/fx/twSurfaceReference.h" should be in front of #include "T3D/fx/fxFoliageReplicator.h"
#17
11/03/2008 (7:46 pm)
Awesome!
#18
11/07/2008 (4:51 am)
Hehe :P
#19
02/26/2009 (7:59 am)
Anyone get this working for 1.8.1...I'm working on the groundcover twReference resource(should be basically the same thing) and I can't get it to work... on compile I get "cannot find file: 'renderInstance/renderInstMgr.h'"
#20
03/13/2012 (3:58 am)
this good 
Torque Owner Taylor Petrick