mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 20:16:10 +08:00
Added original SDK code for Alien Swarm.
This commit is contained in:
67
public/maya/IMayaVGui.h
Normal file
67
public/maya/IMayaVGui.h
Normal file
@ -0,0 +1,67 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: Interface for dealing with vgui focus issues across all plugins
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef IMAYAVGUI_H
|
||||
#define IMAYAVGUI_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "appframework/iappsystem.h"
|
||||
#include "vgui_controls/Frame.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace vgui
|
||||
{
|
||||
class EditablePanel;
|
||||
}
|
||||
|
||||
class CVsVGuiWindowBase;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Factory for creating vgui windows
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IMayaVguiWindowFactory
|
||||
{
|
||||
public:
|
||||
virtual void CreateVguiWindow( const char *pPanelName ) = 0;
|
||||
virtual void DestroyVguiWindow( const char *pPanelName ) = 0;
|
||||
virtual vgui::Frame *GetVGuiPanel( const char *pPanelName = NULL ) = 0;
|
||||
virtual CVsVGuiWindowBase *GetVGuiWindow( const char *pPanelName = NULL ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface for dealing with vgui focus issues across all plugins
|
||||
//-----------------------------------------------------------------------------
|
||||
#define MAYA_VGUI_INTERFACE_VERSION "VMayaVGui001"
|
||||
abstract_class IMayaVGui : public IAppSystem
|
||||
{
|
||||
public:
|
||||
virtual void InstallVguiWindowFactory( const char *pWindowTypeName, IMayaVguiWindowFactory *pFactory ) = 0;
|
||||
virtual void RemoveVguiWindowFactory( const char *pWindowTypeName, IMayaVguiWindowFactory *pFactory ) = 0;
|
||||
virtual void SetFocus( void *hWnd, int hVGuiContext ) = 0;
|
||||
virtual bool HasFocus( void *hWnd ) = 0;
|
||||
|
||||
// In this mode, maya's in a strange re-entrant mode waiting for a modal dialog
|
||||
// We still get WM_PAINT messages, but we're in the middle of a callstack
|
||||
// deep in the bowels of VGUI
|
||||
virtual void SetModalMode( bool bEnable ) = 0;
|
||||
virtual bool IsInModalMode( ) const = 0;
|
||||
};
|
||||
|
||||
extern IMayaVGui* g_pMayaVGui;
|
||||
|
||||
|
||||
#endif // IMAYAVGUI_H
|
30
public/maya/VsMayaDmx.h
Normal file
30
public/maya/VsMayaDmx.h
Normal file
@ -0,0 +1,30 @@
|
||||
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSMAYADMX_H
|
||||
#define VSMAYADMX_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// Maya includes
|
||||
|
||||
#include <maya/MDagPath.h>
|
||||
|
||||
// Valve includes
|
||||
|
||||
#include "movieobjects/dmemesh.h"
|
||||
|
||||
class VsMayaDmx
|
||||
{
|
||||
static CDmeMesh *MayaMeshToDmeMesh(
|
||||
const MDagPath &i_mDagPath,
|
||||
DmFileId_t fileId );
|
||||
|
||||
};
|
||||
|
||||
#endif // VSMAYADMX_H
|
1120
public/maya/VsMayaMPxFactory.h
Normal file
1120
public/maya/VsMayaMPxFactory.h
Normal file
File diff suppressed because it is too large
Load Diff
188
public/maya/VsVGuiWindow.h
Normal file
188
public/maya/VsVGuiWindow.h
Normal file
@ -0,0 +1,188 @@
|
||||
//===== Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Base class for windows that draw vgui in Maya
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VSVGUIWINDOW_H
|
||||
#define VSVGUIWINDOW_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "imayavgui.h"
|
||||
#include "vgui_controls/Frame.h"
|
||||
#include "tier1/UtlMap.h"
|
||||
#include "valveMaya.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IMayaVGui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The singleton is defined here twice just so we don't have to include valvemaya.h also
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IMayaVGui *g_pMayaVGui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace vgui
|
||||
{
|
||||
class EditablePanel;
|
||||
}
|
||||
|
||||
|
||||
class CVsVGuiWindowBase
|
||||
{
|
||||
public:
|
||||
virtual void SetPeriod( float flPeriod ) = 0;
|
||||
virtual void StartTick() = 0;
|
||||
virtual void StartTick( float flPeriod ) = 0;
|
||||
virtual void StopTick() = 0;
|
||||
virtual void Tick( float flElapsedTime ) = 0;
|
||||
virtual void NonTimerTick() = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys a maya vgui window
|
||||
//-----------------------------------------------------------------------------
|
||||
CVsVGuiWindowBase *CreateMayaVGuiWindow( vgui::EditablePanel *pRootPanel, const char *pPanelName );
|
||||
void DestroyMayaVGuiWindow( const char *pPanelName );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Factory used to install vgui windows easily
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVsVguiWindowFactoryBase : public IMayaVguiWindowFactory
|
||||
{
|
||||
public:
|
||||
CVsVguiWindowFactoryBase( const char *pWindowTypeName, const char *pDccStartupCommand );
|
||||
|
||||
// Returns the DCC command
|
||||
const char *GetDccStartupCommand() const;
|
||||
|
||||
// Registers/deregisters all vgui windows
|
||||
static void RegisterAllVguiWindows( );
|
||||
static void UnregisterAllVguiWindows( );
|
||||
|
||||
protected:
|
||||
const char *m_pWindowTypeName;
|
||||
const char *m_pDccStartupCommand;
|
||||
|
||||
private:
|
||||
CVsVguiWindowFactoryBase *m_pNext;
|
||||
static CVsVguiWindowFactoryBase *s_pFirstCommandFactory;
|
||||
};
|
||||
|
||||
template< class T >
|
||||
class CVsVguiWindowFactory : public CVsVguiWindowFactoryBase
|
||||
{
|
||||
typedef CVsVguiWindowFactoryBase BaseClass;
|
||||
|
||||
static bool StringLessFunc( const CUtlString &a, const CUtlString &b )
|
||||
{
|
||||
return StringLessThan( a.Get(), b.Get() );
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
CVsVguiWindowFactory( const char *pWindowTypeName, const char *pDccCommand )
|
||||
: BaseClass( pWindowTypeName, pDccCommand )
|
||||
, m_panelMap( StringLessFunc )
|
||||
{
|
||||
}
|
||||
|
||||
struct PanelMapElem_s
|
||||
{
|
||||
CVsVGuiWindowBase *m_pVGuiWindow;
|
||||
T *m_pPanel;
|
||||
};
|
||||
|
||||
typedef CUtlMap< CUtlString, PanelMapElem_s > PanelMap_t;
|
||||
|
||||
virtual void CreateVguiWindow( const char *pPanelName )
|
||||
{
|
||||
T *pVGuiPanel = new T( NULL, pPanelName );
|
||||
vgui::Frame *pFrame = dynamic_cast< vgui::Frame * >( pVGuiPanel );
|
||||
|
||||
if ( pFrame )
|
||||
{
|
||||
pFrame->SetSizeable( false );
|
||||
pFrame->SetCloseButtonVisible( false );
|
||||
pFrame->SetMoveable( false );
|
||||
|
||||
CVsVGuiWindowBase *pVGuiWindow = CreateMayaVGuiWindow( pVGuiPanel, pPanelName );
|
||||
|
||||
const CUtlString panelName( pPanelName );
|
||||
|
||||
PanelMap_t::IndexType_t nIndex = m_panelMap.Find( panelName );
|
||||
if ( m_panelMap.IsValidIndex( nIndex ) )
|
||||
{
|
||||
merr << "[vsVguiWindow]: Panel \"" << pPanelName << "\" of Type: \"" << m_pWindowTypeName << "\" Already Exists!!!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
PanelMap_t::ElemType_t &element = m_panelMap.Element( m_panelMap.Insert( panelName ) );
|
||||
element.m_pVGuiWindow = pVGuiWindow;
|
||||
element.m_pPanel = pVGuiPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DestroyVguiWindow( const char *pPanelName )
|
||||
{
|
||||
m_panelMap.Remove( CUtlString( pPanelName ) );
|
||||
DestroyMayaVGuiWindow( pPanelName );
|
||||
}
|
||||
|
||||
virtual vgui::Frame *GetVGuiPanel( const char *pPanelName = NULL )
|
||||
{
|
||||
if ( pPanelName )
|
||||
{
|
||||
PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
|
||||
if ( m_panelMap.IsValidIndex( nPanelIndex ) )
|
||||
return dynamic_cast< vgui::Frame * >( m_panelMap.Element( nPanelIndex ).m_pPanel );
|
||||
}
|
||||
else if ( m_panelMap.Count() > 0 )
|
||||
{
|
||||
return dynamic_cast< vgui::Frame * >( m_panelMap.Element( m_panelMap.FirstInorder() ).m_pPanel );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual CVsVGuiWindowBase *GetVGuiWindow( const char *pPanelName = NULL )
|
||||
{
|
||||
if ( pPanelName )
|
||||
{
|
||||
PanelMap_t::IndexType_t nPanelIndex = m_panelMap.Find( CUtlString( pPanelName ) );
|
||||
if ( m_panelMap.IsValidIndex( nPanelIndex ) )
|
||||
return m_panelMap.Element( nPanelIndex ).m_pVGuiWindow;
|
||||
}
|
||||
else if ( m_panelMap.Count() > 0 )
|
||||
{
|
||||
return m_panelMap.Element( m_panelMap.FirstInorder() ).m_pVGuiWindow;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
PanelMap_t m_panelMap;
|
||||
};
|
||||
|
||||
|
||||
#define INSTALL_MAYA_VGUI_WINDOW( _className, _windowTypeName, _dccCommand ) \
|
||||
static CVsVguiWindowFactory< _className > s_VsVguiWindowFactory##_className##( _windowTypeName, _dccCommand )
|
||||
|
||||
|
||||
#endif // VSVGUIWINDOW_H
|
544
public/maya/valveMaya.h
Normal file
544
public/maya/valveMaya.h
Normal file
@ -0,0 +1,544 @@
|
||||
//======= Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VALVEMAYA_H
|
||||
#define VALVEMAYA_H
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// Maya Includes
|
||||
|
||||
#include <maya/MAngle.h>
|
||||
#include <maya/MDagModifier.h>
|
||||
#include <maya/MEulerRotation.h>
|
||||
#include <maya/MFloatVector.h>
|
||||
#include <maya/MGlobal.h>
|
||||
#include <maya/MIOStream.h>
|
||||
#include <maya/MMatrix.h>
|
||||
#include <maya/MObject.h>
|
||||
#include <maya/MQuaternion.h>
|
||||
#include <maya/MSyntax.h>
|
||||
#include <maya/MString.h>
|
||||
#include <maya/MDagPath.h>
|
||||
#include <maya/MVector.h>
|
||||
|
||||
// Valve Includes
|
||||
|
||||
#include "tier1/stringpool.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlstringmap.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
#include "ValveMaya/Undo.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IMayaVGui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Maya-specific library singletons
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IMayaVGui *g_pMayaVGui;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Purpose: Group a bunch of functions into the Valve Maya Namespace
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace ValveMaya
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CUndo;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statics
|
||||
//-----------------------------------------------------------------------------
|
||||
extern const MQuaternion v2mQuat; // Valve Engine -> Maya Quaternion
|
||||
extern const MQuaternion m2vQuat; // Maya -> Valve Engine Quaternion
|
||||
extern const MMatrix v2mMat; // Valve Engine -> Maya Matrix
|
||||
extern const MMatrix m2vMat; // Maya -> Valve Engine Matrix
|
||||
|
||||
extern const MQuaternion vc2mcQuat; // Valve Engine Camera -> Maya Camera Quaternion
|
||||
extern const MQuaternion mc2vcQuat; // Maya Camera -> Valve Camera Engine Quaternion
|
||||
extern const MMatrix vc2mcMat; // Valve Engine Camera -> Maya Camera Quaternion
|
||||
extern const MMatrix mc2vcMat; // Maya Camera -> Valve Camera Engine Quaternion
|
||||
|
||||
inline MQuaternion ValveToMaya( const MQuaternion &q ) { return q * v2mQuat; }
|
||||
inline MQuaternion ValveCameraToMayaCamera( const MQuaternion &q ) { return vc2mcQuat * q * v2mQuat; }
|
||||
inline MQuaternion MayaToValve( const MQuaternion &q ) { return q * m2vQuat; }
|
||||
inline MQuaternion MayaCameraToValveCamera( const MQuaternion &q ) { return mc2vcQuat * q * m2vQuat; }
|
||||
|
||||
inline MVector ValveToMaya( const MVector &p ) { return p.rotateBy( v2mQuat ); }
|
||||
inline MVector ValveCameraToMayaCamera( const MVector &p ) { return p.rotateBy( v2mQuat ); }
|
||||
inline MVector MayaToValve( const MVector &p ) { return p.rotateBy( m2vQuat ); }
|
||||
inline MVector MayaCameraToValveCamera( const MVector &p ) { return p.rotateBy( m2vQuat ); }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConnectLibraries( CreateInterfaceFn factory );
|
||||
void DisconnectLibraries();
|
||||
|
||||
MStatus CreateDagNode(
|
||||
const char *const i_nodeType,
|
||||
const char *const i_transformName = NULL,
|
||||
const MObject &i_parentObj = MObject::kNullObj,
|
||||
MObject *o_pTransformObj = NULL,
|
||||
MObject *o_pShapeObj = NULL,
|
||||
MDagModifier *i_mDagModifier = NULL);
|
||||
|
||||
inline MStatus CreateDagNode(
|
||||
CUndo &undo,
|
||||
const char *const i_nodeType,
|
||||
const char *const i_transformName = NULL,
|
||||
const MObject &i_parentObj = MObject::kNullObj,
|
||||
MObject *o_pTransformObj = NULL,
|
||||
MObject *o_pShapeObj = NULL )
|
||||
{
|
||||
return CreateDagNode( i_nodeType, i_transformName, i_parentObj, o_pTransformObj, o_pShapeObj, &undo.DagModifier() );
|
||||
}
|
||||
|
||||
bool IsNodeVisible( const MDagPath &mDagPath, bool bTemplateAsInvisible = true );
|
||||
bool IsPathVisible( MDagPath mDagPath, bool bTemplateAsInvisible = true );
|
||||
|
||||
class CMSyntaxHelp
|
||||
{
|
||||
public:
|
||||
CMSyntaxHelp()
|
||||
: m_groupedHelp( false ) // Make case sensitive
|
||||
, m_helpCount( 0 )
|
||||
, m_shortNameLength( 0 )
|
||||
{}
|
||||
|
||||
void Clear();
|
||||
|
||||
MStatus AddFlag(
|
||||
MSyntax &i_mSyntax,
|
||||
const char *i_shortName,
|
||||
const char *i_longName,
|
||||
const char *i_group,
|
||||
const char *i_help,
|
||||
const MSyntax::MArgType i_argType1 = MSyntax::kNoArg,
|
||||
const MSyntax::MArgType i_argType2 = MSyntax::kNoArg,
|
||||
const MSyntax::MArgType i_argType3 = MSyntax::kNoArg,
|
||||
const MSyntax::MArgType i_argType4 = MSyntax::kNoArg,
|
||||
const MSyntax::MArgType i_argType5 = MSyntax::kNoArg,
|
||||
const MSyntax::MArgType i_argType6 = MSyntax::kNoArg);
|
||||
|
||||
void PrintHelp(
|
||||
const char *const i_cmdName,
|
||||
const char *const i_cmdDesc,
|
||||
int i_lineLength = 0U);
|
||||
|
||||
void PrintHelp(
|
||||
const MString &i_cmdName,
|
||||
const MString &i_cmdDesc,
|
||||
int i_lineLength = 0U)
|
||||
{
|
||||
PrintHelp( i_cmdName.asChar(), i_cmdDesc.asChar(), i_lineLength );
|
||||
}
|
||||
|
||||
protected:
|
||||
public:
|
||||
protected:
|
||||
CCountedStringPool m_stringPool;
|
||||
|
||||
struct HelpData_t
|
||||
{
|
||||
const char *m_shortName;
|
||||
const char *m_longName;
|
||||
const char *m_help;
|
||||
CUtlVector<MSyntax::MArgType> m_argTypes;
|
||||
};
|
||||
|
||||
CUtlVector<const char *> m_groupOrder;
|
||||
CUtlStringMap<CUtlVector<HelpData_t> > m_groupedHelp;
|
||||
int m_helpCount;
|
||||
int m_shortNameLength;
|
||||
};
|
||||
|
||||
MString RemoveNameSpace( const MString &mString );
|
||||
|
||||
MString &BackslashToSlash( MString &mString );
|
||||
|
||||
template < class T_t > bool IsDefault( T_t &, const MPlug & );
|
||||
|
||||
bool IsDefault( const MPlug &aPlug );
|
||||
|
||||
uint NextAvailable( MPlug &mPlug );
|
||||
|
||||
MPlug NextAvailablePlug( MPlug &mPlug );
|
||||
|
||||
MObject AddColorSetToMesh(
|
||||
const MString &colorSetName,
|
||||
const MDagPath &mDagPath,
|
||||
MDagModifier &mDagModifier );
|
||||
|
||||
MString GetMaterialPath(
|
||||
const MObject &shadingGroupObj,
|
||||
MObject *pSurfaceShaderObj,
|
||||
MObject *pFileObj,
|
||||
MObject *pPlace2dTextureObj,
|
||||
MObject *pVmtObj,
|
||||
bool *pbTransparent,
|
||||
MString *pDebugWhy );
|
||||
|
||||
// Returns the first node that is connected to the specified plug as input or output
|
||||
MObject FindConnectedNode( const MPlug &mPlug );
|
||||
|
||||
// Returns the plug connected to the specified plug as an input, a NULL plug if no plug is connected
|
||||
MPlug FindInputPlug( const MPlug &dstPlug );
|
||||
|
||||
MPlug FindInputPlug( const MObject &dstNodeObj, const MString &dstPlugName );
|
||||
|
||||
MObject FindInputNode( const MPlug &dstPlug );
|
||||
|
||||
MObject FindInputNode( const MObject &dstNodeObj, const MString &dstPlugName );
|
||||
|
||||
MObject FindInputAttr( const MPlug &dstPlug );
|
||||
|
||||
MObject FindInputAttr( const MObject &dstNodeObj, const MString &dstPlugName );
|
||||
|
||||
// Returns the first found node MObject of the specified type in the history of the specified node
|
||||
MObject FindInputNodeOfType( const MObject &dstNodeObj, const MString &typeName, const MString &dstPlugName );
|
||||
|
||||
MObject FindInputNodeOfType( const MObject &dstNodeObj, const MString &typeName, MSelectionList &doneList );
|
||||
|
||||
// Creates a deformer of the specified type and deforms the specified shape with an optional component
|
||||
MObject DeformShape( ValveMaya::CUndo &undo, const MString &deformerType, const MDagPath &inOrigDagPath, MObject &origCompObj = MObject::kNullObj );
|
||||
|
||||
bool Substitute( MString &str, const MString &searchStr, const MString &replaceStr );
|
||||
|
||||
bool SubstituteCaseInsensitive( MString &str, const MString &searchStr, const MString &replaceStr );
|
||||
|
||||
bool SubstituteAll( MString &str, const MString &searchStr, const MString &replaceStr );
|
||||
|
||||
bool SubstituteAllCaseInsensitive( MString &str, const MString &searchStr, const MString &replaceStr );
|
||||
|
||||
void FixSlashes( MString &str, char correctPathSeparator = '/' );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts a Maya MMatrix to a Valve matrix3x4_t (transpose)
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void MatrixMayaToValve( matrix3x4_t &mValve, const MMatrix &mMaya )
|
||||
{
|
||||
mValve[0][0] = mMaya[0][0]; mValve[0][1] = mMaya[1][0]; mValve[0][2] = mMaya[2][0]; mValve[0][3] = mMaya[3][0];
|
||||
mValve[1][0] = mMaya[0][1]; mValve[1][1] = mMaya[1][1]; mValve[1][2] = mMaya[2][1]; mValve[1][3] = mMaya[3][1];
|
||||
mValve[2][0] = mMaya[0][2]; mValve[2][1] = mMaya[1][2]; mValve[2][2] = mMaya[2][2]; mValve[2][3] = mMaya[3][2];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts a Valve matrix3x4_t to a Maya MMatrix (transpose)
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void MatrixValveToMaya( MMatrix &mMaya, const matrix3x4_t &mValve )
|
||||
{
|
||||
mMaya[0][0] = mValve[0][0]; mMaya[0][1] = mValve[1][0]; mMaya[0][2] = mValve[2][0]; mMaya[3][0] = 0.0;
|
||||
mMaya[1][0] = mValve[0][1]; mMaya[1][1] = mValve[1][1]; mMaya[1][2] = mValve[2][1]; mMaya[3][1] = 0.0;
|
||||
mMaya[2][0] = mValve[0][2]; mMaya[2][1] = mValve[1][2]; mMaya[2][2] = mValve[2][2]; mMaya[3][2] = 0.0;
|
||||
mMaya[3][0] = mValve[0][3]; mMaya[3][1] = mValve[1][3]; mMaya[3][2] = mValve[2][3]; mMaya[3][3] = 1.0;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace ValveMaya
|
||||
|
||||
|
||||
// Make an alias for the ValveMaya namespace
|
||||
|
||||
namespace vm = ValveMaya;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A simple stream class for printing information to the Maya script editor
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMayaStream
|
||||
{
|
||||
public:
|
||||
enum StreamType { kInfo, kWarning, kError };
|
||||
|
||||
CMayaStream( const StreamType i_streamType = kInfo )
|
||||
: m_streamType( i_streamType )
|
||||
{}
|
||||
|
||||
template < class T_t >
|
||||
CMayaStream &operator<<( const T_t &v );
|
||||
|
||||
// This is a hack so CMayaStream << std::endl works as expected
|
||||
CMayaStream &operator<<( std::ostream &(*StdEndl_t)( std::ostream & ) )
|
||||
{
|
||||
return flush();
|
||||
}
|
||||
|
||||
CMayaStream &flush() { return outputString(); }
|
||||
|
||||
protected:
|
||||
CMayaStream &outputString()
|
||||
{
|
||||
// Always ensure it's terminated with a newline
|
||||
if ( *( m_string.asChar() + m_string.length() - 1 ) != '\n' )
|
||||
{
|
||||
m_string += "\n";
|
||||
}
|
||||
|
||||
const char *pBegin = m_string.asChar();
|
||||
const char *const pEnd = pBegin + m_string.length();
|
||||
const char *pCurr = pBegin;
|
||||
|
||||
while ( *pCurr && pCurr < pEnd )
|
||||
{
|
||||
if ( *pCurr == '\n' )
|
||||
{
|
||||
switch ( m_streamType )
|
||||
{
|
||||
case kWarning:
|
||||
MGlobal::displayWarning( MString( pBegin, pCurr - pBegin ) );
|
||||
break;
|
||||
case kError:
|
||||
MGlobal::displayError( MString( pBegin, pCurr - pBegin ) );
|
||||
break;
|
||||
default:
|
||||
MGlobal::displayInfo( MString( pBegin, pCurr - pBegin ) );
|
||||
break;
|
||||
}
|
||||
|
||||
++pCurr;
|
||||
pBegin = pCurr;
|
||||
}
|
||||
else
|
||||
{
|
||||
++pCurr;
|
||||
}
|
||||
}
|
||||
|
||||
m_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CMayaStream &checkForFlush()
|
||||
{
|
||||
const char *pCurr = m_string.asChar();
|
||||
const char *pEnd = pCurr + m_string.length();
|
||||
while ( *pCurr && pCurr != pEnd )
|
||||
{
|
||||
if ( *pCurr == '\n' )
|
||||
{
|
||||
return outputString();
|
||||
}
|
||||
|
||||
++pCurr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
StreamType m_streamType;
|
||||
MString m_string;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMayaWarnStream : public CMayaStream
|
||||
{
|
||||
public:
|
||||
CMayaWarnStream()
|
||||
: CMayaStream( CMayaStream::kWarning )
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMayaErrStream : public CMayaStream
|
||||
{
|
||||
public:
|
||||
CMayaErrStream()
|
||||
: CMayaStream( CMayaStream::kError )
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for std::string
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const std::string &v )
|
||||
{
|
||||
*this << v.c_str();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for char
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const char &v )
|
||||
{
|
||||
m_string += MString( &v, 1 );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for MVector
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const MVector &v )
|
||||
{
|
||||
m_string += v.x;
|
||||
m_string += " ";
|
||||
m_string += v.y;
|
||||
m_string += " ";
|
||||
m_string += v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for MFloatVector
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const MFloatVector &v )
|
||||
{
|
||||
m_string += v.x;
|
||||
m_string += " ";
|
||||
m_string += v.y;
|
||||
m_string += " ";
|
||||
m_string += v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for MEulerRotation
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const MEulerRotation &e )
|
||||
{
|
||||
m_string += MAngle( e.x, MAngle::kRadians ).asDegrees();
|
||||
m_string += " ";
|
||||
m_string += MAngle( e.y, MAngle::kRadians ).asDegrees();
|
||||
m_string += " ";
|
||||
m_string += MAngle( e.z, MAngle::kRadians ).asDegrees();
|
||||
switch ( e.order )
|
||||
{
|
||||
case MEulerRotation::kXYZ:
|
||||
m_string += " (XYZ)";
|
||||
break;
|
||||
case MEulerRotation::kXZY:
|
||||
m_string += " (XZY)";
|
||||
break;
|
||||
case MEulerRotation::kYXZ:
|
||||
m_string += " (YXZ)";
|
||||
break;
|
||||
case MEulerRotation::kYZX:
|
||||
m_string += " (YZX)";
|
||||
break;
|
||||
case MEulerRotation::kZXY:
|
||||
m_string += " (ZXY)";
|
||||
break;
|
||||
case MEulerRotation::kZYX:
|
||||
m_string += " (ZYX)";
|
||||
break;
|
||||
default:
|
||||
m_string += " (Unknown)";
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for MQuaternion
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const MQuaternion &q )
|
||||
{
|
||||
m_string += q.x;
|
||||
m_string += " ";
|
||||
m_string += q.y;
|
||||
m_string += " ";
|
||||
m_string += q.z;
|
||||
m_string += " ";
|
||||
m_string += q.w;
|
||||
|
||||
m_string += " (";
|
||||
operator<<( q.asEulerRotation() );
|
||||
m_string += ")";
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for Quaternion
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const Quaternion &q )
|
||||
{
|
||||
return operator<<( MQuaternion( q.x, q.y, q.z, q.w ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for RadianEuler
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const RadianEuler &e )
|
||||
{
|
||||
return operator<<( MEulerRotation( e.x, e.y, e.z ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specialization for RadianEuler
|
||||
//-----------------------------------------------------------------------------
|
||||
template <>
|
||||
inline CMayaStream &CMayaStream::operator<<( const Vector &v )
|
||||
{
|
||||
return operator<<( MVector( v.x, v.y, v.z ) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
template < class T_t >
|
||||
inline CMayaStream &CMayaStream::operator<<( const T_t &v )
|
||||
{
|
||||
m_string += v;
|
||||
return checkForFlush();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// minfo, mwarn & merr are ostreams which can be used to send stuff to
|
||||
// the Maya history window
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern CMayaStream minfo;
|
||||
extern CMayaWarnStream mwarn;
|
||||
extern CMayaErrStream merr;
|
||||
|
||||
|
||||
#endif // VALVEMAYA_H
|
46
public/maya/valveMaya/HyperShadeUtil.h
Normal file
46
public/maya/valveMaya/HyperShadeUtil.h
Normal file
@ -0,0 +1,46 @@
|
||||
//======= Copyright <20> 1996-2007, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// Purpose: Utils for working with HyperShade in Maya
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
// Maya includes
|
||||
#include <maya/MObject.h>
|
||||
|
||||
|
||||
// Valve includes
|
||||
#include "valveMaya/Undo.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace ValveMaya
|
||||
{
|
||||
|
||||
class CHyperShadeUtil
|
||||
{
|
||||
public:
|
||||
CHyperShadeUtil();
|
||||
|
||||
CHyperShadeUtil( CUndo &undo );
|
||||
|
||||
MStatus AddUtility( const MObject &utilityNode );
|
||||
|
||||
MStatus AddShader( const MObject &shaderNode );
|
||||
|
||||
MStatus AddTexture( const MObject &textureNode );
|
||||
|
||||
protected:
|
||||
CUndo m_tmpUndo;
|
||||
CUndo &m_undo;
|
||||
|
||||
MObject m_renderUtilityListObj;
|
||||
MObject m_shaderListObj;
|
||||
MObject m_textureListObj;
|
||||
|
||||
void Init();
|
||||
};
|
||||
|
||||
}
|
327
public/maya/valveMaya/Undo.h
Normal file
327
public/maya/valveMaya/Undo.h
Normal file
@ -0,0 +1,327 @@
|
||||
//======= Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======
|
||||
//
|
||||
// Maya Undo helper, use it like this
|
||||
//
|
||||
// class CMyCmd : MPxCommand
|
||||
// {
|
||||
// // ... regular stuff ... //
|
||||
//
|
||||
// ValveMaya::CUndo m_undo;
|
||||
// };
|
||||
//
|
||||
// MStatus CMyCmd::doIt( const MArgList &mArgList )
|
||||
// {
|
||||
// m_undo.SetArgList( Syntax(), mArgList );
|
||||
// }
|
||||
//
|
||||
// MStatus CMyCmd::redoIt( const MArgList &mArgList )
|
||||
// {
|
||||
// // Get at command line args
|
||||
// m_undo.ArgDatabase().isFlagSet( ... );
|
||||
//
|
||||
// // Do operations
|
||||
// m_undo.SaveCurrentSelection();
|
||||
// m_undo.DagModifier().createNode( ... );
|
||||
// m_undo.DagModifierDoIt();
|
||||
// m_undo.SetAttr( mPlug, value );
|
||||
//
|
||||
// /// etc ...
|
||||
// }
|
||||
//
|
||||
// MStatus CMyCmd::undoIt( const MArgList &mArgList )
|
||||
// {
|
||||
// m_undo.Undo();
|
||||
// }
|
||||
//
|
||||
// bool CMyCmd::isUndoable()
|
||||
// {
|
||||
// return m_undo.IsUndoable();
|
||||
// }
|
||||
//
|
||||
// If there's a need to get fancy, any of the CUndoOp* classes can be
|
||||
// constructed via 'new' and a boost::shared_ptr< CUndoOp > constructed
|
||||
// with that pointed can be passed to CUndo::Push(). Note that means
|
||||
// that the pointer will be managed by boost::shared_ptr so if the
|
||||
// lifetime of the data needs to be controlled by the caller (it shouldn't)
|
||||
// then a shared_ptr should be kept
|
||||
//
|
||||
// Setting the ArgList and using ArgDatabase doesn't affect the undo/redo
|
||||
// ability but it's a convnient place to keep that data
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VALVEMAYA_UNDO_H
|
||||
#define VALVEMAYA_UNDO_H
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
// Standard includes
|
||||
|
||||
|
||||
// Maya includes
|
||||
#include <maya/MArgDatabase.h>
|
||||
#include <maya/MArgList.h>
|
||||
#include <maya/MDagModifier.h>
|
||||
#include <maya/MDagPath.h>
|
||||
#include <maya/MObject.h>
|
||||
#include <maya/MPlug.h>
|
||||
#include <maya/MSelectionList.h>
|
||||
#include <maya/MStatus.h>
|
||||
#include <maya/MString.h>
|
||||
#include <maya/MSyntax.h>
|
||||
#include <maya/MTransformationMatrix.h>
|
||||
|
||||
|
||||
// Valve includes
|
||||
#include "tier1/utlstack.h"
|
||||
|
||||
|
||||
namespace ValveMaya
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class CUndoOp;
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndo: Undo stack manager class
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
class CUndo
|
||||
{
|
||||
public:
|
||||
CUndo();
|
||||
|
||||
~CUndo();
|
||||
|
||||
void Clear();
|
||||
|
||||
MStatus SetArgList(
|
||||
const MSyntax &mSyntax,
|
||||
const MArgList &mArgList );
|
||||
|
||||
const MArgDatabase &ArgDatabase();
|
||||
|
||||
void SaveCurrentSelection();
|
||||
|
||||
MDagModifier &DagModifier();
|
||||
|
||||
MStatus DagModifierDoIt();
|
||||
|
||||
MStatus Connect(
|
||||
const MPlug &srcP,
|
||||
const MPlug &dstP,
|
||||
bool force = false );
|
||||
|
||||
bool SetAttr(
|
||||
MPlug &mPlug,
|
||||
MObject &val );
|
||||
|
||||
bool SetAttr(
|
||||
MPlug &mPlug,
|
||||
double val );
|
||||
|
||||
bool Lock(
|
||||
MPlug &mPlug,
|
||||
bool lock );
|
||||
|
||||
void NodeCreated( MObject &nodeObject );
|
||||
|
||||
void Push(
|
||||
CUndoOp *pUndoOp );
|
||||
|
||||
bool IsUndoable() const;
|
||||
|
||||
MStatus Undo();
|
||||
|
||||
protected:
|
||||
MArgDatabase *m_pArgDatabase;
|
||||
CUtlStack< CUndoOp * > m_undoStack;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndoOp: Undo stack member abstract base class
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOp
|
||||
{
|
||||
public:
|
||||
virtual ~CUndoOp()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo() = 0;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndoOpDagModifier: Undo stack member Dag Modifier class
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOpDagModifier : public CUndoOp
|
||||
{
|
||||
public:
|
||||
virtual ~CUndoOpDagModifier()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo()
|
||||
{
|
||||
m_mDagModifier.undoIt();
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class CUndo;
|
||||
|
||||
MDagModifier m_mDagModifier;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndoOpSetAttr: Undo stack member for setting attributes
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOpSetAttr : public CUndoOp
|
||||
{
|
||||
public:
|
||||
CUndoOpSetAttr(
|
||||
MPlug &mPlug,
|
||||
MObject &mObjectVal );
|
||||
|
||||
CUndoOpSetAttr(
|
||||
MPlug &mPlug,
|
||||
double numericVal );
|
||||
|
||||
virtual ~CUndoOpSetAttr()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo();
|
||||
|
||||
protected:
|
||||
MPlug m_mPlug;
|
||||
MObject m_mObjectVal;
|
||||
double m_numericVal;
|
||||
const bool m_numeric;
|
||||
|
||||
private:
|
||||
// Visual C++ is retarded - tell it there's no assignment operator
|
||||
CUndoOpSetAttr &operator=( const CUndoOpSetAttr &rhs );
|
||||
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndoOpSelection: Undo stack member for changing selection
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOpSelection : public CUndoOp
|
||||
{
|
||||
public:
|
||||
CUndoOpSelection();
|
||||
|
||||
virtual ~CUndoOpSelection()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo();
|
||||
|
||||
protected:
|
||||
MSelectionList m_mSelectionList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
// CUndoOpSelection: Undo stack member for locking and unlocking attributes
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOpLock : public CUndoOp
|
||||
{
|
||||
public:
|
||||
|
||||
CUndoOpLock(
|
||||
MPlug &mPlug,
|
||||
bool lock );
|
||||
|
||||
virtual ~CUndoOpLock()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo();
|
||||
|
||||
protected:
|
||||
MPlug m_mPlug;
|
||||
const bool m_locked;
|
||||
|
||||
private:
|
||||
// Visual C++ is retarded - tell it there's no assignment operator
|
||||
CUndoOpLock &operator=( const CUndoOpLock &rhs );
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//=============================================================================
|
||||
class CUndoOpResetRestPosition : public CUndoOp
|
||||
{
|
||||
public:
|
||||
CUndoOpResetRestPosition(
|
||||
const MDagPath &mDagPath );
|
||||
|
||||
virtual ~CUndoOpResetRestPosition()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo();
|
||||
|
||||
protected:
|
||||
const MDagPath m_mDagPath;
|
||||
MTransformationMatrix m_matrix;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// For node creation via something like MFnMesh::create, etc..
|
||||
//=============================================================================
|
||||
class CUndoOpNodeCreated : public CUndoOp
|
||||
{
|
||||
public:
|
||||
CUndoOpNodeCreated(
|
||||
MObject &mObject );
|
||||
|
||||
virtual ~CUndoOpNodeCreated()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Undo();
|
||||
|
||||
protected:
|
||||
MObject m_nodeObject;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
#endif // VALVEMAYA_UNDO_H
|
Reference in New Issue
Block a user