Beispiel #1
0
INT WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
	char* lpFileChar = NULL;
	INT fileChars;
	if(!readXFile("Warrior.x", NULL, &fileChars))
	{
		goto finallyDo;
	}
	lpFileChar = new CHAR[fileChars];
	if(!readXFile("Warrior.x", &lpFileChar, &fileChars))
	{
		goto finallyDo;
	}

	ID3DXFile* lpXFile = NULL;
	DXvBegin(D3DXFileCreate(&lpXFile))
		goto finallyDo;
	DXvEnd

	DXvBegin(lpXFile->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES))
		goto finallyDo;
	DXvEnd

	DXvBegin(lpXFile->RegisterTemplates(lpFileChar, strlen(lpFileChar)))
		goto finallyDo;
	DXvEnd

	parseXFile(lpXFile);

finallyDo:
	delete []lpFileChar;
	DXreleaseCom(lpXFile);

	return 0;
}
Beispiel #2
0
bool loadXFile( const std::string& filename, FrameNode* rootFrameNode, LPDIRECT3DDEVICE9 d3dDevice )
{
    ID3DXFile* dxFile = 0;
    ID3DXFileEnumObject* dxFileEnum = 0;

    // Create the file parsing structure
    if( APP_ERROR( FAILED( D3DXFileCreate( &dxFile ) ) )( "Couldn't create IDirectXFile to parse source file" ) )
        goto FAILED;

    // Register templates for parsing an X file
    if( APP_ERROR( FAILED( dxFile->RegisterTemplates( (LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES ) ) )
            ( "Failed to register D3DRM X-file templates" ) )
        goto FAILED;

    // Register extended templates for parsing an X file
    if( APP_ERROR( FAILED( dxFile->RegisterTemplates( (LPVOID)XSKINEXP_TEMPLATES, sizeof(XSKINEXP_TEMPLATES) - 1 ) ) )
            ( "Failed to register extended X-file templates" ) )
        goto FAILED;

    // Create an enumerator so that we can look at the top-level entries in the file
    if( APP_ERROR( FAILED( dxFile->CreateEnumObject( (LPCVOID)filename.c_str(), D3DXF_FILELOAD_FROMFILE, &dxFileEnum ) ) )
            ( "Couldn't create enumerator for .X file in memory" ) )
        goto FAILED;

    // Scan all of the top-level objects in the file
    bool continueLoading = true;
    SIZE_T numberOfChildren;
    dxFileEnum->GetChildren( &numberOfChildren );
    for( SIZE_T i = 0; continueLoading && i < numberOfChildren; ++i )
    {
        ID3DXFileData* dxFileDataObject = NULL;
        continueLoading = !APP_ERROR( FAILED( dxFileEnum->GetChild( i, &dxFileDataObject ) ) || !rootFrameNode->load( dxFileDataObject, d3dDevice ) )( "Couldn't load element" );
        SAFE_RELEASE( dxFileDataObject );
    }

    // Free the file objects
    SAFE_RELEASE( dxFileEnum );
    SAFE_RELEASE( dxFile );

    // Success
    return true;


FAILED:

    SAFE_RELEASE( dxFileEnum );
    SAFE_RELEASE( dxFile );

    return false;
}
Beispiel #3
0
INT WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
	ID3DXFile* lpXFile;

	if(FAILED(D3DXFileCreate(&lpXFile)))
	{
		return 0;
	}

	if(FAILED(lpXFile->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES)))
	{
		lpXFile->Release();
		return 0;
	}

	parseXFile(lpXFile);
	lpXFile->Release();

	return 0;
}
Beispiel #4
0
//-----------------------------------------------------------------------------
HRESULT CDXUTMeshFile::Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename )
{
    LPD3DXFILE           pDXFile   = NULL;
    LPD3DXFILEENUMOBJECT pEnumObj  = NULL;
    LPD3DXFILEDATA       pFileData = NULL;
    HRESULT hr;
    SIZE_T cChildren;

    // Create a x file object
    if( FAILED( hr = D3DXFileCreate( &pDXFile ) ) )
        return E_FAIL;

    // Register templates for d3drm and patch extensions.
    if( FAILED( hr = pDXFile->RegisterTemplates( (void*)D3DRM_XTEMPLATES,
                                                 D3DRM_XTEMPLATE_BYTES ) ) )
    {
        SAFE_RELEASE( pDXFile );
        return E_FAIL;
    }

    // Find the path to the file, and convert it to ANSI (for the D3DXOF API)
    WCHAR strPath[MAX_PATH];
    CHAR  strPathANSI[MAX_PATH];
    DXUTFindDXSDKMediaFileCch( strPath, sizeof(strPath) / sizeof(WCHAR), strFilename );
    
    
    WideCharToMultiByte( CP_ACP, 0, strPath, -1, strPathANSI, MAX_PATH, NULL, NULL );
    strPathANSI[MAX_PATH-1] = 0;

    
    // Create enum object
    hr = pDXFile->CreateEnumObject( (void*)strPathANSI, D3DXF_FILELOAD_FROMFILE, 
                                    &pEnumObj );
    if( FAILED(hr) )
    {
        SAFE_RELEASE( pDXFile );
        return hr;
    }

    // Enumerate top level objects (which are always frames)
    pEnumObj->GetChildren(&cChildren);
    for (UINT iChild = 0; iChild < cChildren; iChild++)
    {
        hr = pEnumObj->GetChild(iChild, &pFileData);
        if (FAILED(hr))
            return hr;

        hr = LoadFrame( pd3dDevice, pFileData, this );
        SAFE_RELEASE( pFileData );
        if( FAILED(hr) )
        {
            SAFE_RELEASE( pEnumObj );
            SAFE_RELEASE( pDXFile );
            return E_FAIL;
        }
    }

    SAFE_RELEASE( pFileData );
    SAFE_RELEASE( pEnumObj );
    SAFE_RELEASE( pDXFile );

    return S_OK;
}
Beispiel #5
0
//-----------------------------------------------------------------------------
HRESULT CDXUTMeshFile::CreateFromResource( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strResource, LPCWSTR strType )
{
    LPD3DXFILE           pDXFile   = NULL;
    LPD3DXFILEENUMOBJECT pEnumObj  = NULL;
    LPD3DXFILEDATA       pFileData = NULL;
    HRESULT hr;
    SIZE_T cChildren;

    // Create a x file object
    if( FAILED( hr = D3DXFileCreate( &pDXFile ) ) )
        return E_FAIL;

    // Register templates for d3drm and patch extensions.
    if( FAILED( hr = pDXFile->RegisterTemplates( (void*)D3DRM_XTEMPLATES,
                                                 D3DRM_XTEMPLATE_BYTES ) ) )
    {
        SAFE_RELEASE( pDXFile );
        return E_FAIL;
    }
    
    CHAR strTypeAnsi[MAX_PATH];
    CHAR strResourceAnsi[MAX_PATH];

    WideCharToMultiByte( CP_ACP, 0, strType, -1, strTypeAnsi, MAX_PATH, NULL, NULL );
    strTypeAnsi[MAX_PATH-1] = 0;

    WideCharToMultiByte( CP_ACP, 0, strResource, -1, strResourceAnsi, MAX_PATH, NULL, NULL );
    strResourceAnsi[MAX_PATH-1] = 0;

    D3DXF_FILELOADRESOURCE dxlr;
    dxlr.hModule = NULL;
    dxlr.lpName = strResourceAnsi;
    dxlr.lpType = strTypeAnsi;

    // Create enum object
    hr = pDXFile->CreateEnumObject( (void*)&dxlr, D3DXF_FILELOAD_FROMRESOURCE, 
                                    &pEnumObj );
    if( FAILED(hr) )
    {
        SAFE_RELEASE( pDXFile );
        return hr;
    }

    // Enumerate top level objects (which are always frames)
    pEnumObj->GetChildren(&cChildren);
    for (UINT iChild = 0; iChild < cChildren; iChild++)
    {
        hr = pEnumObj->GetChild(iChild, &pFileData);
        if (FAILED(hr))
            return hr;

        hr = LoadFrame( pd3dDevice, pFileData, this );
        SAFE_RELEASE( pFileData );
        if( FAILED(hr) )
        {
            SAFE_RELEASE( pEnumObj );
            SAFE_RELEASE( pDXFile );
            return E_FAIL;
        }
    }

    SAFE_RELEASE( pFileData );
    SAFE_RELEASE( pEnumObj );
    SAFE_RELEASE( pDXFile );

    return S_OK;
}
Beispiel #6
0
	XFileEnv::XFileEnv()
	{
		D3DXFileCreate(&(*this));
	}
BOOL cMesh::Load(cGraphics *Graphics, char *Filename, char *TexturePath)
{
  ID3DXFile           *pDXFile = NULL;
  ID3DXFileEnumObject *pDXEnum = NULL;
  ID3DXFileData       *pDXData = NULL;
  sFrame                 *TempFrame, *FramePtr;
  sMesh                  *Mesh;

  // Free prior mesh object data
  Free();

  // Error checking
  if((m_Graphics = Graphics) == NULL || Filename == NULL)
    return FALSE;

  // Create the file object
  if(FAILED(D3DXFileCreate(&pDXFile)))	  
    return FALSE;

  // Register the templates
  if(FAILED(pDXFile->RegisterTemplates((LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES))) {
    pDXFile->Release();
    return FALSE;
  }

  // Create an enumeration object
  if(FAILED(pDXFile->CreateEnumObject((LPVOID)Filename, DXFILELOAD_FROMFILE, &pDXEnum))) {
    pDXFile->Release();
    return FALSE;
  }

  // Create a temporary frame
  TempFrame = new sFrame();

  SIZE_T count;

  if (FAILED(pDXEnum->GetChildren(&count)))
  {
	  return FALSE;
  }

  SIZE_T c = 0;

  // Loop through all objects looking for the frames and meshes
  while(c < count) {
	if (FAILED(pDXEnum->GetChild(c, &pDXData)))
		return FALSE;
    c++;
    ParseXFileData(pDXData, TempFrame, TexturePath);
    ReleaseCOM(pDXData);
  }

  // Release used COM objects
  ReleaseCOM(pDXEnum);
  ReleaseCOM(pDXFile);

  // See if we should keep the tempframe as root
  if(TempFrame->m_MeshList != NULL) {
    m_Frames = TempFrame;
    m_Frames->m_Name = new char[7];
    strcpy(m_Frames->m_Name, "%ROOT%");
  } else {
    // Assign the root frame and release temporary frame
    m_Frames = TempFrame->m_Child;
    FramePtr = m_Frames;
    while(FramePtr != NULL) {
      FramePtr->m_Parent = NULL;
      FramePtr = FramePtr->m_Sibling;
    }
    TempFrame->m_Child = NULL;
    delete TempFrame;
  }

  // Match frames to bones (for matrices)
  MapFramesToBones(m_Frames);

  // Calculate bounding box and sphere
  if((Mesh = m_Meshes) != NULL) {
    while(Mesh != NULL) {
      m_Min.x = min(m_Min.x, Mesh->m_Min.x);
      m_Min.y = min(m_Min.y, Mesh->m_Min.y);
      m_Min.z = min(m_Min.z, Mesh->m_Min.z);
      m_Max.x = max(m_Max.x, Mesh->m_Max.x);
      m_Max.y = max(m_Max.y, Mesh->m_Max.y);
      m_Max.z = max(m_Max.z, Mesh->m_Max.z);
      m_Radius = max(m_Radius, Mesh->m_Radius);

      Mesh = Mesh->m_Next;
    }
  }

  return TRUE;
}
Beispiel #8
0
XFileUtils::XFileUtils()
	:m_GuidMap(), m_pFile(nullptr), m_UnknownString("Unknown")
{
	{
		m_GuidMap.insert(container_type::value_type("AnimationOptions",GuidFromString("E2BF56C0-840F-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("AnimTicksPerSecond",GuidFromString("9E415A43-7BA6-4a73-8743-B73D47E88476") ));
		m_GuidMap.insert(container_type::value_type("Boolean",GuidFromString("537da6a0-ca37-11d0-941c-0080c80cfa7b") ));
		m_GuidMap.insert(container_type::value_type("Boolean2d",GuidFromString("4885AE63-78E8-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("ColorRGB",GuidFromString("D3E16E81-7835-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("ColorRGBA",GuidFromString("35FF44E0-6C7C-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("IndexedColor",GuidFromString("1630B820-7842-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("CompressedAnimationSet",GuidFromString("7F9B00B3-F125-4890-876E-1C42BF697C4D") ));
		m_GuidMap.insert(container_type::value_type("Coords2d",GuidFromString("F6F23F44-7686-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("EffectDWord",GuidFromString("622C0ED0-956E-4da9-908A-2AF94F3CE716") ));
		m_GuidMap.insert(container_type::value_type("EffectFloats",GuidFromString("F1CFE2B3-0DE3-4e28-AFA1-155A750A282D") ));
		m_GuidMap.insert(container_type::value_type("Animation",GuidFromString("3D82AB4F-62DA-11cf-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("EffectParamDWord",GuidFromString("E13963BC-AE51-4c5d-B00F-CFA3A9D97CE5") ));
		m_GuidMap.insert(container_type::value_type("EffectParamFloats",GuidFromString("3014B9A0-62F5-478c-9B86-E4AC9F4E418B") ));
		m_GuidMap.insert(container_type::value_type("EffectParamString",GuidFromString("1DBC4C88-94C1-46ee-9076-2C28818C9481") ));
		m_GuidMap.insert(container_type::value_type("EffectString",GuidFromString("D55B097E-BDB6-4c52-B03D-6051C89D0E42") ));
		m_GuidMap.insert(container_type::value_type("EffectInstance",GuidFromString("E331F7E4-0559-4cc2-8E99-1CEC1657928F") ));
		m_GuidMap.insert(container_type::value_type("FaceAdjacency",GuidFromString("A64C844A-E282-4756-8B80-250CDE04398C") ));
		m_GuidMap.insert(container_type::value_type("FloatKeys",GuidFromString("10DD46A9-775B-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("FVFData",GuidFromString("B6E70A0E-8EF9-4e83-94AD-ECC8B0C04897") ));
		m_GuidMap.insert(container_type::value_type("Guid",GuidFromString("a42790e0-7810-11cf-8f52-0040333594a3") ));
		m_GuidMap.insert(container_type::value_type("MaterialWrap",GuidFromString("4885ae60-78e8-11cf-8f52-0040333594a3") ));
		m_GuidMap.insert(container_type::value_type("Matrix4x4",GuidFromString("F6F23F45-7686-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("MeshFace",GuidFromString("3D82AB5F-62DA-11cf-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("Patch",GuidFromString("A3EB5D44-FC22-429D-9AFB-3221CB9719A6") ));
		m_GuidMap.insert(container_type::value_type("PMAttributeRange",GuidFromString("917E0427-C61E-4a14-9C64-AFE65F9E9844") ));
		m_GuidMap.insert(container_type::value_type("Vector",GuidFromString("3D82AB5E-62DA-11cf-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("VertexDuplicationIndices",GuidFromString("B8D65549-D7C9-4995-89CF-53A9A8B031E3") ));
		m_GuidMap.insert(container_type::value_type("VertexElement",GuidFromString("F752461C-1E23-48f6-B9F8-8350850F336F") ));
		m_GuidMap.insert(container_type::value_type("XSkinMeshHeader",GuidFromString("3CF169CE-FF7C-44ab-93C0-F78F62D172E2") ));
		m_GuidMap.insert(container_type::value_type("PMVSplitRecord",GuidFromString("574CCC14-F0B3-4333-822D-93E8A8A08E4C") ));
		m_GuidMap.insert(container_type::value_type("TextureFilename",GuidFromString("A42790E1-7810-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("Material",GuidFromString("3D82AB4D-62DA-11CF-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("TimedFloatKeys",GuidFromString("F406B180-7B3B-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("AnimationKey",GuidFromString("10DD46A8-775B-11CF-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("FrameTransformMatrix",GuidFromString("F6F23F41-7686-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("AnimationSet",GuidFromString("3D82AB50-62DA-11cf-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("DeclData",GuidFromString("BF22E553-292C-4781-9FEA-62BD554BDD93") ));
		m_GuidMap.insert(container_type::value_type("MeshFaceWraps",GuidFromString("ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B") ));
		m_GuidMap.insert(container_type::value_type("MeshNormals",GuidFromString("F6F23F43-7686-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("MeshTextureCoords",GuidFromString("F6F23F40-7686-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("MeshVertexColors",GuidFromString("1630B821-7842-11cf-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("MeshMaterialList",GuidFromString("F6F23F42-7686-11CF-8F52-0040333594A3") ));
		m_GuidMap.insert(container_type::value_type("SkinWeights",GuidFromString("6F0D123B-BAD2-4167-A0D0-80224F25FABB") ));
		m_GuidMap.insert(container_type::value_type("PMInfo",GuidFromString("B6C3E656-EC8B-4b92-9B62-681659522947") ));
		m_GuidMap.insert(container_type::value_type("Mesh",GuidFromString("3D82AB44-62DA-11CF-AB39-0020AF71E433") ));
		m_GuidMap.insert(container_type::value_type("PatchMesh",GuidFromString("D02C95CC-EDBA-4305-9B5D-1820D7704BBF") ));
		m_GuidMap.insert(container_type::value_type("PatchMesh9",GuidFromString("B9EC94E1-B9A6-4251-BA18-94893F02C0EA") ));
		m_GuidMap.insert(container_type::value_type("Frame",GuidFromString("3D82AB46-62DA-11CF-AB39-0020AF71E433") ));
	}

	FILE* f = nullptr;
	errno_t err = fopen_s(&f, "Template.txt", "rb+");
	assert(err == 0);
	char ch = EOF;
	while ((ch = getc(f)) != EOF)
		m_strTemplate.push_back(ch);
	fclose(f);
	D3DXFileCreate(&m_pFile);
	HRESULT result = m_pFile->RegisterTemplates((void*)m_strTemplate.c_str(), (SIZE_T)m_strTemplate.size());
	HRESULT re = D3DXFERR_PARSEERROR;
	assert(SUCCEEDED(result));
}