Anim Test Not working Joints
This commit is contained in:
parent
34f58d4140
commit
97a3792bff
|
@ -32,6 +32,8 @@ namespace Oyster
|
||||||
Render::Resources::Deffered::Init();
|
Render::Resources::Deffered::Init();
|
||||||
|
|
||||||
Render::Preparations::Basic::SetViewPort();
|
Render::Preparations::Basic::SetViewPort();
|
||||||
|
Render::Rendering::Basic::cube = API::CreateModel(L"box.dan");
|
||||||
|
Render::Rendering::Basic::cube2 = API::CreateModel(L"box2.dan");
|
||||||
return API::Sucsess;
|
return API::Sucsess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -397,8 +397,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
|
||||||
anims[a].Keyframes[b][f].bone.Parent = boneIndex;
|
anims[a].Keyframes[b][f].bone.Parent = boneIndex;
|
||||||
|
|
||||||
//read bone transform
|
//read bone transform
|
||||||
ReadData(&anims[a].Keyframes[b][f].bone.Transform,danFile,sizeof(Oyster::Math::Matrix));
|
ReadData(&anims[a].Keyframes[b][f].bone.Relative, danFile, sizeof(Math::Matrix));
|
||||||
|
|
||||||
|
|
||||||
ReadData(&anims[a].Keyframes[b][f].time,danFile,sizeof(double));
|
ReadData(&anims[a].Keyframes[b][f].time,danFile,sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,8 +143,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
return NULL;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type));
|
return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type));
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
struct Bone
|
struct Bone
|
||||||
{
|
{
|
||||||
Math::Float4x4 Transform;
|
Math::Matrix Relative;
|
||||||
|
Math::Matrix Absolute;
|
||||||
int Parent;
|
int Parent;
|
||||||
};
|
};
|
||||||
struct Frame
|
struct Frame
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "../Resources/Deffered.h"
|
#include "../Resources/Deffered.h"
|
||||||
#include "../../Definitions/GraphicalDefinition.h"
|
#include "../../Definitions/GraphicalDefinition.h"
|
||||||
#include "../../Model/ModelInfo.h"
|
#include "../../Model/ModelInfo.h"
|
||||||
|
#include "../../DllInterfaces/GFXAPI.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ namespace Oyster
|
||||||
namespace Rendering
|
namespace Rendering
|
||||||
{
|
{
|
||||||
Definitions::Pointlight pl;
|
Definitions::Pointlight pl;
|
||||||
|
Model::Model* Basic::cube = NULL;
|
||||||
|
Model::Model* Basic::cube2 = NULL;
|
||||||
|
|
||||||
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
||||||
{
|
{
|
||||||
|
@ -40,12 +43,21 @@ namespace Oyster
|
||||||
Resources::Deffered::PointLightsData.Unmap();
|
Resources::Deffered::PointLightsData.Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Matrix RecursiveBindPos(int index, Model::ModelInfo* mi)
|
Math::Matrix RecursiveBindPosRotation(int index, Model::ModelInfo* mi)
|
||||||
{
|
{
|
||||||
if(mi->bones[index].Parent == index)
|
if(mi->bones[index].Parent == index)
|
||||||
return mi->bones[index].Transform;
|
return mi->bones[index].Relative;
|
||||||
|
|
||||||
|
return mi->bones[index].Relative*mi->bones[mi->bones->Parent].Relative;
|
||||||
|
}
|
||||||
|
|
||||||
return mi->bones[index].Transform.GetInverse() * RecursiveBindPos(mi->bones[index].Parent,mi);
|
Math::Vector4 RecursiveBindPosPosition(int index, Model::ModelInfo* mi)
|
||||||
|
{
|
||||||
|
//return Math::Vector4::standard_unit_w;
|
||||||
|
if(mi->bones[index].Parent == index)
|
||||||
|
return mi->bones[index].Relative.v[3];
|
||||||
|
|
||||||
|
return Math::Vector4(RecursiveBindPosPosition(mi->bones->Parent, mi).xyz + (mi->bones[index].Relative.v[3] * RecursiveBindPosRotation(mi->bones->Parent,mi)).xyz,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
|
void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
|
||||||
|
@ -70,10 +82,71 @@ namespace Oyster
|
||||||
Definitions::AnimationData am; //final
|
Definitions::AnimationData am; //final
|
||||||
if(info->Animated && models[i].AnimationPlaying != -1)
|
if(info->Animated && models[i].AnimationPlaying != -1)
|
||||||
{
|
{
|
||||||
|
//store inverse absolut transform
|
||||||
|
Math::Matrix* SkinTransform = new Math::Matrix[info->BoneCount];
|
||||||
|
Math::Matrix* BoneAnimated = new Math::Matrix[info->BoneCount];
|
||||||
|
Math::Matrix* BoneAbsAnimated = new Math::Matrix[info->BoneCount];
|
||||||
|
|
||||||
|
Math::Matrix Scale = Math::Matrix::identity;
|
||||||
|
Scale.m[1][1] = 0.1f;
|
||||||
|
Scale.m[2][2] = 0.1f;
|
||||||
|
Scale.m[3][3] = 2;
|
||||||
|
|
||||||
for(int b = 0; b <info->BoneCount; ++b)
|
for(int b = 0; b <info->BoneCount; ++b)
|
||||||
{
|
{
|
||||||
am.animatedData[b] = RecursiveBindPos(b,info);
|
Model::Bone Bone = info->bones[b];
|
||||||
|
SkinTransform[b] = Bone.Absolute.GetInverse();
|
||||||
|
BoneAnimated[b] = Bone.Relative;
|
||||||
|
BoneAbsAnimated[b] = Bone.Absolute;
|
||||||
}
|
}
|
||||||
|
//for each bone in animation
|
||||||
|
//HACK use first bone
|
||||||
|
int b = 0;
|
||||||
|
Model::Animation A = info->Animations[models[i].AnimationPlaying];
|
||||||
|
//for(int b = 0; b < A.Bones;++b)
|
||||||
|
{
|
||||||
|
//for each frame on bone Write current relative data
|
||||||
|
//HACK use first frame
|
||||||
|
int f = 0;
|
||||||
|
//for(int f = 0; f < A.Frames[b]; ++b)
|
||||||
|
{
|
||||||
|
//find right frame
|
||||||
|
//HACK accept first
|
||||||
|
Model::Frame Current = A.Keyframes[b][f];
|
||||||
|
|
||||||
|
//calculate new matrix
|
||||||
|
Model::Bone CBone = Current.bone;
|
||||||
|
BoneAnimated[CBone.Parent] = CBone.Relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//calculate Absolute Animation Transform
|
||||||
|
for(int b = 0; b < info->BoneCount; ++b)
|
||||||
|
{
|
||||||
|
BoneAbsAnimated[b] = BoneAbsAnimated[info->bones[b].Parent] * BoneAnimated[b];
|
||||||
|
cube->WorldMatrix = BoneAbsAnimated[b] * Scale;
|
||||||
|
cube->WorldMatrix.v[3] = BoneAbsAnimated[b].v[3];
|
||||||
|
//Basic::RenderScene(cube,1,View,Projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
//write data to am
|
||||||
|
for(int b = 0; b < info->BoneCount; ++b)
|
||||||
|
{
|
||||||
|
am.animatedData[b] = BoneAbsAnimated[b] * SkinTransform[b];
|
||||||
|
cube2->WorldMatrix = Scale;
|
||||||
|
cube2->WorldMatrix.v[3] = info->bones[b].Absolute.v[3];
|
||||||
|
Basic::RenderScene(cube2,1,View,Projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
//retore to draw animated model
|
||||||
|
Definitions::PerModel pm;
|
||||||
|
pm.WV = View * models[i].WorldMatrix;
|
||||||
|
pm.WVP = Projection * pm.WV;
|
||||||
|
|
||||||
|
void* data = Resources::Deffered::ModelData.Map();
|
||||||
|
memcpy(data,&(pm),sizeof(pm));
|
||||||
|
Resources::Deffered::ModelData.Unmap();
|
||||||
|
|
||||||
am.Animated = 1;
|
am.Animated = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -97,7 +170,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0);
|
Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ namespace Oyster
|
||||||
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
|
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
|
||||||
static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection);
|
static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection);
|
||||||
static void EndFrame();
|
static void EndFrame();
|
||||||
|
|
||||||
|
static Model::Model* cube;
|
||||||
|
static Model::Model* cube2;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,6 @@ RWTexture2D<float4> Output;
|
||||||
void main( uint3 DTid : SV_DispatchThreadID )
|
void main( uint3 DTid : SV_DispatchThreadID )
|
||||||
{
|
{
|
||||||
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/2].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
|
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/2].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
|
||||||
Output[DTid.xy] = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 1);
|
Output[DTid.xy] = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w */, 1);
|
||||||
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy];
|
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy];
|
||||||
}
|
}
|
|
@ -3,16 +3,14 @@
|
||||||
VertexOut main( VertexIn input )
|
VertexOut main( VertexIn input )
|
||||||
{
|
{
|
||||||
VertexOut output;
|
VertexOut output;
|
||||||
/*input.pos = (
|
/*input.pos =
|
||||||
(mul(BoneAnimation[input.boneIndex.x], input.pos) * input.boneWeight.x) +
|
(mul(BoneAnimation[input.boneIndex.x], input.pos) * input.boneWeight.x * Animated) +
|
||||||
(mul(BoneAnimation[input.boneIndex.y], input.pos) * input.boneWeight.y) +
|
(mul(BoneAnimation[input.boneIndex.y], input.pos) * input.boneWeight.y * Animated) +
|
||||||
(mul(BoneAnimation[input.boneIndex.z], input.pos) * input.boneWeight.z) +
|
(mul(BoneAnimation[input.boneIndex.z], input.pos) * input.boneWeight.z * Animated) +
|
||||||
(mul(BoneAnimation[input.boneIndex.w], input.pos) * input.boneWeight.w)
|
(mul(BoneAnimation[input.boneIndex.w], input.pos) * input.boneWeight.w * Animated) +
|
||||||
* Animated) + input.pos * int(1-Animated);*/
|
input.pos * int(1-Animated);*/
|
||||||
|
|
||||||
input.pos = (
|
/*input.pos = mul(BoneAnimation[input.boneIndex.x], input.pos) * Animated + input.pos * int(1-Animated);*/
|
||||||
(mul(BoneAnimation[input.boneIndex.x], input.pos)/* * input.boneWeight.x*/)
|
|
||||||
* Animated) + input.pos * int(1-Animated);
|
|
||||||
|
|
||||||
//float4x4 m = matrix(float4(1,0,0,0),float4(0,1,0,0), float4(0,0,1,0), float4(0,0,0,1));
|
//float4x4 m = matrix(float4(1,0,0,0),float4(0,1,0,0), float4(0,0,1,0), float4(0,0,0,1));
|
||||||
//input.pos = mul(BoneAnimation[0], float4(input.pos,1));
|
//input.pos = mul(BoneAnimation[0], float4(input.pos,1));
|
||||||
|
|
|
@ -160,7 +160,7 @@ HRESULT InitDirect3D()
|
||||||
}
|
}
|
||||||
|
|
||||||
m = Oyster::Graphics::API::CreateModel(L"untitled.dan");
|
m = Oyster::Graphics::API::CreateModel(L"untitled.dan");
|
||||||
m2 = Oyster::Graphics::API::CreateModel(L"still.dan");
|
m2 = Oyster::Graphics::API::CreateModel(L"still_root_origo.dan");
|
||||||
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
|
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
|
||||||
m2->AnimationPlaying = 0;
|
m2->AnimationPlaying = 0;
|
||||||
m2->AnimationTime = 0.0f;
|
m2->AnimationTime = 0.0f;
|
||||||
|
@ -169,6 +169,7 @@ HRESULT InitDirect3D()
|
||||||
|
|
||||||
|
|
||||||
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000);
|
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000);
|
||||||
|
//P = Oyster::Math3D::ProjectionMatrix_Orthographic(10,10,.1f,10000);
|
||||||
Oyster::Graphics::API::SetProjection(P);
|
Oyster::Graphics::API::SetProjection(P);
|
||||||
|
|
||||||
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
|
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
|
||||||
|
|
Loading…
Reference in New Issue