Hello all!
I started to look into tweening since it looked like a fun and sort of quick way to get some basic animations going on my meshes.
Well, due to the sake of simplicity I decided to implement it on the CPU side first with dynamic buffers. While performance is pitifull, thats to be expected when pushing data back and forth from the CPU to the GPU.
However, I've run into a issue that makes me ask
The OBJ format. I've heard that the blender exporter (correct me if im wrong) will rearrange the vertices from export to export. thus negating any tweening attempts. Since I most comfortable with the OBJ format is there a way around it (I see in the mesh export options in blender, keep vertex order) or is this just wishful thinking. If you think OBJ is a no go. What format do you recommend?
Also, my implementation is based on Advanced Animation with DirectX, i just stuffed all the values into XNA types.
I'm including my tweening implementation just in case I missed something silly that someone could hint to. (And also as a validation that this isn't completely off XD) And also because my meshes when tweening wig out and start rendering crazy polygonal shapes and colors! Also as if I'm referencing out-of bounds garbage memory and passing it to D3D
float time = 0.0f;
float length = 5.0f;
if (isMoving)
{
Time += 5.0f * dt;
if (Time > 5.0f) Time = 0.0f;
}
//Note: vertices[x].at(x) represents a vector of pointers which hold all the info of each subset of the overall mesh
scalar = Time / length;
D3D11_MAPPED_SUBRESOURCE ms;
for (int i = 0; i < mCount; i++) //mCount = subsetMeshCount
{
verticesResult.resize(verticeCount[i]);
for (int j = 0; j < verticeCount[i]; j++)
{
//Interpolate Positions
/////////////////////////////////////////////
XMVECTOR vecSource = XMLoadFloat3(&vertices[i].at(j).pos);
float value = (1.0f - scalar);
vecSource *= value;
XMVECTOR vecTarget = XMLoadFloat3(&vertices2[i].at(j).pos);
vecTarget *= scalar;
XMStoreFloat3(&verticesResult.at(j).pos, (vecSource + vecTarget));
//Iterpolate Normals
//////////////////////////////////////////////
XMVECTOR vecSourceNorm = XMLoadFloat3(&vertices[i].at(j).norm);
value = (1.0f - scalar);
vecSourceNorm *= value;
XMVECTOR vecTargetNorm = XMLoadFloat3(&vertices2[i].at(j).norm);
vecTargetNorm *= scalar;
XMStoreFloat3(&verticesResult.at(j).norm, (vecSourceNorm + vecTargetNorm));
verticesResult.at(j).norm = vertices[i].at(j).norm;
//Pass along Materials
///////////////////////////////////////////////
verticesResult.at(j).color = vertices[i].at(j).color;
}
//Lock the dynamic buffer (block the GPU)
///////////////////////////////////////////////////
bro->devcon->Map(vertexBuffer[i], NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
//Grab a pointer to the data, pass along update vertice info, and remap the buffer
////////////////////////////////////////////////////////////////////////////////////
VertexM *v = reinterpret_cast<VertexM*>(ms.pData);
*v = verticesResult[0];
bro->devcon->Unmap(vertexBuffer[i], NULL);
}
Any replies are appreciated
-Marcus