Game Development Community

dev|Pro Game Development Curriculum

Dynamic decals

by Lukas Joergensen · 04/07/2012 (12:31 pm) · 4 comments

I wanted to be able to move decals in realtime for a spell system. I used them as a spell indicator since they wrapped nicely around the terrain.
When i researched on it almost no threads came up with a solution to this, so i decided to give it a go on my own. I came up with 2 methods to move decals in realtime:

Method number 1:
decalManagerRemoveDecal( $theDecal );
$theDecal = decalManagerAddDecal( %newPosition, %newNormal, 0, 1, "theDecalData", true );
Yes, simply delete the decal and add it again not that clean, but does the work.

Method number 2:
I also came across fixing it by doing some c++:
At the ending of decalManager.cpp:
DefineEngineFunction( decalManagerMoveDecal, bool, ( S32 decalID, Point3F position, Point3F normal ),,
   "Moves specified decal.n"
   "@param decalID ID of the decal to move.n"
   "@return Returns true if successful, false if decal ID not found.n"
   "@tsexamplen"
   "// Specify a decal ID to be removedn"
   "%decalID = 1;nn"
   "// Tell the decal manager to remove the specified decal ID.n"
   "decalManagerRemoveDecal( %decalId )n"
   "@endtsexamplen"
   "@ingroup Decals" )
{
   DecalInstance *inst = gDecalManager->getDecal( decalID );
   if( !inst )
      return false;

   inst->mPosition = position;
   inst->mNormal = normal;
   inst->mFlags |= ClipDecal;
   gDecalManager->notifyDecalModified( inst );

   return true;
}
A little finer result now in the script simply do this:
%result = decalManagerMoveDecal( $theDecal, %newPosition, %newNormal);
if(!%result) { $theDecal = decalManagerAddDecal( %newPosition, %newNormal, 0, 1, "theDecalData", true ); }
And it moves the decal the same way that the DecalEditor does it.
But why did i add another line, where i was testing the result?
Because for some reason the decal gets deleted if it gets very far away from the player in the wrong direction, or too far under water. I guess it is when it gets so far away it stops rendering it on the client side. (Since i was working on the clientside)
On the serverside you might be able to work with only this line:
decalManagerMoveDecal( $theDecal , %newPosition, %newNormal );
But i haven't tested it

#1
04/08/2012 (10:15 am)
i saw your this thread
(http://www.garagegames.com/community/forums/viewthread/130205)
posted just before my this one
(http://www.garagegames.com/community/forums/viewthread/130204).

that time did not realize it.
but now it seems this resource is the only solution for my problem.
no matter what i do,i think that would be costly depending on decals number.
will try it.
thanks.
#2
04/20/2012 (5:55 pm)
I may be misunderstanding this whole thing, but can't we spawn a decal as an aiPlayer? Put it on a path, etc.,?
#3
04/22/2012 (1:41 am)
@Dan never heard about such a thing.. Never seen it done, might be working tho. Will try and look into it! Might get rid of my flickering issue :)
#4
04/22/2012 (3:56 am)
Let us know how you go.