Skip to main content
gamedev.net
🔒 Locked

XFile Loading Class

Started by paranoia33 3 replies 1.2k views
Original Post
paranoia33
paranoia33
I'm having trouble with a Class im writing to load a X-File. The code should be self explanitory..

#include <vector>
#include <math.h>

class CLevel 
{
public: 
	
	ID3DXMesh* mesh;
	ID3DXMesh* meshCollision;
	std::vector<D3DMATERIAL9> Mtrls();
	std::vector<IDirect3DTexture9*> Tex();

	IDirect3DDevice9* Device;

	void setDevice(IDirect3DDevice9* setDevice)
	{
		Device=setDevice;
	}

	void loadLevel(char levelFile[])
	{
		HRESULT hr = 0;
		ID3DXBuffer* adjBuffer = 0;
		ID3DXBuffer* mtrlBuffer = 0;
		DWORD numMtrls = 0;
	
		hr = D3DXLoadMeshFromX(//Load Mesh Data
			levelFile,D3DXMESH_MANAGED,Device,&adjBuffer,&mtrlBuffer,0,&numMtrls,&mesh );

		if(FAILED(hr)) {
			::MessageBox(0,"Mesh Load Unsuccessful","Warning",MB_OK);
		}

		if(mtrlBuffer != 0 && numMtrls != 0) {//Load Textures & Materials
			D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
	
			for(int i = 0; i < (int)numMtrls;i++) {
				mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;
				Mtrls.push_back(mtrls.MatD3D);
				if(mtrls.pTextureFilename!=0) {
					IDirect3DTexture9* tex = 0;
					D3DXCreateTextureFromFile(Device,mtrls.pTextureFilename,&tex);
					Tex.push_back(tex);
				}else{
					Tex.push_back(0);
				}
			}
		}

		d3d::Release<ID3DXBuffer*>(mtrlBuffer);

		//Get Adjacency Info and Optimize Mesh

		hr = mesh->OptimizeInplace(
			D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT | D3DXMESHOPT_VERTEXCACHE,
			(DWORD*)adjBuffer->GetBufferPointer(),0,0,0);
		d3d::Release<ID3DXBuffer*>(adjBuffer);

		if(FAILED(hr)) {
			::MessageBox(0,"Optimization Failed","Warning",MB_OK);
		}

	}

};

and I keep getting the following errors for the Tex.push_back and Mtrls.push_back. error C2228: left of '.push_back' must have class/struct/union type type is 'overloaded-function' Any help or insight is greatly appreciated!!
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/Current Projects:PEngine - Full 3d FPS engine
Trip99
Trip99
My first thought on seeing that was that your Mtrls vector and your D3DXMATERIAL were being mixed up but I notice one has a capital letter and the other does not but even so you could do with renaming one, why not call the vector something like mtrlVector otherwise it will all get horribly confusing. Check you are not mixing them up.
------------------------See my games programming site at: www.toymaker.info
paranoia33
paranoia33
Nope, wasnt the problem....here is the updated source with clearer variable names:

#include "d3dUtility.h"#include <vector>#include <math.h>class CLevel {public: 		ID3DXMesh* mesh;	ID3DXMesh* meshCollision;	std::vector<D3DMATERIAL9> MtrlsVector();	std::vector<IDirect3DTexture9*> TexVector();	IDirect3DDevice9* Device;	void setDevice(IDirect3DDevice9* setDevice)	{		Device=setDevice;	}	void loadLevel(char levelFile[])	{		HRESULT hr = 0;		ID3DXBuffer* adjBuffer = 0;		ID3DXBuffer* mtrlBuffer = 0;		DWORD numMtrls = 0;			hr = D3DXLoadMeshFromX(//Load Mesh Data			levelFile,D3DXMESH_MANAGED,Device,&adjBuffer,&mtrlBuffer,0,&numMtrls,&mesh );		if(FAILED(hr)) {			::MessageBox(0,"Mesh Load Unsuccessful","Warning",MB_OK);		}		if(mtrlBuffer != 0 && numMtrls != 0) {//Load Textures & Materials			D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();				for(int i = 0; i < (int)numMtrls;i++) {				mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;				MtrlsVector.push_back(mtrls.MatD3D);				if(mtrls.pTextureFilename!=0) {					IDirect3DTexture9* tex = 0;					D3DXCreateTextureFromFile(Device,mtrls.pTextureFilename,&tex);					TexVector.push_back(tex);				}else{					TexVector.push_back(0);				}			}		}		d3d::Release<ID3DXBuffer*>(mtrlBuffer);		//Get Adjacency Info and Optimize Mesh		hr = mesh->OptimizeInplace(			D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT | D3DXMESHOPT_VERTEXCACHE,			(DWORD*)adjBuffer->GetBufferPointer(),0,0,0);		d3d::Release<ID3DXBuffer*>(adjBuffer);		if(FAILED(hr)) {			::MessageBox(0,"Optimization Failed","Warning",MB_OK);		}	}};


Help, again, is greatly appreciated!
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/Current Projects:PEngine - Full 3d FPS engine
S1CA
S1CA
Take the brackets off of std::vector<D3DMATERIAL9> Mtrls(); and std::vector<IDirect3DTexture9*> Tex();

Mtrls and Tex are NOT functions - rounded brackets tells C/C++ that they are...

std::vector<D3DMATERIAL9> Mtrls;std::vector<IDirect3DTexture9*> Tex;



[Assuming of course that you're also including d3dx9.h and any other headers/namespaces relevant to d3d::Release and such.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
paranoia33
paranoia33
Thanks ALOT! I must have overlooked that....I just coppied and pasted it with the brackets from another part of my code not in a class....

Thanks again!
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/Current Projects:PEngine - Full 3d FPS engine

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.