Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UTGame.UTGib


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
/**
 * base class for gibs
 *
 * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
 */
class UTGib extends Actor
	config(Game)
	notplaceable
	abstract;


/** Our LightEnvironment **/
var DynamicLightEnvironmentComponent GibLightEnvironment;

/** sound played when we hit a wall */
var SoundCue HitSound;

/** the component that will be set to the chosen mesh */
var MeshComponent GibMeshComp;

/** This is the MIC to use for the gib **/
var MaterialInstanceConstant MIC_Gib;

/** This is the MI to use for the decal that this gib may spawn **/
var MaterialInstance MI_Decal;

/** This is the template/parent to use for the decal which will be spawned **/
var protected MaterialInstanceTimeVarying MITV_DecalTemplate;

/** This is the MITV dissolve param for the decal **/
var name DecalDissolveParamName;

/** How long before the Decal should start dissolving **/
var float DecalWaitTimeBeforeDissolve;

/** This is the template/parent to use for the GibMesh which will be spawned **/
var protected MaterialInstanceTimeVarying MITV_GibMeshTemplate;

/** 
 * This is the template/parent to use for the GibMesh which will be spawned.
 * Some of our gibs types have two different materials/packages used so we need to mark which ones need to use the secondary MITV template 
 **/
var protected MaterialInstanceTimeVarying MITV_GibMeshTemplateSecondary;

/** This is the MITV dissolve param for the GibMesh **/
var protected name GibMeshDissolveParamName;

/** How long before the GibMesh should start dissolving **/
var protected float GibMeshWaitTimeBeforeDissolve;


/** PSC for the GibEffect (e.g. for the link gun we play a little lightning) **/
var ParticleSystemComponent PSC_GibEffect;
/** The ParticleSystem or the Custom Gib Effect (if any) **/
var ParticleSystem PS_CustomEffect;

struct StaticMeshDatum
{
	var StaticMesh TheStaticMesh;

	var SkeletalMesh TheSkelMesh;
	var PhysicsAsset ThePhysAsset;

	/** Different gibs can all have different scales based on where the asset came from**/
	var float DrawScale;

	/** Some of our gibs types have two different materials/packages used so we need to mark which ones need to use the secondary MITV template **/
	var bool bUseSecondaryGibMeshMITV;

	structdefaultproperties
	{
		DrawScale=1.0
	}
};

/** list of generic gib meshes from which one will be chosen at random */
var array<StaticMeshDatum> GibMeshesData;

/** Used when is acting as viewtarget */
var vector OldCamLoc;
var rotator OldCamRot;
var bool bStopMovingCamera;


simulated event PreBeginPlay()
{
	Super.PreBeginPlay();

	ChooseGib();
}


/**
 * This will force the gib material to stay streamed in and not be affected by distance based streaming
 * which often seems to be causing pops.
 *
 * @paran TimeToBeResisent num seconds to be resident
 **/
simulated function SetTexturesToBeResident( float TimeToBeResisent )
{
	local int MatIdx;
	local array<texture> Textures;
	local int TexIdx;

	for( MatIdx = 0; MatIdx < GibMeshComp.Materials.Length; ++MatIdx )
	{
		Textures = GibMeshComp.Materials[MatIdx].GetMaterial().GetTextures();

		for( TexIdx = 0; TexIdx < Textures.Length; ++TexIdx )
		{
			//`log( "Texture setting bForceMiplevelsToBeResident: " $ TimeToBeResisent @ GibMeshComp.Materials[MatIdx] @ Textures[TexIdx] );
			Texture2D(Textures[TexIdx]).TimeToForceMipLevelsToBeResident = TimeToBeResisent;
		}
	}
}


/**
 * @param	HUD		- HUD with canvas to draw on
 * @input	out_YL		- Height of the current font
 * @input	out_YPos	- Y position on Canvas. out_YPos += out_YL, gives position to draw text for next debug line.
 */
simulated function DisplayDebug(HUD HUD, out float out_YL, out float out_YPos)
{
	if ( SkeletalMeshComponent(GibMeshComp) != None )
		HUD.Canvas.DrawText("Mesh "$SkeletalMeshComponent(GibMeshComp).SkeletalMesh, false);
	else
		HUD.Canvas.DrawText("Mesh "$StaticMeshComponent(GibMeshComp).StaticMesh, false);
	out_YPos += out_YL;
	HUD.Canvas.SetPos(4,out_YPos);
	super.DisplayDebug(HUD, out_YL, out_YPos);
}

/**
 * This will set the StaticMeshComponent's StaticMesh.  Useful for spawning a UTGib and then setting the value (e.g. the vehicle gibs)
 **/
simulated function SetGibStaticMesh( StaticMesh NewStaticMesh )
{
	local StaticMeshComponent SMC;

	GibMeshComp = new(self) class'UTGibStaticMeshComponent';
	CollisionComponent = GibMeshComp;

	SMC = StaticMeshComponent(GibMeshComp);
	AttachComponent(GibMeshComp);
	// Need to attach before calling SetStaticMesh, so component is in right place before creating physics
	SMC.SetStaticMesh( NewStaticMesh );

	SMC.SetLightEnvironment( GibLightEnvironment );
}


/** This will choose between the two types of gib meshes that we can have. **/
simulated function ChooseGib()
{
	local StaticMeshDatum SMD;
	local StaticMeshComponent SMC;
	local SkeletalMeshComponent SKMC;
	local int StartIndex, Index;
	local MaterialInstanceTimeVarying GibMaterialInstance;

	if (GibMeshesData.length > 0)
	{
		Index = Rand(GibMeshesData.length);
		// don't allow skeletal gibs if low detail
		if ( WorldInfo.bDropDetail || WorldInfo.GetDetailMode() == DM_Low || class'Engine'.static.IsSplitScreen() )
		{
			StartIndex = Index;
			while (GibMeshesData[Index].ThePhysAsset != None)
			{
				Index++;
				if (Index >= GibMeshesData.length)
				{
					Index = 0;
				}
				if (Index == StartIndex)
				{
					Destroy();
					return;
				}
			}
		}
		SMD = GibMeshesData[Index];

		// do the static mesh version of the gib
		if( SMD.ThePhysAsset == NONE )
		{
			GibMeshComp = new(self) class'UTGibStaticMeshComponent';
			CollisionComponent = GibMeshComp;

			SMC = StaticMeshComponent(GibMeshComp);
			SMC.SetScale(SMD.DrawScale);
			AttachComponent(GibMeshComp);
			// Need to attach before calling SetStaticMesh, so component is in right place before creating physics
			SMC.SetStaticMesh( SMD.TheStaticMesh );
		}
		// do the skeletal mesh version of the gib
		else
		{
			GibMeshComp = new(self) class'UTGibSkeletalMeshComponent';
			CollisionComponent = GibMeshComp;

			SKMC = SkeletalMeshComponent(GibMeshComp);
			SKMC.SetSkeletalMesh( SMD.TheSkelMesh );
			SKMC.SetPhysicsAsset( SMD.ThePhysAsset );
			SKMC.SetScale(SMD.DrawScale);
			AttachComponent(GibMeshComp);
			SKMC.SetHasPhysicsAssetInstance( TRUE ); // this need to comes after the AttachComponent so component is in right place.
		}

		GibMeshComp.SetLightEnvironment( GibLightEnvironment );

		DoCustomGibEffects();

		// this is going to set up the MITV so we can have the gibs burn out nicely
		GibMaterialInstance = new(self) class'MaterialInstanceTimeVarying';
		if( SMD.bUseSecondaryGibMeshMITV == FALSE )
		{
			GibMaterialInstance.SetParent( MITV_GibMeshTemplate );
		}
		else
		{
			GibMaterialInstance.SetParent( MITV_GibMeshTemplateSecondary );
		}

		GibMeshComp.SetMaterial( 0, GibMaterialInstance );

		GibMaterialInstance.SetScalarStartTime( GibMeshDissolveParamName, (GibMeshWaitTimeBeforeDissolve-(FRand()*1.0f)));
		
	}
	else
	{
		//`warn( "Unable to find mesh for: " $ self );
		//ScriptTrace();
		Destroy();
	}
}


/** This will do any custom gib effects for this gib.  (e.g. robots have a sparkie that plays!) **/
simulated function DoCustomGibEffects();


function Timer()
{
	local PlayerController PC;

	ForEach LocalPlayerControllers(class'PlayerController', PC)
	{
		if( PC.ViewTarget == self )
		{
			SetTimer( 4.0, FALSE );
			return;
		}
	}

	Destroy();
}

event BecomeViewTarget( PlayerController PC )
{
	SetHidden( TRUE );
	LifeSpan = 0;
	SetTimer( 4.0, FALSE );
}


/**
 *	Calculate camera view point, when viewing this actor.
 *
 * @param	fDeltaTime	delta time seconds since last update
 * @param	out_CamLoc	Camera Location
 * @param	out_CamRot	Camera Rotation
 * @param	out_FOV		Field of View
 *
 * @return	true if Actor should provide the camera point of view.
 */
simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
	local actor HitActor;
	local vector HitNormal, HitLocation;
	local int InYaw;

	if( Physics != PHYS_None )
	{
		if ( bStopMovingCamera )
		{
			OldCamRot.Roll = OldCamRot.Roll & 65535;
			if ( (OldCamRot.Roll < 8192) || (OldCamRot.Roll > 57343) )
			{
				out_CamRot = Rotation;
				out_CamRot.Pitch = 0;
				OldCamRot = out_CamRot;
			}
			else
			{
				InYaw = out_CamRot.Yaw;
				out_CamRot = OldCamRot;
				out_CamRot.Yaw = InYaw;
			}
		}
		else
		{
			out_CamRot = Rotation;
			out_CamRot.Pitch = 0;
			OldCamRot = out_CamRot;
		}
	}

	out_CamLoc = Location;

	if ( OldCamLoc != vect(0,0,0) )
	{
		HitActor = trace(HitLocation, HitNormal, Location, OldCamLoc, false, vect(14,14,14));
		if ( HitActor != None )
		{
			out_CamLoc = HitLocation;
			bStopMovingCamera = (HitNormal.Z > 0.7);
		}
	}
	OldCamLoc = out_CamLoc;
	return false;
}

simulated event RigidBodyCollision( PrimitiveComponent HitComponent, PrimitiveComponent OtherComponent,
					const out CollisionImpactData RigidCollisionData, int ContactIndex )
{
	// don't spawn a decal unless we have more than likely hit something other than the orig pawn or other Gibs
	if( (WorldInfo.TimeSeconds - CreationTime ) > 0.4 )
	{
		//`log( "RBC: " $ self $ " against " $ HitComponent );

		// once we hit one thing don't fire off anymore hits
		if( GibMeshComp != none )
		{
			GibMeshComp.SetNotifyRigidBodyCollision( FALSE );
		}

		if ( EffectIsRelevant(Location, false, 4000.0) )
		{
			PlaySound( HitSound, TRUE );
			LeaveADecal( Location, Normal(Velocity) );
		}
	}
}


/** Data provided by the derived classes to do their specific form of decal leaving (e.g. blood for bodies, green goop for aliens, etc.) **/
simulated function LeaveADecal( vector HitLoc, vector HitNorm )
{
	local Actor TraceActor;
	local vector out_HitLocation;
	local vector out_HitNormal;
	local vector TraceDest;
	local vector TraceStart;
	local vector TraceExtent;
	local TraceHitInfo HitInfo;

	// this code is mostly duplicated in:  UTGib, UTProjectile, UTVehicle, UTWeaponAttachment be aware when updating
	// see if our child class provided a template to spawn
	if( MITV_DecalTemplate != none )
	{
		// these should be randomized
		TraceStart = HitLoc + ( -HitNorm * 15 );
		TraceDest = HitLoc + ( HitNorm * 15 );
		//DrawDebugLine( TraceStart, TraceDest, 255,255,255, TRUE );

		TraceActor = Trace( out_HitLocation, out_HitNormal, TraceDest, TraceStart, false, TraceExtent, HitInfo, TRACEFLAG_PhysicsVolumes );

		if( TraceActor != None )
		{
			MI_Decal = new(self) class'MaterialInstanceTimeVarying';
			MI_Decal.SetParent( MITV_DecalTemplate );

			WorldInfo.MyDecalManager.SpawnDecal(MI_Decal, out_HitLocation, rotator(-out_HitNormal), 200, 200, 10, false,, HitInfo.HitComponent, true, false, HitInfo.BoneName, HitInfo.Item, HitInfo.LevelIndex);

			MaterialInstanceTimeVarying(MI_Decal).SetScalarStartTime( DecalDissolveParamName, DecalWaitTimeBeforeDissolve );
		}
	}
}


simulated function TurnOnCollision()
{
	//`log( "COLLIDING ON: " $ self );
	//GibMeshComp.SetActorCollision( TRUE, FALSE );

	GibMeshComp.SetBlockRigidBody( TRUE );

	GibMeshComp.SetRBCollidesWithChannel( RBCC_Default, TRUE );
	GibMeshComp.SetRBCollidesWithChannel( RBCC_Pawn, TRUE );
	GibMeshComp.SetRBCollidesWithChannel( RBCC_Vehicle, TRUE );
	GibMeshComp.SetRBCollidesWithChannel( RBCC_GameplayPhysics, TRUE );
	GibMeshComp.SetRBCollidesWithChannel( RBCC_EffectPhysics, TRUE );

	DetachComponent(GibMeshComp);
	AttachComponent(GibMeshComp);

	GibMeshComp.WakeRigidBody();
}

defaultproperties
{
   Begin Object Class=DynamicLightEnvironmentComponent Name=GibLightEnvironmentComp ObjName=GibLightEnvironmentComp Archetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
      AmbientShadowColor=(R=0.300000,G=0.300000,B=0.300000,A=1.000000)
      AmbientGlow=(R=0.500000,G=0.500000,B=0.500000,A=1.000000)
      bCastShadows=False
      Name="GibLightEnvironmentComp"
      ObjectArchetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
   End Object
   GibLightEnvironment=GibLightEnvironmentComp
   DecalDissolveParamName="DissolveAmount"
   DecalWaitTimeBeforeDissolve=20.000000
   GibMeshDissolveParamName="BurnTime"
   GibMeshWaitTimeBeforeDissolve=8.000000
   Components(0)=GibLightEnvironmentComp
   Physics=PHYS_RigidBody
   TickGroup=TG_PostAsyncWork
   bDestroyedByInterpActor=True
   bGameRelevant=True
   bCollideActors=True
   bProjTarget=True
   bNoEncroachCheck=True
   LifeSpan=10.000000
   CollisionType=COLLIDE_CustomDefault
   Name="Default__UTGib"
   ObjectArchetype=Actor'Engine.Default__Actor'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: tr 31-1-2018 17:18:36.000 - Creation time: sk 18-3-2018 10:01:21.217 - Created with UnCodeX