LYN-2537 engine assets (#254)

* LYN-2537 Moved the Engine and Editor folder to be within the EngineAssets folder

* Fixed Documentation in bootstrap.cfg to correct the path to the user project specific registry file

* Adding a newline to the output of AssetCatalog 'Registering asset..., but type is not set' message

* Updating the AssetProcessorPlatformConfig.setreg Scan Folder to detect
the @ENGINEROOT@/EngineAssets/Engine path for engine runtime assets and
@ENGINEROOT@/EngineAssets/Editor path for engine tool assets

* Updating references to Icons and other assets to account for moving the
Engine and Editor folder under a single EngineAssets folder

* Moving the Engine Settings Registry folder from Engine/Registry -> Registry

* Removed the LY_PROJECT_CMAKE_PATH define as it is not portable to other locations. It is hard coded to the project location that was used for the CMake configuration. Furthermore it paths with backslashes within it are treated as escape characters and not a path separator

* Updated the LyTestTools asset_processor.py script to copy the exclude.filetag from the EngineAssets/Engine directory now

* Fixed Atom Shader Preprocessing when running using an External Project

* Updated the TSGenerateAction.cpp to fix the build error with using a renamed variable

* Updated the Install_Common.cmake ly_setup_others function to install the
EngineAssets directory and the each of the Gem's Assets directory while
maintaining the relative directory structure to the Engine Root
Also updated the install step to install the Registry folder at the
engine root

* Fixed the copying of the Registry folder to be in the install root, instead of under a second 'Registry' folder

* Moving the AssetProcessorPlatformConfig.setreg file over to the Registry folder

* Updated the LyTestTools and C++ code to point that the new location of
the AssetProcessorPlatformConfig.setreg file inside of the Registry
folder

* Renamed Test AssetProcessor*Config.ini files to have the .setreg extension

* Converted the AssetProcessor test setreg files from ini format to json
format using the SerializeContextTools convert-ini command

* Updated the AssetProcessor CMakeLists.txt to copy over the test setreg files to the build folder

* Updated the assetprocessor test file list to point at the renamed AsssetProcessor*Config setreg filenames

* Removed the Output Prefix code from the AssetProcessor. The complexity that it brought to the AP code is not needed, as users can replicate the behavior by just moving there assets underneath a another folder, underneath the scan folder

* Adding back support to read the AssetProcessorPlatformConfig.setreg file from the asset root. This is only needed for C++ UnitTests as they run in an environment where the accessing the Engine Settings Registry is not available

* Updating the Install_common.cmake logic to copy any "Assets" folder to
the install layout.
The Script has also been updated to copy over the "Assets" folder in the
Engine Root to the install layout instead of an "EngineAssets" folder

* Updating References to EngineAssets source asset folder in code to be the Assets source folder

* Moved the Engine Source Asset folder of 'EngineAssets' to a new folder name of 'Assets'. This is inline with the naming scheme we use for Gem asset folders

* Adding the EngineFinder.cmake to the AutomatedTesting project to allow it to work in a project centric manner

* Updating the LyTestTools copy_assets_to_project function to be able to copy assets with folders to the temporary project root
Fixed an issue in LyTestTools where the temporary log directory could have shutil.rmtree being called twice on it leading to an exception which fails an automated test

Updated the asset_procesor_gui_tests_2 AddScanFolder test to not use the
output prefix, but instead place the source asset root into a
subdirectory

* Correct the AssetProcessorPlatformConfig Scan Folders for the EngineAssets directory to point at the Assets directory

* Updated the asset procesor batch dependency test scan folder to point at the 'Assets' folder instead of 'EngineAssets'
This commit is contained in:
lumberyard-employee-dm
2021-04-28 21:38:43 -05:00
committed by GitHub
parent ed74bb9166
commit 3dec5d3b71
2087 changed files with 1208 additions and 3655 deletions
@@ -0,0 +1,669 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
Script.ReloadScript( "Scripts/Entities/Physics/BasicEntity.lua" );
SEQUENCE_NOT_STARTED = 0;
SEQUENCE_PLAYING = 1;
SEQUENCE_STOPPED = 2;
AnimObject =
{
Properties =
{
Animation =
{
Animation = "Default",
Speed = 1,
bLoop = 1,
bPlaying = 1,
bAlwaysUpdate = 0,
playerAnimationState = "",
bPhysicalizeAfterAnimation = 0,
},
Physics =
{
bArticulated = 0,
bRigidBody = 0,
bPushableByPlayers = 0,
bBulletCollisionEnabled = 1,
},
Rendering =
{
bWrinkleMap = 0,
},
Cinematic =
{
bOnDemandModelLoad = 0,
bRenderAlways = 0,
},
ActivatePhysicsThreshold = 0,
ActivatePhysicsDist = 50,
bNoFriendlyFire = 0,
object_Model = "",
MultiplayerOptions =
{
bNetworked = 0,
},
},
PHYSICALIZEAFTER_TIMER = 1,
POSTQL_TIMER = 2,
Client = {},
Server = {},
Editor =
{
Icon = "animobject.bmp",
IconOnTop = 0,
}
};
Net.Expose
{
Class = AnimObject,
ClientMethods =
{
ClEvent_StartAnimation = { RELIABLE_ORDERED, NO_ATTACH, FLOAT, },
ClEvent_ResetAnimation = { RELIABLE_ORDERED, NO_ATTACH, },
ClSync = { RELIABLE_ORDERED, NO_ATTACH, FLOAT, FLOAT, FLOAT, },
},
ServerMethods =
{
SVSync = { RELIABLE_ORDERED, NO_ATTACH, },
},
ServerProperties = {},
};
MakeDerivedEntityOverride( AnimObject,BasicEntity )
function AnimObject:LoadModelOnDemand()
return self.Properties.Cinematic.bOnDemandModelLoad;
end
------------------------------------------------------------------------------------------------------
function AnimObject:SetFromProperties()
self.controllingAnimHere = true;
self.isModelLoaded = false;
self.isRagdollized = false;
self.__super.SetFromProperties(self); -- Call parent function.
self.touchedByFlownode = false;
self.animstarted = 0;
self.sequenceStatus = SEQUENCE_NOT_STARTED;
local Properties = self.Properties;
-- if (Properties.Animation.bPlaying ~= self.bAnimPlaying or Properties.Animation.bLoop ~= self.bAnimLoop or
-- Properties.Animation.Animation ~= self.animName or Properties.Animation.Speed ~= self.animationSpeed) then
self.bAnimPlaying = Properties.Animation.bPlaying;
self.bAnimLoop = Properties.Animation.bLoop;
self.animName = Properties.Animation.Animation;
if (Properties.Animation.bPlaying == 1) then
self:DoStartAnimation();
else
self:ResetAnimation(0, -1);
end
-- end
if (Properties.Animation.bAlwaysUpdate == 1) then
self:Activate(1);
end
self:SetAnimationSpeed( 0, 0, Properties.Animation.Speed )
self.animationSpeed = Properties.Animation.Speed;
self.curAnimTime = 0;
if (self.Properties.ActivatePhysicsThreshold>0) then
local apd = { threshold = self.Properties.ActivatePhysicsThreshold, detach_distance = self.Properties.ActivatePhysicsDist }
self:SetPhysicParams(PHYSICPARAM_AUTO_DETACHMENT, apd);
end
self:CheckShaderParamCallbacks();
end
------------------------------------------------------------------------------------------------------
function AnimObject:SetupModel()
if (self:LoadModelOnDemand()==0 or System.IsEditor()) then
self:LoadAndPhysicalizeModel();
else
Game.CacheResource("AnimObject.lua", self.Properties.object_Model, eGameCacheResourceType_StaticObject, 0);
end
end
-------------------------------------------------------------------------------------------------------
function AnimObject:LoadAndPhysicalizeModel()
if (not self.isModelLoaded) then
self:LoadObject(0,self.Properties.object_Model);
self:RenderAlways(self.Properties.Cinematic.bRenderAlways);
if (self.Properties.Physics.bPhysicalize == 1) then
self:PhysicalizeThis();
end
self.isModelLoaded = true;
return 1;
end
return 0;
end
-------------------------------------------------------------------------------------------------------
function AnimObject:UnloadModel()
if (self.isModelLoaded) then
self:DestroyPhysics();
self:FreeSlot(0);
self.isModelLoaded = false;
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:OnSpawn()
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY,0);
end
self.isRagdollized = false;
self.__super.OnSpawn(self); -- Call parent
if (self.Properties.Animation.bAlwaysUpdate == 1) then
CryAction.CreateGameObjectForEntity(self.id);
CryAction.BindGameObjectToNetwork(self.id);
CryAction.ForceGameObjectUpdate(self.id, true);
self:Activate(1);
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:OnReset()
self.__super.OnReset(self); -- Call parent
self.bAnimPlaying = 0;
self:SetFromProperties();
self.sequenceStatus = SEQUENCE_NOT_STARTED;
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_ResetAnimation()
self.controllingAnimHere = true;
self:ResetAnimation(0, -1);
self.animstarted=0;
--
local PhysProps = self.Properties.Physics;
if( PhysProps.Mass>0 ) then
self:OnReset();
else
self.animName = self.Properties.Animation.Animation;
self:StartAnimation( 0,self.Properties.Animation.Animation,0,0,0,false );
end;
-- net
if( CryAction.IsServer() and self.allClients ) then
self.allClients:ClEvent_ResetAnimation();
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_StartAnimation(sender)
self.controllingAnimHere = true;
self:StartEntityAnimation();
self.animstarted=1;
if( CryAction.IsServer() and self.allClients) then
self.allClients:ClEvent_StartAnimation(CryAction.GetServerTime());
--Log("Server:ClEvent_StartAnimation call"..self:GetName());
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_StopAnimation(sender)
self.controllingAnimHere = true;
if (self.animstarted == 1 and self:IsAnimationRunning(0,0)) then
self.curAnimTime = self:GetAnimationTime(0,0);
else
self.curAnimTime = 0;
end
self:StopAnimation(0, -1); -- all layers
self.animstarted = 0;
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_RagdollizeDerived()
self.isRagdollized = true;
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_ModelLoad()
local justLoaded = self:LoadAndPhysicalizeModel();
if(justLoaded ~= 0) then
self:RelinkAllEntities();
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_ModelUnload()
if (not System.IsEditor()) then
self:UnloadModel();
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_RenderAlwaysEnable()
self:RenderAlways(1);
end
------------------------------------------------------------------------------------------------------
function AnimObject:Event_RenderAlwaysDisable()
self:RenderAlways(0);
end
------------------------------------------------------------------------------------------------------
function AnimObject:DoStartAnimation()
self.animName = self.Properties.Animation.Animation;
self:StartAnimation( 0,self.Properties.Animation.Animation,0,0,self.Properties.Animation.Speed,self.Properties.Animation.bLoop,1 );
self:ForceCharacterUpdate(0, true);
self.animstarted = 1;
-- save curAnimTime for QS/QL
if (self.Properties.Animation.Speed < 0) then
self.curAnimTime = 0;
else
self.curAnimTime = self:GetAnimationLength(0, self.Properties.Animation.Animation);
end
-- local currTime = System.GetCurrTime();
self.startTime = CryAction.GetServerTime();--System.GetCurrAsyncTime();
if( self.timeDiff ) then
self.startTime=self.startTime-self.timeDiff;
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:StartEntityAnimation()
self:StopAnimation(0, -1);
self:DoStartAnimation();
self.bStopAnimAfterQL = false;
self:KillTimer(self.POSTQL_TIMER);
local playerAnimationState = self.Properties.Animation.playerAnimationState;
if (g_localActor and playerAnimationState ~= "") then
g_localActor.actor:CreateCodeEvent(
{
event = "animationControl",pos=self:GetWorldPos(),angle=self:GetWorldAngles()
}
); --,entId=self.id})
g_localActor.actor:QueueAnimationState(playerAnimationState);
if (self.Properties.Animation.bPhysicalizeAfterAnimation == 1) then
local animLen = self:GetAnimationLength(0,self.Properties.Animation.Animation) * 1000.0 / self.Properties.Animation.Speed;
self:SetTimer(self.PHYSICALIZEAFTER_TIMER,animLen);
--Log("timer set to:"..animLen.."ms");
end
end
end
------------------------------------------------------------------------------------------------------
function AnimObject.Client:OnTimer(timerId,mSec)
if (timerId == self.PHYSICALIZEAFTER_TIMER) then
local PhysProps = self.Properties.Physics;
PhysProps.bRigidBodyActive = 1;
PhysProps.bPhysicalize=1;
PhysProps.bRigidBody=1;
PhysProps.bResting = 0;
if (self.bRigidBodyActive ~= PhysProps.bRigidBodyActive) then
self.bRigidBodyActive = PhysProps.bRigidBodyActive;
self:PhysicalizeThis();
end
if (PhysProps.bRigidBody == 1) then
self:AwakePhysics(1-PhysProps.bResting);
self.bRigidBodyActive = PhysProps.bRigidBodyActive;
end
end
if (timerId == self.POSTQL_TIMER and self.sequenceStatus == SEQUENCE_NOT_STARTED) then
self:StopAnimation(0, -1);
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:CorrectTiming(frameTime)
-- local skip = 0;
-- if( skip==0 ) then
if( self.animstarted==1 and self:IsAnimationRunning(0,0) and self.Properties.Animation.Speed>0 ) then
local curTime = CryAction.GetServerTime();--System.GetCurrAsyncTime();
local diffRealTime = (curTime-self.startTime)*self.Properties.Animation.Speed;
local curAnimTime = self:GetAnimationTime(0,0);
if( curAnimTime<=self.curAnimTime ) then
local diff = diffRealTime-curAnimTime;
if( diff<-0.02 ) then
-- correct speed
local frameTimeAnim = self.Properties.Animation.Speed*frameTime;
local reqTime = frameTimeAnim-diff;
local ratio = (frameTimeAnim)/reqTime;
if( ratio<0.5 ) then
-- clamp
ratio=0.5;
end
--
newSpeed = ratio*self.Properties.Animation.Speed;
self:SetAnimationSpeed( 0, 0, newSpeed );
--System.LogToConsole(self:GetName().." RealLess="..diff.." Speed="..newSpeed);
else
if( diff>0.02 ) then
-- correct speed
local frameTimeAnim = self.Properties.Animation.Speed*frameTime;
local reqTime = frameTimeAnim+diff;
local ratio = reqTime/(frameTimeAnim);
if( ratio>1.1 ) then
-- clamp
ratio=1.1;
end
newSpeed = ratio*self.Properties.Animation.Speed;
self:SetAnimationSpeed( 0, 0, newSpeed );
--System.LogToConsole(self:GetName().." RealMore="..diff.." Speed="..newSpeed);
else
-- restore speed
if( self.Properties.Animation.Speed>0 ) then
self:SetAnimationSpeed( 0, 0, self.Properties.Animation.Speed );
end
end
end
end
end
-- end
end
------------------------------------------------------------------------------------------------------
function AnimObject.Server:OnUpdate(dt)
if( CryAction.IsServer() ) then
self:CorrectTiming(dt);
end
end
------------------------------------------------------------------------------------------------------
function AnimObject.Client:OnUpdate(dt)
if( CryAction.IsClient() and not CryAction.IsServer() ) then
self:CorrectTiming(dt);
end
if (self.bStopAnimAfterQL) then
self.bStopAnimAfterQL = false;
self:SetTimer(self.POSTQL_TIMER, 0.2);
if (self.Properties.Animation.bAlwaysUpdate ~= 1) then
self:Activate(0);
end
end
end
-------------------------------------------------------
function AnimObject:OnLoad(table)
local wasRagollized = table.isRagdollized;
if (self.isRagdollized and (not wasRagdollized)) then -- for now we dont care about the oposite situation: the object was ragdollized before the save, and is not ragdollized now.
self:OnReset();
end
--self.__super.OnLoad( self,table ); -- Call parent
self.bAnimPlaying = table.bAnimPlaying;
self.bAnimLoop = table.bAnimLoop;
self.animName = table.animName;
self.animstarted = table.animstarted;
self.health = table.health;
self.dead = table.dead;
self.controllingAnimHere = table.bControllingAnimHere;
-- self.movedByFlowgraph = table.movedByFlowgraph;
if (self.controllingAnimHere) then
if (self.animstarted == 1) then -- restart animation
self:StartEntityAnimation();
self:SetAnimationTime(0, 0, table.animTime);
else
--we have to stop the animation
-- either at the point stored in the file
if (table.animTime > 0) then
if (self.animName~=self.Properties.Animation.Animation) then
self:StartAnimation( 0, self.animName, 0, 0, self.Properties.Animation.Speed,self.Properties.Animation.bLoop,1 );
self:SetAnimationTime(0, 0, table.animTime);
else
self:StartEntityAnimation();
end
self:SetAnimationSpeed( 0, 0, 0.0 );
self:SetAnimationTime(0, 0, table.animTime);
self.bStopAnimAfterQL = true;
self:Activate(1);
self.curAnimTime = table.animTime;
end
if (table.animTime==0) then
local bTouchedByTrackview = (table.sequenceStatus == SEQUENCE_NOT_STARTED and self.sequenceStatus ~= SEQUENCE_NOT_STARTED);
-- this check makes no sense imo. But im not removing it at this time (c3 last weeks) to avoid any risk
if (bTouchedByTrackview or self.touchedByFlownode) then
-- or just at the beginning
self:ResetAnimation(0, -1);
self:StartEntityAnimation();
self:SetAnimationSpeed(0, 0, 0.0);
self:SetAnimationTime(0, 0, 0.0);
self.bStopAnimAfterQL = true;
self:Activate(1);
self.curAnimTime = 0;
end
end
end
else
self.externalAnim_anim = table.externalAnim_anim;
self.externalAnim_layer = table.externalAnim_layer;
self.externalAnim_loop = table.externalAnim_loop;
self:StartAnimation( 0, self.externalAnim_anim, self.externalAnim_layer, 0, 1, self.externalAnim_loop );
self:SetAnimationTime(0, self.externalAnim_layer, table.animTime);
end
self.touchedByFlownode = false;
-- physicalized ones that are neither articulated neither rigidbody become static. Static physical entities are not serialized at all. So we just rephysicallize in that case.
if (self.Properties.Physics.bArticulated==0 and self.Properties.Physics.bRigidBody==0 and self.Properties.Physics.bPhysicalize==1) then
self:PhysicalizeThis();
end
self.sequenceStatus = table.sequenceStatus;
end
-------------------------------------------------------
function AnimObject:OnSave(table)
table.isRagdollized = self.isRagdollized;
table.bAnimPlaying = self.bAnimPlaying
table.bAnimLoop = self.bAnimLoop
table.animName = self.animName
table.sequenceStatus = self.sequenceStatus;
table.health = self.health;
table.dead = self.dead;
table.bControllingAnimHere = self.controllingAnimHere;
if (self.controllingAnimHere) then
if (self.animstarted == 1 and self:IsAnimationRunning(0,0)) then
table.animTime = self:GetAnimationTime(0,0);
table.animstarted = 1;
else
table.animstarted = 0;
if (self.curAnimTime) then
table.animTime = self.curAnimTime;
else
table.animTime = 0;
end
end
else
table.externalAnim_anim = self.externalAnim_anim;
table.externalAnim_layer = self.externalAnim_layer;
table.externalAnim_loop = self.externalAnim_loop;
table.animTime = self:GetAnimationTime(0,self.externalAnim_layer);
end
end
------------------------------------------------------------------------------------------------------
-- Additional Flow events.
------------------------------------------------------------------------------------------------------
AnimObject.FlowEvents.Inputs.ResetAnimation = { AnimObject.Event_ResetAnimation, "bool" }
AnimObject.FlowEvents.Inputs.StartAnimation = { AnimObject.Event_StartAnimation, "bool" }
AnimObject.FlowEvents.Inputs.StopAnimation = { AnimObject.Event_StopAnimation, "bool" }
AnimObject.FlowEvents.Inputs.ModelLoad = { AnimObject.Event_ModelLoad, "bool" }
AnimObject.FlowEvents.Inputs.ModelUnload = { AnimObject.Event_ModelUnload, "bool" }
-- client functions
function AnimObject.Client:ClEvent_StartAnimation(servertime)
--Log("ClEvent_StartAnimation recieved"..self:GetName());
self.timeDiff = CryAction.GetServerTime()-servertime;
-- local localDiff = System.GetCurrTime()-servertime;
-- if( self.timeDiff>0.1 ) then
-- System.LogToConsole(self:GetName().." Diff="..self.timeDiff.." localDiff="..localDiff);
-- else
-- if( self.timeDiff<-0.1 ) then
-- System.LogToConsole(self:GetName().." Diff="..self.timeDiff);
-- end
-- end
if( not CryAction.IsServer() ) then
self:Event_StartAnimation();
end
end
function AnimObject.Client:ClEvent_ResetAnimation()
if( not CryAction.IsServer() ) then
self:Event_ResetAnimation();
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:SavePhysicalState()
self.initPos = self:GetPos();
self.initRot = self:GetWorldAngles();
self.initScale = self:GetScale();
end
function AnimObject:RestorePhysicalState()
self:SetPos(self.initPos);
self:SetWorldAngles(self.initRot);
self:SetScale(self.initScale);
-- restore
self:ResetAnimation(0, -1);
self.animstarted=0;
local PhysProps = self.Properties.Physics;
if( PhysProps.Mass>0 ) then
self:OnReset();
else
self.animName = self.Properties.Animation.Animation;
self:StartAnimation( 0,self.Properties.Animation.Animation,0,0,0,false );
end;
end
------------------------------------------------------------------------------------------------------
function AnimObject:PhysicalizeThis()
BasicEntity.PhysicalizeThis(self);
-- Remove bullet collision if desired
local Physics = self.Properties.Physics;
if (Physics.bBulletCollisionEnabled == 0) then
local flagstab = { flags_mask= geom_colltype_ray + geom_colltype_foliage_proxy, flags=geom_colltype_player*Physics.bPushableByPlayers };
self:SetPhysicParams(PHYSICPARAM_PART_FLAGS, flagstab);
end
end
------------------------------------------------------------------------------------------------------
function AnimObject:SendSyncToClient( channelId )
if( self.animstarted==1 ) then
animTime = self:GetAnimationTime(0,0);
self.onClient:ClSync( channelId, animTime, self.startTime, CryAction.GetServerTime() )
end
end
function AnimObject.Server:OnPostInitClient( channelId )
self:SendSyncToClient(channelId);
end
function AnimObject.Server:SVSync(channelId)
self:SendSyncToClient(channelId);
end
function AnimObject.Client:ClSync( animTimeValue, startTimeValue, serverTimeValue )
-- if( self.animstarted==0 ) then
--self:Event_ResetAnimation();
--self.timeDiff = CryAction.GetServerTime()-serverTimeValue;
self:StartEntityAnimation();
self.startTime = startTimeValue;
self:SetAnimationTime(0,0,animTimeValue);
--Log("CLSync recieved"..self:GetName()..animTimeValue);
-- end
end
function AnimObject:UpdateFromServer()
self.server:SVSync();
end
-- notifications from PlaySequence FG node (entire sequence starts/stops)
function AnimObject:OnSequenceStart()
self.sequenceStatus = SEQUENCE_PLAYING;
end
function AnimObject:OnSequenceStop()
self.sequenceStatus = SEQUENCE_STOPPED;
end
-- Notifications from trackview (animation in sequence starts/stops)
function AnimObject:OnSequenceAnimationStart( animName )
self.sequenceStatus = SEQUENCE_PLAYING;
self.animName = animName;
end
function AnimObject:OnSequenceAnimationStop()
self.sequenceStatus = SEQUENCE_STOPPED;
end
function AnimObject:OnFlowGraphAnimationStart( animName, layer, loop )
self.animName = animName;
self.externalAnim_anim = animName;
self.controllingAnimHere = false;
self.externalAnim_layer = layer;
self.externalAnim_loop = loop;
self.touchedByFlownode = true;
end
function AnimObject:OnFlowGraphAnimationStop()
if (self.externalAnim_layer) then
self.curAnimTime = self:GetAnimationTime(0, self.externalAnim_layer);
end
self.controllingAnimHere = true;
end
function AnimObject:OnFlowGraphAnimationEnd()
self.curAnimTime = 1; -- is a normalized time, so 1 == end
self.controllingAnimHere = true;
end
@@ -0,0 +1,99 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
AreaBezierVolume = {
type = "AreaBezierVolume",
Properties =
{
bEnabled = 1,
MultiplayerOptions = {
bNetworked = 0,
},
},
}
-------------------------------------------------------------------------------------------------------
function AreaBezierVolume:OnSpawn()
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY,0);
end
end
-------------------------------------------------------
function AreaBezierVolume:OnLoad(table)
self.bEnabled = table.bEnabled
if(self.bEnabled == 1) then
self:Event_Enable();
else
self:Event_Disable();
end
end
-------------------------------------------------------
function AreaBezierVolume:OnSave(table)
table.bEnabled = self.bEnabled
end
-------------------------------------------------------
function AreaBezierVolume:OnInit()
if(self.Properties.bEnabled == 1) then
self:Event_Enable();
else
self:Event_Disable();
end
end
function AreaBezierVolume:OnPropertyChange()
if(self.Properties.bEnabled == 1) then
self:Event_Enable();
else
self:Event_Disable();
end
end
-------------------------------------------------------
function AreaBezierVolume:OnEnable(enable)
--Log("AreaBezierVolume:OnEnable");
self:SetPhysicParams(PHYSICPARAM_FOREIGNDATA,{foreignData = ZEROG_AREA_ID});
end
-------------------------------------------------------
function AreaBezierVolume:Event_Enable()
--self:TriggerEvent(AIEVENT_ENABLE);
self.bEnabled = 1;
BroadcastEvent(self, "Enable");
end
-------------------------------------------------------
function AreaBezierVolume:Event_Disable()
--self:TriggerEvent(AIEVENT_DISABLE);
self.bEnabled = 0;
BroadcastEvent(self, "Disable");
end
AreaBezierVolume.FlowEvents =
{
Inputs =
{
Disable = { AreaBezierVolume.Event_Disable, "bool" },
Enable = { AreaBezierVolume.Event_Enable, "bool" },
},
Outputs =
{
Disable = "bool",
Enable = "bool",
},
}
@@ -0,0 +1,269 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
Script.ReloadScript("scripts/Utils/EntityUtils.lua")
-- Basic entity
BasicEntity = {
Properties = {
soclasses_SmartObjectClass = "",
--bAutoGenAIHidePts = 0,
bMissionCritical = 0,
bCanTriggerAreas = 0,
DmgFactorWhenCollidingAI = 1,
object_Model = "objects/default/primitive_sphere.cgf",
Physics = {
bPhysicalize = 1, -- True if object should be physicalized at all.
bRigidBody = 1, -- True if rigid body, False if static.
bPushableByPlayers = 1,
Density = -1,
Mass = -1,
},
MultiplayerOptions = {
bNetworked = 0,
},
bExcludeCover=0,
},
Client = {},
Server = {},
-- Temp.
_Flags = {},
Editor={
Icon = "physicsobject.bmp",
IconOnTop=1,
},
}
local Physics_DX9MP_Simple = {
bPhysicalize = 1, -- True if object should be physicalized at all.
bPushableByPlayers = 0,
Density = 0,
Mass = 0,
}
------------------------------------------------------------------------------------------------------
function BasicEntity:OnSpawn()
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY,0);
end
self.bRigidBodyActive = 1;
self:SetFromProperties();
end
------------------------------------------------------------------------------------------------------
function BasicEntity:SetFromProperties()
local Properties = self.Properties;
if (Properties.object_Model == "") then
do return end;
end
self.freezable = (tonumber(Properties.bFreezable) ~= 0);
self:SetupModel();
-- Mark AI hideable flag.
if (Properties.bAutoGenAIHidePts == 1) then
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 0); -- set
else
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 2); -- remove
end
if (self.Properties.bCanTriggerAreas == 1) then
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 0); -- set
else
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 2); -- remove
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity:SetupModel()
local Properties = self.Properties;
self:LoadObject(0,Properties.object_Model);
if (Properties.Physics.bPhysicalize == 1) then
self:PhysicalizeThis();
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity:OnLoad(table)
self.health = table.health;
self.dead = table.dead;
end
function BasicEntity:OnSave(table)
table.health = self.health;
table.dead = self.dead;
end
------------------------------------------------------------------------------------------------------
function BasicEntity:IsRigidBody()
local Properties = self.Properties;
local Mass = Properties.Mass;
local Density = Properties.Density;
if (Mass == 0 or Density == 0 or Properties.bPhysicalize ~= 1) then
return false;
end
return true;
end
------------------------------------------------------------------------------------------------------
function BasicEntity:PhysicalizeThis()
-- Init physics.
local Physics = self.Properties.Physics;
if (CryAction.IsImmersivenessEnabled() == 0) then
Physics = Physics_DX9MP_Simple;
end
EntityCommon.PhysicalizeRigid( self,0,Physics,self.bRigidBodyActive );
end
------------------------------------------------------------------------------------------------------
-- OnPropertyChange called only by the editor.
------------------------------------------------------------------------------------------------------
function BasicEntity:OnPropertyChange()
-- if the properties are changed, we force a reset in the __usable
if (self.__usable) then
if (self.__origUsable ~= self.Properties.bUsable or self.__origPickable ~= self.Properties.bPickable) then
self.__usable = nil;
end
end
self:SetFromProperties();
end
------------------------------------------------------------------------------------------------------
-- OnReset called only by the editor.
------------------------------------------------------------------------------------------------------
function BasicEntity:OnReset()
self:ResetOnUsed()
local PhysProps = self.Properties.Physics;
if (PhysProps.bPhysicalize == 1) then
self:PhysicalizeThis();
self:AwakePhysics(0);
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity:Event_Remove()
self:DrawSlot(0,0);
self:DestroyPhysics();
self:ActivateOutput( "Remove", true );
end
------------------------------------------------------------------------------------------------------
function BasicEntity:Event_Hide()
self:Hide(1);
self:ActivateOutput( "Hide", true );
if CurrentCinematicName then
Log("%.3f %s %s : Event_Hide", _time, CurrentCinematicName, self:GetName() );
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity:Event_UnHide()
self:Hide(0);
self:ActivateOutput( "UnHide", true );
if CurrentCinematicName then
Log("%.3f %s %s : Event_UnHide", _time, CurrentCinematicName, self:GetName() );
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity:Event_Ragdollize()
self:RagDollize(0);
self:ActivateOutput( "Ragdollized", true );
if (self.Event_RagdollizeDerived) then
self:Event_RagdollizeDerived();
end
end
------------------------------------------------------------------------------------------------------
function BasicEntity.Client:OnPhysicsBreak( vPos,nPartId,nOtherPartId )
self:ActivateOutput("Break",nPartId+1 );
end
function BasicEntity:IsUsable(user)
local ret = nil
-- From EntityUtils.lua
if not self.__usable then self.__usable = self.Properties.bUsable end
local mp = System.IsMultiplayer();
if(mp and mp~=0) then
return 0;
end
if (self.__usable == 1) then
ret = 2
else
local PhysProps = self.Properties.Physics;
if (self:IsRigidBody() == true and user and user.CanGrabObject) then
ret = user:CanGrabObject(self)
end
end
return ret or 0
end
BasicEntity.FlowEvents =
{
Inputs =
{
Used = { BasicEntity.Event_Used, "bool" },
EnableUsable = { BasicEntity.Event_EnableUsable, "bool" },
DisableUsable = { BasicEntity.Event_DisableUsable, "bool" },
Hide = { BasicEntity.Event_Hide, "bool" },
UnHide = { BasicEntity.Event_UnHide, "bool" },
Remove = { BasicEntity.Event_Remove, "bool" },
Ragdollize = { BasicEntity.Event_Ragdollize, "bool" },
},
Outputs =
{
Used = "bool",
EnableUsable = "bool",
DisableUsable = "bool",
Activate = "bool",
Hide = "bool",
UnHide = "bool",
Remove = "bool",
Ragdollized = "bool",
Break = "int",
},
}
MakeUsable(BasicEntity);
MakePickable(BasicEntity);
MakeTargetableByAI(BasicEntity);
MakeKillable(BasicEntity);
AddHeavyObjectProperty(BasicEntity);
AddInteractLargeObjectProperty(BasicEntity);
SetupCollisionFiltering(BasicEntity);
@@ -0,0 +1,276 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
Script.ReloadScript("scripts/Utils/EntityUtils.lua")
-- Basic entity
LivingEntity = {
Properties = {
soclasses_SmartObjectClass = "",
bMissionCritical = 0,
bCanTriggerAreas = 1,
DmgFactorWhenCollidingAI = 1,
object_Model = "objects/default/primitive_capsule.cgf",
Physics = {
bPhysicalize = 1, -- True if object should be physicalized at all.
bPushableByPlayers = 1,
},
Living = {
height = 0, -- vertical offset of collision geometry center
vector_size = {0.4, 0.4,0.9}, -- collision cylinder dimensions
height_eye = 1.8, -- vertical offset of camera
height_pivot = 0.1, -- offset from central ground position that is considered entity center
head_radius = 0.3, -- radius of the 'head' geometry (used for camera offset)
height_head = 1.7, -- center.z of the head geometry
groundContactEps = 0.004, --the amount that the living needs to move upwards before ground contact is lost. defaults to which ever is greater 0.004, or 0.01*geometryHeight
bUseCapsule = 1,--switches between capsule and cylinder collider geometry
inertia = 1, -- inertia koefficient, the more it is, the less inertia is, 0 means no inertia
inertiaAccel = 1, -- inertia on acceleration
air_control = 1, -- air control koefficient 0..1, 1 - special value (total control of movement)
air_resistance = 0.1, -- standard air resistance
gravity = 9.8, -- gravity vector
mass = 100, -- mass (in kg)
min_slide_angle = 60, -- if surface slope is more than this angle, player starts sliding (angle is in radians)
max_climb_angle = 60, -- player cannot climb surface which slope is steeper than this angle
max_jump_angle = 45, -- player is not allowed to jump towards ground if this angle is exceeded
min_fall_angle = 65, -- player starts falling when slope is steeper than this
max_vel_ground = 10, -- player cannot stand of surfaces that are moving faster than this
timeImpulseRecover = 0.3, -- forcefully turns on inertia for that duration after receiving an impulse
nod_speed = 1, -- vertical camera shake speed after landings
bActive = 1,-- 0 disables all simulation for the character, apart from moving along the requested velocity
collision_types = 271, -- (271 = ent_static | ent_terrain | ent_living | ent_rigid | ent_sleeping_rigid) entity types to check collisions against
},
MultiplayerOptions = {
bNetworked = 0,
},
bExcludeCover=0,
},
Client = {},
Server = {},
-- Temp.
_Flags = {},
Editor={
Icon = "physicsobject.bmp",
IconOnTop=1,
},
}
------------------------------------------------------------------------------------------------------
function LivingEntity:OnSpawn()
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY,0);
end
self:SetFromProperties();
end
------------------------------------------------------------------------------------------------------
function LivingEntity:SetFromProperties()
local Properties = self.Properties;
if (Properties.object_Model == "") then
do return end;
end
self.freezable = (tonumber(Properties.bFreezable) ~= 0);
self:SetupModel();
-- Mark AI hideable flag.
if (Properties.bAutoGenAIHidePts == 1) then
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 0); -- set
else
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 2); -- remove
end
if (self.Properties.bCanTriggerAreas == 1) then
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 0); -- set
else
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 2); -- remove
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity:SetupModel()
local Properties = self.Properties;
self:LoadObject(0,Properties.object_Model);
if (Properties.Physics.bPhysicalize == 1) then
self:PhysicalizeThis();
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity:OnLoad(table)
self.health = table.health;
self.dead = table.dead;
end
function LivingEntity:OnSave(table)
table.health = self.health;
table.dead = self.dead;
end
------------------------------------------------------------------------------------------------------
function LivingEntity:IsRigidBody()
local Properties = self.Properties;
local Mass = Properties.Mass;
local Density = Properties.Density;
if (Mass == 0 or Density == 0 or Properties.bPhysicalize ~= 1) then
return false;
end
return true;
end
------------------------------------------------------------------------------------------------------
function LivingEntity:PhysicalizeThis()
Entity.Physicalize(self,0, PE_LIVING, self.Properties);
end
------------------------------------------------------------------------------------------------------
-- OnPropertyChange called only by the editor.
------------------------------------------------------------------------------------------------------
function LivingEntity:OnPropertyChange()
-- if the properties are changed, we force a reset in the __usable
if (self.__usable) then
if (self.__origUsable ~= self.Properties.bUsable or self.__origPickable ~= self.Properties.bPickable) then
self.__usable = nil;
end
end
self:SetFromProperties();
end
------------------------------------------------------------------------------------------------------
-- OnReset called only by the editor.
------------------------------------------------------------------------------------------------------
function LivingEntity:OnReset()
self:ResetOnUsed()
local PhysProps = self.Properties.Physics;
if (PhysProps.bPhysicalize == 1) then
self:PhysicalizeThis();
self:AwakePhysics(0);
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity:Event_Remove()
self:DrawSlot(0,0);
self:DestroyPhysics();
self:ActivateOutput( "Remove", true );
end
------------------------------------------------------------------------------------------------------
function LivingEntity:Event_Hide()
self:Hide(1);
self:ActivateOutput( "Hide", true );
if CurrentCinematicName then
Log("%.3f %s %s : Event_Hide", _time, CurrentCinematicName, self:GetName() );
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity:Event_UnHide()
self:Hide(0);
self:ActivateOutput( "UnHide", true );
if CurrentCinematicName then
Log("%.3f %s %s : Event_UnHide", _time, CurrentCinematicName, self:GetName() );
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity:Event_Ragdollize()
self:RagDollize(0);
self:ActivateOutput( "Ragdollized", true );
if (self.Event_RagdollizeDerived) then
self:Event_RagdollizeDerived();
end
end
------------------------------------------------------------------------------------------------------
function LivingEntity.Client:OnPhysicsBreak( vPos,nPartId,nOtherPartId )
self:ActivateOutput("Break",nPartId+1 );
end
function LivingEntity:IsUsable(user)
local ret = nil
-- From EntityUtils.lua
if not self.__usable then self.__usable = self.Properties.bUsable end
local mp = System.IsMultiplayer();
if(mp and mp~=0) then
return 0;
end
if (self.__usable == 1) then
ret = 2
else
local PhysProps = self.Properties.Physics;
if (self:IsRigidBody() == true and user and user.CanGrabObject) then
ret = user:CanGrabObject(self)
end
end
return ret or 0
end
LivingEntity.FlowEvents =
{
Inputs =
{
Used = { LivingEntity.Event_Used, "bool" },
EnableUsable = { LivingEntity.Event_EnableUsable, "bool" },
DisableUsable = { LivingEntity.Event_DisableUsable, "bool" },
Hide = { LivingEntity.Event_Hide, "bool" },
UnHide = { LivingEntity.Event_UnHide, "bool" },
Remove = { LivingEntity.Event_Remove, "bool" },
Ragdollize = { LivingEntity.Event_Ragdollize, "bool" },
},
Outputs =
{
Used = "bool",
EnableUsable = "bool",
DisableUsable = "bool",
Activate = "bool",
Hide = "bool",
UnHide = "bool",
Remove = "bool",
Ragdollized = "bool",
Break = "int",
},
}
MakeUsable(LivingEntity);
MakePickable(LivingEntity);
MakeTargetableByAI(LivingEntity);
MakeKillable(LivingEntity);
AddHeavyObjectProperty(LivingEntity);
AddInteractLargeObjectProperty(LivingEntity);
SetupCollisionFiltering(LivingEntity);
@@ -0,0 +1,392 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
Script.ReloadScript( "Scripts/Entities/Physics/BasicEntity.lua" );
-- Basic entity
RigidBodyEx = {
Properties = {
bSerialize = 0, --by default rigid bodies are not being serialized (save/load)
bDamagesPlayerOnCollisionSP = 0,
AI = {
-- This value is currently used for the MNM Navigation System
bUsedAsDynamicObstacle = 1,
},
Physics = {
bRigidBodyActive = 1,
bActivateOnDamage = 0,
bResting = 1, -- If rigid body is originally in resting state.
bCanBreakOthers = 0,
Simulation =
{
max_time_step = 0.02,
sleep_speed = 0.04,
damping = 0,
bFixedDamping = 0,
bUseSimpleSolver = 0,
},
Buoyancy=
{
water_density = 1000,
water_damping = 0,
water_resistance = 1000,
},
CGFPropsOverride =
{
Joint =
{
limit = "",
twist = "",
bend = "",
push = "",
pull = "",
shift = "",
},
Constraint =
{
constraint_limit = "",
constraint_minang = "",
constraint_maxang = "",
constraint_damping = "",
constraint_collides = "",
},
Deformable =
{
stiffness = "",
thickness = "",
max_stretch = "",
max_impulse = "",
skin_dist = "",
hardness = "",
explosion_scale = "",
},
player_can_break = "",
},
ForeignData =
{
bMovingPlatform = 0,
},
},
MultiplayerOptions = {
bNetworked = 0,
},
},
Editor={
Icon = "physicsobject.bmp",
IconOnTop=1,
},
States = {"Default","Activated"},
bRigidBodyActive = 1,
}
local Physics_DX9MP_Simple = {
bRigidBodyActive = 0,
bActivateOnDamage = 0,
bResting = 1, -- If rigid body is originally in resting state.
Simulation =
{
max_time_step = 0.02,
sleep_speed = 0.04,
damping = 0,
bFixedDamping = 0,
bUseSimpleSolver = 0,
},
Buoyancy=
{
water_density = 1000,
water_damping = 0,
water_resistance = 1000,
},
}
MakeDerivedEntity( RigidBodyEx,BasicEntity )
-------------------------------------------------------
function RigidBodyEx:OnLoad(table)
self.bRigidBodyActive = table.bRigidBodyActive;
self.health = table.health;
self.dead = table.dead;
self.broken = table.broken;
end
-------------------------------------------------------
function RigidBodyEx:OnSave(table)
table.bRigidBodyActive = self.bRigidBodyActive
table.health = self.health;
table.dead = self.dead;
table.broken = self.broken;
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:OnSpawn()
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY,0);
end
if (self.Properties.Physics.bRigidBodyActive == 1) then
self.bRigidBodyActive = 1;
end
self:SetFromProperties();
self:SetupHealthProperties();
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:SetFromProperties()
local Properties = self.Properties;
if (Properties.object_Model == "") then
do return end;
end
self:LoadObject(0,Properties.object_Model);
self:CharacterUpdateOnRender(0,1); -- If it is a character force it to update on render.
-- Enabling drawing of the slot.
self:DrawSlot(0,1);
self.bRigidBodyActive = Properties.Physics.bRigidBodyActive;
if (Properties.Physics.bPhysicalize == 1) then
self:PhysicalizeThis();
else
local params = {};
self:Physicalize(0,PE_NONE,params);
end
self:GotoState("Default");
-- Mark AI hideable flag.
if (self.Properties.bAutoGenAIHidePts == 1) then
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 0); -- set
else
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 2); -- remove
end
if (self.Properties.bCanTriggerAreas == 1) then
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 0); -- set
else
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 2); -- remove
end
self.broken = 0;
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:PhysicalizeThis()
-- Init physics.
local physics = self.Properties.Physics;
if (CryAction.IsImmersivenessEnabled() == 0) then
physics = Physics_DX9MP_Simple;
end
EntityCommon.PhysicalizeRigid( self,0,physics,self.bRigidBodyActive );
end
------------------------------------------------------------------------------------------------------
-- OnPropertyChange called only by the editor.
------------------------------------------------------------------------------------------------------
function RigidBodyEx:OnPropertyChange()
self:SetFromProperties();
end
------------------------------------------------------------------------------------------------------
-- OnReset called only by the editor.
------------------------------------------------------------------------------------------------------
function RigidBodyEx:OnReset()
self:ResetOnUsed()
local PhysProps = self.Properties.Physics;
if (PhysProps.bPhysicalize == 1) then
if (self:IsInState("Default") ~= 0) then
self:AwakePhysics(1-self.Properties.Physics.bResting);
end
self:GotoState("Default");
end
self:SetupHealthProperties();
self.broken = 0;
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_Remove()
self:DrawSlot(0,0);
self:DestroyPhysics();
self:ActivateOutput( "Remove", true );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_Hide()
self:Hide(1);
self:ActivateOutput( "Hide", true );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_UnHide()
self:Hide(0);
self:ActivateOutput( "UnHide", true );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_Ragdollize()
self:RagDollize(0);
self:ActivateOutput( "Ragdollized", true );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:OnPhysicsBreak( vPos,nPartId,nOtherPartId )
self:ActivateOutput("Break",nPartId+1 );
self.broken = 1;
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:OnDamage( hit )
if (self:IsARigidBody() == 1) then
if (self.Properties.Physics.bActivateOnDamage == 1) then
if (hit.explosion and self:GetState()~="Activated") then
BroadcastEvent(self, "Activate");
self:GotoState("AcTivated");
end
end
end
if( hit.ipart and hit.ipart>=0 ) then
self:AddImpulse( hit.ipart, hit.pos, hit.dir, hit.impact_force_mul );
end
end
function RigidBodyEx:IsUsable(user)
local canBeUsed = 0;
if(self.broken == 0) then
if (self.Properties.bUsable==1 or self.Properties.bPickable==1) then
canBeUsed = 1;
end
else
canBeUsed = self.Properties.bUsable;
end
return canBeUsed;
end
------------------------------------------------------------------------------------------------------
-- Input events
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_Activate(sender)
self:GotoState("Activated");
end
------------------------------------------------------------------------------------------------------
-- Events to switch material Applied to object.
------------------------------------------------------------------------------------------------------
function RigidBodyEx:CommonSwitchToMaterial( numStr )
if (not self.sOriginalMaterial) then
self.sOriginalMaterial = self:GetMaterial();
end
if (self.sOriginalMaterial) then
--System.Log( "Material: "..self.sOriginalMaterial..numStr );
self:SetMaterial( self.sOriginalMaterial..numStr );
end
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_SwitchToMaterialOriginal(sender)
self:CommonSwitchToMaterial( "" );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_SwitchToMaterial1(sender)
self:CommonSwitchToMaterial( "1" );
end
------------------------------------------------------------------------------------------------------
function RigidBodyEx:Event_SwitchToMaterial2(sender)
self:CommonSwitchToMaterial( "2" );
end
------------------------------------------------------------------------------------------------------
-- Defaul state.
------------------------------------------------------------------------------------------------------
RigidBodyEx.Server.Default =
{
OnBeginState = function(self)
if (self.Properties.Physics.bRigidBody==1) then
if (self.bRigidBodyActive~=self.Properties.Physics.bRigidBodyActive) then
self.bRigidBodyActive = self.Properties.Physics.bRigidBodyActive;
self:PhysicalizeThis();
else
self:AwakePhysics(1-self.Properties.Physics.bResting);
end
end
end,
OnDamage = RigidBodyEx.OnDamage,
OnPhysicsBreak = RigidBodyEx.OnPhysicsBreak,
}
------------------------------------------------------------------------------------------------------
-- Activated state.
------------------------------------------------------------------------------------------------------
RigidBodyEx.Server.Activated =
{
OnBeginState = function(self)
if (self.Properties.Physics.bRigidBody==1 and self.bRigidBodyActive==0) then
self.bRigidBodyActive = 1;
self:PhysicalizeThis();
self:AwakePhysics(1);
end
end,
OnDamage = RigidBodyEx.OnDamage,
OnPhysicsBreak = RigidBodyEx.OnPhysicsBreak,
}
RigidBodyEx.FlowEvents =
{
Inputs =
{
Used = { RigidBodyEx.Event_Used, "bool" },
EnableUsable = { RigidBodyEx.Event_EnableUsable, "bool" },
DisableUsable = { RigidBodyEx.Event_DisableUsable, "bool" },
Activate = { RigidBodyEx.Event_Activate, "bool" },
Hide = { RigidBodyEx.Event_Hide, "bool" },
UnHide = { RigidBodyEx.Event_UnHide, "bool" },
Remove = { RigidBodyEx.Event_Remove, "bool" },
Ragdollize = { RigidBodyEx.Event_Ragdollize, "bool" },
SwitchToMaterial1 = { RigidBodyEx.Event_SwitchToMaterial1, "bool" },
SwitchToMaterial2 = { RigidBodyEx.Event_SwitchToMaterial2, "bool" },
SwitchToMaterialOriginal = { RigidBodyEx.Event_SwitchToMaterialOriginal, "bool" },
ResetHealth = { RigidBodyEx.Event_ResetHealth, "any" },
MakeVulnerable = { RigidBodyEx.Event_MakeVulnerable, "any" },
MakeInvulnerable = { RigidBodyEx.Event_MakeInvulnerable, "any" },
},
Outputs =
{
Used = "bool",
EnableUsable = "bool",
DisableUsable = "bool",
Activate = "bool",
Hide = "bool",
UnHide = "bool",
Remove = "bool",
Ragdollized = "bool",
Break = "int",
Dead = "bool",
Hit = "bool",
Health = "float",
},
}