### Material Defined Decals

Expanding and utilizing the engine via C++.
• 1
• 2

#### Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
ive been trying to create a resource that specifies a decal for any material, similar to the way that a footstepsound is set by the material. code changes are as follows.

in materialDefinition.h

Includes

Code: Select all

#include "T3D/decal/decalManager.h" #include "T3D/decal/decalData.h"

Code: Select all

class DecalData;
below SFXTrack* mImpactSoundCustom;

Code: Select all

DecalData *mDecal;
in materialDefinition.cpp
set the default of mDecal to null

Code: Select all

 mFootstepSoundId = -1; mImpactSoundId = -1; mFootstepSoundCustom = 0; mImpactSoundCustom = 0; mDecal = NULL;

Code: Select all

 ///add field for the decal addField( "customDecal", TYPEID< DecalData >(), Offset(mDecal, Material), "The Decal to display when a projectile impacts on the surface. If no decal is defined it will revert to the default decal for that projectile");
in projectile.h

Code: Select all

class Material;
changed the virtual void of explode

Code: Select all

 virtual void explode(const Point3F& p, const Point3F& n, const U32 collideType, Material *contactMaterial );
then in projectile.cpp

included

Code: Select all

#include "materials/baseMatInstance.h"
updated the explode function

Code: Select all

void Projectile::explode( const Point3F &p, const Point3F &n, const U32 collideType, Material *contactMaterial ) { // Make sure we don't explode twice... if ( mHasExploded ) return; mHasExploded = true; // Move the explosion point slightly off the surface to avoid problems with radius damage Point3F explodePos = p + n * 0.001f; if ( isServerObject() ) { // Do what the server needs to do, damage the surrounding objects, etc. mExplosionPosition = explodePos; mExplosionNormal = n; mCollideHitType = collideType; mDataBlock->onExplode_callback( this, mExplosionPosition, mFadeValue ); setMaskBits(ExplosionMask); // Just wait till the timeout to self delete. This // gives server object time to get ghosted to the client. } else { // Client just plays the explosion at the right place... // Explosion* pExplosion = NULL; if (mDataBlock->waterExplosion && pointInWater(p)) { pExplosion = new Explosion; pExplosion->onNewDataBlock(mDataBlock->waterExplosion, false); } else if (mDataBlock->explosion) { pExplosion = new Explosion; pExplosion->onNewDataBlock(mDataBlock->explosion, false); } if( pExplosion ) { MatrixF xform(true); xform.setPosition(explodePos); pExplosion->setTransform(xform); pExplosion->setInitialState(explodePos, n); pExplosion->setCollideType( collideType ); if (pExplosion->registerObject() == false) { Con::errorf(ConsoleLogEntry::General, "Projectile(%s)::explode: couldn't register explosion", mDataBlock->getName() ); delete pExplosion; pExplosion = NULL; } } if (contactMaterial && contactMaterial->mDecal) { gDecalManager->addDecal(p, n, 0.0f, contactMaterial->mDecal); } // Client (impact) decal. else if(mDataBlock->decal) { gDecalManager->addDecal(p, n, 0.0f, mDataBlock->decal); } // Client object updateSound(); } /* // Client and Server both should apply forces to PhysicsWorld objects // within the explosion. if ( false && mPhysicsWorld ) { F32 force = 200.0f; mPhysicsWorld->explosion( p, 15.0f, force ); } */ }

in projectile::simulate

i added these lines after the RayInfo

Code: Select all

Material* material = (rInfo.material ? dynamic_cast< Material* >(rInfo.material->getMaterial()) : 0);
then changed the explode to have the material

Code: Select all

// Next order of business: do we explode on this hit? if ( mCurrTick > mDataBlock->armingDelay || mDataBlock->armingDelay == 0 ) { mCurrVelocity = Point3F::Zero; explode( rInfo.point, rInfo.normal, objectType, material); }
then in the material definition i added

Code: Select all

customDecal = "ScorchBigDecal";
but it only uses the default decal set by the projectile. Need a fresh set of eyes to look on this and tell me where i am being so stupid lol

#### Re: Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
ive updated this to also have the contactMaterial in the oncollision function and callback, still not working

#### Re: Material Defined Decals

Azaezel
Posts: 395
Joined: Tue Feb 03, 2015 9:50 pm

https://github.com/Azaezel/Torque3D/commits/FX

same thing you're attempting with explosions (prolly be throwin that on over to head at some point). might use that as a template/checklist.

#### Re: Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
ill be honest i prefer using explosions than just editing the decal lol good thinking. Would those changes work with stock 3.10 ?

i was thinking the reason mine wouldn't work was because i wasn't adding a decal id in materialDefinition which i think would be why this

Code: Select all

if (contactMaterial && contactMaterial->mDecal) { gDecalManager->addDecal(p, n, 0.0f, contactMaterial->mDecal); }
was always returning false.

Im gonna revert these files back to stock and use ur resource with explosions instead

#### Re: Material Defined Decals

Azaezel
Posts: 395
Joined: Tue Feb 03, 2015 9:50 pm

Yes, as mentioned http://forums.torque3d.org/viewtopic.php?f=40&t=964 the eventual intent is to squeeze out a wholistic, straightforward, generic approach to interaction effects.

EDIT: special note, for material detection using raycasts, do have to flip that on: https://github.com/Azaezel/Torque3D/com ... 0ebdcR1144

#### Re: Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
thats definitely a better idea lol i was going to attempt rolling everything into the material definition separately, using an explosion is definitely the better way to go good job. Do u know of any way to get decals to stick to a moving object?

I was thinking of trying to add a type to the decal class
Static or attached

static works the way the default one does, attached will move with an object.

Finding the objects position on one tick then on the next tick finding out the difference in its xyz on its next tick and applying the difference to the decals xyz.

Do u think something like that would work?

reason for the two different types is because i think such a thing would be quite expensive maybe so wouldnt want too many of those flying around

#### Re: Material Defined Decals

Duion
Posts: 1006
Joined: Sun Feb 08, 2015 1:51 am

Will explosions then also have decals? I have the problem that my grenades that are made with custom code do not spawn decals, since the decal behavior is inside the weapon code or so.

#### Re: Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
browsing over az's code it shouldnt be too hard to implement a decal, it has all the required info, position and normal from the raycast, just needs a section for decal data like the projectile does, i want to be able to make decals stick to a moving object would definitely make things a bit better for my game. Have a character coming running over with burn marks on his head from plasma blast as he called his enemy players mother a spawn of satan!!!!!....... no seriously i wanna see the damage i do to people

#### Re: Material Defined Decals

Azaezel
Posts: 395
Joined: Tue Feb 03, 2015 9:50 pm

fars the sticking to players bit off the top of my head, would try doin it in 3 phases:

1-
a) hack into the decal manager and tie individual decals to objectIDs
b) toss a check into the lifetime code round about https://github.com/GarageGames/Torque3D ... 1090-L1098 and kill em if they don't exist

2- track relative position motion for tracked objects and offset decals to suit.

3- figure out how to offset decals for animated meshes so if a player moves it's arm where you shot it, it updates to suit. (maybe the equivalent of mounting a decal to a parent bone with a calculated offset, say?)

I will say for ourselves, we've been cooking with https://www.youtube.com/watch?v=lImwpGJhRA4 / https://www.youtube.com/watch?v=F95vYsU ... bv&index=8 (damage lerp that'll be brought along into the engine with the PBR code, since that's a value already ghosted as-is over the network, which means no additional hit there.) Not exactly the same, admitedly, but hey, if the intent is just to get the point across...

#### Re: Material Defined Decals

marauder2k9
Posts: 162
Joined: Wed Feb 18, 2015 7:36 am
i will say the damage map looks cool, but if i shoot a person with my shotgun i want to see the big red wounds where i hit them lol ill try what u suggested with the offset due to particular position, as for the animation, do u know of a way to find the nearest node to a raycast?

i was thinking of screenspace decal rendering

something like whats discussed here https://www.slideshare.net/blindrendere ... e-14699854
• 1
• 2

#### Who is online

Users browsing this forum: No registered users and 0 guests