Custom view in XSI

From: Alexandre Jean Claude [ajclaude@softimage.com]
Sent: Thursday, April 18, 2002 7:35 PM
To: 'billvb@valvesoftware.com'
Cc: Dominic Laflamme; Gareth Morgan; Marc Stevens
Subject: Custom view in XSI
Follow Up Flag: Follow up
Flag Status: Flagged

Hello Bill, and everyone at Valve. Please forward to anyone concerned by this

Backgrounder
Following our discussions at GDC, here are the goals of this features

- Provide a customizable window context that a user-plugin will use to display a custom runtime engine
- Provide hooks between XSI and that window context to communicate scene data
- The window does not need to be embedded inside the XSI UI, a floating window seemed to be a good solution

So I've investigated several solutions, and this is the one I came up with that would fit in the current timetable and would meet all the requirements. The solution essentially consists of using the realtime shader architecture are the underlying backbone for communication between XSI and the custom window. In this case, I used a directX window as a test example to show how to circumvent most problems.

Flow of execution

- The user hooks a DXDraw realtime shader on a material
- the DirectX_Shader.dll gets loaded and the dllmain function gets called, initializing a bunch of global states
- the DXDraw_Init function gets called and initializes the entire custom window system (if for the first time). The window that gets created if a top level window (always on top) and is a modeless dialog that runs in the same process space as XSI (and in the same thread). At this point, the window gets initialized, winproc attached and DirectX context initialized.
- the DXDraw_Eval function gets called each time XSI draws in the realtime shader viewport. In here, we first check if we must initialize the DX scene for drawing, then we draw the usual stuff using DirectX (I've added supplemental code to display the geometry in the XSI Ogl window, but this is completely optional if you don't need visual in the rts window). The final thing that happens in the DXDraw_Eval is that the custom window gets dirtified. When XSI completes its own drawing, it also generates a WM_PAINT event that gets sent to the custom window (because it is a child of XSI), the WM_PAINT handler simply swap the buffers and shows up the objects on the screen
- If the DXDraw rts gets deleted, then the plugin checks that no one elses uses the window and automatically closes it, and cleans up the entire custom window system.

Notes

- This is work in progress and crashes can happen
- The update of the custom window may appear jittery sometimes, this is due to the XSI threading mechanism. Let me know if this is a big problem.
- The source code is not compilable without some changes, mainly the include and lib paths in the project settings, let me know if you need help getting setup
- I've written a bunch of functions to synchronize and track the XSI states into the custom window, take a look at these :

// DirectX context functions
void DirectX_Initialize(HWND in_hwnd);
void DirectX_Uninitialize();
void DirectX_Begin();
void DirectX_CheckInvalidEval(LPVOID, LPVOID);
void DirectX_SetWindowDirty();
void DirectX_SetParentWindowDirty();
void DirectX_End();

// DirectX utility functions
void DirectX_DrawGrid();
void DirectX_SetDefaultMaterial();

// DirectX tracking functions
void DirectX_TrackViewMatrix();
void DirectX_TrackWorldMatrix();
void DirectX_TrackProjectionMatrix();
void DirectX_TrackLights();

- I took care of adding comments where it was the most important, but let me know of you want more implementation details.

Instructions on how to install the runtime

- open a Softimage|XSI command prompt
- cd <to the directory where you've extracted the zip file>
- cd generic\spdl
- xsi -i dxdraw.spdl
- copy DirectX_Shaders.dll %XSI_BINDIR%

in XSI you should now have access to DXDraw as a realtime shader. Connect a DXDraw on your material and set the viewport in Realtime Shader mode. You should see the Softimage DirectX Custom View window appear with a replica of your realtime shader viewport.

<<DXCustomView.zip>>

So, we would like to have your feedback on the usability of this solution and if we are on the right track.

Best regards.

Alexandre Jean Claude

Team Leader - Games Team
Softimage
514-845-1636 x3414
mailto:ajclaude@softimage.com