Advertisement Jump to content
Sign in to follow this  
ankhd

Does Anyone Know How To Use The BIG DWORD Array In Template DeclData

This topic is 1860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there.

how do you use that dword array, the first array is the vertexElements like so

template VertexElement
{
    < F752461C-1E23-48f6-B9F8-8350850F336F >
    DWORD Type;
    DWORD Method;
    DWORD Usage;
    DWORD UsageIndex;
}
//this tells me what size and position ans some ffp stuff but how do I use the DWORD array in this template

template DeclData
{
    < BF22E553-292C-4781-9FEA-62BD554BDD93 >
    DWORD nElements;
    array VertexElement Elements[nElements];
    DWORD nDWords;
    array DWORD data[nDWords];//here
}
what am I missing help anyone. google not like this one ????????
 

 

Share this post


Link to post
Share on other sites
Advertisement

Im not sure if this is correct but the data is all there

here it is..

I did have to use a float pointer for the DWORD array or it was giving junk values

also I needed to increament the floatpointer by 1 just after getting the data pointer for it.

 if(*Type == DXFILEOBJ_DeclData && Reference == FALSE)
  {
	//we need to pass our declData new 	  
	OutPutDebugText("DXFILEOBJ_DeclData Reference",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

	  //decl data is like this
//	  template DeclData
//{
 //   < BF22E553-292C-4781-9FEA-62BD554BDD93 >
   DWORD nElements = 0;
  
 //   array VertexElement Elements[nElements];
  //  DWORD nDWords;
  //  array DWORD data[nDWords];
//} 


   cParserDeclData ParserDeclData;

   cParserDeclData::cVertexElement *vertexelement = NULL;
	DWORD *DataPtr = NULL;
	DWORD DataSize = 0;
	DWORD nRecords = 0;
	DWORD ndwordsused = 0;
	DWORD elementcount = 0;

	//get the number of elements
	HRESULT hr = pDataObj->GetData("nElements",&DataSize, (void **)&DataPtr);
	if(FAILED(hr))
	{
		OutPutDebugText("DXFILEOBJ_DeclData Failed to get nElements",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

		
	}

	//set the number of elements
	nElements = *DataPtr;



	//get the vertex elements
	//get the vertex elemets first data pointer
	hr = pDataObj->GetData("Elements",&DataSize, (void **)&vertexelement);
	if(FAILED(hr))
	{
		OutPutDebugText("DXFILEOBJ_DeclData Failed to get Elements",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

		
	}

	//we need howmany records we have
	hr = pDataObj->GetData("nDWords",&DataSize, (void **)&DataPtr);
	if(FAILED(hr))
	{
		OutPutDebugText("DXFILEOBJ_DeclData Failed to get nDWords",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

		
	}
		
	nRecords = *DataPtr;


	
	//we need our pointer to the data now
	float *datafloat = NULL;
	hr = pDataObj->GetData("data",&DataSize, (void **)&datafloat);
	if(FAILED(hr))
	{
		OutPutDebugText("DXFILEOBJ_DeclData Failed to get data",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

		
	}

	//not sure if this is right but with out it the first normals x value has junk in it 
	datafloat++;//why this first

	//get the number of DWORDS used
	for(DWORD ctr = 0; ctr < nElements; ctr++)
	{
		elementcount = ParserDeclData.HowManyDwordsForThisType(vertexelement[ctr].Type);
					
		ndwordsused += elementcount;
	}
		
	if( ndwordsused <= 0)
	{
		OutPutDebugText("DXFILEOBJ_DeclData Failed ndwordsused = 0",//the message to display
				"cXMeshParser::ParseObject",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox

		return FALSE;
	}


	//calculate the number of vertices
	DWORD vertexcount = nRecords /ndwordsused;


	//the elements tell us what was saved first so we need to go through all elements and
	//load each data we want 
	for(DWORD ctr = 0; ctr < nElements; ctr++)
	{

		switch(vertexelement[ctr].Usage)
		{
			case D3DDECLUSAGE_NORMAL:
			{
				D3DXVECTOR3 normal;
				//we should have a record for each vertex we have ????
				for(DWORD ctr = 0; ctr < vertexcount; ctr++)
				{
					//normal = (D3DXVECTOR3)*DataPtr;
							//double temp = (double)*DataPtr;
					
					normal.x = (float)*datafloat;
							
					normal.y = (float)*datafloat;
					datafloat++;
					normal.z = (float)*datafloat;
					datafloat++;

					ParserDeclData.m_Normals.push_back(normal);

				}

							
			}break;
			case D3DDECLUSAGE_TEXCOORD:
			{
				for(DWORD ctr = 0; ctr < vertexcount; ctr++)
				{
					//I think I need to read the  data in the order it was saved
		
					D3DXVECTOR2 coords;
					coords.x = (float)*datafloat;
					datafloat++;
					coords.y = (float)*datafloat;
					datafloat++;
							
					ParserDeclData.m_TextCoords.push_back(coords);

				}

			}break;
			case D3DDECLUSAGE_TANGENT:
			{
					D3DXVECTOR3 tangent;
				//we should have a record for each vertex we have ????
				for(DWORD ctr = 0; ctr < vertexcount; ctr++)
				{
					//normal = (D3DXVECTOR3)*DataPtr;
							//double temp = (double)*DataPtr;
					datafloat++;//why this first
					tangent.x = (float)*datafloat;
							
					tangent.y = (float)*datafloat;
					datafloat++;
					tangent.z = (float)*datafloat;
					datafloat++;

					ParserDeclData.m_Tangents.push_back(tangent);

				}
			}break;
			case D3DDECLUSAGE_BINORMAL:
			{
				D3DXVECTOR3 binormal;
				//we should have a record for each vertex we have ????
				for(DWORD ctr = 0; ctr < vertexcount; ctr++)
				{
					//normal = (D3DXVECTOR3)*DataPtr;
							//double temp = (double)*DataPtr;
					datafloat++;//why this first
					binormal.x = (float)*datafloat;
							
					binormal.y = (float)*datafloat;
					datafloat++;
					binormal.z = (float)*datafloat;
					datafloat++;

					ParserDeclData.m_BiNormals.push_back(binormal);

				}
							
			}break;
		
		}//end switch usage index

	}//end all elements


Share this post


Link to post
Share on other sites

datafloat++;//why this first

I think you may delete this line

 

The for loop is not correct, you should use:

for(DWORD ctr = 0; ctr < vertexcount; ctr++)

{

   for(DWORD ctr = 0; ctr < nElements; ctr++)

  {

      ...

  }

}

Take a simple sample: a plane has 4 vertex  (the x file DeclData_Plane1_2011.zip can be found on my download page )

every vertex has a position, normal, texcoord, then the layout is:

  DeclData {
   2;           // nElements == 2 
   2;0;3;0;,    // type == 2 (Float3);  usage == 3 (Normal) 
   1;0;5;0;;    // type == 1 (Float2);  usage == 5 (Texcoord) 
   20;          // nDWords == 20; This because 1 Normal and 1 Texcoord will use 5 DWORD, so 4 * 5 = 20
   0,           // normal0.x == 0
   1065353216,  // normal0.y == 1.0   
   0,           // normal0.z == 0
   0,           // tex0.x == 0
   0,           // tex0.y == 0
   0,           // normal1.x == 0
   1065353216,  // normal1.y == 1.0
   0,           // normal1.y == 0
   1065353216,  // tex1.x == 1.0
   0,           // tex1.y == 0
   0,           // normal2.x == 0
   1065353216,  // normal2.y == 1.0 
   0,           // normal2.z == 0
   0,           // tex2.x == 0
   1065353216,  // tex2.y == 1
   0,           // normal3.x == 0
   1065353216,  // normal3.y == 1.0 
   0,           // normal3.z == 0
   1065353216,  // tex3.x == 1.0
   1065353216;  // tex3.y == 1.0
  }
Edited by Alin

Share this post


Link to post
Share on other sites

Hi. I ran the plane.x mesh through the above code and yes it failed to render right.

 

I now do what you say and the plane.x mesh works.Thanks good spot.

 

It should work now. Here is the updated code.


//every thing above this point was not changed
	//the elements tell us what was saved first so we need to go through all elements and
	//load each data we want 
	//we should have a record for each vertex we have ????
	for(DWORD ctr = 0; ctr < vertexcount; ctr++)
	{
		//for each vertex get its data type
		for(DWORD el = 0; el < nElements; el++)
		{
			switch(vertexelement[el].Usage)
			{
				case D3DDECLUSAGE_NORMAL:
				{
					D3DXVECTOR3 normal;
					//we should have a record for each vertex we have ????
					normal.x = (float)*datafloat;
					datafloat++;		
					normal.y = (float)*datafloat;
					datafloat++;
					normal.z = (float)*datafloat;
					datafloat++;

					ParserDeclData.m_Normals.push_back(normal);
			
				}break;
				case D3DDECLUSAGE_TEXCOORD:
				{						
					//I think I need to read the  data in the order it was saved
					D3DXVECTOR2 coords;
					coords.x = (float)*datafloat;
					datafloat++;
					coords.y = (float)*datafloat;
					datafloat++;
								
					ParserDeclData.m_TextCoords.push_back(coords);

				}break;
			case D3DDECLUSAGE_TANGENT:
			{
				D3DXVECTOR3 tangent;
				//we should have a record for each vertex we have ????
				
				tangent.x = (float)*datafloat;
				datafloat++;			
				tangent.y = (float)*datafloat;
				datafloat++;
				tangent.z = (float)*datafloat;
				datafloat++;

				ParserDeclData.m_Tangents.push_back(tangent);

			
			}break;
			case D3DDECLUSAGE_BINORMAL:
			{
				D3DXVECTOR3 binormal;

				binormal.x = (float)*datafloat;
				datafloat++;//why this first		
				binormal.y = (float)*datafloat;
				datafloat++;
				binormal.z = (float)*datafloat;
				datafloat++;

				ParserDeclData.m_BiNormals.push_back(binormal);
	
			}break;

			}//end switch usage

		}//end for elements

	}//end all vertex

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!