📄 mdlviewer.cpp
字号:
CChoreoScene *scene = g_pChoreoView->GetScene();
if ( scene )
{
CChoiceParams params;
strcpy( params.m_szDialogTitle, "Associate Actor" );
params.m_bPositionDialog = false;
params.m_nLeft = 0;
params.m_nTop = 0;
strcpy( params.m_szPrompt, "Choose actor:" );
params.m_Choices.RemoveAll();
params.m_nSelected = -1;
int oldsel = -1;
int c = scene->GetNumActors();
ChoiceText text;
for ( int i = 0; i < c; i++ )
{
CChoreoActor *a = scene->GetActor( i );
Assert( a );
strcpy( text.choice, a->GetName() );
if ( !stricmp( a->GetFacePoserModelName(), modelname ) )
{
params.m_nSelected = i;
oldsel = -1;
}
params.m_Choices.AddToTail( text );
}
if ( ChoiceProperties( ¶ms ) &&
params.m_nSelected != oldsel )
{
// Chose something new...
CChoreoActor *a = scene->GetActor( params.m_nSelected );
g_pChoreoView->AssociateModelToActor( a, idx );
}
}
}
}
}
}
break;
}
if ( iret )
return iret;
return BaseClass::handleEvent( event );
}
void HandleModelSelect( void )
{
int idx = getSelectedIndex();
if ( idx < 0 )
return;
// FIXME: Do any necessary window resetting here!!!
g_pControlPanel->OnModelChanged( models->GetModelFileName( idx ) );
}
void Init( void )
{
removeAll();
int c = models->Count();
int i;
for ( i = 0; i < c ; i++ )
{
char const *name = models->GetModelName( i );
add( name );
}
}
};
#define IDC_TOOL_TOGGLEVISIBILITY 1000
#define IDC_TOOL_TOGGLELOCK 1001
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CMDLViewerWindowTab : public CTabWindow
{
public:
typedef CTabWindow BaseClass;
CMDLViewerWindowTab( mxWindow *parent, int x, int y, int w, int h, int id = 0, int style = 0 ) :
CTabWindow( parent, x, y, w, h, id, style )
{
SetInverted( true );
m_nLastSelected = -1;
m_flLastSelectedTime = -1;
}
virtual void ShowRightClickMenu( int mx, int my )
{
IFacePoserToolWindow *tool = GetSelectedTool();
if ( !tool )
return;
mxWindow *toolw = tool->GetMxWindow();
if ( !toolw )
return;
mxPopupMenu *pop = new mxPopupMenu();
Assert( pop );
bool isVisible = toolw->isVisible();
bool isLocked = tool->IsLocked();
pop->add( isVisible ? "Hide" : "Show", IDC_TOOL_TOGGLEVISIBILITY );
pop->add( isLocked ? "Unlock" : "Lock", IDC_TOOL_TOGGLELOCK );
// Convert click position
POINT pt;
pt.x = mx;
pt.y = my;
/*
ClientToScreen( (HWND)getHandle(), &pt );
ScreenToClient( (HWND)g_MDLViewer->getHandle(), &pt );
*/
// Convert coordinate space
pop->popup( this, pt.x, pt.y );
}
virtual int handleEvent( mxEvent *event )
{
int iret = 0;
switch ( event->event )
{
case mxEvent::Action:
{
iret = 1;
switch ( event->action )
{
default:
iret = 0;
break;
case IDC_TOOL_TOGGLEVISIBILITY:
{
IFacePoserToolWindow *tool = GetSelectedTool();
if ( tool )
{
mxWindow *toolw = tool->GetMxWindow();
if ( toolw )
{
toolw->setVisible( !toolw->isVisible() );
g_MDLViewer->UpdateWindowMenu();
}
}
}
break;
case IDC_TOOL_TOGGLELOCK:
{
IFacePoserToolWindow *tool = GetSelectedTool();
if ( tool )
{
tool->ToggleLockedState();
}
}
break;
}
}
break;
default:
break;
}
if ( iret )
return iret;
return BaseClass::handleEvent( event );
}
void Init( void )
{
int c = IFacePoserToolWindow::GetToolCount();
int i;
for ( i = 0; i < c ; i++ )
{
IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( i );
add( tool->GetDisplayNameRoot() );
}
}
#define WINDOW_DOUBLECLICK_TIME 0.4
void HandleWindowSelect( void )
{
extern double realtime;
IFacePoserToolWindow *tool = GetSelectedTool();
if ( !tool )
return;
bool doubleclicked = false;
double curtime = realtime;
int clickedItem = getSelectedIndex();
if ( clickedItem == m_nLastSelected )
{
if ( curtime < m_flLastSelectedTime + WINDOW_DOUBLECLICK_TIME )
{
doubleclicked = true;
}
}
m_flLastSelectedTime = curtime;
m_nLastSelected = clickedItem;
mxWindow *toolw = tool->GetMxWindow();
if ( !toolw )
return;
if ( doubleclicked )
{
toolw->setVisible( !toolw->isVisible() );
m_flLastSelectedTime = -1;
}
if ( !toolw->isVisible() )
{
return;
}
// Move window to front
HWND wnd = (HWND)tool->GetMxWindow()->getHandle();
SetFocus( wnd );
SetWindowPos( wnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
private:
IFacePoserToolWindow *GetSelectedTool()
{
int idx = getSelectedIndex();
int c = IFacePoserToolWindow::GetToolCount();
if ( idx < 0 || idx >= c )
return NULL;
IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( idx );
return tool;
}
// HACKY double click handler
int m_nLastSelected;
double m_flLastSelectedTime;
};
//-----------------------------------------------------------------------------
// Purpose: The workspace is the parent of all of the tool windows
//-----------------------------------------------------------------------------
class CMDLViewerWorkspace : public mxWindow
{
public:
CMDLViewerWorkspace( mxWindow *parent, int x, int y, int w, int h, const char *label = 0, int style = 0)
: mxWindow( parent, x, y, w, h, label, style )
{
FacePoser_AddWindowStyle( this, WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS );
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool PaintBackground( void )
{
CChoreoWidgetDrawHelper drawHelper( this );
RECT rc;
drawHelper.GetClientRect( rc );
drawHelper.DrawFilledRect( GetSysColor( COLOR_APPWORKSPACE ), rc );
return false;
}
};
void MDLViewer::LoadPosition( void )
{
bool visible;
bool locked;
bool zoomed;
int x, y, w, h;
FacePoser_LoadWindowPositions( "MDLViewer", visible, x, y, w, h, locked, zoomed );
if ( w == 0 || h == 0 )
{
zoomed = true;
visible = true;
}
setBounds( x, y, w, h );
if ( zoomed )
{
ShowWindow( (HWND)getHandle(), SW_SHOWMAXIMIZED );
}
else
{
setVisible( visible );
}
}
void MDLViewer::SavePosition( void )
{
bool visible;
int xpos, ypos, width, height;
visible = isVisible();
xpos = x();
ypos = y();
width = w();
height = h();
// xpos and ypos are screen space
POINT pt;
pt.x = xpos;
pt.y = ypos;
// Convert from screen space to relative to client area of parent window so
// the setBounds == MoveWindow call will offset to the same location
if ( getParent() )
{
ScreenToClient( (HWND)getParent()->getHandle(), &pt );
xpos = (short)pt.x;
ypos = (short)pt.y;
}
bool zoomed = IsZoomed( (HWND)getHandle() ) ? true : false;
FacePoser_SaveWindowPositions( "MDLViewer", visible, xpos, ypos, width, height, false, zoomed );
}
MDLViewer::MDLViewer ()
: mxWindow (0, 0, 0, 0, 0, g_appTitle, mxWindow::Normal)
{
int i;
g_MDLViewer = this;
FacePoser_MakeToolWindow( this, false );
workspace = new CMDLViewerWorkspace( this, 0, 0, 500, 500, "" );
windowtab = new CMDLViewerWindowTab( this, 0, 500, 500, 20, IDC_WINDOW_TAB );
modeltab = new CMDLViewerModelTab( this, 500, 500, 100, 20, IDC_MODEL_TAB );
gridsettings = new CMDLViewerGridSettings( this, 0, 500, 500, 20 );
modeltab->SetRightJustify( true );
g_pStatusWindow = new mxStatusWindow( workspace, 0, 0, 1024, 150, "" );
g_pStatusWindow->setVisible( true );
InitViewerSettings( "faceposer" );
g_viewerSettings.speechapiindex = SPEECH_API_LIPSINC;
g_viewerSettings.flHeadTurn = 0.0f;
g_viewerSettings.m_iEditAttachment = -1;
LoadPosition();
// ShowWindow( (HWND)getHandle(), SW_SHOWMAXIMIZED );
g_pStatusWindow->setBounds( 0, h2() - 150, w2(), 150 );
Con_Printf( "MDLViewer started\n" );
Con_Printf( "CSoundEmitterSystemBase::Init()\n" );
soundemitter->BaseInit();
Con_Printf( "Creating menu bar\n" );
// create menu stuff
mb = new mxMenuBar (this);
menuFile = new mxMenu ();
menuOptions = new mxMenu ();
menuWindow = new mxMenu ();
menuHelp = new mxMenu ();
menuEdit = new mxMenu ();
menuExpressions = new mxMenu();
menuChoreography = new mxMenu();
mb->addMenu ("File", menuFile);
mb->addMenu( "Edit", menuEdit );
mb->addMenu ("Options", menuOptions);
mb->addMenu ( "Expression", menuExpressions );
mb->addMenu ( "Choreography", menuChoreography );
mb->addMenu ("Window", menuWindow);
mb->addMenu ("Help", menuHelp);
mxMenu *menuRecentModels = new mxMenu ();
menuRecentModels->add ("(empty)", IDC_FILE_RECENTMODELS1);
menuRecentModels->add ("(empty)", IDC_FILE_RECENTMODELS2);
menuRecentModels->add ("(empty)", IDC_FILE_RECENTMODELS3);
menuRecentModels->add ("(empty)", IDC_FILE_RECENTMODELS4);
menuFile->add ("Load Model...", IDC_FILE_LOADMODEL);
menuFile->add( "Refresh\tF5", IDC_FILE_REFRESH );
menuFile->addSeparator();
menuFile->add ("Load Background Texture...", IDC_FILE_LOADBACKGROUNDTEX);
menuFile->add ("Load Ground Texture...", IDC_FILE_LOADGROUNDTEX);
menuFile->addSeparator ();
menuFile->add ("Unload Ground Texture", IDC_FILE_UNLOADGROUNDTEX);
menuFile->addSeparator ();
menuFile->addMenu ("Recent Models", menuRecentModels);
menuFile->addSeparator ();
menuFile->add ("Exit", IDC_FILE_EXIT);
menuFile->setEnabled(IDC_FILE_LOADBACKGROUNDTEX, false);
menuFile->setEnabled(IDC_FILE_LOADGROUNDTEX, false);
menuFile->setEnabled(IDC_FILE_UNLOADGROUNDTEX, false);
menuEdit->add( "&Undo\tCtrl+Z", IDC_EDIT_UNDO );
//menuFile->setEnabled( IDC_EDIT_UNDO, false );
menuEdit->add( "&Redo\tCtrl+Y", IDC_EDIT_REDO );
//menuFile->setEnabled( IDC_EDIT_REDO, false );
menuEdit->addSeparator();
menuEdit->add( "&Copy\tCtrl+C", IDC_EDIT_COPY );
menuEdit->add( "&Paste\tCtrl+V", IDC_EDIT_PASTE );
menuOptions->add ("Background Color...", IDC_OPTIONS_COLORBACKGROUND);
menuOptions->add ("Ground Color...", IDC_OPTIONS_COLORGROUND);
menuOptions->add ("Light Color...", IDC_OPTIONS_COLORLIGHT);
menuOptions->addSeparator ();
menuOptions->add ("Center View", IDC_OPTIONS_CENTERVIEW);
menuOptions->add ("Center on Face", IDC_OPTIONS_CENTERONFACE );
#ifdef WIN32
menuOptions->addSeparator ();
menuOptions->add ("Make Screenshot...", IDC_OPTIONS_MAKESCREENSHOT);
//menuOptions->add ("Dump Model Info", IDC_OPTIONS_DUMP);
#endif
menuExpressions->add( "New...", IDC_EXPRESSIONS_NEW );
menuExpressions->addSeparator ();
menuExpressions->add( "Load...", IDC_EXPRESSIONS_LOAD );
menuExpressions->add( "Save", IDC_EXPRESSIONS_SAVE );
menuExpressions->addSeparator ();
menuExpressions->add( "Export to VFE", IDC_EXPRESSIONS_EXPORT );
menuExpressions->addSeparator ();
menuExpressions->add( "Close class", IDC_EXPRESSIONS_CLOSE );
menuExpressions->add( "Close all classes", IDC_EXPRESSIONS_CLOSEALL );
menuExpressions->addSeparator();
menuExpressions->add( "Recreate all bitmaps", IDC_EXPRESSIONS_REDOBITMAPS );
menuChoreography->add( "New...", IDC_CHOREOSCENE_NEW );
menuChoreography->addSeparator();
menuChoreography->add( "Load...", IDC_CHOREOSCENE_LOAD );
menuChoreography->add( "Save", IDC_CHOREOSCENE_SAVE );
menuChoreography->add( "Save As...", IDC_CHOREOSCENE_SAVEAS );
menuChoreography->addSeparator();
menuChoreography->add( "Close", IDC_CHOREOSCENE_CLOSE );
menuChoreography->addSeparator();
menuChoreography->add( "Add Actor...", IDC_CHOREOSCENE_ADDACTOR );
#ifdef WIN32
menuHelp->add ("Goto Homepage...", IDC_HELP_GOTOHOMEPAGE);
menuHelp->addSeparator ();
#endif
menuHelp->add ("About...", IDC_HELP_ABOUT);
// create the Material System window
Con_Printf( "Creating 3D View\n" );
g_pMatSysWindow = new MatSysWindow (workspace, 0, 0, 0, 0, "", mxWindow::Normal);
Con_Printf( "Creating control panel\n" );
g_pControlPanel = new ControlPanel (workspace);
Con_Printf( "Creating phoneme editor\n" );
g_pPhonemeEditor = new PhonemeEditor( workspace );
Con_Printf( "Creating expression tool\n" );
g_pExpressionTool = new ExpressionTool( workspace );
Con_Printf( "Creating gesture tool\n" );
g_pGestureTool = new GestureTool( workspace );
Con_Printf( "Creating ramp tool\n" );
g_pRampTool = new RampTool( workspace );
Con_Printf( "Creating scene ramp tool\n" );
g_pSceneRampTool = new SceneRampTool( workspace );
Con_Printf( "Creating expression tray\n" );
g_pExpressionTrayTool = new mxExpressionTray( workspace, IDC_EXPRESSIONTRAY );
Con_Printf( "Creating flex slider window\n" );
g_pFlexPanel = new FlexPanel( workspace );
Con_Printf( "Creating choreography view\n" );
g_pChoreoView = new CChoreoView( workspace, 200, 200, 400, 300, 0 );
// Choreo scene file drives main window title name
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -