Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

631 lines
21 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "matsys_controls/mdlpanel.h"
  7. #include "materialsystem/imaterialsystem.h"
  8. #include "materialsystem/imaterialsystemhardwareconfig.h"
  9. #include "materialsystem/imesh.h"
  10. #include "vgui/IVGui.h"
  11. #include "tier1/keyvalues.h"
  12. #include "vgui_controls/Frame.h"
  13. #include "tier1/convar.h"
  14. #include "tier0/dbg.h"
  15. #include "istudiorender.h"
  16. #include "matsys_controls/matsyscontrols.h"
  17. #include "vcollide.h"
  18. #include "vcollide_parse.h"
  19. #include "bone_setup.h"
  20. #include "renderparm.h"
  21. #include "vphysics_interface.h"
  22. #include "game/client/irendercaptureconfiguration.h"
  23. // memdbgon must be the last include file in a .cpp file!!!
  24. #include "tier0/memdbgon.h"
  25. using namespace vgui;
  26. DECLARE_BUILD_FACTORY( CMDLPanel );
  27. //-----------------------------------------------------------------------------
  28. // Purpose: Keeps a global clock to autoplay sequences to run from
  29. // Also deals with speedScale changes
  30. //-----------------------------------------------------------------------------
  31. static float GetAutoPlayTime( void )
  32. {
  33. static int g_prevTicks;
  34. static float g_time;
  35. int ticks = Plat_MSTime();
  36. // limit delta so that float time doesn't overflow
  37. if (g_prevTicks == 0)
  38. {
  39. g_prevTicks = ticks;
  40. }
  41. g_time += ( ticks - g_prevTicks ) / 1000.0f;
  42. g_prevTicks = ticks;
  43. return g_time;
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Constructor, destructor
  47. //-----------------------------------------------------------------------------
  48. CMDLPanel::CMDLPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
  49. {
  50. SetVisible( true );
  51. // Used to poll input
  52. vgui::ivgui()->AddTickSignal( GetVPanel() );
  53. SetIdentityMatrix( m_RootMDL.m_MDLToWorld );
  54. m_bDrawCollisionModel = false;
  55. m_bWireFrame = false;
  56. m_bGroundGrid = false;
  57. m_bLockView = false;
  58. m_bLookAtCamera = true;
  59. m_bAnimationPause = false;
  60. m_iCameraAttachment = -1;
  61. m_iRenderCaptureCameraAttachment = -1;
  62. Q_memset( m_iDirectionalLightAttachments, ~0, sizeof( m_iDirectionalLightAttachments ) );
  63. m_flAutoPlayTimeBase = GetAutoPlayTime();
  64. m_bCameraOrientOverrideEnabled = false;
  65. m_bCameraPositionOverrideEnabled = false;
  66. m_vecCameraOrientOverride.Init();
  67. m_vecCameraPositionOverride.Init();
  68. }
  69. CMDLPanel::~CMDLPanel()
  70. {
  71. m_aMergeMDLs.Purge();
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Scheme settings
  75. //-----------------------------------------------------------------------------
  76. void CMDLPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  77. {
  78. BaseClass::ApplySchemeSettings( pScheme );
  79. SetBackgroundColor( GetBgColor() );
  80. SetBorder( pScheme->GetBorder( "MenuBorder") );
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Rendering options
  84. //-----------------------------------------------------------------------------
  85. void CMDLPanel::SetCollsionModel( bool bVisible )
  86. {
  87. m_bDrawCollisionModel = bVisible;
  88. }
  89. void CMDLPanel::SetGroundGrid( bool bVisible )
  90. {
  91. m_bGroundGrid = bVisible;
  92. }
  93. void CMDLPanel::SetWireFrame( bool bVisible )
  94. {
  95. m_bWireFrame = bVisible;
  96. }
  97. void CMDLPanel::SetLockView( bool bLocked )
  98. {
  99. m_bLockView = bLocked;
  100. }
  101. void CMDLPanel::SetLookAtCamera( bool bLookAtCamera )
  102. {
  103. m_bLookAtCamera = bLookAtCamera;
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Lock the camera position and angles to an attachment point
  107. //-----------------------------------------------------------------------------
  108. void CMDLPanel::SetCameraAttachment( const char *pszAttachment )
  109. {
  110. // Check to see if we have a valid model to look at.
  111. if ( m_RootMDL.m_MDL.GetMDL() == MDLHANDLE_INVALID )
  112. return;
  113. SetLookAtCamera( false );
  114. CStudioHdr studioHdr( g_pMDLCache->GetStudioHdr( m_RootMDL.m_MDL.GetMDL() ), g_pMDLCache );
  115. m_iCameraAttachment = Studio_FindAttachment( &studioHdr, pszAttachment );
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Set the light render capture camera position and angles to an attachment point
  119. //-----------------------------------------------------------------------------
  120. void CMDLPanel::SetRenderCaptureCameraAttachment( const char *pszAttachment )
  121. {
  122. // Check to see if we have a valid model to look at.
  123. if ( m_RootMDL.m_MDL.GetMDL() == MDLHANDLE_INVALID )
  124. return;
  125. CStudioHdr studioHdr( g_pMDLCache->GetStudioHdr( m_RootMDL.m_MDL.GetMDL() ), g_pMDLCache );
  126. m_iRenderCaptureCameraAttachment = Studio_FindAttachment( &studioHdr, pszAttachment );
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Set the directional light attachment point for direction animation
  130. //-----------------------------------------------------------------------------
  131. void CMDLPanel::SetDirectionalLightAttachment( int idx, const char *pszAttachment )
  132. {
  133. // Check to see if we have a valid model to look at.
  134. if ( m_RootMDL.m_MDL.GetMDL() == MDLHANDLE_INVALID )
  135. return;
  136. if ( idx < 0 || idx >= MATERIAL_MAX_LIGHT_COUNT )
  137. return;
  138. CStudioHdr studioHdr( g_pMDLCache->GetStudioHdr( m_RootMDL.m_MDL.GetMDL() ), g_pMDLCache );
  139. m_iDirectionalLightAttachments[idx] = Studio_FindAttachment( &studioHdr, pszAttachment );
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Sets the camera to look at the model
  143. //-----------------------------------------------------------------------------
  144. void CMDLPanel::LookAtMDL()
  145. {
  146. // Check to see if we have a valid model to look at.
  147. if ( m_RootMDL.m_MDL.GetMDL() == MDLHANDLE_INVALID )
  148. return;
  149. if ( m_bLockView )
  150. return;
  151. float flRadius;
  152. Vector vecCenter;
  153. GetBoundingSphere( vecCenter, flRadius );
  154. LookAt( vecCenter, flRadius );
  155. }
  156. //-----------------------------------------------------------------------------
  157. // FIXME: This should be moved into studiorender
  158. //-----------------------------------------------------------------------------
  159. static ConVar r_showenvcubemap( "r_showenvcubemap", "0", FCVAR_CHEAT );
  160. static ConVar r_eyegloss ( "r_eyegloss", "1", FCVAR_ARCHIVE ); // wet eyes
  161. static ConVar r_eyemove ( "r_eyemove", "1", FCVAR_ARCHIVE ); // look around
  162. static ConVar r_eyeshift_x ( "r_eyeshift_x", "0", FCVAR_ARCHIVE ); // eye X position
  163. static ConVar r_eyeshift_y ( "r_eyeshift_y", "0", FCVAR_ARCHIVE ); // eye Y position
  164. static ConVar r_eyeshift_z ( "r_eyeshift_z", "0", FCVAR_ARCHIVE ); // eye Z position
  165. static ConVar r_eyesize ( "r_eyesize", "0", FCVAR_ARCHIVE ); // adjustment to iris textures
  166. static ConVar mat_softwareskin( "mat_softwareskin", "0", FCVAR_CHEAT );
  167. static ConVar r_nohw ( "r_nohw", "0", FCVAR_CHEAT );
  168. static ConVar r_nosw ( "r_nosw", "0", FCVAR_CHEAT );
  169. static ConVar r_teeth ( "r_teeth", "1" );
  170. static ConVar r_drawentities ( "r_drawentities", "1", FCVAR_CHEAT );
  171. static ConVar r_flex ( "r_flex", "1" );
  172. static ConVar r_eyes ( "r_eyes", "1" );
  173. static ConVar r_skin ( "r_skin","0", FCVAR_CHEAT );
  174. static ConVar r_maxmodeldecal ( "r_maxmodeldecal", "50" );
  175. static ConVar r_modelwireframedecal ( "r_modelwireframedecal", "0", FCVAR_CHEAT );
  176. static ConVar mat_normals ( "mat_normals", "0", FCVAR_CHEAT );
  177. static ConVar r_eyeglintlodpixels ( "r_eyeglintlodpixels", "0" );
  178. static ConVar r_rootlod ( "r_rootlod", "0" );
  179. static StudioRenderConfig_t s_StudioRenderConfig;
  180. void CMDLPanel::UpdateStudioRenderConfig( void )
  181. {
  182. memset( &s_StudioRenderConfig, 0, sizeof(s_StudioRenderConfig) );
  183. s_StudioRenderConfig.bEyeMove = !!r_eyemove.GetInt();
  184. s_StudioRenderConfig.fEyeShiftX = r_eyeshift_x.GetFloat();
  185. s_StudioRenderConfig.fEyeShiftY = r_eyeshift_y.GetFloat();
  186. s_StudioRenderConfig.fEyeShiftZ = r_eyeshift_z.GetFloat();
  187. s_StudioRenderConfig.fEyeSize = r_eyesize.GetFloat();
  188. if( mat_softwareskin.GetInt() || m_bWireFrame )
  189. {
  190. s_StudioRenderConfig.bSoftwareSkin = true;
  191. }
  192. else
  193. {
  194. s_StudioRenderConfig.bSoftwareSkin = false;
  195. }
  196. s_StudioRenderConfig.bNoHardware = !!r_nohw.GetInt();
  197. s_StudioRenderConfig.bNoSoftware = !!r_nosw.GetInt();
  198. s_StudioRenderConfig.bTeeth = !!r_teeth.GetInt();
  199. s_StudioRenderConfig.drawEntities = r_drawentities.GetInt();
  200. s_StudioRenderConfig.bFlex = !!r_flex.GetInt();
  201. s_StudioRenderConfig.bEyes = !!r_eyes.GetInt();
  202. s_StudioRenderConfig.bWireframe = m_bWireFrame;
  203. s_StudioRenderConfig.bDrawNormals = mat_normals.GetBool();
  204. s_StudioRenderConfig.skin = r_skin.GetInt();
  205. s_StudioRenderConfig.maxDecalsPerModel = r_maxmodeldecal.GetInt();
  206. s_StudioRenderConfig.bWireframeDecals = r_modelwireframedecal.GetInt() != 0;
  207. s_StudioRenderConfig.fullbright = false;
  208. s_StudioRenderConfig.bSoftwareLighting = false;
  209. s_StudioRenderConfig.bShowEnvCubemapOnly = r_showenvcubemap.GetBool();
  210. s_StudioRenderConfig.fEyeGlintPixelWidthLODThreshold = r_eyeglintlodpixels.GetFloat();
  211. StudioRender()->UpdateConfig( s_StudioRenderConfig );
  212. }
  213. void CMDLPanel::DrawCollisionModel()
  214. {
  215. vcollide_t *pCollide = MDLCache()->GetVCollide( m_RootMDL.m_MDL.GetMDL() );
  216. if ( !pCollide || pCollide->solidCount <= 0 )
  217. return;
  218. static color32 color = {255,0,0,0};
  219. IVPhysicsKeyParser *pParser = g_pPhysicsCollision->VPhysicsKeyParserCreate( pCollide );
  220. CStudioHdr studioHdr( g_pMDLCache->GetStudioHdr( m_RootMDL.m_MDL.GetMDL() ), g_pMDLCache );
  221. matrix3x4_t pBoneToWorld[MAXSTUDIOBONES];
  222. m_RootMDL.m_MDL.SetUpBones( m_RootMDL.m_MDLToWorld, MAXSTUDIOBONES, pBoneToWorld );
  223. // PERFORMANCE: Just parse the script each frame. It's fast enough for tools. If you need
  224. // this to go faster then cache off the bone index mapping in an array like HLMV does
  225. while ( !pParser->Finished() )
  226. {
  227. const char *pBlock = pParser->GetCurrentBlockName();
  228. if ( !stricmp( pBlock, "solid" ) )
  229. {
  230. solid_t solid;
  231. pParser->ParseSolid( &solid, NULL );
  232. int boneIndex = Studio_BoneIndexByName( &studioHdr, solid.name );
  233. Vector *outVerts;
  234. int vertCount = g_pPhysicsCollision->CreateDebugMesh( pCollide->solids[solid.index], &outVerts );
  235. if ( vertCount )
  236. {
  237. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  238. pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
  239. // NOTE: assumes these have been set up already by the model render code
  240. // So this is a little bit of a back door to a cache of the bones
  241. // this code wouldn't work unless you draw the model this frame before calling
  242. // this routine. CMDLPanel always does this, but it's worth noting.
  243. // A better solution would be to move the ragdoll visulization into the CDmeMdl
  244. // and either draw it there or make it queryable and query/draw here.
  245. matrix3x4_t xform;
  246. SetIdentityMatrix( xform );
  247. if ( boneIndex >= 0 )
  248. {
  249. MatrixCopy( pBoneToWorld[ boneIndex ], xform );
  250. }
  251. IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, GetWireframeMaterial() );
  252. CMeshBuilder meshBuilder;
  253. meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, vertCount/3 );
  254. for ( int j = 0; j < vertCount; j++ )
  255. {
  256. Vector out;
  257. VectorTransform( outVerts[j].Base(), xform, out.Base() );
  258. meshBuilder.Position3fv( out.Base() );
  259. meshBuilder.Color4ub( color.r, color.g, color.b, color.a );
  260. meshBuilder.TexCoord2f( 0, 0, 0 );
  261. meshBuilder.AdvanceVertex();
  262. }
  263. meshBuilder.End();
  264. pMesh->Draw();
  265. }
  266. g_pPhysicsCollision->DestroyDebugMesh( vertCount, outVerts );
  267. }
  268. else
  269. {
  270. pParser->SkipBlock();
  271. }
  272. }
  273. g_pPhysicsCollision->VPhysicsKeyParserDestroy( pParser );
  274. }
  275. //-----------------------------------------------------------------------------
  276. // paint it!
  277. //-----------------------------------------------------------------------------
  278. void CMDLPanel::OnPaint3D()
  279. {
  280. if ( m_RootMDL.m_MDL.GetMDL() == MDLHANDLE_INVALID )
  281. return;
  282. // FIXME: Move this call into DrawModel in StudioRender
  283. StudioRenderConfig_t oldStudioRenderConfig;
  284. StudioRender()->GetCurrentConfig( oldStudioRenderConfig );
  285. UpdateStudioRenderConfig();
  286. CMatRenderContextPtr pRenderContext( vgui::MaterialSystem() );
  287. // We want the models to use their natural alpha, not depth in alpha
  288. pRenderContext->SetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA, 0 );
  289. if ( IsPaint3dForRenderCapture() )
  290. {
  291. // We are rendering into flashlight depth texture
  292. pRenderContext->SetFlashlightMode( false ); // disable shadows since we should be using DEPTH_WRITE material
  293. }
  294. else if ( GetRenderingWithFlashlightConfiguration() )
  295. {
  296. // Setup shadow state that we configured
  297. g_pStudioRender->ClearAllShadows();
  298. // NOTE: flashlight shadow is added post bone setup
  299. }
  300. else
  301. {
  302. // flashlights can't work in the model panel under queued mode (the state isn't ready yet, so causes a crash)
  303. pRenderContext->SetFlashlightMode( false );
  304. }
  305. ITexture *pMyCube = materials->FindTexture( "engine/defaultcubemap", TEXTURE_GROUP_CUBE_MAP, true );
  306. if ( HasLightProbe() )
  307. {
  308. pMyCube = GetLightProbeCubemap( vgui::MaterialSystemHardwareConfig()->GetHDRType() != HDR_TYPE_NONE );
  309. }
  310. pRenderContext->BindLocalCubemap( pMyCube );
  311. if ( m_bGroundGrid )
  312. {
  313. DrawGrid();
  314. }
  315. if ( m_bLookAtCamera )
  316. {
  317. matrix3x4_t worldToCamera;
  318. ComputeCameraTransform( &worldToCamera );
  319. Vector vecPosition;
  320. MatrixGetColumn( worldToCamera, 3, vecPosition );
  321. m_RootMDL.m_MDL.m_bWorldSpaceViewTarget = true;
  322. m_RootMDL.m_MDL.m_vecViewTarget = vecPosition;
  323. }
  324. Draw();
  325. if ( m_bDrawCollisionModel )
  326. {
  327. DrawCollisionModel();
  328. }
  329. if ( IsPaint3dForRenderCapture() )
  330. {
  331. // We are finished rendering into flashlight buffer
  332. }
  333. else if ( GetRenderingWithFlashlightConfiguration() )
  334. {
  335. // Clear all shadow state that we configured and used now
  336. g_pStudioRender->ClearAllShadows();
  337. }
  338. pRenderContext->Flush();
  339. StudioRender()->UpdateConfig( oldStudioRenderConfig );
  340. }
  341. void CMDLPanel::OnModelDrawPassStart( int iPass, CStudioHdr *pStudioHdr, int &nFlags )
  342. {
  343. if ( IsPaint3dForRenderCapture() )
  344. nFlags |= STUDIORENDER_SHADOWDEPTHTEXTURE;
  345. else if ( GetRenderingWithFlashlightConfiguration() )
  346. nFlags &=~STUDIORENDER_DRAW_NO_SHADOWS;
  347. }
  348. void CMDLPanel::OnModelDrawPassFinished( int iPass, CStudioHdr *pStudioHdr, int &nFlags )
  349. {
  350. }
  351. void CMDLPanel::OnPostSetUpBonesPreDraw()
  352. {
  353. bool bFlashlightPosKnown = false;
  354. Vector vecPositionFlashlight;
  355. QAngle anglesFlashlight;
  356. bool bCameraPosKnown = false;
  357. Vector vecPositionCamera;
  358. QAngle anglesCamera;
  359. if ( m_iRenderCaptureCameraAttachment >= 0 )
  360. {
  361. matrix3x4_t camera;
  362. if ( GetAttachment( m_iRenderCaptureCameraAttachment+1, camera ) )
  363. {
  364. Vector vecPosition;
  365. QAngle angles;
  366. MatrixPosition( camera, vecPosition );
  367. MatrixAngles( camera, angles );
  368. bFlashlightPosKnown = true;
  369. vecPositionFlashlight = vecPosition;
  370. anglesFlashlight = angles;
  371. }
  372. }
  373. if ( m_iCameraAttachment >= 0 )
  374. {
  375. matrix3x4_t camera;
  376. if ( GetAttachment( m_iCameraAttachment+1, camera ) )
  377. {
  378. Vector vecPosition;
  379. QAngle angles;
  380. MatrixPosition( camera, vecPosition );
  381. MatrixAngles( camera, angles );
  382. bCameraPosKnown = true;
  383. vecPositionCamera = vecPosition;
  384. anglesCamera = angles;
  385. if ( IsCameraPositionOverrideEnabled() )
  386. {
  387. vecPositionCamera += m_vecCameraPositionOverride;
  388. }
  389. if ( !bFlashlightPosKnown )
  390. {
  391. // DEBUG: move light off from the actual camera
  392. Vector basisUp, basisRight, basisForward;
  393. AngleVectors( angles, &basisForward, &basisRight, &basisUp );
  394. float flCycle0to1 = ( m_RootMDL.m_MDL.m_flTime - floor( m_RootMDL.m_MDL.m_flTime ) );
  395. float flDistance = 1.0f + ( flCycle0to1 - 0.5f ) * ( flCycle0to1 - 0.5f ) * 4 * 9;
  396. vecPosition += basisUp * flDistance;
  397. bFlashlightPosKnown = true;
  398. vecPositionFlashlight = vecPosition;
  399. anglesFlashlight = angles;
  400. }
  401. if ( IsCameraOrientOverrideEnabled() )
  402. {
  403. anglesCamera.x += m_vecCameraOrientOverride.x;
  404. anglesCamera.y += m_vecCameraOrientOverride.y;
  405. anglesCamera.z += m_vecCameraOrientOverride.z;
  406. }
  407. }
  408. }
  409. if ( bFlashlightPosKnown && GetRenderingWithFlashlightConfiguration() != NULL )
  410. {
  411. CRenderCaptureConfigurationState *pFlashlightInfo = reinterpret_cast< CRenderCaptureConfigurationState * >( GetRenderingWithFlashlightConfiguration() );
  412. //
  413. // Update flashlight position
  414. //
  415. {
  416. pFlashlightInfo->m_renderFlashlightState.m_vecLightOrigin = vecPositionFlashlight;
  417. AngleQuaternion( anglesFlashlight, pFlashlightInfo->m_renderFlashlightState.m_quatOrientation );
  418. }
  419. //
  420. // Build world to shadow matrix, then perspective projection and concatenate
  421. //
  422. {
  423. VMatrix matWorldToShadowView, matPerspective;
  424. matrix3x4_t matOrientation;
  425. QuaternionMatrix( pFlashlightInfo->m_renderFlashlightState.m_quatOrientation, matOrientation ); // Convert quat to matrix3x4
  426. PositionMatrix( vec3_origin, matOrientation ); // Zero out translation elements
  427. VMatrix matBasis( matOrientation ); // Convert matrix3x4 to VMatrix
  428. Vector vForward, vLeft, vUp;
  429. matBasis.GetBasisVectors( vForward, vLeft, vUp );
  430. matBasis.SetForward( vLeft ); // Bizarre vector flip inherited from earlier code, WTF?
  431. matBasis.SetLeft( vUp );
  432. matBasis.SetUp( vForward );
  433. matWorldToShadowView = matBasis.Transpose(); // Transpose
  434. Vector translation;
  435. Vector3DMultiply( matWorldToShadowView, pFlashlightInfo->m_renderFlashlightState.m_vecLightOrigin, translation );
  436. translation *= -1.0f;
  437. matWorldToShadowView.SetTranslation( translation );
  438. // The the bottom row.
  439. matWorldToShadowView[3][0] = matWorldToShadowView[3][1] = matWorldToShadowView[3][2] = 0.0f;
  440. matWorldToShadowView[3][3] = 1.0f;
  441. MatrixBuildPerspective( matPerspective, pFlashlightInfo->m_renderFlashlightState.m_fHorizontalFOVDegrees,
  442. pFlashlightInfo->m_renderFlashlightState.m_fVerticalFOVDegrees,
  443. pFlashlightInfo->m_renderFlashlightState.m_NearZ, pFlashlightInfo->m_renderFlashlightState.m_FarZ );
  444. MatrixMultiply( matPerspective, matWorldToShadowView, pFlashlightInfo->m_renderMatrixWorldToShadow );
  445. }
  446. }
  447. for ( int j = 0; j < ( int ) MIN( m_LightingState.m_nLocalLightCount, Q_ARRAYSIZE( m_iDirectionalLightAttachments ) ); ++ j )
  448. {
  449. if ( m_iDirectionalLightAttachments[j] >= 0 )
  450. {
  451. matrix3x4_t camera;
  452. if ( GetAttachment( m_iDirectionalLightAttachments[j]+1, camera ) )
  453. {
  454. Vector vecPosition;
  455. QAngle angles;
  456. MatrixPosition( camera, vecPosition );
  457. MatrixAngles( camera, angles );
  458. Vector vecForward;
  459. AngleVectors( angles, &vecForward );
  460. m_LightingState.m_pLocalLightDesc[j].m_Direction = vecForward;
  461. m_LightingState.m_pLocalLightDesc[j].RecalculateDerivedValues();
  462. }
  463. }
  464. }
  465. if ( IsPaint3dForRenderCapture() )
  466. {
  467. Assert( bFlashlightPosKnown );
  468. CRenderCaptureConfigurationState *pFlashlightInfo = reinterpret_cast< CRenderCaptureConfigurationState * >( GetRenderingWithFlashlightConfiguration() );
  469. SetCameraPositionAndAngles( vecPositionFlashlight, anglesFlashlight );
  470. Camera_t &cameraSettings = GetCameraSettings();
  471. float flZnear = cameraSettings.m_flZNear, flZfar = cameraSettings.m_flZFar;
  472. cameraSettings.m_flZNear = pFlashlightInfo->m_renderFlashlightState.m_NearZ;
  473. cameraSettings.m_flZFar = pFlashlightInfo->m_renderFlashlightState.m_FarZ;
  474. SetupRenderStateDelayed(); // Configure view with the updated camera settings and restore Z planes
  475. cameraSettings.m_flZNear = flZnear, cameraSettings.m_flZFar = flZfar;
  476. }
  477. else
  478. {
  479. if ( bCameraPosKnown )
  480. {
  481. SetCameraPositionAndAngles( vecPositionCamera, anglesCamera );
  482. }
  483. SetupRenderStateDelayed();
  484. if ( GetRenderingWithFlashlightConfiguration() )
  485. {
  486. Assert( bFlashlightPosKnown );
  487. // Add the shadow we rendered in previous pass to our model
  488. CRenderCaptureConfigurationState *pFlashlightInfo = reinterpret_cast< CRenderCaptureConfigurationState * >( GetRenderingWithFlashlightConfiguration() );
  489. g_pStudioRender->AddShadow( NULL, NULL, &pFlashlightInfo->m_renderFlashlightState, &pFlashlightInfo->m_renderMatrixWorldToShadow, pFlashlightInfo->m_pFlashlightDepthTexture );
  490. }
  491. }
  492. }
  493. //-----------------------------------------------------------------------------
  494. // called when we're ticked...
  495. //-----------------------------------------------------------------------------
  496. void CMDLPanel::OnTick()
  497. {
  498. BaseClass::OnTick();
  499. float flCurrentTime = GetAutoPlayTime();
  500. float flMdlTime = flCurrentTime - m_flAutoPlayTimeBase;
  501. m_flAutoPlayTimeBase = flCurrentTime;
  502. if ( m_RootMDL.m_MDL.GetMDL() != MDLHANDLE_INVALID && !m_bAnimationPause )
  503. {
  504. m_RootMDL.m_MDL.AdjustTime( flMdlTime );
  505. }
  506. for ( int k = 0; k < m_aMergeMDLs.Count(); ++ k )
  507. {
  508. if ( m_aMergeMDLs[k].m_MDL.GetMDL() != MDLHANDLE_INVALID && !m_bAnimationPause )
  509. {
  510. m_aMergeMDLs[k].m_MDL.AdjustTime( flMdlTime );
  511. }
  512. }
  513. }
  514. //-----------------------------------------------------------------------------
  515. // input
  516. //-----------------------------------------------------------------------------
  517. void CMDLPanel::OnMouseDoublePressed( vgui::MouseCode code )
  518. {
  519. float flRadius;
  520. Vector vecCenter;
  521. GetBoundingSphere( vecCenter, flRadius );
  522. LookAt( vecCenter, flRadius );
  523. BaseClass::OnMouseDoublePressed( code );
  524. }