IDirect3DRM::Load

Loads an object.

HRESULT Load(
LPVOID lpvObjSource,
LPVOID lpvObjID,
LPIID * lplpGUIDs,
DWORD dwcGUIDs,
D3DRMLOADOPTIONS d3drmLOFlags,
D3DRMLOADCALLBACK d3drmLoadProc,
LPVOID lpArgLP,
D3DRMLOADTEXTURECALLBACK d3drmLoadTextureProc,
LPVOID lpArgLTP,
LPDIRECT3DRMFRAME lpParentFrame
);

Parameters

lpvObjSource

Source for the object to be loaded. This source can be a file, resource, memory block, or stream, depending on the source flags specified in the d3drmLOFlags parameter.

lpvObjID

Object name or position to be loaded. The use of this parameter depends on the identifier flags specified in the d3drmLOFlags parameter. If the D3DRMLOAD_BYPOSITION flag is specified, this parameter is a pointer to a DWORD value that gives the object's order in the file. This parameter can be NULL.

lplpGUIDs

Address of an array of interface identifiers to be loaded. For example, if this parameter is a two-element array containing IID_IDirect3DRMMeshBuilder and IID_IDirect3DRMAnimationSet, this method loads all the animation sets and mesh-builder objects. Possible GUIDs must be one or more of the following: IID_IDirect3DRMMeshBuilder, IID_IDirect3DRMAnimationSet, IID_IDirect3DRMAnimation, and IID_IDirect3DRMFrame.

dwcGUIDs

Number of elements specified in the lplpGUIDs parameter.

d3drmLOFlags

Value of the D3DRMLOADOPTIONS type describing the load options.

d3drmLoadProc

A D3DRMLOADCALLBACK callback function called when the system reads the specified object.

lpArgLP

Address of application-defined data passed to the D3DRMLOADCALLBACK callback function.

d3drmLoadTextureProc

A D3DRMLOADTEXTURECALLBACK callback function called to load any textures used by an object that require special formatting. This parameter can be NULL.

lpArgLTP

Address of application-defined data passed to the D3DRMLOADTEXTURECALLBACK callback function.

lpParentFrame

Address of a parent Direct3DRMFrame object. This argument only affects the loading of animation sets. When an animation that is loaded from an X file references an unparented frame in the X file, its parent is set to this parent frame argument. However, if you ask Load to load any frames in the X file, the parent frame argument will not be used as the parent frame for frames in the X file with no parent. That is, the parent frame argument is used only when you load animation sets. This value of this argument can be NULL.

Return Values

Returns D3DRM_OK if successful, or an error otherwise. For a list of possible return codes, see Direct3D Retained-Mode Return Values.

Remarks

This method allows great flexibility in loading objects from DirectX files. Here is an example of how to use it:

#include <windows.h>

#include <stdio.h>

#include <initguid.h>

#include <d3drm.h>

LPDIRECT3DRM d3dApi;

int totalMesh = 0, totalAnim = 0, totalFrames = 0;

HRESULT loadTexture(LPSTR name, LPVOID lpArg, LPDIRECT3DRMTEXTURE *tex)

{

return d3dApi->lpVtbl->LoadTexture(d3dApi, name, tex);

}

void loadCallback(LPDIRECT3DRMOBJECT lpObject, REFIID objGuid, LPVOID lpArg)

{

if (IsEqualIID(objGuid, &IID_IDirect3DRMFrame)) {

totalFrames ++;

return;

}

if (IsEqualIID(objGuid, &IID_IDirect3DRMAnimationSet)) {

totalAnim ++;

return;

}

if (IsEqualIID(objGuid, &IID_IDirect3DRMMeshBuilder)) {

totalMesh ++;

return;

}

return;

}

BOOL loadObjects(LPSTR filename)

{

LPGUID guids[] = { (LPGUID)&IID_IDirect3DRMMeshBuilder,

(LPGUID)&IID_IDirect3DRMAnimationSet,

(LPGUID)&IID_IDirect3DRMFrame };

/* Tell the loader which objects you're interested in */

if (FAILED(d3dApi->lpVtbl->Load(d3dApi, filename, NULL,

guids, 3, D3DRMLOAD_FROMFILE,

loadCallback, NULL, loadTexture, NULL, NULL)))

return FALSE;

printf("Total Frames loaded = %d\n", totalFrames);

printf("Total Animation Sets loaded = %d\n", totalAnim);

printf("Total Meshbuilders loaded = %d\n", totalMesh);

return TRUE;

}

int main(int argc, char **argv)

{

if (FAILED(Direct3DRMCreate(&d3dApi)))

return FALSE;

if (argc != 2) {

fprintf(stderr, "usage: %s filename\n", argv[0]);

return FALSE;

}

if (!loadObjects(argv[1])) return FALSE;

return(0);

}