initial
This commit is contained in:
406
movieobjects/_vpc_/manifest_movieobjects/win32/manifest.txt
Normal file
406
movieobjects/_vpc_/manifest_movieobjects/win32/manifest.txt
Normal file
@@ -0,0 +1,406 @@
|
||||
// ----------------------------------------- //
|
||||
// File generated by VPC //
|
||||
// ----------------------------------------- //
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\collisionutils.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\collisionutils.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\collisionutils.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationlist.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationlist.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationlist.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationset.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationset.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeanimationset.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeattachment.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeattachment.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeattachment.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeattributereference.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeattributereference.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeattributereference.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeaxissystem.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeaxissystem.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeaxissystem.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmebookmark.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmebookmark.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmebookmark.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmecamera.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmecamera.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmecamera.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmechannel.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmechannel.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmechannel.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeclip.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeclip.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeclip.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmecombinationoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmecombinationoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmecombinationoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeconnectionoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeconnectionoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeconnectionoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmecontrolgroup.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmecontrolgroup.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmecontrolgroup.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmedag.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmedag.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmedag.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmedccmakefile.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmedccmakefile.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmedccmakefile.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmedrawsettings.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmedrawsettings.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmedrawsettings.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeeditortypedictionary.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeeditortypedictionary.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeeditortypedictionary.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeexporttags.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeexporttags.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeexporttags.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeexpressionoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeexpressionoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeexpressionoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmefaceset.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmefaceset.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmefaceset.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeflexrules.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeflexrules.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeflexrules.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmegamemodel.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmegamemodel.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmegamemodel.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeinput.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeinput.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeinput.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmejoint.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmejoint.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmejoint.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmekeyboardinput.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmekeyboardinput.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmekeyboardinput.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmelight.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmelight.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmelight.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmelog.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmelog.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmelog.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefile.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefile.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefile.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefileutils.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefileutils.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemakefileutils.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmematerial.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmematerial.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmematerial.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmematerialoverlayfxclip.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmematerialoverlayfxclip.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmematerialoverlayfxclip.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemdl.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemdl.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemdl.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemdlmakefile.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemdlmakefile.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemdlmakefile.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemesh.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemesh.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemesh.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemodel.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemodel.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemodel.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemorphoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemorphoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemorphoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmemouseinput.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmemouseinput.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmemouseinput.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeoverlay.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeoverlay.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeoverlay.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmepackoperators.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmepackoperators.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmepackoperators.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeparticlesystemdefinition.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeparticlesystemdefinition.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeparticlesystemdefinition.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmephonememapping.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmephonememapping.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmephonememapping.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmerig.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmerig.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmerig.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmerigconstraintoperators.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmerigconstraintoperators.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmerigconstraintoperators.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmerighandle.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmerighandle.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmerighandle.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeselection.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeselection.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeselection.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeshape.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeshape.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeshape.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmesound.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmesound.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmesound.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeframe.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeframe.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeframe.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeselection.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeselection.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetimeselection.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetrack.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetrack.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetrack.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetrackgroup.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetrackgroup.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetrackgroup.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetransform.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransform.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransform.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformcontrol.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformcontrol.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformcontrol.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetransforminput.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransforminput.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransforminput.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformlist.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformlist.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformlist.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformoperator.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformoperator.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmetransformoperator.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeunpackoperators.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeunpackoperators.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeunpackoperators.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmeusersettings.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmeusersettings.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmeusersettings.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmevertexdata.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmevertexdata.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmevertexdata.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmmeshcomp.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmmeshcomp.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmmeshcomp.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\dmobjserializer.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\dmobjserializer.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\dmobjserializer.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\exportfacialanimation.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\exportfacialanimation.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\exportfacialanimation.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\movieobjects\movieobjects_interfaces.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\movieobjects\movieobjects_interfaces.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\movieobjects\movieobjects_interfaces.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
68
movieobjects/dmeanimationlist.cpp
Normal file
68
movieobjects/dmeanimationlist.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// An element that contains a list of animations
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeanimationlist.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAnimationList, CDmeAnimationList );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAnimationList::OnConstruction()
|
||||
{
|
||||
m_Animations.Init( this, "animations" );
|
||||
}
|
||||
|
||||
void CDmeAnimationList::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds, removes animations
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeAnimationList::AddAnimation( CDmeChannelsClip *pAnimation )
|
||||
{
|
||||
return m_Animations.AddToTail( pAnimation );
|
||||
}
|
||||
|
||||
void CDmeAnimationList::RemoveAnimation( int nIndex )
|
||||
{
|
||||
m_Animations.Remove( nIndex );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the transform
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAnimationList::SetAnimation( int nIndex, CDmeChannelsClip *pAnimation )
|
||||
{
|
||||
m_Animations.Set( nIndex, pAnimation );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds an animation by name
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeAnimationList::FindAnimation( const char *pAnimName )
|
||||
{
|
||||
int nCount = m_Animations.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( m_Animations[i]->GetName(), pAnimName ) )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
1721
movieobjects/dmeanimationset.cpp
Normal file
1721
movieobjects/dmeanimationset.cpp
Normal file
File diff suppressed because it is too large
Load Diff
123
movieobjects/dmeattachment.cpp
Normal file
123
movieobjects/dmeattachment.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Dme version of a model attachment point
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeattachment.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier1/keyvalues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statics
|
||||
//-----------------------------------------------------------------------------
|
||||
IMaterial *CDmeAttachment::sm_pMatAttachment = NULL;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAttachment, CDmeAttachment );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAttachment::OnConstruction()
|
||||
{
|
||||
m_bIsRigid.Init( this, "isRigid" );
|
||||
m_bIsWorldAligned.Init( this, "isWorldAligned" );
|
||||
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
if ( !sm_pMatAttachment )
|
||||
{
|
||||
KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
|
||||
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
|
||||
pVMTKeyValues->SetInt( "$ignorez", 0 );
|
||||
sm_pMatAttachment = g_pMaterialSystem->CreateMaterial( "__DmeAttachment", pVMTKeyValues );
|
||||
if ( sm_pMatAttachment )
|
||||
{
|
||||
m_MatRefAttachment.Init( sm_pMatAttachment );
|
||||
sm_pMatAttachment->DecrementReferenceCount(); // CreateMaterial adds a ref, just want the CMaterialReference's
|
||||
|
||||
// Cache material now to avoid an unwanted implicit Ref that occurs on first use which is never cleared
|
||||
g_pMaterialSystem->CacheUsedMaterials();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MatRefAttachment.Init( sm_pMatAttachment );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAttachment::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// For rendering joints
|
||||
//-----------------------------------------------------------------------------
|
||||
#define AXIS_SIZE 6.0f
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rendering method for the dag
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAttachment::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
|
||||
{
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PushMatrix();
|
||||
pRenderContext->LoadMatrix( shapeToWorld );
|
||||
|
||||
pRenderContext->Bind( sm_pMatAttachment );
|
||||
IMesh *pMesh = pRenderContext->GetDynamicMesh();
|
||||
|
||||
CMeshBuilder meshBuilder;
|
||||
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 255, 0, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 255, 0, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 255, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 255, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 0, 255, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
|
||||
meshBuilder.Color4ub( 0, 0, 255, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PopMatrix();
|
||||
}
|
||||
165
movieobjects/dmeattributereference.cpp
Normal file
165
movieobjects/dmeattributereference.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Implementation of the CDmeAttributeReference class, a simple
|
||||
// DmElement used to store references to attributes within other DmElements.
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeattributereference.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Expose the CDmeAttributeReference class to the scene database
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAttributeReference, CDmeAttributeReference );
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Perform construction tasks, initializes attributes
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeAttributeReference::OnConstruction()
|
||||
{
|
||||
m_Element.Init( this, "element", FATTRIB_HAS_CALLBACK | FATTRIB_NEVERCOPY );
|
||||
m_AttributeName.Init( this, "attribute", FATTRIB_HAS_CALLBACK | FATTRIB_TOPOLOGICAL );
|
||||
m_AttributeIndex.Init( this, "index", FATTRIB_TOPOLOGICAL );
|
||||
m_AttributeHandle = DMATTRIBUTE_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Perform destruction tasks
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeAttributeReference::OnDestruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Process notifications of changed attributes and update the attribute handles if needed.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeAttributeReference::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
if ( ( pAttribute == m_Element.GetAttribute() ) || ( pAttribute == m_AttributeName.GetAttribute() ) )
|
||||
{
|
||||
// Invalidate the attribute handle so that it will be updated.
|
||||
m_AttributeHandle = DMATTRIBUTE_HANDLE_INVALID;
|
||||
return;
|
||||
}
|
||||
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the attribute by specifying the element, name of the attribute and optionally the
|
||||
// array index of the attribute.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeAttributeReference::SetAttribute( CDmElement* pElement, const char* pchAttributeName, int index )
|
||||
{
|
||||
m_Element = pElement;
|
||||
m_AttributeName = pchAttributeName;
|
||||
m_AttributeIndex = index;
|
||||
|
||||
CDmAttribute *pAttr = LookupAttributeHandle();
|
||||
return ( pAttr != NULL );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Lookup and cache the attribute handle
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmAttribute *CDmeAttributeReference::LookupAttributeHandle() const
|
||||
{
|
||||
m_AttributeHandle = DMATTRIBUTE_HANDLE_INVALID;
|
||||
|
||||
CDmElement *pElement = m_Element.GetElement();
|
||||
const char *pName= m_AttributeName.Get();
|
||||
|
||||
if ( pElement == NULL || pName == NULL || !pName[0] )
|
||||
return NULL;
|
||||
|
||||
CDmAttribute *pAttr = pElement->GetAttribute( pName );
|
||||
if ( !pAttr )
|
||||
return NULL;
|
||||
|
||||
m_AttributeHandle = pAttr->GetHandle();
|
||||
return pAttr;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the attribute using the cached handle or looking up the handle if needed.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmAttribute* CDmeAttributeReference::GetReferencedAttribute() const
|
||||
{
|
||||
CDmAttribute *pAttribute = g_pDataModel->GetAttribute( m_AttributeHandle );
|
||||
if ( !pAttribute )
|
||||
{
|
||||
pAttribute = LookupAttributeHandle();
|
||||
}
|
||||
return pAttribute;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the value of the referenced attribute
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
const void *CDmeAttributeReference::GetAttributeValue( DmAttributeType_t &type ) const
|
||||
{
|
||||
CDmAttribute *pAttribute = GetReferencedAttribute();
|
||||
if ( pAttribute == NULL )
|
||||
return NULL;
|
||||
|
||||
const void *pValue = NULL;
|
||||
|
||||
type = pAttribute->GetType();
|
||||
if ( IsArrayType( type ) )
|
||||
{
|
||||
CDmrGenericArray array( pAttribute );
|
||||
pValue = array.GetUntyped( m_AttributeIndex.Get() );
|
||||
type = ArrayTypeToValueType( type );
|
||||
}
|
||||
else
|
||||
{
|
||||
pValue = pAttribute->GetValueUntyped();
|
||||
}
|
||||
|
||||
return pValue;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the value of the referenced attribute
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeAttributeReference::SetAttributeValue( const void *pValue, DmAttributeType_t type ) const
|
||||
{
|
||||
CDmAttribute *pAttribute = GetReferencedAttribute();
|
||||
if ( pAttribute == NULL )
|
||||
return;
|
||||
|
||||
if ( IsArrayType( pAttribute->GetType() ) )
|
||||
{
|
||||
CDmrGenericArray array( pAttribute );
|
||||
array.Set( m_AttributeIndex.Get(), type, pValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
pAttribute->SetValue( type, pValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Determine if the attribute reference points to a valid attribute
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeAttributeReference::IsValid() const
|
||||
{
|
||||
return ( GetReferencedAttribute() != NULL );
|
||||
}
|
||||
|
||||
|
||||
537
movieobjects/dmeaxissystem.cpp
Normal file
537
movieobjects/dmeaxissystem.cpp
Normal file
@@ -0,0 +1,537 @@
|
||||
//============ Copyright (c) Valve Corporation, All rights reserved. ==========
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmechannel.h"
|
||||
#include "movieobjects/dmelog.h"
|
||||
#include "movieobjects/dmemesh.h"
|
||||
#include "movieobjects/dmemodel.h"
|
||||
#include "movieobjects/dmevertexdata.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
|
||||
#include "movieobjects/dmeaxissystem.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAxisSystem, CDmeAxisSystem );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static CDmeAxisSystem::Axis_t GetAbsAxisAndSign(
|
||||
int &nSign, const CDmeAxisSystem::Axis_t eAxis )
|
||||
{
|
||||
nSign = ( eAxis < 0 ) ? -1 : 1;
|
||||
return static_cast< CDmeAxisSystem::Axis_t >( abs( eAxis ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static CDmeAxisSystem::ForwardParity_t GetAbsForwardParityAndSign(
|
||||
int &nSign, const CDmeAxisSystem::ForwardParity_t eForwardParity )
|
||||
{
|
||||
nSign = ( eForwardParity < 0 ) ? -1 : 1;
|
||||
return static_cast< CDmeAxisSystem::ForwardParity_t >( abs( eForwardParity ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static CDmeAxisSystem::Axis_t ComputeAbsForwardAxisAndSign(
|
||||
int &nSign,
|
||||
const CDmeAxisSystem::Axis_t eUpAxis,
|
||||
const CDmeAxisSystem::ForwardParity_t eForwardParity )
|
||||
{
|
||||
Assert( CDmeAxisSystem::IsValid( eUpAxis, eForwardParity ) );
|
||||
|
||||
int nUpAxisSign = 0;
|
||||
const CDmeAxisSystem::Axis_t eAbsUpAxis = GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
|
||||
AssertDbg( eAbsUpAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsUpAxis <= CDmeAxisSystem::AS_AXIS_Z );
|
||||
|
||||
const CDmeAxisSystem::ForwardParity_t eAbsForwardParity = GetAbsForwardParityAndSign( nSign, eForwardParity );
|
||||
AssertDbg( eAbsForwardParity >= CDmeAxisSystem::AS_PARITY_EVEN && eAbsForwardParity <= CDmeAxisSystem::AS_PARITY_ODD );
|
||||
|
||||
// eAxisParityMap[Axis_t - 1][ ForwardParityType_t - 1 ] gives parity axis
|
||||
static const CDmeAxisSystem::Axis_t eAxisParityMap[][2] = {
|
||||
{ CDmeAxisSystem::AS_AXIS_Y, CDmeAxisSystem::AS_AXIS_Z }, // Up X
|
||||
{ CDmeAxisSystem::AS_AXIS_X, CDmeAxisSystem::AS_AXIS_Z }, // Up Y
|
||||
{ CDmeAxisSystem::AS_AXIS_X, CDmeAxisSystem::AS_AXIS_Y } // Up Z
|
||||
};
|
||||
|
||||
const CDmeAxisSystem::Axis_t nAbsForwardAxis = eAxisParityMap[ eAbsUpAxis - 1 ][ eAbsForwardParity - 1 ];
|
||||
AssertDbg( nAbsForwardAxis != eAbsUpAxis );
|
||||
|
||||
return nAbsForwardAxis;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static CDmeAxisSystem::Axis_t ComputeAbsLeftAxisAndSign(
|
||||
int &nSign,
|
||||
const CDmeAxisSystem::Axis_t eUpAxis,
|
||||
const CDmeAxisSystem::ForwardParity_t eForwardParity,
|
||||
const CDmeAxisSystem::CoordSys_t eCoordSys )
|
||||
{
|
||||
Assert( CDmeAxisSystem::IsValid( eUpAxis, eForwardParity, eCoordSys ) );
|
||||
|
||||
int nUpAxisSign = 0;
|
||||
const CDmeAxisSystem::Axis_t eAbsUpAxis = GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
|
||||
AssertDbg( nUpAxisSign == -1 || nUpAxisSign == 1 );
|
||||
AssertDbg( eAbsUpAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsUpAxis <= CDmeAxisSystem::AS_AXIS_Z );
|
||||
|
||||
int nForwardAxisSign = 0;
|
||||
const CDmeAxisSystem::Axis_t eAbsForwardAxis = ComputeAbsForwardAxisAndSign( nForwardAxisSign, eUpAxis, eForwardParity );
|
||||
AssertDbg( eAbsForwardAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsForwardAxis <= CDmeAxisSystem::AS_AXIS_Z );
|
||||
AssertDbg( nForwardAxisSign == -1 || nForwardAxisSign == 1 );
|
||||
|
||||
AssertDbg( eAbsForwardAxis != eAbsUpAxis );
|
||||
|
||||
// Chart of cross products, COL x ROW, 24 possibilities as parallel vectors are not allowed
|
||||
// NOTE: The 3x3 matrices are the same across both diagonals and the two sets of 3x3's are
|
||||
// simply the negative image of each other
|
||||
//
|
||||
// +=====+=====+=====+=====+=====+=====+
|
||||
// | -X | -Y | -Z | X | Y | Z |
|
||||
// +=====+=====+=====+=====+=====+=====+
|
||||
//
|
||||
// +=====+ +-----+-----+-----+-----+-----+-----+
|
||||
// | -X | | . | Z | -Y | . | -Z | Y |
|
||||
// +-----+ +-----+-----+-----+-----+-----+-----+
|
||||
// | -Y | | -Z | . | X | Z | . | -X |
|
||||
// +-----+ +-----+-----+-----+-----+-----+-----+
|
||||
// | -Z | | Y | -X | . | -Y | X | . |
|
||||
// +-----+ +-----+-----+-----+-----+-----+-----+
|
||||
// | X | | . | -Z | Y | . | Z | -Y |
|
||||
// +-----+ +-----+-----+-----+-----+-----+-----+
|
||||
// | Y | | Z | . | -X | -Z | . | X |
|
||||
// +-----+ +-----+-----+-----+-----+-----+-----+
|
||||
// | Z | | -Y | X | . | Y | -X | . |
|
||||
// +=====+ +-----+-----+-----+-----+-----+-----+
|
||||
|
||||
// The 3x3 matrix from the above table without sign, sign is broken down in next table
|
||||
// 0's are invalid cases, index [up - 1][forward - 1]
|
||||
static const CDmeAxisSystem::Axis_t eAxisUpForwardMap[3][3] = {
|
||||
{ (CDmeAxisSystem::Axis_t)0, CDmeAxisSystem::AS_AXIS_Z, CDmeAxisSystem::AS_AXIS_Y },
|
||||
{ CDmeAxisSystem::AS_AXIS_Z, (CDmeAxisSystem::Axis_t)0, CDmeAxisSystem::AS_AXIS_X },
|
||||
{ CDmeAxisSystem::AS_AXIS_Y, CDmeAxisSystem::AS_AXIS_X, (CDmeAxisSystem::Axis_t)0 }
|
||||
};
|
||||
|
||||
// The signs from the lower right 3x3 case (positive axis x positive axis)
|
||||
// 0's are invalid cases, index [up - 1][forward - 1]
|
||||
static const int nSignUpForwardMap[3][3] = {
|
||||
{ 0, 1, -1 },
|
||||
{ -1, 0, 1 },
|
||||
{ 1, -1, 0 }
|
||||
};
|
||||
|
||||
const CDmeAxisSystem::Axis_t eAbsLeftAxis = eAxisUpForwardMap[ eAbsUpAxis - 1 ][ eAbsForwardAxis - 1 ];
|
||||
AssertDbg( eAbsLeftAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsLeftAxis <= CDmeAxisSystem::AS_AXIS_Z );
|
||||
AssertDbg( eAbsLeftAxis != eAbsUpAxis );
|
||||
AssertDbg( eAbsLeftAxis != eAbsForwardAxis );
|
||||
|
||||
nSign = nSignUpForwardMap[ eAbsUpAxis - 1 ][ eAbsForwardAxis - 1 ];
|
||||
|
||||
// If up and forward are not the same sign, then sign is reversed from table
|
||||
if ( nUpAxisSign != nForwardAxisSign )
|
||||
{
|
||||
nSign = -nSign;
|
||||
}
|
||||
|
||||
// If left handed, reverse sign of axis
|
||||
if ( eCoordSys == CDmeAxisSystem::AS_LEFT_HANDED )
|
||||
{
|
||||
nSign = -nSign;
|
||||
}
|
||||
|
||||
return eAbsLeftAxis;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::OnConstruction()
|
||||
{
|
||||
// Initialize to Maya Y Up
|
||||
m_nUpAxis.InitAndSet( this, "upAxis", AS_AXIS_Y );
|
||||
m_nForwardParity.InitAndSet( this, "forwardParity", AS_PARITY_ODD );
|
||||
m_nCoordSys.InitAndSet( this, "coordSys", AS_RIGHT_HANDED );
|
||||
|
||||
Assert( IsValid() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::Init( Axis_t eUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys /*= AS_RIGHT_HANDED */ )
|
||||
{
|
||||
if ( !IsValid( eUpAxis, eForwardParity, eCoordSys ) )
|
||||
{
|
||||
AssertMsg( false, "Invalid Initialization of CDmeAxisSystem" );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_nUpAxis = eUpAxis;
|
||||
m_nForwardParity = eForwardParity;
|
||||
m_nCoordSys = eCoordSys;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::Init( PredefinedAxisSystem ePredefinedAxisSystem )
|
||||
{
|
||||
Axis_t eUpAxis = static_cast< Axis_t >( m_nUpAxis.Get() );
|
||||
ForwardParity_t eForwardParity = static_cast< ForwardParity_t >( m_nForwardParity.Get() );
|
||||
CoordSys_t eCoordSys = static_cast< CoordSys_t >( m_nCoordSys.Get() );
|
||||
|
||||
if ( !GetPredefinedAxisSystem( eUpAxis, eForwardParity, eCoordSys, ePredefinedAxisSystem ) )
|
||||
return false;
|
||||
|
||||
return Init( eUpAxis, eForwardParity, eCoordSys );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::IsValid() const
|
||||
{
|
||||
return IsValid(
|
||||
static_cast< Axis_t >( m_nUpAxis.Get() ),
|
||||
static_cast< ForwardParity_t >( m_nForwardParity.Get() ),
|
||||
static_cast< CoordSys_t >( m_nCoordSys.Get() ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::IsValid( Axis_t nUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys )
|
||||
{
|
||||
if ( nUpAxis == 0 || nUpAxis < AS_AXIS_NZ || nUpAxis > AS_AXIS_Z )
|
||||
return false;
|
||||
|
||||
if ( eForwardParity == 0 || eForwardParity < AS_PARITY_NODD || eForwardParity > AS_PARITY_ODD )
|
||||
return false;
|
||||
|
||||
if ( eCoordSys < AS_RIGHT_HANDED || eCoordSys > AS_LEFT_HANDED )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::GetPredefinedAxisSystem(
|
||||
Axis_t &eUpAxis,
|
||||
ForwardParity_t &eForwardParity,
|
||||
CoordSys_t &eCoordSys,
|
||||
PredefinedAxisSystem ePredefinedAxisSystem )
|
||||
{
|
||||
if ( ePredefinedAxisSystem < AS_VALVE_ENGINE || ePredefinedAxisSystem > AS_3DSMAX )
|
||||
return false;
|
||||
|
||||
static int predefinedAxisSystemList[][3] = {
|
||||
{ AS_AXIS_Z, AS_PARITY_EVEN, AS_RIGHT_HANDED }, // AS_VALVE_ENGINE +Z, +X
|
||||
{ AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_SMD +Z, -Y
|
||||
{ AS_AXIS_Y, AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MAYA_YUP +Y, +Z
|
||||
{ AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MAYA_ZUP +Z, -Y
|
||||
{ AS_AXIS_Y, AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MODO +Y, +Z
|
||||
{ AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED } // AS_3DSMAX +Z, -Y
|
||||
};
|
||||
|
||||
COMPILE_TIME_ASSERT( AS_VALVE_ENGINE == 0 );
|
||||
COMPILE_TIME_ASSERT( AS_SMD == 1 );
|
||||
COMPILE_TIME_ASSERT( AS_MAYA_YUP == 2 );
|
||||
COMPILE_TIME_ASSERT( AS_MAYA_ZUP == 3 );
|
||||
COMPILE_TIME_ASSERT( AS_MODO_YUP == 4 );
|
||||
COMPILE_TIME_ASSERT( AS_3DSMAX == 5 );
|
||||
COMPILE_TIME_ASSERT( AS_3DSMAX + 1 == ARRAYSIZE( predefinedAxisSystemList ) );
|
||||
|
||||
eUpAxis = static_cast< Axis_t >( predefinedAxisSystemList[ePredefinedAxisSystem][0] );
|
||||
eForwardParity = static_cast< ForwardParity_t >( predefinedAxisSystemList[ePredefinedAxisSystem][1] );
|
||||
eCoordSys = static_cast< CoordSys_t >( predefinedAxisSystemList[ePredefinedAxisSystem][2] );
|
||||
|
||||
Assert( IsValid( eUpAxis, eForwardParity, eCoordSys ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAxisSystem::IsEqual( PredefinedAxisSystem ePredefinedAxisSystem ) const
|
||||
{
|
||||
Axis_t eAUpAxis;
|
||||
ForwardParity_t eAForwardParity;
|
||||
CoordSys_t eACoordSys;
|
||||
|
||||
if ( !GetPredefinedAxisSystem( eAUpAxis, eAForwardParity, eACoordSys, ePredefinedAxisSystem ) )
|
||||
return false;
|
||||
|
||||
const Axis_t eBUpAxis = GetUpAxis();
|
||||
const ForwardParity_t eBForwardParity = GetForwardParity();
|
||||
const CoordSys_t eBCoordSys = GetCoordSys();
|
||||
|
||||
return ( eBUpAxis == eAUpAxis ) && ( eBForwardParity == eAForwardParity ) && ( eBCoordSys == eACoordSys );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::Axis_t CDmeAxisSystem::GetUpAxis() const
|
||||
{
|
||||
return static_cast< Axis_t >( m_nUpAxis.Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::ForwardParity_t CDmeAxisSystem::GetForwardParity() const
|
||||
{
|
||||
return static_cast< ForwardParity_t >( m_nForwardParity.Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::CoordSys_t CDmeAxisSystem::GetCoordSys() const
|
||||
{
|
||||
return static_cast< CoordSys_t >( m_nCoordSys.Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::ComputeMatrix(
|
||||
matrix3x4a_t &mMatrix, const PredefinedAxisSystem ePredefinedAxisSystem )
|
||||
{
|
||||
Axis_t eUpAxis;
|
||||
ForwardParity_t eForwardParity;
|
||||
CoordSys_t eCoordSys;
|
||||
|
||||
GetPredefinedAxisSystem( eUpAxis, eForwardParity, eCoordSys, ePredefinedAxisSystem );
|
||||
ComputeMatrix( mMatrix, eUpAxis, eForwardParity, eCoordSys );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::GetConversionMatrix(
|
||||
matrix3x4a_t &mMat,
|
||||
PredefinedAxisSystem eFromAxisSystem,
|
||||
PredefinedAxisSystem eToAxisSystem )
|
||||
{
|
||||
Axis_t eFromUpAxis;
|
||||
ForwardParity_t eFromForwardParity;
|
||||
CoordSys_t eFromCoordSys;
|
||||
|
||||
GetPredefinedAxisSystem( eFromUpAxis, eFromForwardParity, eFromCoordSys, eFromAxisSystem );
|
||||
Assert( IsValid( eFromUpAxis, eFromForwardParity, eFromCoordSys ) );
|
||||
|
||||
Axis_t eToUpAxis;
|
||||
ForwardParity_t eToForwardParity;
|
||||
CoordSys_t eToCoordSys;
|
||||
|
||||
GetPredefinedAxisSystem( eToUpAxis, eToForwardParity, eToCoordSys, eToAxisSystem );
|
||||
Assert( IsValid( eToUpAxis, eToForwardParity, eToCoordSys ) );
|
||||
|
||||
GetConversionMatrix( mMat,
|
||||
eFromUpAxis, eFromForwardParity, eFromCoordSys,
|
||||
eToUpAxis, eToForwardParity, eToCoordSys );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::GetConversionMatrix(
|
||||
matrix3x4a_t &mMat,
|
||||
Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity,
|
||||
Axis_t eToUpAxis, ForwardParity_t eToForwardParity )
|
||||
{
|
||||
GetConversionMatrix( mMat,
|
||||
eFromUpAxis, eFromForwardParity, AS_RIGHT_HANDED,
|
||||
eToUpAxis, eToForwardParity, AS_RIGHT_HANDED );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::GetConversionMatrix(
|
||||
matrix3x4a_t &mMat,
|
||||
Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity, CoordSys_t eFromCoordSys,
|
||||
Axis_t eToUpAxis, ForwardParity_t eToForwardParity, CoordSys_t eToCoordSys )
|
||||
{
|
||||
matrix3x4a_t mFrom;
|
||||
ComputeMatrix( mFrom, eFromUpAxis, eFromForwardParity, eFromCoordSys );
|
||||
|
||||
matrix3x4a_t mTo;
|
||||
ComputeMatrix( mTo, eToUpAxis, eToForwardParity, eToCoordSys );
|
||||
|
||||
// Matrix is guaranteed to be a rotation matrix (orthonormal upper 3x3) with no translation
|
||||
// so in this case, Transpose is the same as Inverse
|
||||
matrix3x4a_t mFromInv;
|
||||
MatrixTranspose( mFrom, mFromInv );
|
||||
|
||||
MatrixMultiply( mTo, mFromInv, mMat );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlString CDmeAxisSystem::GetAxisString(
|
||||
Axis_t eUpAxis,
|
||||
ForwardParity_t eForwardParity,
|
||||
CoordSys_t eCoordSys )
|
||||
{
|
||||
int nUSign = 0;
|
||||
const int nU = GetAbsAxisAndSign( nUSign, eUpAxis );
|
||||
int nFSign = 0;
|
||||
const int nF = ::ComputeAbsForwardAxisAndSign( nFSign, eUpAxis, eForwardParity );
|
||||
int nLSign = 0;
|
||||
const int nL = ::ComputeAbsLeftAxisAndSign( nLSign, eUpAxis, eForwardParity, eCoordSys );
|
||||
|
||||
const char *szAxis[] = { "x", "y", "z" };
|
||||
|
||||
return CUtlString( CFmtStr( "u_%s%s_f_%s%s_l_%s%s",
|
||||
nUSign < 0 ? "n" : "", szAxis[nU - 1],
|
||||
nFSign < 0 ? "n" : "", szAxis[nF - 1],
|
||||
nLSign < 0 ? "n" : "", szAxis[nL - 1] ).Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::Axis_t CDmeAxisSystem::GetAbsUpAxisAndSign( int &nSign ) const
|
||||
{
|
||||
return ::GetAbsAxisAndSign( nSign, static_cast< Axis_t >( m_nUpAxis.Get() ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::ForwardParity_t CDmeAxisSystem::GetAbsForwardParityAndSign( int &nSign ) const
|
||||
{
|
||||
return ::GetAbsForwardParityAndSign( nSign, GetForwardParity() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::Axis_t CDmeAxisSystem::ComputeAbsForwardAxisAndSign( int &nSign ) const
|
||||
{
|
||||
Assert( IsValid() );
|
||||
return ::ComputeAbsForwardAxisAndSign( nSign, GetUpAxis(), GetForwardParity() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAxisSystem::Axis_t CDmeAxisSystem::ComputeLeftAxis( int &nSign ) const
|
||||
{
|
||||
Assert( IsValid() );
|
||||
return ::ComputeAbsLeftAxisAndSign( nSign, GetUpAxis(), GetForwardParity(), GetCoordSys() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAxisSystem::ComputeMatrix(
|
||||
matrix3x4a_t &mMatrix,
|
||||
const Axis_t eUpAxis,
|
||||
const ForwardParity_t eForwardParity,
|
||||
const CoordSys_t eCoordSys )
|
||||
{
|
||||
Assert( IsValid( eUpAxis, eForwardParity, eCoordSys ) );
|
||||
|
||||
int nUpAxisSign = 0;
|
||||
const Axis_t eAbsUpAxis = ::GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
|
||||
AssertDbg( nUpAxisSign == -1 || nUpAxisSign == 1 );
|
||||
AssertDbg( eAbsUpAxis >= AS_AXIS_X && eAbsUpAxis <= AS_AXIS_Z );
|
||||
|
||||
int nForwardAxisSign = 0;
|
||||
const Axis_t eAbsForwardAxis = ::ComputeAbsForwardAxisAndSign( nForwardAxisSign, eUpAxis, eForwardParity );
|
||||
AssertDbg( eAbsForwardAxis >= AS_AXIS_X && eAbsForwardAxis <= AS_AXIS_Z );
|
||||
AssertDbg( nForwardAxisSign == -1 || nForwardAxisSign == 1 );
|
||||
|
||||
AssertDbg( eAbsForwardAxis != eAbsUpAxis );
|
||||
|
||||
int nLeftAxisSign = 0;
|
||||
const Axis_t eAbsLeftAxis = ::ComputeAbsLeftAxisAndSign( nLeftAxisSign, eUpAxis, eForwardParity, eCoordSys );
|
||||
AssertDbg( eAbsLeftAxis >= AS_AXIS_X && eAbsLeftAxis <= AS_AXIS_Z );
|
||||
AssertDbg( nLeftAxisSign == -1 || nLeftAxisSign == 1 );
|
||||
AssertDbg( eAbsLeftAxis != eAbsUpAxis );
|
||||
AssertDbg( eAbsLeftAxis != eAbsForwardAxis );
|
||||
|
||||
// flVectorList[nAbsAxis - 1][( nSign + 1 ) / 2][]
|
||||
static const float flVectorList[][2][3] = {
|
||||
{
|
||||
{ -1.0f, 0.0f, 0.0f }, // -X
|
||||
{ 1.0f, 0.0f, 0.0f } // X
|
||||
},
|
||||
{
|
||||
{ 0.0f, -1.0f, 0.0f }, // -Y
|
||||
{ 0.0f, 1.0f, 0.0f } // Y
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, -1.0f }, // -Z
|
||||
{ 0.0f, 0.0f, 1.0f } // Z
|
||||
}
|
||||
};
|
||||
|
||||
const int nUpSignIndex = ( nUpAxisSign + 1 ) / 2;
|
||||
const int nForwardSignIndex = ( nForwardAxisSign + 1 ) / 2;
|
||||
const int nLeftSignIndex = ( nLeftAxisSign + 1 ) / 2;
|
||||
|
||||
// Is this a bad idea?
|
||||
const Vector &vUp = *reinterpret_cast< const Vector * >( flVectorList[eAbsUpAxis - 1][nUpSignIndex] );
|
||||
const Vector &vForward = *reinterpret_cast< const Vector * >( flVectorList[eAbsForwardAxis - 1][nForwardSignIndex] );
|
||||
const Vector &vLeft = *reinterpret_cast< const Vector * >( flVectorList[eAbsLeftAxis - 1][nLeftSignIndex] );
|
||||
|
||||
MatrixInitialize/*FLU*/( mMatrix, vec3_origin, vForward, vLeft, vUp );
|
||||
}
|
||||
75
movieobjects/dmebookmark.cpp
Normal file
75
movieobjects/dmebookmark.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmebookmark.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class factory
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeBookmark, CDmeBookmark );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeBookmark::OnConstruction()
|
||||
{
|
||||
m_Time.InitAndSet( this, "time", DMETIME_ZERO );
|
||||
m_Duration.InitAndSet( this, "duration", DMETIME_ZERO );
|
||||
m_Note.Init( this, "note" );
|
||||
}
|
||||
|
||||
void CDmeBookmark::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class factory
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeBookmarkSet, CDmeBookmarkSet );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeBookmarkSet::OnConstruction()
|
||||
{
|
||||
m_Bookmarks.Init( this, "bookmarks" );
|
||||
}
|
||||
|
||||
void CDmeBookmarkSet::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
const CDmaElementArray< CDmeBookmark > &CDmeBookmarkSet::GetBookmarks() const
|
||||
{
|
||||
return m_Bookmarks;
|
||||
}
|
||||
|
||||
CDmaElementArray< CDmeBookmark > &CDmeBookmarkSet::GetBookmarks()
|
||||
{
|
||||
return m_Bookmarks;
|
||||
}
|
||||
|
||||
void CDmeBookmarkSet::ScaleBookmarkTimes( float scale )
|
||||
{
|
||||
int nBookmarks = m_Bookmarks.Count();
|
||||
for ( int i = 0; i < nBookmarks; ++i )
|
||||
{
|
||||
CDmeBookmark *pBookmark = m_Bookmarks[ i ];
|
||||
if ( !pBookmark )
|
||||
continue;
|
||||
|
||||
pBookmark->SetTime ( pBookmark->GetTime () * scale );
|
||||
pBookmark->SetDuration( pBookmark->GetDuration() * scale );
|
||||
}
|
||||
}
|
||||
500
movieobjects/dmecamera.cpp
Normal file
500
movieobjects/dmecamera.cpp
Normal file
@@ -0,0 +1,500 @@
|
||||
//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// A class representing a camera
|
||||
//
|
||||
//===============================================================================
|
||||
|
||||
#include "movieobjects/dmecamera.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// FIXME: REMOVE
|
||||
#include "istudiorender.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeCamera, CDmeCamera );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::OnConstruction()
|
||||
{
|
||||
m_flFieldOfView.InitAndSet( this, "fieldOfView", 30.0f );
|
||||
|
||||
// FIXME: This currently matches the client DLL for HL2
|
||||
// but we probably need a way of getting this state from the client DLL
|
||||
m_zNear.InitAndSet( this, "znear", 3.0f );
|
||||
m_zFar.InitAndSet( this, "zfar", 16384.0f * 1.73205080757f );
|
||||
|
||||
m_flFocalDistance.InitAndSet( this, "focalDistance", 72.0f);
|
||||
m_flZeroParallaxDistance.InitAndSet( this, "zeroParallaxDistance", 75.0f );
|
||||
m_flEyeSeparation.InitAndSet( this, "eyeSeparation", 0.75f );
|
||||
m_flAperture.InitAndSet( this, "aperture", 0.2f);
|
||||
m_shutterSpeed.InitAndSet( this, "shutterSpeed", DmeTime_t( 0.5f / 24.0f ) );
|
||||
m_flToneMapScale.InitAndSet( this, "toneMapScale", 1.0f );
|
||||
m_flAOBias.InitAndSet( this, "SSAOBias", 0.0005f );
|
||||
m_flAOStrength.InitAndSet( this, "SSAOStrength", 1.0f );
|
||||
m_flAORadius.InitAndSet( this, "SSAORadius", 15.0f );
|
||||
m_flBloomScale.InitAndSet( this, "bloomScale", 0.28f );
|
||||
m_nDoFQuality.InitAndSet( this, "depthOfFieldQuality", 0 );
|
||||
m_nMotionBlurQuality.InitAndSet( this, "motionBlurQuality", 0 );
|
||||
m_flBloomWidth.InitAndSet( this, "bloomWidth", 9.0f );
|
||||
m_bOrtho.InitAndSet( this, "ortho", false );
|
||||
|
||||
// Ortho
|
||||
m_nAxis.InitAndSet( this, "axis", 0 );
|
||||
m_bWasBehindFrustum.InitAndSet( this, "behindfrustum", false );
|
||||
m_flDistance.InitAndSet( this, "distance", 32.0f );
|
||||
for ( int i = 0; i < AXIS_COUNT; ++i )
|
||||
{
|
||||
char sz[ 32 ];
|
||||
Q_snprintf( sz, sizeof( sz ), "scale%d", i );
|
||||
m_flScale[ i ].InitAndSet( this, sz, 1.0f );
|
||||
Q_snprintf( sz, sizeof( sz ), "lookat%d", i );
|
||||
m_vecLookAt[ i ].Init( this, sz );
|
||||
}
|
||||
|
||||
m_vecAxis.Init();
|
||||
m_vecOrigin.Init();
|
||||
m_angRotation.Init();
|
||||
SetIdentityMatrix( m_Transform );
|
||||
}
|
||||
|
||||
void CDmeCamera::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads the material system view matrix based on the transform
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::LoadViewMatrix( bool bUseEngineCoordinateSystem )
|
||||
{
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
VMatrix view;
|
||||
GetViewMatrix( view, bUseEngineCoordinateSystem );
|
||||
pRenderContext->MatrixMode( MATERIAL_VIEW );
|
||||
pRenderContext->LoadMatrix( view );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads the material system projection matrix based on the fov, etc.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::LoadProjectionMatrix( int nDisplayWidth, int nDisplayHeight )
|
||||
{
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->MatrixMode( MATERIAL_PROJECTION );
|
||||
|
||||
VMatrix proj;
|
||||
GetProjectionMatrix( proj, nDisplayWidth, nDisplayHeight );
|
||||
pRenderContext->LoadMatrix( proj );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up studiorender camera state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::LoadStudioRenderCameraState()
|
||||
{
|
||||
// FIXME: Remove this! This should automatically happen in DrawModel
|
||||
// in studiorender.
|
||||
if ( !g_pStudioRender )
|
||||
return;
|
||||
|
||||
matrix3x4_t transform;
|
||||
GetTransform()->GetTransform( transform );
|
||||
|
||||
Vector vecOrigin, vecRight, vecUp, vecForward;
|
||||
MatrixGetColumn( transform, 0, vecRight );
|
||||
MatrixGetColumn( transform, 1, vecUp );
|
||||
MatrixGetColumn( transform, 2, vecForward );
|
||||
MatrixGetColumn( transform, 3, vecOrigin );
|
||||
g_pStudioRender->SetViewState( vecOrigin, vecRight, vecUp, vecForward );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the x FOV (the full angle)
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetFOVx() const
|
||||
{
|
||||
return m_flFieldOfView;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the near Z in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetNearZ() const
|
||||
{
|
||||
return m_zNear;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the near Z in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetNearZ( float zNear )
|
||||
{
|
||||
m_zNear = zNear;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the far Z in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetFarZ() const
|
||||
{
|
||||
return m_zFar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the far Z in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetFarZ( float zFar )
|
||||
{
|
||||
m_zFar = zFar;
|
||||
}
|
||||
|
||||
void CDmeCamera::SetFOVx( float fov )
|
||||
{
|
||||
m_flFieldOfView = fov;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the focal distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetFocalDistance() const
|
||||
{
|
||||
return m_flFocalDistance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the focal distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetFocalDistance( const float &flFocalDistance )
|
||||
{
|
||||
m_flFocalDistance = flFocalDistance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the zero-parallax distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetZeroParallaxDistance() const
|
||||
{
|
||||
return m_flZeroParallaxDistance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the zero-parallax distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetZeroParallaxDistance( const float &flZeroParallaxDistance )
|
||||
{
|
||||
m_flZeroParallaxDistance = flZeroParallaxDistance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the eye separation distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetEyeSeparation() const
|
||||
{
|
||||
return m_flEyeSeparation;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the eye separation distance in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetEyeSeparation( const float &flEyeSeparation )
|
||||
{
|
||||
m_flEyeSeparation = flEyeSeparation;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the camera aperture in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetAperture() const
|
||||
{
|
||||
return m_flAperture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the camera aperture in inches
|
||||
//-----------------------------------------------------------------------------
|
||||
DmeTime_t CDmeCamera::GetShutterSpeed() const
|
||||
{
|
||||
return m_shutterSpeed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the tone map scale
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetToneMapScale() const
|
||||
{
|
||||
return m_flToneMapScale;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the camera's Ambient occlusion bias
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetAOBias() const
|
||||
{
|
||||
return m_flAOBias;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the camera's Ambient occlusion strength
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetAOStrength() const
|
||||
{
|
||||
return m_flAOStrength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the camera's Ambient occlusion radius
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetAORadius() const
|
||||
{
|
||||
return m_flAORadius;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the bloom scale
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetBloomScale() const
|
||||
{
|
||||
return m_flBloomScale;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the bloom width
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeCamera::GetBloomWidth() const
|
||||
{
|
||||
return m_flBloomWidth;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of Depth of Field samples
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeCamera::GetDepthOfFieldQuality() const
|
||||
{
|
||||
return m_nDoFQuality;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of Motion Blur samples
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeCamera::GetMotionBlurQuality() const
|
||||
{
|
||||
return m_nMotionBlurQuality;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the view direction
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::GetViewDirection( Vector *pDirection )
|
||||
{
|
||||
matrix3x4_t transform;
|
||||
GetTransform()->GetTransform( transform );
|
||||
MatrixGetColumn( transform, 2, *pDirection );
|
||||
|
||||
// We look down the -z axis
|
||||
*pDirection *= -1.0f;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up render state in the material system for rendering
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::SetupRenderState( int nDisplayWidth, int nDisplayHeight, bool bUseEngineCoordinateSystem /* = false */ )
|
||||
{
|
||||
LoadViewMatrix( bUseEngineCoordinateSystem );
|
||||
LoadProjectionMatrix( nDisplayWidth, nDisplayHeight );
|
||||
LoadStudioRenderCameraState( );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessors for generated matrices
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::GetViewMatrix( VMatrix &view, bool bUseEngineCoordinateSystem /* = false */ )
|
||||
{
|
||||
matrix3x4_t transform, invTransform;
|
||||
CDmeTransform *pTransform = GetTransform();
|
||||
pTransform->GetTransform( transform );
|
||||
|
||||
if ( bUseEngineCoordinateSystem )
|
||||
{
|
||||
VMatrix matRotate( transform );
|
||||
VMatrix matRotateZ;
|
||||
MatrixBuildRotationAboutAxis( matRotateZ, Vector(0,0,1), -90 );
|
||||
MatrixMultiply( matRotate, matRotateZ, matRotate );
|
||||
|
||||
VMatrix matRotateX;
|
||||
MatrixBuildRotationAboutAxis( matRotateX, Vector(1,0,0), 90 );
|
||||
MatrixMultiply( matRotate, matRotateX, matRotate );
|
||||
transform = matRotate.As3x4();
|
||||
}
|
||||
|
||||
MatrixInvert( transform, invTransform );
|
||||
view.Init( invTransform );
|
||||
}
|
||||
|
||||
void CDmeCamera::GetProjectionMatrix( VMatrix &proj, int width, int height )
|
||||
{
|
||||
float flFOV = m_flFieldOfView.Get();
|
||||
float flZNear = m_zNear.Get();
|
||||
float flZFar = m_zFar.Get();
|
||||
float flApsectRatio = (float)width / (float)height;
|
||||
|
||||
// MatrixBuildPerspective( proj, flFOV, flFOV * flApsectRatio, flZNear, flZFar );
|
||||
|
||||
#if 1
|
||||
float halfWidth = tan( flFOV * M_PI / 360.0 );
|
||||
float halfHeight = halfWidth / flApsectRatio;
|
||||
#else
|
||||
float halfHeight = tan( flFOV * M_PI / 360.0 );
|
||||
float halfWidth = flApsectRatio * halfHeight;
|
||||
#endif
|
||||
memset( proj.Base(), 0, sizeof( proj ) );
|
||||
proj[0][0] = 1.0f / halfWidth;
|
||||
proj[1][1] = 1.0f / halfHeight;
|
||||
proj[2][2] = flZFar / ( flZNear - flZFar );
|
||||
proj[3][2] = -1.0f;
|
||||
proj[2][3] = flZNear * flZFar / ( flZNear - flZFar );
|
||||
}
|
||||
|
||||
void CDmeCamera::GetViewProjectionInverse( VMatrix &viewprojinv, int width, int height )
|
||||
{
|
||||
VMatrix view, proj;
|
||||
GetViewMatrix( view );
|
||||
GetProjectionMatrix( proj, width, height );
|
||||
|
||||
VMatrix viewproj;
|
||||
MatrixMultiply( proj, view, viewproj );
|
||||
bool success = MatrixInverseGeneral( viewproj, viewprojinv );
|
||||
if ( !success )
|
||||
{
|
||||
Assert( 0 );
|
||||
MatrixInverseTR( viewproj, viewprojinv );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the screen space position given a screen size
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCamera::ComputeScreenSpacePosition( const Vector &vecWorldPosition, int width, int height, Vector2D *pScreenPosition )
|
||||
{
|
||||
VMatrix view, proj, viewproj;
|
||||
GetViewMatrix( view );
|
||||
GetProjectionMatrix( proj, width, height );
|
||||
MatrixMultiply( proj, view, viewproj );
|
||||
|
||||
Vector vecScreenPos;
|
||||
Vector3DMultiplyPositionProjective( viewproj, vecWorldPosition, vecScreenPos );
|
||||
|
||||
pScreenPosition->x = ( vecScreenPos.x + 1.0f ) * width / 2.0f;
|
||||
pScreenPosition->y = ( -vecScreenPos.y + 1.0f ) * height / 2.0f;
|
||||
}
|
||||
|
||||
const matrix3x4_t &CDmeCamera::GetOrthoTransform() const
|
||||
{
|
||||
return m_Transform;
|
||||
}
|
||||
|
||||
const Vector &CDmeCamera::GetOrthoAbsOrigin() const
|
||||
{
|
||||
return m_vecOrigin;
|
||||
}
|
||||
|
||||
const QAngle &CDmeCamera::GetOrthoAbsAngles() const
|
||||
{
|
||||
return m_angRotation;
|
||||
}
|
||||
|
||||
void CDmeCamera::OrthoUpdate()
|
||||
{
|
||||
m_vecAxis.Init( 0, 0, 0 );
|
||||
switch ( m_nAxis )
|
||||
{
|
||||
default:
|
||||
Assert( 0 );
|
||||
case AXIS_X:
|
||||
m_vecAxis[ 1 ] = 1;
|
||||
break;
|
||||
case AXIS_Y:
|
||||
m_vecAxis[ 2 ] = -1;
|
||||
break;
|
||||
case AXIS_Z:
|
||||
m_vecAxis[ 0 ] = 1;
|
||||
break;
|
||||
case AXIS_X_NEG:
|
||||
m_vecAxis[ 1 ] = -1;
|
||||
break;
|
||||
case AXIS_Y_NEG:
|
||||
m_vecAxis[ 2 ] = 1;
|
||||
break;
|
||||
case AXIS_Z_NEG:
|
||||
m_vecAxis[ 0 ] = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
m_vecOrigin = m_vecLookAt[ m_nAxis ].Get() - m_flDistance * m_vecAxis;
|
||||
Assert( m_vecOrigin.IsValid() );
|
||||
|
||||
VectorAngles( m_vecAxis,m_angRotation );
|
||||
AngleMatrix( m_angRotation, m_vecOrigin, m_Transform );
|
||||
}
|
||||
|
||||
void CDmeCamera::FromCamera( CDmeCamera *pCamera )
|
||||
{
|
||||
m_bOrtho = pCamera->m_bOrtho;
|
||||
matrix3x4_t mat;
|
||||
pCamera->GetAbsTransform( mat );
|
||||
MatrixCopy( mat, m_Transform );
|
||||
m_flFieldOfView = pCamera->GetFOVx();
|
||||
|
||||
for ( int i = 0; i < AXIS_COUNT; ++i )
|
||||
{
|
||||
m_vecLookAt[ i ] =pCamera->m_vecLookAt[ i ];
|
||||
m_flScale[ i ] = pCamera->m_flScale[ i ];
|
||||
}
|
||||
m_flDistance = pCamera->m_flDistance;
|
||||
m_nAxis = pCamera->m_nAxis;
|
||||
m_bWasBehindFrustum = pCamera->m_bWasBehindFrustum;
|
||||
|
||||
if ( m_bOrtho )
|
||||
{
|
||||
OrthoUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeCamera::ToCamera( CDmeCamera *pCamera )
|
||||
{
|
||||
pCamera->m_bOrtho = m_bOrtho;
|
||||
pCamera->SetFOVx( m_flFieldOfView );
|
||||
pCamera->SetAbsTransform( m_Transform );
|
||||
|
||||
for ( int i = 0; i < AXIS_COUNT; ++i )
|
||||
{
|
||||
pCamera->m_vecLookAt[ i ] = m_vecLookAt[ i ];
|
||||
pCamera->m_flScale[ i ] = m_flScale[ i ];
|
||||
}
|
||||
pCamera->m_flDistance = m_flDistance;
|
||||
pCamera->m_nAxis = m_nAxis;
|
||||
pCamera->m_bWasBehindFrustum = m_bWasBehindFrustum;
|
||||
|
||||
if ( m_bOrtho )
|
||||
{
|
||||
pCamera->OrthoUpdate();
|
||||
}
|
||||
}
|
||||
3281
movieobjects/dmechannel.cpp
Normal file
3281
movieobjects/dmechannel.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2278
movieobjects/dmeclip.cpp
Normal file
2278
movieobjects/dmeclip.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2207
movieobjects/dmecombinationoperator.cpp
Normal file
2207
movieobjects/dmecombinationoperator.cpp
Normal file
File diff suppressed because it is too large
Load Diff
188
movieobjects/dmeconnectionoperator.cpp
Normal file
188
movieobjects/dmeconnectionoperator.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Declaration of the CDmeConnectionOperator class, a CDmeOperator
|
||||
// which copies one attribute value to another, providing similar functionality
|
||||
// to CDmeChannel, but does not store a log and is not effected by the
|
||||
// recording mode.
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeconnectionoperator.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeConnectionOperator, CDmeConnectionOperator );
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Constructor, initializes attributes, create the embedded target
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::OnConstruction()
|
||||
{
|
||||
m_Input.InitAndCreate( this, "input" );
|
||||
m_Outputs.Init( this, "outputs" );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Perform destruction tasks, destroy the internal elements of the constraint.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::OnDestruction()
|
||||
{
|
||||
g_pDataModel->DestroyElement( m_Input.GetHandle() );
|
||||
|
||||
int nOutputs = m_Outputs.Count();
|
||||
for ( int i = 0 ;i < nOutputs; ++i )
|
||||
{
|
||||
if ( m_Outputs[ i ] )
|
||||
{
|
||||
g_pDataModel->DestroyElement( m_Outputs[ i ]->GetHandle() );
|
||||
}
|
||||
}
|
||||
|
||||
m_Outputs.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Run the operator, which copies the value from the source attribute to the destination
|
||||
// attributes.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::Operate()
|
||||
{
|
||||
if ( !m_Input->IsValid() )
|
||||
return;
|
||||
|
||||
int nOutputs = m_Outputs.Count();
|
||||
if ( nOutputs == 0 )
|
||||
return;
|
||||
|
||||
DmAttributeType_t inputType = AT_UNKNOWN;
|
||||
const void *pValue = m_Input->GetAttributeValue( inputType );
|
||||
|
||||
for ( int iOutput = 0; iOutput < nOutputs; ++iOutput )
|
||||
{
|
||||
m_Outputs[ iOutput ]->SetAttributeValue( pValue, inputType );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Determine if data has changed and the operator needs to be updated
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeConnectionOperator::IsDirty()
|
||||
{
|
||||
CDmAttribute* pAttr = m_Input->GetReferencedAttribute();
|
||||
|
||||
if ( pAttr )
|
||||
{
|
||||
return pAttr->IsFlagSet( FATTRIB_DIRTY );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add the input attribute used by the operator to the provided list of attributes, This
|
||||
// is generally used by the evaluation process to find the attributes an operator is dependent on.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
CDmAttribute *pInputAttr = m_Input->GetReferencedAttribute();
|
||||
if ( pInputAttr )
|
||||
{
|
||||
attrs.AddToTail( pInputAttr );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add each of attributes the connection operator outputs to the provided list of
|
||||
// attributes. This is generally used by the evaluation process to find out what attributes are
|
||||
// written by the operator in order to determine what other operators are dependent on this
|
||||
// operator.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
int nOutputs = m_Outputs.Count();
|
||||
for ( int iOutput = 0; iOutput < nOutputs; ++iOutput )
|
||||
{
|
||||
CDmAttribute *pOutputAttr = m_Outputs[ iOutput ]->GetReferencedAttribute();
|
||||
if ( pOutputAttr )
|
||||
{
|
||||
attrs.AddToTail( pOutputAttr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the input attribute of the connection.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::SetInput( CDmElement* pElement, const char* pchAttributeName, int index )
|
||||
{
|
||||
m_Input->SetAttribute( pElement, pchAttributeName, index );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add an attribute to be written to by the connection.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeConnectionOperator::AddOutput( CDmElement* pElement, const char* pchAttributeName, int index )
|
||||
{
|
||||
if ( ( pElement == NULL ) || ( pchAttributeName == NULL ) )
|
||||
return;
|
||||
|
||||
CDmeAttributeReference *pAttrRef = CreateElement< CDmeAttributeReference >( CFmtStr( "%s_%s", pElement->GetName() , pchAttributeName ), GetFileId() );
|
||||
if ( pAttrRef )
|
||||
{
|
||||
if ( pAttrRef->SetAttribute( pElement, pchAttributeName, index ) )
|
||||
{
|
||||
// Add the new reference to the list of outputs of the connection.
|
||||
m_Outputs.AddToTail( pAttrRef );
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the specified attribute was not valid destroy the reference.
|
||||
g_pDataModel->DestroyElement( pAttrRef->GetHandle() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the number of output attributes
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
int CDmeConnectionOperator::NumOutputAttributes() const
|
||||
{
|
||||
return m_Outputs.Count();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the specified output attribute
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmAttribute *CDmeConnectionOperator::GetOutputAttribute( int index ) const
|
||||
{
|
||||
if ( index >= m_Outputs.Count() )
|
||||
return NULL;
|
||||
|
||||
return m_Outputs[ index ]->GetReferencedAttribute();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the input attribute
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmAttribute *CDmeConnectionOperator::GetInputAttribute()
|
||||
{
|
||||
return m_Input.GetAttribute();
|
||||
}
|
||||
|
||||
855
movieobjects/dmecontrolgroup.cpp
Normal file
855
movieobjects/dmecontrolgroup.cpp
Normal file
@@ -0,0 +1,855 @@
|
||||
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Implementation of the CDmeControlGroup class. The CDmeControlGroup
|
||||
// class provides hierarchical grouping of animation controls and used for
|
||||
// selection of the animation set controls.
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmecontrolgroup.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "movieobjects/dmetransformcontrol.h"
|
||||
#include "movieobjects/dmeanimationset.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeControlGroup, CDmeControlGroup );
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide post construction processing.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::OnConstruction()
|
||||
{
|
||||
m_Children.Init( this, "children" );
|
||||
m_Controls.Init( this, "controls" );
|
||||
m_GroupColor.InitAndSet( this, "groupColor", Color( 200, 200, 200, 255 ) );
|
||||
m_ControlColor.InitAndSet( this, "controlColor", Color( 200, 200, 200, 255 ) );
|
||||
m_Visible.InitAndSet( this, "visible", true );
|
||||
m_Selectable.InitAndSet( this, "selectable", true );
|
||||
m_Snappable.InitAndSet( this, "snappable", true );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide processing and cleanup before shutdown
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::OnDestruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add a the provided control to the group, if the control is currently in another group
|
||||
// it will be removed from the other group first.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::AddControl( CDmElement *pControl, const CDmElement *pInsertBeforeControl )
|
||||
{
|
||||
if ( pControl == NULL )
|
||||
return;
|
||||
|
||||
// Remove the control from any group it is currently in.
|
||||
CDmeControlGroup *pCurrentGroup = FindGroupContainingControl( pControl );
|
||||
if ( pCurrentGroup )
|
||||
{
|
||||
pCurrentGroup->RemoveControl( pControl );
|
||||
}
|
||||
|
||||
|
||||
// If a insert location control was specified find it in the list of controls
|
||||
int nInsertLocation = m_Controls.InvalidIndex();
|
||||
if ( pInsertBeforeControl )
|
||||
{
|
||||
nInsertLocation = m_Controls.Find( pInsertBeforeControl );
|
||||
}
|
||||
|
||||
// Add the control to the group
|
||||
if ( nInsertLocation != m_Controls.InvalidIndex() )
|
||||
{
|
||||
m_Controls.InsertBefore( nInsertLocation, pControl );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Controls.AddToTail( pControl );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove a control from the group. This will only search the immediate group for the
|
||||
// specified control and remove it. It will not remove the control if it is in a child of this
|
||||
// group. Returns false if the control was not found.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::RemoveControl( const CDmElement *pControl )
|
||||
{
|
||||
if ( pControl == NULL )
|
||||
return false;
|
||||
|
||||
int nControls = m_Controls.Count();
|
||||
for ( int iControl = 0; iControl < nControls; ++iControl )
|
||||
{
|
||||
if ( pControl == m_Controls[ iControl ] )
|
||||
{
|
||||
m_Controls.Remove( iControl );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get a flat list of all of the controls in the group. If the recursive flag is true
|
||||
// a flat list of all of the controls in the entire sub-tree of the group will be returned. If
|
||||
// the recursive flag is false on
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::GetControlsInGroup( CUtlVector< CDmElement* > &controlList, bool recursive ) const
|
||||
{
|
||||
// If the recursive flag is set add all of the controls
|
||||
// of the entire tree of each child group within the group.
|
||||
if ( recursive )
|
||||
{
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
pChild->GetControlsInGroup( controlList, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the controls from this group.
|
||||
int nControls = m_Controls.Count();
|
||||
for ( int iControl = 0; iControl < nControls; ++iControl )
|
||||
{
|
||||
CDmElement *pControl = m_Controls[ iControl ];
|
||||
if ( pControl )
|
||||
{
|
||||
controlList.AddToTail( pControl );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Find a control with the specified name within the group. If the recursive flag is true
|
||||
// the entire sub-tree of the group will be searched, otherwise only the immediate control will
|
||||
// be searched for the group. If the parent group pointer is provided it will be returned with the
|
||||
// group to which the control belongs directly.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmElement *CDmeControlGroup::FindControlByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup )
|
||||
{
|
||||
// Search the controls contained directly by the group for one with the specified name.
|
||||
int nControls = m_Controls.Count();
|
||||
for ( int iControl = 0; iControl < nControls; ++iControl )
|
||||
{
|
||||
CDmElement *pControl = m_Controls[ iControl ];
|
||||
if ( pControl )
|
||||
{
|
||||
if ( V_stricmp( pControl->GetName(), pchName ) == 0 )
|
||||
{
|
||||
if ( pParentGroup )
|
||||
{
|
||||
*pParentGroup = this;
|
||||
}
|
||||
|
||||
return pControl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the control was not found in the controls contained directly by the group
|
||||
// search the children and their sub-trees if the recursive flag is true.
|
||||
if ( recursive )
|
||||
{
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
CDmElement *pControl = pChild->FindControlByName( pchName, true, pParentGroup );
|
||||
if ( pControl )
|
||||
return pControl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Find the group to which the specified control belongs, if any. This function searches
|
||||
// for any control groups which reference the specified control. It simply returns the first one
|
||||
// it finds, as a control should only every belong to a single control group.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::FindGroupContainingControl( const CDmElement* pControl )
|
||||
{
|
||||
return FindReferringElement< CDmeControlGroup >( pControl, "controls" );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Make the specified group a child of this group. The group will be removed from the
|
||||
// child list of any other group to which it may currently belong.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::AddChild( CDmeControlGroup *pGroup, const CDmeControlGroup *pInsertBeforeGroup )
|
||||
{
|
||||
// Can't make a group its own child
|
||||
Assert( pGroup != this );
|
||||
if ( pGroup == this )
|
||||
return;
|
||||
|
||||
// Remove the group from its current control group if it belongs one.
|
||||
CDmeControlGroup *pParentGroup = pGroup->FindParent();
|
||||
if ( pParentGroup )
|
||||
{
|
||||
pParentGroup->RemoveChild( pGroup );
|
||||
}
|
||||
|
||||
// If a insert location group was specified find it in the list of children
|
||||
int nInsertLocation = m_Children.InvalidIndex();
|
||||
if ( pInsertBeforeGroup )
|
||||
{
|
||||
nInsertLocation = m_Children.Find( pInsertBeforeGroup );
|
||||
}
|
||||
|
||||
// Add the specified group as child of this group.
|
||||
if ( nInsertLocation != m_Children.InvalidIndex() )
|
||||
{
|
||||
m_Children.InsertBefore( nInsertLocation, pGroup );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Children.AddToTail( pGroup );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove the specified child group. Searches the immediate children of the node for the
|
||||
// specified group and removes it from the child list if the group is found. Returns true if the
|
||||
// group is found, false if the group is not found.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::RemoveChild( const CDmeControlGroup *pGroup )
|
||||
{
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
if ( m_Children[ iChild ] == pGroup )
|
||||
{
|
||||
m_Children.Remove( iChild );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Move the specified child group to the top of the list
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::MoveChildToTop( const CDmeControlGroup *pGroup )
|
||||
{
|
||||
// Make sure the group is actually a child, and move it
|
||||
// to the top of the list if it is not already there.
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 1; iChild < nChildren; ++iChild )
|
||||
{
|
||||
if ( m_Children[ iChild ] == pGroup )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
m_Children.Remove( iChild );
|
||||
m_Children.InsertBefore( 0, pChild );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Move the specified child group to the bottom of the list
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::MoveChildToBottom( const CDmeControlGroup *pGroup )
|
||||
{
|
||||
// Make sure the group is actually a child, and move it
|
||||
// to the bottom of the list if it is not already there.
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < (nChildren - 1); ++iChild )
|
||||
{
|
||||
if ( m_Children[ iChild ] == pGroup )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
m_Children.Remove( iChild );
|
||||
m_Children.AddToTail( pChild );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compare the two groups by name for an ascending sort
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeControlGroup::CompareByNameAscending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB )
|
||||
{
|
||||
return V_stricmp( (*pGroupA)->GetName(), (*pGroupB)->GetName() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compare the two groups by name for a descending sort
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeControlGroup::CompareByNameDecending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB )
|
||||
{
|
||||
return V_stricmp( (*pGroupB)->GetName(), (*pGroupA)->GetName() );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Sore the children by name
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SortChildrenByName( bool bAscending )
|
||||
{
|
||||
// Copy the children into a temporary array to be sorted.
|
||||
int nNumChildren = m_Children.Count();
|
||||
CUtlVector< CDmeControlGroup * > sortedList( 0, nNumChildren );
|
||||
|
||||
for ( int iChild = 0; iChild < nNumChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pGroup = m_Children[ iChild ];
|
||||
if ( pGroup )
|
||||
{
|
||||
sortedList.AddToTail( pGroup );
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the temporary array in ascending or descending order
|
||||
if ( bAscending )
|
||||
{
|
||||
sortedList.Sort( CompareByNameAscending );
|
||||
}
|
||||
else
|
||||
{
|
||||
sortedList.Sort( CompareByNameDecending );
|
||||
}
|
||||
|
||||
// Remove all of the children from the original list and then add them back in sorted order
|
||||
m_Children.RemoveAll();
|
||||
int nNumSorted = sortedList.Count();
|
||||
for ( int iChild = 0; iChild < nNumSorted; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pGroup = sortedList[ iChild ];
|
||||
if ( pGroup )
|
||||
{
|
||||
m_Children.AddToTail( pGroup );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Determine if the group has child of the specified name
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::HasChildGroup( const char *pchName, bool recursive )
|
||||
{
|
||||
if ( FindChildByName( pchName, recursive ) == NULL )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Find the child group with the specified name. If the recursive flag is true the entire
|
||||
// sub-tree of the group will be searched, otherwise only the immediate children of the group will
|
||||
// be searched for the specified child. If a parent group pointer is provided it will be returned
|
||||
// with the immediate parent in which the child was located.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::FindChildByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup )
|
||||
{
|
||||
// Search the immediate children for a group with the specified name.
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
if ( V_stricmp( pChild->GetName(), pchName ) == 0 )
|
||||
{
|
||||
if ( pParentGroup )
|
||||
{
|
||||
*pParentGroup = this;
|
||||
}
|
||||
return pChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the group was not found in the immediate children of the current group and the recursive
|
||||
// flag is set, search the sub-trees of all the children for the specified group.
|
||||
if ( recursive )
|
||||
{
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
CDmeControlGroup *pGroup = pChild->FindChildByName( pchName, true, pParentGroup );
|
||||
if ( pGroup )
|
||||
return pGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Find the parent of the group. Searches for groups which reference this group as a
|
||||
// child. Each group is allowed to be the child of only one group, so the first group found is
|
||||
// returned.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::FindParent() const
|
||||
{
|
||||
const static CUtlSymbolLarge symChildren = g_pDataModel->GetSymbol( "children" );
|
||||
CDmeControlGroup *pParent = FindReferringElement< CDmeControlGroup >( this, symChildren );
|
||||
return pParent;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Determine if this group is an ancestor of the specified group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::IsAncestorOfGroup( const CDmeControlGroup *pGroup ) const
|
||||
{
|
||||
if ( pGroup == NULL )
|
||||
return false;
|
||||
|
||||
const CDmeControlGroup *pCurrentGroup = pGroup;
|
||||
const CDmeControlGroup *pParent = pGroup->FindParent();
|
||||
|
||||
while ( pParent )
|
||||
{
|
||||
if ( pParent == this )
|
||||
return true;
|
||||
|
||||
pCurrentGroup = pParent;
|
||||
pParent = pParent->FindParent();
|
||||
Assert( pCurrentGroup != pParent );
|
||||
if ( pCurrentGroup == pParent )
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Create a control group with the provided name and add it to the specified parent. If a child of
|
||||
// the specified name already exists it will be returned and no new group will be created.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::CreateControlGroup( const char *pchName )
|
||||
{
|
||||
CDmeControlGroup *pExistingGroup = FindChildByName( pchName, false );
|
||||
if ( pExistingGroup )
|
||||
return pExistingGroup;
|
||||
|
||||
// Create the new control group with the specified name
|
||||
CDmeControlGroup *pNewGroup = CreateElement< CDmeControlGroup >( pchName, GetFileId() );
|
||||
|
||||
// Add the group to as a child of this group
|
||||
AddChild( pNewGroup );
|
||||
|
||||
return pNewGroup;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get a flat list of all of the groups in sub-tree of the group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::GetAllChildren( CUtlVector< DmElementHandle_t > &childGroupList ) const
|
||||
{
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
childGroupList.AddToTail( pChild->GetHandle() );
|
||||
pChild->GetAllChildren( childGroupList );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Recursively destroy the children of the specified group which have no controls or sub groups
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::DestroyEmptyChildren_R( CDmeControlGroup *pGroup )
|
||||
{
|
||||
int nNumChildren = pGroup->m_Children.Count();
|
||||
|
||||
// Build a list of the children which are empty and should be destroyed. This
|
||||
// process will recursively remove empty children of the children so that if
|
||||
// a child has only empty sub-children then it will still be removed.
|
||||
CUtlVector< CDmeControlGroup * > childrenToDestroy( 0, nNumChildren );
|
||||
for ( int iChild = 0; iChild < nNumChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = pGroup->m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
if ( DestroyEmptyChildren_R( pChild ) )
|
||||
{
|
||||
childrenToDestroy.AddToTail( pChild );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the empty children
|
||||
int nNumToDestroy = childrenToDestroy.Count();
|
||||
for ( int iChild = 0; iChild < nNumToDestroy; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = childrenToDestroy[ iChild ];
|
||||
pGroup->RemoveChild( pChild );
|
||||
}
|
||||
|
||||
// If this node is now empty return true indicating that it may be destroyed
|
||||
return ( ( pGroup->m_Children.Count() == 0 ) && ( pGroup->m_Controls.Count() == 0 ) );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Destroy all of the empty children of the group, will not destroy this group even it is empty.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::DestroyEmptyChildren()
|
||||
{
|
||||
DestroyEmptyChildren_R( this );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Destroy the control group, moving all of its children and controls into this node
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::DestroyGroup( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive )
|
||||
{
|
||||
if ( pGroup == NULL )
|
||||
return;
|
||||
|
||||
// Remove the group from its parent
|
||||
CDmeControlGroup *pParent = pGroup->FindParent();
|
||||
if ( pParent )
|
||||
{
|
||||
pParent->RemoveChild( pGroup );
|
||||
if ( pRecipient == NULL )
|
||||
{
|
||||
pRecipient = pParent;
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the group and all of its children if specified
|
||||
DestroyGroup_R( pGroup, pRecipient, recursive );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Recursively destroy the child groups of the specified group and and the controls to the
|
||||
// specified recipient group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::DestroyGroup_R( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive )
|
||||
{
|
||||
if ( pGroup == NULL )
|
||||
return;
|
||||
|
||||
// If the group is not empty there must be a recipient to receive its controls and groups
|
||||
if ( pRecipient == NULL && !pGroup->IsEmpty() )
|
||||
{
|
||||
Assert( pGroup->IsEmpty() || pRecipient );
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate through the children, if recursive destroy the
|
||||
// children otherwise copy the children to the recipient.
|
||||
int nChildren = pGroup->m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
CDmeControlGroup *pChild = pGroup->m_Children[ iChild ];
|
||||
if ( pChild )
|
||||
{
|
||||
if ( recursive )
|
||||
{
|
||||
DestroyGroup_R( pChild, pRecipient, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
pRecipient->m_Children.AddToTail( pChild );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy all the controls of the node into the recipient
|
||||
int nControls = pGroup->m_Controls.Count();
|
||||
for ( int iControl = 0; iControl < nControls; ++iControl )
|
||||
{
|
||||
CDmElement *pControl = pGroup->m_Controls[ iControl ];
|
||||
pRecipient->m_Controls.AddToTail( pControl );
|
||||
}
|
||||
|
||||
// Destroy the group
|
||||
DestroyElement( pGroup );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Remove all of the children and controls from the group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::RemoveAllChildrenAndControls()
|
||||
{
|
||||
m_Children.RemoveAll();
|
||||
m_Controls.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the color of the group, this is the color that is used when displaying the group in
|
||||
// the user interface.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SetGroupColor( const Color &groupColor, bool bRecursive )
|
||||
{
|
||||
m_GroupColor = groupColor;
|
||||
|
||||
if ( !bRecursive )
|
||||
return;
|
||||
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
if ( m_Children[ iChild ] )
|
||||
{
|
||||
m_Children[ iChild ]->SetGroupColor( groupColor, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the color to be used on the controls of the group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SetControlColor( const Color &controlColor, bool bRecursive )
|
||||
{
|
||||
m_ControlColor = controlColor;
|
||||
|
||||
if ( !bRecursive )
|
||||
return;
|
||||
|
||||
int nChildren = m_Children.Count();
|
||||
for ( int iChild = 0; iChild < nChildren; ++iChild )
|
||||
{
|
||||
if ( m_Children[ iChild ] )
|
||||
{
|
||||
m_Children[ iChild ]->SetControlColor( controlColor, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the visible state of the group
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SetVisible( bool bVisible )
|
||||
{
|
||||
m_Visible = bVisible;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Enable or disable selection of the controls
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SetSelectable( bool bSelectable )
|
||||
{
|
||||
m_Selectable = bSelectable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Enable or disable control snapping
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeControlGroup::SetSnappable( bool bSnappable )
|
||||
{
|
||||
m_Snappable = bSnappable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Determine if there are any controls or children in the group
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::IsEmpty() const
|
||||
{
|
||||
if ( m_Controls.Count() > 0 ) return false;
|
||||
if ( m_Children.Count() > 0 ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is the group visible
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::IsVisible() const
|
||||
{
|
||||
CDmeControlGroup *pParent = FindParent();
|
||||
if ( pParent && !pParent->IsVisible() )
|
||||
return false;
|
||||
|
||||
return m_Visible;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Can controls in the group be selected in the viewport
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::IsSelectable() const
|
||||
{
|
||||
CDmeControlGroup *pParent = FindParent();
|
||||
if ( pParent && !pParent->IsSelectable() )
|
||||
return false;
|
||||
|
||||
return m_Selectable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Can controls in the group be snapped to in the viewport
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeControlGroup::IsSnappable() const
|
||||
{
|
||||
CDmeControlGroup *pParent = FindParent();
|
||||
if ( pParent && !pParent->IsSnappable() )
|
||||
return false;
|
||||
|
||||
return m_Snappable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find the shared ancestor between this control group and the specified control
|
||||
// group. Will return NULL if groups are not in the same tree and do not share a
|
||||
// common ancestor. If one group is an ancestor of the other group then that
|
||||
// group will be returned, so result may be one of the nodes which is not
|
||||
// technically an ancestor of that node.
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::FindCommonAncestor( CDmeControlGroup *pControlGroupB )
|
||||
{
|
||||
CDmeControlGroup *pControlGroupA = this;
|
||||
|
||||
// If the specified group is this group then
|
||||
// the common ancestor is the group itself.
|
||||
if ( pControlGroupA == pControlGroupB )
|
||||
return pControlGroupA;
|
||||
|
||||
// Build the path from each group to the root
|
||||
CUtlVector< CDmeControlGroup * > pathToGroupA;
|
||||
CUtlVector< CDmeControlGroup * > pathToGroupB;
|
||||
pControlGroupA->BuildPathFromRoot( pathToGroupA );
|
||||
pControlGroupB->BuildPathFromRoot( pathToGroupB );
|
||||
|
||||
// Now walk each of the the paths until they diverge
|
||||
CDmeControlGroup *pCommonGroup = NULL;
|
||||
int nNumSteps = MIN( pathToGroupA.Count(), pathToGroupB.Count() );
|
||||
|
||||
int iStep = 0;
|
||||
while ( iStep < nNumSteps )
|
||||
{
|
||||
if ( pathToGroupA[ iStep ] != pathToGroupB[ iStep ] )
|
||||
break;
|
||||
|
||||
pCommonGroup = pathToGroupA[ iStep ];
|
||||
++iStep;
|
||||
}
|
||||
|
||||
return pCommonGroup;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find the root control group which this control group is in the sub tree of.
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeControlGroup *CDmeControlGroup::FindRootControlGroup()
|
||||
{
|
||||
CDmeControlGroup *pCurrent = this;
|
||||
CDmeControlGroup *pParent = pCurrent->FindParent();
|
||||
|
||||
while ( pParent )
|
||||
{
|
||||
pCurrent = pParent;
|
||||
pParent = pParent->FindParent();
|
||||
}
|
||||
|
||||
return pCurrent;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Build a list of the control group that form the path to the root of the tree
|
||||
// to which the control group belongs
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeControlGroup::BuildPathFromRoot( CUtlVector< CDmeControlGroup * > &pathToGroup )
|
||||
{
|
||||
CUtlVector< CDmeControlGroup * > pathToRoot( 0, 16 );
|
||||
|
||||
CDmeControlGroup *pCurrent = this;
|
||||
|
||||
while ( pCurrent )
|
||||
{
|
||||
pathToRoot.AddToTail( pCurrent );
|
||||
pCurrent = pCurrent->FindParent();
|
||||
}
|
||||
|
||||
int nNumGroups = pathToRoot.Count();
|
||||
pathToGroup.SetCount( nNumGroups );
|
||||
|
||||
for ( int iGroup = 0; iGroup < nNumGroups; ++iGroup )
|
||||
{
|
||||
pathToGroup[ iGroup ] = pathToRoot[ nNumGroups - 1 - iGroup ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find the animation set associated with the control group
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeAnimationSet *CDmeControlGroup::FindAnimationSet( bool bSearchAncestors ) const
|
||||
{
|
||||
const static CUtlSymbolLarge symRootControlGroup = g_pDataModel->GetSymbol( "rootControlGroup" );
|
||||
const CDmeControlGroup *pCurrent = this;
|
||||
|
||||
while ( pCurrent )
|
||||
{
|
||||
CDmeAnimationSet *pAnimationSet = FindReferringElement< CDmeAnimationSet >( pCurrent, symRootControlGroup );
|
||||
if ( pAnimationSet != NULL )
|
||||
return pAnimationSet;
|
||||
|
||||
if ( bSearchAncestors == false )
|
||||
break;
|
||||
|
||||
const CDmeControlGroup *pParent = pCurrent->FindParent();
|
||||
if ( pCurrent == pParent )
|
||||
break;
|
||||
|
||||
pCurrent = pParent;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
95
movieobjects/dmecycle.cpp
Normal file
95
movieobjects/dmecycle.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// A class representing a procedural texture
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmecycle.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include <math.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Consts
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INT_FLOAT_SCALE 0.000001f
|
||||
//#define USE_NEW_WAY
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeCycle, CDmeCycle );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeCycle::OnConstruction()
|
||||
{
|
||||
m_cycleRate.Init( this, "cycleRate" );
|
||||
m_prevCycle.Init( this, "prevCycle" );
|
||||
m_lastCycleResetTime.Init( this, "lastCycleResetTime" );
|
||||
m_lastCycleResetValue.Init( this, "lastCycleResetValue" );
|
||||
}
|
||||
|
||||
void CDmeCycle::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeCycle::SetCycleRate( float flCycleRate )
|
||||
{
|
||||
m_cycleRate = flCycleRate;
|
||||
}
|
||||
|
||||
void CDmeCycle::SetPrevCycle( float flPrevCycle )
|
||||
{
|
||||
m_prevCycle = (int)(flPrevCycle / INT_FLOAT_SCALE);
|
||||
}
|
||||
|
||||
void CDmeCycle::SetCycle( float flCycle, float flCurTime )
|
||||
{
|
||||
#ifdef USE_NEW_WAY
|
||||
float const flCycleDelta = fabs( flCycle - GetPrevCycle() );
|
||||
|
||||
// NOTE: Overlays depend on this logic - record if cycle==0. There may be a better way to
|
||||
// do this, but if an overlay is at 0 while it's dormant (ie its weight==0), we need to
|
||||
// record at the moment its weight>0.
|
||||
bool bForceCycleRecord = flCycle == 0.0f;
|
||||
|
||||
if ( bForceCycleRecord || flCycleDelta >= 0.1f )
|
||||
{
|
||||
// Store this time
|
||||
m_lastCycleResetTime = (int)(flCurTime / INT_FLOAT_SCALE);
|
||||
|
||||
// For this method, m_cycle is only recorded when a reset of some kind has occurred
|
||||
m_lastCycleResetValue = (int)(flCycle / INT_FLOAT_SCALE);
|
||||
|
||||
DevMsg(" resetting cycle at: time=%f cycle=%f\n", flCurTime, flCycle );
|
||||
}
|
||||
#else
|
||||
m_lastCycleResetValue = (int)(flCycle / INT_FLOAT_SCALE);
|
||||
#endif
|
||||
|
||||
// Store as previous cycle
|
||||
SetPrevCycle( flCycle );
|
||||
}
|
||||
|
||||
float CDmeCycle::GetCycleRate() const
|
||||
{
|
||||
return m_cycleRate;
|
||||
}
|
||||
|
||||
float CDmeCycle::GetPrevCycle() const
|
||||
{
|
||||
return m_prevCycle * INT_FLOAT_SCALE;
|
||||
}
|
||||
|
||||
float CDmeCycle::GetCycle( float flCurTime ) const
|
||||
{
|
||||
#ifdef USE_NEW_WAY
|
||||
float const dt = flCurTime - INT_FLOAT_SCALE * m_lastCycleResetTime;
|
||||
float const flCycle = INT_FLOAT_SCALE * m_lastCycleResetValue + GetCycleRate() * dt; Assert( flCycle >= 0.0f && flCycle <= 2.0f );
|
||||
return fmod( flCycle, 1.0f ); // In case it's 1.0f
|
||||
#else
|
||||
return INT_FLOAT_SCALE * m_lastCycleResetValue;
|
||||
#endif
|
||||
}
|
||||
1787
movieobjects/dmedag.cpp
Normal file
1787
movieobjects/dmedag.cpp
Normal file
File diff suppressed because it is too large
Load Diff
323
movieobjects/dmedccmakefile.cpp
Normal file
323
movieobjects/dmedccmakefile.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Describes an asset: something that is compiled from sources,
|
||||
// in potentially multiple steps, to a compiled resource
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "movieobjects/dmedccmakefile.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier2/fileutils.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceDCCFile, CDmeSourceDCCFile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceDCCFile::OnConstruction()
|
||||
{
|
||||
m_RootDCCObjects.Init( this, "rootDCCObjects" );
|
||||
m_ExportType.InitAndSet( this, "exportType", 0 );
|
||||
m_FrameStart.InitAndSet( this, "frameStart", 0.0f );
|
||||
m_FrameEnd.InitAndSet( this, "frameEnd", 0.0f );
|
||||
m_FrameIncrement.InitAndSet( this, "frameIncrement", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeSourceDCCFile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaFile, CDmeSourceMayaFile );
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaModelFile, CDmeSourceMayaModelFile );
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaAnimationFile, CDmeSourceMayaAnimationFile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceMayaFile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeSourceMayaFile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeSourceMayaModelFile::OnConstruction()
|
||||
{
|
||||
m_ExportType = 0;
|
||||
}
|
||||
|
||||
void CDmeSourceMayaModelFile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeSourceMayaAnimationFile::OnConstruction()
|
||||
{
|
||||
m_ExportType = 1;
|
||||
}
|
||||
|
||||
void CDmeSourceMayaAnimationFile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceXSIFile, CDmeSourceXSIFile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceXSIFile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeSourceXSIFile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeDCCMakefile, CDmeDCCMakefile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDCCMakefile::OnConstruction()
|
||||
{
|
||||
m_bFlushFile = false;
|
||||
}
|
||||
|
||||
void CDmeDCCMakefile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compile assets
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDCCMakefile::GetOutputs( CUtlVector<CUtlString> &fullPaths )
|
||||
{
|
||||
fullPaths.RemoveAll();
|
||||
|
||||
char pOutputName[MAX_PATH];
|
||||
Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
|
||||
if ( !pOutputName[0] )
|
||||
return;
|
||||
|
||||
// FIXME: We need to come up with an appropriate directory structure for export
|
||||
char pOutputDir[MAX_PATH];
|
||||
GetMakefilePath( pOutputDir, sizeof(pOutputDir) );
|
||||
if ( !pOutputDir[0] )
|
||||
return;
|
||||
|
||||
Q_StripTrailingSlash( pOutputDir );
|
||||
char pFullPath[MAX_PATH];
|
||||
Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.dmx", pOutputDir, pOutputName );
|
||||
fullPaths.AddToTail( pFullPath );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys the output element associated with this makefile
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CDmeDCCMakefile::CreateOutputElement( )
|
||||
{
|
||||
if ( m_bFlushFile )
|
||||
{
|
||||
m_bFlushFile = false;
|
||||
if ( GetFileId() != DMFILEID_INVALID )
|
||||
{
|
||||
// NOTE: CDmeHandles will correctly re-hook up to the new makefile after load
|
||||
// If the file fails to load, we have the copy. If the file correctly has the make in it
|
||||
// it will replace this copy I made
|
||||
CDmeHandle< CDmeDCCMakefile > hMakefileOld;
|
||||
hMakefileOld = this;
|
||||
|
||||
// NOTE NOTE NOTE
|
||||
// UnloadFile essentially calls delete this!
|
||||
// So don't refer to any state in this DmElement after that
|
||||
DmFileId_t fileId = GetFileId();
|
||||
g_pDataModel->UnloadFile( fileId );
|
||||
|
||||
CDmElement *pRoot = NULL;
|
||||
if ( g_pDataModel->RestoreFromFile( g_pDataModel->GetFileName( fileId ), NULL, NULL, &pRoot, CR_DELETE_OLD ) != DMFILEID_INVALID )
|
||||
{
|
||||
// NOTE: Unload/restore kills the this pointer, we need to redo this
|
||||
if ( hMakefileOld.Get() )
|
||||
{
|
||||
hMakefileOld->SetDirty( false );
|
||||
return hMakefileOld->CreateOutputElement();
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: We expect file backup prior to compile to avoid really fatal errors
|
||||
// This case happens if the file failed to load. In this case, we must use
|
||||
// the copy of the makefile
|
||||
Assert( 0 );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// The output element is the root element containing the makefile
|
||||
return FindReferringElement< CDmElement >( this, "makefile" );
|
||||
}
|
||||
|
||||
void CDmeDCCMakefile::DestroyOutputElement( CDmElement *pOutput )
|
||||
{
|
||||
m_bFlushFile = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMayaMakefile, CDmeMayaMakefile );
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMayaModelMakefile, CDmeMayaModelMakefile );
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMayaAnimationMakefile, CDmeMayaAnimationMakefile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMayaMakefile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMayaMakefile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMayaModelMakefile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMayaModelMakefile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMayaAnimationMakefile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMayaAnimationMakefile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns source types
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_pMayaModelSourceTypes[] =
|
||||
{
|
||||
{ "DmeSourceMayaModelFile", "Maya Model File", true, "makefiledir:../maya", "*.ma;*.mb", "Maya File (*.ma,*.mb)" },
|
||||
{ NULL, NULL, false, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
DmeMakefileType_t* CDmeMayaModelMakefile::GetSourceTypes()
|
||||
{
|
||||
return s_pMayaModelSourceTypes;
|
||||
}
|
||||
|
||||
static DmeMakefileType_t s_pMayaAnimationSourceTypes[] =
|
||||
{
|
||||
{ "DmeSourceMayaAnimationFile", "Maya Animation File", true, "makefiledir:../maya", "*.ma;*.mb", "Maya File (*.ma,*.mb)" },
|
||||
{ NULL, NULL, false, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
DmeMakefileType_t* CDmeMayaAnimationMakefile::GetSourceTypes()
|
||||
{
|
||||
return s_pMayaAnimationSourceTypes;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Makefile type
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_MayaModelMakefileType =
|
||||
{
|
||||
"DmeMayaModelMakefile", "Maya Model Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)"
|
||||
};
|
||||
|
||||
DmeMakefileType_t *CDmeMayaModelMakefile::GetMakefileType()
|
||||
{
|
||||
return &s_MayaModelMakefileType;
|
||||
}
|
||||
|
||||
static DmeMakefileType_t s_MayaAnimationMakefileType =
|
||||
{
|
||||
"DmeMayaAnimationMakefile", "Maya Animation Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)"
|
||||
};
|
||||
|
||||
DmeMakefileType_t *CDmeMayaAnimationMakefile::GetMakefileType()
|
||||
{
|
||||
return &s_MayaAnimationMakefileType;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeXSIMakefile, CDmeXSIMakefile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeXSIMakefile::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeXSIMakefile::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns source types
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_pXSISourceTypes[] =
|
||||
{
|
||||
{ "DmeSourceXSIFile", "XSI File", true, "makefiledir:../xsi", "*.xsi", "XSI File (*.xsi)" },
|
||||
{ NULL, NULL, false, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
DmeMakefileType_t* CDmeXSIMakefile::GetSourceTypes()
|
||||
{
|
||||
return s_pXSISourceTypes;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Makefile type
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_XSIMakefileType =
|
||||
{
|
||||
"DmeXSIMakefile", "XSI Model Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)",
|
||||
};
|
||||
|
||||
DmeMakefileType_t *CDmeXSIMakefile::GetMakefileType()
|
||||
{
|
||||
return &s_XSIMakefileType;
|
||||
}
|
||||
|
||||
|
||||
265
movieobjects/dmedrawsettings.cpp
Normal file
265
movieobjects/dmedrawsettings.cpp
Normal file
@@ -0,0 +1,265 @@
|
||||
//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/utlrbtree.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
#include "movieobjects/dmedrawsettings.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeDrawSettings, CDmeDrawSettings );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statics
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeDrawSettings::s_bWireframeMaterialInitialized( false );
|
||||
CMaterialReference CDmeDrawSettings::s_WireframeMaterial;
|
||||
bool CDmeDrawSettings::s_bWireframeOnShadedMaterialInitialized( false );
|
||||
CMaterialReference CDmeDrawSettings::s_WireframeOnShadedMaterial;
|
||||
bool CDmeDrawSettings::s_bFlatGrayMaterial( false );
|
||||
CMaterialReference CDmeDrawSettings::s_FlatGrayMaterial;
|
||||
bool CDmeDrawSettings::s_bUnlitGrayMaterial( false );
|
||||
CMaterialReference CDmeDrawSettings::s_UnlitGrayMaterial;
|
||||
|
||||
CUtlRBTree< CUtlSymbolLarge > CDmeDrawSettings::s_KnownDrawableTypes;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::OnConstruction()
|
||||
{
|
||||
if ( s_KnownDrawableTypes.Count() == 0 )
|
||||
{
|
||||
BuildKnownDrawableTypes();
|
||||
}
|
||||
|
||||
SetDefLessFunc< CUtlRBTree< CUtlSymbolLarge > >( m_NotDrawable );
|
||||
m_NotDrawable.RemoveAll();
|
||||
|
||||
m_DrawType.InitAndSet( this, "drawType", static_cast< int >( DRAW_SMOOTH ) );
|
||||
m_bBackfaceCulling.InitAndSet( this, "backfaceCulling", true );
|
||||
m_bWireframeOnShaded.InitAndSet( this, "wireframeOnShaded", false );
|
||||
m_bXRay.InitAndSet( this, "xray", false );
|
||||
m_bGrayShade.InitAndSet( this, "grayShade", false );
|
||||
m_bNormals.InitAndSet( this, "normals", false );
|
||||
m_NormalLength.InitAndSet( this, "normalLength", 1.0 );
|
||||
m_Color.InitAndSet( this, "color", Color( 0, 0, 0, 1 ) );
|
||||
m_bDeltaHighlight.InitAndSet( this, "highlightDeltas", false );
|
||||
m_flHighlightSize.InitAndSet( this, "highlightSize", 1.5f );
|
||||
m_cHighlightColor.InitAndSet( this, "highlightColor", Color( 0xff, 0x14, 0x93, 0xff ) ); // Deep Pink
|
||||
|
||||
m_IsAMaterialBound = false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::Resolve()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Wireframe
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::BindWireframe()
|
||||
{
|
||||
if ( !s_bWireframeMaterialInitialized )
|
||||
{
|
||||
s_bWireframeMaterialInitialized = true;
|
||||
|
||||
KeyValues *pKeyValues = new KeyValues( "wireframe" );
|
||||
pKeyValues->SetInt( "$decal", 0 );
|
||||
pKeyValues->SetInt( "$vertexcolor", 1 );
|
||||
pKeyValues->SetInt( "$ignorez", 1 );
|
||||
s_WireframeMaterial.Init( "__DmeWireframe", pKeyValues );
|
||||
}
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->Bind( s_WireframeMaterial );
|
||||
m_IsAMaterialBound = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Wireframe as a decal
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::BindWireframeOnShaded()
|
||||
{
|
||||
if ( !s_bWireframeOnShadedMaterialInitialized )
|
||||
{
|
||||
s_bWireframeOnShadedMaterialInitialized = true;
|
||||
|
||||
KeyValues *pKeyValues = new KeyValues( "wireframe" );
|
||||
pKeyValues->SetInt( "$decal", 0 );
|
||||
pKeyValues->SetInt( "$vertexcolor", 1 );
|
||||
pKeyValues->SetInt( "$ignorez", 0 );
|
||||
s_WireframeOnShadedMaterial.Init( "__DmeWireframeOnShaded", pKeyValues );
|
||||
}
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->Bind( s_WireframeOnShadedMaterial );
|
||||
m_IsAMaterialBound = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flat Gray Shaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::BindGray()
|
||||
{
|
||||
if ( !s_bFlatGrayMaterial )
|
||||
{
|
||||
s_bFlatGrayMaterial = true;
|
||||
|
||||
KeyValues *pKeyValues = new KeyValues( "VertexLitGeneric" );
|
||||
pKeyValues->SetInt( "$model", 1 );
|
||||
s_FlatGrayMaterial.Init( "__DmeFlatGray", pKeyValues );
|
||||
}
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->Bind( s_FlatGrayMaterial );
|
||||
m_IsAMaterialBound = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flat Gray Shaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::BindUnlitGray()
|
||||
{
|
||||
if ( !s_bUnlitGrayMaterial )
|
||||
{
|
||||
s_bUnlitGrayMaterial = true;
|
||||
|
||||
KeyValues *pKeyValues = new KeyValues( "UnlitGeneric" );
|
||||
pKeyValues->SetInt( "$model", 1 );
|
||||
pKeyValues->SetInt( "$vertexcolor", 1 );
|
||||
s_UnlitGrayMaterial.Init( "__DmeUnlitGray", pKeyValues );
|
||||
}
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->Bind( s_UnlitGrayMaterial );
|
||||
m_IsAMaterialBound = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeDrawSettings::Drawable( CDmElement *pElement )
|
||||
{
|
||||
if ( m_NotDrawable.IsValidIndex( m_NotDrawable.Find( pElement->GetType() ) ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::BuildKnownDrawableTypes()
|
||||
{
|
||||
SetDefLessFunc< CUtlRBTree< CUtlSymbolLarge > >( s_KnownDrawableTypes );
|
||||
|
||||
s_KnownDrawableTypes.RemoveAll();
|
||||
|
||||
s_KnownDrawableTypes.InsertIfNotFound( g_pDataModel->GetSymbol( "DmeMesh" ) );
|
||||
s_KnownDrawableTypes.InsertIfNotFound( g_pDataModel->GetSymbol( "DmeJoint" ) );
|
||||
s_KnownDrawableTypes.InsertIfNotFound( g_pDataModel->GetSymbol( "DmeModel" ) );
|
||||
s_KnownDrawableTypes.InsertIfNotFound( g_pDataModel->GetSymbol( "DmeAttachment" ) );
|
||||
|
||||
m_NotDrawable.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDrawSettings::DrawDag( CDmeDag *pDag )
|
||||
{
|
||||
if ( !pDag )
|
||||
return;
|
||||
|
||||
m_vHighlightPoints.RemoveAll();
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
m_IsAMaterialBound = false;
|
||||
|
||||
if ( GetDeltaHighlight() )
|
||||
{
|
||||
BindUnlitGray();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !Shaded() )
|
||||
{
|
||||
BindWireframe();
|
||||
}
|
||||
else if ( GetGrayShade() )
|
||||
{
|
||||
BindGray();
|
||||
}
|
||||
}
|
||||
|
||||
pDag->Draw( this );
|
||||
|
||||
m_IsAMaterialBound = false;
|
||||
|
||||
if ( GetDeltaHighlight() || ( GetWireframeOnShaded() && Shaded() ) )
|
||||
{
|
||||
VMatrix m;
|
||||
|
||||
pRenderContext->GetMatrix( MATERIAL_PROJECTION, &m );
|
||||
|
||||
/* Extract the near and far clipping plane values from projection matrix
|
||||
float c = m[ 2 ][ 2 ];
|
||||
float d = m[ 2 ][ 3 ];
|
||||
|
||||
const float near = d / ( c - 1.0f );
|
||||
const float far = d / ( c + 1.0f );
|
||||
*/
|
||||
|
||||
const float zBias = 0.00025;
|
||||
m[ 2 ][ 2 ] += zBias;
|
||||
m[ 2 ][ 3 ] += zBias;
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_PROJECTION );
|
||||
pRenderContext->PushMatrix();
|
||||
pRenderContext->LoadMatrix( m );
|
||||
|
||||
BindWireframeOnShaded();
|
||||
PushDrawType();
|
||||
SetDrawType( CDmeDrawSettings::DRAW_WIREFRAME );
|
||||
pDag->Draw( this );
|
||||
PopDrawType();
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_PROJECTION );
|
||||
pRenderContext->PopMatrix();
|
||||
}
|
||||
}
|
||||
322
movieobjects/dmeeditortypedictionary.cpp
Normal file
322
movieobjects/dmeeditortypedictionary.cpp
Normal file
@@ -0,0 +1,322 @@
|
||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
|
||||
//
|
||||
// Contains a bunch of information about editor types
|
||||
// Editor types are arbitrary
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "movieobjects/dmeeditortypedictionary.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose DmeEditorAttributeInfo to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeEditorAttributeInfo, CDmeEditorAttributeInfo );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorAttributeInfo::OnConstruction()
|
||||
{
|
||||
m_Widget.Init( this, "widget" );
|
||||
m_bIsVisible.Init( this, "isVisible" );
|
||||
m_bIsReadOnly.Init( this, "isReadOnly" );
|
||||
m_ArrayEntries.Init( this, "arrayEntries" );
|
||||
m_bHideType.Init( this, "hideType" );
|
||||
m_bHideValue.Init( this, "hideValue" );
|
||||
m_Help.Init( this, "help" );
|
||||
|
||||
m_bIsVisible = true;
|
||||
m_bIsReadOnly = false;
|
||||
}
|
||||
|
||||
void CDmeEditorAttributeInfo::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the attribute name this info is associated with
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeEditorAttributeInfo::GetAttributeName() const
|
||||
{
|
||||
return GetName();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the widget name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeEditorAttributeInfo::GetWidgetName() const
|
||||
{
|
||||
return m_Widget.Get();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the info for a entry in an attribute array, if this attribute is an array type
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorAttributeInfo *CDmeEditorAttributeInfo::GetArrayInfo()
|
||||
{
|
||||
return m_ArrayEntries;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the info for an entry in an attribute array
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorAttributeInfo::SetArrayInfo( CDmeEditorAttributeInfo *pInfo )
|
||||
{
|
||||
m_ArrayEntries = pInfo;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// CDmeEditorChoicesInfo, Base class for configuration for choices
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose DmeEditorChoicesInfo to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeEditorChoicesInfo, CDmeEditorChoicesInfo );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorChoicesInfo::OnConstruction()
|
||||
{
|
||||
m_Choices.Init( this, "choices" );
|
||||
m_ChoiceType.Init( this, "choicetype" );
|
||||
}
|
||||
|
||||
void CDmeEditorChoicesInfo::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets/gets choice type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorChoicesInfo::SetChoiceType( const char *pChoiceType )
|
||||
{
|
||||
m_ChoiceType = pChoiceType;
|
||||
}
|
||||
|
||||
const char *CDmeEditorChoicesInfo::GetChoiceType() const
|
||||
{
|
||||
return m_ChoiceType;
|
||||
}
|
||||
|
||||
bool CDmeEditorChoicesInfo::HasChoiceType() const
|
||||
{
|
||||
return m_ChoiceType.Length() > 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the choices
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeEditorChoicesInfo::GetChoiceCount() const
|
||||
{
|
||||
return m_Choices.Count();
|
||||
}
|
||||
|
||||
CDmElement *CDmeEditorChoicesInfo::CreateChoice( const char *pChoiceString )
|
||||
{
|
||||
CDmElement *pChoice = CreateElement< CDmElement >( "", GetFileId() );
|
||||
m_Choices.AddToTail( pChoice );
|
||||
CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pChoiceString );
|
||||
pChoice->SetValue<CUtlSymbolLarge>( "string", symbol );
|
||||
return pChoice;
|
||||
}
|
||||
|
||||
const char *CDmeEditorChoicesInfo::GetChoiceString( int nIndex ) const
|
||||
{
|
||||
Assert( ( nIndex < GetChoiceCount() ) && ( nIndex >= 0 ) );
|
||||
CDmElement *pChoice = m_Choices[nIndex];
|
||||
if ( !pChoice )
|
||||
return "";
|
||||
|
||||
return pChoice->GetValueString( "string" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose DmeEditorType class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeEditorType, CDmeEditorType );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorType::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeEditorType::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the actual attribute name stored in the type
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeEditorType::GetActualAttributeName( const char *pAttributeName )
|
||||
{
|
||||
// Fixup the names of the attribute info for the 3 standard fields (name, type, id)
|
||||
if ( !V_stricmp( "name", pAttributeName ) )
|
||||
return "__name";
|
||||
return pAttributeName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor info associated with an editor type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorType::AddAttributeInfo( const char *pAttributeName, CDmeEditorAttributeInfo *pInfo )
|
||||
{
|
||||
pAttributeName = GetActualAttributeName( pAttributeName );
|
||||
SetValue( pAttributeName, pInfo );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes a editor type associated with a particular attribute
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorType::RemoveAttributeInfo( const char *pAttributeName )
|
||||
{
|
||||
pAttributeName = GetActualAttributeName( pAttributeName );
|
||||
if ( HasAttribute( pAttributeName ) )
|
||||
{
|
||||
RemoveAttribute( pAttributeName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor info associated with an editor type
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorAttributeInfo *CDmeEditorType::GetAttributeInfo( const char *pAttributeName )
|
||||
{
|
||||
pAttributeName = GetActualAttributeName( pAttributeName );
|
||||
if ( !HasAttribute( pAttributeName ) )
|
||||
return NULL;
|
||||
|
||||
return GetValueElement< CDmeEditorAttributeInfo >( pAttributeName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor info associated with a single entry in an attribute array
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorAttributeInfo *CDmeEditorType::GetAttributeArrayInfo( const char *pAttributeName )
|
||||
{
|
||||
CDmeEditorAttributeInfo *pAttributeInfo = GetAttributeInfo( pAttributeName );
|
||||
if ( !pAttributeInfo )
|
||||
return NULL;
|
||||
|
||||
return pAttributeInfo->GetArrayInfo();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose DmeEditorTypeDictionary class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeEditorTypeDictionary, CDmeEditorTypeDictionary );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorTypeDictionary::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeEditorTypeDictionary::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeEditorTypeDictionary::AddEditorType( CDmeEditorType *pEditorType )
|
||||
{
|
||||
const char *pEditorTypeName = pEditorType->GetName();
|
||||
if ( HasAttribute( pEditorTypeName ) )
|
||||
{
|
||||
Warning( "Editor type %s is already defined! Ignoring...\n", pEditorTypeName );
|
||||
return;
|
||||
}
|
||||
|
||||
SetValue( pEditorTypeName, pEditorType->GetHandle() );
|
||||
}
|
||||
|
||||
void CDmeEditorTypeDictionary::AddEditorTypesFromFile( const char *pFileName, const char *pPathID )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor type to use with an element
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorType *CDmeEditorTypeDictionary::GetEditorType( CDmElement *pElement )
|
||||
{
|
||||
if ( !pElement )
|
||||
return NULL;
|
||||
|
||||
const char *pEditorTypeName = NULL;
|
||||
if ( pElement->HasAttribute( "editorType" ) )
|
||||
{
|
||||
pEditorTypeName = pElement->GetValueString( "editorType" );
|
||||
}
|
||||
|
||||
if ( !pEditorTypeName || !pEditorTypeName[0] )
|
||||
{
|
||||
// Try to use the type name as an editor
|
||||
pEditorTypeName = pElement->GetTypeString();
|
||||
}
|
||||
|
||||
if ( !pEditorTypeName || !pEditorTypeName[0] )
|
||||
return NULL;
|
||||
|
||||
if ( !HasAttribute( pEditorTypeName ) )
|
||||
return NULL;
|
||||
|
||||
return GetValueElement< CDmeEditorType >( pEditorTypeName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor info associated with an editor type
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorAttributeInfo *CDmeEditorTypeDictionary::GetAttributeInfo( CDmElement *pElement, const char *pAttributeName )
|
||||
{
|
||||
CDmeEditorType *pEditorType = GetEditorType( pElement );
|
||||
if ( !pEditorType )
|
||||
return NULL;
|
||||
return pEditorType->GetAttributeInfo( pAttributeName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor info associated with an editor type
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorAttributeInfo *CDmeEditorTypeDictionary::GetAttributeArrayInfo( CDmElement *pElement, const char *pAttributeName )
|
||||
{
|
||||
CDmeEditorType *pEditorType = GetEditorType( pElement );
|
||||
if ( !pEditorType )
|
||||
return NULL;
|
||||
return pEditorType->GetAttributeArrayInfo( pAttributeName );
|
||||
}
|
||||
183
movieobjects/dmeexporttags.cpp
Normal file
183
movieobjects/dmeexporttags.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
//============ Copyright (c) Valve Corporation, All rights reserved. ==========
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include <Windows.h>
|
||||
#endif // PLATFORM_WINDOWS
|
||||
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#include "movieobjects/dmeexporttags.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeExportTags, CDmeExportTags );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::OnConstruction()
|
||||
{
|
||||
m_sDate.Init( this, "date" );
|
||||
m_sTime.Init( this, "time" );
|
||||
m_sUser.Init( this, "user" );
|
||||
m_sMachine.Init( this, "machine" );
|
||||
m_sApp.Init( this, "app" );
|
||||
m_sAppVersion.Init( this, "appVersion" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::Init( const char *pszApp /* = NULL */, const char *pszAppVersion /* = NULL */ )
|
||||
{
|
||||
SetApp( pszApp );
|
||||
SetAppVersion( pszAppVersion );
|
||||
|
||||
// Avoid the issue of inconsistent date/time if run just as midnight approaches, SetDate/SetTime without args
|
||||
// query time twice, query it once and use the value for both time and date
|
||||
struct tm localTime;
|
||||
Plat_GetLocalTime( &localTime );
|
||||
|
||||
SetDate( CFmtStr( "%04d/%02d/%02d", localTime.tm_year + 1900, localTime.tm_mon + 1, localTime.tm_mday ).Get() );
|
||||
|
||||
int nHour = localTime.tm_hour % 12;
|
||||
if ( nHour == 0 )
|
||||
{
|
||||
nHour = 12;
|
||||
}
|
||||
|
||||
SetTime( CFmtStr( "%02d:%02d:%02d %2s", nHour, localTime.tm_min, localTime.tm_sec, localTime.tm_hour > 11 ? "pm" : "am" ).Get() );
|
||||
|
||||
SetUser();
|
||||
SetMachine();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetApp( const char *pszVal /*= NULL */ )
|
||||
{
|
||||
m_sApp.Set( pszVal );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetAppVersion( const char *pszVal /* = NULL */ )
|
||||
{
|
||||
m_sAppVersion.Set( pszVal );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetDate( const char *pszVal /* = NULL */ )
|
||||
{
|
||||
if ( pszVal )
|
||||
{
|
||||
m_sDate.Set( pszVal );
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tm localTime;
|
||||
Plat_GetLocalTime( &localTime );
|
||||
m_sDate.Set( CFmtStr( "%04d/%02d/%02d", localTime.tm_year + 1900, localTime.tm_mon + 1, localTime.tm_mday ).Get() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetTime( const char *pszVal /* = NULL */ )
|
||||
{
|
||||
if ( pszVal )
|
||||
{
|
||||
m_sTime.Set( pszVal );
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tm localTime;
|
||||
Plat_GetLocalTime( &localTime );
|
||||
|
||||
int nHour = localTime.tm_hour % 12;
|
||||
if ( nHour == 0 )
|
||||
{
|
||||
nHour = 12;
|
||||
}
|
||||
|
||||
m_sTime.Set( CFmtStr( "%02d:%02d:%02d %2s", nHour, localTime.tm_min, localTime.tm_sec, localTime.tm_hour > 11 ? "pm" : "am" ).Get() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetUser( const char *pszVal /* = NULL */ )
|
||||
{
|
||||
if ( pszVal )
|
||||
{
|
||||
m_sUser.Set( pszVal );
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
char szUserName[ 256 ];
|
||||
DWORD nLen = ARRAYSIZE( szUserName );
|
||||
GetUserName( szUserName, &nLen );
|
||||
|
||||
m_sUser.Set( szUserName );
|
||||
#else // PLATFORM_WINDOWS
|
||||
m_sMachine.Set( NULL );
|
||||
#endif // PLATFORM_WINDOWS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExportTags::SetMachine( const char *pszVal /* = NULL */ )
|
||||
{
|
||||
if ( pszVal )
|
||||
{
|
||||
m_sMachine.Set( pszVal );
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
char szComputerName[ 256 ];
|
||||
DWORD nLen = ARRAYSIZE( szComputerName );
|
||||
GetComputerName( szComputerName, &nLen );
|
||||
|
||||
m_sMachine.Set( szComputerName );
|
||||
#else // PLATFORM_WINDOWS
|
||||
m_sMachine.Set( NULL );
|
||||
#endif // PLATFORM_WINDOWS
|
||||
}
|
||||
}
|
||||
187
movieobjects/dmeexpressionoperator.cpp
Normal file
187
movieobjects/dmeexpressionoperator.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// The expression operator class - scalar math calculator
|
||||
// for a good list of operators and simple functions, see:
|
||||
// \\fileserver\user\MarcS\boxweb\aliveDistLite\v4.2.0\doc\alive\functions.txt
|
||||
// (although we'll want to implement elerp as the standard 3x^2 - 2x^3 with rescale)
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeexpressionoperator.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datamodel/dmattribute.h"
|
||||
#include "mathlib/noise.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include <ctype.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
void TestCalculator( const char *expr, float answer )
|
||||
{
|
||||
CExpressionCalculator calc( expr );
|
||||
float result = 0.0f;
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool success =
|
||||
#endif
|
||||
calc.Evaluate( result );
|
||||
Assert( success && ( result == answer ) );
|
||||
}
|
||||
|
||||
void TestCalculator( const char *expr, float answer, const char *var, float value )
|
||||
{
|
||||
CExpressionCalculator calc( expr );
|
||||
calc.SetVariable( var, value );
|
||||
float result = 0.0f;
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool success =
|
||||
#endif
|
||||
calc.Evaluate( result );
|
||||
Assert( success && ( result == answer ) );
|
||||
}
|
||||
|
||||
void TestCalculator()
|
||||
{
|
||||
// TestCalculator( "-1", 1 );
|
||||
TestCalculator( "2 * 3 + 4", 10 );
|
||||
TestCalculator( "2 + 3 * 4", 14 );
|
||||
TestCalculator( "2 * 3 * 4", 24 );
|
||||
TestCalculator( "2 * -3 + 4", -2 );
|
||||
TestCalculator( "12.0 / 2.0", 6 );
|
||||
TestCalculator( "(2*3)+4", 10 );
|
||||
TestCalculator( "( 1 + 2 ) / (1+2)", 1 );
|
||||
TestCalculator( "(((5)))", 5 );
|
||||
TestCalculator( "--5", 5 );
|
||||
TestCalculator( "3.5 % 2", 1.5 );
|
||||
TestCalculator( "1e-2", 0.01 );
|
||||
TestCalculator( "9 == ( 3 * ( 1 + 2 ) )", 1 );
|
||||
TestCalculator( "9 != ( 3 * ( 1 + 2 ) )", 0 );
|
||||
TestCalculator( "9 <= ( 3 * ( 1 + 2 ) )", 1 );
|
||||
TestCalculator( "9 < ( 3 * ( 1 + 2 ) )", 0 );
|
||||
TestCalculator( "9 < 3", 0 );
|
||||
TestCalculator( "10 >= 5", 1 );
|
||||
// TestCalculator( "9 < ( 3 * ( 2 + 2 ) )", 0 );
|
||||
TestCalculator( "x + 1", 5, "x", 4 );
|
||||
TestCalculator( "pi - 3.14159", 0, "pi", 3.14159 );
|
||||
// TestCalculator( "pi / 2", 0, "pi", 3.14159 );
|
||||
TestCalculator( "abs(-10)", 10 );
|
||||
TestCalculator( "sqr(-5)", 25 );
|
||||
TestCalculator( "sqrt(9)", 3 );
|
||||
// TestCalculator( "sqrt(-9)", -3 );
|
||||
TestCalculator( "pow(2,3)", 8 );
|
||||
TestCalculator( "min(abs(-4),2+3/2)", 3.5 );
|
||||
TestCalculator( "round(0.5)", 1 );
|
||||
TestCalculator( "round(0.49)", 0 );
|
||||
TestCalculator( "round(-0.5)", 0 );
|
||||
TestCalculator( "round(-0.51)", -1 );
|
||||
TestCalculator( "inrange( 5, -8, 10 )", 1 );
|
||||
TestCalculator( "inrange( 5, 5, 10 )", 1 );
|
||||
TestCalculator( "inrange( 5, 6, 10 )", 0 );
|
||||
TestCalculator( "elerp( 1/4, 0, 1 )", 3/16.0f - 1/32.0f );
|
||||
TestCalculator( "rescale( 0.5, -1, 1, 0, 100 )", 75 );
|
||||
TestCalculator( "1 > 2 ? 6 : 9", 9 );
|
||||
TestCalculator( "1 ? 1 ? 2 : 4 : 1 ? 6 : 8", 2 );
|
||||
TestCalculator( "0 ? 1 ? 2 : 4 : 1 ? 6 : 8", 6 );
|
||||
TestCalculator( "noise( 0.123, 4.56, 78.9 )", ImprovedPerlinNoise( Vector( 0.123, 4.56, 78.9 ) ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeExpressionOperator, CDmeExpressionOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeExpressionOperator::OnConstruction()
|
||||
{
|
||||
m_result.Init( this, "result" );
|
||||
m_expr.Init( this, "expr" );
|
||||
m_bSpewResult.Init( this, "spewresult" );
|
||||
|
||||
#ifdef _DEBUG
|
||||
TestCalculator();
|
||||
#endif _DEBUG
|
||||
}
|
||||
|
||||
void CDmeExpressionOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeExpressionOperator::IsInputAttribute( CDmAttribute *pAttribute )
|
||||
{
|
||||
const char *pName = pAttribute->GetName( );
|
||||
#if 0 // skip this test, since none of these are float attributes, but leave the code as a reminder
|
||||
if ( Q_strcmp( pName, "name" ) == 0 )
|
||||
return false;
|
||||
|
||||
if ( Q_strcmp( pName, "expr" ) == 0 )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if ( Q_strcmp( pName, "result" ) == 0 )
|
||||
return false;
|
||||
|
||||
if ( pAttribute->GetType() != AT_FLOAT )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDmeExpressionOperator::Operate()
|
||||
{
|
||||
m_calc.SetExpression( m_expr.Get() );
|
||||
|
||||
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
if ( IsInputAttribute( pAttribute ) )
|
||||
{
|
||||
const char *pName = pAttribute->GetName( );
|
||||
m_calc.SetVariable( pName, pAttribute->GetValue< float >() );
|
||||
}
|
||||
}
|
||||
|
||||
float oldValue = m_result;
|
||||
|
||||
m_calc.Evaluate( oldValue );
|
||||
|
||||
m_result = oldValue;
|
||||
|
||||
if ( m_bSpewResult )
|
||||
{
|
||||
Msg( "%s = '%f'\n", GetName(), (float)m_result );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeExpressionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
if ( IsInputAttribute( pAttribute ) )
|
||||
{
|
||||
attrs.AddToTail( pAttribute );
|
||||
}
|
||||
}
|
||||
|
||||
attrs.AddToTail( m_expr.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeExpressionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_result.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
void CDmeExpressionOperator::SetSpewResult( bool state )
|
||||
{
|
||||
m_bSpewResult = state;
|
||||
}
|
||||
187
movieobjects/dmefaceset.cpp
Normal file
187
movieobjects/dmefaceset.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmefaceset.h"
|
||||
#include "movieobjects/dmematerial.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "UtlBuffer.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFaceSet, CDmeFaceSet );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFaceSet::OnConstruction()
|
||||
{
|
||||
m_indices.Init( this, "faces" );
|
||||
m_material.Init( this, "material" );
|
||||
}
|
||||
|
||||
void CDmeFaceSet::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessors
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeMaterial *CDmeFaceSet::GetMaterial()
|
||||
{
|
||||
return m_material.GetElement();
|
||||
}
|
||||
|
||||
void CDmeFaceSet::SetMaterial( CDmeMaterial *pMaterial )
|
||||
{
|
||||
m_material = pMaterial;
|
||||
}
|
||||
|
||||
int CDmeFaceSet::AddIndices( int nCount )
|
||||
{
|
||||
int nCurrentCount = m_indices.Count();
|
||||
m_indices.EnsureCount( nCount + nCurrentCount );
|
||||
return nCurrentCount;
|
||||
}
|
||||
|
||||
void CDmeFaceSet::SetIndices( int nFirstIndex, int nCount, int *pIndices )
|
||||
{
|
||||
m_indices.SetMultiple( nFirstIndex, nCount, pIndices );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFaceSet::SetIndex( int i, int nValue )
|
||||
{
|
||||
m_indices.Set( i, nValue );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of triangulated indices
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeFaceSet::GetNextPolygonVertexCount( int nFirstIndex ) const
|
||||
{
|
||||
int nCurrIndex = nFirstIndex;
|
||||
int nTotalCount = m_indices.Count();
|
||||
while( nCurrIndex < nTotalCount )
|
||||
{
|
||||
if ( m_indices[nCurrIndex] == -1 )
|
||||
break;
|
||||
++nCurrIndex;
|
||||
}
|
||||
|
||||
return nCurrIndex - nFirstIndex;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of triangulated indices total
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeFaceSet::GetTriangulatedIndexCount() const
|
||||
{
|
||||
int nIndexCount = 0;
|
||||
int nVertexCount = 0;
|
||||
int nTotalCount = m_indices.Count();
|
||||
for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
|
||||
{
|
||||
if ( m_indices[nCurrIndex] == -1 )
|
||||
{
|
||||
if ( nVertexCount >= 3 )
|
||||
{
|
||||
nIndexCount += ( nVertexCount - 2 ) * 3;
|
||||
}
|
||||
nVertexCount = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
++nVertexCount;
|
||||
}
|
||||
|
||||
if ( nVertexCount >= 3 )
|
||||
{
|
||||
nIndexCount += ( nVertexCount - 2 ) * 3;
|
||||
}
|
||||
|
||||
return nIndexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of indices total
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeFaceSet::GetIndexCount() const
|
||||
{
|
||||
int nIndexCount = 0;
|
||||
int nVertexCount = 0;
|
||||
int nTotalCount = m_indices.Count();
|
||||
|
||||
for ( int nCurrIndex = 0; nCurrIndex < nTotalCount; ++nCurrIndex )
|
||||
{
|
||||
if ( m_indices[nCurrIndex] == -1 )
|
||||
{
|
||||
nIndexCount += nVertexCount;
|
||||
nVertexCount = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
++nVertexCount;
|
||||
}
|
||||
|
||||
nIndexCount += nVertexCount;
|
||||
|
||||
return nIndexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFaceSet::RemoveMultiple( int elem, int num )
|
||||
{
|
||||
m_indices.RemoveMultiple( elem, num );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of faces in the face set
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeFaceSet::GetFaceCount() const
|
||||
{
|
||||
int nFaceCount = 0;
|
||||
int nVertexCount = 0;
|
||||
|
||||
const int nIndexCount = NumIndices();
|
||||
for ( int i = 0; i < nIndexCount; ++i )
|
||||
{
|
||||
if ( GetIndex( i ) < 0 )
|
||||
{
|
||||
if ( nVertexCount > 0 )
|
||||
{
|
||||
++nFaceCount;
|
||||
}
|
||||
nVertexCount = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
++nVertexCount;
|
||||
}
|
||||
|
||||
if ( nVertexCount > 0 )
|
||||
{
|
||||
++nFaceCount;
|
||||
}
|
||||
|
||||
return nFaceCount;
|
||||
}
|
||||
443
movieobjects/dmeflexrules.cpp
Normal file
443
movieobjects/dmeflexrules.cpp
Normal file
@@ -0,0 +1,443 @@
|
||||
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// DmeEyeball
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
// Standard includes
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// Valve includes
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmecombinationoperator.h"
|
||||
#include "movieobjects/dmeexpressionoperator.h"
|
||||
#include "movieobjects/dmeflexrules.h"
|
||||
|
||||
|
||||
// Last include
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFlexRuleBase, CDmeFlexRuleBase );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleBase::OnConstruction()
|
||||
{
|
||||
m_flResult.Init( this, "result" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleBase::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleBase::GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
BaseClass::GetInputAttributes( attrs );
|
||||
|
||||
CDmeFlexRules *pDmeFlexRules = GetFlexRules();
|
||||
if ( pDmeFlexRules )
|
||||
{
|
||||
attrs.AddToTail( pDmeFlexRules->m_vDeltaStateWeights.GetAttribute() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleBase::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
BaseClass::GetOutputAttributes( attrs );
|
||||
|
||||
attrs.AddToTail( m_flResult.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the first DmeExpressionRules element that refers to this element
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeFlexRules *CDmeFlexRuleBase::GetFlexRules() const
|
||||
{
|
||||
return FindReferringElement< CDmeFlexRules >( this, "deltaStates" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFlexRulePassThrough, CDmeFlexRulePassThrough );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRulePassThrough::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRulePassThrough::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRulePassThrough::Operate()
|
||||
{
|
||||
CDmeFlexRules *pDmeFlexRules = GetFlexRules();
|
||||
if ( !pDmeFlexRules )
|
||||
return;
|
||||
|
||||
const float flResult = pDmeFlexRules->GetDeltaStateWeight( GetName() );
|
||||
|
||||
m_flResult.Set( flResult );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFlexRuleExpression, CDmeFlexRuleExpression );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleExpression::OnConstruction()
|
||||
{
|
||||
m_expr.Init( this, "expr" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleExpression::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleExpression::Operate()
|
||||
{
|
||||
CDmeFlexRules *pDmeFlexRules = GetFlexRules();
|
||||
if ( pDmeFlexRules )
|
||||
{
|
||||
for ( int i = 0; i < m_calc.VariableCount(); ++i )
|
||||
{
|
||||
m_calc.SetVariable( i, pDmeFlexRules->GetDeltaStateWeight( m_calc.VariableName( i ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
float flVal = 0.0f;
|
||||
|
||||
if ( m_calc.Evaluate( flVal ) )
|
||||
{
|
||||
m_flResult.Set( flVal );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleExpression::Resolve()
|
||||
{
|
||||
if ( m_expr.IsDirty() )
|
||||
{
|
||||
m_calc.SetExpression( m_expr.Get() );
|
||||
m_calc.BuildVariableListFromExpression();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeFlexRuleExpression::SetExpression( const char *pszExpression )
|
||||
{
|
||||
if ( !pszExpression || *pszExpression == '\0' )
|
||||
return false;
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
CUtlVector< char *, CUtlMemory< char *, int > > pathStrings;
|
||||
V_SplitString( pszExpression, "=", pathStrings );
|
||||
if ( pathStrings.Count() == 2 )
|
||||
{
|
||||
char *pszLhs = pathStrings[0];
|
||||
while ( V_isspace( *pszLhs ) )
|
||||
{
|
||||
++pszLhs;
|
||||
}
|
||||
|
||||
for ( char *pszChar = pszLhs + V_strlen( pszLhs ) - 1; V_isspace( *pszChar ) && pszChar >= pszLhs; --pszChar )
|
||||
{
|
||||
*pszChar = '\0';
|
||||
}
|
||||
|
||||
char *pszRhs = pathStrings[1];
|
||||
while ( V_isspace( *pszRhs ) )
|
||||
{
|
||||
++pszRhs;
|
||||
}
|
||||
|
||||
for ( char *pszChar = pszRhs + V_strlen( pszRhs ) - 1; V_isspace( *pszChar ) && pszChar >= pszRhs; --pszChar )
|
||||
{
|
||||
*pszChar = '\0';
|
||||
}
|
||||
|
||||
m_expr = pszRhs;
|
||||
|
||||
Resolve();
|
||||
|
||||
// It's assumed the name of the node is the same as the variable on the left hand side of the expression
|
||||
Assert( !V_strcmp( pszLhs, GetName() ) );
|
||||
}
|
||||
|
||||
pathStrings.PurgeAndDeleteElements();
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFlexRuleLocalVar, CDmeFlexRuleLocalVar );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleLocalVar::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRuleLocalVar::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeFlexRules, CDmeFlexRules );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::OnConstruction()
|
||||
{
|
||||
// Required to drive this node from a DmeCombinationOperator
|
||||
m_eDeltaStates.Init( this, "deltaStates" );
|
||||
m_vDeltaStateWeights.Init( this, "deltaStateWeights" );
|
||||
|
||||
m_eTarget.Init( this, "target" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::Operate()
|
||||
{
|
||||
if ( m_deltaToTargetMap.Count() <= 0 )
|
||||
{
|
||||
Resolve();
|
||||
}
|
||||
|
||||
const int nDeltaCount = MIN( m_eDeltaStates.Count(), m_deltaToTargetMap.Count() );
|
||||
|
||||
CDmrArray< Vector2D > targetWeights( m_eTarget, "deltaStateWeights" );
|
||||
const int nTargetWeightCount = targetWeights.Count();
|
||||
|
||||
for ( int i = 0; i < nDeltaCount; ++i )
|
||||
{
|
||||
const int nTargetIndex = m_deltaToTargetMap[i];
|
||||
if ( nTargetIndex < 0 || nTargetIndex >= nTargetWeightCount )
|
||||
continue;
|
||||
|
||||
CDmeFlexRuleBase *pDmeFlexRuleBase = m_eDeltaStates[i];
|
||||
if ( !pDmeFlexRuleBase )
|
||||
continue;
|
||||
|
||||
const CDmAttribute *pDmResultAttr = pDmeFlexRuleBase->ResultAttr();
|
||||
if ( !pDmResultAttr )
|
||||
continue;
|
||||
|
||||
const float flVal = pDmResultAttr->GetValue< float >();
|
||||
|
||||
targetWeights.Set( nTargetIndex, Vector2D( flVal, flVal ) ); // FlexRules ignore the built in stereo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::Resolve()
|
||||
{
|
||||
if ( m_deltaToTargetMap.Count() <= 0 || m_eTarget.IsDirty() || m_eDeltaStates.IsDirty() )
|
||||
{
|
||||
m_deltaToTargetMap.SetCountNonDestructively( m_eDeltaStates.Count() );
|
||||
|
||||
const CDmrElementArrayConst< CDmElement > targetStates( m_eTarget, "deltaStates" );
|
||||
|
||||
for ( int i = 0; i < m_eDeltaStates.Count(); ++i )
|
||||
{
|
||||
m_deltaToTargetMap[i] = -1;
|
||||
|
||||
CDmeFlexRuleBase *pDmeFlexRuleBase = m_eDeltaStates[i];
|
||||
if ( !pDmeFlexRuleBase )
|
||||
continue;
|
||||
|
||||
for ( int j = 0; j < targetStates.Count(); ++j )
|
||||
{
|
||||
if ( !V_strcmp( targetStates[j]->GetName(), pDmeFlexRuleBase->GetName() ) )
|
||||
{
|
||||
m_deltaToTargetMap[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_eDeltaStates.GetAttribute() );
|
||||
attrs.AddToTail( m_vDeltaStateWeights.GetAttribute() );
|
||||
|
||||
for ( int i = 0; i < m_eDeltaStates.Count(); ++i )
|
||||
{
|
||||
m_eDeltaStates[i]->GetOutputAttributes( attrs );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
CDmrArray<Vector2D> targetWeights( m_eTarget, "deltaStateWeights" );
|
||||
|
||||
if ( targetWeights.IsValid() )
|
||||
{
|
||||
attrs.AddToTail( targetWeights.GetAttribute() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::AddFlexRule( CDmeFlexRuleBase *pDmeFlexRule )
|
||||
{
|
||||
if ( !pDmeFlexRule )
|
||||
return;
|
||||
|
||||
m_eDeltaStates.AddToTail( pDmeFlexRule );
|
||||
|
||||
m_vDeltaStateWeights.AddToTail();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::RemoveAllRules()
|
||||
{
|
||||
m_eDeltaStates.RemoveAll();
|
||||
m_vDeltaStateWeights.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeFlexRules::SetTarget( CDmElement *pDmElement )
|
||||
{
|
||||
if ( !pDmElement )
|
||||
return;
|
||||
|
||||
m_eTarget = pDmElement;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeFlexRules::GetDeltaStateIndex( const char *pszDeltaName ) const
|
||||
{
|
||||
for ( int i = 0; i < m_eDeltaStates.Count(); ++i )
|
||||
{
|
||||
if ( !V_strcmp( pszDeltaName, m_eDeltaStates[i]->GetName() ) )
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeFlexRules::GetDeltaStateWeight( const char *pszDeltaName ) const
|
||||
{
|
||||
const int nDeltaStateIndex = GetDeltaStateIndex( pszDeltaName );
|
||||
if ( nDeltaStateIndex < 0 || nDeltaStateIndex >= m_vDeltaStateWeights.Count() )
|
||||
return 0.0f;
|
||||
|
||||
return m_vDeltaStateWeights[nDeltaStateIndex].x; // Weights are stereo...
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeCombinationOperator *CDmeFlexRules::GetComboOp() const
|
||||
{
|
||||
return FindReferringElement< CDmeCombinationOperator >( this, m_vDeltaStateWeights.GetAttribute()->GetName() );
|
||||
}
|
||||
986
movieobjects/dmegamemodel.cpp
Normal file
986
movieobjects/dmegamemodel.cpp
Normal file
@@ -0,0 +1,986 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Dme version of a game model (MDL)
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmegamemodel.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "studio.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
#include "bone_setup.h"
|
||||
|
||||
#include "movieobjects/dmeoverlay.h" // FIXME: Why do I have to explicitly include dmeoverlay.h here?
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeGlobalFlexControllerOperator, CDmeGlobalFlexControllerOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGlobalFlexControllerOperator::OnConstruction()
|
||||
{
|
||||
m_flexWeight.Init( this, "flexWeight" );
|
||||
m_gameModel.Init( this, "gameModel", FATTRIB_HAS_CALLBACK | FATTRIB_NEVERCOPY );
|
||||
|
||||
m_ToAttributeHandle = DMATTRIBUTE_HANDLE_INVALID;
|
||||
|
||||
m_nFlexControllerIndex = -1;
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::Resolve()
|
||||
{
|
||||
if ( m_nFlexControllerIndex < 0 )
|
||||
{
|
||||
m_nFlexControllerIndex = FindGlobalFlexControllerIndex();
|
||||
}
|
||||
if ( m_ToAttributeHandle == DMATTRIBUTE_HANDLE_INVALID )
|
||||
{
|
||||
SetupToAttribute();
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
// Don't have the required interface...
|
||||
if ( !g_pGlobalFlexController )
|
||||
return;
|
||||
|
||||
if ( pAttribute == m_gameModel.GetAttribute() && m_gameModel.GetElement() )
|
||||
{
|
||||
m_nFlexControllerIndex = FindGlobalFlexControllerIndex();
|
||||
|
||||
SetupToAttribute();
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::Operate()
|
||||
{
|
||||
CDmAttribute *pToAttr = g_pDataModel->GetAttribute( m_ToAttributeHandle );
|
||||
if ( !pToAttr )
|
||||
return;
|
||||
|
||||
DmAttributeType_t type = m_flexWeight.GetAttribute()->GetType();
|
||||
|
||||
const void *pValue = m_flexWeight.GetAttribute()->GetValueUntyped();
|
||||
if ( IsArrayType( pToAttr->GetType() ) )
|
||||
{
|
||||
if ( m_nFlexControllerIndex == -1 )
|
||||
return;
|
||||
|
||||
CDmrGenericArray array( pToAttr );
|
||||
array.Set( m_nFlexControllerIndex, type, pValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
pToAttr->SetValue( type, pValue );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::SetGameModel( CDmeGameModel *gameModel )
|
||||
{
|
||||
m_gameModel = gameModel;
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::SetWeight( float flWeight )
|
||||
{
|
||||
m_flexWeight = flWeight;
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::SetMapping( int globalIndex )
|
||||
{
|
||||
m_nFlexControllerIndex = globalIndex;
|
||||
if ( m_gameModel.GetElement() )
|
||||
{
|
||||
if ( (uint)globalIndex >= m_gameModel->NumFlexWeights() )
|
||||
{
|
||||
m_gameModel->SetNumFlexWeights( (uint)( globalIndex + 1 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CDmeGlobalFlexControllerOperator::GetGlobalIndex() const
|
||||
{
|
||||
return m_nFlexControllerIndex;
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_flexWeight.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
CDmAttribute *toAttribute = g_pDataModel->GetAttribute( m_ToAttributeHandle );
|
||||
if ( toAttribute )
|
||||
{
|
||||
attrs.AddToTail( toAttribute );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGlobalFlexControllerOperator::SetupToAttribute()
|
||||
{
|
||||
CDmElement *pObject = m_gameModel.GetElement();
|
||||
if ( pObject == NULL)
|
||||
return;
|
||||
|
||||
CDmAttribute *pAttr = pObject->GetAttribute( "flexWeights" );
|
||||
Assert( pAttr );
|
||||
if ( !pAttr )
|
||||
return;
|
||||
|
||||
m_ToAttributeHandle = pAttr->GetHandle();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect up stuff by index
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeGlobalFlexControllerOperator::FindGlobalFlexControllerIndex() const
|
||||
{
|
||||
int nGlobalFlexControllerIndex = -1;
|
||||
MDLHandle_t h = m_gameModel->GetModelHandle();
|
||||
if ( h != MDLHANDLE_INVALID )
|
||||
{
|
||||
studiohdr_t *hdr = g_pMDLCache->GetStudioHdr( h );
|
||||
Assert( hdr );
|
||||
if ( hdr )
|
||||
{
|
||||
int fc = hdr->numflexcontrollers;
|
||||
for ( LocalFlexController_t i = LocalFlexController_t(0) ; i < fc; ++i )
|
||||
{
|
||||
mstudioflexcontroller_t *flex = hdr->pFlexcontroller( i );
|
||||
if ( flex->localToGlobal == -1 && g_pGlobalFlexController )
|
||||
{
|
||||
flex->localToGlobal = g_pGlobalFlexController->FindGlobalFlexController( flex->pszName() );
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( flex->pszName(), GetName() ) )
|
||||
{
|
||||
nGlobalFlexControllerIndex = flex->localToGlobal;
|
||||
// Grow the array
|
||||
if ( (uint)flex->localToGlobal >= m_gameModel->NumFlexWeights() )
|
||||
{
|
||||
m_gameModel->SetNumFlexWeights( (uint)( flex->localToGlobal + 1 ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nGlobalFlexControllerIndex;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeGameModel, CDmeGameModel );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameModel::OnConstruction()
|
||||
{
|
||||
m_flexWeights.Init( this, "flexWeights" );
|
||||
m_modelName.Init( this, "modelName", FATTRIB_HAS_CALLBACK );
|
||||
m_skin.Init( this, "skin" );
|
||||
m_body.Init( this, "body" );
|
||||
m_sequence.Init( this, "sequence" );
|
||||
m_flags.Init( this, "flags" );
|
||||
m_bones.Init( this, "bones" );
|
||||
m_globalFlexControllers.Init( this, "globalFlexControllers" );
|
||||
m_bComputeBounds.Init( this, "computeBounds" );
|
||||
m_bEvaluateProceduralBones.InitAndSet( this, "evaluateProceduralBones", true );
|
||||
|
||||
m_hMDL = MDLHANDLE_INVALID;
|
||||
m_bHMDLDirty = true;
|
||||
}
|
||||
|
||||
void CDmeGameModel::OnDestruction()
|
||||
{
|
||||
if ( m_hMDL != MDLHANDLE_INVALID )
|
||||
{
|
||||
g_pMDLCache->Release( m_hMDL );
|
||||
m_hMDL = MDLHANDLE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGameModel::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
if ( pAttribute == m_modelName.GetAttribute() )
|
||||
{
|
||||
m_bHMDLDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
CDmeGlobalFlexControllerOperator *CDmeGameModel::AddGlobalFlexController( const char *controllerName, int globalIndex )
|
||||
{
|
||||
int i, c;
|
||||
c = m_globalFlexControllers.Count();
|
||||
for ( i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeGlobalFlexControllerOperator *op = m_globalFlexControllers.Get( i );
|
||||
Assert( op );
|
||||
if ( op && !Q_stricmp( op->GetName(), controllerName ) )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( i >= c )
|
||||
{
|
||||
CDmeGlobalFlexControllerOperator *newOperator = CreateElement< CDmeGlobalFlexControllerOperator >( controllerName, GetFileId() );
|
||||
Assert( newOperator );
|
||||
if ( !newOperator )
|
||||
return NULL;
|
||||
|
||||
i = m_globalFlexControllers.AddToTail( newOperator );
|
||||
}
|
||||
|
||||
Assert( m_globalFlexControllers.IsValidIndex( i ) );
|
||||
CDmeGlobalFlexControllerOperator *op = m_globalFlexControllers.Get( i );
|
||||
Assert( op );
|
||||
if ( op )
|
||||
{
|
||||
op->SetMapping( globalIndex );
|
||||
op->SetGameModel( this );
|
||||
}
|
||||
|
||||
if ( (uint)globalIndex >= NumFlexWeights() )
|
||||
{
|
||||
SetNumFlexWeights( globalIndex + 1 );
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find a flex controller by its global index
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeGlobalFlexControllerOperator *CDmeGameModel::FindGlobalFlexController( int nGlobalIndex )
|
||||
{
|
||||
int i, c;
|
||||
c = m_globalFlexControllers.Count();
|
||||
for ( i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeGlobalFlexControllerOperator *op = m_globalFlexControllers.Get( i );
|
||||
Assert( op );
|
||||
if ( op && op->GetGlobalIndex() == nGlobalIndex )
|
||||
return op;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
studiohdr_t* CDmeGameModel::GetStudioHdr() const
|
||||
{
|
||||
const char *pModelName = GetModelName();
|
||||
MDLHandle_t h = pModelName && pModelName[0] ? g_pMDLCache->FindMDL( pModelName ) : MDLHANDLE_INVALID;
|
||||
return ( h != MDLHANDLE_INVALID ) ? g_pMDLCache->GetStudioHdr( h ) : NULL;
|
||||
}
|
||||
|
||||
|
||||
// A src bone transform transforms pre-compiled data (.dmx or .smd files, for example)
|
||||
// into post-compiled data (.mdl or .ani files)
|
||||
bool CDmeGameModel::GetSrcBoneTransforms( matrix3x4_t *pPreTransform, matrix3x4_t *pPostTransform, int nBoneIndex ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( !pStudioHdr )
|
||||
return false;
|
||||
|
||||
if ( pStudioHdr->numbones <= nBoneIndex )
|
||||
return false;
|
||||
|
||||
const char *pBoneName = pStudioHdr->pBone( nBoneIndex )->pszName();
|
||||
int nCount = pStudioHdr->NumSrcBoneTransforms();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
const mstudiosrcbonetransform_t *pSrcTransform = pStudioHdr->SrcBoneTransform( i );
|
||||
if ( Q_stricmp( pSrcTransform->pszName(), pBoneName ) )
|
||||
continue;
|
||||
|
||||
MatrixCopy( pSrcTransform->pretransform, *pPreTransform );
|
||||
MatrixCopy( pSrcTransform->posttransform, *pPostTransform );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the default position of the specified bone.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeGameModel::GetBoneDefaultPosition( int nBoneIndex, Vector &position ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( !pStudioHdr )
|
||||
return false;
|
||||
|
||||
if ( ( nBoneIndex < 0 ) || ( nBoneIndex >= pStudioHdr->numbones ) )
|
||||
return false;
|
||||
|
||||
const mstudiobone_t *pBone = pStudioHdr->pBone( nBoneIndex );
|
||||
if ( pBone == NULL )
|
||||
return false;
|
||||
|
||||
position = pBone->pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the default orientation of the specified bone.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeGameModel::GetBoneDefaultOrientation( int nBoneIndex, Quaternion &orientation ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( !pStudioHdr )
|
||||
return false;
|
||||
|
||||
if ( ( nBoneIndex < 0 ) || ( nBoneIndex >= pStudioHdr->numbones ) )
|
||||
return false;
|
||||
|
||||
const mstudiobone_t *pBone = pStudioHdr->pBone( nBoneIndex );
|
||||
if ( pBone == NULL )
|
||||
return false;
|
||||
|
||||
orientation = pBone->quat;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CDmeGameModel::IsRootTransform( int nBoneIndex ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( !pStudioHdr )
|
||||
return true;
|
||||
|
||||
if ( pStudioHdr->numbones <= nBoneIndex )
|
||||
return true;
|
||||
|
||||
const mstudiobone_t *pBone = pStudioHdr->pBone( nBoneIndex );
|
||||
return pBone->parent == -1;
|
||||
}
|
||||
|
||||
int CDmeGameModel::NumGlobalFlexControllers() const
|
||||
{
|
||||
return m_globalFlexControllers.Count();
|
||||
}
|
||||
|
||||
CDmeGlobalFlexControllerOperator *CDmeGameModel::GetGlobalFlexController( int localIndex )
|
||||
{
|
||||
return m_globalFlexControllers.Get( localIndex );
|
||||
}
|
||||
|
||||
void CDmeGameModel::RemoveGlobalFlexController( CDmeGlobalFlexControllerOperator *controller )
|
||||
{
|
||||
int c = m_globalFlexControllers.Count();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeGlobalFlexControllerOperator *check = m_globalFlexControllers.Get( i );
|
||||
if ( check == controller )
|
||||
{
|
||||
m_globalFlexControllers.Remove( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGameModel::AppendGlobalFlexControllerOperators( CUtlVector< IDmeOperator * >& list )
|
||||
{
|
||||
int c = m_globalFlexControllers.Count();
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
CDmeOperator *op = m_globalFlexControllers.Get( i );
|
||||
if ( !op )
|
||||
continue;
|
||||
list.AddToTail( op );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Find the dependencies of each flex controller on the other flex
|
||||
// controllers
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameModel::FindFlexControllerDependencies( CUtlVector< CUtlVector< int > > &dependencyList ) const
|
||||
{
|
||||
studiohdr_t *hdr = GetStudioHdr();
|
||||
if ( hdr == NULL )
|
||||
return;
|
||||
|
||||
|
||||
// Build a table to reference the controller operators by the
|
||||
// global index of the flex control they are associated with.
|
||||
int controllerTable[ MAXSTUDIOFLEXDESC ];
|
||||
memset( controllerTable, -1, sizeof( controllerTable ) );
|
||||
|
||||
int nControllers = m_globalFlexControllers.Count();
|
||||
if ( nControllers > MAXSTUDIOFLEXDESC )
|
||||
{
|
||||
Assert( nControllers < MAXSTUDIOFLEXDESC );
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int iCtrl = 0; iCtrl < nControllers; ++iCtrl )
|
||||
{
|
||||
CDmeGlobalFlexControllerOperator *pCtrlOp = m_globalFlexControllers[ iCtrl ];
|
||||
if ( pCtrlOp )
|
||||
{
|
||||
int globalIndex = pCtrlOp->GetGlobalIndex();
|
||||
if ( ( globalIndex < MAXSTUDIOFLEXDESC ) && ( globalIndex >= 0 ) )
|
||||
{
|
||||
controllerTable[ globalIndex ] = iCtrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Determine which rules each of the controllers contribute to
|
||||
CStudioHdr studioHdr( hdr );
|
||||
|
||||
CUtlVector< int > controllerRuleTable[ MAXSTUDIOFLEXDESC ]; // Table of rules each controller contributes to
|
||||
CUtlVector< int > ruleDepTable[ MAXSTUDIOFLEXDESC ]; // Table of controllers contributing to each rule
|
||||
|
||||
int nFlexRules = studioHdr.numflexrules();
|
||||
|
||||
for ( int iRule = 0; iRule < nFlexRules; ++iRule )
|
||||
{
|
||||
mstudioflexrule_t *pRule = studioHdr.pFlexRule( iRule );
|
||||
|
||||
if ( pRule == NULL )
|
||||
return;
|
||||
|
||||
for ( int iOp = 0; iOp < pRule->numops; ++iOp )
|
||||
{
|
||||
mstudioflexop_t *pOp = pRule->iFlexOp( iOp );
|
||||
|
||||
switch ( pOp->op )
|
||||
{
|
||||
case STUDIO_FETCH1:
|
||||
case STUDIO_2WAY_0:
|
||||
case STUDIO_2WAY_1:
|
||||
case STUDIO_NWAY:
|
||||
case STUDIO_DME_LOWER_EYELID:
|
||||
case STUDIO_DME_UPPER_EYELID:
|
||||
{
|
||||
int globalIndex = studioHdr.pFlexcontroller( (LocalFlexController_t)pOp->d.index )->localToGlobal;
|
||||
if ( ( globalIndex < MAXSTUDIOFLEXDESC ) && ( pRule->flex < MAXSTUDIOFLEXDESC ) && ( globalIndex >= 0 ) )
|
||||
{
|
||||
int controllerIndex = controllerTable[ globalIndex ];
|
||||
if ( controllerIndex >= 0 )
|
||||
{
|
||||
if ( controllerRuleTable[ controllerIndex ].Find( pRule->flex ) == CUtlVector< int >::InvalidIndex() )
|
||||
{
|
||||
controllerRuleTable[ controllerIndex ].AddToTail( pRule->flex );
|
||||
ruleDepTable[ pRule->flex ].AddToTail( controllerIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For each controller, find the other controllers that contribute to the same rules.
|
||||
bool dependencyTable[ MAXSTUDIOFLEXDESC ];
|
||||
memset( dependencyTable, 0, sizeof( dependencyTable ) );
|
||||
for ( int iCtrl = 0; iCtrl < nControllers; ++iCtrl )
|
||||
{
|
||||
memset( dependencyTable, 0, sizeof( bool ) * nControllers );
|
||||
|
||||
// Get the list of rules that controller contributes to
|
||||
CUtlVector< int > &ruleList = controllerRuleTable[ iCtrl ];
|
||||
int nRules = ruleList.Count();
|
||||
int nDependencies = 0;
|
||||
|
||||
for ( int iRule = 0; iRule < nRules; ++iRule )
|
||||
{
|
||||
int ruleIndex = ruleList[ iRule ];
|
||||
CUtlVector< int > &ruleControllerList = ruleDepTable[ ruleIndex ];
|
||||
int nRuleDep = ruleControllerList.Count();
|
||||
|
||||
for ( int iDep = 0; iDep < nRuleDep; ++iDep )
|
||||
{
|
||||
int controllerIndex = ruleControllerList[ iDep ];
|
||||
if ( ( controllerIndex != iCtrl ) && ( dependencyTable[ controllerIndex ] == false ) )
|
||||
{
|
||||
dependencyTable[ controllerIndex ] = true;
|
||||
++nDependencies;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( nDependencies > 0 )
|
||||
{
|
||||
dependencyList.AddToTail();
|
||||
CUtlVector< int > &dependencies = dependencyList.Tail();
|
||||
dependencies.EnsureCapacity( nDependencies + 1 );
|
||||
dependencies.AddToTail( iCtrl );
|
||||
for ( int iDepCtrl = 0; iDepCtrl < nControllers; ++iDepCtrl )
|
||||
{
|
||||
if ( dependencyTable[ iDepCtrl ] == true )
|
||||
{
|
||||
dependencies.AddToTail( iDepCtrl );
|
||||
--nDependencies;
|
||||
}
|
||||
}
|
||||
Assert( nDependencies == 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessors
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameModel::AddBone( CDmeTransform* pTransform )
|
||||
{
|
||||
m_bones.AddToTail( pTransform );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is this dag under the game model?
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool IsDagUnderGameModel( CDmeDag *pDag, CDmeGameModel *pGameModel )
|
||||
{
|
||||
if ( pDag == pGameModel )
|
||||
return true;
|
||||
|
||||
DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( pDag->GetHandle() );
|
||||
while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
|
||||
{
|
||||
CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
|
||||
CDmElement *pDmeParent = pAttribute->GetOwner();
|
||||
const static CUtlSymbolLarge symChildren = g_pDataModel->GetSymbol( "children" );
|
||||
if ( pDmeParent && pAttribute->GetNameSymbol() == symChildren )
|
||||
{
|
||||
CDmeDag *pParent = CastElement< CDmeDag >( pDmeParent );
|
||||
if ( pParent && ( pParent->GetFileId() == pDag->GetFileId() ) )
|
||||
{
|
||||
if ( IsDagUnderGameModel( pParent, pGameModel ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = g_pDataModel->NextAttributeReferencingElement( i );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds existing dags
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameModel::PopulateExistingDagList( CDmeDag** pDags, int nCount )
|
||||
{
|
||||
int nCurrentBoneCount = m_bones.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( i >= nCurrentBoneCount )
|
||||
{
|
||||
pDags[ i ] = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
CDmeTransform *pTransform = GetBone( i );
|
||||
Assert( pTransform );
|
||||
pDags[ i ] = pTransform ? pTransform->GetDag() : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds bones to the game model
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameModel::AddBones( studiohdr_t *pStudioHdr, int nFirstBone, int nCount )
|
||||
{
|
||||
if ( nFirstBone + nCount > pStudioHdr->numbones )
|
||||
{
|
||||
nCount = pStudioHdr->numbones - nFirstBone;
|
||||
if ( nCount <= 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
// make room for bones
|
||||
CDmeDag** pDags = ( CDmeDag** )_alloca( pStudioHdr->numbones * sizeof(CDmeDag*) );
|
||||
int nDagCount = nFirstBone;
|
||||
PopulateExistingDagList( pDags, nFirstBone );
|
||||
|
||||
char name[ 256 ];
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
int bi = i + nFirstBone;
|
||||
|
||||
// get parent
|
||||
const mstudiobone_t *pBone = pStudioHdr->pBone( bi );
|
||||
int parentIndex = pBone->parent;
|
||||
Assert( parentIndex < nDagCount );
|
||||
|
||||
// build dag hierarchy to match bone hierarchy
|
||||
CDmeDag *pParent = ( parentIndex < 0 ) ? this : pDags[ parentIndex ];
|
||||
Q_snprintf( name, sizeof( name ), "bone %d (%s)", bi, pBone->pszName() );
|
||||
CDmeDag *pDag = CreateElement< CDmeDag >( name, GetFileId() );
|
||||
pDags[nDagCount++] = pDag;
|
||||
pParent->AddChild( pDag );
|
||||
|
||||
CDmeTransform *pTransform = pDag->GetTransform();
|
||||
pTransform->SetName( name );
|
||||
|
||||
// add different bone representations to dme model and input
|
||||
AddBone( pTransform );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetBone( uint index, const Vector& pos, const Quaternion& rot )
|
||||
{
|
||||
m_bones[ index ]->SetPosition( pos );
|
||||
m_bones[ index ]->SetOrientation( rot );
|
||||
}
|
||||
|
||||
void CDmeGameModel::RemoveAllBones()
|
||||
{
|
||||
m_bones.RemoveAll();
|
||||
}
|
||||
|
||||
uint CDmeGameModel::NumBones() const
|
||||
{
|
||||
return m_bones.Count();
|
||||
}
|
||||
|
||||
CDmeTransform *CDmeGameModel::GetBone( uint index ) const
|
||||
{
|
||||
return m_bones[ index ];
|
||||
}
|
||||
|
||||
int CDmeGameModel::FindBone( CDmeTransform *pTransform ) const
|
||||
{
|
||||
return m_bones.Find( pTransform );
|
||||
}
|
||||
|
||||
uint CDmeGameModel::NumFlexWeights() const
|
||||
{
|
||||
return m_flexWeights.Count();
|
||||
}
|
||||
|
||||
const CUtlVector< float >& CDmeGameModel::GetFlexWeights() const
|
||||
{
|
||||
return m_flexWeights.Get();
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetNumFlexWeights( uint nFlexWeights )
|
||||
{
|
||||
if ( nFlexWeights > (uint)m_flexWeights.Count() )
|
||||
{
|
||||
while ( (uint)m_flexWeights.Count() < nFlexWeights )
|
||||
{
|
||||
m_flexWeights.AddToTail( 0.0f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( (uint)m_flexWeights.Count() > nFlexWeights )
|
||||
{
|
||||
m_flexWeights.Remove( (uint)m_flexWeights.Count() - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetFlexWeights( uint nFlexWeights, const float* flexWeights )
|
||||
{
|
||||
m_flexWeights.CopyArray( flexWeights, nFlexWeights );
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetFlags( int nFlags )
|
||||
{
|
||||
m_flags = nFlags;
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetSkin( int nSkin )
|
||||
{
|
||||
m_skin = nSkin;
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetBody( int nBody )
|
||||
{
|
||||
m_body = nBody;
|
||||
}
|
||||
|
||||
void CDmeGameModel::SetSequence( int nSequence )
|
||||
{
|
||||
m_sequence = nSequence;
|
||||
}
|
||||
|
||||
int CDmeGameModel::GetSkin() const
|
||||
{
|
||||
return m_skin;
|
||||
}
|
||||
|
||||
int CDmeGameModel::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
int CDmeGameModel::GetSequence() const
|
||||
{
|
||||
return m_sequence;
|
||||
}
|
||||
|
||||
int CDmeGameModel::GetFlags() const
|
||||
{
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
const char *CDmeGameModel::GetModelName() const
|
||||
{
|
||||
return m_modelName.Get();
|
||||
}
|
||||
|
||||
MDLHandle_t CDmeGameModel::GetModelHandle()
|
||||
{
|
||||
if ( m_bHMDLDirty )
|
||||
{
|
||||
UpdateHMDL();
|
||||
}
|
||||
return m_hMDL;
|
||||
}
|
||||
|
||||
void CDmeGameModel::UpdateHMDL()
|
||||
{
|
||||
// Yes, we're intentionally referencing before we unref
|
||||
MDLHandle_t h = MDLHANDLE_INVALID;
|
||||
const char *pModelName = m_modelName.Get();
|
||||
if ( pModelName && *pModelName )
|
||||
{
|
||||
h = g_pMDLCache->FindMDL( pModelName );
|
||||
}
|
||||
|
||||
if ( m_hMDL != MDLHANDLE_INVALID )
|
||||
{
|
||||
g_pMDLCache->Release( m_hMDL );
|
||||
}
|
||||
|
||||
m_hMDL = h;
|
||||
m_bHMDLDirty = false;
|
||||
}
|
||||
|
||||
|
||||
int CDmeGameModel::FindAttachment( const char *pchAttachmentName ) const
|
||||
{
|
||||
if ( studiohdr_t *pStudioHdr = GetStudioHdr() )
|
||||
{
|
||||
CStudioHdr studioHdr( pStudioHdr );
|
||||
return Studio_FindAttachment( &studioHdr, pchAttachmentName ) + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compute the world space position of the specified attachment.
|
||||
//-----------------------------------------------------------------------------
|
||||
Vector CDmeGameModel::ComputeAttachmentPosition( const char *pchAttachmentName ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( pStudioHdr == NULL )
|
||||
return vec3_origin;
|
||||
|
||||
// Find the index of the attachment by its name and verify
|
||||
// that the attachment was found and that the index is valid.
|
||||
CStudioHdr studioHdr( pStudioHdr );
|
||||
int attachmentIndex = Studio_FindAttachment( &studioHdr, pchAttachmentName );
|
||||
if ( ( attachmentIndex < 0 ) || ( attachmentIndex > studioHdr.GetNumAttachments() ) )
|
||||
return vec3_origin;
|
||||
|
||||
// Get the bone to which in attachment position is defined
|
||||
// and then find the dag node using the bone transform.
|
||||
int boneIndex = studioHdr.GetAttachmentBone( attachmentIndex );
|
||||
CDmeTransform *pBoneTranform = GetBone( boneIndex );
|
||||
CDmeDag *pBoneDag = pBoneTranform->GetDag();
|
||||
if ( pBoneDag == NULL )
|
||||
return vec3_origin;
|
||||
|
||||
// Get the local offset position of the attachment and then transform
|
||||
// it into world space using the transform of the associated dag node.
|
||||
const mstudioattachment_t &attachment = studioHdr.pAttachment( attachmentIndex );
|
||||
|
||||
matrix3x4_t wsTransform;
|
||||
Vector localPosition;
|
||||
Vector worldPosition;
|
||||
pBoneDag->GetAbsTransform( wsTransform );
|
||||
MatrixPosition( attachment.local, localPosition );
|
||||
VectorTransform( localPosition, wsTransform, worldPosition );
|
||||
|
||||
return worldPosition;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Create a dag node for the specified attachment and make it a child of the
|
||||
// the bone it is local to.
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeDag *CDmeGameModel::CreateDagForAttachment( const char *pchAttachmentName ) const
|
||||
{
|
||||
studiohdr_t *pStudioHdr = GetStudioHdr();
|
||||
if ( pStudioHdr == NULL )
|
||||
return NULL;
|
||||
|
||||
// Find the index of the attachment by its name and verify
|
||||
// that the attachment was found and that the index is valid.
|
||||
CStudioHdr studioHdr( pStudioHdr );
|
||||
int attachmentIndex = Studio_FindAttachment( &studioHdr, pchAttachmentName );
|
||||
if ( ( attachmentIndex < 0 ) || ( attachmentIndex > studioHdr.GetNumAttachments() ) )
|
||||
return NULL;
|
||||
|
||||
// Get the bone in which the attachment position is defined
|
||||
// and then find the dag node using the bone transform.
|
||||
int boneIndex = studioHdr.GetAttachmentBone( attachmentIndex );
|
||||
CDmeTransform *pBoneTranform = GetBone( boneIndex );
|
||||
CDmeDag *pBoneDag = pBoneTranform->GetDag();
|
||||
if ( pBoneDag == NULL )
|
||||
return NULL;
|
||||
|
||||
CDmeDag *pDagNode = CreateElement< CDmeDag >( CFmtStr( "attach_%s", pchAttachmentName ), GetFileId() );
|
||||
|
||||
if ( pDagNode )
|
||||
{
|
||||
// Position the node based on the attachment position
|
||||
const mstudioattachment_t &attachment = studioHdr.pAttachment( attachmentIndex );
|
||||
CDmeTransform *pTransform = pDagNode->GetTransform();
|
||||
if ( pTransform )
|
||||
{
|
||||
Vector vAttachmentPos;
|
||||
MatrixPosition( attachment.local, vAttachmentPos );
|
||||
pTransform->SetPosition( vAttachmentPos );
|
||||
}
|
||||
|
||||
// Make the attachment dag node a child of bone it is associated with
|
||||
pBoneDag->AddChild( pDagNode );
|
||||
}
|
||||
|
||||
return pDagNode;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeGameSprite, CDmeGameSprite );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameSprite::OnConstruction()
|
||||
{
|
||||
m_modelName .Init( this, "modelName" );
|
||||
m_frame .Init( this, "frame" );
|
||||
m_rendermode.Init( this, "rendermode" );
|
||||
m_renderfx .Init( this, "renderfx" );
|
||||
m_renderscale.Init( this, "renderscale" );
|
||||
m_color .Init( this, "color" );
|
||||
m_proxyRadius.Init( this, "proxyRadius" );
|
||||
}
|
||||
|
||||
void CDmeGameSprite::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessors
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeGameSprite::GetModelName() const
|
||||
{
|
||||
return m_modelName.Get();
|
||||
}
|
||||
|
||||
float CDmeGameSprite::GetScale() const
|
||||
{
|
||||
return m_renderscale;
|
||||
}
|
||||
|
||||
float CDmeGameSprite::GetFrame() const
|
||||
{
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
int CDmeGameSprite::GetRenderMode() const
|
||||
{
|
||||
return m_rendermode;
|
||||
}
|
||||
|
||||
int CDmeGameSprite::GetRenderFX() const
|
||||
{
|
||||
return m_renderfx;
|
||||
}
|
||||
|
||||
const Color &CDmeGameSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
float CDmeGameSprite::GetProxyRadius() const
|
||||
{
|
||||
return m_proxyRadius;
|
||||
}
|
||||
|
||||
void CDmeGameSprite::SetState( bool bVisible, float nFrame, int nRenderMode, int nRenderFX, float flRenderScale, float flProxyRadius,
|
||||
const Vector &pos, const Quaternion &rot, const Color &color )
|
||||
{
|
||||
m_Visible = bVisible;
|
||||
m_frame = nFrame;
|
||||
m_rendermode = nRenderMode;
|
||||
m_renderfx = nRenderFX;
|
||||
m_renderscale = flRenderScale;
|
||||
m_proxyRadius = flProxyRadius;
|
||||
m_color = color;
|
||||
|
||||
CDmeTransform *pTransform = GetTransform();
|
||||
pTransform->SetPosition( pos );
|
||||
pTransform->SetOrientation( rot );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeGamePortal, CDmeGamePortal );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGamePortal::OnConstruction()
|
||||
{
|
||||
m_flStaticAmount .Init( this, "staticAmount" );
|
||||
m_flSecondaryStaticAmount .Init( this, "secondaryStaticAmount" );
|
||||
m_flOpenAmount .Init( this, "openAmount" );
|
||||
m_flHalfWidth .Init( this, "halfWidth" );
|
||||
m_flHalfHeight .Init( this, "halfHeight" );
|
||||
m_nPortalId .Init( this, "portalId" );
|
||||
m_nLinkedPortalId .Init( this, "linkedPortalId" );
|
||||
m_bIsPortal2 .Init( this, "isPortal2" );
|
||||
m_PortalType .Init( this, "portalType" );
|
||||
}
|
||||
|
||||
void CDmeGamePortal::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
36
movieobjects/dmeinput.cpp
Normal file
36
movieobjects/dmeinput.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeinput.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ABSTRACT_ELEMENT( DmeInput, CDmeInput );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeInput::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeInput::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsDirty - ie needs to operate
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeInput::IsDirty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
166
movieobjects/dmejoint.cpp
Normal file
166
movieobjects/dmejoint.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Dme version of a joint of a skeletal model (gets compiled into a MDL)
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmejoint.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier1/keyvalues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeJoint, CDmeJoint );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statics
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeJoint::sm_bDrawJoints = false;
|
||||
IMaterial *CDmeJoint::sm_pMatJoint = NULL;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeJoint::OnConstruction()
|
||||
{
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
if ( !sm_pMatJoint )
|
||||
{
|
||||
KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
|
||||
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
|
||||
pVMTKeyValues->SetInt( "$ignorez", 1 );
|
||||
sm_pMatJoint = g_pMaterialSystem->CreateMaterial( "__DmeJoint", pVMTKeyValues );
|
||||
|
||||
if ( sm_pMatJoint )
|
||||
{
|
||||
m_MatRefJoint.Init( sm_pMatJoint );
|
||||
sm_pMatJoint->DecrementReferenceCount(); // CreateMaterial adds a ref, just want the CMaterialReference's
|
||||
|
||||
// Cache material now to avoid an unwanted implicit Ref that occurs on first use which is never cleared
|
||||
g_pMaterialSystem->CacheUsedMaterials();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MatRefJoint.Init( sm_pMatJoint );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeJoint::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Activate, deactivate joint drawing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeJoint::DrawJointHierarchy( bool bDrawJoints )
|
||||
{
|
||||
sm_bDrawJoints = bDrawJoints;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// For rendering joints
|
||||
//-----------------------------------------------------------------------------
|
||||
#define AXIS_SIZE 3.0f
|
||||
|
||||
void CDmeJoint::DrawJoints( )
|
||||
{
|
||||
if ( !g_pMaterialSystem )
|
||||
return;
|
||||
|
||||
int cn = GetChildCount();
|
||||
|
||||
// Draw the joint hierarchy
|
||||
PushDagTransform();
|
||||
matrix3x4_t shapeToWorld;
|
||||
GetShapeToWorldTransform( shapeToWorld );
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->LoadMatrix( shapeToWorld );
|
||||
|
||||
pRenderContext->Bind( m_MatRefJoint );
|
||||
IMesh *pMesh = pRenderContext->GetDynamicMesh( );
|
||||
|
||||
CMeshBuilder meshBuilder;
|
||||
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 + cn );
|
||||
|
||||
for ( int ci = 0; ci < cn; ++ci )
|
||||
{
|
||||
CDmeJoint *pJoint = CastElement<CDmeJoint>( GetChild( ci ) );
|
||||
if ( !pJoint )
|
||||
continue;
|
||||
|
||||
Vector vecChildPosition = pJoint->GetTransform()->GetPosition();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 128, 128, 128, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3fv( vecChildPosition.Base() );
|
||||
meshBuilder.Color4ub( 128, 128, 128, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
}
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 255, 0, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 255, 0, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 255, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 255, 0, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
|
||||
meshBuilder.Color4ub( 0, 0, 255, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
|
||||
meshBuilder.Color4ub( 0, 0, 255, 255 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->LoadIdentity();
|
||||
|
||||
PopDagTransform();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rendering method for the dag
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeJoint::Draw( CDmeDrawSettings *pDrawSettings /* = NULL */ )
|
||||
{
|
||||
if ( sm_bDrawJoints && IsVisible() )
|
||||
{
|
||||
DrawJoints();
|
||||
}
|
||||
|
||||
BaseClass::Draw( pDrawSettings );
|
||||
}
|
||||
141
movieobjects/dmekeyboardinput.cpp
Normal file
141
movieobjects/dmekeyboardinput.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmekeyboardinput.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
#include "vgui/iinput.h"
|
||||
#include "vgui/keycode.h"
|
||||
#include "tier3/tier3.h"
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// global list of all keys supported
|
||||
//-----------------------------------------------------------------------------
|
||||
struct KeyInfo
|
||||
{
|
||||
vgui::KeyCode code;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
const uint g_nKeys = 48;
|
||||
const KeyInfo g_keyInfo[ g_nKeys ] =
|
||||
{
|
||||
{ KEY_0, "0" },
|
||||
{ KEY_1, "1" },
|
||||
{ KEY_2, "2" },
|
||||
{ KEY_3, "3" },
|
||||
{ KEY_4, "4" },
|
||||
{ KEY_5, "5" },
|
||||
{ KEY_6, "6" },
|
||||
{ KEY_7, "7" },
|
||||
{ KEY_8, "8" },
|
||||
{ KEY_9, "9" },
|
||||
{ KEY_A, "A" },
|
||||
{ KEY_B, "B" },
|
||||
{ KEY_C, "C" },
|
||||
{ KEY_D, "D" },
|
||||
{ KEY_E, "E" },
|
||||
{ KEY_F, "F" },
|
||||
{ KEY_G, "G" },
|
||||
{ KEY_H, "H" },
|
||||
{ KEY_I, "I" },
|
||||
{ KEY_J, "J" },
|
||||
{ KEY_K, "K" },
|
||||
{ KEY_L, "L" },
|
||||
{ KEY_M, "M" },
|
||||
{ KEY_N, "N" },
|
||||
{ KEY_O, "O" },
|
||||
{ KEY_P, "P" },
|
||||
{ KEY_Q, "Q" },
|
||||
{ KEY_R, "R" },
|
||||
{ KEY_S, "S" },
|
||||
{ KEY_T, "T" },
|
||||
{ KEY_U, "U" },
|
||||
{ KEY_V, "V" },
|
||||
{ KEY_W, "W" },
|
||||
{ KEY_X, "X" },
|
||||
{ KEY_Y, "Y" },
|
||||
{ KEY_Z, "Z" },
|
||||
{ KEY_F1, "F1" },
|
||||
{ KEY_F2, "F2" },
|
||||
{ KEY_F3, "F3" },
|
||||
{ KEY_F4, "F4" },
|
||||
{ KEY_F5, "F5" },
|
||||
{ KEY_F6, "F6" },
|
||||
{ KEY_F7, "F7" },
|
||||
{ KEY_F8, "F8" },
|
||||
{ KEY_F9, "F9" },
|
||||
{ KEY_F10, "F10" },
|
||||
{ KEY_F11, "F11" },
|
||||
{ KEY_F12, "F12" },
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeKeyboardInput, CDmeKeyboardInput );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeKeyboardInput::OnConstruction()
|
||||
{
|
||||
m_keys = new CDmaVar< bool >[ g_nKeys ];
|
||||
|
||||
for ( uint ki = 0; ki < g_nKeys; ++ki )
|
||||
{
|
||||
m_keys[ ki ].Init( this, g_keyInfo[ ki ].str );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeKeyboardInput::OnDestruction()
|
||||
{
|
||||
delete[] m_keys;
|
||||
}
|
||||
|
||||
bool CDmeKeyboardInput::IsDirty()
|
||||
{
|
||||
for ( uint ki = 0; ki < g_nKeys; ++ki )
|
||||
{
|
||||
if ( m_keys[ ki ].Get() != GetKeyStatus( ki ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDmeKeyboardInput::Operate()
|
||||
{
|
||||
for ( uint ki = 0; ki < g_nKeys; ++ki )
|
||||
{
|
||||
m_keys[ ki ].Set( GetKeyStatus( ki ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeKeyboardInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeKeyboardInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
for ( uint ki = 0; ki < g_nKeys; ++ki )
|
||||
{
|
||||
attrs.AddToTail( m_keys[ ki ].GetAttribute() );
|
||||
}
|
||||
}
|
||||
|
||||
bool CDmeKeyboardInput::GetKeyStatus( uint ki )
|
||||
{
|
||||
return g_pVGuiInput->IsKeyDown( g_keyInfo[ ki ].code );
|
||||
}
|
||||
272
movieobjects/dmelight.cpp
Normal file
272
movieobjects/dmelight.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmelight.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeLight, CDmeLight );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeLight::OnConstruction()
|
||||
{
|
||||
m_Color.InitAndSet( this, "color", Color( 255, 255, 255, 255 ) );
|
||||
m_flIntensity.InitAndSet( this, "intensity", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeLight::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the color and intensity
|
||||
// NOTE: Color is specified 0-255 floating point.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeLight::SetColor( const Color &color )
|
||||
{
|
||||
m_Color.Set( color );
|
||||
}
|
||||
|
||||
void CDmeLight::SetIntensity( float flIntensity )
|
||||
{
|
||||
m_flIntensity = flIntensity;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up render state in the material system for rendering
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeLight::SetupRenderStateInternal( LightDesc_t &desc, float flAtten0, float flAtten1, float flAtten2 )
|
||||
{
|
||||
desc.m_Color[0] = m_Color.Get().r();
|
||||
desc.m_Color[1] = m_Color.Get().g();
|
||||
desc.m_Color[2] = m_Color.Get().b();
|
||||
desc.m_Color *= m_flIntensity / 255.0f;
|
||||
|
||||
desc.m_Attenuation0 = flAtten0;
|
||||
desc.m_Attenuation1 = flAtten1;
|
||||
desc.m_Attenuation2 = flAtten2;
|
||||
|
||||
desc.m_Flags = 0;
|
||||
if ( desc.m_Attenuation0 != 0.0f )
|
||||
{
|
||||
desc.m_Flags |= LIGHTTYPE_OPTIMIZATIONFLAGS_HAS_ATTENUATION0;
|
||||
}
|
||||
if ( desc.m_Attenuation1 != 0.0f )
|
||||
{
|
||||
desc.m_Flags |= LIGHTTYPE_OPTIMIZATIONFLAGS_HAS_ATTENUATION1;
|
||||
}
|
||||
if ( desc.m_Attenuation2 != 0.0f )
|
||||
{
|
||||
desc.m_Flags |= LIGHTTYPE_OPTIMIZATIONFLAGS_HAS_ATTENUATION2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// A directional light
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeDirectionalLight, CDmeDirectionalLight );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeDirectionalLight::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeDirectionalLight::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets a light desc for the light
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeDirectionalLight::GetLightDesc( LightDesc_t *pDesc )
|
||||
{
|
||||
memset( pDesc, 0, sizeof(LightDesc_t) );
|
||||
|
||||
pDesc->m_Type = MATERIAL_LIGHT_DIRECTIONAL;
|
||||
SetupRenderStateInternal( *pDesc, 1.0f, 0.0f, 0.0f );
|
||||
|
||||
matrix3x4_t m;
|
||||
GetAbsTransform( m );
|
||||
MatrixGetColumn( m, 0, pDesc->m_Direction ); // from mathlib_base.cpp: MatrixVectors(): Matrix is right-handed x=forward, y=left, z=up. We a left-handed convention for vectors in the game code (forward, right, up)
|
||||
|
||||
pDesc->m_Theta = 0.0f;
|
||||
pDesc->m_Phi = 0.0f;
|
||||
pDesc->m_Falloff = 1.0f;
|
||||
pDesc->RecalculateDerivedValues();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// A point light
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePointLight, CDmePointLight );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmePointLight::OnConstruction()
|
||||
{
|
||||
m_flAttenuation0.InitAndSet( this, "constantAttenuation", 1.0f );
|
||||
m_flAttenuation1.InitAndSet( this, "linearAttenuation", 0.0f );
|
||||
m_flAttenuation2.InitAndSet( this, "quadraticAttenuation", 0.0f );
|
||||
m_flMaxDistance.InitAndSet( this, "maxDistance", 600.0f ); // 50 feet
|
||||
}
|
||||
|
||||
void CDmePointLight::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the attenuation factors
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmePointLight::SetAttenuation( float flConstant, float flLinear, float flQuadratic )
|
||||
{
|
||||
m_flAttenuation0 = flConstant;
|
||||
m_flAttenuation1 = flLinear;
|
||||
m_flAttenuation2 = flQuadratic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the maximum range
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmePointLight::SetMaxDistance( float flMaxDistance )
|
||||
{
|
||||
m_flMaxDistance = flMaxDistance;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up render state in the material system for rendering
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmePointLight::GetLightDesc( LightDesc_t *pDesc )
|
||||
{
|
||||
memset( pDesc, 0, sizeof(LightDesc_t) );
|
||||
|
||||
pDesc->m_Type = MATERIAL_LIGHT_POINT;
|
||||
SetupRenderStateInternal( *pDesc, m_flAttenuation0, m_flAttenuation1, m_flAttenuation2 );
|
||||
|
||||
matrix3x4_t m;
|
||||
GetAbsTransform( m );
|
||||
MatrixPosition( m, pDesc->m_Position );
|
||||
pDesc->m_Direction.Init( 0, 0, 1 );
|
||||
pDesc->m_Range = m_flMaxDistance;
|
||||
|
||||
pDesc->m_Theta = 0.0f;
|
||||
pDesc->m_Phi = 0.0f;
|
||||
pDesc->m_Falloff = 1.0f;
|
||||
pDesc->RecalculateDerivedValues();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// A spot light
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSpotLight, CDmeSpotLight );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSpotLight::OnConstruction()
|
||||
{
|
||||
m_flSpotInnerAngle.InitAndSet( this, "spotInnerAngle", 60.0f );
|
||||
m_flSpotOuterAngle.InitAndSet( this, "spotOuterAngle", 90.0f );
|
||||
m_flSpotAngularFalloff.InitAndSet( this, "spotAngularFalloff", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeSpotLight::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the spotlight angle factors
|
||||
// Angles are specified in degrees, as full angles (as opposed to half-angles)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSpotLight::SetAngles( float flInnerAngle, float flOuterAngle, float flAngularFalloff )
|
||||
{
|
||||
m_flSpotInnerAngle = flInnerAngle;
|
||||
m_flSpotOuterAngle = flOuterAngle;
|
||||
m_flSpotAngularFalloff = flAngularFalloff;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up render state in the material system for rendering
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSpotLight::GetLightDesc( LightDesc_t *pDesc )
|
||||
{
|
||||
memset( pDesc, 0, sizeof(LightDesc_t) );
|
||||
|
||||
pDesc->m_Type = MATERIAL_LIGHT_SPOT;
|
||||
SetupRenderStateInternal( *pDesc, m_flAttenuation0, m_flAttenuation1, m_flAttenuation2 );
|
||||
|
||||
matrix3x4_t m;
|
||||
GetAbsTransform( m );
|
||||
MatrixPosition( m, pDesc->m_Position );
|
||||
MatrixGetColumn( m, 0, pDesc->m_Direction ); // from mathlib_base.cpp: MatrixVectors(): Matrix is right-handed x=forward, y=left, z=up. We a left-handed convention for vectors in the game code (forward, right, up)
|
||||
pDesc->m_Range = m_flMaxDistance;
|
||||
|
||||
// Convert to radians
|
||||
pDesc->m_Theta = 0.5f * m_flSpotInnerAngle * M_PI / 180.0f;
|
||||
pDesc->m_Phi = 0.5f * m_flSpotOuterAngle * M_PI / 180.0f;
|
||||
pDesc->m_Falloff = m_flSpotAngularFalloff;
|
||||
pDesc->RecalculateDerivedValues();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// An ambient light
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAmbientLight, CDmeAmbientLight );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmbientLight::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeAmbientLight::OnDestruction()
|
||||
{
|
||||
}
|
||||
9266
movieobjects/dmelog.cpp
Normal file
9266
movieobjects/dmelog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
628
movieobjects/dmemakefile.cpp
Normal file
628
movieobjects/dmemakefile.cpp
Normal file
@@ -0,0 +1,628 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Describes an asset: something that is compiled from sources,
|
||||
// in potentially multiple steps, to a compiled resource
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "movieobjects/dmemdlmakefile.h"
|
||||
#include "movieobjects/idmemakefileutils.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier2/fileutils.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into element factories
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSource, CDmeSource );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Construction/destruction
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSource::OnConstruction()
|
||||
{
|
||||
m_DependentMakefile = NULL;
|
||||
}
|
||||
|
||||
void CDmeSource::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets/gets the makefile that was used to build this source
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSource::SetDependentMakefile( CDmeMakefile *pMakeFile )
|
||||
{
|
||||
m_DependentMakefile = pMakeFile;
|
||||
}
|
||||
|
||||
CDmeMakefile *CDmeSource::GetDependentMakefile()
|
||||
{
|
||||
return m_DependentMakefile.Get();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Call this to open the source file in an editor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSource::OpenEditor()
|
||||
{
|
||||
if ( g_pDmeMakefileUtils )
|
||||
{
|
||||
g_pDmeMakefileUtils->PerformOpenEditor( this );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into element factories
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMakefile, CDmeMakefile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Construction/destruction
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::OnConstruction()
|
||||
{
|
||||
m_Sources.Init( this, "sources" );
|
||||
m_hOutput = NULL;
|
||||
m_hCompileProcess = NULL;
|
||||
m_bIsDirty = false;
|
||||
}
|
||||
|
||||
void CDmeMakefile::OnDestruction()
|
||||
{
|
||||
DestroyOutputElement( m_hOutput.Get() );
|
||||
m_hOutput = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Performs pre-compilation step
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::PreCompile( )
|
||||
{
|
||||
// Make all outputs writeable
|
||||
MakeOutputsWriteable();
|
||||
|
||||
// Destroy the current output object; we'll need to reload it
|
||||
// NOTE: Don't check for m_hOutput == 0; we always need to call DestroyOutputElement
|
||||
// Sometimes makefiles have to do stuff even if m_hOutput == NULL
|
||||
DestroyOutputElement( m_hOutput );
|
||||
m_hOutput = NULL;
|
||||
}
|
||||
|
||||
void CDmeMakefile::PostCompile( )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the output element created by compilation of this makefile
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CDmeMakefile::GetOutputElement( bool bCreateIfNecessary )
|
||||
{
|
||||
if ( m_hOutput.Get() )
|
||||
return m_hOutput.Get();
|
||||
|
||||
if ( !bCreateIfNecessary )
|
||||
return NULL;
|
||||
|
||||
if ( !g_pDmeMakefileUtils || !g_pDmeMakefileUtils->IsCurrentlyCompiling() )
|
||||
{
|
||||
m_hOutput = CreateOutputElement();
|
||||
}
|
||||
|
||||
return m_hOutput.Get();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the path of the makefile
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::GetMakefilePath( char *pFullPath, int nBufLen )
|
||||
{
|
||||
DmFileId_t fileId = GetFileId();
|
||||
const char *pFileName = ( fileId != DMFILEID_INVALID ) ? g_pDataModel->GetFileName( fileId ) : "";
|
||||
Assert( !pFileName[0] || Q_IsAbsolutePath( pFileName ) );
|
||||
|
||||
Q_ExtractFilePath( pFileName, pFullPath, nBufLen );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the output directory we expect to compile files into
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::GetOutputDirectory( char *pFullPath, int nBufLen )
|
||||
{
|
||||
return GetDefaultDirectory( GetOutputDirectoryID(), pFullPath, nBufLen );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the output name (output directory + filename, no extension)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::GetOutputName( char *pFullPath, int nBufLen )
|
||||
{
|
||||
pFullPath[0] = 0;
|
||||
|
||||
char pOutputPath[MAX_PATH];
|
||||
if ( !GetDefaultDirectory( GetOutputDirectoryID(), pOutputPath, sizeof(pOutputPath) ) )
|
||||
return false;
|
||||
|
||||
DmFileId_t fileId = GetFileId();
|
||||
const char *pFileName = ( fileId != DMFILEID_INVALID ) ? g_pDataModel->GetFileName( fileId ) : "";
|
||||
if ( !pFileName || !pFileName[0] )
|
||||
return false;
|
||||
|
||||
Q_ComposeFileName( pOutputPath, Q_UnqualifiedFileName(pFileName), pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts the m_pDefaultDirectoryID field of the DmeMakefileType_t to a full path
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::GetDefaultDirectory( const char *pDefaultDirectoryID, char *pFullPath, int nBufLen )
|
||||
{
|
||||
if ( StringHasPrefix( pDefaultDirectoryID, "contentdir:" ) )
|
||||
{
|
||||
pDefaultDirectoryID += 11;
|
||||
GetModContentSubdirectory( pDefaultDirectoryID, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( StringHasPrefix( pDefaultDirectoryID, "gamedir:" ) )
|
||||
{
|
||||
pDefaultDirectoryID += 8;
|
||||
GetModSubdirectory( pDefaultDirectoryID, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( StringHasPrefix( pDefaultDirectoryID, "makefiledir:" ) )
|
||||
{
|
||||
char pMakefilePath[MAX_PATH];
|
||||
GetMakefilePath( pMakefilePath, sizeof(pMakefilePath) );
|
||||
pDefaultDirectoryID += 12;
|
||||
Q_ComposeFileName( pMakefilePath, pDefaultDirectoryID, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( StringHasPrefix( pDefaultDirectoryID, "makefilegamedir:" ) )
|
||||
{
|
||||
char pMakefilePath[MAX_PATH];
|
||||
GetMakefilePath( pMakefilePath, sizeof(pMakefilePath) );
|
||||
|
||||
char pModContentDirectory[MAX_PATH];
|
||||
GetModContentSubdirectory( NULL, pModContentDirectory, sizeof(pModContentDirectory) );
|
||||
|
||||
char pRelativePath[MAX_PATH];
|
||||
if ( !Q_MakeRelativePath( pMakefilePath, pModContentDirectory, pRelativePath, sizeof(pRelativePath) ) )
|
||||
{
|
||||
pFullPath[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
char pModDirectory[MAX_PATH];
|
||||
GetModSubdirectory( NULL, pModDirectory, sizeof(pModDirectory) );
|
||||
|
||||
char pMakefileGamePath[MAX_PATH];
|
||||
Q_ComposeFileName( pModDirectory, pRelativePath, pMakefileGamePath, sizeof(pMakefileGamePath) );
|
||||
|
||||
pDefaultDirectoryID += 16;
|
||||
Q_ComposeFileName( pMakefileGamePath, pDefaultDirectoryID, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
// Assume it's a content subdir
|
||||
GetModContentSubdirectory( pDefaultDirectoryID, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Relative path to full path
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::RelativePathToFullPath( const char *pRelativePath, char *pFullPath, int nBufLen )
|
||||
{
|
||||
if ( !pRelativePath[0] )
|
||||
{
|
||||
pFullPath[0] = 0;
|
||||
return;
|
||||
}
|
||||
char pRootDir[ MAX_PATH ];
|
||||
GetMakefilePath( pRootDir, sizeof(pRootDir) );
|
||||
Q_ComposeFileName( pRootDir, pRelativePath, pFullPath, nBufLen );
|
||||
Q_RemoveDotSlashes( pFullPath );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fullpath to relative path
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::FullPathToRelativePath( const char *pFullPath, char *pRelativePath, int nBufLen )
|
||||
{
|
||||
if ( !pFullPath[0] )
|
||||
{
|
||||
pRelativePath[0] = 0;
|
||||
return;
|
||||
}
|
||||
char pRootDir[ MAX_PATH ];
|
||||
GetMakefilePath( pRootDir, sizeof(pRootDir) );
|
||||
if ( pRootDir[0] )
|
||||
{
|
||||
Q_MakeRelativePath( pFullPath, pRootDir, pRelativePath, nBufLen );
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_strncpy( pRelativePath, pFullPath, nBufLen );
|
||||
Q_FixSlashes( pRelativePath );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds a single source
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeSource *CDmeMakefile::AddSource( const char *pSourceType, const char *pFullPath )
|
||||
{
|
||||
if ( pFullPath[0] && FindSource( pSourceType, pFullPath ) )
|
||||
{
|
||||
Warning( "Attempted to add the same source twice %s!\n", pFullPath );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDmElement *pElement = GetElement< CDmElement >( g_pDataModel->CreateElement( pSourceType, "", GetFileId() ) );
|
||||
CDmeSource *pSource = CastElement< CDmeSource >( pElement );
|
||||
Assert( pSource );
|
||||
if ( !pSource )
|
||||
{
|
||||
Warning( "Invalid source type name %s!\n", pSourceType );
|
||||
if ( pElement )
|
||||
{
|
||||
DestroyElement( pElement );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char pRelativePath[MAX_PATH];
|
||||
FullPathToRelativePath( pFullPath, pRelativePath, sizeof( pRelativePath ) );
|
||||
pSource->SetRelativeFileName( pRelativePath );
|
||||
m_Sources.AddToTail( pSource );
|
||||
return pSource;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes a single source
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeSource *CDmeMakefile::FindSource( const char *pSourceType, const char *pFullPath )
|
||||
{
|
||||
char pRelativePath[MAX_PATH];
|
||||
FullPathToRelativePath( pFullPath, pRelativePath, sizeof( pRelativePath ) );
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( Q_stricmp( pSourceType, m_Sources[i]->GetTypeString() ) )
|
||||
continue;
|
||||
|
||||
if ( !Q_stricmp( pRelativePath, m_Sources[i]->GetRelativeFileName() ) )
|
||||
return m_Sources[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets a source to be a single source
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeSource *CDmeMakefile::SetSingleSource( const char *pSourceType, const char *pFullPath )
|
||||
{
|
||||
// FIXME: we maybe shouldn't remove everything if the source can't be created for some reason?
|
||||
RemoveAllSources( pSourceType );
|
||||
return AddSource( pSourceType, pFullPath );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Changes a source
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::SetSourceFullPath( CDmeSource *pSource, const char *pFullPath )
|
||||
{
|
||||
char pRelativePath[MAX_PATH];
|
||||
FullPathToRelativePath( pFullPath, pRelativePath, sizeof( pRelativePath ) );
|
||||
|
||||
if ( Q_stricmp( pRelativePath, pSource->GetRelativeFileName() ) )
|
||||
{
|
||||
pSource->SetRelativeFileName( pRelativePath );
|
||||
|
||||
// FIXME: Should we delete the dependent makefile?
|
||||
pSource->SetDependentMakefile( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the full path of a source
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::GetSourceFullPath( CDmeSource *pSource, char *pFullPath, int nBufLen )
|
||||
{
|
||||
const char *pRelativePath = pSource->GetRelativeFileName( );
|
||||
RelativePathToFullPath( pRelativePath, pFullPath, nBufLen );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns a list of sources
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::GetSources( const char *pSourceType, CUtlVector< CDmeHandle< CDmeSource > > &sources )
|
||||
{
|
||||
int nCount = m_Sources.Count();
|
||||
sources.EnsureCapacity( nCount );
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( m_Sources[i]->IsA( pSourceType ) )
|
||||
{
|
||||
int j = sources.AddToTail();
|
||||
sources[j] = m_Sources[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets a list of all sources, regardless of type
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeMakefile::GetSourceCount()
|
||||
{
|
||||
return m_Sources.Count();
|
||||
}
|
||||
|
||||
CDmeSource *CDmeMakefile::GetSource( int nIndex )
|
||||
{
|
||||
return m_Sources[nIndex];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes a single source
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::RemoveSource( CDmeSource *pSource )
|
||||
{
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( m_Sources[i] == pSource )
|
||||
{
|
||||
m_Sources.Remove( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeMakefile::RemoveSource( const char *pSourceType, const char *pFullPath )
|
||||
{
|
||||
char pRelativePath[MAX_PATH];
|
||||
FullPathToRelativePath( pFullPath, pRelativePath, sizeof( pRelativePath ) );
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( Q_stricmp( pSourceType, m_Sources[i]->GetTypeString() ) )
|
||||
continue;
|
||||
|
||||
if ( !Q_stricmp( pRelativePath, m_Sources[i]->GetRelativeFileName() ) )
|
||||
{
|
||||
m_Sources.Remove( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes all sources of a particular type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::RemoveAllSources( const char *pSourceType )
|
||||
{
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = nCount; --i >= 0; )
|
||||
{
|
||||
if ( !Q_stricmp( pSourceType, m_Sources[i]->GetTypeString() ) )
|
||||
{
|
||||
// NOTE: This works because we're iterating backward
|
||||
m_Sources.Remove( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Source iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::HasSourceOfType( const char *pSourceType )
|
||||
{
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = nCount; --i >= 0; )
|
||||
{
|
||||
if ( !Q_stricmp( pSourceType, m_Sources[i]->GetTypeString() ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Updates the source names to be relative to a particular path
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::UpdateSourceNames( const char *pOldRootDir, const char *pNewRootDir, bool bApplyChanges )
|
||||
{
|
||||
char pOldSourcePath[ MAX_PATH ];
|
||||
char pNewSourcePath[ MAX_PATH ];
|
||||
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
const char *pOldRelativePath = m_Sources[i]->GetRelativeFileName();
|
||||
if ( pOldRelativePath[0] )
|
||||
{
|
||||
Q_ComposeFileName( pOldRootDir, pOldRelativePath, pOldSourcePath, sizeof(pOldSourcePath) );
|
||||
Q_RemoveDotSlashes( pOldSourcePath );
|
||||
if ( !Q_MakeRelativePath( pOldSourcePath, pNewRootDir, pNewSourcePath, sizeof(pNewSourcePath) ) )
|
||||
{
|
||||
Assert( !bApplyChanges );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pNewSourcePath[0] = 0;
|
||||
}
|
||||
|
||||
if ( !bApplyChanges )
|
||||
continue;
|
||||
|
||||
m_Sources[i]->SetRelativeFileName( pNewSourcePath );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the filename
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeMakefile::GetFileName() const
|
||||
{
|
||||
DmFileId_t fileId = GetFileId();
|
||||
return g_pDataModel->GetFileName( fileId );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Call this to change the file the makefile is stored in
|
||||
// Will make all sources be relative to this path
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefile::SetFileName( const char *pFileName )
|
||||
{
|
||||
if ( !Q_IsAbsolutePath( pFileName ) )
|
||||
return false;
|
||||
|
||||
char pOldRootDir[ MAX_PATH ];
|
||||
char pNewRootDir[ MAX_PATH ];
|
||||
GetMakefilePath( pOldRootDir, sizeof(pOldRootDir) );
|
||||
Q_ExtractFilePath( pFileName, pNewRootDir, sizeof(pNewRootDir) );
|
||||
|
||||
// Gotta do this twice; once to check for validity, once to actually do it
|
||||
if ( !UpdateSourceNames( pOldRootDir, pNewRootDir, false ) )
|
||||
return false;
|
||||
|
||||
UpdateSourceNames( pOldRootDir, pNewRootDir, true );
|
||||
|
||||
DmFileId_t fileId = GetFileId();
|
||||
if ( fileId == DMFILEID_INVALID )
|
||||
{
|
||||
fileId = g_pDataModel->FindOrCreateFileId( pFileName );
|
||||
SetFileId( fileId, TD_DEEP );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pDataModel->SetFileName( fileId, pFileName );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Make all outputs writeable
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::MakeOutputsWriteable( )
|
||||
{
|
||||
// When we publish, we'll check them out.
|
||||
CUtlVector<CUtlString> outputs;
|
||||
GetOutputs( outputs );
|
||||
int nCount = outputs.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
g_pFullFileSystem->SetFileWritable( outputs[i], true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets a makefile/source association
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefile::SetAssociation( CDmeSource *pSource, CDmeMakefile *pSourceMakefile )
|
||||
{
|
||||
if ( !pSource )
|
||||
return;
|
||||
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( m_Sources[i] != pSource )
|
||||
continue;
|
||||
|
||||
CDmeMakefile *pDependentMakeFile = m_Sources[i]->GetDependentMakefile();
|
||||
if ( pSourceMakefile != pDependentMakeFile )
|
||||
{
|
||||
// FIXME: Should I recursively delete pDependentMakeFile ?
|
||||
m_Sources[i]->SetDependentMakefile( pSourceMakefile );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds a dependent makefile
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeMakefile *CDmeMakefile::FindDependentMakefile( CDmeSource *pSource )
|
||||
{
|
||||
if ( !pSource )
|
||||
return NULL;
|
||||
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( m_Sources[i] == pSource )
|
||||
return m_Sources[i]->GetDependentMakefile();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the associated source
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeSource *CDmeMakefile::FindAssociatedSource( CDmeMakefile *pChildMakefile )
|
||||
{
|
||||
if ( !pChildMakefile )
|
||||
return NULL;
|
||||
|
||||
int nCount = m_Sources.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( m_Sources[i]->GetDependentMakefile() == pChildMakefile )
|
||||
return m_Sources[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
617
movieobjects/dmemakefileutils.cpp
Normal file
617
movieobjects/dmemakefileutils.cpp
Normal file
@@ -0,0 +1,617 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =====//
|
||||
//
|
||||
// Interface for makefiles to build differently depending on where they are run from
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "movieobjects/dmemakefileutils.h"
|
||||
#include "movieobjects/dmemdlmakefile.h"
|
||||
#include "movieobjects/dmedccmakefile.h"
|
||||
#include "tier2/fileutils.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statics
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_DMEMAKEFILE_UTIL_CLASS( CDmeMakefileUtils );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Default implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
static CDmeMakefileUtils s_MakefileUtils;
|
||||
IDmeMakefileUtils *GetDefaultDmeMakefileUtils()
|
||||
{
|
||||
return &s_MakefileUtils;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeMakefileUtils::CDmeMakefileUtils()
|
||||
{
|
||||
m_CompilationStep = NOT_COMPILING;
|
||||
m_hCompileProcess = NULL;
|
||||
m_nCurrentCompileTask = -1;
|
||||
m_nExitCode = 0;
|
||||
}
|
||||
|
||||
CDmeMakefileUtils::~CDmeMakefileUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Here's where systems can access other interfaces implemented by this object
|
||||
//-----------------------------------------------------------------------------
|
||||
void *CDmeMakefileUtils::QueryInterface( const char *pInterfaceName )
|
||||
{
|
||||
if ( !V_strcmp( pInterfaceName, DMEMAKEFILE_UTILS_INTERFACE_VERSION ) )
|
||||
return (IDmeMakefileUtils*)this;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialization.. set up messagemaps
|
||||
//-----------------------------------------------------------------------------
|
||||
InitReturnVal_t CDmeMakefileUtils::Init()
|
||||
{
|
||||
InitializeFuncMaps();
|
||||
return INIT_OK;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Looks for an appropriate method to compile this element with
|
||||
//-----------------------------------------------------------------------------
|
||||
CCompileFuncAdapterBase *CDmeMakefileUtils::DetermineCompileAdapter( CDmElement *pElement )
|
||||
{
|
||||
int nBestInheritanceDepth = -1;
|
||||
CCompileFuncAdapterBase *pBestAdapter = NULL;
|
||||
|
||||
CompileFuncTree_t *pTree = GetCompileTree();
|
||||
while ( pTree )
|
||||
{
|
||||
CCompileFuncAdapterBase *pCurr = pTree->m_pFirstAdapter;
|
||||
for ( ; pCurr; pCurr = pCurr->m_pNext )
|
||||
{
|
||||
// Choose this factory if it's more derived than the previous best
|
||||
int nInheritanceDepth = pElement->GetInheritanceDepth( pCurr->m_ElementType );
|
||||
if ( nInheritanceDepth < 0 )
|
||||
continue;
|
||||
|
||||
if ( nInheritanceDepth == 0 )
|
||||
{
|
||||
// Found exact match.. do it!
|
||||
return pCurr;
|
||||
}
|
||||
|
||||
// Don't look for the best thingy if we're not the root
|
||||
if ( nBestInheritanceDepth >= 0 && ( nInheritanceDepth >= nBestInheritanceDepth ) )
|
||||
continue;
|
||||
|
||||
nBestInheritanceDepth = nInheritanceDepth;
|
||||
pBestAdapter = pCurr;
|
||||
}
|
||||
|
||||
pTree = pTree->m_pBaseAdapterTree;
|
||||
}
|
||||
|
||||
// Return the closest match we could find
|
||||
return pBestAdapter;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Looks for an appropriate method to open this element with
|
||||
//-----------------------------------------------------------------------------
|
||||
COpenEditorFuncAdapterBase *CDmeMakefileUtils::DetermineOpenEditorAdapter( CDmElement *pElement )
|
||||
{
|
||||
int nBestInheritanceDepth = -1;
|
||||
COpenEditorFuncAdapterBase *pBestAdapter = NULL;
|
||||
OpenEditorFuncTree_t *pTree = GetOpenEditorTree();
|
||||
while ( pTree )
|
||||
{
|
||||
COpenEditorFuncAdapterBase *pCurr = pTree->m_pFirstAdapter;
|
||||
for ( ; pCurr; pCurr = pCurr->m_pNext )
|
||||
{
|
||||
// Choose this factory if it's more derived than the previous best
|
||||
int nInheritanceDepth = pElement->GetInheritanceDepth( pCurr->m_ElementType );
|
||||
if ( nInheritanceDepth < 0 )
|
||||
continue;
|
||||
|
||||
// Found exact match.. do it!
|
||||
if ( nInheritanceDepth == 0 )
|
||||
return pCurr;
|
||||
|
||||
if ( nBestInheritanceDepth >= 0 && ( nInheritanceDepth >= nBestInheritanceDepth ) )
|
||||
continue;
|
||||
|
||||
nBestInheritanceDepth = nInheritanceDepth;
|
||||
pBestAdapter = pCurr;
|
||||
}
|
||||
|
||||
pTree = pTree->m_pBaseAdapterTree;
|
||||
}
|
||||
return pBestAdapter;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens a element in an external editor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::PerformOpenEditor( CDmElement *pElement )
|
||||
{
|
||||
COpenEditorFuncAdapterBase *pAdapter = DetermineOpenEditorAdapter( pElement );
|
||||
if ( pAdapter )
|
||||
{
|
||||
pAdapter->OpenEditor( pElement );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Queues up a compilation task
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::AddCompilationTask( CDmElement* pElement, CCompileFuncAdapterBase *pAdapter )
|
||||
{
|
||||
Assert( m_CompilationStep == BUILDING_STANDARD_DEPENDENCIES || m_CompilationStep == BUILDING_ALL_DEPENDENCIES );
|
||||
|
||||
// Queue up the compilation task
|
||||
int j = m_CompileTasks.AddToTail();
|
||||
m_CompileTasks[j].m_hElement = pElement;
|
||||
m_CompileTasks[j].m_pAdapter = pAdapter;
|
||||
}
|
||||
|
||||
void CDmeMakefileUtils::AddCompilationTask( CDmElement* pElement )
|
||||
{
|
||||
CCompileFuncAdapterBase *pAdapter = DetermineCompileAdapter( pElement );
|
||||
if ( pAdapter )
|
||||
{
|
||||
// Queue up the compilation task
|
||||
AddCompilationTask( pElement, pAdapter );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the compile process
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::SetCompileProcess( IProcess *hProcess )
|
||||
{
|
||||
Assert( m_CompilationStep == PERFORMING_COMPILATION );
|
||||
m_hCompileProcess = hProcess;
|
||||
if ( m_hCompileProcess == NULL )
|
||||
{
|
||||
m_CompilationStep = AFTER_COMPILATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Default implementatations for compile dependencies
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::AddCompileDependencies( CDmeMakefile *pMakefile, bool bBuildAllDependencies )
|
||||
{
|
||||
if ( !pMakefile )
|
||||
return true;
|
||||
|
||||
CUtlVector< CUtlString > outputs;
|
||||
int nCount = pMakefile->GetSourceCount();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeSource *pSource = pMakefile->GetSource( i );
|
||||
if ( !pSource )
|
||||
continue;
|
||||
|
||||
CDmeMakefile *pDependentMakefile = pSource->GetDependentMakefile();
|
||||
if ( !pDependentMakefile )
|
||||
continue;
|
||||
|
||||
bool bShouldBuildFile = bBuildAllDependencies;
|
||||
|
||||
// Does the output files exist?
|
||||
int j = 0;
|
||||
if ( !bBuildAllDependencies )
|
||||
{
|
||||
pDependentMakefile->GetOutputs( outputs );
|
||||
int nOutputCount = outputs.Count();
|
||||
for ( j = 0; j < nOutputCount; ++j )
|
||||
{
|
||||
// If the file doesn't exist, we have to build it
|
||||
if ( !g_pFullFileSystem->FileExists( outputs[j] ) )
|
||||
break;
|
||||
|
||||
bShouldBuildFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !bShouldBuildFile )
|
||||
continue;
|
||||
|
||||
CCompileFuncAdapterBase *pAdapter = DetermineCompileAdapter( pDependentMakefile );
|
||||
if ( pAdapter )
|
||||
{
|
||||
// Add dependent makefiles first
|
||||
if ( !pAdapter->PerformCompilationStep( pDependentMakefile, bBuildAllDependencies ? BUILDING_ALL_DEPENDENCIES : BUILDING_STANDARD_DEPENDENCIES ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Queue up the compilation task
|
||||
AddCompilationTask( pDependentMakefile, pAdapter );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Default implementatations for precompilation step
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::PerformCompilationStep( CDmElement *pElement, CompilationStep_t step )
|
||||
{
|
||||
// Do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDmeMakefileUtils::PerformCompilationStep( CDmeMakefile *pMakefile, CompilationStep_t step )
|
||||
{
|
||||
switch( step )
|
||||
{
|
||||
case BUILDING_ALL_DEPENDENCIES:
|
||||
return AddCompileDependencies( pMakefile, true );
|
||||
|
||||
case BUILDING_STANDARD_DEPENDENCIES:
|
||||
return AddCompileDependencies( pMakefile, false );
|
||||
|
||||
case BEFORE_COMPILATION:
|
||||
pMakefile->PreCompile();
|
||||
break;
|
||||
|
||||
case AFTER_COMPILATION_SUCCEEDED:
|
||||
pMakefile->PostCompile();
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Starts the next compile task
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::StartNextCompileTask( )
|
||||
{
|
||||
Assert( m_hCompileProcess == NULL );
|
||||
++m_nCurrentCompileTask;
|
||||
if ( m_nCurrentCompileTask == m_CompileTasks.Count() )
|
||||
{
|
||||
PerformCompilationStep( AFTER_COMPILATION_SUCCEEDED );
|
||||
m_nCurrentCompileTask = -1;
|
||||
m_CompileTasks.RemoveAll();
|
||||
return;
|
||||
}
|
||||
|
||||
m_hCompileProcess = NULL;
|
||||
|
||||
// NOTE: PerformCompilationStep is expected to call SetCompileProcess to set m_hCompileProcess
|
||||
CompileInfo_t &info = m_CompileTasks[m_nCurrentCompileTask];
|
||||
bool bOk = info.m_pAdapter->PerformCompilationStep( info.m_hElement, PERFORMING_COMPILATION );
|
||||
|
||||
if ( !bOk || ( m_hCompileProcess == NULL ) )
|
||||
{
|
||||
AbortCurrentCompilation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Performs the compilation step on all elements
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::PerformCompilationStep( CompilationStep_t step )
|
||||
{
|
||||
// Iterate through all elements and run a compilation step
|
||||
m_CompilationStep = step;
|
||||
int nCount = m_CompileTasks.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CompileInfo_t &info = m_CompileTasks[i];
|
||||
if ( info.m_hElement.Get() )
|
||||
{
|
||||
if ( !info.m_pAdapter->PerformCompilationStep( info.m_hElement, step ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main entry point for compilation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::PerformCompile( CDmElement *pElement, bool bBuildAllDependencies )
|
||||
{
|
||||
if ( IsCurrentlyCompiling() )
|
||||
{
|
||||
AbortCurrentCompilation();
|
||||
}
|
||||
|
||||
CCompileFuncAdapterBase *pAdapter = DetermineCompileAdapter( pElement );
|
||||
if ( !pAdapter )
|
||||
{
|
||||
m_CompilationStep = AFTER_COMPILATION_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add dependent makefiles first
|
||||
m_CompilationStep = bBuildAllDependencies ? BUILDING_ALL_DEPENDENCIES : BUILDING_STANDARD_DEPENDENCIES;
|
||||
if ( !pAdapter->PerformCompilationStep( pElement, m_CompilationStep ) )
|
||||
{
|
||||
AbortCurrentCompilation();
|
||||
return;
|
||||
}
|
||||
|
||||
// Queue up the compilation task
|
||||
AddCompilationTask( pElement, pAdapter );
|
||||
|
||||
// Iterate through all elements and run a precompilation step
|
||||
// NOTE: This is where perforce integration should go
|
||||
if ( !PerformCompilationStep( BEFORE_COMPILATION ) )
|
||||
{
|
||||
AbortCurrentCompilation();
|
||||
return;
|
||||
}
|
||||
|
||||
// Dequeue the first compile task and start it up
|
||||
m_CompilationStep = PERFORMING_COMPILATION;
|
||||
StartNextCompileTask();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we in the middle of compiling this makefile?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::IsCurrentlyCompiling()
|
||||
{
|
||||
return ( m_CompilationStep != NOT_COMPILING );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Aborts any current compilation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::AbortCurrentCompilation()
|
||||
{
|
||||
if ( m_hCompileProcess != NULL )
|
||||
{
|
||||
m_hCompileProcess->Abort();
|
||||
m_hCompileProcess->Release();
|
||||
m_hCompileProcess = NULL;
|
||||
}
|
||||
|
||||
if ( IsCurrentlyCompiling() )
|
||||
{
|
||||
PerformCompilationStep( AFTER_COMPILATION_FAILED );
|
||||
m_nCurrentCompileTask = -1;
|
||||
m_CompileTasks.RemoveAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the exit code of the failed compilation (if COMPILATION_FAILED occurred)
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeMakefileUtils::GetExitCode()
|
||||
{
|
||||
return m_nExitCode;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns output from the compilation
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeMakefileUtils::GetCompileOutputSize()
|
||||
{
|
||||
if ( m_hCompileProcess == NULL )
|
||||
return 0;
|
||||
return m_hCompileProcess->GetStdout()->GetNumBytesAvailable();
|
||||
}
|
||||
|
||||
CompilationState_t CDmeMakefileUtils::UpdateCompilation( char *pOutputBuf, int nBufLen )
|
||||
{
|
||||
switch( m_CompilationStep )
|
||||
{
|
||||
case BUILDING_STANDARD_DEPENDENCIES:
|
||||
case BUILDING_ALL_DEPENDENCIES:
|
||||
case BEFORE_COMPILATION:
|
||||
return COMPILATION_NOT_COMPLETE;
|
||||
|
||||
case AFTER_COMPILATION_FAILED:
|
||||
m_CompilationStep = NOT_COMPILING;
|
||||
return COMPILATION_FAILED;
|
||||
|
||||
case AFTER_COMPILATION_SUCCEEDED:
|
||||
m_CompilationStep = NOT_COMPILING;
|
||||
return COMPILATION_SUCCESSFUL;
|
||||
}
|
||||
|
||||
// This is the PERFORMING_COMPILATION case:
|
||||
|
||||
// FIXME: Check return codes from compile process..
|
||||
// fail if compilation process had a problem
|
||||
if ( m_hCompileProcess == NULL )
|
||||
{
|
||||
if ( nBufLen > 0 )
|
||||
{
|
||||
pOutputBuf[0] = 0;
|
||||
}
|
||||
return COMPILATION_SUCCESSFUL;
|
||||
}
|
||||
|
||||
if ( nBufLen > 0 )
|
||||
{
|
||||
CUtlString sOutput;
|
||||
m_hCompileProcess->GetStdout()->ReadAvailable( sOutput );
|
||||
V_strncpy( pOutputBuf, sOutput.String(), nBufLen );
|
||||
V_TranslateLineFeedsToUnix( pOutputBuf );
|
||||
}
|
||||
|
||||
if ( !m_hCompileProcess->IsComplete() )
|
||||
return COMPILATION_NOT_COMPLETE;
|
||||
|
||||
m_nExitCode = m_hCompileProcess->GetExitCode();
|
||||
bool bCompileSucceeded = ( m_nExitCode == 0 );
|
||||
m_hCompileProcess->Release();
|
||||
m_hCompileProcess = NULL;
|
||||
|
||||
if ( !bCompileSucceeded )
|
||||
{
|
||||
AbortCurrentCompilation();
|
||||
return COMPILATION_NOT_COMPLETE;
|
||||
}
|
||||
|
||||
StartNextCompileTask();
|
||||
if ( m_CompilationStep == PERFORMING_COMPILATION )
|
||||
return COMPILATION_NOT_COMPLETE;
|
||||
|
||||
CompilationState_t retVal = ( m_CompilationStep == AFTER_COMPILATION_SUCCEEDED ) ? COMPILATION_SUCCESSFUL : COMPILATION_FAILED;
|
||||
m_CompilationStep = NOT_COMPILING;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type-specific compilation functions
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::PerformCompilationStep( CDmeMDLMakefile *pMakeFile, CompilationStep_t step )
|
||||
{
|
||||
if ( step != PERFORMING_COMPILATION )
|
||||
return PerformCompilationStep( static_cast<CDmeMakefile*>( pMakeFile ), step );
|
||||
|
||||
char pBinDirectory[MAX_PATH];
|
||||
GetModSubdirectory( "..\\bin", pBinDirectory, sizeof(pBinDirectory) );
|
||||
Q_RemoveDotSlashes( pBinDirectory );
|
||||
|
||||
char pStudioMDLCmd[MAX_PATH];
|
||||
#ifdef _DEBUG
|
||||
Q_snprintf( pStudioMDLCmd, sizeof(pStudioMDLCmd), "%s\\studiomdl.exe -allowdebug %s", pBinDirectory, pMakeFile->GetFileName() );
|
||||
#else
|
||||
Q_snprintf( pStudioMDLCmd, sizeof(pStudioMDLCmd), "%s\\studiomdl.exe %s", pBinDirectory, pMakeFile->GetFileName() );
|
||||
#endif
|
||||
|
||||
IProcess *hProcess = g_pProcessUtils->StartProcess( pStudioMDLCmd, STARTPROCESS_CONNECTSTDPIPES );
|
||||
SetCompileProcess( hProcess );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports a Maya file to a DMX file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMakefileUtils::PerformCompilationStep( CDmeMayaMakefile *pMakeFile, CompilationStep_t step )
|
||||
{
|
||||
if ( step != PERFORMING_COMPILATION )
|
||||
return PerformCompilationStep( static_cast<CDmeMakefile*>( pMakeFile ), step );
|
||||
|
||||
// FIXME: Create batch export command here
|
||||
CUtlString mayaCommand;
|
||||
mayaCommand = "vsDmxIO -export";
|
||||
|
||||
CUtlVector< CDmeHandle< CDmeSourceMayaFile > > sources;
|
||||
pMakeFile->GetSources( sources );
|
||||
|
||||
if ( !sources.Count() )
|
||||
return false;
|
||||
|
||||
CDmeSourceMayaFile *pDmeSourceDCCFile( sources[ 0 ].Get() );
|
||||
|
||||
mayaCommand += " -selection";
|
||||
|
||||
char pObjectId[128];
|
||||
UniqueIdToString( pMakeFile->GetId(), pObjectId, sizeof(pObjectId) );
|
||||
mayaCommand += " -makefileObjectId \\\"";
|
||||
mayaCommand += pObjectId;
|
||||
mayaCommand += "\\\"";
|
||||
|
||||
mayaCommand += " -";
|
||||
mayaCommand += pDmeSourceDCCFile->m_ExportType.GetAttribute()->GetName();
|
||||
|
||||
switch ( pDmeSourceDCCFile->m_ExportType.Get() )
|
||||
{
|
||||
case 1: // skeletal animation
|
||||
mayaCommand += " skeletalAnimation";
|
||||
|
||||
mayaCommand += " -";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameStart.GetAttribute()->GetName();
|
||||
mayaCommand += " ";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameStart.Get();
|
||||
|
||||
mayaCommand += " -";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameEnd.GetAttribute()->GetName();
|
||||
mayaCommand += " ";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameEnd.Get();
|
||||
|
||||
mayaCommand += " -";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameIncrement.GetAttribute()->GetName();
|
||||
mayaCommand += " ";
|
||||
mayaCommand += pDmeSourceDCCFile->m_FrameIncrement.Get();
|
||||
break;
|
||||
default: // Model
|
||||
mayaCommand += " model";
|
||||
break;
|
||||
}
|
||||
|
||||
char pFileName[MAX_PATH];
|
||||
Q_strncpy( pFileName, pMakeFile->GetFileName(), sizeof( pFileName ) );
|
||||
Q_FixSlashes( pFileName, '/' );
|
||||
mayaCommand += " -filename \\\"";
|
||||
mayaCommand += pFileName;
|
||||
mayaCommand += "\\\"";
|
||||
|
||||
const int rootObjectCount( pDmeSourceDCCFile->m_RootDCCObjects.Count() );
|
||||
for ( int rootObjectIndex( 0 ); rootObjectIndex < rootObjectCount; ++rootObjectIndex )
|
||||
{
|
||||
mayaCommand += " ";
|
||||
mayaCommand += pDmeSourceDCCFile->m_RootDCCObjects[ rootObjectIndex ];
|
||||
}
|
||||
|
||||
char pSourcePath[MAX_PATH];
|
||||
pMakeFile->GetSourceFullPath( pDmeSourceDCCFile, pSourcePath, sizeof(pSourcePath) );
|
||||
|
||||
// Maya wants forward slashes
|
||||
Q_FixSlashes( pSourcePath, '/' );
|
||||
|
||||
char pMayaCommand[1024];
|
||||
Q_snprintf( pMayaCommand, sizeof(pMayaCommand), "mayabatch.exe -batch -file \"%s\" -command \"%s\"", pSourcePath, mayaCommand.Get() );
|
||||
IProcess *hProcess = g_pProcessUtils->StartProcess( pMayaCommand, STARTPROCESS_CONNECTSTDPIPES );
|
||||
SetCompileProcess( hProcess );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens Maya with a particular file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMakefileUtils::OpenEditor( CDmeSourceMayaFile *pDmeSourceDCCFile )
|
||||
{
|
||||
CDmeMayaMakefile *pMakefile = FindReferringElement< CDmeMayaMakefile >( pDmeSourceDCCFile, "sources" );
|
||||
if ( !pMakefile )
|
||||
return;
|
||||
|
||||
char pSourcePath[MAX_PATH];
|
||||
pMakefile->GetSourceFullPath( pDmeSourceDCCFile, pSourcePath, sizeof(pSourcePath) );
|
||||
|
||||
// Maya wants forward slashes
|
||||
Q_FixSlashes( pSourcePath, '/' );
|
||||
|
||||
char pMayaCommand[1024];
|
||||
Q_snprintf( pMayaCommand, sizeof(pMayaCommand), "maya.exe -file \"%s\"", pSourcePath );
|
||||
g_pProcessUtils->StartProcess( pMayaCommand, STARTPROCESS_CONNECTSTDPIPES );
|
||||
}
|
||||
89
movieobjects/dmematerial.cpp
Normal file
89
movieobjects/dmematerial.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmematerial.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
|
||||
#include "materialsystem/IMaterial.h"
|
||||
#include "materialsystem/IMaterialSystem.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "datamodel/dmattributevar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMaterial, CDmeMaterial );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterial::OnConstruction()
|
||||
{
|
||||
m_mtlName.Init( this, "mtlName" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterial::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// resolve
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterial::Resolve()
|
||||
{
|
||||
BaseClass::Resolve();
|
||||
|
||||
if ( m_mtlName.IsDirty() )
|
||||
{
|
||||
m_mtlRef.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the material
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterial::SetMaterial( const char *pMaterialName )
|
||||
{
|
||||
m_mtlName = pMaterialName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the material name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CDmeMaterial::GetMaterialName() const
|
||||
{
|
||||
return m_mtlName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessor for cached IMaterial
|
||||
//-----------------------------------------------------------------------------
|
||||
IMaterial *CDmeMaterial::GetCachedMTL()
|
||||
{
|
||||
if ( !m_mtlRef.IsValid() )
|
||||
{
|
||||
const char *mtlName = m_mtlName.Get();
|
||||
if ( mtlName == NULL )
|
||||
return NULL;
|
||||
|
||||
m_mtlRef.Init( g_pMaterialSystem->FindMaterial( mtlName, NULL, false ) );
|
||||
}
|
||||
|
||||
return (IMaterial * )m_mtlRef;
|
||||
}
|
||||
323
movieobjects/dmematerialoverlayfxclip.cpp
Normal file
323
movieobjects/dmematerialoverlayfxclip.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmematerialoverlayfxclip.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "tier1/keyvalues.h"
|
||||
#include "tier1/convar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeClip - common base class for filmclips, soundclips, and channelclips
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_FX_CLIP_ELEMENT_FACTORY( DmeMaterialOverlayFXClip, CDmeMaterialOverlayFXClip, "Material Overlay Effect" );
|
||||
|
||||
void CDmeMaterialOverlayFXClip::OnConstruction()
|
||||
{
|
||||
m_Material.Init( this, "material" );
|
||||
m_Color.Init( this, "overlaycolor" );
|
||||
m_nLeft.Init( this, "left" );
|
||||
m_nTop.Init( this, "top" );
|
||||
m_nWidth.Init( this, "width" );
|
||||
m_nHeight.Init( this, "height" );
|
||||
m_bFullScreen.Init( this, "fullscreen" );
|
||||
m_bUseSubRect.Init( this, "useSubRect" );
|
||||
m_flMovementAngle.Init( this, "movementAngle" );
|
||||
m_flMovementSpeed.Init( this, "movementSpeed" );
|
||||
m_nSubRectLeft.Init( this, "subRectLeft" );
|
||||
m_nSubRectTop.Init( this, "subRectTop" );
|
||||
m_nSubRectWidth.Init( this, "subRectWidth" );
|
||||
m_nSubRectHeight.Init( this, "subRectHeight" );
|
||||
|
||||
m_Color.SetColor( 255, 255, 255, 255 );
|
||||
m_bFullScreen = true;
|
||||
m_nLeft = m_nTop = 0;
|
||||
m_nWidth = m_nHeight = 1;
|
||||
|
||||
// Set up the Blt material
|
||||
KeyValues *pVMTKeyValues = new KeyValues( "accumbuff4sample" );
|
||||
pVMTKeyValues->SetString( "$INPUT", "Effects/FilmScan256" ); // dummy
|
||||
|
||||
KeyValues *pProxiesKV = pVMTKeyValues->FindKey( "proxies", true ); // create a subkey
|
||||
pProxiesKV->FindKey( "sfm_blt", true );
|
||||
|
||||
m_BltMaterial.Init( "accumbuff4sample", pVMTKeyValues );
|
||||
m_BltMaterial->Refresh();
|
||||
}
|
||||
|
||||
void CDmeMaterialOverlayFXClip::OnDestruction()
|
||||
{
|
||||
m_BltMaterial.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resolve
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterialOverlayFXClip::Resolve()
|
||||
{
|
||||
if ( m_Material.IsDirty() )
|
||||
{
|
||||
m_OverlayMaterial.Shutdown();
|
||||
const char *pName = m_Material.Get();
|
||||
if ( pName && pName[0] )
|
||||
{
|
||||
m_OverlayMaterial.Init( pName, NULL, false );
|
||||
}
|
||||
m_Material.GetAttribute()->RemoveFlag( FATTRIB_DIRTY );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper for overlays
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterialOverlayFXClip::SetOverlayEffect( const char *pMaterialName )
|
||||
{
|
||||
m_Material = pMaterialName;
|
||||
}
|
||||
|
||||
void CDmeMaterialOverlayFXClip::SetAlpha( float flAlpha )
|
||||
{
|
||||
m_Color.SetAlpha( flAlpha * 255 );
|
||||
}
|
||||
|
||||
float CDmeMaterialOverlayFXClip::GetAlpha( void )
|
||||
{
|
||||
return ( (float)m_Color.a() ) / 255.0f;
|
||||
}
|
||||
|
||||
bool CDmeMaterialOverlayFXClip::HasOpaqueOverlay( void )
|
||||
{
|
||||
if ( m_OverlayMaterial )
|
||||
return ( !m_OverlayMaterial->IsTranslucent() && ( m_Color.a() == 255 ) && m_bFullScreen );
|
||||
|
||||
// no material overlay set
|
||||
return false;
|
||||
}
|
||||
|
||||
IMaterial *CDmeMaterialOverlayFXClip::GetMaterial()
|
||||
{
|
||||
return m_OverlayMaterial;
|
||||
}
|
||||
|
||||
|
||||
void CDmeMaterialOverlayFXClip::DrawQuad( int x, int y, int w, int h, float u0, float v0, float u1, float v1 )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
IMesh *pMesh = pRenderContext->GetDynamicMesh();
|
||||
CMeshBuilder meshBuilder;
|
||||
|
||||
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLE_STRIP, 2 );
|
||||
|
||||
meshBuilder.Position3f( x, y, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.Color4ub( 255, 255, 255, 255 );
|
||||
meshBuilder.TexCoord2f( 0, u0, v0 );
|
||||
meshBuilder.TexCoord2f( 1, 0.0f, 0.0f );
|
||||
meshBuilder.TexCoord2f( 2, 0.0f, 0.0f );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 3>();
|
||||
|
||||
meshBuilder.Position3f( x, y+h, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.Color4ub( 255, 255, 255, 255 );
|
||||
meshBuilder.TexCoord2f( 0, u0, v1 );
|
||||
meshBuilder.TexCoord2f( 1, 0.0f, 1.0f );
|
||||
meshBuilder.TexCoord2f( 2, 0.0f, 0.0f );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 3>();
|
||||
|
||||
meshBuilder.Position3f( x+w, y, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.Color4ub( 255, 255, 255, 255 );
|
||||
meshBuilder.TexCoord2f( 0, u1, v0 );
|
||||
meshBuilder.TexCoord2f( 1, 1.0f, 0.0f );
|
||||
meshBuilder.TexCoord2f( 2, 0.0f, 0.0f );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 3>();
|
||||
|
||||
meshBuilder.Position3f( x+w, y+h, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.Color4ub( 255, 255, 255, 255 );
|
||||
meshBuilder.TexCoord2f( 0, u1, v1 );
|
||||
meshBuilder.TexCoord2f( 1, 1.0f, 1.0f );
|
||||
meshBuilder.TexCoord2f( 2, 0.0f, 0.0f );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 3>();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
}
|
||||
|
||||
void CDmeMaterialOverlayFXClip::DrawOneToOneQuad( int nWidth, int nHeight )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
IMesh *pMesh = pRenderContext->GetDynamicMesh();
|
||||
CMeshBuilder meshBuilder;
|
||||
|
||||
// Epsilons for 1:1 texel to pixel mapping
|
||||
float fWidthEpsilon = 0.5f / ((float) nWidth);
|
||||
float fHeightEpsilon = 0.5f / ((float) nHeight);
|
||||
|
||||
meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
|
||||
|
||||
meshBuilder.Position3f( -1.0f, 1.0f, 0.5f ); // Upper left
|
||||
meshBuilder.TexCoord2f( 0, 0.0f + fWidthEpsilon, 0.0f + fHeightEpsilon);
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS, 1>();
|
||||
|
||||
meshBuilder.Position3f( -1.0f, -1.0f, 0.5f ); // Lower left
|
||||
meshBuilder.TexCoord2f( 0, 0.0f + fWidthEpsilon, 1.0f + fHeightEpsilon);
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS, 1>();
|
||||
|
||||
meshBuilder.Position3f( 1.0f, -1.0f, 0.5 ); // Lower right
|
||||
meshBuilder.TexCoord2f( 0, 1.0f + fWidthEpsilon, 1.0f + fHeightEpsilon);
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS, 1>();
|
||||
|
||||
meshBuilder.Position3f( 1.0f, 1.0f, 0.5 ); // Upper right
|
||||
meshBuilder.TexCoord2f( 0, 1.0f + fWidthEpsilon, 0.0f + fHeightEpsilon);
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS, 1>();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// All effects must be able to apply their effect
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMaterialOverlayFXClip::ApplyEffect( DmeTime_t time, Rect_t ¤tRect, Rect_t &totalRect, ITexture *pTextures[MAX_FX_INPUT_TEXTURES] )
|
||||
{
|
||||
if ( !m_OverlayMaterial || !m_BltMaterial || m_Color.a() == 0 )
|
||||
return;
|
||||
|
||||
time = ToChildMediaTime( time, false );
|
||||
|
||||
// Clip the overlay rectangle to the currently drawn one
|
||||
int x, y, w, h;
|
||||
int tx, ty, tw, th;
|
||||
if ( m_bFullScreen )
|
||||
{
|
||||
x = currentRect.x;
|
||||
y = currentRect.y;
|
||||
w = currentRect.width;
|
||||
h = currentRect.height;
|
||||
tx = ty = 0;
|
||||
tw = totalRect.width;
|
||||
th = totalRect.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = clamp( m_nLeft.Get(), currentRect.x, currentRect.x + currentRect.width );
|
||||
y = clamp( m_nTop.Get(), currentRect.y, currentRect.y + currentRect.height );
|
||||
int x1 = clamp( m_nLeft + m_nWidth, currentRect.x, currentRect.x + currentRect.width );
|
||||
int y1 = clamp( m_nTop + m_nHeight, currentRect.y, currentRect.y + currentRect.height );
|
||||
w = x1 - x;
|
||||
h = y1 - y;
|
||||
|
||||
tx = m_nLeft;
|
||||
ty = m_nTop;
|
||||
tw = m_nWidth;
|
||||
th = m_nHeight;
|
||||
|
||||
// Clipped...
|
||||
if ( w <= 0 || h <= 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tw == 0 || th == 0 )
|
||||
return;
|
||||
|
||||
// Compute texture coordinate range of the entire texture
|
||||
int mw = m_OverlayMaterial->GetMappingWidth();
|
||||
int mh = m_OverlayMaterial->GetMappingHeight();
|
||||
|
||||
// Compute the texture coords in texels we want over the entire image
|
||||
float uMin = 0;
|
||||
float uMax = mw;
|
||||
float vMin = 0;
|
||||
float vMax = mh;
|
||||
|
||||
if ( m_bUseSubRect )
|
||||
{
|
||||
uMin = m_nSubRectLeft;
|
||||
vMin = m_nSubRectTop;
|
||||
uMax = uMin + m_nSubRectWidth;
|
||||
vMax = vMin + m_nSubRectHeight;
|
||||
}
|
||||
|
||||
if ( m_flMovementSpeed )
|
||||
{
|
||||
float flRadians = M_PI * m_flMovementAngle / 180.0f;
|
||||
float dUdT = -m_flMovementSpeed * cos( flRadians );
|
||||
float dVdT = m_flMovementSpeed * sin( flRadians );
|
||||
float dU = time.GetSeconds() * dUdT;
|
||||
float dV = time.GetSeconds() * dVdT;
|
||||
uMin += dU; uMax += dU;
|
||||
vMin += dV; vMax += dV;
|
||||
}
|
||||
|
||||
// This is the range of normalizes (u,v) coordinates over the *total* image
|
||||
uMin = ( uMin + 0.5f ) / mw;
|
||||
vMin = ( vMin + 0.5f ) / mh;
|
||||
uMax = ( uMax - 0.5f ) / mw;
|
||||
vMax = ( vMax - 0.5f ) / mh;
|
||||
|
||||
// Now determine the subrange we should use given we're rendering a portion of the image
|
||||
float u0, v0, u1, v1, f;
|
||||
|
||||
f = ( x - tx ) / tw;
|
||||
u0 = Lerp( f, uMin, uMax );
|
||||
|
||||
f = ( x + w - tx ) / tw;
|
||||
u1 = Lerp( f, uMin, uMax );
|
||||
|
||||
f = ( y - ty ) / th;
|
||||
v0 = Lerp( f, vMin, vMax );
|
||||
|
||||
f = ( y + h - ty ) / th;
|
||||
v1 = Lerp( f, vMin, vMax );
|
||||
|
||||
x -= currentRect.x;
|
||||
y -= currentRect.y;
|
||||
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
|
||||
if ( m_OverlayMaterial->NeedsPowerOfTwoFrameBufferTexture() )
|
||||
{
|
||||
pRenderContext->Bind( m_BltMaterial, pTextures[0] );
|
||||
pRenderContext->PushRenderTargetAndViewport( pTextures[1], 0, 0, w, h ); // Blt current input to temp surface
|
||||
DrawOneToOneQuad( w, h );
|
||||
pRenderContext->PopRenderTargetAndViewport();
|
||||
|
||||
pRenderContext->SetFrameBufferCopyTexture( pTextures[1] );
|
||||
|
||||
pRenderContext->PushRenderTargetAndViewport( pTextures[0], 0, 0, w, h ); // Render to result surface
|
||||
}
|
||||
|
||||
float r, g, b, a;
|
||||
m_OverlayMaterial->GetColorModulation( &r, &g, &b );
|
||||
a = m_OverlayMaterial->GetAlphaModulation();
|
||||
|
||||
m_OverlayMaterial->ColorModulate( m_Color.r() / 255.0f, m_Color.g() / 255.0f, m_Color.b() / 255.0f );
|
||||
m_OverlayMaterial->AlphaModulate( m_Color.a() / 255.0f );
|
||||
|
||||
pRenderContext->Bind( m_OverlayMaterial );
|
||||
|
||||
DrawQuad( x, y, w, h, u0, v0, u1, v1 );
|
||||
|
||||
if ( m_OverlayMaterial->NeedsPowerOfTwoFrameBufferTexture() )
|
||||
{
|
||||
pRenderContext->PopRenderTargetAndViewport();
|
||||
}
|
||||
|
||||
m_OverlayMaterial->ColorModulate( r, g, b );
|
||||
m_OverlayMaterial->AlphaModulate( a );
|
||||
}
|
||||
|
||||
217
movieobjects/dmemdl.cpp
Normal file
217
movieobjects/dmemdl.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmemdl.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datacache/imdlcache.h"
|
||||
#include "istudiorender.h"
|
||||
#include "bone_setup.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "tier3/mdlutils.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMDL, CDmeMDL );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::OnConstruction()
|
||||
{
|
||||
m_bDrawInEngine = false;
|
||||
m_bZUp = false;
|
||||
// SetAttributeValueElement( "transform", CreateElement< CDmeTransform >() );
|
||||
// SetAttributeValue( "mdlfilename", "models/alyx.mdl" );
|
||||
m_Color.InitAndSet( this, "color", Color( 255, 255, 255, 255 ) );
|
||||
m_nSkin.InitAndSet( this, "skin", 0 );
|
||||
m_nBody.InitAndSet( this, "body", 0 );
|
||||
m_nSequence.InitAndSet( this, "sequence", 0 );
|
||||
m_nLOD.InitAndSet( this, "lod", 0 );
|
||||
m_flPlaybackRate.InitAndSet( this, "playbackrate", 30.0f );
|
||||
m_flTime.InitAndSet( this, "time", 0.0f );
|
||||
m_vecViewTarget.Init( this, "viewTarget" );
|
||||
m_bWorldSpaceViewTarget.Init( this, "worldSpaceViewTarget" );
|
||||
}
|
||||
|
||||
void CDmeMDL::OnDestruction()
|
||||
{
|
||||
m_MDL.SetMDL( MDLHANDLE_INVALID );
|
||||
}
|
||||
|
||||
|
||||
void CDmeMDL::SetMDL( MDLHandle_t handle )
|
||||
{
|
||||
m_MDL.SetMDL( handle );
|
||||
|
||||
Vector vecMins, vecMaxs;
|
||||
GetMDLBoundingBox( &vecMins, &vecMaxs, m_MDL.GetMDL(), m_nSequence );
|
||||
Vector vecLookAt( 100.0f, 0.0f, vecMaxs.z );
|
||||
|
||||
m_vecViewTarget.Set( vecLookAt );
|
||||
m_bWorldSpaceViewTarget = false;
|
||||
}
|
||||
|
||||
MDLHandle_t CDmeMDL::GetMDL( ) const
|
||||
{
|
||||
return m_MDL.GetMDL();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads the model matrix based on the transform
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::DrawInEngine( bool bDrawInEngine )
|
||||
{
|
||||
m_bDrawInEngine = bDrawInEngine;
|
||||
}
|
||||
|
||||
bool CDmeMDL::IsDrawingInEngine() const
|
||||
{
|
||||
return m_bDrawInEngine;
|
||||
}
|
||||
|
||||
void CDmeMDL::ZUp( bool bZUp )
|
||||
{
|
||||
m_bZUp = bZUp;
|
||||
}
|
||||
|
||||
bool CDmeMDL::IsZUp() const
|
||||
{
|
||||
return m_bZUp;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the bounding box for the model
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::GetBoundingBox( Vector *pMins, Vector *pMaxs ) const
|
||||
{
|
||||
GetMDLBoundingBox( pMins, pMaxs, m_MDL.GetMDL(), m_nSequence );
|
||||
|
||||
// Rotate the root transform to make it align with DMEs
|
||||
// DMEs up vector is the y axis
|
||||
if ( !m_bDrawInEngine )
|
||||
{
|
||||
Vector vecMins, vecMaxs;
|
||||
matrix3x4_t engineToDme;
|
||||
CDmeDag::EngineToDmeMatrix( engineToDme, m_bZUp );
|
||||
TransformAABB( engineToDme, *pMins, *pMaxs, vecMins, vecMaxs );
|
||||
*pMins = vecMins;
|
||||
*pMaxs = vecMaxs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the radius of the model as measured from the origin
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeMDL::GetRadius() const
|
||||
{
|
||||
return GetMDLRadius( m_MDL.GetMDL(), m_nSequence );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns a more accurate bounding sphere
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::GetBoundingSphere( Vector &vecCenter, float &flRadius )
|
||||
{
|
||||
Vector vecEngineCenter;
|
||||
GetMDLBoundingSphere( &vecEngineCenter, &flRadius, m_MDL.GetMDL(), m_nSequence );
|
||||
|
||||
// Rotate the root transform to make it align with DMEs
|
||||
// DMEs up vector is the y axis
|
||||
if ( !m_bDrawInEngine )
|
||||
{
|
||||
matrix3x4_t engineToDme;
|
||||
CDmeDag::EngineToDmeMatrix( engineToDme, m_bZUp );
|
||||
VectorTransform( vecEngineCenter, engineToDme, vecCenter );
|
||||
}
|
||||
else
|
||||
{
|
||||
vecCenter = vecEngineCenter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Updates the MDL rendering helper
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::UpdateMDL()
|
||||
{
|
||||
m_MDL.m_Color = m_Color;
|
||||
m_MDL.m_nSkin = m_nSkin;
|
||||
m_MDL.m_nBody = m_nBody;
|
||||
m_MDL.m_nSequence = m_nSequence;
|
||||
m_MDL.m_nLOD = m_nLOD;
|
||||
m_MDL.m_flPlaybackRate = m_flPlaybackRate;
|
||||
m_MDL.m_flTime = m_flTime;
|
||||
m_MDL.m_vecViewTarget = m_vecViewTarget;
|
||||
m_MDL.m_Color = m_Color;
|
||||
m_MDL.m_bWorldSpaceViewTarget = m_bWorldSpaceViewTarget;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDL::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
|
||||
{
|
||||
UpdateMDL();
|
||||
studiohdr_t *pStudioHdr = m_MDL.GetStudioHdr();
|
||||
if ( !pStudioHdr )
|
||||
return;
|
||||
|
||||
// FIXME: Why is this necessary!?!?!?
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
if ( !m_bDrawInEngine )
|
||||
{
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
|
||||
}
|
||||
|
||||
CMatRenderData< matrix3x4_t > rdPoseToWorld( pRenderContext, pStudioHdr->numbones );
|
||||
matrix3x4_t *pPoseToWorld = rdPoseToWorld.Base();
|
||||
SetUpBones( shapeToWorld, pStudioHdr->numbones, pPoseToWorld );
|
||||
|
||||
m_MDL.Draw( shapeToWorld, pPoseToWorld );
|
||||
|
||||
// FIXME: Why is this necessary!?!?!?
|
||||
if ( !m_bDrawInEngine )
|
||||
{
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDmeMDL::SetUpBones( const matrix3x4_t& shapeToWorld, int nMaxBoneCount, matrix3x4_t *pOutputMatrices )
|
||||
{
|
||||
UpdateMDL();
|
||||
|
||||
// Root transform
|
||||
matrix3x4_t rootToWorld;
|
||||
|
||||
// Rotate the root transform to make it align with DMEs
|
||||
// DMEs up vector is the y axis
|
||||
if ( !m_bDrawInEngine )
|
||||
{
|
||||
matrix3x4_t engineToDme;
|
||||
CDmeDag::EngineToDmeMatrix( engineToDme, m_bZUp );
|
||||
ConcatTransforms( engineToDme, shapeToWorld, rootToWorld );
|
||||
}
|
||||
else
|
||||
{
|
||||
MatrixCopy( shapeToWorld, rootToWorld );
|
||||
}
|
||||
|
||||
m_MDL.SetUpBones( rootToWorld, nMaxBoneCount, pOutputMatrices );
|
||||
}
|
||||
288
movieobjects/dmemdlmakefile.cpp
Normal file
288
movieobjects/dmemdlmakefile.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Describes an asset: something that is compiled from sources,
|
||||
// in potentially multiple steps, to a compiled resource
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "movieobjects/dmemdlmakefile.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
#include "movieobjects/dmemdl.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datacache/imdlcache.h"
|
||||
#include "filesystem.h"
|
||||
#include "tier3/tier3.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceSkin, CDmeSourceSkin );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceSkin::OnConstruction()
|
||||
{
|
||||
m_SkinName.Init( this, "skinName" );
|
||||
m_bFlipTriangles.Init( this, "flipTriangles" );
|
||||
m_bQuadSubd.Init( this, "quadSubd" );
|
||||
m_flScale.InitAndSet( this, "scale", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeSourceSkin::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These can be built from DCC makefiles
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pSkinMakeFiles[] =
|
||||
{
|
||||
"DmeMayaModelMakefile",
|
||||
"DmeXSIModelMakefile",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char **CDmeSourceSkin::GetSourceMakefileTypes()
|
||||
{
|
||||
return s_pSkinMakeFiles;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceCollisionModel, CDmeSourceCollisionModel );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceCollisionModel::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeSourceCollisionModel::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These can be built from DCC makefiles
|
||||
//-----------------------------------------------------------------------------
|
||||
const char **CDmeSourceCollisionModel::GetSourceMakefileTypes()
|
||||
{
|
||||
return s_pSkinMakeFiles;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSourceAnimation, CDmeSourceAnimation );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSourceAnimation::OnConstruction()
|
||||
{
|
||||
m_AnimationName.Init( this, "animationName" );
|
||||
m_SourceAnimationName.Init( this, "sourceAnimationName" );
|
||||
}
|
||||
|
||||
void CDmeSourceAnimation::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These can be built from DCC makefiles
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pAnimationMakeFiles[] =
|
||||
{
|
||||
"DmeMayaAnimationMakefile",
|
||||
"DmeXSIAnimationMakefile",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char **CDmeSourceAnimation::GetSourceMakefileTypes()
|
||||
{
|
||||
return s_pAnimationMakeFiles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hook into datamodel
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMDLMakefile, CDmeMDLMakefile );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDLMakefile::OnConstruction()
|
||||
{
|
||||
m_hMDL = CreateElement< CDmeMDL >( "MDLMakefile Preview", DMFILEID_INVALID );
|
||||
m_bFlushMDL = false;
|
||||
}
|
||||
|
||||
void CDmeMDLMakefile::OnDestruction()
|
||||
{
|
||||
DestroyElement( m_hMDL.Get() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns source types
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_pSourceTypes[] =
|
||||
{
|
||||
{ "DmeSourceSkin", "Skin", true, "makefiledir:models\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
|
||||
{ "DmeSourceAnimation", "Animation", false, "makefiledir:animations\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
|
||||
{ "DmeSourceCollisionModel", "Collision Model", true, "makefiledir:models\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
|
||||
{ NULL, NULL, false, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
DmeMakefileType_t* CDmeMDLMakefile::GetSourceTypes()
|
||||
{
|
||||
return s_pSourceTypes;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Makefile type
|
||||
//-----------------------------------------------------------------------------
|
||||
static DmeMakefileType_t s_MakefileType =
|
||||
{
|
||||
"DmeMDLMakefile", "Model", true, "contentdir:models", "*.dmx", "Valve Model MakeFile (*.dmx)"
|
||||
};
|
||||
|
||||
|
||||
DmeMakefileType_t *CDmeMDLMakefile::GetMakefileType()
|
||||
{
|
||||
return &s_MakefileType;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Add, remove sources
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMDLMakefile::SetSkin( const char *pFullPath )
|
||||
{
|
||||
RemoveAllSources( "DmeSourceSkin" );
|
||||
AddSource( "DmeSourceSkin", pFullPath );
|
||||
}
|
||||
|
||||
void CDmeMDLMakefile::AddAnimation( const char *pFullPath )
|
||||
{
|
||||
AddSource( "animation", pFullPath );
|
||||
}
|
||||
|
||||
void CDmeMDLMakefile::RemoveAnimation( const char *pFullPath )
|
||||
{
|
||||
RemoveSource( "animation", pFullPath );
|
||||
}
|
||||
|
||||
void CDmeMDLMakefile::RemoveAllAnimations( )
|
||||
{
|
||||
RemoveAllSources( "animation" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited classes should re-implement these methods
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CDmeMDLMakefile::CreateOutputElement( )
|
||||
{
|
||||
if ( m_bFlushMDL )
|
||||
{
|
||||
// Flush the model out of the cache; detach it from the MDL
|
||||
MDLHandle_t h = m_hMDL->GetMDL();
|
||||
if ( h != MDLHANDLE_INVALID )
|
||||
{
|
||||
g_pMDLCache->Flush( h );
|
||||
}
|
||||
m_bFlushMDL = false;
|
||||
}
|
||||
m_hMDL->SetMDL( MDLHANDLE_INVALID );
|
||||
|
||||
// FIXME: Should we ask the tool (studiomdl) for this?
|
||||
// Should we have output type names? Not sure yet..
|
||||
// Doing the simplest thing first.
|
||||
char pOutputName[MAX_PATH];
|
||||
Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
|
||||
if ( !pOutputName[0] )
|
||||
return m_hMDL.Get();
|
||||
|
||||
char pOutputDir[MAX_PATH];
|
||||
GetOutputDirectory( pOutputDir, sizeof(pOutputDir) );
|
||||
if ( !pOutputDir[0] )
|
||||
return m_hMDL.Get();
|
||||
|
||||
Q_StripTrailingSlash( pOutputDir );
|
||||
char pFullPath[MAX_PATH];
|
||||
Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.mdl", pOutputDir, pOutputName );
|
||||
|
||||
char pRelativePath[MAX_PATH];
|
||||
g_pFullFileSystem->FullPathToRelativePathEx( pFullPath, "GAME", pRelativePath, sizeof( pRelativePath ) );
|
||||
|
||||
MDLHandle_t h = g_pMDLCache->FindMDL( pRelativePath );
|
||||
m_hMDL->SetMDL( h );
|
||||
return m_hMDL.Get();
|
||||
}
|
||||
|
||||
void CDmeMDLMakefile::DestroyOutputElement( CDmElement *pOutput )
|
||||
{
|
||||
m_bFlushMDL = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compile assets
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pOutputExtensions[] =
|
||||
{
|
||||
"dx80.vtx",
|
||||
"dx90.vtx",
|
||||
"sw.vtx",
|
||||
"mdl",
|
||||
"vvd",
|
||||
"phy",
|
||||
NULL
|
||||
};
|
||||
|
||||
void CDmeMDLMakefile::GetOutputs( CUtlVector<CUtlString> &fullPaths )
|
||||
{
|
||||
fullPaths.RemoveAll();
|
||||
|
||||
// FIXME: Should we ask the tool (studiomdl) for this?
|
||||
// Should we have output type names? Not sure yet..
|
||||
// Doing the simplest thing first.
|
||||
char pOutputName[MAX_PATH];
|
||||
Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
|
||||
if ( !pOutputName[0] )
|
||||
return;
|
||||
|
||||
char pOutputDir[MAX_PATH];
|
||||
GetOutputDirectory( pOutputDir, sizeof(pOutputDir) );
|
||||
if ( !pOutputDir[0] )
|
||||
return;
|
||||
|
||||
Q_StripTrailingSlash( pOutputDir );
|
||||
char pFullPath[MAX_PATH];
|
||||
for ( int i = 0; s_pOutputExtensions[i]; ++i )
|
||||
{
|
||||
Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.%s", pOutputDir, pOutputName, s_pOutputExtensions[i] );
|
||||
fullPaths.AddToTail( pFullPath );
|
||||
}
|
||||
}
|
||||
|
||||
5258
movieobjects/dmemesh.cpp
Normal file
5258
movieobjects/dmemesh.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1489
movieobjects/dmemodel.cpp
Normal file
1489
movieobjects/dmemodel.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
movieobjects/dmemorphoperator.cpp
Normal file
157
movieobjects/dmemorphoperator.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmemorphoperator.h"
|
||||
#include "movieobjects/dmevertexdata.h"
|
||||
#include "movieobjects/dmemesh.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMorphOperator, CDmeMorphOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMorphOperator::OnConstruction()
|
||||
{
|
||||
m_mesh.Init( this, "mesh", FATTRIB_HAS_CALLBACK );
|
||||
m_deltaStateWeights.Init( this, "deltaStateWeights", FATTRIB_MUSTCOPY );
|
||||
m_baseStateName.Init( this, "baseStateName", FATTRIB_TOPOLOGICAL );
|
||||
}
|
||||
|
||||
void CDmeMorphOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// accessors
|
||||
//-----------------------------------------------------------------------------
|
||||
uint CDmeMorphOperator::NumDeltaStateWeights()
|
||||
{
|
||||
return m_deltaStateWeights.Count();
|
||||
}
|
||||
|
||||
CDmElement *CDmeMorphOperator::GetDeltaStateWeight( uint i )
|
||||
{
|
||||
return m_deltaStateWeights[ i ];
|
||||
}
|
||||
|
||||
CDmeMesh *CDmeMorphOperator::GetMesh()
|
||||
{
|
||||
return m_mesh.GetElement();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This function gets called whenever an attribute changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMorphOperator::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
if ( pAttribute == m_mesh.GetAttribute() )
|
||||
{
|
||||
CDmeMesh *pMesh = GetMesh();
|
||||
if ( pMesh )
|
||||
{
|
||||
#if 0 // right now, the file already contains these weights, and re-creating them breaks the channel connections
|
||||
m_deltaStateWeights.RemoveAll();
|
||||
|
||||
uint dn = pMesh->NumDeltaStates();
|
||||
for ( uint di = 0; di < dn; ++di )
|
||||
{
|
||||
CDmElement *pDeltaState = pMesh->GetDeltaState( di );
|
||||
const char *name = pDeltaState->GetName();
|
||||
|
||||
CDmElement *pDeltaWeight = CreateElement< CDmElement >( name, GetFileId() );
|
||||
pDeltaWeight->SetAttributeValue( "weight", 0.0f );
|
||||
|
||||
m_deltaStateWeights.AddToTail( pDeltaWeight->GetHandle() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMorphOperator::Operate()
|
||||
{
|
||||
CDmeMesh *mesh = GetMesh();
|
||||
|
||||
uint mn = NumDeltaStateWeights();
|
||||
for ( uint mi = 0; mi < mn; ++mi )
|
||||
{
|
||||
CDmElement *pDeltaState = GetDeltaStateWeight( mi );
|
||||
const char *deltaName = pDeltaState->GetName();
|
||||
float deltaWeight = pDeltaState->GetValue< float >( "weight" );
|
||||
|
||||
int di = mesh->FindDeltaStateIndex( deltaName );
|
||||
if ( di != -1 )
|
||||
{
|
||||
mesh->SetDeltaStateWeight( di, MESH_DELTA_WEIGHT_NORMAL, deltaWeight );
|
||||
}
|
||||
else
|
||||
{
|
||||
Msg( "MorphOperator::Operate: invalid delta state name: %s\n", deltaName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hack to avoid MSVC complaining about multiply defined symbols
|
||||
namespace MorphOp
|
||||
{
|
||||
void AddAttr( CUtlVector< CDmAttribute * > &attrs, CDmAttribute *pAttr )
|
||||
{
|
||||
if ( pAttr == NULL )
|
||||
return;
|
||||
attrs.AddToTail( pAttr );
|
||||
}
|
||||
|
||||
void AddVertexAttributes( CUtlVector< CDmAttribute * > &attrs, CDmElement *pObject )
|
||||
{
|
||||
AddAttr( attrs, pObject->GetAttribute( "coordinates" ) );
|
||||
AddAttr( attrs, pObject->GetAttribute( "normals" ) );
|
||||
AddAttr( attrs, pObject->GetAttribute( "textureCoordinates" ) );
|
||||
// TODO - add colors, occlusionFactors, boneIndices*, boneWeights*, tangents
|
||||
}
|
||||
};
|
||||
using namespace MorphOp;
|
||||
|
||||
void CDmeMorphOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
uint nWeights = NumDeltaStateWeights();
|
||||
for ( uint wi = 0; wi < nWeights; ++wi )
|
||||
{
|
||||
CDmElement *pDelta = GetDeltaStateWeight( wi );
|
||||
AddAttr( attrs, pDelta->GetAttribute( "weight" ) );
|
||||
}
|
||||
|
||||
CDmeMesh *pMesh = GetMesh();
|
||||
CDmeVertexData *pBaseState = pMesh->FindBaseState( m_baseStateName.Get() );
|
||||
AddVertexAttributes( attrs, pBaseState );
|
||||
|
||||
uint nDeltas = pMesh->DeltaStateCount();
|
||||
for ( uint di = 0; di < nDeltas; ++di )
|
||||
{
|
||||
CDmElement *pDeltaState = pMesh->GetDeltaState( di );
|
||||
AddAttr( attrs, pDeltaState->GetAttribute( "indices" ) );
|
||||
AddVertexAttributes( attrs, pDeltaState );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeMorphOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
AddVertexAttributes( attrs, GetMesh() );
|
||||
}
|
||||
104
movieobjects/dmemouseinput.cpp
Normal file
104
movieobjects/dmemouseinput.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmemouseinput.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
#include "vgui/iinput.h"
|
||||
#include "vgui/ipanel.h"
|
||||
#include "tier3/tier3.h"
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeMouseInput, CDmeMouseInput );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeMouseInput::OnConstruction()
|
||||
{
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
|
||||
m_xOrigin = 0.0f;
|
||||
m_yOrigin = 0.0f;
|
||||
}
|
||||
|
||||
void CDmeMouseInput::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsDirty - ie needs to operate
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeMouseInput::IsDirty()
|
||||
{
|
||||
float flX, flY;
|
||||
GetNormalizedCursorPos( flX, flY );
|
||||
flX -= m_xOrigin;
|
||||
flY -= m_yOrigin;
|
||||
|
||||
return ( flX != GetValue< float >( "x" ) ) || ( flY != GetValue< float >( "y" ) );
|
||||
}
|
||||
|
||||
void CDmeMouseInput::Operate()
|
||||
{
|
||||
float flX, flY;
|
||||
GetNormalizedCursorPos( flX, flY );
|
||||
|
||||
SetValue( "x", flX - m_xOrigin );
|
||||
SetValue( "y", flY - m_yOrigin );
|
||||
|
||||
// Msg( "CDmeMouseInput::Operate() at <%f, %f>\n", flX, flY );
|
||||
}
|
||||
|
||||
void CDmeMouseInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeMouseInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( GetAttribute( "x" ) );
|
||||
attrs.AddToTail( GetAttribute( "y" ) );
|
||||
}
|
||||
|
||||
void CDmeMouseInput::ResetOrigin( float dx, float dy )
|
||||
{
|
||||
GetNormalizedCursorPos( m_xOrigin, m_yOrigin );
|
||||
m_xOrigin += dx;
|
||||
m_yOrigin += dy;
|
||||
}
|
||||
|
||||
void CDmeMouseInput::GetNormalizedCursorPos( float &flX, float &flY )
|
||||
{
|
||||
int x, y;
|
||||
g_pVGuiInput->GetCursorPos( x, y );
|
||||
|
||||
vgui::VPANEL vpanel = g_pVGuiInput->GetFocus();
|
||||
if ( !vpanel )
|
||||
{
|
||||
flX = flY = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
int x0, y0;
|
||||
g_pVGuiPanel->GetPos( vpanel, x0, y0 );
|
||||
|
||||
int w, h;
|
||||
g_pVGuiPanel->GetSize( vpanel, w, h );
|
||||
|
||||
flX = ( x - x0 ) / float(w);
|
||||
flY = ( y - y0 ) / float(h);
|
||||
}
|
||||
186
movieobjects/dmeoperator.cpp
Normal file
186
movieobjects/dmeoperator.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeoperator.h"
|
||||
#include "movieobjects/dmeattributereference.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ABSTRACT_ELEMENT( DmeOperator, CDmeOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeOperator::OnConstruction()
|
||||
{
|
||||
m_nSortKey = -1;
|
||||
}
|
||||
|
||||
void CDmeOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsDirty - ie needs to operate
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeOperator::IsDirty()
|
||||
{
|
||||
return BaseClass::IsDirty();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose : get a list of all of the operators whose evaluation affects the
|
||||
// result of this operator's evaluation.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeOperator::GatherInputOperators( CUtlVector< CDmeOperator * > &operatorList )
|
||||
{
|
||||
// Another operator will only affect this operator if one or more of its output attributes is
|
||||
// an input attribute of this operator. So to find all of the input operators we first find all
|
||||
// of the input attributes of this operator, then find the elements which own those attributes
|
||||
// and find all of the operators referencing those elements. Finally we check to see if any of
|
||||
// the output attributes of the operators match any of the input attributes of this operator.
|
||||
|
||||
// Find the input attributes of this operator.
|
||||
CUtlVector< CDmAttribute* > inputAttributes( 0, 32 );
|
||||
GetInputAttributes( inputAttributes );
|
||||
|
||||
// Build a list of all the operators which are referencing any of the elements which own an input
|
||||
// attribute of this operator, these are all the operators which can possibly be input operators.
|
||||
int nInputAttributes = inputAttributes.Count();
|
||||
CUtlVector< CDmeOperator* > connectedOperators( 0, nInputAttributes );
|
||||
CUtlVector< CDmElement* > inputOwnerList( 0, nInputAttributes );
|
||||
|
||||
for ( int iAttr = 0; iAttr < nInputAttributes; ++iAttr )
|
||||
{
|
||||
CDmAttribute *pInputAttr = inputAttributes[ iAttr ];
|
||||
if ( pInputAttr == NULL )
|
||||
continue;
|
||||
|
||||
CDmElement *pInputOwner = pInputAttr->GetOwner();
|
||||
|
||||
// If the owner of the input is another operator, add it directly to the connected operator list.
|
||||
if ( ( pInputOwner != this ) && ( pInputOwner->IsA( CDmeOperator::GetStaticTypeSymbol() ) ) )
|
||||
{
|
||||
connectedOperators.AddToTail( CastElement< CDmeOperator >( pInputOwner ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the owner of the input is not an operator, check to see if it has any operators referring
|
||||
// to it. A list of these elements is kept so that the check is only done once per element.
|
||||
if ( inputOwnerList.Find( pInputOwner ) != inputOwnerList.InvalidIndex() )
|
||||
continue;
|
||||
|
||||
inputOwnerList.AddToTail( pInputOwner );
|
||||
|
||||
|
||||
for ( DmAttributeReferenceIterator_t it = g_pDataModel->FirstAttributeReferencingElement( pInputOwner->GetHandle() );
|
||||
it != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID;
|
||||
it = g_pDataModel->NextAttributeReferencingElement( it ) )
|
||||
{
|
||||
CDmAttribute *pAttr = g_pDataModel->GetAttribute( it );
|
||||
if ( pAttr == NULL )
|
||||
continue;
|
||||
|
||||
CDmElement *pElement = pAttr->GetOwner();
|
||||
CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
|
||||
|
||||
if ( pOperator == NULL )
|
||||
{
|
||||
pOperator = FindAncestorReferencingElement< CDmeOperator >( pElement );
|
||||
}
|
||||
|
||||
if ( pOperator != NULL )
|
||||
{
|
||||
if ( connectedOperators.Find( pOperator ) == connectedOperators.InvalidIndex() )
|
||||
{
|
||||
connectedOperators.AddToTail( pOperator );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now check each of the connected operators to determine if any of its output attributes is one
|
||||
// of this operator's input attributes. If so add it to the list of output operators if it is not
|
||||
// already there. Note, as soon as one attribute match is found there is no need to check the rest.
|
||||
CUtlVector< CDmAttribute* > outputAttributes( 0, 32 );
|
||||
|
||||
int nConnectedOperators = connectedOperators.Count();
|
||||
for ( int iOper = 0; iOper < nConnectedOperators; ++iOper )
|
||||
{
|
||||
CDmeOperator *pOperator = connectedOperators[ iOper ];
|
||||
|
||||
outputAttributes.RemoveAll();
|
||||
pOperator->GetOutputAttributes( outputAttributes );
|
||||
|
||||
int nOutputAttributes = outputAttributes.Count();
|
||||
for ( int iAttr = 0; iAttr < nOutputAttributes; ++iAttr )
|
||||
{
|
||||
CDmAttribute *pOuputAttr = outputAttributes[ iAttr ];
|
||||
if ( inputAttributes.Find( pOuputAttr ) != inputAttributes.InvalidIndex() )
|
||||
{
|
||||
if ( operatorList.Find( pOperator ) == operatorList.InvalidIndex() )
|
||||
{
|
||||
pOperator->GatherInputOperators( operatorList );
|
||||
operatorList.AddToTail( pOperator );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CDmeOperator::SetSortKey( int key )
|
||||
{
|
||||
m_nSortKey = key;
|
||||
}
|
||||
|
||||
int CDmeOperator::GetSortKey() const
|
||||
{
|
||||
return m_nSortKey;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose : Gather a list of all of the operators referencing this element and
|
||||
// all of the operators that they depend on.
|
||||
//-----------------------------------------------------------------------------
|
||||
void GatherOperatorsForElement( CDmElement *pRootElement, CUtlVector< CDmeOperator * > &operatorList )
|
||||
{
|
||||
for ( DmAttributeReferenceIterator_t it = g_pDataModel->FirstAttributeReferencingElement( pRootElement->GetHandle() );
|
||||
it != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID;
|
||||
it = g_pDataModel->NextAttributeReferencingElement( it ) )
|
||||
{
|
||||
CDmAttribute *pAttr = g_pDataModel->GetAttribute( it );
|
||||
CDmElement *pOwnerElement = pAttr->GetOwner();
|
||||
|
||||
if ( !g_pDataModel->GetElement( pOwnerElement->GetHandle() ) )
|
||||
continue;
|
||||
|
||||
CDmeOperator *pOperator = CastElement< CDmeOperator >( pOwnerElement );
|
||||
|
||||
if ( pOwnerElement->IsA( CDmeAttributeReference::GetStaticTypeSymbol() ) )
|
||||
{
|
||||
pOperator = FindAncestorReferencingElement< CDmeOperator >( pOwnerElement );
|
||||
}
|
||||
|
||||
if ( pOperator == NULL )
|
||||
continue;
|
||||
|
||||
if ( operatorList.Find( pOperator ) == operatorList.InvalidIndex() )
|
||||
{
|
||||
pOperator->GatherInputOperators( operatorList );
|
||||
operatorList.AddToTail( pOperator );
|
||||
}
|
||||
}
|
||||
}
|
||||
175
movieobjects/dmeoverlay.cpp
Normal file
175
movieobjects/dmeoverlay.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeoverlay.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include "datamodel/dmattributevar.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeOverlay, CDmeOverlay );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeOverlay::OnConstruction()
|
||||
{
|
||||
m_flWeight.Init( this, "weight", FATTRIB_HAS_CALLBACK );
|
||||
m_nSequence.Init( this, "sequence", FATTRIB_HAS_CALLBACK );
|
||||
m_flPrevCycle.Init( this, "prevCycle", FATTRIB_HAS_CALLBACK );
|
||||
m_flCycle.Init( this, "cycle", FATTRIB_HAS_CALLBACK );
|
||||
m_nOrder.Init( this, "order", FATTRIB_HAS_CALLBACK );
|
||||
m_flPlaybackRate.Init( this, "playbackRate", FATTRIB_HAS_CALLBACK );
|
||||
m_flLayerAnimtime.Init( this, "layerAnimtime", FATTRIB_HAS_CALLBACK );
|
||||
m_flLayerFadeOuttime.Init( this, "layerFadeOuttime", FATTRIB_HAS_CALLBACK );
|
||||
}
|
||||
|
||||
void CDmeOverlay::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeOverlay::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
|
||||
InvokeOnAttributeChangedOnReferrers( GetHandle(), pAttribute );
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetWeight() const
|
||||
{
|
||||
return m_flWeight;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetSequence() const
|
||||
{
|
||||
return m_nSequence;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetPrevCycle() const
|
||||
{
|
||||
return m_flPrevCycle;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetCycle() const
|
||||
{
|
||||
return m_flCycle;
|
||||
}
|
||||
|
||||
int CDmeOverlay::GetOrder() const
|
||||
{
|
||||
return m_nOrder;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetPlaybackRate() const
|
||||
{
|
||||
return m_flPlaybackRate;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetLayerAnimtime() const
|
||||
{
|
||||
return m_flLayerAnimtime;
|
||||
}
|
||||
|
||||
float CDmeOverlay::GetLayerFadeOuttime() const
|
||||
{
|
||||
return m_flLayerFadeOuttime;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetWeight( float flWeight )
|
||||
{
|
||||
m_flWeight = flWeight;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetSequence( int nSequence )
|
||||
{
|
||||
m_nSequence = nSequence;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetPrevCycle( float flPrevCycle )
|
||||
{
|
||||
m_flPrevCycle = flPrevCycle;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetCycle( float flCycle )
|
||||
{
|
||||
m_flCycle = flCycle;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetOrder( int nOrder )
|
||||
{
|
||||
m_nOrder = nOrder;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetPlaybackRate( float flPlaybackRate )
|
||||
{
|
||||
m_flPlaybackRate = flPlaybackRate;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetLayerAnimttime( float flAnimttime )
|
||||
{
|
||||
m_flLayerAnimtime = flAnimttime;
|
||||
}
|
||||
|
||||
void CDmeOverlay::SetLayerFadeOuttime( float flLayerFadeOuttime )
|
||||
{
|
||||
m_flLayerFadeOuttime = flLayerFadeOuttime;
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetWeightAttribute()
|
||||
{
|
||||
return m_flWeight.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetSequenceAttribute()
|
||||
{
|
||||
return m_nSequence.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetPrevCycleAttribute()
|
||||
{
|
||||
return m_flPrevCycle.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetCycleAttribute()
|
||||
{
|
||||
return m_flCycle.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetOrderAttribute()
|
||||
{
|
||||
return m_nOrder.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetPlaybackRateAttribute()
|
||||
{
|
||||
return m_flPlaybackRate.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetLayerAnimtimeAttribute()
|
||||
{
|
||||
return m_flLayerAnimtime.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeOverlay::GetLayerFadeOuttimeAttribute()
|
||||
{
|
||||
return m_flLayerFadeOuttime.GetAttribute();
|
||||
}
|
||||
|
||||
CDmeDag *CDmeOverlay::GetDag()
|
||||
{
|
||||
static CUtlSymbolLarge overlaySymbol = g_pDataModel->GetSymbol( "overlay" );
|
||||
CDmeDag *pDag = FindReferringElement< CDmeDag >( this, overlaySymbol );
|
||||
return pDag;
|
||||
}
|
||||
324
movieobjects/dmepackoperators.cpp
Normal file
324
movieobjects/dmepackoperators.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmepackoperators.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datamodel/dmattribute.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackColorOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackColorOperator, CDmePackColorOperator );
|
||||
|
||||
void CDmePackColorOperator::OnConstruction()
|
||||
{
|
||||
m_color.Init( this, "color" );
|
||||
m_red .Init( this, "red" );
|
||||
m_green.Init( this, "green" );
|
||||
m_blue .Init( this, "blue" );
|
||||
m_alpha.Init( this, "alpha" );
|
||||
}
|
||||
|
||||
void CDmePackColorOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackColorOperator::IsDirty()
|
||||
{
|
||||
const Color &c = m_color.Get();
|
||||
float s = 255.999f;
|
||||
return c.r() != s*m_red.Get() || c.g() != s*m_green.Get() || c.b() != s*m_blue.Get() || c.a() != s*m_alpha.Get();
|
||||
// return c.r() != m_red.Get() || c.g() != m_green.Get() || c.b() != m_blue.Get() || c.a() != m_alpha.Get();
|
||||
}
|
||||
|
||||
void CDmePackColorOperator::Operate()
|
||||
{
|
||||
float s = 255.999f;
|
||||
int r = clamp( s*m_red.Get(), 0, 255 );
|
||||
int g = clamp( s*m_green.Get(), 0, 255 );
|
||||
int b = clamp( s*m_blue.Get(), 0, 255 );
|
||||
int a = clamp( s*m_alpha.Get(), 0, 255 );
|
||||
m_color.Set( Color( r, g, b, a ) );
|
||||
}
|
||||
|
||||
void CDmePackColorOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_red.GetAttribute() );
|
||||
attrs.AddToTail( m_green.GetAttribute() );
|
||||
attrs.AddToTail( m_blue.GetAttribute() );
|
||||
attrs.AddToTail( m_alpha.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackColorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_color.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackVector2Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackVector2Operator, CDmePackVector2Operator );
|
||||
|
||||
void CDmePackVector2Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
}
|
||||
|
||||
void CDmePackVector2Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackVector2Operator::IsDirty()
|
||||
{
|
||||
const Vector2D &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get();
|
||||
}
|
||||
|
||||
void CDmePackVector2Operator::Operate()
|
||||
{
|
||||
m_vector.Set( Vector2D( m_x.Get(), m_y.Get() ) );
|
||||
}
|
||||
|
||||
void CDmePackVector2Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackVector2Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackVector3Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackVector3Operator, CDmePackVector3Operator );
|
||||
|
||||
void CDmePackVector3Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
}
|
||||
|
||||
void CDmePackVector3Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackVector3Operator::IsDirty()
|
||||
{
|
||||
const Vector &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get();
|
||||
}
|
||||
|
||||
void CDmePackVector3Operator::Operate()
|
||||
{
|
||||
m_vector.Set( Vector( m_x.Get(), m_y.Get(), m_z.Get() ) );
|
||||
}
|
||||
|
||||
void CDmePackVector3Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackVector3Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackVector4Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackVector4Operator, CDmePackVector4Operator );
|
||||
|
||||
void CDmePackVector4Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
m_w.Init( this, "w" );
|
||||
}
|
||||
|
||||
void CDmePackVector4Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackVector4Operator::IsDirty()
|
||||
{
|
||||
const Vector4D &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get() || v.w != m_w.Get();
|
||||
}
|
||||
|
||||
void CDmePackVector4Operator::Operate()
|
||||
{
|
||||
m_vector.Set( Vector4D( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
|
||||
}
|
||||
|
||||
void CDmePackVector4Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
attrs.AddToTail( m_w.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackVector4Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackQAngleOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackQAngleOperator, CDmePackQAngleOperator );
|
||||
|
||||
void CDmePackQAngleOperator::OnConstruction()
|
||||
{
|
||||
m_qangle.Init( this, "qangle" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
}
|
||||
|
||||
void CDmePackQAngleOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackQAngleOperator::IsDirty()
|
||||
{
|
||||
const QAngle &q = m_qangle.Get();
|
||||
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get();
|
||||
}
|
||||
|
||||
void CDmePackQAngleOperator::Operate()
|
||||
{
|
||||
m_qangle.Set( QAngle( m_x.Get(), m_y.Get(), m_z.Get() ) );
|
||||
}
|
||||
|
||||
void CDmePackQAngleOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackQAngleOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_qangle.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackQuaternionOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackQuaternionOperator, CDmePackQuaternionOperator );
|
||||
|
||||
void CDmePackQuaternionOperator::OnConstruction()
|
||||
{
|
||||
m_quaternion.Init( this, "quaternion" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
m_w.Init( this, "w" );
|
||||
}
|
||||
|
||||
void CDmePackQuaternionOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackQuaternionOperator::IsDirty()
|
||||
{
|
||||
const Quaternion &q = m_quaternion.Get();
|
||||
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get() || q.w != m_w.Get();
|
||||
}
|
||||
|
||||
void CDmePackQuaternionOperator::Operate()
|
||||
{
|
||||
m_quaternion.Set( Quaternion( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
|
||||
}
|
||||
|
||||
void CDmePackQuaternionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
attrs.AddToTail( m_w.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmePackQuaternionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_quaternion.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePackVMatrixOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePackVMatrixOperator, CDmePackVMatrixOperator );
|
||||
|
||||
void CDmePackVMatrixOperator::OnConstruction()
|
||||
{
|
||||
m_vmatrix.Init( this, "vmatrix" );
|
||||
char name[ 4 ];
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
Q_snprintf( name, sizeof(name), "m%d%d", i >> 2, i & 0x3 );
|
||||
m_cells[ i ].Init( this, name );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmePackVMatrixOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmePackVMatrixOperator::IsDirty()
|
||||
{
|
||||
const VMatrix &v = m_vmatrix.Get();
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
if ( *( v[ i ] ) != m_cells[ i ].Get() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDmePackVMatrixOperator::Operate()
|
||||
{
|
||||
VMatrix v;
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
*( v[ i ] ) = m_cells[ i ].Get();
|
||||
}
|
||||
m_vmatrix.Set( v );
|
||||
}
|
||||
|
||||
void CDmePackVMatrixOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
attrs.AddToTail( m_cells[i].GetAttribute() );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmePackVMatrixOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vmatrix.GetAttribute() );
|
||||
}
|
||||
781
movieobjects/dmeparticlesystemdefinition.cpp
Normal file
781
movieobjects/dmeparticlesystemdefinition.cpp
Normal file
@@ -0,0 +1,781 @@
|
||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmeparticlesystemdefinition.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmeeditortypedictionary.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "tier1/keyvalues.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/convar.h"
|
||||
#include "particles/particles.h"
|
||||
#include "dme_controls/attributeintchoicepanel.h"
|
||||
#include "dme_controls/attributeboolchoicepanel.h"
|
||||
#include "dme_controls/attributestringchoicepanel.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Human readable string for the particle functions
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pParticleFuncTypeName[PARTICLE_FUNCTION_COUNT] =
|
||||
{
|
||||
"Renderer", // FUNCTION_RENDERER = 0,
|
||||
"Operator", // FUNCTION_OPERATOR,
|
||||
"Initializer", // FUNCTION_INITIALIZER,
|
||||
"Emitter", // FUNCTION_EMITTER,
|
||||
"Children", // FUNCTION_CHILDREN,
|
||||
"ForceGenerator", // FUNCTION_FORCEGENERATOR
|
||||
"Constraint", // FUNCTION_CONSTRAINT
|
||||
};
|
||||
|
||||
const char *GetParticleFunctionTypeName( ParticleFunctionType_t type )
|
||||
{
|
||||
return s_pParticleFuncTypeName[type];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY_INSTALL_EXPLICITLY( DmeParticleFunction, CDmeParticleFunction );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::OnConstruction()
|
||||
{
|
||||
m_bSkipNextResolve = false;
|
||||
m_hTypeDictionary.Init( this, "type_dictionary", FATTRIB_DONTSAVE | FATTRIB_HIDDEN );
|
||||
}
|
||||
|
||||
void CDmeParticleFunction::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Construct an appropriate editor attribute info
|
||||
//-----------------------------------------------------------------------------
|
||||
static void CreateEditorAttributeInfo( CDmeEditorType *pEditorType, const char *pAttributeName, const char *pWidgetInfo )
|
||||
{
|
||||
if ( !pWidgetInfo )
|
||||
return;
|
||||
|
||||
CCommand parse;
|
||||
parse.Tokenize( pWidgetInfo );
|
||||
if ( parse.ArgC() == 1 )
|
||||
{
|
||||
CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "field info", DMFILEID_INVALID );
|
||||
pEditorType->AddAttributeInfo( pAttributeName, pInfo );
|
||||
pInfo->m_Widget = parse[0];
|
||||
return;
|
||||
}
|
||||
|
||||
if ( parse.ArgC() == 2 )
|
||||
{
|
||||
CDmeEditorChoicesInfo *pInfo = NULL;
|
||||
if ( !Q_stricmp( parse[0], "intchoice" ) )
|
||||
{
|
||||
pInfo = CreateElement< CDmeEditorIntChoicesInfo >( "field info", DMFILEID_INVALID );
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( parse[0], "boolchoice" ) )
|
||||
{
|
||||
pInfo = CreateElement< CDmeEditorBoolChoicesInfo >( "field info", DMFILEID_INVALID );
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( parse[0], "stringchoice" ) )
|
||||
{
|
||||
pInfo = CreateElement< CDmeEditorStringChoicesInfo >( "field info", DMFILEID_INVALID );
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( parse[0], "elementchoice" ) )
|
||||
{
|
||||
pInfo = CreateElement< CDmeEditorChoicesInfo >( "field info", DMFILEID_INVALID );
|
||||
}
|
||||
|
||||
if ( pInfo )
|
||||
{
|
||||
pInfo->SetChoiceType( parse[1] );
|
||||
pEditorType->AddAttributeInfo( pAttributeName, pInfo );
|
||||
pInfo->m_Widget = parse[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used for backward compat
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::AddMissingFields( const DmxElementUnpackStructure_t *pUnpack )
|
||||
{
|
||||
DestroyElement( m_hTypeDictionary, TD_DEEP );
|
||||
m_hTypeDictionary = CreateElement< CDmeEditorTypeDictionary >( "particleFunctionDict", DMFILEID_INVALID );
|
||||
CDmeEditorType *pEditorType = CreateElement< CDmeEditorType >( GetTypeString(), DMFILEID_INVALID );
|
||||
|
||||
for ( ; pUnpack->m_pAttributeName; ++pUnpack )
|
||||
{
|
||||
CreateEditorAttributeInfo( pEditorType, pUnpack->m_pAttributeName, (const char *)pUnpack->m_pUserData );
|
||||
|
||||
// Can happen if 'name' or 'functionName' is used
|
||||
if ( HasAttribute( pUnpack->m_pAttributeName ) )
|
||||
continue;
|
||||
|
||||
CDmAttribute *pAttribute = AddAttribute( pUnpack->m_pAttributeName, pUnpack->m_AttributeType );
|
||||
if ( pUnpack->m_pDefaultString )
|
||||
{
|
||||
int nLen = Q_strlen( pUnpack->m_pDefaultString );
|
||||
CUtlBuffer bufParse( pUnpack->m_pDefaultString, nLen, CUtlBuffer::TEXT_BUFFER | CUtlBuffer::READ_ONLY );
|
||||
pAttribute->Unserialize( bufParse );
|
||||
}
|
||||
}
|
||||
|
||||
m_hTypeDictionary->AddEditorType( pEditorType );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the particle operator
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::UpdateAttributes( const DmxElementUnpackStructure_t *pUnpack )
|
||||
{
|
||||
// Delete all old attributes
|
||||
CDmAttribute *pNext;
|
||||
for( CDmAttribute *pAttr = FirstAttribute(); pAttr; pAttr = pNext )
|
||||
{
|
||||
pNext = pAttr->NextAttribute();
|
||||
if ( pAttr->IsStandard() || pAttr->IsFlagSet( FATTRIB_EXTERNAL ) )
|
||||
continue;
|
||||
|
||||
RemoveAttributeByPtr( pAttr );
|
||||
}
|
||||
|
||||
AddMissingFields( pUnpack );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Marks a particle system as a new instance
|
||||
// This is basically a workaround to prevent newly-copied particle functions
|
||||
// from recompiling themselves a zillion times
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::MarkNewInstance()
|
||||
{
|
||||
m_bSkipNextResolve = true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Don't bother resolving during unserialization, the owning def will handle it
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::OnElementUnserialized()
|
||||
{
|
||||
BaseClass::OnElementUnserialized();
|
||||
MarkNewInstance();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recompiles the particle system when a change occurs
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleFunction::Resolve()
|
||||
{
|
||||
BaseClass::Resolve();
|
||||
|
||||
if ( m_bSkipNextResolve )
|
||||
{
|
||||
m_bSkipNextResolve = false;
|
||||
return;
|
||||
}
|
||||
|
||||
for( CDmAttribute* pAttr = FirstAttribute(); pAttr; pAttr = pAttr->NextAttribute() )
|
||||
{
|
||||
if ( !pAttr->IsFlagSet( FATTRIB_DIRTY ) )
|
||||
continue;
|
||||
|
||||
// Find all CDmeParticleSystemDefinitions referring to this function
|
||||
DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
|
||||
while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
|
||||
{
|
||||
CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
|
||||
|
||||
// NOTE: This could cause the same particle system definition to recompile
|
||||
// multiple times if it refers to the same function multiple times,
|
||||
// but we don't expect that to happen, so we won't bother checking for it
|
||||
CDmeParticleSystemDefinition *pDef = CastElement<CDmeParticleSystemDefinition>( pAttribute->GetOwner() );
|
||||
if ( pDef && pDef->GetFileId() == GetFileId() )
|
||||
{
|
||||
pDef->RecompileParticleSystem();
|
||||
}
|
||||
i = g_pDataModel->NextAttributeReferencingElement( i );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor type dictionary
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorTypeDictionary* CDmeParticleFunction::GetEditorTypeDictionary()
|
||||
{
|
||||
return m_hTypeDictionary;
|
||||
}
|
||||
|
||||
void CDmeParticleFunction::InstanceTypeDictionary()
|
||||
{
|
||||
if ( m_hTypeDictionary != DMELEMENT_HANDLE_INVALID )
|
||||
{
|
||||
m_hTypeDictionary = m_hTypeDictionary->Copy();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY_INSTALL_EXPLICITLY( DmeParticleOperator, CDmeParticleOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleOperator::OnConstruction()
|
||||
{
|
||||
m_FunctionName.Init( this, "functionName" );
|
||||
}
|
||||
|
||||
void CDmeParticleOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the particle operator
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleOperator::SetFunction( IParticleOperatorDefinition *pDefinition )
|
||||
{
|
||||
m_FunctionName = pDefinition->GetName();
|
||||
const DmxElementUnpackStructure_t *pUnpack = pDefinition->GetUnpackStructure();
|
||||
UpdateAttributes( pUnpack );
|
||||
}
|
||||
|
||||
const char *CDmeParticleOperator::GetFunctionType() const
|
||||
{
|
||||
return m_FunctionName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY_INSTALL_EXPLICITLY( DmeParticleChild, CDmeParticleChild );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleChild::OnConstruction()
|
||||
{
|
||||
m_Child.Init( this, "child", FATTRIB_NEVERCOPY );
|
||||
/*
|
||||
CDmeEditorType *pEditorType = CreateElement< CDmeEditorType >( "DmeParticleChild", DMFILEID_INVALID );
|
||||
CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "field info", DMFILEID_INVALID );
|
||||
pEditorType->AddAttributeInfo( "child", pInfo );
|
||||
pInfo->m_Widget = "particle_picker";
|
||||
m_hTypeDictionary->AddEditorType( pEditorType );
|
||||
*/
|
||||
}
|
||||
|
||||
void CDmeParticleChild::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the particle system child
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleChild::SetChildParticleSystem( CDmeParticleSystemDefinition *pDef, IParticleOperatorDefinition *pDefinition )
|
||||
{
|
||||
// FIXME: Convert system name into a
|
||||
m_Child = pDef;
|
||||
const DmxElementUnpackStructure_t *pUnpack = pDefinition->GetUnpackStructure();
|
||||
UpdateAttributes( pUnpack );
|
||||
}
|
||||
|
||||
const char *CDmeParticleChild::GetFunctionType() const
|
||||
{
|
||||
const CDmeParticleSystemDefinition *pChild = m_Child;
|
||||
return pChild ? pChild->GetName() : "";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY_INSTALL_EXPLICITLY( DmeParticleSystemDefinition, CDmeParticleSystemDefinition );
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::OnConstruction()
|
||||
{
|
||||
m_ParticleFunction[FUNCTION_RENDERER].Init( this, "renderers" );
|
||||
m_ParticleFunction[FUNCTION_OPERATOR].Init( this, "operators" );
|
||||
m_ParticleFunction[FUNCTION_INITIALIZER].Init( this, "initializers" );
|
||||
m_ParticleFunction[FUNCTION_EMITTER].Init( this, "emitters" );
|
||||
m_ParticleFunction[FUNCTION_CHILDREN].Init( this, "children" );
|
||||
m_ParticleFunction[FUNCTION_FORCEGENERATOR].Init( this, "forces" );
|
||||
m_ParticleFunction[FUNCTION_CONSTRAINT].Init( this, "constraints" );
|
||||
m_bPreventNameBasedLookup.Init( this, "preventNameBasedLookup" );
|
||||
|
||||
m_hTypeDictionary = CreateElement< CDmeEditorTypeDictionary >( "particleSystemDefinitionDict", DMFILEID_INVALID );
|
||||
CDmeEditorType *pEditorType = CreateElement< CDmeEditorType >( "DmeParticleSystemDefinition", DMFILEID_INVALID );
|
||||
|
||||
const DmxElementUnpackStructure_t *pUnpack = g_pParticleSystemMgr->GetParticleSystemDefinitionUnpackStructure();
|
||||
for ( ; pUnpack->m_pAttributeName; ++pUnpack )
|
||||
{
|
||||
CreateEditorAttributeInfo( pEditorType, pUnpack->m_pAttributeName, (const char *)pUnpack->m_pUserData );
|
||||
|
||||
CDmAttribute *pAttribute = AddAttribute( pUnpack->m_pAttributeName, pUnpack->m_AttributeType );
|
||||
if ( pUnpack->m_pDefaultString )
|
||||
{
|
||||
int nLen = MAX( 1, Q_strlen( pUnpack->m_pDefaultString ) );
|
||||
CUtlBuffer bufParse( pUnpack->m_pDefaultString, nLen, CUtlBuffer::TEXT_BUFFER | CUtlBuffer::READ_ONLY );
|
||||
pAttribute->Unserialize( bufParse );
|
||||
}
|
||||
}
|
||||
|
||||
m_hTypeDictionary->AddEditorType( pEditorType );
|
||||
}
|
||||
|
||||
void CDmeParticleSystemDefinition::OnDestruction()
|
||||
{
|
||||
DestroyElement( m_hTypeDictionary, TD_DEEP );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the editor type dictionary
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeEditorTypeDictionary* CDmeParticleSystemDefinition::GetEditorTypeDictionary()
|
||||
{
|
||||
return m_hTypeDictionary;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Remove obsolete attributes
|
||||
//-----------------------------------------------------------------------------
|
||||
static void RemoveObsoleteAttributes( CDmElement *pElement, const DmxElementUnpackStructure_t *pUnpack )
|
||||
{
|
||||
// Delete all obsolete attributes
|
||||
CDmAttribute *pNext;
|
||||
for( CDmAttribute *pAttr = pElement->FirstAttribute(); pAttr; pAttr = pNext )
|
||||
{
|
||||
pNext = pAttr->NextAttribute();
|
||||
if ( pAttr->IsStandard() || pAttr->IsFlagSet( FATTRIB_EXTERNAL ) )
|
||||
continue;
|
||||
|
||||
bool bFound = false;
|
||||
for ( const DmxElementUnpackStructure_t *pTrav = pUnpack; pTrav->m_pAttributeName; ++pTrav )
|
||||
{
|
||||
if ( !Q_stricmp( pTrav->m_pAttributeName, pAttr->GetName() ) )
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !bFound )
|
||||
{
|
||||
pElement->RemoveAttributeByPtr( pAttr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all attributes from the element that are either:
|
||||
// A) Not in the unpack structure (eg. stale)
|
||||
// B) Equal to their default value
|
||||
static void CompactElement( CDmElement *pElement, const DmxElementUnpackStructure_t *pUnpack )
|
||||
{
|
||||
CDmAttribute *pNext;
|
||||
for( CDmAttribute *pAttr = pElement->FirstAttribute(); pAttr; pAttr = pNext )
|
||||
{
|
||||
pNext = pAttr->NextAttribute();
|
||||
if ( pAttr->IsStandard() || pAttr->IsFlagSet( FATTRIB_EXTERNAL ) )
|
||||
continue;
|
||||
|
||||
const DmxElementUnpackStructure_t *pFoundUnpack = NULL;
|
||||
for ( const DmxElementUnpackStructure_t *pTrav = pUnpack; pTrav->m_pAttributeName; ++pTrav )
|
||||
{
|
||||
if ( !Q_stricmp( pTrav->m_pAttributeName, pAttr->GetName() ) )
|
||||
{
|
||||
pFoundUnpack = pTrav;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !pFoundUnpack )
|
||||
{
|
||||
// wasn't found in the unpack - attribute is stale
|
||||
pElement->RemoveAttributeByPtr( pAttr );
|
||||
}
|
||||
else if ( pFoundUnpack && pFoundUnpack->m_pDefaultString )
|
||||
{
|
||||
int nLen = Q_strlen( pFoundUnpack->m_pDefaultString );
|
||||
CUtlBuffer bufParse( pFoundUnpack->m_pDefaultString, nLen, CUtlBuffer::TEXT_BUFFER | CUtlBuffer::READ_ONLY );
|
||||
|
||||
if ( pAttr->IsIdenticalToSerializedValue( bufParse ) )
|
||||
{
|
||||
// equal to the default value - safe to remove
|
||||
pElement->RemoveAttributeByPtr( pAttr );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used for automatic handling of backward compatability
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::OnElementUnserialized()
|
||||
{
|
||||
BaseClass::OnElementUnserialized();
|
||||
|
||||
RemoveObsoleteAttributes( this, g_pParticleSystemMgr->GetParticleSystemDefinitionUnpackStructure() );
|
||||
|
||||
// Add missing fields that are new
|
||||
for ( int i = 0; i < PARTICLE_FUNCTION_COUNT; ++i )
|
||||
{
|
||||
ParticleFunctionType_t type = (ParticleFunctionType_t)i;
|
||||
CUtlVector< IParticleOperatorDefinition *> &list = g_pParticleSystemMgr->GetAvailableParticleOperatorList( type );
|
||||
int nAvailType = list.Count();
|
||||
int nCount = GetParticleFunctionCount( type );
|
||||
for ( int j = 0; j < nCount; ++j )
|
||||
{
|
||||
CDmeParticleFunction *pFunction = GetParticleFunction( type, j );
|
||||
|
||||
if ( i == FUNCTION_CHILDREN )
|
||||
{
|
||||
RemoveObsoleteAttributes( pFunction, list[0]->GetUnpackStructure() );
|
||||
pFunction->AddMissingFields( list[0]->GetUnpackStructure() );
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int k = 0; k < nAvailType; ++k )
|
||||
{
|
||||
if ( Q_stricmp( pFunction->GetName(), list[k]->GetName() ) )
|
||||
continue;
|
||||
|
||||
RemoveObsoleteAttributes( pFunction, list[k]->GetUnpackStructure() );
|
||||
pFunction->AddMissingFields( list[k]->GetUnpackStructure() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Check to see if any attributes changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::Resolve()
|
||||
{
|
||||
BaseClass::Resolve();
|
||||
for( CDmAttribute* pAttr = FirstAttribute(); pAttr; pAttr = pAttr->NextAttribute() )
|
||||
{
|
||||
if ( pAttr->IsFlagSet( FATTRIB_DIRTY ) )
|
||||
{
|
||||
RecompileParticleSystem();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Add, remove
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeParticleFunction* CDmeParticleSystemDefinition::AddOperator( ParticleFunctionType_t type, const char *pFunctionName )
|
||||
{
|
||||
CUtlVector< IParticleOperatorDefinition *> &list = g_pParticleSystemMgr->GetAvailableParticleOperatorList( type );
|
||||
|
||||
int nCount = list.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( Q_stricmp( pFunctionName, list[i]->GetName() ) )
|
||||
continue;
|
||||
|
||||
CDmeParticleOperator *pFunction = CreateElement< CDmeParticleOperator >( pFunctionName, GetFileId() );
|
||||
m_ParticleFunction[type].AddToTail( pFunction );
|
||||
pFunction->SetFunction( list[i] );
|
||||
return pFunction;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CDmeParticleSystemDefinition::OverrideAttributesFromOtherDefinition( CDmeParticleSystemDefinition *pDef )
|
||||
{
|
||||
for ( const CDmAttribute *pAttr = pDef->FirstAttribute(); pAttr != NULL; pAttr = pAttr->NextAttribute() )
|
||||
{
|
||||
DmAttributeType_t type = pAttr->GetType();
|
||||
const char *pAttrName = pAttr->GetName();
|
||||
CDmAttribute *pCopyAttr = GetAttribute( pAttrName );
|
||||
|
||||
if ( !V_stricmp( pAttrName, "name" ) )
|
||||
continue;
|
||||
|
||||
if ( pCopyAttr == NULL )
|
||||
{
|
||||
pCopyAttr = AddAttribute( pAttrName, type );
|
||||
|
||||
int flags = pAttr->GetFlags();
|
||||
Assert( ( flags & FATTRIB_EXTERNAL ) == 0 );
|
||||
flags &= ~FATTRIB_EXTERNAL;
|
||||
|
||||
pCopyAttr->ClearFlags();
|
||||
pCopyAttr->AddFlag( flags );
|
||||
}
|
||||
|
||||
// Temporarily remove the read-only flag from the copy while we copy into it
|
||||
bool bReadOnly = pCopyAttr->IsFlagSet( FATTRIB_READONLY );
|
||||
if ( bReadOnly )
|
||||
{
|
||||
pCopyAttr->RemoveFlag( FATTRIB_READONLY );
|
||||
}
|
||||
|
||||
if ( type == AT_ELEMENT )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
else if ( type == AT_ELEMENT_ARRAY )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
else
|
||||
{
|
||||
pCopyAttr->SetValue( pAttr );
|
||||
}
|
||||
|
||||
if ( bReadOnly )
|
||||
{
|
||||
pCopyAttr->AddFlag( FATTRIB_READONLY );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CDmeParticleFunction* CDmeParticleSystemDefinition::AddCopyOfOperator( CDmeParticleFunction *pFunc )
|
||||
{
|
||||
for ( int nType = 0; nType < PARTICLE_FUNCTION_COUNT; ++nType )
|
||||
{
|
||||
CUtlVector< IParticleOperatorDefinition *> &list = g_pParticleSystemMgr->GetAvailableParticleOperatorList( (ParticleFunctionType_t)nType );
|
||||
|
||||
int nCount = list.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( nType == FUNCTION_CHILDREN )
|
||||
{
|
||||
if ( !pFunc->IsA<CDmeParticleChild>() )
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Q_stricmp( pFunc->GetFunctionType(), list[i]->GetName() ) )
|
||||
continue;
|
||||
}
|
||||
|
||||
CDmeParticleFunction *pCopy = pFunc->Copy(TD_SHALLOW);
|
||||
pCopy->SetFileId( GetFileId(), TD_SHALLOW );
|
||||
pCopy->InstanceTypeDictionary();
|
||||
m_ParticleFunction[nType].AddToTail( pCopy );
|
||||
|
||||
return pCopy;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CDmeParticleFunction* CDmeParticleSystemDefinition::AddChild( CDmeParticleSystemDefinition *pChild )
|
||||
{
|
||||
Assert( pChild );
|
||||
|
||||
CUtlVector< IParticleOperatorDefinition *> &list = g_pParticleSystemMgr->GetAvailableParticleOperatorList( FUNCTION_CHILDREN );
|
||||
Assert( list.Count() == 1 );
|
||||
CDmeParticleChild *pFunction = CreateElement< CDmeParticleChild >( pChild->GetName(), GetFileId() );
|
||||
m_ParticleFunction[FUNCTION_CHILDREN].AddToTail( pFunction );
|
||||
pFunction->SetChildParticleSystem( pChild, list[0] );
|
||||
return pFunction;
|
||||
}
|
||||
|
||||
void CDmeParticleSystemDefinition::RemoveFunction( ParticleFunctionType_t type, CDmeParticleFunction *pFunction )
|
||||
{
|
||||
int nIndex = FindFunction( type, pFunction );
|
||||
if ( nIndex >= 0 )
|
||||
{
|
||||
m_ParticleFunction[type].Remove(nIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeParticleSystemDefinition::FindFunction( ParticleFunctionType_t type, CDmeParticleFunction *pParticleFunction )
|
||||
{
|
||||
int nCount = m_ParticleFunction[type].Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( pParticleFunction == m_ParticleFunction[type][i] )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CDmeParticleSystemDefinition::FindFunction( ParticleFunctionType_t type, const char *pFunctionName )
|
||||
{
|
||||
int nCount = m_ParticleFunction[type].Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pFunctionName, m_ParticleFunction[type][i]->GetFunctionType() ) )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeParticleSystemDefinition::GetParticleFunctionCount( ParticleFunctionType_t type ) const
|
||||
{
|
||||
return m_ParticleFunction[type].Count();
|
||||
}
|
||||
|
||||
CDmeParticleFunction *CDmeParticleSystemDefinition::GetParticleFunction( ParticleFunctionType_t type, int nIndex )
|
||||
{
|
||||
return m_ParticleFunction[type][nIndex];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reordering
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::MoveFunctionUp( ParticleFunctionType_t type, CDmeParticleFunction *pElement )
|
||||
{
|
||||
int nIndex = FindFunction( type, pElement );
|
||||
if ( nIndex > 0 )
|
||||
{
|
||||
m_ParticleFunction[type].Swap( nIndex, nIndex - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeParticleSystemDefinition::MoveFunctionDown( ParticleFunctionType_t type, CDmeParticleFunction *pElement )
|
||||
{
|
||||
int nIndex = FindFunction( type, pElement );
|
||||
int nLastIndex = m_ParticleFunction[type].Count() - 1;
|
||||
if ( nIndex >= 0 && nIndex < nLastIndex )
|
||||
{
|
||||
m_ParticleFunction[type].Swap( nIndex, nIndex + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Marks a particle system as a new instance
|
||||
// This is basically a workaround to prevent newly-copied particle functions
|
||||
// from recompiling themselves a zillion times
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::MarkNewInstance()
|
||||
{
|
||||
for ( int i = 0; i < PARTICLE_FUNCTION_COUNT; ++i )
|
||||
{
|
||||
int nCount = m_ParticleFunction[i].Count();
|
||||
for ( int j = 0; j < nCount; ++j )
|
||||
{
|
||||
m_ParticleFunction[i][j]->MarkNewInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recompiles the particle system when a change occurs
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeParticleSystemDefinition::RecompileParticleSystem()
|
||||
{
|
||||
const char *pFileFormat = "pcf";
|
||||
const char *pEncoding = g_pDataModel->GetDefaultEncoding( pFileFormat );
|
||||
int nFlags = g_pDataModel->IsEncodingBinary( pEncoding ) ? 0 : CUtlBuffer::TEXT_BUFFER;
|
||||
CUtlBuffer buf( 0, 0, nFlags );
|
||||
if ( g_pDataModel->Serialize( buf, pEncoding, pFileFormat, GetHandle() ) )
|
||||
{
|
||||
g_pParticleSystemMgr->ReadParticleConfigFile( buf, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDmeParticleSystemDefinition::RemoveInvalidFunctions()
|
||||
{
|
||||
for ( int f = 0; f < PARTICLE_FUNCTION_COUNT; ++f )
|
||||
{
|
||||
for ( int i = 0; i < m_ParticleFunction[f].Count(); )
|
||||
{
|
||||
CDmeParticleFunction* pFunc = m_ParticleFunction[f].Element(i);
|
||||
if ( pFunc == NULL )
|
||||
{
|
||||
m_ParticleFunction[f].Remove(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeParticleSystemDefinition::Compact()
|
||||
{
|
||||
// Traverse the entire definition and purge all the DM elements
|
||||
|
||||
CompactElement( this, g_pParticleSystemMgr->GetParticleSystemDefinitionUnpackStructure() );
|
||||
|
||||
for ( int i = 0; i < PARTICLE_FUNCTION_COUNT; ++i )
|
||||
{
|
||||
ParticleFunctionType_t type = (ParticleFunctionType_t)i;
|
||||
CUtlVector< IParticleOperatorDefinition *> &list = g_pParticleSystemMgr->GetAvailableParticleOperatorList( type );
|
||||
int nAvailType = list.Count();
|
||||
int nCount = GetParticleFunctionCount( type );
|
||||
for ( int j = 0; j < nCount; ++j )
|
||||
{
|
||||
CDmeParticleFunction *pFunction = GetParticleFunction( type, j );
|
||||
|
||||
if ( i == FUNCTION_CHILDREN )
|
||||
{
|
||||
CompactElement( pFunction, list[0]->GetUnpackStructure() );
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int k = 0; k < nAvailType; ++k )
|
||||
{
|
||||
if ( Q_stricmp( pFunction->GetName(), list[k]->GetName() ) )
|
||||
continue;
|
||||
|
||||
CompactElement( pFunction, list[k]->GetUnpackStructure() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
movieobjects/dmephonememapping.cpp
Normal file
22
movieobjects/dmephonememapping.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmephonememapping.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmePhonemeMapping
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePhonemeMapping, CDmePhonemeMapping );
|
||||
|
||||
void CDmePhonemeMapping::OnConstruction()
|
||||
{
|
||||
m_Preset.Init( this, "preset" );
|
||||
m_Weight.InitAndSet( this, "weight", 1.0f );
|
||||
}
|
||||
|
||||
void CDmePhonemeMapping::OnDestruction()
|
||||
{
|
||||
}
|
||||
667
movieobjects/dmerig.cpp
Normal file
667
movieobjects/dmerig.cpp
Normal file
@@ -0,0 +1,667 @@
|
||||
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Implementation of the CDmeRig class, a class which groups a set of
|
||||
// associated constraints and operators together, allowing operations to be
|
||||
// performed on the group of elements. Also contains the implementation of
|
||||
// CDmeRigAnimSetElements, a helper class used to store a list of elements which
|
||||
// are all associated with a single animation set.
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmerig.h"
|
||||
#include "movieobjects/dmeanimationset.h"
|
||||
#include "movieobjects/dmeoperator.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
#include "movieobjects/dmetrackgroup.h"
|
||||
#include "movieobjects/dmetrack.h"
|
||||
#include "movieobjects/dmerigconstraintoperators.h"
|
||||
#include "movieobjects/dmetransformcontrol.h"
|
||||
#include "movieobjects/dmechannel.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
// Expose this the classes to the scene database
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeRigAnimSetElements, CDmeRigAnimSetElements );
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeRig, CDmeRig );
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide post construction processing.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::OnConstruction()
|
||||
{
|
||||
m_AnimationSet.Init( this, "animationSet" );
|
||||
m_ElementList.Init( this, "elementList" );
|
||||
m_HiddenGroups.Init( this, "hiddenGroups" );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide processing and cleanup before shutdown
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::OnDestruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Set the animation set elements in the list are to be associated with, only allowed
|
||||
// when the element list is empty.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::SetAnimationSet( CDmeAnimationSet* pAnimationSet )
|
||||
{
|
||||
// The element list must be empty when the animation set is assigned.
|
||||
Assert( m_ElementList.Count() == 0 );
|
||||
|
||||
if ( m_ElementList.Count() == 0 )
|
||||
{
|
||||
m_AnimationSet = pAnimationSet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add an element to the list
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::AddElement( CDmElement *pElement )
|
||||
{
|
||||
if ( pElement == NULL )
|
||||
return;
|
||||
|
||||
m_ElementList.AddToTail( pElement );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove the specified element from the list. Returns true if the element is found and
|
||||
// removed, return false if the element could not be found.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeRigAnimSetElements::RemoveElement( CDmElement *pElement )
|
||||
{
|
||||
int index = m_ElementList.Find( pElement );
|
||||
if ( index != m_ElementList.InvalidIndex() )
|
||||
{
|
||||
m_ElementList.Remove( index );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove all of the elements from the list
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::RemoveAll()
|
||||
{
|
||||
m_ElementList.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add all of the elements to the provided array
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::GetElements( CUtlVector< CDmElement* > &elementList ) const
|
||||
{
|
||||
int nElements = m_ElementList.Count();
|
||||
for ( int iElement = 0; iElement < nElements; ++iElement )
|
||||
{
|
||||
CDmElement *pElement = m_ElementList[ iElement ];
|
||||
if ( pElement )
|
||||
{
|
||||
elementList.AddToTail( pElement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Add a control group to the list of hidden control groups
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRigAnimSetElements::AddHiddenControlGroup( CDmeControlGroup *pControlGroup )
|
||||
{
|
||||
m_HiddenGroups.AddToTail( pControlGroup->GetName() );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide post construction processing.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::OnConstruction()
|
||||
{
|
||||
m_AnimSetList.Init( this, "animSetList" );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Provide processing and cleanup before shutdown
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::OnDestruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Add an element to the rig
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::AddElement( CDmElement* pElement, CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
if ( ( pElement == NULL ) || ( pAnimationSet == NULL ) )
|
||||
return;
|
||||
|
||||
// Search for an element set with the specified
|
||||
// animation set, if none is found, create one.
|
||||
CDmeRigAnimSetElements *pAnimSetElementList = FindOrCreateAnimSetElementList( pAnimationSet );
|
||||
|
||||
if ( pAnimSetElementList )
|
||||
{
|
||||
pAnimSetElementList->AddElement( pElement );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Set the state of the specified control group and add it to list of control group modified by
|
||||
// the rig
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::HideControlGroup( CDmeControlGroup *pGroup )
|
||||
{
|
||||
if ( pGroup == NULL )
|
||||
return;
|
||||
|
||||
CDmeAnimationSet *pAnimationSet = pGroup->FindAnimationSet( true );
|
||||
if ( pAnimationSet == NULL )
|
||||
return;
|
||||
|
||||
CDmeRigAnimSetElements *pAnimSetElementList = FindOrCreateAnimSetElementList( pAnimationSet );
|
||||
|
||||
if ( pAnimSetElementList)
|
||||
{
|
||||
pGroup->SetVisible( false );
|
||||
pAnimSetElementList->AddHiddenControlGroup( pGroup );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove an element from the rig
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::RemoveElement( CDmElement *pElement, CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
if ( pElement == NULL )
|
||||
return;
|
||||
|
||||
// Search each of the animation set element lists for the specified element, if the element
|
||||
// is found and removed from an animation set element list, stop and don't search the others,
|
||||
// as each element should belong to only on animation set.
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements )
|
||||
{
|
||||
if ( pAnimSetElements->AnimationSet() == pAnimationSet )
|
||||
{
|
||||
if ( pAnimSetElements->RemoveElement( pElement ) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove an animation set and all associated elements from the group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::RemoveAnimationSet( CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
int index = FindAnimSetElementList( pAnimationSet );
|
||||
|
||||
if ( index != m_AnimSetList.InvalidIndex() )
|
||||
{
|
||||
m_AnimSetList.Remove( index );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Determine if the rig has any animation sets associated with it
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeRig::HasAnyAnimationSets() const
|
||||
{
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
if ( CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ] )
|
||||
{
|
||||
if ( CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet() )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the list of animation sets in the group
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::GetAnimationSets( CUtlVector< CDmeAnimationSet* > &animationSetList ) const
|
||||
{
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
animationSetList.EnsureCapacity( animationSetList.Count() + nAnimSets );
|
||||
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements != NULL )
|
||||
{
|
||||
CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
|
||||
if ( pAnimSet != NULL )
|
||||
{
|
||||
animationSetList.AddToTail( pAnimSet );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Get the list of elements for the specified animation set
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::GetAnimationSetElements( const CDmeAnimationSet* pAnimationSet, CUtlVector< CDmElement* > &elementList ) const
|
||||
{
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
|
||||
// Count the number of total elements in all the animation sets
|
||||
int nTotalElements = 0;
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements != NULL )
|
||||
{
|
||||
nTotalElements = pAnimSetElements->NumElements();
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate enough space in the element list for all of the elements in the rig.
|
||||
elementList.EnsureCapacity( elementList.Count() + nTotalElements );
|
||||
|
||||
// Add all the elements in the rig to the provided element list
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements != NULL )
|
||||
{
|
||||
pAnimSetElements->GetElements( elementList );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Determine if the rig has any elements from the specified animation set
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
bool CDmeRig::HasAnimationSet( const CDmeAnimationSet *pAnimationSet ) const
|
||||
{
|
||||
return ( FindAnimSetElementList( pAnimationSet ) != m_AnimSetList.InvalidIndex() );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Find the element list for the specified animation set
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
int CDmeRig::FindAnimSetElementList( const CDmeAnimationSet *pAnimationSet ) const
|
||||
{
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements == NULL )
|
||||
continue;
|
||||
|
||||
if ( pAnimSetElements->AnimationSet() == pAnimationSet )
|
||||
{
|
||||
return iAnimSet;
|
||||
}
|
||||
}
|
||||
|
||||
return m_AnimSetList.InvalidIndex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Find the element list for the specified animation set or create one
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CDmeRigAnimSetElements *CDmeRig::FindOrCreateAnimSetElementList( CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
int nIndex = FindAnimSetElementList( pAnimationSet );
|
||||
if ( nIndex != m_AnimSetList.InvalidIndex() )
|
||||
return m_AnimSetList[ nIndex ];
|
||||
|
||||
|
||||
CDmeRigAnimSetElements *pAnimSetElementList = CreateElement< CDmeRigAnimSetElements >( CFmtStr( "rigElements_%s", pAnimationSet->GetName() ), GetFileId() );
|
||||
if ( pAnimSetElementList )
|
||||
{
|
||||
pAnimSetElementList->SetAnimationSet( pAnimationSet );
|
||||
m_AnimSetList.AddToTail( pAnimSetElementList );
|
||||
}
|
||||
|
||||
return pAnimSetElementList;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Build a list of all of the dag nodes which are influenced by rig, does not include
|
||||
// dag nodes that are part of the rig.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::FindInfluencedDags( CUtlVector< CDmeDag* > &dagList ) const
|
||||
{
|
||||
// Count the total number of elements, this is done to calculate a good pre-allocation size for lists
|
||||
int totalElements = 0;
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
totalElements += m_AnimSetList[ iAnimSet ]->NumElements();
|
||||
}
|
||||
|
||||
// First build a tree of all of the dag nodes that are part of the rig, we do this so that we
|
||||
// can quickly determine if a dag which is influenced by some element of the rig is part of the
|
||||
// rig and therefore should not be added to the list of influenced dag nodes.
|
||||
CUtlVector< CDmElement* > elementList( 0, totalElements );
|
||||
CUtlRBTree< const CDmeDag* > rigDags( 0, totalElements, DefLessFunc( const CDmeDag *) );
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
const CDmaElementArray< CDmElement > &animSetElements = m_AnimSetList[ iAnimSet ]->Elements();
|
||||
int nElements = animSetElements.Count();
|
||||
for ( int iElement = 0; iElement < nElements; ++iElement )
|
||||
{
|
||||
CDmElement *pElement = animSetElements[ iElement ];
|
||||
if ( pElement )
|
||||
{
|
||||
elementList.AddToTail( pElement );
|
||||
|
||||
CDmeDag *pDag = CastElement< CDmeDag >( pElement );
|
||||
if ( pDag )
|
||||
{
|
||||
rigDags.Insert( pDag );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now iterate through all of the elements that belong to the rig and find any dag nodes which
|
||||
// are influenced by the rig elements. This is done by looking for any operators and then
|
||||
// getting the output attributes of the operator and determining if any of those attributes
|
||||
// belong to a dag node which is not part of the rig.
|
||||
CUtlRBTree< CDmeDag* > influencedDags( 0, totalElements, DefLessFunc( CDmeDag *) );
|
||||
CUtlVector< CDmAttribute* > outputAttributes( 0, 32 );
|
||||
int nElements = elementList.Count();
|
||||
for ( int iElement = 0; iElement < nElements; ++iElement )
|
||||
{
|
||||
CDmElement *pElement = elementList[ iElement ];
|
||||
|
||||
CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
|
||||
if ( pOperator )
|
||||
{
|
||||
outputAttributes.RemoveAll();
|
||||
pOperator->GetOutputAttributes( outputAttributes );
|
||||
|
||||
int nAttributes = outputAttributes.Count();
|
||||
for ( int iAttr = 0; iAttr < nAttributes; ++iAttr )
|
||||
{
|
||||
CDmAttribute *pAttr = outputAttributes[ iAttr ];
|
||||
if ( pAttr == NULL )
|
||||
continue;
|
||||
|
||||
CDmeDag *pDag = CastElement< CDmeDag >( pAttr->GetOwner() );
|
||||
if ( pDag == NULL )
|
||||
{
|
||||
CDmeTransform *pTransform = CastElement< CDmeTransform >( pAttr->GetOwner() );
|
||||
if ( pTransform )
|
||||
{
|
||||
pDag = pTransform->GetDag();
|
||||
}
|
||||
}
|
||||
|
||||
if ( pDag == NULL )
|
||||
continue;
|
||||
|
||||
// Make sure the dag is not part of the rig, if
|
||||
// not add it to the list of influenced dag nodes.
|
||||
if ( rigDags.Find( pDag ) == rigDags.InvalidIndex() )
|
||||
{
|
||||
influencedDags.InsertIfNotFound( pDag );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the influenced dag nodes into the provided list
|
||||
int nDagNodes = influencedDags.Count();
|
||||
dagList.SetCount( nDagNodes );
|
||||
for ( int iDag = 0; iDag < nDagNodes; ++iDag )
|
||||
{
|
||||
dagList[ iDag ] = influencedDags[ iDag ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove all of elements in the rig from the specified shot
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::RemoveElementsFromShot( CDmeFilmClip *pShot )
|
||||
{
|
||||
// Find the animation set channels track group, this will be used to find
|
||||
// the the channels clip for each of the animation sets referenced by the rig.
|
||||
CDmeTrack *pAnimSetEditorTrack = NULL;
|
||||
CDmeTrackGroup *pTrackGroup = pShot->FindOrAddTrackGroup( "channelTrackGroup" );
|
||||
if ( pTrackGroup )
|
||||
{
|
||||
pAnimSetEditorTrack = pTrackGroup->FindOrAddTrack( "animSetEditorChannels", DMECLIP_CHANNEL );
|
||||
}
|
||||
|
||||
|
||||
int nAnimSets = m_AnimSetList.Count();
|
||||
for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
|
||||
{
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
|
||||
if ( pAnimSetElements == NULL )
|
||||
continue;
|
||||
|
||||
CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
|
||||
if ( pAnimSet == NULL )
|
||||
continue;
|
||||
|
||||
CDmeChannelsClip *pChannelsClip = NULL;
|
||||
if ( pAnimSetEditorTrack )
|
||||
{
|
||||
pChannelsClip = CastElement< CDmeChannelsClip >( pAnimSetEditorTrack->FindNamedClip( pAnimSet->GetName() ) );
|
||||
}
|
||||
|
||||
// Make a copy of the array since we may remove elements from the original while iterating
|
||||
const CDmaElementArray< CDmElement > &elements = pAnimSetElements->Elements();
|
||||
int nElements = elements.Count();
|
||||
|
||||
CUtlVector< DmElementHandle_t > elementHandles( 0, nElements );
|
||||
for ( int iElement = 0; iElement < nElements; ++iElement )
|
||||
{
|
||||
CDmElement *pElement = elements[ iElement ];
|
||||
if ( pElement )
|
||||
{
|
||||
elementHandles.AddToTail( pElement->GetHandle() );
|
||||
}
|
||||
}
|
||||
|
||||
int nElementHandles = elementHandles.Count();
|
||||
for ( int iHandle = 0; iHandle < nElementHandles; ++iHandle )
|
||||
{
|
||||
// Get the element using its handle because it may have been destroyed already
|
||||
CDmElement *pElement = GetElement< CDmElement >( elementHandles[ iHandle ] );
|
||||
if ( pElement == NULL )
|
||||
continue;
|
||||
|
||||
// If the element is an operator make sure it is removed from the
|
||||
// list of operators maintained by the shot and animation set.
|
||||
CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
|
||||
if ( pOperator )
|
||||
{
|
||||
pAnimSet->RemoveOperator( pOperator );
|
||||
pShot->RemoveOperator( pOperator );
|
||||
|
||||
// If the element is a channel remove it from the animation set's channel clip.
|
||||
if ( pChannelsClip )
|
||||
{
|
||||
CDmeChannel *pChannel = CastElement< CDmeChannel >( pElement );
|
||||
if ( pChannel )
|
||||
{
|
||||
pChannelsClip->RemoveChannel( pChannel );
|
||||
}
|
||||
}
|
||||
|
||||
// If the element is a constraint reconnect the original
|
||||
// channels of the constrained dag back to the transform.
|
||||
CDmeRigBaseConstraintOperator *pConstraint = CastElement< CDmeRigBaseConstraintOperator >( pElement );
|
||||
if ( pConstraint )
|
||||
{
|
||||
pConstraint->ReconnectTransformChannels();
|
||||
}
|
||||
}
|
||||
else if ( pElement->IsA( CDmeDag::GetStaticTypeSymbol() ) )
|
||||
{
|
||||
CDmeDag *pDag = CastElement< CDmeDag >( pElement );
|
||||
CDmeDag *pParent = pDag->GetParent();
|
||||
|
||||
if ( pParent )
|
||||
{
|
||||
// Make sure the parent hasn't already been destroyed
|
||||
if ( g_pDataModel->GetElement( pParent->GetHandle() ) )
|
||||
{
|
||||
pParent->RemoveChild( pDag );
|
||||
}
|
||||
}
|
||||
|
||||
// If the dag has any constraints on it, remove them
|
||||
CDmeRigBaseConstraintOperator::RemoveConstraintsFromDag( pDag );
|
||||
}
|
||||
else if ( ( pElement->GetType() == CDmElement::GetStaticTypeSymbol() ) || pElement->IsA( CDmeTransformControl::GetStaticTypeSymbol() ) )
|
||||
{
|
||||
// If the element is just only element assume it may be a control or if the element is
|
||||
// a transform control try to remove it from the animation set's list of controls.
|
||||
pAnimSet->RemoveControl( pElement );
|
||||
}
|
||||
|
||||
// Destroy the element, this is done because many elements refer to each other so if undo is enabled
|
||||
// the auto cleanup will not take place and the elements will persist until the undo history is cleared.
|
||||
g_pDataModel->DestroyElement( pElement->GetHandle() );
|
||||
|
||||
} // For iElement
|
||||
|
||||
|
||||
// Reset the visibility on control groups that were hidden by the rig
|
||||
SetHiddenControlGroupVisibility( pAnimSetElements, true );
|
||||
|
||||
|
||||
// Clear the element list since they have all been destroyed
|
||||
pAnimSetElements->RemoveAll();
|
||||
|
||||
} // For iAnimSet
|
||||
|
||||
m_AnimSetList.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Set the visibility of the control groups in the hidden list
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::SetHiddenControlGroupVisibility( CDmeRigAnimSetElements *pAnimSetElements, bool bVisible )
|
||||
{
|
||||
CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
|
||||
if ( pAnimSet == NULL )
|
||||
return;
|
||||
|
||||
const CDmaStringArray &hiddenGroupList = pAnimSetElements->HiddenControlGroups();
|
||||
int nNumGroups = hiddenGroupList.Count();
|
||||
for ( int iGroup = 0; iGroup < nNumGroups; ++iGroup )
|
||||
{
|
||||
CDmeControlGroup *pGroup = pAnimSet->FindControlGroup( hiddenGroupList[ iGroup ] );
|
||||
if ( pGroup )
|
||||
{
|
||||
pGroup->SetVisible( bVisible );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Hide all of the control groups in the rig's list of hidden control groups
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::HideHiddenControlGroups( CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
int nAnimSetIndex = FindAnimSetElementList( pAnimationSet );
|
||||
if ( nAnimSetIndex == m_AnimSetList.InvalidIndex() )
|
||||
return;
|
||||
|
||||
CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ nAnimSetIndex ];
|
||||
if ( pAnimSetElements == NULL )
|
||||
return;
|
||||
|
||||
SetHiddenControlGroupVisibility( pAnimSetElements, false );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Purpose: Remove the specified element from any rig which it may be associated with.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CDmeRig::RemoveElementFromRig( CDmElement *pElement )
|
||||
{
|
||||
if ( pElement == NULL )
|
||||
return;
|
||||
|
||||
CUtlVector< CDmeRigAnimSetElements* > rigElementLists;
|
||||
FindAncestorsReferencingElement( pElement, rigElementLists );
|
||||
|
||||
for ( int iList = 0; iList < rigElementLists.Count(); ++iList )
|
||||
{
|
||||
CDmeRigAnimSetElements *pElementList = rigElementLists[ iList ];
|
||||
if ( pElementList )
|
||||
{
|
||||
pElementList->RemoveElement( pElement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Find all of the rigs which refer to the specified animation set
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void CollectRigsOnAnimationSet( CDmeAnimationSet *pAnimSet, CUtlVector< CDmeRig* > &rigList )
|
||||
{
|
||||
CDmeFilmClip *pFilmClip = FindReferringElement< CDmeFilmClip >( pAnimSet, "animationSets" );
|
||||
if ( pFilmClip == NULL )
|
||||
return;
|
||||
|
||||
CDmeDag *pScene = pFilmClip->GetScene();
|
||||
|
||||
if ( !pScene || !pAnimSet )
|
||||
return;
|
||||
|
||||
pScene->FindChildrenOfType( rigList );
|
||||
|
||||
int i = rigList.Count();
|
||||
while ( --i >= 0 )
|
||||
{
|
||||
CDmeRig *pRig = rigList[ i ];
|
||||
if ( !pRig || !pRig->HasAnimationSet( pAnimSet ) )
|
||||
{
|
||||
rigList.Remove( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
2311
movieobjects/dmerigconstraintoperators.cpp
Normal file
2311
movieobjects/dmerigconstraintoperators.cpp
Normal file
File diff suppressed because it is too large
Load Diff
27
movieobjects/dmerighandle.cpp
Normal file
27
movieobjects/dmerighandle.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmerighandle.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeRigHandle, CDmeRigHandle );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeRigHandle::OnConstruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CDmeRigHandle::OnDestruction()
|
||||
{
|
||||
|
||||
}
|
||||
577
movieobjects/dmeselection.cpp
Normal file
577
movieobjects/dmeselection.cpp
Normal file
@@ -0,0 +1,577 @@
|
||||
//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmeselection.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeComponent, CDmeComponent );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeComponent::OnConstruction()
|
||||
{
|
||||
m_Type.InitAndSet( this, "componentType", COMP_INVALID );
|
||||
m_bComplete.InitAndSet( this, "complete", false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeComponent::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeComponent::Resolve()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSingleIndexedComponent, CDmeSingleIndexedComponent );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::OnConstruction()
|
||||
{
|
||||
m_CompleteCount.InitAndSet( this, "completeCount", 0 );
|
||||
m_Components.Init( this, "components" );
|
||||
m_Weights.Init( this, "weights" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::Resolve()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeSingleIndexedComponent::Count() const
|
||||
{
|
||||
return IsComplete() ? m_CompleteCount.Get() : m_Components.Count();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSingleIndexedComponent::SetType( Component_t type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case COMP_VTX:
|
||||
case COMP_FACE:
|
||||
m_Type.Set( type );
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::AddComponent( int component, float weight /*= 1.0f */ )
|
||||
{
|
||||
if ( IsComplete() )
|
||||
return;
|
||||
|
||||
const int index( BinarySearch( component ) );
|
||||
Assert( index >= 0 );
|
||||
Assert( index <= m_Components.Count() );
|
||||
if ( index == m_Components.Count() )
|
||||
{
|
||||
m_Components.AddToTail( component );
|
||||
m_Weights.AddToTail( weight );
|
||||
}
|
||||
else if ( component == m_Components.Get( index ) )
|
||||
{
|
||||
Assert( index < m_Weights.Count() );
|
||||
m_Weights.Set( index, weight );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Components.InsertBefore( index, component );
|
||||
m_Weights.InsertBefore( index, weight );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::AddComponents( const CUtlVector< int > &components )
|
||||
{
|
||||
const int nComponents( components.Count() );
|
||||
for ( int i( 0 ); i < nComponents; ++i )
|
||||
{
|
||||
AddComponent( components[ i ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::AddComponents(
|
||||
const CUtlVector< int > &components, const CUtlVector< float > &weights )
|
||||
{
|
||||
const int nComponents( MIN( components.Count(), weights.Count() ) );
|
||||
for ( int i( 0 ); i < nComponents; ++i )
|
||||
{
|
||||
AddComponent( components[ i ], weights[ i ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::RemoveComponent( int component )
|
||||
{
|
||||
Assert( !IsComplete() ); // TODO: Convert from complete to complete - component
|
||||
|
||||
const int cIndex = BinarySearch( component );
|
||||
if ( cIndex >= m_Components.Count() || m_Components[ cIndex ] != component ) // Component not in selection
|
||||
return;
|
||||
|
||||
m_Components.Remove( cIndex );
|
||||
m_Weights.Remove( cIndex );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSingleIndexedComponent::GetComponent( int index, int &component, float &weight ) const
|
||||
{
|
||||
if ( index < Count() )
|
||||
{
|
||||
if ( IsComplete() )
|
||||
{
|
||||
component = index;
|
||||
weight = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
component = m_Components[ index ];
|
||||
weight = m_Weights[ index ];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::GetComponents( CUtlVector< int > &components, CUtlVector< float > &weights ) const
|
||||
{
|
||||
if ( IsComplete() )
|
||||
{
|
||||
const int nComponents = Count();
|
||||
|
||||
int *pComponents = reinterpret_cast< int * >( alloca( nComponents * sizeof( int ) ) );
|
||||
float *pWeights = reinterpret_cast< float * >( alloca( nComponents * sizeof( float ) ) );
|
||||
|
||||
for ( int i = 0; i < nComponents; ++i )
|
||||
{
|
||||
pComponents[ i ] = i;
|
||||
pWeights[ i ] = 1.0f;
|
||||
}
|
||||
|
||||
components.CopyArray( pComponents, nComponents );
|
||||
weights.CopyArray( pWeights, nComponents );
|
||||
}
|
||||
else
|
||||
{
|
||||
components.RemoveAll();
|
||||
components.CopyArray( m_Components.Base(), m_Components.Count() );
|
||||
|
||||
weights.RemoveAll();
|
||||
weights.CopyArray( m_Weights.Base(), m_Weights.Count() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::GetComponents( CUtlVector< int > &components ) const
|
||||
{
|
||||
if ( IsComplete() )
|
||||
{
|
||||
const int nComponents = Count();
|
||||
|
||||
int *pComponents = reinterpret_cast< int * >( alloca( nComponents * sizeof( int ) ) );
|
||||
|
||||
for ( int i = 0; i < nComponents; ++i )
|
||||
{
|
||||
pComponents[ i ] = i;
|
||||
}
|
||||
|
||||
components.CopyArray( pComponents, nComponents );
|
||||
}
|
||||
else
|
||||
{
|
||||
components.RemoveAll();
|
||||
components.CopyArray( m_Components.Base(), m_Components.Count() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::SetComplete( int nComplete )
|
||||
{
|
||||
m_bComplete.Set( true );
|
||||
m_CompleteCount.Set( MAX( 0, nComplete ) );
|
||||
m_Components.Purge();
|
||||
m_Weights.Purge();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeSingleIndexedComponent::GetComplete() const
|
||||
{
|
||||
return IsComplete() ? m_CompleteCount.Get() : 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reset to an empty selection
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void CDmeSingleIndexedComponent::Clear()
|
||||
{
|
||||
CDmeComponent::Clear();
|
||||
m_CompleteCount.Set( 0 );
|
||||
m_Components.RemoveAll();
|
||||
m_Weights.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Searches for the component in the sorted component list and returns the
|
||||
// index if it's found or if it's not found, returns the index at which it
|
||||
// should be inserted to maintain the sorted order of the component list
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeSingleIndexedComponent::BinarySearch( int component ) const
|
||||
{
|
||||
const CUtlVector< int > &components( m_Components.Get() );
|
||||
const int nComponents( components.Count() );
|
||||
|
||||
int left( 0 );
|
||||
int right( nComponents - 1 );
|
||||
int mid;
|
||||
|
||||
while ( left <= right )
|
||||
{
|
||||
mid = ( left + right ) >> 1; // floor( ( left + right ) / 2.0 )
|
||||
if ( component > m_Components[ mid ] )
|
||||
{
|
||||
left = mid + 1;
|
||||
}
|
||||
else if ( component < m_Components[ mid ] )
|
||||
{
|
||||
right = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSingleIndexedComponent::HasComponent( int component ) const
|
||||
{
|
||||
if ( IsComplete() )
|
||||
return true;
|
||||
|
||||
const int cIndex = BinarySearch( component );
|
||||
if ( cIndex >= m_Components.Count() )
|
||||
return false;
|
||||
|
||||
if ( m_Components[ cIndex ] == component )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSingleIndexedComponent::GetWeight( int component, float &weight ) const
|
||||
{
|
||||
Assert( !IsComplete() );
|
||||
|
||||
const int cIndex = BinarySearch( component );
|
||||
if ( cIndex >= m_Components.Count() )
|
||||
return false;
|
||||
|
||||
if ( m_Components[ cIndex ] == component )
|
||||
{
|
||||
weight = m_Weights[ cIndex ];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::Subtract( const CDmeSingleIndexedComponent &rhs )
|
||||
{
|
||||
const int nLhs = Count();
|
||||
const int nRhs = rhs.Count();
|
||||
|
||||
int l = 0;
|
||||
int r = 0;
|
||||
|
||||
if ( IsComplete() )
|
||||
{
|
||||
// TODO
|
||||
Assert( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
CUtlVector< int > newComponents;
|
||||
newComponents.EnsureCapacity( nLhs );
|
||||
CUtlVector< float > newWeights;
|
||||
newWeights.EnsureCapacity( nLhs );
|
||||
|
||||
while ( l < nLhs || r < nRhs )
|
||||
{
|
||||
// In LHS but not RHS
|
||||
while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
|
||||
{
|
||||
newComponents.AddToTail( m_Components[ l ] );
|
||||
newWeights.AddToTail( m_Weights[ l ] );
|
||||
++l;
|
||||
}
|
||||
|
||||
// In RHS but not LHS
|
||||
while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
|
||||
{
|
||||
++r;
|
||||
}
|
||||
|
||||
// In Both LHS & RHS
|
||||
while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
|
||||
{
|
||||
++l;
|
||||
++r;
|
||||
}
|
||||
}
|
||||
|
||||
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
|
||||
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
|
||||
}
|
||||
|
||||
m_CompleteCount.Set( 0 );
|
||||
m_bComplete.Set( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::Add( const CDmeSingleIndexedComponent &rhs )
|
||||
{
|
||||
int nLhs = Count();
|
||||
const int nRhs = rhs.Count();
|
||||
|
||||
int l = 0;
|
||||
int r = 0;
|
||||
|
||||
if ( IsComplete() )
|
||||
{
|
||||
if ( rhs.IsComplete() && nRhs > nLhs )
|
||||
{
|
||||
m_CompleteCount.Set( nRhs );
|
||||
}
|
||||
else
|
||||
{
|
||||
while ( r < nRhs )
|
||||
{
|
||||
if ( rhs.m_Components[ r ] >= nLhs )
|
||||
{
|
||||
// Got one that's greater than the complete count of this one
|
||||
|
||||
CUtlVector< int > newComponents;
|
||||
newComponents.EnsureCapacity( nLhs + nRhs - r );
|
||||
|
||||
CUtlVector< float > newWeights;
|
||||
newWeights.EnsureCapacity( nLhs + nRhs - r );
|
||||
|
||||
GetComponents( newComponents, newWeights );
|
||||
|
||||
while ( r < nRhs )
|
||||
{
|
||||
newComponents.AddToTail( rhs.m_Components[ r ] );
|
||||
newWeights.AddToTail( rhs.m_Weights[ r ] );
|
||||
++r;
|
||||
}
|
||||
|
||||
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
|
||||
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
|
||||
|
||||
m_CompleteCount.Set( 0 );
|
||||
m_bComplete.Set( false );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
++r;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CUtlVector< int > newComponents;
|
||||
newComponents.EnsureCapacity( nLhs + nRhs * 0.5 ); // Just an estimate assuming 50% of the components in rhs aren't in lhs
|
||||
CUtlVector< float > newWeights;
|
||||
newWeights.EnsureCapacity( nLhs + nRhs * 0.5 ); // Just an estimate
|
||||
|
||||
while ( l < nLhs || r < nRhs )
|
||||
{
|
||||
while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
|
||||
{
|
||||
newComponents.AddToTail( m_Components[ l ] );
|
||||
newWeights.AddToTail( m_Weights[ l ] );
|
||||
++l;
|
||||
}
|
||||
|
||||
// In RHS but not LHS
|
||||
while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
|
||||
{
|
||||
newComponents.AddToTail( rhs.m_Components[ r ] );
|
||||
newWeights.AddToTail( rhs.m_Weights[ r ] );
|
||||
++r;
|
||||
}
|
||||
|
||||
// In Both LHS & RHS
|
||||
while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
|
||||
{
|
||||
newComponents.AddToTail( m_Components[ l ] );
|
||||
newWeights.AddToTail( m_Weights[ l ] );
|
||||
++l;
|
||||
++r;
|
||||
}
|
||||
}
|
||||
|
||||
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
|
||||
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
|
||||
}
|
||||
|
||||
m_CompleteCount.Set( 0 );
|
||||
m_bComplete.Set( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSingleIndexedComponent::Intersection( const CDmeSingleIndexedComponent &rhs )
|
||||
{
|
||||
const int nLhs = Count();
|
||||
const int nRhs = rhs.Count();
|
||||
|
||||
int l = 0;
|
||||
int r = 0;
|
||||
|
||||
if ( IsComplete() )
|
||||
{
|
||||
// TODO
|
||||
Assert( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
CUtlVector< int > newComponents;
|
||||
newComponents.EnsureCapacity( nLhs );
|
||||
CUtlVector< float > newWeights;
|
||||
newWeights.EnsureCapacity( nLhs );
|
||||
|
||||
while ( l < nLhs || r < nRhs )
|
||||
{
|
||||
// In LHS but not RHS
|
||||
while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
|
||||
{
|
||||
++l;
|
||||
}
|
||||
|
||||
// In RHS but not LHS
|
||||
while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
|
||||
{
|
||||
++r;
|
||||
}
|
||||
|
||||
// In Both LHS & RHS
|
||||
while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
|
||||
{
|
||||
newComponents.AddToTail( m_Components[ l ] );
|
||||
newWeights.AddToTail( m_Weights[ l ] );
|
||||
++l;
|
||||
++r;
|
||||
}
|
||||
}
|
||||
|
||||
m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
|
||||
m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
|
||||
}
|
||||
|
||||
m_CompleteCount.Set( 0 );
|
||||
m_bComplete.Set( false );
|
||||
}
|
||||
260
movieobjects/dmeshader.cpp
Normal file
260
movieobjects/dmeshader.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeshader.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "materialsystem/IMaterialSystem.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeShader, CDmeShader );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::OnConstruction()
|
||||
{
|
||||
m_ShaderName.Init( this, "shaderName" );
|
||||
|
||||
m_ShaderName = "wireframe";
|
||||
m_pShader = NULL;
|
||||
}
|
||||
|
||||
void CDmeShader::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shader name access
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::SetShaderName( const char *pShaderName )
|
||||
{
|
||||
m_ShaderName = pShaderName;
|
||||
}
|
||||
|
||||
const char *CDmeShader::GetShaderName() const
|
||||
{
|
||||
return m_ShaderName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds a shader
|
||||
//-----------------------------------------------------------------------------
|
||||
IShader *CDmeShader::FindShader()
|
||||
{
|
||||
int nCount = MaterialSystem()->ShaderCount();
|
||||
IShader **ppShaderList = (IShader**)_alloca( nCount * sizeof(IShader*) );
|
||||
MaterialSystem()->GetShaders( 0, nCount, ppShaderList );
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( m_ShaderName, ppShaderList[i]->GetName() ) )
|
||||
return ppShaderList[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Remove all shader parameters that don't exist in the new shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::RemoveUnusedShaderParams( IShader *pShader )
|
||||
{
|
||||
IDmAttribute* pAttribute = FirstAttribute();
|
||||
IDmAttribute* pNextAttribute = NULL;
|
||||
for ( ; pAttribute; pAttribute = pNextAttribute )
|
||||
{
|
||||
pNextAttribute = pAttribute->NextAttribute();
|
||||
|
||||
// Don't remove name, type, or id
|
||||
if ( pAttribute->IsFlagSet( FATTRIB_STANDARD ) )
|
||||
continue;
|
||||
|
||||
const char *pShaderParam = pAttribute->GetName();
|
||||
int nCount = pShader->GetNumParams();
|
||||
int i;
|
||||
for ( i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pShaderParam, pShader->GetParamName( i ) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
// No match? Remove it!
|
||||
if ( i == nCount )
|
||||
{
|
||||
RemoveAttributeByPtr( pAttribute );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Add attribute for shader parameter
|
||||
//-----------------------------------------------------------------------------
|
||||
IDmAttribute* CDmeShader::AddAttributeForShaderParameter( IShader *pShader, int nIndex )
|
||||
{
|
||||
ShaderParamType_t paramType = pShader->GetParamType( nIndex );
|
||||
const char *pParamName = pShader->GetParamName( nIndex );
|
||||
|
||||
IDmAttribute *pAttribute = NULL;
|
||||
switch ( paramType )
|
||||
{
|
||||
case SHADER_PARAM_TYPE_INTEGER:
|
||||
pAttribute = AddAttributeTyped<int>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_BOOL:
|
||||
pAttribute = AddAttributeTyped<bool>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_FLOAT:
|
||||
pAttribute = AddAttributeTyped<float>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_STRING:
|
||||
pAttribute = AddAttributeTyped<CUtlString>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_COLOR:
|
||||
pAttribute = AddAttributeTyped<Color>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_VEC2:
|
||||
pAttribute = AddAttributeTyped<Vector2D>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_VEC3:
|
||||
pAttribute = AddAttributeTyped<Vector>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_VEC4:
|
||||
pAttribute = AddAttributeTyped<Vector4D>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_FOURCC:
|
||||
Assert( 0 );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_MATRIX:
|
||||
pAttribute = AddAttributeTyped<VMatrix>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_TEXTURE:
|
||||
pAttribute = AddAttributeTyped<CDmElementRef>( pParamName );
|
||||
break;
|
||||
|
||||
case SHADER_PARAM_TYPE_MATERIAL:
|
||||
pAttribute = AddAttributeTyped<CDmElementRef>( pParamName );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return pAttribute;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Add all shader parameters that don't currently exist
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::AddNewShaderParams( IShader *pShader )
|
||||
{
|
||||
int nCount = pShader->GetNumParams();
|
||||
int i;
|
||||
for ( i = 0; i < nCount; ++i )
|
||||
{
|
||||
const char *pParamName = pShader->GetParamName( i );
|
||||
|
||||
IDmAttribute* pAttribute = NULL;
|
||||
for ( pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
// Don't remove name, type, or id
|
||||
if ( pAttribute->IsFlagSet( FATTRIB_STANDARD ) )
|
||||
continue;
|
||||
|
||||
const char *pAttributeName = pAttribute->GetName();
|
||||
if ( !Q_stricmp( pAttributeName, pParamName ) )
|
||||
break;
|
||||
}
|
||||
|
||||
// No match? Add it!
|
||||
if ( pAttribute != NULL )
|
||||
continue;
|
||||
|
||||
pAttribute = AddAttributeForShaderParameter( pShader, i );
|
||||
if ( pAttribute )
|
||||
{
|
||||
const char *pDefault = pShader->GetParamDefault( i );
|
||||
|
||||
SetAttributeValueFromString( pParamName, pDefault );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// resolve
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::Resolve()
|
||||
{
|
||||
if ( !m_ShaderName.IsDirty() || !MaterialSystem() )
|
||||
return;
|
||||
|
||||
// First, find the shader
|
||||
IShader *pShader = FindShader();
|
||||
|
||||
// Remove all shader parameters that don't exist in the new shader
|
||||
RemoveUnusedShaderParams( pShader );
|
||||
|
||||
// Add all shader parameters that don't currently exist
|
||||
AddNewShaderParams( pShader );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns a procedural material to be associated with this shader
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShader::CreateMaterial( const char *pMaterialName )
|
||||
{
|
||||
KeyValues *pVMTKeyValues = new KeyValues( GetShaderName() );
|
||||
|
||||
IDmAttribute* pAttribute = FirstAttribute();
|
||||
IDmAttribute* pNextAttribute = NULL;
|
||||
for ( ; pAttribute; pAttribute = pNextAttribute )
|
||||
{
|
||||
pNextAttribute = pAttribute->NextAttribute();
|
||||
|
||||
// Don't remove name, type, or id
|
||||
if ( pAttribute->IsFlagSet( FATTRIB_STANDARD ) )
|
||||
continue;
|
||||
|
||||
const char *pShaderParam = pAttribute->GetName();
|
||||
int nCount = pShader->GetNumParams();
|
||||
int i;
|
||||
for ( i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pShaderParam, pShader->GetParamName( i ) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
// No match? Remove it!
|
||||
if ( i == nCount )
|
||||
{
|
||||
RemoveAttributeByPtr( pAttribute );
|
||||
}
|
||||
}
|
||||
|
||||
pVMTKeyValues->SetInt( "$model", 1 );
|
||||
pVMTKeyValues->SetFloat( "$decalscale", 0.05f );
|
||||
pVMTKeyValues->SetString( "$basetexture", "error" );
|
||||
return MaterialSystem()->CreateMaterial( pMaterialName, pVMTKeyValues );
|
||||
}
|
||||
115
movieobjects/dmeshape.cpp
Normal file
115
movieobjects/dmeshape.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeshape.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeShape, CDmeShape );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShape::OnConstruction()
|
||||
{
|
||||
m_visible.InitAndSet( this, "visible", true );
|
||||
}
|
||||
|
||||
void CDmeShape::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeShape::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The default bounding sphere is empty at the origin
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShape::GetBoundingSphere( Vector &c, float &r ) const
|
||||
{
|
||||
c.Zero();
|
||||
r = 0.0f;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeShape::GetParentCount() const
|
||||
{
|
||||
int nReferringDags = 0;
|
||||
|
||||
DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
|
||||
while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
|
||||
{
|
||||
CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
|
||||
CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
|
||||
const static CUtlSymbolLarge symShape = g_pDataModel->GetSymbol( "shape" );
|
||||
if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId() )
|
||||
{
|
||||
++nReferringDags;
|
||||
}
|
||||
|
||||
i = g_pDataModel->NextAttributeReferencingElement( i );
|
||||
}
|
||||
|
||||
return nReferringDags;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeDag *CDmeShape::GetParent( int nParentIndex /*= 0 */ ) const
|
||||
{
|
||||
int nReferringDags = 0;
|
||||
|
||||
DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
|
||||
while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
|
||||
{
|
||||
CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
|
||||
CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
|
||||
const static CUtlSymbolLarge symShape = g_pDataModel->GetSymbol( "shape" );
|
||||
if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId() )
|
||||
{
|
||||
if ( nReferringDags == nParentIndex )
|
||||
return pDag;
|
||||
|
||||
++nReferringDags;
|
||||
}
|
||||
|
||||
i = g_pDataModel->NextAttributeReferencingElement( i );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeShape::GetShapeToWorldTransform( matrix3x4_t &mat, int nParentIndex /*= 0 */ ) const
|
||||
{
|
||||
CDmeDag *pDag = GetParent( nParentIndex );
|
||||
|
||||
if ( pDag )
|
||||
{
|
||||
pDag->GetShapeToWorldTransform( mat );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetIdentityMatrix( mat );
|
||||
}
|
||||
}
|
||||
94
movieobjects/dmesound.cpp
Normal file
94
movieobjects/dmesound.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmesound.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "filesystem.h"
|
||||
#include "datamodel/dmattributevar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSound, CDmeSound );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeSound::OnConstruction()
|
||||
{
|
||||
m_SoundName.Init( this, "soundname" );
|
||||
m_GameSoundName.Init( this, "gameSoundName" );
|
||||
}
|
||||
|
||||
void CDmeSound::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// For sounds that are relative paths (instead of GameSound names), get full path
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeSound::ComputeSoundFullPath( char *pBuf, int nBufLen )
|
||||
{
|
||||
if ( !m_SoundName[0] )
|
||||
{
|
||||
pBuf[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute the full path of the sound
|
||||
char pRelativePath[MAX_PATH];
|
||||
Q_snprintf( pRelativePath, sizeof(pRelativePath), "sound\\%s", m_SoundName.Get() );
|
||||
return g_pFullFileSystem->RelativePathToFullPath( pRelativePath, "GAME", pBuf, nBufLen ) != NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeGameSound, CDmeGameSound );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeGameSound::OnConstruction()
|
||||
{
|
||||
m_Volume .Init( this, "volume" );
|
||||
m_Level .Init( this, "level" );
|
||||
m_Pitch .Init( this, "pitch" );
|
||||
|
||||
m_IsStatic .Init( this, "static" );
|
||||
m_Channel .Init( this, "channel" );
|
||||
m_Flags .Init( this, "flags" );
|
||||
|
||||
// m_Source .Init( this, "source" );
|
||||
// m_FollowSource.Init( this, "followsource" );
|
||||
m_Origin .Init( this, "origin" );
|
||||
m_Direction .Init( this, "direction" );
|
||||
}
|
||||
|
||||
void CDmeGameSound::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
CDmElement *CDmeGameSound::FindOrAddPhonemeExtractionSettings()
|
||||
{
|
||||
if ( HasAttribute( "PhonemeExtractionSettings" ) )
|
||||
return GetValueElement< CDmElement >( "PhonemeExtractionSettings" );
|
||||
|
||||
CDmElement *settings = CreateElement< CDmElement >( "PhonemeExtractionSettings", GetFileId() );
|
||||
if ( !settings )
|
||||
return NULL;
|
||||
|
||||
SetValue( "PhonemeExtractionSettings", settings );
|
||||
return settings;
|
||||
}
|
||||
1757
movieobjects/dmetestmesh.cpp
Normal file
1757
movieobjects/dmetestmesh.cpp
Normal file
File diff suppressed because it is too large
Load Diff
92
movieobjects/dmetimeframe.cpp
Normal file
92
movieobjects/dmetimeframe.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmetimeframe.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class factory
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTimeFrame, CDmeTimeFrame );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTimeFrame::OnConstruction()
|
||||
{
|
||||
m_Start .InitAndSet( this, "start", DMETIME_ZERO, FATTRIB_HAS_CALLBACK );
|
||||
m_Duration.InitAndSet( this, "duration", DMETIME_ZERO, FATTRIB_HAS_CALLBACK );
|
||||
m_Offset .InitAndSet( this, "offset", DMETIME_ZERO );
|
||||
m_Scale .InitAndSet( this, "scale", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeTimeFrame::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CDmeTimeFrame::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
|
||||
// notify parent clip that the time has changed
|
||||
if ( pAttribute == m_Start.GetAttribute() || pAttribute == m_Duration.GetAttribute() )
|
||||
{
|
||||
InvokeOnAttributeChangedOnReferrers( GetHandle(), pAttribute );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTimeFrame::SetEndTime( DmeTime_t endTime, bool bChangeDuration )
|
||||
{
|
||||
if ( bChangeDuration )
|
||||
{
|
||||
m_Duration = endTime - m_Start;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Start = endTime - m_Duration;
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTimeFrame::SetTimeScale( float flScale, DmeTime_t scaleCenter, bool bChangeDuration )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
DmeTime_t preCenterTime = ToChildMediaTime( scaleCenter, false );
|
||||
#endif
|
||||
|
||||
float ratio = m_Scale / flScale;
|
||||
DmeTime_t t = scaleCenter - m_Start;
|
||||
|
||||
if ( bChangeDuration )
|
||||
{
|
||||
DmeTime_t newDuration = m_Duration.Get() * ratio;
|
||||
|
||||
if ( scaleCenter != m_Start )
|
||||
{
|
||||
DmeTime_t newStart = ( m_Start.Get() - scaleCenter ) * ratio + scaleCenter;
|
||||
SetStartTime( newStart );
|
||||
}
|
||||
|
||||
SetTimeOffset( ( t + m_Offset.Get() ) * ratio + m_Start.Get() - scaleCenter );
|
||||
SetDuration( newDuration );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTimeOffset( ( t + m_Offset.Get() ) * ratio - t );
|
||||
}
|
||||
|
||||
SetTimeScale( flScale );
|
||||
|
||||
#ifdef _DEBUG
|
||||
DmeTime_t postCenterTime = ToChildMediaTime( scaleCenter, false );
|
||||
Assert( abs( preCenterTime - postCenterTime ) <= DMETIME_MINDELTA );
|
||||
#endif
|
||||
}
|
||||
465
movieobjects/dmetimeselection.cpp
Normal file
465
movieobjects/dmetimeselection.cpp
Normal file
@@ -0,0 +1,465 @@
|
||||
#include "movieobjects/dmetimeselection.h"
|
||||
#include "interpolatortypes.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
// #include "dme_controls/RecordingState.h"
|
||||
|
||||
float ComputeInterpolationFactor( float flFactor, int nInterpolatorType );
|
||||
float GetAmountForTime( DmeTime_t dmetime, const TimeSelection_t ×, const int nInterpolationTypes[ 2 ] );
|
||||
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTimeSelection, CDmeTimeSelection );
|
||||
|
||||
void CDmeTimeSelection::OnConstruction()
|
||||
{
|
||||
m_bEnabled.InitAndSet( this, "enabled", false );
|
||||
m_bRelative.InitAndSet( this, "relative", false );
|
||||
|
||||
DmeTime_t one( 1.0f );
|
||||
|
||||
m_falloff[ 0 ].InitAndSet( this, "falloff_left", -one );
|
||||
m_falloff[ 1 ].InitAndSet( this, "falloff_right", one );
|
||||
|
||||
m_hold[ 0 ].Init( this, "hold_left" );
|
||||
m_hold[ 1 ].Init( this, "hold_right" );
|
||||
|
||||
m_nFalloffInterpolatorType[ 0 ].InitAndSet( this, "interpolator_left", INTERPOLATE_LINEAR_INTERP );
|
||||
m_nFalloffInterpolatorType[ 1 ].InitAndSet( this, "interpolator_right", INTERPOLATE_LINEAR_INTERP );
|
||||
|
||||
m_threshold.InitAndSet( this, "threshold", 0.0005f );
|
||||
|
||||
m_resampleInterval.InitAndSet( this, "resampleinterval", DmeTime_t( 100 ) ); // 10 ms
|
||||
|
||||
m_nRecordingState.InitAndSet( this, "recordingstate", 3 /*AS_PLAYBACK : HACK THIS SHOULD MOVE TO A PUBLIC HEADER*/ );
|
||||
}
|
||||
|
||||
|
||||
void CDmeTimeSelection::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
float CDmeTimeSelection::AdjustFactorForInterpolatorType( float factor, int side )
|
||||
{
|
||||
return ComputeInterpolationFactor( factor, GetFalloffInterpolatorType( side ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// per-type averaging methods
|
||||
//-----------------------------------------------------------------------------
|
||||
float CDmeTimeSelection::GetAmountForTime( DmeTime_t t, DmeTime_t curtime )
|
||||
{
|
||||
Assert( IsEnabled() );
|
||||
|
||||
TimeSelection_t times;
|
||||
times[ 0 ] = GetAbsFalloff( curtime, 0 );
|
||||
times[ 1 ] = GetAbsHold( curtime, 0 );
|
||||
times[ 2 ] = GetAbsHold( curtime, 1 );
|
||||
times[ 3 ] = GetAbsFalloff( curtime, 1 );
|
||||
|
||||
int nInterpolatorTypes[ 2 ] = { m_nFalloffInterpolatorType[0], m_nFalloffInterpolatorType[1] };
|
||||
|
||||
return ::GetAmountForTime( t, times, nInterpolatorTypes );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::GetAlphaForTime( DmeTime_t t, DmeTime_t curtime, byte& alpha )
|
||||
{
|
||||
Assert( IsEnabled() );
|
||||
|
||||
byte minAlpha = 31;
|
||||
if ( alpha <= minAlpha )
|
||||
return;
|
||||
|
||||
float f = GetAmountForTime( t, curtime );
|
||||
alpha = ( byte )( f * ( alpha - minAlpha ) + minAlpha );
|
||||
alpha = clamp( alpha, minAlpha, 255 );
|
||||
}
|
||||
|
||||
int CDmeTimeSelection::GetFalloffInterpolatorType( int side ) const
|
||||
{
|
||||
return m_nFalloffInterpolatorType[ side ];
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetFalloffInterpolatorType( int side, int interpolatorType )
|
||||
{
|
||||
m_nFalloffInterpolatorType[ side ] = interpolatorType;
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsEnabled() const
|
||||
{
|
||||
return m_bEnabled;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetEnabled( bool state )
|
||||
{
|
||||
m_bEnabled = state;
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsRelative() const
|
||||
{
|
||||
return m_bRelative;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetRelative( DmeTime_t time, bool state )
|
||||
{
|
||||
Assert( !IsSuspicious( true ) );
|
||||
|
||||
bool changed = m_bRelative != state;
|
||||
m_bRelative = state;
|
||||
if ( changed )
|
||||
{
|
||||
if ( state )
|
||||
ConvertToRelative( time );
|
||||
else
|
||||
ConvertToAbsolute( time );
|
||||
}
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetAbsFalloff( DmeTime_t time, int side ) const
|
||||
{
|
||||
if ( IsInfinite( side ) )
|
||||
{
|
||||
return m_falloff[ side ];
|
||||
}
|
||||
return m_bRelative ? m_falloff[ side ].Get() + time : m_falloff[ side ];
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetAbsHold( DmeTime_t time, int side ) const
|
||||
{
|
||||
if ( IsInfinite( side ) )
|
||||
{
|
||||
return m_hold[ side ];
|
||||
}
|
||||
return m_bRelative ? m_hold[ side ].Get() + time : m_hold[ side ];
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetRelativeFalloff( DmeTime_t time, int side ) const
|
||||
{
|
||||
if ( IsInfinite( side ) )
|
||||
{
|
||||
return m_falloff[ side ];
|
||||
}
|
||||
return m_bRelative ? m_falloff[ side ] : m_falloff[ side ].Get() - time;
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetRelativeHold( DmeTime_t time, int side ) const
|
||||
{
|
||||
if ( IsInfinite( side ) )
|
||||
{
|
||||
return m_hold[ side ];
|
||||
}
|
||||
return m_bRelative ? m_hold[ side ] : m_hold[ side ].Get() - time;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::ConvertToRelative( DmeTime_t time )
|
||||
{
|
||||
Assert( !IsSuspicious( true ) );
|
||||
|
||||
for ( int side = 0; side < 2; ++side )
|
||||
{
|
||||
if ( !IsInfinite( side ) )
|
||||
{
|
||||
m_falloff[ side ] -= time;
|
||||
m_hold[ side ] -= time;
|
||||
}
|
||||
}
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::ConvertToAbsolute( DmeTime_t time )
|
||||
{
|
||||
Assert( !IsSuspicious( true ) );
|
||||
|
||||
for ( int side = 0; side < 2; ++side )
|
||||
{
|
||||
if ( !IsInfinite( side ) )
|
||||
{
|
||||
m_falloff[ side ] += time;
|
||||
m_hold[ side ] += time;
|
||||
}
|
||||
}
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetAbsFalloff( DmeTime_t time, int side, DmeTime_t absfallofftime )
|
||||
{
|
||||
// If going to infinite edge, don't need to remember the time delta in relative mode, so zero it
|
||||
if ( absfallofftime == DMETIME_MAXTIME ||
|
||||
absfallofftime == DMETIME_MINTIME )
|
||||
{
|
||||
time = DMETIME_ZERO;
|
||||
}
|
||||
|
||||
m_falloff[ side ] = m_bRelative ? absfallofftime - time : absfallofftime;
|
||||
Assert( !IsSuspicious() );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetAbsHold( DmeTime_t time, int side, DmeTime_t absholdtime )
|
||||
{
|
||||
// If going to infinite edge, don't need to remember the time delta in relative mode, so zero it
|
||||
if ( absholdtime == DMETIME_MAXTIME ||
|
||||
absholdtime == DMETIME_MINTIME )
|
||||
{
|
||||
time = DMETIME_ZERO;
|
||||
}
|
||||
|
||||
m_hold[ side ] = m_bRelative ? absholdtime - time : absholdtime;
|
||||
Assert( !IsSuspicious() );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::CopyFrom( const CDmeTimeSelection& src )
|
||||
{
|
||||
m_bEnabled = src.m_bEnabled;
|
||||
m_bRelative = src.m_bRelative;
|
||||
m_threshold = src.m_threshold;
|
||||
|
||||
for ( int i = 0 ; i < 2; ++i )
|
||||
{
|
||||
m_falloff[ i ] = src.m_falloff[ i ];
|
||||
m_hold[ i ] = src.m_hold[ i ];
|
||||
m_nFalloffInterpolatorType[ i ] = src.m_nFalloffInterpolatorType[ i ];
|
||||
}
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
|
||||
m_nRecordingState = src.m_nRecordingState;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::GetAbsTimes( DmeTime_t time, DmeTime_t pTimes[TS_TIME_COUNT] ) const
|
||||
{
|
||||
if ( m_bRelative )
|
||||
{
|
||||
pTimes[TS_LEFT_FALLOFF ] = GetRelativeFalloff( time, 0 );
|
||||
pTimes[TS_LEFT_HOLD ] = GetRelativeHold( time, 0 );
|
||||
pTimes[TS_RIGHT_HOLD ] = GetRelativeHold( time, 1 );
|
||||
pTimes[TS_RIGHT_FALLOFF] = GetRelativeFalloff( time, 1 );
|
||||
return;
|
||||
}
|
||||
pTimes[TS_LEFT_FALLOFF ] = m_falloff[ 0 ];
|
||||
pTimes[TS_LEFT_HOLD ] = m_hold [ 0 ];
|
||||
pTimes[TS_RIGHT_HOLD ] = m_hold [ 1 ];
|
||||
pTimes[TS_RIGHT_FALLOFF] = m_falloff[ 1 ];
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::GetCurrent( DmeTime_t pTimes[TS_TIME_COUNT] ) const
|
||||
{
|
||||
pTimes[TS_LEFT_FALLOFF ] = m_falloff[ 0 ];
|
||||
pTimes[TS_LEFT_HOLD ] = m_hold [ 0 ];
|
||||
pTimes[TS_RIGHT_HOLD ] = m_hold [ 1 ];
|
||||
pTimes[TS_RIGHT_FALLOFF] = m_falloff[ 1 ];
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetCurrent( const TimeSelection_t × )
|
||||
{
|
||||
m_falloff[ 0 ] = times[ TS_LEFT_FALLOFF ];
|
||||
m_hold [ 0 ] = times[ TS_LEFT_HOLD ];
|
||||
m_hold [ 1 ] = times[ TS_RIGHT_HOLD ];
|
||||
m_falloff[ 1 ] = times[ TS_RIGHT_FALLOFF ];
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
}
|
||||
|
||||
float CDmeTimeSelection::GetThreshold() const
|
||||
{
|
||||
return m_threshold;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetThreshold( float threshold )
|
||||
{
|
||||
m_threshold = threshold;
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetResampleInterval() const
|
||||
{
|
||||
return m_resampleInterval.Get();
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetResampleInterval( DmeTime_t resampleInterval )
|
||||
{
|
||||
m_resampleInterval.Set( resampleInterval );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetRecordingState( RecordingState_t state )
|
||||
{
|
||||
m_nRecordingState = ( int )state;
|
||||
}
|
||||
|
||||
RecordingState_t CDmeTimeSelection::GetRecordingState() const
|
||||
{
|
||||
return ( RecordingState_t )m_nRecordingState.Get();
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::GetTimeSelectionTimes( DmeTime_t curtime, DmeTime_t t[ TS_TIME_COUNT ] ) const
|
||||
{
|
||||
t[0] = GetAbsFalloff( curtime, 0 );
|
||||
t[1] = GetAbsHold ( curtime, 0 );
|
||||
t[2] = GetAbsHold ( curtime, 1 );
|
||||
t[3] = GetAbsFalloff( curtime, 1 );
|
||||
}
|
||||
|
||||
|
||||
void CDmeTimeSelection::SetTimeSelectionTimes( DmeTime_t curtime, DmeTime_t t[ TS_TIME_COUNT ] )
|
||||
{
|
||||
SetAbsFalloff( curtime, 0, t[0] );
|
||||
SetAbsHold ( curtime, 0, t[1] );
|
||||
SetAbsHold ( curtime, 1, t[2] );
|
||||
SetAbsFalloff( curtime, 1, t[3] );
|
||||
|
||||
Assert( !IsSuspicious( true ) );
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsInfinite( int side ) const
|
||||
{
|
||||
if ( side == 0 )
|
||||
{
|
||||
return m_hold[ side ] == DMETIME_MINTIME;
|
||||
}
|
||||
else if ( side == 1 )
|
||||
{
|
||||
return m_hold[ side ] == DMETIME_MAXTIME;
|
||||
}
|
||||
|
||||
// Shouldn't get here
|
||||
Assert( 0 );
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::GetInfinite( bool bInfinite[ 2 ] ) const
|
||||
{
|
||||
bInfinite[ 0 ] = IsInfinite( 0 );
|
||||
bInfinite[ 1 ] = IsInfinite( 1 );
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsFullyInfinite() const
|
||||
{
|
||||
return ( m_hold[ 0 ] == DMETIME_MINTIME ) && ( m_hold[ 1 ] == DMETIME_MAXTIME );
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsEitherInfinite() const
|
||||
{
|
||||
return ( m_hold[ 0 ] == DMETIME_MINTIME ) || ( m_hold[ 1 ] == DMETIME_MAXTIME );
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetInfinite( int side )
|
||||
{
|
||||
if ( side == 0 )
|
||||
{
|
||||
m_hold[ side ] = DMETIME_MINTIME;
|
||||
m_falloff[ side ] = DMETIME_MINTIME;
|
||||
}
|
||||
else if ( side == 1 )
|
||||
{
|
||||
m_hold[ side ] = DMETIME_MAXTIME;
|
||||
m_falloff[ side ] = DMETIME_MAXTIME;
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
bool CDmeTimeSelection::IsSuspicious( bool bCheckHoldAndFalloff /*= false*/ )
|
||||
{
|
||||
DmeTime_t t[ TS_TIME_COUNT ];
|
||||
GetAbsTimes( DMETIME_ZERO, t );
|
||||
DmeTime_t bounds[ 2 ] =
|
||||
{
|
||||
( DMETIME_MINTIME + DmeTime_t( 1000.0f ) ),
|
||||
( DMETIME_MAXTIME - DmeTime_t( 1000.0f ) )
|
||||
};
|
||||
for ( int i = 0; i < 4 ; ++i )
|
||||
{
|
||||
if ( t[ i ] == DMETIME_MINTIME ||
|
||||
t[ i ] == DMETIME_MAXTIME )
|
||||
continue;
|
||||
|
||||
if ( t[ i ] < bounds[ 0 ] ||
|
||||
t[ i ] > bounds[ 1 ] )
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( bCheckHoldAndFalloff )
|
||||
{
|
||||
// Also check for mismatched edges if infinite
|
||||
bool bEdgesInfinite[ 4 ] =
|
||||
{
|
||||
t[ TS_LEFT_FALLOFF ] == DMETIME_MINTIME,
|
||||
t[ TS_LEFT_HOLD ] == DMETIME_MINTIME,
|
||||
t[ TS_RIGHT_HOLD ] == DMETIME_MAXTIME,
|
||||
t[ TS_RIGHT_FALLOFF ] == DMETIME_MAXTIME,
|
||||
};
|
||||
|
||||
if ( ( bEdgesInfinite[ 0 ] ^ bEdgesInfinite[ 1 ] ) ||
|
||||
( bEdgesInfinite[ 2 ] ^ bEdgesInfinite[ 3 ] ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetAbsTime( DmeTime_t time, int tsType ) const
|
||||
{
|
||||
switch ( tsType )
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case TS_LEFT_FALLOFF:
|
||||
return GetAbsFalloff( time, 0 );
|
||||
case TS_LEFT_HOLD:
|
||||
return GetAbsHold( time, 0 );
|
||||
case TS_RIGHT_HOLD:
|
||||
return GetAbsHold( time, 1 );
|
||||
case TS_RIGHT_FALLOFF:
|
||||
return GetAbsFalloff( time, 1 );
|
||||
}
|
||||
Assert( 0 );
|
||||
return DMETIME_ZERO;
|
||||
}
|
||||
|
||||
DmeTime_t CDmeTimeSelection::GetRelativeTime( DmeTime_t time, int tsType ) const
|
||||
{
|
||||
switch ( tsType )
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case TS_LEFT_FALLOFF:
|
||||
return GetRelativeFalloff( time, 0 );
|
||||
case TS_LEFT_HOLD:
|
||||
return GetRelativeHold( time, 0 );
|
||||
case TS_RIGHT_HOLD:
|
||||
return GetRelativeHold( time, 1 );
|
||||
case TS_RIGHT_FALLOFF:
|
||||
return GetRelativeFalloff( time, 1 );
|
||||
}
|
||||
Assert( 0 );
|
||||
return DMETIME_ZERO;
|
||||
}
|
||||
|
||||
void CDmeTimeSelection::SetAbsTime( DmeTime_t time, int tsType, DmeTime_t absTime )
|
||||
{
|
||||
switch ( tsType )
|
||||
{
|
||||
default:
|
||||
Assert( 0 );
|
||||
break;
|
||||
case TS_LEFT_FALLOFF:
|
||||
SetAbsFalloff( time, 0, absTime );
|
||||
break;
|
||||
case TS_LEFT_HOLD:
|
||||
SetAbsHold( time, 0, absTime );
|
||||
break;
|
||||
case TS_RIGHT_HOLD:
|
||||
SetAbsHold( time, 1, absTime );
|
||||
break;
|
||||
case TS_RIGHT_FALLOFF:
|
||||
SetAbsFalloff( time, 1, absTime );
|
||||
break;
|
||||
}
|
||||
|
||||
Assert( !IsSuspicious() );
|
||||
}
|
||||
824
movieobjects/dmetrack.cpp
Normal file
824
movieobjects/dmetrack.cpp
Normal file
@@ -0,0 +1,824 @@
|
||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmetrack.h"
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
#include "movieobjects/dmetrackgroup.h"
|
||||
|
||||
#include "movieobjects_interfaces.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The solo track
|
||||
//-----------------------------------------------------------------------------
|
||||
DmElementHandle_t CDmeTrack::m_hSoloTrack[ DMECLIP_TYPE_COUNT ] =
|
||||
{
|
||||
DMELEMENT_HANDLE_INVALID,
|
||||
DMELEMENT_HANDLE_INVALID,
|
||||
DMELEMENT_HANDLE_INVALID,
|
||||
DMELEMENT_HANDLE_INVALID,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeTrack - common container class for clip objects
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTrack, CDmeTrack );
|
||||
|
||||
void CDmeTrack::OnConstruction()
|
||||
{
|
||||
m_hOwner = DMELEMENT_HANDLE_INVALID;
|
||||
|
||||
m_Flags.ClearAllFlags();
|
||||
m_Clips.Init( this, "children", FATTRIB_HAS_CALLBACK );
|
||||
m_Collapsed.InitAndSet( this, "collapsed", true );
|
||||
m_Mute.InitAndSet( this, "mute", false );
|
||||
m_Synched.InitAndSet( this, "synched", true );
|
||||
m_ClipType.InitAndSet( this, "clipType", DMECLIP_UNKNOWN, FATTRIB_HAS_CALLBACK );
|
||||
|
||||
m_Volume.InitAndSet( this, "volume", 1.0 );
|
||||
m_flDisplayScale.InitAndSet( this, "displayScale", 1.0f );
|
||||
}
|
||||
|
||||
void CDmeTrack::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods of IDmElement
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
|
||||
// Attach callbacks to detected sorted conditions if we're a film clip
|
||||
if ( pAttribute == m_ClipType.GetAttribute() )
|
||||
{
|
||||
if ( m_ClipType == DMECLIP_FILM )
|
||||
{
|
||||
m_Flags.ClearFlag( IS_SORTED );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// This gets called when start/end time of children change, or if the array changes
|
||||
// This is a hack, since any OnAttributeChanged call that gets chained here from another element will trigger this
|
||||
// At some point, we'll probably have to start sending more data through OnAttributeChanged, (like an event string or chain path)
|
||||
// or perhaps add a new callback OnElementChanged() with this data
|
||||
if ( pAttribute == m_Clips.GetAttribute() || ( pAttribute->GetOwner() != this ) )
|
||||
{
|
||||
if ( !m_Flags.IsFlagSet( SUPPRESS_DIRTY_ORDERING ) )
|
||||
{
|
||||
m_Flags.ClearFlag( IS_SORTED );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clip type
|
||||
//-----------------------------------------------------------------------------
|
||||
DmeClipType_t CDmeTrack::GetClipType() const
|
||||
{
|
||||
return (DmeClipType_t)m_ClipType.Get();
|
||||
}
|
||||
|
||||
void CDmeTrack::SetClipType( DmeClipType_t type )
|
||||
{
|
||||
m_ClipType = type;
|
||||
}
|
||||
|
||||
void CDmeTrack::SetCollapsed( bool state )
|
||||
{
|
||||
m_Collapsed = state;
|
||||
|
||||
}
|
||||
|
||||
bool CDmeTrack::IsCollapsed() const
|
||||
{
|
||||
return m_Collapsed.Get();
|
||||
}
|
||||
|
||||
void CDmeTrack::SetMute( bool state )
|
||||
{
|
||||
m_Mute = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Volume
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::SetVolume( float state )
|
||||
{
|
||||
m_Volume = state;
|
||||
}
|
||||
float CDmeTrack::GetVolume() const
|
||||
{
|
||||
return m_Volume.Get();
|
||||
}
|
||||
|
||||
// Is this track synched to the film track?
|
||||
void CDmeTrack::SetSynched( bool bState )
|
||||
{
|
||||
m_Synched = bState;
|
||||
}
|
||||
|
||||
bool CDmeTrack::IsSynched() const
|
||||
{
|
||||
return m_Synched;
|
||||
}
|
||||
|
||||
bool CDmeTrack::IsMute( bool bCheckSoloing ) const
|
||||
{
|
||||
// if we're muted, don't play regardless of whether we're solo
|
||||
CDmeTrack *pSoloTrack = bCheckSoloing ? GetSoloTrack() : NULL;
|
||||
return m_Mute.Get() || ( pSoloTrack != this && pSoloTrack != NULL );
|
||||
}
|
||||
|
||||
int CDmeTrack::GetClipCount() const
|
||||
{
|
||||
return m_Clips.Count();
|
||||
}
|
||||
|
||||
CDmeClip *CDmeTrack::GetClip( int i ) const
|
||||
{
|
||||
return m_Clips[ i ];
|
||||
}
|
||||
|
||||
const CUtlVector< DmElementHandle_t > &CDmeTrack::GetClips( ) const
|
||||
{
|
||||
return m_Clips.Get();
|
||||
}
|
||||
|
||||
void CDmeTrack::AddClip( CDmeClip *clip )
|
||||
{
|
||||
if ( clip->GetClipType() == GetClipType() )
|
||||
{
|
||||
// FIXME: In the case of a non-overlapped track,
|
||||
// we could optimize this to insert the clip in sorted order,
|
||||
// then fix overlaps (fixing overlaps requires a sorted list)
|
||||
Assert( FindClip( clip ) < 0 );
|
||||
m_Clips.AddToTail( clip );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrack::RemoveClip( int i )
|
||||
{
|
||||
// NOTE: Removal shouldn't cause sort order or fixup to become invalid
|
||||
CSuppressAutoFixup suppress( this, SUPPRESS_OVERLAP_FIXUP | SUPPRESS_DIRTY_ORDERING );
|
||||
m_Clips.Remove( i );
|
||||
}
|
||||
|
||||
bool CDmeTrack::RemoveClip( CDmeClip *clip )
|
||||
{
|
||||
Assert( clip->GetClipType() == GetClipType() );
|
||||
int i = FindClip( clip );
|
||||
if ( i != -1 )
|
||||
{
|
||||
RemoveClip( i );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDmeTrack::RemoveAllClips()
|
||||
{
|
||||
CSuppressAutoFixup suppress( this, SUPPRESS_OVERLAP_FIXUP | SUPPRESS_DIRTY_ORDERING );
|
||||
m_Clips.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the solo track, if any
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrack::GetSoloTrack( DmeClipType_t clipType )
|
||||
{
|
||||
return GetElement< CDmeTrack >( m_hSoloTrack[ clipType ] );
|
||||
}
|
||||
|
||||
void CDmeTrack::SetSoloTrack( DmeClipType_t clipType, CDmeTrack *pTrack )
|
||||
{
|
||||
m_hSoloTrack[ clipType ] = pTrack ? pTrack->GetHandle() : DMELEMENT_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
bool CDmeTrack::IsSoloTrack() const
|
||||
{
|
||||
return m_hSoloTrack[ GetClipType() ] == GetHandle();
|
||||
}
|
||||
|
||||
CDmeTrack *CDmeTrack::GetSoloTrack() const
|
||||
{
|
||||
return GetSoloTrack( GetClipType() );
|
||||
}
|
||||
|
||||
void CDmeTrack::SetSoloTrack( )
|
||||
{
|
||||
m_hSoloTrack[ GetClipType() ] = GetHandle();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods related to finding clips
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeTrack::FindClip( CDmeClip *clip )
|
||||
{
|
||||
Assert( clip->GetClipType() == GetClipType() );
|
||||
int c = m_Clips.Count();
|
||||
for ( int i = c - 1; i >= 0; --i )
|
||||
{
|
||||
if ( m_Clips[ i ] == clip )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
CDmeClip *CDmeTrack::FindNamedClip( const char *name )
|
||||
{
|
||||
int c = m_Clips.Count();
|
||||
for ( int i = c - 1; i >= 0; --i )
|
||||
{
|
||||
CDmeClip *child = m_Clips[ i ];
|
||||
if ( child && !Q_stricmp( child->GetName(), name ) )
|
||||
return child;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find clips at, intersecting or within a particular time interval
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::FindClipsAtTime( DmeTime_t time, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && IsCollapsed() )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int nClipCount = GetClipCount();
|
||||
for ( int j = 0; j < nClipCount; ++j )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( j );
|
||||
if ( !pSubClip )
|
||||
continue;
|
||||
if ( ( flags & DMESKIP_MUTED ) && pSubClip->IsMute() )
|
||||
continue;
|
||||
|
||||
if ( time.IsInRange( pSubClip->GetStartTime(), pSubClip->GetEndTime() ) )
|
||||
{
|
||||
clips.AddToTail( pSubClip );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrack::FindClipsIntersectingTime( DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && IsCollapsed() )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int nClipCount = GetClipCount();
|
||||
for ( int j = 0; j < nClipCount; ++j )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( j );
|
||||
if ( !pSubClip )
|
||||
continue;
|
||||
if ( ( flags & DMESKIP_MUTED ) && pSubClip->IsMute() )
|
||||
continue;
|
||||
|
||||
DmeTime_t clipStart = pSubClip->GetStartTime();
|
||||
DmeTime_t clipEnd = pSubClip->GetEndTime();
|
||||
if ( clipEnd >= startTime && clipStart < endTime )
|
||||
{
|
||||
clips.AddToTail( pSubClip );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrack::FindClipsWithinTime( DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && IsCollapsed() )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int nClipCount = GetClipCount();
|
||||
for ( int j = 0; j < nClipCount; ++j )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( j );
|
||||
if ( !pSubClip )
|
||||
continue;
|
||||
if ( ( flags & DMESKIP_MUTED ) && pSubClip->IsMute() )
|
||||
continue;
|
||||
|
||||
DmeTime_t clipStart = pSubClip->GetStartTime();
|
||||
DmeTime_t clipEnd = pSubClip->GetEndTime();
|
||||
if ( clipStart >= startTime && clipEnd <= endTime )
|
||||
{
|
||||
clips.AddToTail( pSubClip );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods related to shifting clips
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::ShiftAllClips( DmeTime_t dt )
|
||||
{
|
||||
if ( dt == DmeTime_t( 0 ) )
|
||||
return;
|
||||
|
||||
CSuppressAutoFixup suppress( this, SUPPRESS_OVERLAP_FIXUP | SUPPRESS_DIRTY_ORDERING );
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = m_Clips[ i ];
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrack::ShiftAllClipsAfter( DmeTime_t startTime, DmeTime_t dt, bool bTestStartingTime )
|
||||
{
|
||||
if ( dt == DmeTime_t( 0 ) )
|
||||
return;
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
DmeTime_t testTime = bTestStartingTime ? pSubClip->GetStartTime() : pSubClip->GetEndTime();
|
||||
if ( startTime < testTime )
|
||||
{
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrack::ShiftAllClipsBefore( DmeTime_t endTime, DmeTime_t dt, bool bTestEndingTime )
|
||||
{
|
||||
if ( dt == DmeTime_t( 0 ) )
|
||||
return;
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
DmeTime_t testTime = bTestEndingTime ? pSubClip->GetEndTime() : pSubClip->GetStartTime();
|
||||
if ( endTime > testTime )
|
||||
{
|
||||
DmeTime_t startTime = pSubClip->GetStartTime();
|
||||
pSubClip->SetStartTime( startTime + dt );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A version that works only on film clips
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::ShiftAllFilmClipsAfter( CDmeClip *pClip, DmeTime_t dt, bool bShiftClip /*=false*/, bool bSortClips /*=true*/ )
|
||||
{
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) || ( dt == DmeTime_t( 0 ) ) )
|
||||
return;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
if ( bSortClips )
|
||||
{
|
||||
SortClipsByStartTime();
|
||||
}
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = c; --i >= 0; )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( pSubClip == pClip )
|
||||
{
|
||||
if ( bShiftClip )
|
||||
{
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
return;
|
||||
}
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
|
||||
// Clip wasn't found!
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
void CDmeTrack::ShiftAllFilmClipsBefore( CDmeClip *pClip, DmeTime_t dt, bool bShiftClip /*=false*/, bool bSortClips /*=true*/ )
|
||||
{
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) || ( dt == DmeTime_t( 0 ) ) )
|
||||
return;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
if ( bSortClips )
|
||||
{
|
||||
SortClipsByStartTime();
|
||||
}
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
|
||||
if ( pSubClip == pClip )
|
||||
{
|
||||
if ( bShiftClip )
|
||||
{
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
return;
|
||||
}
|
||||
pSubClip->SetStartTime( pSubClip->GetStartTime() + dt );
|
||||
}
|
||||
|
||||
// Clip wasn't found!
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Method to sort clips by start time
|
||||
//-----------------------------------------------------------------------------
|
||||
struct SortInfo_t
|
||||
{
|
||||
DmeTime_t m_startTime;
|
||||
CDmeClip *m_pClip;
|
||||
};
|
||||
|
||||
static int ClipStartLessFunc( const void * lhs, const void * rhs )
|
||||
{
|
||||
SortInfo_t *pInfo1 = (SortInfo_t*)lhs;
|
||||
SortInfo_t *pInfo2 = (SortInfo_t*)rhs;
|
||||
if ( pInfo1->m_startTime == pInfo2->m_startTime )
|
||||
return 0;
|
||||
|
||||
return pInfo1->m_startTime < pInfo2->m_startTime ? -1 : 1;
|
||||
}
|
||||
|
||||
void CDmeTrack::SortClipsByStartTime( )
|
||||
{
|
||||
// If we're not a film clip, then we haven't installed callbacks to make sorting fast.
|
||||
// The IS_SORTED flag is some random state
|
||||
if ( (m_ClipType == DMECLIP_FILM) && m_Flags.IsFlagSet( IS_SORTED ) )
|
||||
return;
|
||||
m_Flags.SetFlag( IS_SORTED );
|
||||
|
||||
int c = GetClipCount();
|
||||
if ( c <= 1 )
|
||||
return;
|
||||
|
||||
DmeTime_t lastTime;
|
||||
SortInfo_t *pSortInfo = (SortInfo_t*)_alloca( c * sizeof(SortInfo_t) );
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip(i);
|
||||
pSortInfo[i].m_startTime = pSubClip ? pSubClip->GetStartTime() : DmeTime_t::InvalidTime();
|
||||
pSortInfo[i].m_pClip = pSubClip;
|
||||
if ( lastTime > pSortInfo[i].m_startTime )
|
||||
{
|
||||
m_Flags.ClearFlag( IS_SORTED );
|
||||
}
|
||||
lastTime = pSortInfo[i].m_startTime;
|
||||
}
|
||||
if ( m_Flags.IsFlagSet( IS_SORTED ) )
|
||||
return;
|
||||
|
||||
m_Flags.SetFlag( IS_SORTED );
|
||||
qsort( pSortInfo, c, sizeof(SortInfo_t), ClipStartLessFunc );
|
||||
|
||||
CSuppressAutoFixup suppress( this, SUPPRESS_OVERLAP_FIXUP | SUPPRESS_DIRTY_ORDERING );
|
||||
|
||||
m_Clips.RemoveAll();
|
||||
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
m_Clips.AddToTail( pSortInfo[i].m_pClip );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shifts all clips to be non-overlapping
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::FixOverlaps()
|
||||
{
|
||||
int c = GetClipCount();
|
||||
if ( c <= 1 )
|
||||
return;
|
||||
|
||||
SortClipsByStartTime();
|
||||
|
||||
CSuppressAutoFixup suppress( this, SUPPRESS_OVERLAP_FIXUP | SUPPRESS_DIRTY_ORDERING );
|
||||
|
||||
// Cull NULL clips
|
||||
int nActualCount = 0;
|
||||
CDmeClip **pClips = (CDmeClip**)_alloca( c * sizeof(CDmeClip*) );
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pCurr = GetClip( i );
|
||||
if ( pCurr && ((i == 0) || (pClips[i-1] != pCurr)) )
|
||||
{
|
||||
pClips[nActualCount++] = pCurr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( nActualCount <= 1 )
|
||||
return;
|
||||
|
||||
CDmeClip *pPrev = pClips[0];
|
||||
for ( int i = 1; i < nActualCount; ++i )
|
||||
{
|
||||
CDmeClip *pCurr = pClips[i];
|
||||
|
||||
DmeTime_t prevEndTime = pPrev->GetEndTime();
|
||||
DmeTime_t startTime = pCurr->GetStartTime();
|
||||
|
||||
if ( startTime < prevEndTime )
|
||||
{
|
||||
pCurr->SetStartTime( prevEndTime );
|
||||
}
|
||||
|
||||
pPrev = pCurr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds a clip at a particular time
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeClip* CDmeTrack::FindFilmClipAtTime( DmeTime_t localTime )
|
||||
{
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return NULL;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( pSubClip && pSubClip->GetStartTime() <= localTime && pSubClip->GetEndTime() > localTime )
|
||||
return pSubClip;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find first clip in a specific time range
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeClip* CDmeTrack::FindFirstFilmClipIntesectingTime( DmeTime_t localStartTime, DmeTime_t localEndTime )
|
||||
{
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return NULL;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( !pSubClip )
|
||||
continue;
|
||||
if ( ( localStartTime < pSubClip->GetEndTime() ) && ( localEndTime >= pSubClip->GetStartTime() ) )
|
||||
return static_cast<CDmeFilmClip*>( pSubClip );
|
||||
if ( localEndTime <= pSubClip->GetStartTime() )
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inserts space in a film track for a film clip
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::InsertSpaceInFilmTrack( DmeTime_t localStartTime, DmeTime_t localEndTime )
|
||||
{
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
CDmeClip *pClip = FindFirstFilmClipIntesectingTime( localStartTime, localEndTime );
|
||||
if ( pClip )
|
||||
{
|
||||
DmeTime_t filmStart = pClip->GetStartTime();
|
||||
DmeTime_t dt = localEndTime - filmStart;
|
||||
ShiftAllFilmClipsAfter( pClip, dt, true );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the next/previous clip in a film track
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeClip* CDmeTrack::FindPrevFilmClip( CDmeClip *pClip )
|
||||
{
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return NULL;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
if ( !pClip )
|
||||
return m_Clips[ m_Clips.Count() - 1 ];
|
||||
|
||||
// FIXME: Could use a binary search here based on time.
|
||||
// Probably doesn't matter though, since there will usually not be a ton of tracks
|
||||
CDmeClip *pPrevClip = NULL;
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( pSubClip == pClip )
|
||||
return pPrevClip;
|
||||
|
||||
pPrevClip = pSubClip;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDmeClip* CDmeTrack::FindNextFilmClip( CDmeClip *pClip )
|
||||
{
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return NULL;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
if ( !pClip )
|
||||
return m_Clips[ 0 ];
|
||||
|
||||
CDmeClip *pNextClip = NULL;
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = c; --i >= 0; )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( pSubClip == pClip )
|
||||
return pNextClip;
|
||||
|
||||
pNextClip = pSubClip;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void CDmeTrack::FindAdjacentFilmClips( CDmeClip *pClip, CDmeClip *&pPrevClip, CDmeClip *&pNextClip )
|
||||
{
|
||||
pPrevClip = pNextClip = NULL;
|
||||
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || !pClip || ( m_Clips.Count() == 0 ) )
|
||||
return;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( pSubClip == pClip )
|
||||
{
|
||||
pNextClip = ( i != c-1 ) ? GetClip( i+1 ) : NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
pPrevClip = pSubClip;
|
||||
}
|
||||
|
||||
pPrevClip = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the start/end time of the owning clip in local time
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::FindAdjacentFilmClips( DmeTime_t localTime, CDmeClip *&pPrevClip, CDmeClip *&pNextClip )
|
||||
{
|
||||
pPrevClip = pNextClip = NULL;
|
||||
|
||||
Assert( IsFilmTrack() );
|
||||
if ( !IsFilmTrack() || ( m_Clips.Count() == 0 ) )
|
||||
return;
|
||||
|
||||
// This algorithm requires sorted clips
|
||||
SortClipsByStartTime();
|
||||
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pSubClip = GetClip( i );
|
||||
if ( localTime >= pSubClip->GetEndTime() )
|
||||
{
|
||||
pPrevClip = pSubClip;
|
||||
}
|
||||
if ( localTime < pSubClip->GetStartTime() )
|
||||
{
|
||||
pNextClip = pSubClip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fills all gaps in a film track with slugs
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrack::FillAllGapsWithSlugs( const char *pSlugName, DmeTime_t startTime, DmeTime_t endTime )
|
||||
{
|
||||
if ( !IsFilmTrack() )
|
||||
return;
|
||||
|
||||
FixOverlaps();
|
||||
|
||||
// Create temporary slugs to fill in the gaps
|
||||
bool bSlugAdded = false;
|
||||
int c = GetClipCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeClip *pFilmClip = GetClip(i);
|
||||
DmeTime_t clipStartTime = pFilmClip->GetStartTime();
|
||||
if ( clipStartTime > startTime )
|
||||
{
|
||||
// There's a gap, create a slug
|
||||
CDmeFilmClip *pSlug = CreateSlugClip( pSlugName, startTime, clipStartTime, GetFileId() );
|
||||
|
||||
// This will add the slug to the end; so we don't have to
|
||||
// worry about iterating over it (we've cached off the initial count)
|
||||
AddClip( pSlug );
|
||||
|
||||
bSlugAdded = true;
|
||||
}
|
||||
startTime = pFilmClip->GetEndTime();
|
||||
}
|
||||
|
||||
if ( endTime > startTime )
|
||||
{
|
||||
// There's a gap, create a temporary slug
|
||||
CDmeFilmClip *pSlug = CreateSlugClip( pSlugName, startTime, endTime, GetFileId() );
|
||||
|
||||
// This will add the slug to the end; so we don't have to
|
||||
// worry about iterating over it (we've cached off the initial count)
|
||||
AddClip( pSlug );
|
||||
|
||||
bSlugAdded = true;
|
||||
}
|
||||
|
||||
if ( bSlugAdded )
|
||||
{
|
||||
FixOverlaps();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// helper methods
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrackGroup *GetParentTrackGroup( CDmeTrack *pTrack )
|
||||
{
|
||||
DmAttributeReferenceIterator_t hAttr = g_pDataModel->FirstAttributeReferencingElement( pTrack->GetHandle() );
|
||||
for ( ; hAttr != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID; hAttr = g_pDataModel->NextAttributeReferencingElement( hAttr ) )
|
||||
{
|
||||
CDmAttribute *pAttr = g_pDataModel->GetAttribute( hAttr );
|
||||
if ( !pAttr )
|
||||
continue;
|
||||
|
||||
CDmeTrackGroup *pTrackGroup = CastElement< CDmeTrackGroup >( pAttr->GetOwner() );
|
||||
if ( pTrackGroup )
|
||||
return pTrackGroup;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
532
movieobjects/dmetrackgroup.cpp
Normal file
532
movieobjects/dmetrackgroup.cpp
Normal file
@@ -0,0 +1,532 @@
|
||||
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmetrackgroup.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "movieobjects/dmetrack.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
|
||||
#include "movieobjects_interfaces.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeTrackGroup - contains a list of tracks
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTrackGroup, CDmeTrackGroup );
|
||||
|
||||
void CDmeTrackGroup::OnConstruction()
|
||||
{
|
||||
m_Tracks.Init( this, "tracks", FATTRIB_MUSTCOPY | FATTRIB_HAS_CALLBACK );
|
||||
m_bIsVisible.InitAndSet( this, "visible", true );
|
||||
m_bMute.Init( this, "mute" );
|
||||
m_flDisplayScale.InitAndSet( this, "displayScale", 1.0f );
|
||||
m_bMinimized.InitAndSet( this, "minimized", true );
|
||||
m_nMaxTrackCount = INT_MAX;
|
||||
m_Volume.InitAndSet( this, "volume", 1.0 );
|
||||
m_bForceMultiTrack.InitAndSet( this, "forcemultitrack", false );
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::OnDestruction()
|
||||
{
|
||||
// NOTE: The track owner handles may still be pointing to us when we get destructed,
|
||||
// but their handles will be invalid, so GetTrackGroup on a track
|
||||
// will correctly return NULL.
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Max track count
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::SetMaxTrackCount( int nCount )
|
||||
{
|
||||
m_nMaxTrackCount = nCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Mute
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::SetMute( bool state )
|
||||
{
|
||||
m_bMute = state;
|
||||
}
|
||||
|
||||
bool CDmeTrackGroup::IsMute( ) const
|
||||
{
|
||||
return m_bMute;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Volume
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::SetVolume( float state )
|
||||
{
|
||||
m_Volume = state;
|
||||
}
|
||||
float CDmeTrackGroup::GetVolume() const
|
||||
{
|
||||
return m_Volume.Get();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Owning clip
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeClip *CDmeTrackGroup::GetOwnerClip()
|
||||
{
|
||||
CDmeClip *pFindClip = FindReferringElement< CDmeClip >( this, "subClipTrackGroup" );
|
||||
if ( !pFindClip )
|
||||
{
|
||||
pFindClip = FindReferringElement< CDmeClip >( this, "trackGroups" );
|
||||
}
|
||||
return pFindClip;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we a film track group?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeTrackGroup::IsFilmTrackGroup()
|
||||
{
|
||||
CDmeClip *pOwnerClip = GetOwnerClip();
|
||||
if ( pOwnerClip )
|
||||
return pOwnerClip->GetFilmTrackGroup() == this;
|
||||
return m_nMaxTrackCount == 1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is a particular clip typed able to be added?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeTrackGroup::IsSubClipTypeAllowed( DmeClipType_t type )
|
||||
{
|
||||
if ( IsFilmTrackGroup() )
|
||||
{
|
||||
if ( type != DMECLIP_FILM )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( type == DMECLIP_FILM )
|
||||
return false;
|
||||
}
|
||||
|
||||
CDmeClip *pOwnerClip = GetOwnerClip();
|
||||
Assert( pOwnerClip );
|
||||
if ( !pOwnerClip )
|
||||
return true;
|
||||
|
||||
return pOwnerClip->IsSubClipTypeAllowed( type );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Track addition/removal
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::AddTrack( CDmeTrack *pTrack )
|
||||
{
|
||||
// FIXME: Should check if track with same name already exists???
|
||||
if ( GetTrackIndex( pTrack ) < 0 )
|
||||
{
|
||||
// Tracks can only exist in one track group
|
||||
Assert( GetTrackIndex( pTrack ) >= 0 );
|
||||
m_Tracks.AddToTail( pTrack );
|
||||
Assert( m_nMaxTrackCount >= m_Tracks.Count() );
|
||||
}
|
||||
}
|
||||
|
||||
CDmeTrack* CDmeTrackGroup::AddTrack( const char *pTrackName, DmeClipType_t trackType )
|
||||
{
|
||||
CDmeTrack *pTrack = CreateElement< CDmeTrack >( pTrackName, GetFileId() );
|
||||
pTrack->SetClipType( trackType );
|
||||
pTrack->SetCollapsed( false );
|
||||
m_Tracks.AddToTail( pTrack );
|
||||
Assert( m_nMaxTrackCount >= m_Tracks.Count() );
|
||||
return pTrack;
|
||||
}
|
||||
|
||||
CDmeTrack* CDmeTrackGroup::FindOrAddTrack( const char *pTrackName, DmeClipType_t trackType )
|
||||
{
|
||||
CDmeTrack *pTrack = FindTrack( pTrackName );
|
||||
if ( pTrack )
|
||||
{
|
||||
// If we found it, but it's the wrong type, no dice
|
||||
if ( pTrack->GetClipType() != trackType )
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTrack = AddTrack( pTrackName, trackType );
|
||||
}
|
||||
return pTrack;
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::RemoveTrack( int nIndex )
|
||||
{
|
||||
m_Tracks.Remove( nIndex );
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::RemoveTrack( CDmeTrack *pTrack )
|
||||
{
|
||||
int i = GetTrackIndex( pTrack );
|
||||
if ( i >= 0 )
|
||||
{
|
||||
m_Tracks.Remove( i );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::RemoveTrack( const char *pTrackName )
|
||||
{
|
||||
if ( !pTrackName )
|
||||
{
|
||||
pTrackName = DMETRACK_DEFAULT_NAME;
|
||||
}
|
||||
|
||||
int c = m_Tracks.Count();
|
||||
for ( int i = c; --i >= 0; )
|
||||
{
|
||||
if ( !Q_strcmp( m_Tracks[i]->GetName(), pTrackName ) )
|
||||
{
|
||||
m_Tracks.Remove( i );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Track finding
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::FindTrack( const char *pTrackName ) const
|
||||
{
|
||||
if ( !pTrackName )
|
||||
{
|
||||
pTrackName = DMETRACK_DEFAULT_NAME;
|
||||
}
|
||||
|
||||
int c = m_Tracks.Count();
|
||||
for ( int i = 0 ; i < c; ++i )
|
||||
{
|
||||
CDmeTrack *pTrack = m_Tracks[i];
|
||||
if ( !pTrack )
|
||||
continue;
|
||||
|
||||
if ( !Q_strcmp( pTrack->GetName(), pTrackName ) )
|
||||
return pTrack;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CDmeTrackGroup::GetTrackIndex( CDmeTrack *pTrack ) const
|
||||
{
|
||||
int nTracks = m_Tracks.Count();
|
||||
for ( int i = 0 ; i < nTracks; ++i )
|
||||
{
|
||||
if ( pTrack == m_Tracks[i] )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates the film track group [for internal use only]
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::CreateFilmTrack()
|
||||
{
|
||||
Assert( GetTrackCount() == 0 );
|
||||
return AddTrack( "Film", DMECLIP_FILM );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the film track, if any
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::GetFilmTrack()
|
||||
{
|
||||
if ( !IsFilmTrackGroup() )
|
||||
return NULL;
|
||||
|
||||
if ( GetTrackCount() > 0 )
|
||||
{
|
||||
Assert( GetTrackCount() == 1 );
|
||||
return m_Tracks[0];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adding/removing clips from tracks
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::AddClip( CDmeClip *pClip, const char *pTrackName )
|
||||
{
|
||||
DmeClipType_t type = pClip->GetClipType();
|
||||
if ( !pTrackName )
|
||||
{
|
||||
pTrackName = DMETRACK_DEFAULT_NAME;
|
||||
}
|
||||
|
||||
CDmeTrack *pTrack = FindOrAddTrack( pTrackName, type );
|
||||
if ( pTrack )
|
||||
{
|
||||
pTrack->AddClip( pClip );
|
||||
}
|
||||
return pTrack;
|
||||
}
|
||||
|
||||
bool CDmeTrackGroup::RemoveClip( CDmeClip *pClip )
|
||||
{
|
||||
CDmeTrack *pTrack = FindTrackForClip( pClip );
|
||||
if ( pTrack )
|
||||
return pTrack->RemoveClip( pClip );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Changing clip track
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::ChangeTrack( CDmeClip *pClip, const char *pNewTrack )
|
||||
{
|
||||
// Add, then remove, to avoid refcount problems
|
||||
// Don't remove if it wasn't added for some reason.
|
||||
CDmeTrack *pOldTrack = FindTrackForClip( pClip );
|
||||
CDmeTrack *pTrack = AddClip( pClip, pNewTrack );
|
||||
if ( pTrack && pOldTrack )
|
||||
{
|
||||
pOldTrack->RemoveClip( pClip );
|
||||
}
|
||||
return pTrack;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finding clips in tracks
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTrack *CDmeTrackGroup::FindTrackForClip( CDmeClip *pClip ) const
|
||||
{
|
||||
int nTrackIndex = -1;
|
||||
if ( !FindTrackForClip( pClip, &nTrackIndex, NULL ) )
|
||||
return NULL;
|
||||
|
||||
return GetTrack( nTrackIndex );
|
||||
}
|
||||
|
||||
|
||||
bool CDmeTrackGroup::FindTrackForClip( CDmeClip *pClip, int *pTrackIndex, int *pClipIndex ) const
|
||||
{
|
||||
DmeClipType_t type = pClip->GetClipType();
|
||||
int c = GetTrackCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeTrack *pTrack = GetTrack( i );
|
||||
if ( !pTrack )
|
||||
continue;
|
||||
|
||||
if ( pTrack->GetClipType() != type )
|
||||
continue;
|
||||
|
||||
int nClipCount = pTrack->GetClipCount();
|
||||
for ( int j = 0; j < nClipCount; ++j )
|
||||
{
|
||||
if ( pTrack->GetClip( j ) == pClip )
|
||||
{
|
||||
if ( pTrackIndex )
|
||||
{
|
||||
*pTrackIndex = i;
|
||||
}
|
||||
if ( pClipIndex )
|
||||
{
|
||||
*pClipIndex = j;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finding clips in tracks by time
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::FindClipsAtTime( DmeClipType_t clipType, DmeTime_t time, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && ( !IsVisible() || IsMinimized() ) )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int c = GetTrackCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeTrack *pTrack = GetTrack( i );
|
||||
if ( !pTrack )
|
||||
continue;
|
||||
|
||||
if ( ( clipType != DMECLIP_UNKNOWN ) && ( pTrack->GetClipType() != clipType ) )
|
||||
continue;
|
||||
|
||||
pTrack->FindClipsAtTime( time, flags, clips );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDmeTrackGroup::FindClipsIntersectingTime( DmeClipType_t clipType, DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && ( !IsVisible() || IsMinimized() ) )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int c = GetTrackCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeTrack *pTrack = GetTrack( i );
|
||||
if ( !pTrack )
|
||||
continue;
|
||||
|
||||
if ( ( clipType != DMECLIP_UNKNOWN ) && ( pTrack->GetClipType() != clipType ) )
|
||||
continue;
|
||||
|
||||
pTrack->FindClipsIntersectingTime( startTime, endTime, flags, clips );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDmeTrackGroup::FindClipsWithinTime( DmeClipType_t clipType, DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const
|
||||
{
|
||||
if ( ( flags & DMESKIP_INVISIBLE ) && ( !IsVisible() || IsMinimized() ) )
|
||||
return;
|
||||
|
||||
if ( ( flags & DMESKIP_MUTED ) && IsMute() )
|
||||
return;
|
||||
|
||||
int c = GetTrackCount();
|
||||
for ( int i = 0; i < c; ++i )
|
||||
{
|
||||
CDmeTrack *pTrack = GetTrack( i );
|
||||
if ( !pTrack )
|
||||
continue;
|
||||
|
||||
if ( ( clipType != DMECLIP_UNKNOWN ) && ( pTrack->GetClipType() != clipType ) )
|
||||
continue;
|
||||
|
||||
pTrack->FindClipsWithinTime( startTime, endTime, flags, clips );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Removes empty tracks
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTrackGroup::RemoveEmptyTracks()
|
||||
{
|
||||
int tc = GetTrackCount();
|
||||
for ( int i = tc; --i >= 0; )
|
||||
{
|
||||
CDmeTrack *pTrack = GetTrack( i );
|
||||
if ( pTrack->GetClipCount() == 0 )
|
||||
{
|
||||
RemoveTrack( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sort tracks by track type, then alphabetically
|
||||
//-----------------------------------------------------------------------------
|
||||
static int TrackLessFunc( const void * lhs, const void * rhs )
|
||||
{
|
||||
CDmeTrack *pInfo1 = *(CDmeTrack**)lhs;
|
||||
CDmeTrack *pInfo2 = *(CDmeTrack**)rhs;
|
||||
if ( pInfo1->GetClipType() < pInfo2->GetClipType() )
|
||||
return -1;
|
||||
if ( pInfo1->GetClipType() > pInfo2->GetClipType() )
|
||||
return 1;
|
||||
return Q_strcmp( pInfo1->GetName(), pInfo2->GetName() );
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::SortTracksByType()
|
||||
{
|
||||
int tc = GetTrackCount();
|
||||
if ( tc == 0 )
|
||||
return;
|
||||
|
||||
CDmeTrack **ppTrack = (CDmeTrack**)_alloca( tc * sizeof(CDmeTrack*) );
|
||||
for ( int i = 0; i < tc; ++i )
|
||||
{
|
||||
ppTrack[i] = GetTrack(i);
|
||||
}
|
||||
|
||||
qsort( ppTrack, tc, sizeof(CDmeTrack*), TrackLessFunc );
|
||||
|
||||
m_Tracks.RemoveAll();
|
||||
|
||||
for ( int i = 0; i < tc; ++i )
|
||||
{
|
||||
m_Tracks.AddToTail( ppTrack[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the flattened clip count
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeTrackGroup::GetSubClipCount() const
|
||||
{
|
||||
int nCount = 0;
|
||||
DMETRACKGROUP_FOREACH_CLIP_START( this, pTrack, pClip )
|
||||
++nCount;
|
||||
DMETRACKGROUP_FOREACH_CLIP_END()
|
||||
return nCount;
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::GetSubClips( CDmeClip **ppClips )
|
||||
{
|
||||
int nCount = 0;
|
||||
DMETRACKGROUP_FOREACH_CLIP_START( this, pTrack, pClip )
|
||||
ppClips[nCount++] = pClip;
|
||||
DMETRACKGROUP_FOREACH_CLIP_END()
|
||||
}
|
||||
|
||||
bool CDmeTrackGroup::GetForceMultiTrack() const
|
||||
{
|
||||
return const_cast< CDmeTrackGroup * >( this )->IsFilmTrackGroup() && m_bForceMultiTrack;
|
||||
}
|
||||
|
||||
void CDmeTrackGroup::SetForceMultiTrack( bool bForce )
|
||||
{
|
||||
m_bForceMultiTrack = bForce;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// helper methods
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeFilmClip *GetParentClip( CDmeTrackGroup *pTrackGroup )
|
||||
{
|
||||
DmAttributeReferenceIterator_t hAttr = g_pDataModel->FirstAttributeReferencingElement( pTrackGroup->GetHandle() );
|
||||
for ( ; hAttr != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID; hAttr = g_pDataModel->NextAttributeReferencingElement( hAttr ) )
|
||||
{
|
||||
CDmAttribute *pAttr = g_pDataModel->GetAttribute( hAttr );
|
||||
if ( !pAttr )
|
||||
continue;
|
||||
|
||||
CDmeFilmClip *pFilmClip = CastElement< CDmeFilmClip >( pAttr->GetOwner() );
|
||||
if ( pFilmClip )
|
||||
return pFilmClip;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
94
movieobjects/dmetransform.cpp
Normal file
94
movieobjects/dmetransform.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include "datamodel/dmattributevar.h"
|
||||
#include "movieobjects/dmedag.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTransform, CDmeTransform );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransform::OnConstruction()
|
||||
{
|
||||
m_Position.Init( this, TRANSFORM_POSITION, FATTRIB_HAS_CALLBACK );
|
||||
m_Orientation.Init( this, TRANSFORM_ORIENTATION, FATTRIB_HAS_CALLBACK );
|
||||
}
|
||||
|
||||
void CDmeTransform::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeTransform::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
|
||||
InvokeOnAttributeChangedOnReferrers( GetHandle(), pAttribute );
|
||||
}
|
||||
|
||||
void CDmeTransform::SetTransform( const matrix3x4_t &transform )
|
||||
{
|
||||
Vector origin;
|
||||
Quaternion angles;
|
||||
MatrixAngles( transform, angles, origin );
|
||||
m_Orientation.Set( angles );
|
||||
m_Position.Set( origin );
|
||||
}
|
||||
|
||||
void CDmeTransform::GetTransform( matrix3x4_t &transform )
|
||||
{
|
||||
QuaternionMatrix( m_Orientation.Get(), m_Position.Get(), transform );
|
||||
}
|
||||
|
||||
const Vector &CDmeTransform::GetPosition() const
|
||||
{
|
||||
return m_Position.Get();
|
||||
}
|
||||
|
||||
void CDmeTransform::SetPosition( const Vector &vecPosition )
|
||||
{
|
||||
m_Position = vecPosition;
|
||||
}
|
||||
|
||||
const Quaternion &CDmeTransform::GetOrientation() const
|
||||
{
|
||||
return m_Orientation.Get();
|
||||
}
|
||||
|
||||
void CDmeTransform::SetOrientation( const Quaternion &orientation )
|
||||
{
|
||||
m_Orientation = orientation;
|
||||
}
|
||||
|
||||
|
||||
CDmAttribute *CDmeTransform::GetPositionAttribute()
|
||||
{
|
||||
return m_Position.GetAttribute();
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeTransform::GetOrientationAttribute()
|
||||
{
|
||||
return m_Orientation.GetAttribute();
|
||||
}
|
||||
|
||||
CDmeDag *CDmeTransform::GetDag()
|
||||
{
|
||||
static CUtlSymbolLarge symTransform = g_pDataModel->GetSymbol( "transform" );
|
||||
CDmeDag *pDag = FindReferringElement< CDmeDag >( this, symTransform );
|
||||
return pDag;
|
||||
}
|
||||
468
movieobjects/dmetransformcontrol.cpp
Normal file
468
movieobjects/dmetransformcontrol.cpp
Normal file
@@ -0,0 +1,468 @@
|
||||
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Implementation of CDmeTransformControl class, a helper for
|
||||
// modifying a transform. The CDmeTransformControl class implementation
|
||||
// contains functions for setting and retrieving parameters used in transform
|
||||
// manipulations, these parameters are allocated when the first value is set.
|
||||
// If the manipulation parameters have not been allocated a default value will
|
||||
// be returned. Additionally the CDmeTransformControl provides access to the
|
||||
// rotation channel associated with the transform, even if the transform
|
||||
// control is not directly attached to the rotation channel.
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeanimationset.h"
|
||||
#include "movieobjects/dmetransformcontrol.h"
|
||||
#include "movieobjects/dmechannel.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "movieobjects/dmerigconstraintoperators.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTransformControl, CDmeTransformControl );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Provide post construction processing.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::OnConstruction()
|
||||
{
|
||||
m_PivotOffset = vec3_origin;
|
||||
m_pManipulationParams = NULL;
|
||||
|
||||
m_PositionValue.InitAndSet( this, "valuePosition", vec3_origin );
|
||||
m_OrientationValue.InitAndSet( this, "valueOrientation", quat_identity );
|
||||
m_PositionChannel.Init( this, "positionChannel" );
|
||||
m_OrientationChannel.Init( this, "orientationChannel" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Provide processing and cleanup before shutdown
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::OnDestruction()
|
||||
{
|
||||
// Destroy the manipulation parameters if they have been created.
|
||||
delete m_pManipulationParams;
|
||||
m_pManipulationParams = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Allocate and initialize the manipulation parameters
|
||||
//
|
||||
// Output : Returns true if the manipulation parameters were successfully
|
||||
// initialized, false if the initialization failed.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeTransformControl::InitManipulationParams()
|
||||
{
|
||||
if ( m_pManipulationParams == NULL )
|
||||
{
|
||||
m_pManipulationParams = new ManipulationParams_t;
|
||||
|
||||
if ( m_pManipulationParams )
|
||||
{
|
||||
m_pManipulationParams->Pivot = vec3_origin;
|
||||
m_pManipulationParams->RotationLocal = quat_identity;
|
||||
m_pManipulationParams->RotationParent = quat_identity;
|
||||
SetIdentityMatrix( m_pManipulationParams->Transform );
|
||||
}
|
||||
}
|
||||
|
||||
return ( m_pManipulationParams != NULL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the manipulation transform matrix
|
||||
//
|
||||
// Output : transform - The transform that will be applied by the current
|
||||
// manipulation.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::GetManipulationTransform( matrix3x4_t &transform ) const
|
||||
{
|
||||
if ( m_pManipulationParams )
|
||||
{
|
||||
transform = m_pManipulationParams->Transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetIdentityMatrix( transform );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the manipulation transform matrix
|
||||
//
|
||||
// Input : transform - Matrix specifying the transform to be performed by the
|
||||
// manipulation.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetManipulationTransform( const matrix3x4_t &transform )
|
||||
{
|
||||
if ( InitManipulationParams() )
|
||||
{
|
||||
m_pManipulationParams->Transform = transform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the manipulation rotation amount in the transform local space
|
||||
//
|
||||
// Output : deltaRotation - Current rotation that will be applied in the
|
||||
// transform manipulation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::GetManipulationRotationLocal( Quaternion &rotation ) const
|
||||
{
|
||||
if ( m_pManipulationParams )
|
||||
{
|
||||
rotation = m_pManipulationParams->RotationLocal;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotation = quat_identity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the manipulation rotation amount in the transform local space
|
||||
//
|
||||
// Input : deltaRotation - Rotation to be applied in the transform manipulation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetManipulationRotationLocal( const Quaternion &rotation )
|
||||
{
|
||||
if ( InitManipulationParams() )
|
||||
{
|
||||
m_pManipulationParams->RotationLocal = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the manipulation rotation amount in the parent space of the transform
|
||||
//
|
||||
// Output : localRotation - Current local rotation that will be applied in the
|
||||
// transform manipulation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::GetManipulationRotationParent( Quaternion &rotation ) const
|
||||
{
|
||||
if ( m_pManipulationParams )
|
||||
{
|
||||
rotation = m_pManipulationParams->RotationParent;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotation = quat_identity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the manipulation rotation amount in the parent space of the transform
|
||||
//
|
||||
// Input : localRotation - Local rotation to be applied in the transform
|
||||
// manipulation.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetManipulationRotationParent( const Quaternion &rotation )
|
||||
{
|
||||
if ( InitManipulationParams() )
|
||||
{
|
||||
m_pManipulationParams->RotationParent = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the manipulation pivot position, this may differ from the pivot
|
||||
// offset
|
||||
//
|
||||
// Output : pivotPosition - Pivot position being used for the current transform
|
||||
// manipulation
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::GetManipulationPivot( Vector &pivotPosition ) const
|
||||
{
|
||||
if ( m_pManipulationParams )
|
||||
{
|
||||
pivotPosition = m_pManipulationParams->Pivot;
|
||||
}
|
||||
else
|
||||
{
|
||||
pivotPosition = vec3_origin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the manipulation pivot position
|
||||
//
|
||||
// Input : Position to be used as the pivot location for manipulations
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetManipulationPivot( const Vector &pivotPosition )
|
||||
{
|
||||
if ( InitManipulationParams() )
|
||||
{
|
||||
m_pManipulationParams->Pivot = pivotPosition;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the current local space pivot offset
|
||||
//
|
||||
// Output : Return the current local space pivot offset
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector &CDmeTransformControl::GetPivotOffset() const
|
||||
{
|
||||
return m_PivotOffset;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the current local space pivot offset
|
||||
//
|
||||
// Input : localOffset - The new local offset that is to be assigned to the
|
||||
// pivot.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetPivotOffset( const Vector &localOffset )
|
||||
{
|
||||
m_PivotOffset = localOffset;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the transform associated with the transform control
|
||||
//
|
||||
// Output : Returns the pointer to the transform element
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTransform *CDmeTransformControl::GetTransform() const
|
||||
{
|
||||
CDmeTransform *pTransform = NULL;
|
||||
|
||||
CDmeChannel *pChannel = GetPositionChannel();
|
||||
if ( pChannel == NULL )
|
||||
{
|
||||
pChannel = GetOrientationChannel();
|
||||
}
|
||||
|
||||
if ( pChannel )
|
||||
{
|
||||
CDmElement *pToElement = pChannel->GetToElement();
|
||||
pTransform = CastElement< CDmeTransform>( pToElement );
|
||||
|
||||
// If the element targeted by the channel is not a transform,
|
||||
// see if it is a constraint slave, and get the transform from that.
|
||||
if ( pTransform == NULL )
|
||||
{
|
||||
CDmeConstraintSlave *pConstraintSlave = CastElement< CDmeConstraintSlave >( pToElement );
|
||||
if ( pConstraintSlave )
|
||||
{
|
||||
CDmeDag *pDag = pConstraintSlave->GetDag();
|
||||
if ( pDag )
|
||||
{
|
||||
pTransform = pDag->GetTransform();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pTransform;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the dag node associated with the transform control
|
||||
//
|
||||
// Output: Returns the pointer to the dag node targeted by the transform
|
||||
// control.
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeDag *CDmeTransformControl::GetDag() const
|
||||
{
|
||||
CDmeDag *pDagNode = NULL;
|
||||
CDmeTransform *pTransform = GetTransform();
|
||||
|
||||
if ( pTransform )
|
||||
{
|
||||
pDagNode = pTransform->GetDag();
|
||||
}
|
||||
|
||||
return pDagNode;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the position attribute of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmAttribute *CDmeTransformControl::GetPositionAttr()
|
||||
{
|
||||
return m_PositionValue.GetAttribute();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the orientation attribute of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmAttribute *CDmeTransformControl::GetOrientationAttr()
|
||||
{
|
||||
return m_OrientationValue.GetAttribute();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the position value of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector &CDmeTransformControl::GetPosition() const
|
||||
{
|
||||
return m_PositionValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the orientation value of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
const Quaternion &CDmeTransformControl::GetOrientation() const
|
||||
{
|
||||
return m_OrientationValue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Determine if the control currently has a default position set
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeTransformControl::HasDefaultPosition() const
|
||||
{
|
||||
return HasAttribute( DEFAULT_POSITION_ATTR, AT_VECTOR3 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Determine if the control currently has a default orientation set
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeTransformControl::HasDefaultOrientation() const
|
||||
{
|
||||
return HasAttribute( DEFAULT_ORIENTATION_ATTR, AT_QUATERNION );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the default position of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector &CDmeTransformControl::GetDefaultPosition() const
|
||||
{
|
||||
return GetValue< Vector >( DEFAULT_POSITION_ATTR, vec3_origin );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the default orientation of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
const Quaternion &CDmeTransformControl::GetDefaultOrientation() const
|
||||
{
|
||||
return GetValue< Quaternion >( DEFAULT_ORIENTATION_ATTR, quat_identity );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the default position attribute
|
||||
//-----------------------------------------------------------------------------
|
||||
const CDmAttribute *CDmeTransformControl::GetDefaultPositionAttr() const
|
||||
{
|
||||
return GetAttribute( DEFAULT_POSITION_ATTR, AT_VECTOR3 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the default position attribute
|
||||
//-----------------------------------------------------------------------------
|
||||
const CDmAttribute *CDmeTransformControl::GetDefaultOrientationAttr() const
|
||||
{
|
||||
return GetAttribute( DEFAULT_ORIENTATION_ATTR, AT_QUATERNION );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the position channel targeting the control
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeChannel *CDmeTransformControl::GetPositionChannel() const
|
||||
{
|
||||
return m_PositionChannel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the orientation channel targeting the control
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeChannel *CDmeTransformControl::GetOrientationChannel() const
|
||||
{
|
||||
return m_OrientationChannel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the position value of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetPosition( const Vector &position )
|
||||
{
|
||||
m_PositionValue = position;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the orientation value of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetOrientation( const Quaternion &orientation )
|
||||
{
|
||||
m_OrientationValue = orientation;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the default position of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetDefaultPosition( const Vector &position )
|
||||
{
|
||||
CDmAttribute *pAttr = SetValue< Vector >( DEFAULT_POSITION_ATTR, position );
|
||||
if ( pAttr )
|
||||
{
|
||||
pAttr->AddFlag( FATTRIB_DONTSAVE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the default orientation of the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetDefaultOrientation( const Quaternion &orientation )
|
||||
{
|
||||
CDmAttribute *pAttr = SetValue< Quaternion >( DEFAULT_ORIENTATION_ATTR, orientation );
|
||||
if ( pAttr )
|
||||
{
|
||||
pAttr->AddFlag( FATTRIB_DONTSAVE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the position channel that is targeting the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetPositionChannel( CDmeChannel *pChannel )
|
||||
{
|
||||
m_PositionChannel = pChannel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the orientation channel that is targeting the control
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformControl::SetOrientationChannel( CDmeChannel *pChannel )
|
||||
{
|
||||
m_OrientationChannel = pChannel;
|
||||
}
|
||||
|
||||
98
movieobjects/dmetransforminput.cpp
Normal file
98
movieobjects/dmetransforminput.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/dmetransforminput.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTranslationInput, CDmeTranslationInput );
|
||||
|
||||
|
||||
void CDmeTranslationInput::OnConstruction()
|
||||
{
|
||||
m_translation.Init( this, "translation" );
|
||||
}
|
||||
|
||||
void CDmeTranslationInput::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeTranslationInput::IsDirty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDmeTranslationInput::Operate()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeTranslationInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeTranslationInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_translation.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeRotationInput, CDmeRotationInput );
|
||||
|
||||
|
||||
void CDmeRotationInput::OnConstruction()
|
||||
{
|
||||
m_orientation.Init( this, "orientation" );
|
||||
m_angles.Init( this, "angles" );
|
||||
}
|
||||
|
||||
void CDmeRotationInput::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeRotationInput::IsDirty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDmeRotationInput::Operate()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeRotationInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeRotationInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_orientation.GetAttribute() );
|
||||
attrs.AddToTail( m_angles.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeRotationInput::SetRotation( const Quaternion& quat )
|
||||
{
|
||||
QAngle qangle;
|
||||
QuaternionAngles( quat, qangle );
|
||||
m_angles = qangle;
|
||||
m_orientation = quat;
|
||||
}
|
||||
|
||||
void CDmeRotationInput::SetRotation( const QAngle& qangle )
|
||||
{
|
||||
Quaternion quat;
|
||||
AngleQuaternion( qangle, quat );
|
||||
m_orientation = quat;
|
||||
m_angles = qangle;
|
||||
}
|
||||
38
movieobjects/dmetransformlist.cpp
Normal file
38
movieobjects/dmetransformlist.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// An element that contains a transformlist
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmetransformlist.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTransformList, CDmeTransformList );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformList::OnConstruction()
|
||||
{
|
||||
m_Transforms.Init( this, "transforms" );
|
||||
}
|
||||
|
||||
void CDmeTransformList::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the transform
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformList::SetTransform( int nIndex, const matrix3x4_t& mat )
|
||||
{
|
||||
m_Transforms[nIndex]->SetTransform( mat );
|
||||
}
|
||||
107
movieobjects/dmetransformoperator.cpp
Normal file
107
movieobjects/dmetransformoperator.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// The transform operator class - shortcut to setting transform values from floats
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmetransformoperator.h"
|
||||
#include "movieobjects/dmetransform.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTransformOperator, CDmeTransformOperator );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformOperator::OnConstruction()
|
||||
{
|
||||
m_transform.Init( this, "transform" );
|
||||
m_positionX.Init( this, "positionX" );
|
||||
m_positionY.Init( this, "positionY" );
|
||||
m_positionZ.Init( this, "positionZ" );
|
||||
m_orientationX.Init( this, "orientationX" );
|
||||
m_orientationY.Init( this, "orientationY" );
|
||||
m_orientationZ.Init( this, "orientationZ" );
|
||||
m_orientationW.Init( this, "orientationW" );
|
||||
}
|
||||
|
||||
void CDmeTransformOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTransformOperator::Operate()
|
||||
{
|
||||
CDmeTransform *pTransform = m_transform.GetElement();
|
||||
if ( pTransform == NULL )
|
||||
return;
|
||||
|
||||
Vector position = pTransform->GetValue< Vector >( TRANSFORM_POSITION );
|
||||
Quaternion orientation = pTransform->GetValue< Quaternion >( TRANSFORM_ORIENTATION );
|
||||
|
||||
position.x = m_positionX.Get();
|
||||
position.y = m_positionY.Get();
|
||||
position.z = m_positionZ.Get();
|
||||
|
||||
orientation.x = m_orientationX.Get();
|
||||
orientation.y = m_orientationY.Get();
|
||||
orientation.z = m_orientationZ.Get();
|
||||
orientation.w = m_orientationW.Get();
|
||||
|
||||
pTransform->SetValue( TRANSFORM_POSITION, position );
|
||||
pTransform->SetValue( TRANSFORM_ORIENTATION, orientation );
|
||||
}
|
||||
|
||||
// hack to avoid MSVC complaining about multiply defined symbols
|
||||
namespace TransformOp
|
||||
{
|
||||
void AddAttr( CUtlVector< CDmAttribute * > &attrs, CDmAttribute *pAttr )
|
||||
{
|
||||
if ( pAttr == NULL )
|
||||
return;
|
||||
attrs.AddToTail( pAttr );
|
||||
}
|
||||
};
|
||||
using namespace TransformOp;
|
||||
|
||||
void CDmeTransformOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
AddAttr( attrs, m_positionX.GetAttribute() );
|
||||
AddAttr( attrs, m_positionY.GetAttribute() );
|
||||
AddAttr( attrs, m_positionZ.GetAttribute() );
|
||||
AddAttr( attrs, m_orientationX.GetAttribute() );
|
||||
AddAttr( attrs, m_orientationY.GetAttribute() );
|
||||
AddAttr( attrs, m_orientationZ.GetAttribute() );
|
||||
AddAttr( attrs, m_orientationW.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeTransformOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
CDmeTransform *pTransform = m_transform.GetElement();
|
||||
if ( pTransform == NULL )
|
||||
return;
|
||||
|
||||
AddAttr( attrs, pTransform->GetAttribute( TRANSFORM_POSITION ) );
|
||||
AddAttr( attrs, pTransform->GetAttribute( TRANSFORM_ORIENTATION ) );
|
||||
}
|
||||
|
||||
void CDmeTransformOperator::SetTransform( CDmeTransform *pTransform )
|
||||
{
|
||||
m_transform.Set( pTransform );
|
||||
}
|
||||
|
||||
const CDmeTransform *CDmeTransformOperator::GetTransform() const
|
||||
{
|
||||
return m_transform.GetElement();
|
||||
}
|
||||
334
movieobjects/dmeunpackoperators.cpp
Normal file
334
movieobjects/dmeunpackoperators.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects/dmeunpackoperators.h"
|
||||
#include "movieobjects_interfaces.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datamodel/dmattribute.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackColorOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackColorOperator, CDmeUnpackColorOperator );
|
||||
|
||||
void CDmeUnpackColorOperator::OnConstruction()
|
||||
{
|
||||
m_color.Init( this, "color" );
|
||||
m_red .Init( this, "red" );
|
||||
m_green.Init( this, "green" );
|
||||
m_blue .Init( this, "blue" );
|
||||
m_alpha.Init( this, "alpha" );
|
||||
}
|
||||
|
||||
void CDmeUnpackColorOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackColorOperator::IsDirty()
|
||||
{
|
||||
const Color &c = m_color.Get();
|
||||
float s = 255.999f;
|
||||
return c.r() != s*m_red.Get() || c.g() != s*m_green.Get() || c.b() != s*m_blue.Get() || c.a() != s*m_alpha.Get();
|
||||
// return c.r() != m_red.Get() || c.g() != m_green.Get() || c.b() != m_blue.Get() || c.a() != m_alpha.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackColorOperator::Operate()
|
||||
{
|
||||
static const float s_inv = 1.0f / 255.999f;
|
||||
m_red .Set( s_inv * m_color.Get().r() );
|
||||
m_green.Set( s_inv * m_color.Get().g() );
|
||||
m_blue .Set( s_inv * m_color.Get().b() );
|
||||
m_alpha.Set( s_inv * m_color.Get().a() );
|
||||
}
|
||||
|
||||
void CDmeUnpackColorOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_color.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackColorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_red.GetAttribute() );
|
||||
attrs.AddToTail( m_green.GetAttribute() );
|
||||
attrs.AddToTail( m_blue.GetAttribute() );
|
||||
attrs.AddToTail( m_alpha.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackVector2Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector2Operator, CDmeUnpackVector2Operator );
|
||||
|
||||
void CDmeUnpackVector2Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector2Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackVector2Operator::IsDirty()
|
||||
{
|
||||
const Vector2D &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackVector2Operator::Operate()
|
||||
{
|
||||
m_x.Set( m_vector.Get().x );
|
||||
m_y.Set( m_vector.Get().y );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector2Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector2Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackVector3Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector3Operator, CDmeUnpackVector3Operator );
|
||||
|
||||
void CDmeUnpackVector3Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector3Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackVector3Operator::IsDirty()
|
||||
{
|
||||
const Vector &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackVector3Operator::Operate()
|
||||
{
|
||||
m_x.Set( m_vector.Get().x );
|
||||
m_y.Set( m_vector.Get().y );
|
||||
m_z.Set( m_vector.Get().z );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector3Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector3Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackVector4Operator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector4Operator, CDmeUnpackVector4Operator );
|
||||
|
||||
void CDmeUnpackVector4Operator::OnConstruction()
|
||||
{
|
||||
m_vector.Init( this, "vector" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
m_w.Init( this, "w" );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector4Operator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackVector4Operator::IsDirty()
|
||||
{
|
||||
const Vector4D &v = m_vector.Get();
|
||||
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get() || v.w != m_w.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackVector4Operator::Operate()
|
||||
{
|
||||
m_x.Set( m_vector.Get().x );
|
||||
m_y.Set( m_vector.Get().y );
|
||||
m_z.Set( m_vector.Get().z );
|
||||
m_w.Set( m_vector.Get().w );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector4Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vector.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackVector4Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
attrs.AddToTail( m_w.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackQAngleOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackQAngleOperator, CDmeUnpackQAngleOperator );
|
||||
|
||||
void CDmeUnpackQAngleOperator::OnConstruction()
|
||||
{
|
||||
m_qangle.Init( this, "qangle" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
}
|
||||
|
||||
void CDmeUnpackQAngleOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackQAngleOperator::IsDirty()
|
||||
{
|
||||
const QAngle &q = m_qangle.Get();
|
||||
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackQAngleOperator::Operate()
|
||||
{
|
||||
m_x.Set( m_qangle.Get().x );
|
||||
m_y.Set( m_qangle.Get().y );
|
||||
m_z.Set( m_qangle.Get().z );
|
||||
}
|
||||
|
||||
void CDmeUnpackQAngleOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_qangle.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackQAngleOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackQuaternionOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackQuaternionOperator, CDmeUnpackQuaternionOperator );
|
||||
|
||||
void CDmeUnpackQuaternionOperator::OnConstruction()
|
||||
{
|
||||
m_quaternion.Init( this, "quaternion" );
|
||||
m_x.Init( this, "x" );
|
||||
m_y.Init( this, "y" );
|
||||
m_z.Init( this, "z" );
|
||||
m_w.Init( this, "w" );
|
||||
}
|
||||
|
||||
void CDmeUnpackQuaternionOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackQuaternionOperator::IsDirty()
|
||||
{
|
||||
const Quaternion &q = m_quaternion.Get();
|
||||
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get() || q.w != m_w.Get();
|
||||
}
|
||||
|
||||
void CDmeUnpackQuaternionOperator::Operate()
|
||||
{
|
||||
m_x.Set( m_quaternion.Get().x );
|
||||
m_y.Set( m_quaternion.Get().y );
|
||||
m_z.Set( m_quaternion.Get().z );
|
||||
m_w.Set( m_quaternion.Get().w );
|
||||
}
|
||||
|
||||
void CDmeUnpackQuaternionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_quaternion.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackQuaternionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_x.GetAttribute() );
|
||||
attrs.AddToTail( m_y.GetAttribute() );
|
||||
attrs.AddToTail( m_z.GetAttribute() );
|
||||
attrs.AddToTail( m_w.GetAttribute() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDmeUnpackVMatrixOperator
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVMatrixOperator, CDmeUnpackVMatrixOperator );
|
||||
|
||||
void CDmeUnpackVMatrixOperator::OnConstruction()
|
||||
{
|
||||
m_vmatrix.Init( this, "vmatrix" );
|
||||
char name[ 4 ];
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
Q_snprintf( name, sizeof(name), "m%d%d", i >> 2, i & 0x3 );
|
||||
m_cells[ i ].Init( this, name );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeUnpackVMatrixOperator::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
bool CDmeUnpackVMatrixOperator::IsDirty()
|
||||
{
|
||||
const VMatrix &v = m_vmatrix.Get();
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
if ( *( v[ i ] ) != m_cells[ i ].Get() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDmeUnpackVMatrixOperator::Operate()
|
||||
{
|
||||
VMatrix v;
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
m_cells[ i ].Set( *( v[ i ] ) );
|
||||
}
|
||||
m_vmatrix.Set( v );
|
||||
}
|
||||
|
||||
void CDmeUnpackVMatrixOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
attrs.AddToTail( m_vmatrix.GetAttribute() );
|
||||
}
|
||||
|
||||
void CDmeUnpackVMatrixOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
|
||||
{
|
||||
for ( uint i = 0; i < 16; ++i )
|
||||
{
|
||||
attrs.AddToTail( m_cells[i].GetAttribute() );
|
||||
}
|
||||
}
|
||||
265
movieobjects/dmeusersettings.cpp
Normal file
265
movieobjects/dmeusersettings.cpp
Normal file
@@ -0,0 +1,265 @@
|
||||
//============ Copyright (c) Valve Corporation, All rights reserved. ============
|
||||
|
||||
|
||||
#include "movieobjects/dmeusersettings.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "datamodel/dmattributevar.h"
|
||||
|
||||
#if !defined( _X360 )
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define OEMRESOURCE
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "tier0/memdbgon.h" // memdbgon must be the last include file in a .cpp file!!!
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeUserSettings, CDmeUserSettings);
|
||||
|
||||
static CUtlMap< const char *, CDmAttribute * >s_RegistryPathToAttribute( DefLessFunc( const char * ) );
|
||||
|
||||
CUtlVector< IDmeUserSettingsChangedListener * > CDmeUserSettings::s_UserSettingsChangedListeners;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CDmeUserSettings *CDmeUserSettings::SharedUserSettings()
|
||||
{
|
||||
static CDmeUserSettings *s_UserSettings;
|
||||
if( !s_UserSettings )
|
||||
{
|
||||
s_UserSettings = CreateElement< CDmeUserSettings >( "userSettings", DMFILEID_INVALID );
|
||||
}
|
||||
return s_UserSettings;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CDmeUserSettings::OnConstruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CDmeUserSettings::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CDmeUserSettings::AddUserSettingsChangedListener( IDmeUserSettingsChangedListener *pListener )
|
||||
{
|
||||
s_UserSettingsChangedListeners.AddToTail( pListener );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CDmeUserSettings::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
|
||||
const char *pRegistryPath = FindRegistryPathForAttribute( pAttribute );
|
||||
if( pRegistryPath )
|
||||
{
|
||||
SetRegistryFromAttribute( pAttribute, pRegistryPath );
|
||||
|
||||
KeyValues *pMessage = new KeyValues( "OnUserSettingsChanged", NameKey, pAttribute->GetName() );
|
||||
pMessage->SetPtr( AttributeKey, pAttribute );
|
||||
pMessage->SetString( RegistryPathKey, pRegistryPath );
|
||||
|
||||
int nListenerCount = s_UserSettingsChangedListeners.Count();
|
||||
for( int i=nListenerCount - 1; i>=0 ; i-- )
|
||||
{
|
||||
s_UserSettingsChangedListeners[ i ]->OnUserSettingsChanged( pMessage );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CDmeUserSettings::SetAttributeForRegistryPathInDatabase( CDmAttribute *pAttribute, const char *pRegistryPath )
|
||||
{
|
||||
s_RegistryPathToAttribute.InsertOrReplace( pRegistryPath, pAttribute );
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeUserSettings::FindAttributeForRegistryPath( const char *pRegistryPath )
|
||||
{
|
||||
int nIndex = s_RegistryPathToAttribute.Find( pRegistryPath );
|
||||
if( s_RegistryPathToAttribute.IsValidIndex( nIndex ) )
|
||||
{
|
||||
return s_RegistryPathToAttribute.Element( nIndex );
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char *CDmeUserSettings::FindRegistryPathForAttribute( CDmAttribute *pAttribute )
|
||||
{
|
||||
const char *pReturnValue = NULL;
|
||||
for ( int i = s_RegistryPathToAttribute.FirstInorder(); i != s_RegistryPathToAttribute.InvalidIndex(); i = s_RegistryPathToAttribute.NextInorder( i ) )
|
||||
{
|
||||
CDmAttribute *pCurrentAttribute = s_RegistryPathToAttribute[i];
|
||||
if( pCurrentAttribute == pAttribute )
|
||||
{
|
||||
pReturnValue = s_RegistryPathToAttribute.Key( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pReturnValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CDmeUserSettings::GetAttributeNameFromRegistryPath( const char *pRegistryPath, char *pAttributeName, int nAttributeNameLength )
|
||||
{
|
||||
CUtlVector<char*, CUtlMemory<char*, int> > attributeStrings;
|
||||
V_SplitString( pRegistryPath, "\\", attributeStrings );
|
||||
Q_snprintf( pAttributeName, nAttributeNameLength, "%s", attributeStrings.Tail());
|
||||
attributeStrings.PurgeAndDeleteElements();
|
||||
}
|
||||
|
||||
CDmeUserSettings *CDmeUserSettings::GetUserSettingsForRegistryPath( const char *pRegistryPath )
|
||||
{
|
||||
CDmeUserSettings *pReturnSettings = this;
|
||||
CDmeUserSettings *pCurrentSettings = this;
|
||||
CUtlVector<char*, CUtlMemory<char*, int> > attributeStrings;
|
||||
V_SplitString( pRegistryPath, "\\", attributeStrings );
|
||||
|
||||
if( attributeStrings.Count() > 1 )
|
||||
{
|
||||
for( int i = 0; i < attributeStrings.Count() - 1; i++ )
|
||||
{
|
||||
const char *currentName = attributeStrings[i];
|
||||
pCurrentSettings = pReturnSettings->GetValueElement< CDmeUserSettings >(currentName );
|
||||
if( !pCurrentSettings )
|
||||
{
|
||||
pCurrentSettings = CreateElement< CDmeUserSettings >( currentName, pReturnSettings->GetFileId() );
|
||||
pReturnSettings->SetValue( currentName, pCurrentSettings, true );
|
||||
}
|
||||
pReturnSettings = pCurrentSettings;
|
||||
}
|
||||
}
|
||||
|
||||
attributeStrings.PurgeAndDeleteElements();
|
||||
|
||||
return pReturnSettings;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool CDmeUserSettings::RegistryPathHasValue( const char *pRegistryPath )
|
||||
{
|
||||
char pValueString[1024] = "";
|
||||
bool bKeyIsAvailable = GetRegistryString( pRegistryPath, pValueString, sizeof( pValueString ) );
|
||||
return bKeyIsAvailable;
|
||||
}
|
||||
|
||||
void CDmeUserSettings::SetAttributeFromRegistry( CDmAttribute *pAttribute, const char *pRegistryPath )
|
||||
{
|
||||
char pValueString[1024];
|
||||
GetRegistryString( pRegistryPath, pValueString, sizeof( pValueString ) );
|
||||
pAttribute->SetValueFromString( pValueString );
|
||||
}
|
||||
|
||||
void CDmeUserSettings::SetRegistryFromAttribute( CDmAttribute *pAttribute, const char *pRegistryPath )
|
||||
{
|
||||
char pValueString[1024];
|
||||
pAttribute->GetValueAsString( pValueString, sizeof( pValueString ) );
|
||||
SetRegistryString( pRegistryPath, pValueString );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [10/23/2009 Stefan] Replace the following methods by something in tierX when it is available
|
||||
|
||||
void CDmeUserSettings::CreateRegistryEntryAndValueKey( const char *pRegistryPath, char *pEntryKey, int nEntryKeyLength, char *pValueKey, int nValueKeyLength )
|
||||
{
|
||||
char pFullPath[1024];
|
||||
|
||||
V_snprintf(
|
||||
pFullPath,
|
||||
sizeof(pFullPath),
|
||||
"Software\\Valve\\SourceFilmMaker\\%s",
|
||||
pRegistryPath );
|
||||
|
||||
int nFullPathLength = V_strlen( pFullPath );
|
||||
int nSplitPosition = -1;
|
||||
for( int i = nFullPathLength - 1; i >= 0; i-- )
|
||||
{
|
||||
if( pFullPath[i]=='\\')
|
||||
{
|
||||
nSplitPosition = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( nSplitPosition >= 0 && nSplitPosition < nFullPathLength )
|
||||
{
|
||||
V_StrRight( pFullPath, nFullPathLength - nSplitPosition, pValueKey, nValueKeyLength );
|
||||
V_StrLeft( pFullPath, nSplitPosition, pEntryKey, nEntryKeyLength );
|
||||
}
|
||||
else
|
||||
{
|
||||
V_snprintf( pEntryKey, nEntryKeyLength, "%s", pFullPath );
|
||||
V_snprintf( pValueKey, nValueKeyLength, "" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CDmeUserSettings::SetRegistryString(const char *pRegistryPath, const char *pStringValue)
|
||||
{
|
||||
#ifndef _X360
|
||||
HKEY hKey;
|
||||
HKEY hSlot = HKEY_CURRENT_USER;
|
||||
|
||||
char pEntryKey[1024];
|
||||
char pValueKey[1024];
|
||||
CreateRegistryEntryAndValueKey( pRegistryPath, pEntryKey, sizeof( pEntryKey), pValueKey, sizeof( pValueKey ) );
|
||||
|
||||
if ( RegCreateKeyEx( hSlot, pEntryKey ,NULL, NULL, REG_OPTION_NON_VOLATILE, pStringValue ? KEY_WRITE : KEY_ALL_ACCESS, NULL, &hKey , NULL) != ERROR_SUCCESS )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( RegSetValueEx( hKey, pValueKey, NULL, REG_SZ, (unsigned char *)pStringValue, strlen(pStringValue) + 1 ) == ERROR_SUCCESS )
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDmeUserSettings::GetRegistryString(const char *pRegistryPath, char *pStringValue, int nStringValueLen)
|
||||
{
|
||||
#ifndef _X360
|
||||
pStringValue[0] = 0;
|
||||
|
||||
HKEY hKey;
|
||||
HKEY hSlot = HKEY_CURRENT_USER;
|
||||
|
||||
char pEntryKey[1024];
|
||||
char pValueKey[1024];
|
||||
CreateRegistryEntryAndValueKey( pRegistryPath, pEntryKey, sizeof( pEntryKey), pValueKey, sizeof( pValueKey ) );
|
||||
|
||||
if ( RegOpenKeyEx( hSlot, pEntryKey, NULL, KEY_READ, &hKey ) != ERROR_SUCCESS )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long len = nStringValueLen;
|
||||
if ( RegQueryValueEx( hKey, pValueKey, NULL, NULL, (unsigned char *)pStringValue, &len ) == ERROR_SUCCESS )
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
1220
movieobjects/dmevertexdata.cpp
Normal file
1220
movieobjects/dmevertexdata.cpp
Normal file
File diff suppressed because it is too large
Load Diff
480
movieobjects/dmmeshcomp.cpp
Normal file
480
movieobjects/dmmeshcomp.cpp
Normal file
@@ -0,0 +1,480 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Implementation of CDmMeshComp - CDmeMesh computation class
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
// Valve includes
|
||||
#include "movieobjects/dmmeshcomp.h"
|
||||
#include "movieobjects/dmefaceset.h"
|
||||
#include "movieobjects/dmemesh.h"
|
||||
#include "movieobjects/dmevertexdata.h"
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//=============================================================================
|
||||
CDmMeshComp::CDmMeshComp( CDmeMesh *pMesh, CDmeVertexData *pPassedBase )
|
||||
: m_pMesh( pMesh )
|
||||
, m_pBase( NULL )
|
||||
{
|
||||
m_pBase = pPassedBase ? pPassedBase : pMesh->GetCurrentBaseState();
|
||||
if ( !m_pBase )
|
||||
return;
|
||||
|
||||
const FieldIndex_t pIndex( m_pBase->FindFieldIndex( CDmeVertexData::FIELD_POSITION ) );
|
||||
if ( pIndex < 0 )
|
||||
return;
|
||||
|
||||
const CUtlVector< Vector > &pPositionData( m_pBase->GetPositionData() );
|
||||
const CUtlVector<int> &pPositionIndices( m_pBase->GetVertexIndexData( CDmeVertexData::FIELD_POSITION ) );
|
||||
|
||||
const int nVertices( pPositionData.Count() );
|
||||
if ( nVertices <= 0 )
|
||||
return;
|
||||
|
||||
// Create vertices
|
||||
// TODO: check for duplicates in pPositionData - that would break this algorithm
|
||||
m_verts.EnsureCapacity( nVertices );
|
||||
for ( int i = 0; i < nVertices; ++i )
|
||||
{
|
||||
const CUtlVector< int > &vertexIndices = m_pBase->FindVertexIndicesFromDataIndex( CDmeVertexData::FIELD_POSITION, i );
|
||||
m_verts.AddToTail( new CVert( i, &vertexIndices, &pPositionData[ i ] ) );
|
||||
}
|
||||
|
||||
// Create edges and faces
|
||||
const int nFaceSets( pMesh->FaceSetCount() );
|
||||
for ( int i = 0; i < nFaceSets; ++i )
|
||||
{
|
||||
CDmeFaceSet *pFaceSet( pMesh->GetFaceSet( i ) );
|
||||
const int nIndices( pFaceSet->NumIndices() );
|
||||
if ( nIndices < 4 ) // At least a triangle and a -1
|
||||
continue;
|
||||
|
||||
m_faces.EnsureCapacity( m_faces.Count() + nIndices / 4 ); // # new faces <= nIndices/4 (tri + -1)
|
||||
m_edges.EnsureCapacity( m_edges.Count() + nIndices / 2 ); // # new edges <= 2*new faces
|
||||
|
||||
int facePosIndex( -1 );
|
||||
int edgePosIndex0( -1 );
|
||||
int edgePosIndex1( -1 );
|
||||
|
||||
CUtlVector< CVert * > verts;
|
||||
CUtlVector< CEdge * > edges;
|
||||
CUtlVector< bool > edgeReverseMap;
|
||||
bool bReverse = false;
|
||||
|
||||
for ( int j( 0 ); j < nIndices; ++j )
|
||||
{
|
||||
const int faceVertexIndex( pFaceSet->GetIndex( j ) );
|
||||
|
||||
if ( faceVertexIndex < 0 )
|
||||
{
|
||||
// End of face
|
||||
edgePosIndex0 = edgePosIndex1;
|
||||
edgePosIndex1 = facePosIndex;
|
||||
|
||||
Assert( edgePosIndex0 >= 0 );
|
||||
Assert( edgePosIndex1 >= 0 );
|
||||
|
||||
edges.AddToTail( FindOrCreateEdge( edgePosIndex0, edgePosIndex1, &bReverse ) );
|
||||
edgeReverseMap.AddToTail( bReverse );
|
||||
|
||||
CreateFace( verts, edges, edgeReverseMap );
|
||||
|
||||
facePosIndex = -1;
|
||||
verts.RemoveAll();
|
||||
edges.RemoveAll();
|
||||
edgeReverseMap.RemoveAll();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( facePosIndex < 0 )
|
||||
{
|
||||
// First vertex
|
||||
facePosIndex = pPositionIndices[ faceVertexIndex ];
|
||||
edgePosIndex1 = facePosIndex;
|
||||
verts.AddToTail( m_verts[ edgePosIndex1 ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2nd through last vertex
|
||||
edgePosIndex0 = edgePosIndex1;
|
||||
edgePosIndex1 = pPositionIndices[ faceVertexIndex ];
|
||||
verts.AddToTail( m_verts[ edgePosIndex1 ] );
|
||||
|
||||
Assert( edgePosIndex0 >= 0 );
|
||||
Assert( edgePosIndex1 >= 0 );
|
||||
|
||||
edges.AddToTail( FindOrCreateEdge( edgePosIndex0, edgePosIndex1, &bReverse ) );
|
||||
edgeReverseMap.AddToTail( bReverse );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::~CDmMeshComp()
|
||||
{
|
||||
m_verts.PurgeAndDeleteElements();
|
||||
m_edges.PurgeAndDeleteElements();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CVert::CVert( int nPositionIndex, const CUtlVector< int > *pVertexIndices, const Vector *pPosition )
|
||||
: m_positionIndex( nPositionIndex )
|
||||
, m_pVertexIndices( pVertexIndices )
|
||||
, m_pPosition( pPosition )
|
||||
, m_edges( 8, 8 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CVert::CVert( const CVert &src )
|
||||
: m_positionIndex( src.m_positionIndex )
|
||||
, m_pVertexIndices( src.m_pVertexIndices )
|
||||
, m_pPosition( src.m_pPosition )
|
||||
, m_edges( 8, 8 )
|
||||
{
|
||||
m_edges.AddMultipleToTail( src.m_edges.Count(), src.m_edges.Base() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmMeshComp::CVert::PositionIndex() const
|
||||
{
|
||||
return m_positionIndex;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector *CDmMeshComp::CVert::Position() const
|
||||
{
|
||||
return m_pPosition;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
const CUtlVector< int > *CDmMeshComp::CVert::VertexIndices() const
|
||||
{
|
||||
return m_pVertexIndices;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmMeshComp::CVert::operator==( const CVert &rhs ) const
|
||||
{
|
||||
return ( m_pPosition->DistToSqr( *rhs.m_pPosition ) < FLT_EPSILON );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CEdge::CEdge()
|
||||
: m_pVert0( NULL )
|
||||
, m_pVert1( NULL )
|
||||
, m_faceCount( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the vertex position index given the edge relative vertex index
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmMeshComp::CEdge::GetVertPositionIndex( int edgeRelativeVertexIndex ) const
|
||||
{
|
||||
if ( edgeRelativeVertexIndex == 0 && m_pVert0 )
|
||||
return m_pVert0->PositionIndex();
|
||||
|
||||
if ( edgeRelativeVertexIndex == 1 && m_pVert1 )
|
||||
return m_pVert1->PositionIndex();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CVert *CDmMeshComp::CEdge::GetVert( int edgeRelativeVertexIndex ) const
|
||||
{
|
||||
if ( edgeRelativeVertexIndex == 0 )
|
||||
return m_pVert0;
|
||||
|
||||
if ( edgeRelativeVertexIndex == 1 )
|
||||
return m_pVert1;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the edge starts and stops at the same position in space
|
||||
// The order of the vertices is not checked
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmMeshComp::CEdge::operator==( const CEdge &rhs ) const
|
||||
{
|
||||
return (
|
||||
( *m_pVert0 == *rhs.m_pVert0 && *m_pVert1 == *rhs.m_pVert1 ) ||
|
||||
( *m_pVert0 == *rhs.m_pVert1 && *m_pVert1 == *rhs.m_pVert0 ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
Vector CDmMeshComp::CEdge::EdgeVector() const
|
||||
{
|
||||
if ( m_pVert0 && m_pVert1 )
|
||||
return *m_pVert1->Position() - *m_pVert0->Position();
|
||||
|
||||
return vec3_origin;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds or Creates an edge... Can still return NULL if vertices do not exist
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CEdge *CDmMeshComp::FindOrCreateEdge( int vIndex0, int vIndex1, bool *pReverse /* = NULL */ )
|
||||
{
|
||||
CEdge *pEdge = FindEdge( vIndex0, vIndex1, pReverse );
|
||||
if ( pEdge )
|
||||
return pEdge;
|
||||
|
||||
CVert *pVert0 = m_verts[ vIndex0 ];
|
||||
if ( pVert0 == NULL )
|
||||
return NULL;
|
||||
|
||||
CVert *pVert1 = m_verts[ vIndex1 ];
|
||||
if ( pVert1 == NULL )
|
||||
return NULL;
|
||||
|
||||
pEdge = m_edges[ m_edges.AddToTail( new CEdge() ) ];
|
||||
pEdge->m_pVert0 = pVert0;
|
||||
pEdge->m_pVert1 = pVert1;
|
||||
pVert0->m_edges.AddToTail( pEdge );
|
||||
if ( vIndex0 != vIndex1 )
|
||||
pVert1->m_edges.AddToTail( pEdge );
|
||||
|
||||
if ( pReverse )
|
||||
{
|
||||
*pReverse = false;
|
||||
}
|
||||
|
||||
return pEdge;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the edge between vIndex0 & vIndex1 (or vice versa), NULL if not found
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CEdge *CDmMeshComp::FindEdge( int vIndex0, int vIndex1, bool *pReverse /* = NULL */ )
|
||||
{
|
||||
CUtlVector< CEdge * > &edges = m_verts[ vIndex0 ]->m_edges;
|
||||
for ( int i = 0; i < edges.Count(); i++ )
|
||||
{
|
||||
CEdge *e = edges[ i ];
|
||||
|
||||
if ( e->GetVertPositionIndex( 0 ) == vIndex0 && e->GetVertPositionIndex( 1 ) == vIndex1 )
|
||||
{
|
||||
if ( pReverse )
|
||||
{
|
||||
*pReverse = false;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
if ( e->GetVertPositionIndex( 1 ) == vIndex0 && e->GetVertPositionIndex( 0 ) == vIndex1 )
|
||||
{
|
||||
if ( pReverse )
|
||||
{
|
||||
*pReverse = true;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmMeshComp::CFace *CDmMeshComp::CreateFace( const CUtlVector< CVert * > &verts, const CUtlVector< CEdge * > &edges, const CUtlVector< bool > &edgeReverseMap )
|
||||
{
|
||||
CFace *pFace = &m_faces[ m_faces.AddToTail() ];
|
||||
|
||||
pFace->m_verts.RemoveAll();
|
||||
pFace->m_verts.AddVectorToTail( verts );
|
||||
|
||||
pFace->m_edges.RemoveAll();
|
||||
pFace->m_edges.AddVectorToTail( edges );
|
||||
|
||||
pFace->m_edgeReverseMap.RemoveAll();
|
||||
pFace->m_edgeReverseMap.AddVectorToTail( edgeReverseMap );
|
||||
|
||||
for ( int nEdgeIndex = edges.Count() - 1; nEdgeIndex >= 0; --nEdgeIndex )
|
||||
{
|
||||
edges[ nEdgeIndex ]->m_faceCount += 1;
|
||||
}
|
||||
|
||||
return pFace;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmMeshComp::FindFacesWithVert( int vIndex, CUtlVector< CFace * > &faces )
|
||||
{
|
||||
// TODO: optimize this by adding a vector of face pointers to each vertex
|
||||
faces.RemoveAll();
|
||||
|
||||
for ( intp fi( m_faces.Head() ); fi != m_faces.InvalidIndex(); fi = m_faces.Next( fi ) )
|
||||
{
|
||||
CFace &face( m_faces[ fi ] );
|
||||
for ( int i = 0; i < face.m_verts.Count(); ++i )
|
||||
{
|
||||
if ( face.m_verts[ i ]->PositionIndex() == vIndex )
|
||||
{
|
||||
faces.AddToTail( &face );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return faces.Count();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmMeshComp::FindNeighbouringVerts( int vIndex, CUtlVector< CVert * > &verts )
|
||||
{
|
||||
verts.RemoveAll();
|
||||
|
||||
const CUtlVector< CEdge * > & edges = m_verts[ vIndex ]->m_edges;
|
||||
|
||||
for ( int i = 0; i < edges.Count(); ++i )
|
||||
{
|
||||
CEdge *e = edges[ i ];
|
||||
if ( e->GetVertPositionIndex( 0 ) == vIndex )
|
||||
{
|
||||
verts.AddToTail( e->GetVert( 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
verts.AddToTail( e->GetVert( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
return verts.Count();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find all edges that are only used by 1 face
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmMeshComp::GetBorderEdges( CUtlVector< CUtlVector< CEdge * > > &borderEdgesList )
|
||||
{
|
||||
// TODO: optimize this by stepping from edge to edge to build chains, using CVert::m_edges
|
||||
int retVal = 0;
|
||||
|
||||
borderEdgesList.RemoveAll();
|
||||
|
||||
bool connected;
|
||||
|
||||
for ( int ei = 0; ei < m_edges.Count(); ei++ )
|
||||
{
|
||||
CEdge *pEdge = m_edges[ ei ];
|
||||
if ( pEdge->IsBorderEdge() )
|
||||
{
|
||||
++retVal;
|
||||
connected = false;
|
||||
|
||||
for ( int i = borderEdgesList.Count() - 1; !connected && i >= 0; --i )
|
||||
{
|
||||
CUtlVector< CEdge * > &borderEdges = borderEdgesList[ i ];
|
||||
for ( int j = borderEdges.Count() - 1; j >= 0; --j )
|
||||
{
|
||||
if ( borderEdges[ j ]->ConnectedTo( pEdge ) )
|
||||
{
|
||||
borderEdges.AddToTail( pEdge );
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !connected )
|
||||
{
|
||||
CUtlVector< CEdge * > &borderEdges = borderEdgesList[ borderEdgesList.AddToTail() ];
|
||||
borderEdges.AddToTail( pEdge );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shrink the borderEdgesList to minimum number required
|
||||
|
||||
bool anyConnected = false;
|
||||
do
|
||||
{
|
||||
anyConnected = false;
|
||||
|
||||
for ( int i = borderEdgesList.Count() - 1; i >= 0; --i )
|
||||
{
|
||||
CUtlVector< CEdge * > &srcBorderEdges = borderEdgesList[ i ];
|
||||
for ( int j = srcBorderEdges.Count() - 1; j >= 0; --j )
|
||||
{
|
||||
CEdge *pSrcEdge = srcBorderEdges[ j ];
|
||||
connected = false;
|
||||
|
||||
for ( int k = 0; !connected && k < i; ++k )
|
||||
{
|
||||
CUtlVector< CEdge * > &dstBorderEdges = borderEdgesList[ k ];
|
||||
for ( int l = dstBorderEdges.Count() - 1; l >= 0; --l )
|
||||
{
|
||||
if ( dstBorderEdges[ l ]->ConnectedTo( pSrcEdge ) )
|
||||
{
|
||||
connected = true;
|
||||
anyConnected = true;
|
||||
dstBorderEdges.AddToTail( pSrcEdge );
|
||||
srcBorderEdges.Remove( j );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( srcBorderEdges.Count() == 0 )
|
||||
{
|
||||
borderEdgesList.Remove( i );
|
||||
}
|
||||
}
|
||||
} while( anyConnected );
|
||||
|
||||
return retVal;
|
||||
}
|
||||
1462
movieobjects/dmobjserializer.cpp
Normal file
1462
movieobjects/dmobjserializer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
235
movieobjects/exportfacialanimation.cpp
Normal file
235
movieobjects/exportfacialanimation.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// A class representing session state for the SFM
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "movieobjects/exportfacialanimation.h"
|
||||
#include "movieobjects/dmeclip.h"
|
||||
#include "movieobjects/dmeanimationset.h"
|
||||
#include "movieobjects/dmegamemodel.h"
|
||||
#include "movieobjects/dmetrackgroup.h"
|
||||
#include "movieobjects/dmetrack.h"
|
||||
#include "movieobjects/dmesound.h"
|
||||
#include "movieobjects/dmelog.h"
|
||||
#include "movieobjects/dmechannel.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains export information
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ExportInfo_t
|
||||
{
|
||||
CDmeFilmClip *m_pMovie;
|
||||
CDmeFilmClip *m_pShot;
|
||||
CDmeAnimationSet *m_pAnimationSet;
|
||||
DmeTime_t m_tExportStart;
|
||||
DmeTime_t m_tExportEnd;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to transform channel data into export time
|
||||
//-----------------------------------------------------------------------------
|
||||
static void ComputeExportChannelScaleBias( double *pScale, DmeTime_t *pBias, ExportInfo_t &info, CDmeChannel *pChannel )
|
||||
{
|
||||
DmeClipStack_t channelToGlobal;
|
||||
if ( pChannel->BuildClipStack( &channelToGlobal, info.m_pMovie, info.m_pShot ) )
|
||||
{
|
||||
DmeTime_t tOffset = channelToGlobal.FromChildMediaTime( DMETIME_ZERO, false );
|
||||
DmeTime_t tScale = channelToGlobal.FromChildMediaTime( DmeTime_t( 1.0f ), false );
|
||||
*pBias = tOffset - info.m_pShot->GetStartTime();
|
||||
*pScale = ( tScale - tOffset ).GetSeconds();
|
||||
}
|
||||
}
|
||||
|
||||
static void GetExportTimeRange( DmeTime_t *pExportStart, DmeTime_t *pExportEnd, CDmeFilmClip *pShot )
|
||||
{
|
||||
*pExportStart = DMETIME_ZERO;
|
||||
*pExportEnd = pShot->GetDuration();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds a log layer to the list of logs for export
|
||||
//-----------------------------------------------------------------------------
|
||||
static void AddLogLayerForExport( ExportInfo_t &info, CDmElement *pRoot, const char *pControlName, CDmeChannel *pChannel )
|
||||
{
|
||||
CDmeLog *pLog = pChannel->GetLog();
|
||||
if ( !pLog || pLog->GetNumLayers() == 0 )
|
||||
return;
|
||||
|
||||
CDmrElementArray<> animations( pRoot, "animations" );
|
||||
|
||||
DmeTime_t tBias;
|
||||
double flScale;
|
||||
ComputeExportChannelScaleBias( &flScale, &tBias, info, pChannel );
|
||||
|
||||
// Only export the base layer
|
||||
CDmeLogLayer* pLogLayer = pLog->GetLayer( 0 )->Copy();
|
||||
pLogLayer->SetName( pControlName );
|
||||
pLogLayer->ScaleBiasKeyTimes( flScale, tBias );
|
||||
|
||||
// Forcibly add keys @ the start + end time
|
||||
DmeTime_t tStartTime = ( info.m_tExportStart - tBias ) / flScale;
|
||||
DmeTime_t tEndTime = ( info.m_tExportEnd - tBias ) / flScale;
|
||||
pLogLayer->InsertKeyFromLayer( info.m_tExportStart, pLog->GetLayer(0), tStartTime );
|
||||
pLogLayer->InsertKeyFromLayer( info.m_tExportEnd, pLog->GetLayer(0), tEndTime );
|
||||
|
||||
pLogLayer->RemoveKeysOutsideRange( info.m_tExportStart, info.m_tExportEnd );
|
||||
animations.AddToTail( pLogLayer );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports animations
|
||||
//-----------------------------------------------------------------------------
|
||||
static void ExportAnimations( ExportInfo_t &info, CDmElement *pRoot )
|
||||
{
|
||||
CDmrElementArray<> animations( pRoot, "animations", true );
|
||||
|
||||
// Build a list of all controls
|
||||
const CDmaElementArray< CDmElement > &controls = info.m_pAnimationSet->GetControls();
|
||||
int nControlCount = controls.Count();
|
||||
for ( int i = 0; i < nControlCount; ++i )
|
||||
{
|
||||
CDmElement *pControl = controls[i];
|
||||
if ( !pControl || IsTransformControl( pControl ) )
|
||||
continue;
|
||||
|
||||
bool bIsStereo = IsStereoControl( pControl );
|
||||
if ( bIsStereo )
|
||||
{
|
||||
char pControlName[512];
|
||||
Q_snprintf( pControlName, sizeof(pControlName), "left_%s", pControl->GetName() );
|
||||
CDmeChannel *pLeftChannel = pControl->GetValueElement<CDmeChannel>( "leftvaluechannel" );
|
||||
AddLogLayerForExport( info, pRoot, pControlName, pLeftChannel );
|
||||
|
||||
Q_snprintf( pControlName, sizeof(pControlName), "right_%s", pControl->GetName() );
|
||||
CDmeChannel *pRightChannel = pControl->GetValueElement<CDmeChannel>( "leftvaluechannel" );
|
||||
AddLogLayerForExport( info, pRoot, pControlName, pRightChannel );
|
||||
}
|
||||
else
|
||||
{
|
||||
CDmeChannel *pChannel = pControl->GetValueElement<CDmeChannel>( "channel" );
|
||||
AddLogLayerForExport( info, pRoot, pControl->GetName(), pChannel );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper to export sounds
|
||||
//-----------------------------------------------------------------------------
|
||||
static void ExportSounds( ExportInfo_t &info, CDmElement *pRoot, CDmeClip *pClip, DmeTime_t tOffset )
|
||||
{
|
||||
CDmrElementArray<> sounds( pRoot, "sounds", true );
|
||||
|
||||
DmeClipStack_t soundToGlobal;
|
||||
int gc = pClip->GetTrackGroupCount();
|
||||
for ( int i = 0; i < gc; ++i )
|
||||
{
|
||||
CDmeTrackGroup *pTrackGroup = pClip->GetTrackGroup( i );
|
||||
DMETRACKGROUP_FOREACH_CLIP_TYPE_START( CDmeSoundClip, pTrackGroup, pTrack, pSoundClip )
|
||||
|
||||
const char *pGameSoundName = pSoundClip->m_Sound->m_GameSoundName;
|
||||
if ( !pGameSoundName || !pGameSoundName[0] )
|
||||
continue;
|
||||
|
||||
if ( pSoundClip->IsMute() )
|
||||
continue;
|
||||
|
||||
if ( !pSoundClip->BuildClipStack( &soundToGlobal, info.m_pMovie, pClip ) )
|
||||
continue;
|
||||
|
||||
DmeTime_t tStart = soundToGlobal.FromChildMediaTime( DMETIME_ZERO, false );
|
||||
DmeTime_t tEnd = soundToGlobal.FromChildMediaTime( pSoundClip->GetDuration(), false );
|
||||
tStart -= tOffset;
|
||||
tEnd -= tOffset;
|
||||
if ( tStart >= info.m_tExportEnd || tEnd <= info.m_tExportStart )
|
||||
continue;
|
||||
|
||||
const char *pName = pSoundClip->GetName();
|
||||
CDmElement *pSoundEvent = CreateElement<CDmElement>( pName, pRoot->GetFileId() );
|
||||
pSoundEvent->SetValue( "start", tStart );
|
||||
pSoundEvent->SetValue( "end", tEnd );
|
||||
pSoundEvent->SetValue( "gamesound", pGameSoundName );
|
||||
sounds.AddToTail( pSoundEvent );
|
||||
|
||||
DMETRACKGROUP_FOREACH_CLIP_TYPE_END()
|
||||
}
|
||||
}
|
||||
|
||||
static void ExportSounds_R( ExportInfo_t &info, CDmElement *pRoot, CDmeClip *pClip, DmeTime_t tOffset )
|
||||
{
|
||||
ExportSounds( info, pRoot, pClip, tOffset );
|
||||
|
||||
// Recurse
|
||||
DmeClipStack_t childToGlobal;
|
||||
int gc = pClip->GetTrackGroupCount();
|
||||
for ( int i = 0; i < gc; ++i )
|
||||
{
|
||||
CDmeTrackGroup *pTrackGroup = pClip->GetTrackGroup( i );
|
||||
DMETRACKGROUP_FOREACH_CLIP_START( pTrackGroup, pTrack, pChild )
|
||||
|
||||
if ( !pChild->BuildClipStack( &childToGlobal, info.m_pMovie, pClip ) )
|
||||
continue;
|
||||
|
||||
DmeTime_t tStart = childToGlobal.FromChildMediaTime( DMETIME_ZERO, false );
|
||||
DmeTime_t tEnd = childToGlobal.FromChildMediaTime( pChild->GetDuration(), false );
|
||||
tStart -= tOffset;
|
||||
tEnd -= tOffset;
|
||||
if ( tStart >= info.m_tExportEnd || tEnd <= info.m_tExportStart )
|
||||
continue;
|
||||
|
||||
ExportSounds_R( info, pRoot, pChild, tOffset );
|
||||
|
||||
DMETRACKGROUP_FOREACH_CLIP_END()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports sounds, default implementation
|
||||
//-----------------------------------------------------------------------------
|
||||
static void ExportSounds( ExportInfo_t &info, CDmElement *pRoot )
|
||||
{
|
||||
DmeTime_t tOffset = info.m_pShot->GetStartTime();
|
||||
ExportSounds( info, pRoot, info.m_pMovie, tOffset );
|
||||
ExportSounds_R( info, pRoot, info.m_pShot, tOffset );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports an .fac file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ExportFacialAnimation( const char *pFileName, CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CDmeAnimationSet *pAnimationSet )
|
||||
{
|
||||
if ( !pMovie || !pShot || !pAnimationSet )
|
||||
return false;
|
||||
|
||||
const char *pFileFormat = "facial_animation";
|
||||
CDmElement *pRoot = CreateElement< CDmElement >( pAnimationSet->GetName(), DMFILEID_INVALID );
|
||||
|
||||
ExportInfo_t info;
|
||||
info.m_pMovie = pMovie;
|
||||
info.m_pShot = pShot;
|
||||
info.m_pAnimationSet = pAnimationSet;
|
||||
GetExportTimeRange( &info.m_tExportStart, &info.m_tExportEnd, pShot );
|
||||
|
||||
CDmeGameModel *pGameModel = pAnimationSet->GetValueElement<CDmeGameModel>( "gameModel" );
|
||||
if ( pGameModel )
|
||||
{
|
||||
pRoot->SetValue( "gamemodel", pGameModel->GetModelName() );
|
||||
}
|
||||
ExportAnimations( info, pRoot );
|
||||
ExportSounds( info, pRoot );
|
||||
|
||||
pRoot->SetFileId( DMFILEID_INVALID, TD_DEEP );
|
||||
const char *pEncoding = "keyvalues2_flat";
|
||||
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pEncoding, pFileFormat, pRoot );
|
||||
DestroyElement( pRoot, TD_DEEP );
|
||||
return bOk;
|
||||
}
|
||||
|
||||
|
||||
173
movieobjects/movieobjects.vpc
Normal file
173
movieobjects/movieobjects.vpc
Normal file
@@ -0,0 +1,173 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// MOVIEOBJECTS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR ".."
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$PreprocessorDefinitions "$BASE;MOVIEOBJECTS_LIB"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "Movieobjects"
|
||||
{
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "movieobjects_interfaces.h"
|
||||
}
|
||||
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "dmeanimationlist.cpp"
|
||||
$File "dmeanimationset.cpp"
|
||||
$File "dmeattachment.cpp"
|
||||
$File "dmeattributereference.cpp"
|
||||
$File "dmebookmark.cpp"
|
||||
$File "dmecamera.cpp"
|
||||
$File "dmechannel.cpp"
|
||||
$File "dmeclip.cpp"
|
||||
$File "dmecombinationoperator.cpp"
|
||||
$File "dmeconnectionoperator.cpp"
|
||||
$File "dmecontrolgroup.cpp"
|
||||
$File "dmedag.cpp"
|
||||
$File "dmedccmakefile.cpp"
|
||||
$File "dmeeditortypedictionary.cpp"
|
||||
$File "dmeexpressionoperator.cpp"
|
||||
$File "dmefaceset.cpp"
|
||||
$File "dmegamemodel.cpp"
|
||||
$File "dmeinput.cpp"
|
||||
$File "dmejoint.cpp"
|
||||
$File "dmekeyboardinput.cpp"
|
||||
$File "dmelight.cpp"
|
||||
$File "dmelog.cpp"
|
||||
$File "dmemakefile.cpp"
|
||||
$File "dmemakefileutils.cpp"
|
||||
$File "dmematerial.cpp"
|
||||
$File "dmematerialoverlayfxclip.cpp"
|
||||
$File "dmemdl.cpp"
|
||||
$File "dmemdlmakefile.cpp"
|
||||
$File "dmemesh.cpp"
|
||||
$File "dmemodel.cpp"
|
||||
$File "dmemorphoperator.cpp"
|
||||
$File "dmemouseinput.cpp"
|
||||
$File "dmeoperator.cpp"
|
||||
$File "dmepackoperators.cpp"
|
||||
$File "dmeparticlesystemdefinition.cpp"
|
||||
$File "dmephonememapping.cpp"
|
||||
$File "dmerighandle.cpp"
|
||||
$File "dmerigconstraintoperators.cpp"
|
||||
$File "dmerig.cpp"
|
||||
$File "dmeselection.cpp"
|
||||
$File "dmeshape.cpp"
|
||||
$File "dmesound.cpp"
|
||||
$File "dmetimeframe.cpp"
|
||||
$File "dmetimeselection.cpp"
|
||||
$File "dmetrack.cpp"
|
||||
$File "dmetrackgroup.cpp"
|
||||
$File "dmetransform.cpp"
|
||||
$File "dmetransformcontrol.cpp"
|
||||
$File "dmetransforminput.cpp"
|
||||
$File "dmetransformlist.cpp"
|
||||
$File "dmetransformoperator.cpp"
|
||||
$File "dmeunpackoperators.cpp"
|
||||
$File "dmeusersettings.cpp"
|
||||
$File "dmevertexdata.cpp"
|
||||
$File "dmobjserializer.cpp"
|
||||
$File "movieobjects_interfaces.cpp"
|
||||
$File "dmedrawsettings.cpp"
|
||||
$File "dmmeshcomp.cpp"
|
||||
$File "dmeoverlay.cpp"
|
||||
$File "exportfacialanimation.cpp"
|
||||
$File "dmeflexrules.cpp"
|
||||
$File "dmeaxissystem.cpp"
|
||||
$File "dmeexporttags.cpp"
|
||||
}
|
||||
|
||||
$Folder "Interface"
|
||||
{
|
||||
$File "$SRCDIR\public\movieobjects\animsetattributevalue.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeanimationlist.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeanimationset.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeattributereference.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmebookmark.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmecamera.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmechannel.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeclip.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmecombinationoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeconnectionoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmecontrolgroup.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmedag.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmedccmakefile.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeexpressionoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmefaceset.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmegamemodel.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeinput.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmejoint.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmekeyboardinput.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmelight.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmelog.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemakefile.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemakefileutils.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmematerial.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemdl.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemdlmakefile.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemesh.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemodel.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemorphoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmemouseinput.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmepackoperators.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmephonememapping.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmerighandle.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmerigconstraintoperators.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmerig.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeselection.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeshape.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmesound.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetestmesh.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetimeframe.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetimeselection.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetimeselectiontimes.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetrack.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetrackgroup.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetransform.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetransformcontrol.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetransforminput.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetransformlist.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmetransformoperator.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeusersettings.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeunpackoperators.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmevertexdata.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmobjserializer.h"
|
||||
$File "$SRCDIR\public\movieobjects\idmemakefileutils.h"
|
||||
$File "$SRCDIR\public\movieobjects\idmeusersettingschangedlistener.h"
|
||||
$File "$SRCDIR\public\movieobjects\movieobjects.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeattachment.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeeditortypedictionary.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeparticlesystemdefinition.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmematerialoverlayfxclip.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmedrawsettings.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmmeshcomp.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeoverlay.h"
|
||||
$File "$SRCDIR\public\movieobjects\exportfacialanimation.h"
|
||||
$File "$SRCDIR\public\movieobjects\dmeflexrules.h"
|
||||
}
|
||||
|
||||
$Folder "external"
|
||||
{
|
||||
$File "$SRCDIR\public\bone_setup.h"
|
||||
$File "$SRCDIR\public\collisionutils.cpp"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
$File "$SRCDIR\public\phonemeconverter.cpp"
|
||||
$File "$SRCDIR\public\phonemeconverter.h"
|
||||
$File "$SRCDIR\public\studio.cpp"
|
||||
$File "$SRCDIR\public\mathlib\vector.h"
|
||||
}
|
||||
}
|
||||
13
movieobjects/movieobjects.vpc.vpc_cache
Normal file
13
movieobjects/movieobjects.vpc.vpc_cache
Normal file
@@ -0,0 +1,13 @@
|
||||
"vpc_cache"
|
||||
{
|
||||
"CacheVersion" "1"
|
||||
"win32"
|
||||
{
|
||||
"CRCFile" "movieobjects.vcxproj.vpc_crc"
|
||||
"OutputFiles"
|
||||
{
|
||||
"0" "movieobjects.vcxproj"
|
||||
"1" "movieobjects.vcxproj.filters"
|
||||
}
|
||||
}
|
||||
}
|
||||
8
movieobjects/movieobjects_interfaces.cpp
Normal file
8
movieobjects/movieobjects_interfaces.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "movieobjects_interfaces.h"
|
||||
|
||||
IGlobalFlexController *g_pGlobalFlexController = 0;
|
||||
36
movieobjects/movieobjects_interfaces.h
Normal file
36
movieobjects/movieobjects_interfaces.h
Normal file
@@ -0,0 +1,36 @@
|
||||
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef MOVIEOBJECTS_INTERFACE_H
|
||||
#define MOVIEOBJECTS_INTERFACE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// typedefs that should be in platform.h
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IGlobalFlexController;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces used by the movieobjects library
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IGlobalFlexController *g_pGlobalFlexController;
|
||||
|
||||
|
||||
#endif // MOVIEOBJECTS_INTERFACE_H
|
||||
199
movieobjects/timeutils.cpp
Normal file
199
movieobjects/timeutils.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
|
||||
#include "movieobjects/timeutils.h"
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DmeFramerate_t
|
||||
//
|
||||
// exact (rational) representation of common framerates - any integral or ntsc framerate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DmeFramerate_t::DmeFramerate_t( float fps )
|
||||
{
|
||||
SetFramerate( fps );
|
||||
}
|
||||
|
||||
DmeFramerate_t::DmeFramerate_t( int fps /*= 0*/ ) :
|
||||
m_num( fps ), m_den( 10000 )
|
||||
{
|
||||
}
|
||||
|
||||
DmeFramerate_t::DmeFramerate_t( int nNumerator, int nDenominator ) :
|
||||
m_num( nNumerator ), m_den( nDenominator * 10000 )
|
||||
{
|
||||
}
|
||||
|
||||
void DmeFramerate_t::SetFramerate( float flFrameRate )
|
||||
{
|
||||
if ( IsIntegralValue( flFrameRate ) )
|
||||
{
|
||||
SetFramerate( RoundFloatToInt( flFrameRate ) );
|
||||
}
|
||||
else if ( IsIntegralValue( flFrameRate * 1001.0f / 1000.0f ) ) // 1001 is the ntsc divisor (30*1000/1001 = 29.97, etc)
|
||||
{
|
||||
SetFramerateNTSC( RoundFloatToInt( flFrameRate * 1001.0f / 1000.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( 0 );
|
||||
SetFramerate( RoundFloatToInt( flFrameRate ) );
|
||||
}
|
||||
}
|
||||
|
||||
void DmeFramerate_t::SetFramerate( int fps )
|
||||
{
|
||||
m_num = fps;
|
||||
m_den = 10000;
|
||||
}
|
||||
|
||||
// other (uncommon) options besides 30(29.97 - ntsc video) are 24 (23.976 - ntsc film) and 60 (59.94 - ntsc progressive)
|
||||
void DmeFramerate_t::SetFramerateNTSC( int multiplier /*= 30*/ )
|
||||
{
|
||||
// ntsc = 30 fps * 1000 / 1001
|
||||
// = ( 30 / 10000 fptms ) * 1000 / 1001
|
||||
// = 30 / 10010
|
||||
m_num = multiplier;
|
||||
m_den = 10010;
|
||||
}
|
||||
|
||||
float DmeFramerate_t::GetFramesPerSecond() const
|
||||
{
|
||||
return 10000.0f * m_num / float( m_den );
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DmeTime_t
|
||||
//
|
||||
// representing time as integral tenths of a millisecond (tms)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DmeTime_t::DmeTime_t( int frame, DmeFramerate_t framerate )
|
||||
{
|
||||
__int64 num = __int64( framerate.m_num );
|
||||
__int64 prod = frame * __int64( framerate.m_den );
|
||||
// add signed offset to force integer truncation (towards 0) to give us truncation towards -inf
|
||||
if ( frame < 0 )
|
||||
{
|
||||
prod -= num - 1;
|
||||
}
|
||||
m_tms = int( prod / num ); // round tms towards 0
|
||||
}
|
||||
|
||||
|
||||
// float operators - comment these out to find potentially incorrect uses of DmeTime_t
|
||||
|
||||
DmeTime_t DmeTime_t::operator*=( float f )
|
||||
{
|
||||
m_tms = int( floor( m_tms * f + 0.5f ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
DmeTime_t DmeTime_t::operator/=( float f )
|
||||
{
|
||||
m_tms = int( floor( m_tms / f + 0.5f ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// helper methods
|
||||
|
||||
void DmeTime_t::Clamp( DmeTime_t lo, DmeTime_t hi )
|
||||
{
|
||||
m_tms = clamp( m_tms, lo.m_tms, hi.m_tms );
|
||||
}
|
||||
|
||||
bool DmeTime_t::IsInRange( DmeTime_t lo, DmeTime_t hi ) const
|
||||
{
|
||||
return m_tms >= lo.m_tms && m_tms < hi.m_tms;
|
||||
}
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
float GetFractionOfTimeBetween( DmeTime_t t, DmeTime_t start, DmeTime_t end, bool bClamp /*= false*/ )
|
||||
{
|
||||
return GetFractionOfTime( t - start, end - start, bClamp );
|
||||
}
|
||||
|
||||
float GetFractionOfTime( DmeTime_t t, DmeTime_t duration, bool bClamp /*= false*/ )
|
||||
{
|
||||
if ( duration == DMETIME_ZERO )
|
||||
return 0.0f;
|
||||
|
||||
if ( bClamp )
|
||||
{
|
||||
t.Clamp( DMETIME_ZERO, duration );
|
||||
}
|
||||
return t.m_tms / float( duration.m_tms );
|
||||
}
|
||||
|
||||
int FrameForTime( DmeTime_t t, DmeFramerate_t framerate )
|
||||
{
|
||||
return t.CurrentFrame( framerate );
|
||||
}
|
||||
|
||||
|
||||
// framerate-dependent conversions to/from frames
|
||||
|
||||
int DmeTime_t::CurrentFrame( DmeFramerate_t framerate, bool bRoundDown ) const
|
||||
{
|
||||
__int64 den = __int64( framerate.m_den );
|
||||
__int64 num = __int64( framerate.m_num );
|
||||
__int64 prod = __int64( m_tms ) * num;
|
||||
|
||||
// times within this range are considered on a frame: (frame*den/num - 1, frame*den/num]
|
||||
// this follows from the truncation towards -inf behavior of the frame,framerate constructor above
|
||||
// the following logic is there to ensure the above rule,
|
||||
// while working around the truncation towards 0 behavior of integer divide
|
||||
if ( m_tms < 0 )
|
||||
{
|
||||
if ( bRoundDown )
|
||||
prod -= den - num;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( bRoundDown )
|
||||
prod += num - 1;
|
||||
else
|
||||
prod += den - 1;
|
||||
}
|
||||
return int( prod / den );
|
||||
}
|
||||
|
||||
DmeTime_t DmeTime_t::TimeAtCurrentFrame( DmeFramerate_t framerate, bool bRoundDown ) const
|
||||
{
|
||||
int frame = CurrentFrame( framerate, bRoundDown );
|
||||
return DmeTime_t( frame, framerate );
|
||||
}
|
||||
DmeTime_t DmeTime_t::TimeAtNextFrame( DmeFramerate_t framerate ) const
|
||||
{
|
||||
// since we always round towards -inf, go to next frame whether we're on a frame or not
|
||||
int frame = CurrentFrame( framerate, true );
|
||||
return DmeTime_t( frame + 1, framerate );
|
||||
}
|
||||
DmeTime_t DmeTime_t::TimeAtPrevFrame( DmeFramerate_t framerate ) const
|
||||
{
|
||||
int frame = CurrentFrame( framerate, false );
|
||||
return DmeTime_t( frame - 1, framerate ); // we're exactly on a frame
|
||||
}
|
||||
|
||||
|
||||
int DmeTime_t::RoundSecondsToTMS( float sec )
|
||||
{
|
||||
return floor( 10000.0f * sec + 0.5f ); // round at half-tms boundary
|
||||
}
|
||||
|
||||
int DmeTime_t::RoundSecondsToTMS( double sec )
|
||||
{
|
||||
return floor( 10000.0 * sec + 0.5 ); // round at half-tms boundary
|
||||
}
|
||||
Reference in New Issue
Block a user