Ribbons On Projectiles And Vehicles
by Steve Acaster · 02/12/2015 (10:55 am) · 12 comments
90% of the code comes from Tim at MaxGaming for TGE/A, 10% from myself to get it working in Torque3D.
www.yorkshirerifles.com/downloads/ribbons_Torque3D.zip
Make sure you've got ribbon.cpp/h and ribbonNode.cpp/h in T3D/fx and the ribbon shaders basicRibbonShaderP/V.hlsl in shaders/ribbons.
ribbons.cs goes in art/datablocks, don't forget to exec it in art/datablocks/datablockExec.cs.
ribbons.cs
new ShaderData( basicRibbonShader )
{
DXVertexShaderFile = "shaders/ribbons/basicRibbonShaderV.hlsl";
DXPixelShaderFile = "shaders/ribbons/basicRibbonShaderP.hlsl";
pixVersion = 2.0;
};
//custom material////////////////////////////////////
singleton CustomMaterial( basicRibbonGlow )
{
shader = basicRibbonShader;
version = 2.0;
emissive[0] = true;
glow[0] = true;
doubleSided = false;
translucent = true;
BlendOp = AddAlpha;
translucentBlendOp = AddAlpha;
preload = false;//yorks
};
//ribbon data////////////////////////////////////////
datablock RibbonData(basicRibbon)
{
category = "Misc";
size[0] = 0.8;
color[0] = "1.0 0.3 0.0 1.0";
position[0] = 1.0;
size[1] = 0;
color[1] = "1.0 0 0.0 0.0";
position[1] = 0.0;
RibbonLength = 6;
fadeAwayStep = 0.25;
RibbonMaterial = basicRibbonGlow;
};
datablock RibbonData(longRibbon)
{
size[0] = 0.5;
color[0] = "0.6 0.7 0.8 1.0";
position[0] = 1.0;
size[1] = 0.25;
color[1] = "0.6 0.7 0.8 0.5";
position[1] = 0.5;
size[2] = 0;
color[2] = "0.6 0.7 0.8 0.0";
position[2] = 0.0;
RibbonLength = 40;
fadeAwayStep = 0.25;
UseFadeOut = true;
RibbonMaterial = basicRibbonGlow;
};
datablock RibbonData(amberRibbon)
{
size[0] = 0.2;
color[0] = "1.0 0.65 0.1 1.0";
position[0] = 1.0;
size[1] = 0;
color[1] = "1.0 0.65 0.1 0.0";
position[1] = 0.0;
RibbonLength = 30;
fadeAwayStep = 0.25;
UseFadeOut = true;
RibbonMaterial = basicRibbonGlow;
};
datablock RibbonData(greenRibbon)
{
size[0] = 0.2;
color[0] = "0.0 1.0 0.0 1.0";
position[0] = 1.0;
size[1] = 0;
color[1] = "0.0 1.0 0.0 0.0";
position[1] = 0.0;
RibbonLength = 30;
fadeAwayStep = 0.25;
UseFadeOut = true;
RibbonMaterial = basicRibbonGlow;
};
datablock RibbonNodeData(DefaultRibbonNodeData)
{
timeMultiple = 1.0;
};
function createRibbon(%emitter, %pos)
{
%r = new RibbonNode()
{
datablock = DefaultRibbonNodeData;
emitter = %emitter;
position = %pos;
};
if(isObject(MissionCleanup))
MissionCleanup.add(%r);
return %r;
}scripts/server/weapon.cs weaponImage::onFire function at the end.
// Create the projectile object
%p = new (%this.projectileType)()
{
dataBlock = %this.projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
sourceClass = %obj.getClassName();
};
MissionCleanup.add(%p);
//yorks we now have a projectile so let's attach a ribbon to it
%ribbon = createRibbon(longRibbon, %obj.getMuzzlePoint(%slot));
%p.mountObject(%ribbon, 0);
}
}Next lets add some ribbons to the Cheetah. scripts/server/cheetah.cs, onAdd function
// Mount the brake lights %obj.mountObject(%obj.rightBrakeLight, %this.rightBrakeSlot); %obj.mountObject(%obj.leftBrakeLight, %this.leftBrakeSlot); //yorks add ribbons! %ribbon1 = createRibbon(amberRibbon, %obj.getTransform()); %ribbon2 = createRibbon(greenRibbon, %obj.getTransform()); %obj.mountObject(%ribbon1, %this.rightBrakeSlot); %obj.mountObject(%ribbon2, %this.leftBrakeSlot);
And make sure we don't get console spam when the vehicle is removed.
scripts/server/vehicle.cs VehicleData::onRemove function
function VehicleData::onRemove(%this, %obj)
{
//echo("c4VehicleData::onRemove("@ %this.getName() @", "@ %obj.getClassName() @")");
// if there are passengers/driver, kick them out
for(%i = 0; %i < %obj.getDatablock().numMountPoints; %i++)
{
if (%obj.getMountNodeObject(%i))
{
%passenger = %obj.getMountNodeObject(%i);
if(isMethod(%passenger, doDismount))//yorks in
%passenger.getDataBlock().doDismount(%passenger, true);
else//yorks in
%passenger.delete();//yorks in for ribbons etc
}
}
}Also resourced at forums.torque3d.org/viewtopic.php?f=17&t=35

About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
#2
02/12/2015 (7:53 pm)
Awesome :-D :-D :-D
#3
02/13/2015 (6:13 am)
Sweet - but I was only joking on the energy rifle resource.
#4
02/13/2015 (12:59 pm)
That's really cool, Mr. Acaster.
#5
02/13/2015 (6:03 pm)
Thanks, Steve! Excellent resource!
#6
02/22/2015 (11:25 am)
Great job Steve! As always.
#7
Etc....Has anyone else experienced this??
03/17/2015 (1:43 pm)
Hey Steve, followed instructions, go to compile the engine and get 42 errors???'GFXVertexPCNTT' : undeclared identifier 'GFXVertexPCNTT' : undeclared identifier 'GFXVertexBufferHandle' : no appropriate default constructor available 'GFXVertexPCNTT' : undeclared identifier 'const GFXVertexFormat *getGFXVertexFormat(void)' : could not deduce template argument for 'T' 'GFXVertexPCNTT' : undeclared identifier 'GFXVertexBufferHandle<T>::set' : cannot convert 'this' pointer
Etc....Has anyone else experienced this??
#8
Thanks in advance....
03/19/2015 (10:25 am)
Hey Steve, using the latest 3.6.3, I see in gfxVertexTypes.h the following has been commented out??DEFINE_VERT( GFXVertexPCNTT,
GFXVertexFlagXYZ | GFXVertexFlagNormal | GFXVertexFlagDiffuse | GFXVertexFlagTextureCount2 | GFXVertexFlagUV0 | GFXVertexFlagUV1)
{
Point3F point;
Point3F normal;
GFXVertexColor color;
Point2F texCoord[2];
};Thanks in advance....
#9
03/27/2015 (10:01 am)
Updated the zip file, turns out I forgot to include the gfxVertexTypes changes. Apologies.
#10
03/28/2015 (3:54 pm)
no probs thank you so much steve for sharing this...
#11
04/09/2015 (10:07 pm)
Thinking of modifing this to smoke particles. Or has someone already done this?
#12
02/14/2016 (12:02 pm)
Cool resource TY 
Richard Marrevee
R.G.S - Richards Game Studio