Jump to content

  • Log In with Google      Sign In   
  • Create Account

simpler

Member Since 15 Jul 2010
Offline Last Active Jul 30 2014 03:06 PM

#5003475 Loading and caching resources

Posted by simpler on 23 November 2012 - 06:47 AM

As Waterlimon said, you can add the dimensions to the string key, instead of only using the texture name.

The key could look something like this "texture.bmp 500 200".


#4998225 Simple 3D model loader DirectX 11

Posted by simpler on 06 November 2012 - 04:23 PM

I'm using Assimp and it's working great! The hardest part is to import animated models and extracting the skinning data from the aiScene object. But just loading static models is really simple, here's how I do it:

[source lang="cpp"]//! Loads and returns a static model from a file.StaticModel* ModelImporter::LoadStaticModel(string filename){ // Is the model already loaded? if(mStaticModelMap.find(filename) != mStaticModelMap.end()) return mStaticModelMap[filename]; Assimp::Importer importer; mFilename = filename; StaticModel* model = NULL; // Important! Makes sure that if the angle between two face normals is > 80 they are not smoothed together. // Since the angle between a cubes face normals is 90 the lighting looks very bad if we don't specify this. importer.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f); importer.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1); importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE); // Load scene from the file. const aiScene* scene = importer.ReadFile(filename, aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_SplitLargeMeshes | aiProcess_ConvertToLeftHanded | aiProcess_SortByPType); // Successfully loaded the scene. if(scene) { // Create the model that is getting filled out. model = new StaticModel(); // Loop through all meshes. for(int i = 0; i < scene->mNumMeshes; i++) { aiMesh* assimpMesh = scene->mMeshes[i]; vector<Vertex> vertices; vector<UINT> indices; // Add vertices to the vertex list. for(int i = 0; i < assimpMesh->mNumVertices; i++) { aiVector3D v = assimpMesh->mVertices[i]; aiVector3D n = assimpMesh->mNormals[i]; aiVector3D t = aiVector3D(0, 0, 0); if(assimpMesh->HasTextureCoords(0)) t = assimpMesh->mTextureCoords[0][i]; n = n.Normalize(); Vertex vertex(v.x, v.y, v.z, n.x, n.y, n.z, 0, 0, 0, t.x, t.y); vertices.push_back(vertex); } // Add indices to the index list. for(int i = 0; i < assimpMesh->mNumFaces; i++) for(int j = 0; j < assimpMesh->mFaces[i].mNumIndices; j++) indices.push_back(assimpMesh->mFaces[i].mIndices[j]); } } ...}[/source]

I recommend going through the source code for AssimpView, everything you need to know is there. Also, this made it a lot easier to get the animations up and running. It basicly takes care of calculating the final transforms at a given time, really convenient. And if you want to then take a look at my github repository for my graphics library, all the code that has to do with Assimp and model loading is located in this file: https://github.com/s...delImporter.cpp

Good luck!


#4991880 Importing "Static" 3D objects and playing their various animations in...

Posted by simpler on 19 October 2012 - 01:25 PM

I recently got my skinned model importer working. To load the models I used the Assimp library which have been working great. It can load many different formats both for static models and animated ones and the only job you have to do for yourself is to extract the data you need from the aiScene object. To extract the skeleton and animation data I used this. I first tried extracting the skeletion hierarchy myself but that was above my head so I was really happy finding that animation extractor. Even if you won't use Assimp you can take a look at the source code for the animation extractor to see how it works.

To do the animation you send the array of bone transforms to the shader. You should have a vertex structure containing indexes to which bone the vertex gets affected by and also weights deciding how much it's affected.

struct SkinnedVertexIn
{
	 float3 PosL	   : POSITION;
	 float3 NormalL	: NORMAL;
	 float2 Tex		: TEXCOORD;
	 float3 Weights	: WEIGHTS;	
	 uint4 BoneIndices : BONEINDICES;	 // Indices into the bone transform array
};

And then you do something like this to calculate the position for a vertex after applying the bone transforms:

cbuffer cbSkinned
{
	 float4x4 gBoneTransforms[96];
};

...

for(int i = 0; i < 4; ++i)
{
   posL	 += weights[i]*mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
   normalL  += weights[i]*mul(vin.NormalL, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
}

Good luck!


#4989446 Destructor vs Cleanup()

Posted by simpler on 12 October 2012 - 06:59 AM

Hey I have bumped into a lot of code that uses a Cleanup() member function for their classes instead of using the destructor. I have found myself starting to mix both alternatives which feels bad and I'd rather want to be consistent. What are the pros and cons? What's your opinion?

EDIT: The same question goes for the constructor and Init().


#4983050 Problem sending vertex data to shader

Posted by simpler on 23 September 2012 - 05:28 PM

For some reason the vertex data wont be transfered correctly from the vertex buffer to the vertex shader.

This is the c++ vertex structure:

//! Vertex with skinning info.
struct SkinnedVertex
{
XMFLOAT3 Pos;
XMFLOAT3 Normal;
XMFLOAT2 Tex;
XMFLOAT4 Tangent;
XMFLOAT3 Weights;
BYTE BoneIndices[4];
};

This is the HLSL structure:

//! Input vertex data.
struct SkinnedVertexIn
{
float3 PosL	   : POSITION;
float3 NormalL	: NORMAL;
float2 Tex		: TEXCOORD;
float4 TangentL   : TANGENT;
float3 Weights	: WEIGHTS;
uint4 BoneIndices : BONEINDICES;
};

And this is the input layout:

// Create the vertex input layout.
D3D11_INPUT_ELEMENT_DESC vertexDesc[6] =
{
  {"POSITION",	 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"NORMAL",	   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"TEXCOORD",	 0, DXGI_FORMAT_R32G32_FLOAT,	0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"TANGENT",	  0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"WEIGHTS",	  0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0},
  {"BONEINDICES",  0, DXGI_FORMAT_R8G8B8A8_UINT,   0, 60, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
// Create the input layout.
	D3DX11_PASS_DESC passDesc;
	mTech->GetPassByIndex(0)->GetDesc(&passDesc);
HR(gGame->GetD3D()->GetDevice()->CreateInputLayout(vertexDesc, 6, passDesc.pIAInputSignature,
  passDesc.IAInputSignatureSize, &mInputLayout));

This is what it looks like in PIX:

Posted Image

As you can see the position, normal, texcoord and tangent are transfered correctly. But the weights and bone indices are totally wrong. I have no idea why and I have realised I won't be able to solve this on my own, I really appreciate any help. Also, it seems kinda weird that the tangent is shown as a float3 in PIX when it's acctually a float4.

If you need more information in order to help let me know. Thanks!


#4893253 Help with improving drawing in DX9

Posted by simpler on 12 December 2011 - 03:24 PM

You don't need to change the vertices when moving, rotating or scaling the sprite, just alter the sprite's world matrix for that!


Oh right. But will that work when the drawing calls are between a LPD3DXSPRITE::Begin() and End()?
The reason for all the draw calls being within Begin() and End() is to get 2D screen coordintes, without mixing with the projection matrix.


Should each object have their own vertex buffer?






#4818394 Simply2D - a platform game

Posted by simpler on 01 June 2011 - 12:47 PM

After working on it since about christmas last year I can finally call it finised!
Simply2D is a mario-like platform game where you complete maps and progress through a (short) campaign where you unluck new maps. It currently has 11 different types
of objects which are:

  • Platforms
  • Moving Platforms
  • Enemies
  • Turrets
  • Teleports
  • Trampolines
  • Spikes
  • Walljumps
  • Buttons
  • Gates
  • Gun powerups
What I've spent a lot of time on is the level editor. You can build your own maps and play them immediately. The editor has a inspector gui where you can change the values of the selected object. The gui consists of different types of window controls, which I've done myself by building an own window handler. I don't know what else I can say other than you should try it out and tell me what you think :)

It's written in C++ and uses DirectX for graphics and IrrKlang for sound.

The game can be downloaded from here.

Please visit my website and take a look around. I've writtin more about the game there as well.

I would really appreciate if you test the game and leave a comment about what you thought or if you discovered a bug or similar. Feedback is very very welcome Posted Image

Here's some screenshots:

Posted Image


Posted Image


Posted Image


Posted Image


Thanks for your time,
simpler


#4791053 Engine Programming

Posted by simpler on 27 March 2011 - 01:28 PM

If you don't got alot of experience in writing 2D game then writing a flexible game engine that can be used in several games is really hard to pull off. Since you said you just started with game development I suggest you write games first. Every game needs some kind of engine, but it's a big difference between an engine made for a specific game and one made for several.


PARTNERS