• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
pnt1614

DX11
Load and render MS3D file problem in DX11

2 posts in this topic

I am trying to load and render a MS3D file in DX11 but there is a problem that texture coordinate does not match as well as the object looks like be triangulated. The left image is rendered with DX11, and the other is opened  with Milkshape 3D.

 

loadandrenderams3dmesh.jpgahouseusemilkshape3d.jpg

 

In the source code, I try to convert to LHS such as: index, z coordinate, normal vector, it has not worked.

HRESULT MeshHandler::LoadMS3DFile( std::wstring filename, ID3D11Device* pd3dDevice ) {
	#pragma region local variables
	// Temporary Milkshape structures
	unsigned short usVertexCount = 0;
	unsigned short usTriangleCount = 0;
	unsigned short usGroupCount = 0;
	unsigned short usMaterialCount = 0;

	MS3DVertex* pMS3DVertices = NULL;
	MS3DTriangle* pMS3DTriangles = NULL;
	MS3DGroup* pMS3DGroups = NULL;
	MS3DMaterial* pMS3DMaterials = NULL;

	std::ifstream fin;
	MS3DHeader header;
	#pragma endregion

	// Open the file and read the MS3D header data
	fin.open( filename.c_str(),std::ios::binary );
	fin.read((char*)(&(header.id)), sizeof(header.id));
	fin.read((char*)(&(header.version)), sizeof(header.version));
	if (header.version!=3 && header.version!=4)
		return NULL;

	#pragma region Load all the vertices
	fin.read((char*)(&usVertexCount), sizeof(unsigned short));
	pMS3DVertices = new MS3DVertex[usVertexCount];
	m_NumOfVertices = usVertexCount;
	for (int i = 0; i < usVertexCount; i++)
	{
		fin.read((char*)&(pMS3DVertices[i].flags), sizeof(unsigned char));
		fin.read((char*)&(pMS3DVertices[i].vertex[0]), sizeof(float));
		fin.read((char*)&(pMS3DVertices[i].vertex[1]), sizeof(float));
		fin.read((char*)&(pMS3DVertices[i].vertex[2]), sizeof(float));
		fin.read((char*)&(pMS3DVertices[i].boneId), sizeof(char));
		fin.read((char*)&(pMS3DVertices[i].referenceCount), sizeof(unsigned char));
	}
	#pragma endregion

	#pragma region Load all the triangle indices
	fin.read((char*)(&usTriangleCount), sizeof(unsigned short));
	if (usTriangleCount >0)
	{
		pMS3DTriangles = new MS3DTriangle[usTriangleCount];
		if (pMS3DTriangles != NULL)
		{
			m_NumOfTriangles = usTriangleCount;
			for (int i = 0; i < usTriangleCount; i++)
			{
				fin.read((char*)&(pMS3DTriangles[i].flags),sizeof(unsigned short));

				fin.read((char*)&(pMS3DTriangles[i].vertexIndices[0]), sizeof(unsigned short)); //3*sizeof(unsigned short));
				fin.read((char*)&(pMS3DTriangles[i].vertexIndices[1]), sizeof(unsigned short)); //3*sizeof(unsigned short));
				fin.read((char*)&(pMS3DTriangles[i].vertexIndices[2]), sizeof(unsigned short)); //3*sizeof(unsigned short));
				fin.read((char*)&(pMS3DTriangles[i].vertexNormals[0]), 3*sizeof(float));
				fin.read((char*)&(pMS3DTriangles[i].vertexNormals[1]), 3*sizeof(float));
				fin.read((char*)&(pMS3DTriangles[i].vertexNormals[2]), 3*sizeof(float));
				fin.read((char*)&(pMS3DTriangles[i].s), 3*sizeof(float));
				fin.read((char*)&(pMS3DTriangles[i].t), 3*sizeof(float));
				fin.read((char*)&(pMS3DTriangles[i].smoothingGroup), sizeof(unsigned char));
				fin.read((char*)&(pMS3DTriangles[i].groupIndex), sizeof(unsigned char));
			}
		}		
	}	
	#pragma endregion

	#pragma region Load all the group information
	fin.read((char*)(&usGroupCount), sizeof(unsigned short));
	if (usGroupCount > 0)  
	{
		pMS3DGroups = new MS3DGroup[usGroupCount];
		if (pMS3DGroups != NULL)
		{
			m_NumOfGroups = usGroupCount;
			m_pGroups = new Group[m_NumOfGroups];
			if (m_pGroups != NULL)
			{
				for (int i = 0; i < usGroupCount; i++)
				{
					fin.read((char*)&(pMS3DGroups[i].flags), sizeof(unsigned char));
					fin.read((char*)&(pMS3DGroups[i].name), sizeof(char[32]));
					fin.read((char*)&(pMS3DGroups[i].numtriangles), sizeof(unsigned short));
					unsigned short triCount = pMS3DGroups[i].numtriangles;
					pMS3DGroups[i].triangleIndices = new unsigned short[triCount];
					fin.read((char*)(pMS3DGroups[i].triangleIndices), sizeof(unsigned short) * triCount);
					fin.read((char*)&(pMS3DGroups[i].materialIndex), sizeof(char));

					m_pGroups[i].m_MaterialIndex = pMS3DGroups[i].materialIndex;
					m_pGroups[i].m_NumTriangles = pMS3DGroups[i].numtriangles;
					m_pGroups[i].m_pTriangleIndices = new unsigned short[triCount];
					memcpy(m_pGroups[i].m_pTriangleIndices, pMS3DGroups[i].triangleIndices, sizeof(unsigned short) * triCount );
				}
			}			
		}		
	}	
	#pragma endregion

	#pragma region Load all the material information
	fin.read((char*)(&usMaterialCount),sizeof(unsigned short));

	if (usMaterialCount > 0) 
	{
		pMS3DMaterials = new MS3DMaterial[usMaterialCount];
		m_NumOfMaterials = usMaterialCount;
		m_pMaterials = new Material[m_NumOfMaterials];
		if (pMS3DMaterials != NULL && m_pMaterials != NULL)
		{			
			for (int i = 0; i < m_NumOfMaterials; i++)
			{
				fin.read((char*)&(pMS3DMaterials[i].name), sizeof(char[32]));
				fin.read((char*)&(pMS3DMaterials[i].ambient), 4 * sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].diffuse), 4 * sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].specular), 4 * sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].emissive), 4 * sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].shininess), sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].transparency), sizeof(float));
				fin.read((char*)&(pMS3DMaterials[i].mode), sizeof(char));
				fin.read((char*)&(pMS3DMaterials[i].texture), sizeof(char[128]));
				fin.read((char*)&(pMS3DMaterials[i].alphamap), sizeof(char[128]));

				memcpy(m_pMaterials[i].m_ambient, pMS3DMaterials[i].ambient, sizeof(float)*4);
				memcpy(m_pMaterials[i].m_diffuse, pMS3DMaterials[i].diffuse, sizeof(float)*4);
				memcpy(m_pMaterials[i].m_emissive, pMS3DMaterials[i].emissive, sizeof(float)*4);				
				memcpy(m_pMaterials[i].m_specular, pMS3DMaterials[i].specular, sizeof(float)*4);
				m_pMaterials[i].m_shininess = pMS3DMaterials[i].shininess;

				m_pMaterials[i].m_filename_length = strlen(pMS3DMaterials[i].texture) + 1;
				strcpy(m_pMaterials[i].m_pTextureFilename, pMS3DMaterials[i].texture);
			}
		}
	}
	#pragma endregion

	// Close the file (remaining file data unused)
	fin.close();

	//-----------------------------------------------------------------------------------------------------
	// Swap the 2nd and the 3rd indices
	//-----------------------------------------------------------------------------------------------------
	for (int i=0; i<m_NumOfTriangles; i++)
	{
		unsigned short temp = pMS3DTriangles[i].vertexIndices[1];
		pMS3DTriangles[i].vertexIndices[1] = pMS3DTriangles[i].vertexIndices[2];
		pMS3DTriangles[i].vertexIndices[2] = temp;
	}

	//-----------------------------------------------------------------------------------------------------
	#pragma region
	//Create an array of vertices for generating a new vertex buffer
	m_NumOfVertices = m_NumOfTriangles * 3;
	m_pRenderVertices = new D3DVERTEX[m_NumOfVertices];
	UINT iCount = 0;
	for ( int i=0; i<m_NumOfGroups; i++ ) 
	{
		m_pGroups[i].m_VertexStart = iCount;		
		for ( int j=0; j<m_pGroups[i].m_NumTriangles; j++ ) 
		{
			int iTriangleIndex = pMS3DGroups[i].triangleIndices[j];
			for ( int k=0; k<3; k++ )	
			{
				float vx = pMS3DVertices[pMS3DTriangles[iTriangleIndex].vertexIndices[k]].vertex[0];
				float vy = pMS3DVertices[pMS3DTriangles[iTriangleIndex].vertexIndices[k]].vertex[1];
				float vz = pMS3DVertices[pMS3DTriangles[iTriangleIndex].vertexIndices[k]].vertex[2] * -1.0f;
				m_pRenderVertices[iCount].pos = D3DXVECTOR3(vx, vy, vz);;

				float nx = pMS3DTriangles[iTriangleIndex].vertexNormals[k][0];
				float ny = pMS3DTriangles[iTriangleIndex].vertexNormals[k][1];
				float nz = pMS3DTriangles[iTriangleIndex].vertexNormals[k][2] * -1.0f;				
				m_pRenderVertices[iCount].normal = D3DXVECTOR3(nx, ny, nz);

				float u = pMS3DTriangles[iTriangleIndex].s[k]; 
				float v = pMS3DTriangles[iTriangleIndex].t[k];				
				m_pRenderVertices[iCount].tex = D3DXVECTOR2(u, v);

				++iCount;
			}
		}
		m_pGroups[i].m_NumOfVertices = iCount - m_pGroups[i].m_VertexStart;
	}
	

	//-----------------------------------------------------------------------------------------------------
	//Create an index array
	//Did not test yet.
	iCount = 0;
	UINT NumOfIndices = m_NumOfTriangles * 3;
	m_pRenderIndices = new int[NumOfIndices];
	for ( int i=0; i<m_NumOfGroups; i++ ) 
	{
		m_pGroups[i].m_IndexStart = iCount;
		for ( int j=0; j<m_pGroups[i].m_NumTriangles; j++ ) 
		{			
			for ( int k=0; k<3; k++ )	
			{				
				m_pRenderIndices[iCount] = j*3 + k;
				++iCount;
			}
		}
		m_pGroups[i].m_IndexCount = iCount - m_pGroups[i].m_IndexStart;
	}
	#pragma endregion

	//-----------------------------------------------------------------------------------------------------
	// Releasing
	//-----------------------------------------------------------------------------------------------------
	if (pMS3DMaterials != NULL)
	{
		delete []pMS3DMaterials;
		pMS3DMaterials = NULL;
	}

	if (pMS3DGroups != NULL)
	{
		for (int i = 0; i < usGroupCount; i++)
		{
			if (pMS3DGroups[i].triangleIndices != NULL)
			{
				delete []pMS3DGroups[i].triangleIndices;
				pMS3DGroups[i].triangleIndices = NULL;
			}
		}
		delete []pMS3DGroups;
		pMS3DGroups = NULL;
	}

	if (pMS3DTriangles != NULL)
	{
		delete[] pMS3DTriangles;
		pMS3DTriangles = NULL;
	}
	
	if (pMS3DVertices != NULL)
	{
		delete []pMS3DVertices;
		pMS3DVertices = NULL;
	}

	return S_OK;
}

 

Anybody helps me, please. Thank in advance

 

0

Share this post


Link to post
Share on other sites

I would offer for you to take a look at my geometry loader class from Hieroglyph 3, but I think you are already aware of it...  Have you verified if there is an issue on all of the vertices, or is it only some of them?  I would recommend to do a frame grab with PIX and then compare the vertex data that you have with what you find in the Milkshape3D editor (IIRC there is a way to look at the raw data via the editor itself).

0

Share this post


Link to post
Share on other sites

Thank for helping me, Jason Z. I have already looked at you geometry loader class and figured out the reason. We just comment the following lines:

 

for (int i=0; i<m_NumOfTriangles; i++)
	{
		unsigned short temp = pMS3DTriangles[i].vertexIndices[1];
		pMS3DTriangles[i].vertexIndices[1] = pMS3DTriangles[i].vertexIndices[2];
		pMS3DTriangles[i].vertexIndices[2] = temp;
	}

 

and we do not need to inverse z value.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By thmfrnk
      Hello,
      I am working on a Deferred Shading Engine, which actually uses MSAA for Antialising. Apart from the big G-Buffer ressources its working fine. But the intention of my engine is not only realtime-rendering as also render Screenshots as well as Videos. In that case I've enough time to do everything to get the best results. While using 8x MSAA, some scenes might still flicker.. especially on vegetations. Unfortunately 8x seems to be the maximum on DX11 Hardware, so there is no way to get better results, even if don't prefer realtime.
      So finally I am looking for a solution, which might offer an unlimited Sample count. The first thing I thought about was to find a way to manually manipulate MSAA Sample locations, in order to be able to render multiple frames with different patterns and combining them. I found out that NVIDIA did something equal with TXAA. However, I only found a solution to use NVAPI, in order to change sample locations. https://mynameismjp.wordpress.com/2015/09/13/programmable-sample-points/
      While I am working on .NET and SlimDX I've no idea how hard it would to implement the NVIDIA API and if its possible to use it together with SlimDX. And this approach would be also limited to NV.
      Does anyone have an idea or maybe a better approach I could use?
      Thanks, Thomas
    • By matt77hias
      For vector operations which mathematically result in a single scalar f (such as XMVector3Length or XMPlaneDotCoord), which of the following extractions from an XMVECTOR is preferred:
      1. The very explicit store operation
      const XMVECTOR v = ...; float f; XMStoreFloat(&f, v); 2. A shorter but less explicit version (note that const can now be used explicitly)
      const XMVECTOR v = ...; const float f = XMVectorGetX(v);  
    • By Coelancanth
      Hi guys,
      this is a exam question regarding alpha blending, however there is no official solution, so i am wondering  whether my solution is right or not... thanks in advance...

      my idea:
      BS1:
      since BS1 with BlendEnable set as false, just write value into back buffer.
      -A : (0.4, 0.4, 0.0, 0.5)
      -B : (0.2, 0.4, 0.8, 0.5)
       
      BS2:
       
      backbuffer.RGB: = (0.4, 0.0, 0.0) * 1 + (0.0, 0.0, 0.0) * (1-0.5)      = ( 0.4, 0.0, 0.0)
      backbuffer.Alpha = 1*1 + 0*0   =1
       
      A.RGB = (0.4, 0.4, 0.0)* 0.5 + (0.4, 0.0, 0.0)* ( 1-0.5)   = (0.4,0.2,0.0)
      A.Alpha=0.5*1+1*(1-0.5) = 1
       
       
      B.RGB = (0.2, 0.4, 0.8) * 0.5 + (0.4, 0.2, 0.0) * (1-0.5)  = (0.3, 0.3, 0.4)
      B.Alpha = 0.5 * 1 + 1*(1-0.5)  = 1
       
      ==========================
      BS3:
       
      backbuffer.RGB = (0.4, 0.0, 0.0) + (0.0, 0.0, 0.0)  = (0.4, 0.0, 0.0)
      backbuffer.Alpha = 0
       
      A.RGB = (0.4, 0.4, 0.0) + (0.4, 0.0, 0.0) = (0.8, 0.4, 0.0)
      A.Alpha = 0
       
      B.RGB = (0.2, 0.4, 0.8) + (0.8, 0.4, 0.0) = (1.0, 0.8, 0.8)
      B.Alpha = 0
       
       
       
    • By lonewolff
      Hi Guys,
      I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
      I am trying to set the pixel shader resources and am getting the following error on every loop.
      As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
      ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);  
      I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
      At this stage I am out of ideas.
      Any help would be greatly appreciated
       
    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
       
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
       
       
      https://github.com/Microsoft/DXUT/blob/master/Optional/DXUTcamera.cpp
  • Popular Now