basic skinned animation demo
This commit is contained in:
parent
532288906d
commit
2477f849c7
13
gltf.h
13
gltf.h
@ -1,13 +0,0 @@
|
|||||||
union Accessor {
|
|
||||||
DWORD * dw;
|
|
||||||
float * f;
|
|
||||||
D3DXVECTOR3 * v3;
|
|
||||||
D3DXVECTOR4 * v4;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mesh {
|
|
||||||
int position;
|
|
||||||
int normal;
|
|
||||||
int texcoord_0;
|
|
||||||
int indices;
|
|
||||||
};
|
|
||||||
61
gltf.hpp
Normal file
61
gltf.hpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
struct Mesh {
|
||||||
|
const D3DXVECTOR3 * position;
|
||||||
|
const DWORD position_size;
|
||||||
|
|
||||||
|
const D3DXVECTOR3 * normal;
|
||||||
|
const DWORD normal_size;
|
||||||
|
|
||||||
|
const D3DXVECTOR2 * texcoord_0;
|
||||||
|
const DWORD texcoord_0_size;
|
||||||
|
|
||||||
|
const D3DXVECTOR4 * weights_0;
|
||||||
|
const DWORD weights_0_size;
|
||||||
|
|
||||||
|
const D3DXVECTOR4 * joints_0;
|
||||||
|
const DWORD joints_0_size;
|
||||||
|
|
||||||
|
const DWORD * indices;
|
||||||
|
const DWORD indices_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Skin;
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
const Skin * skin; // skin index (global)
|
||||||
|
const Mesh * mesh; // mesh index (global)
|
||||||
|
const D3DXVECTOR3 translation;
|
||||||
|
const D3DXQUATERNION rotation;
|
||||||
|
const D3DXVECTOR3 scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Skin {
|
||||||
|
const D3DXMATRIX * inverse_bind_matrices; // accessor
|
||||||
|
const Node ** joints;
|
||||||
|
DWORD joints_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum AnimationChannelPath {
|
||||||
|
ACP__WEIGHTS,
|
||||||
|
ACP__ROTATION,
|
||||||
|
ACP__TRANSLATION,
|
||||||
|
ACP__SCALE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnimationSampler {
|
||||||
|
const float * input; // accessor index, containing keyframe timestamps
|
||||||
|
const void * output; // accessor index, containing keyframe values (type depends on channel target path)
|
||||||
|
const int length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnimationChannel {
|
||||||
|
const AnimationSampler * sampler; // sampler index, this animation
|
||||||
|
struct {
|
||||||
|
const Node * node; // node index
|
||||||
|
const AnimationChannelPath path; // property to animate
|
||||||
|
} target;
|
||||||
|
};
|
||||||
|
|
||||||
|
//struct Animation {
|
||||||
|
// const AnimationChannel * channels;
|
||||||
|
// const AnimationSampler * samplers;
|
||||||
|
//};
|
||||||
200
main.cpp
200
main.cpp
@ -4,6 +4,9 @@
|
|||||||
#include <d3dx10.h>
|
#include <d3dx10.h>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
|
#include "gltf.hpp"
|
||||||
|
#include "skin.hpp"
|
||||||
|
|
||||||
HINSTANCE g_hInstance = NULL;
|
HINSTANCE g_hInstance = NULL;
|
||||||
HWND g_hWnd = NULL;
|
HWND g_hWnd = NULL;
|
||||||
ID3D10Device * g_pd3dDevice = NULL;
|
ID3D10Device * g_pd3dDevice = NULL;
|
||||||
@ -15,7 +18,7 @@ ID3D10Effect * g_pEffect = NULL;
|
|||||||
ID3D10EffectTechnique * g_pTechniqueRender = NULL;
|
ID3D10EffectTechnique * g_pTechniqueRender = NULL;
|
||||||
ID3D10EffectTechnique * g_pTechniqueRenderLight = NULL;
|
ID3D10EffectTechnique * g_pTechniqueRenderLight = NULL;
|
||||||
ID3D10InputLayout * g_pVertexLayout = NULL;
|
ID3D10InputLayout * g_pVertexLayout = NULL;
|
||||||
ID3D10Buffer * g_pVertexBuffer = NULL;
|
//ID3D10Buffer * g_pVertexBuffer = NULL;
|
||||||
ID3D10Buffer * g_pIndexBuffer = NULL;
|
ID3D10Buffer * g_pIndexBuffer = NULL;
|
||||||
|
|
||||||
ID3D10Texture2D * g_pTexture = NULL;
|
ID3D10Texture2D * g_pTexture = NULL;
|
||||||
@ -24,6 +27,7 @@ ID3D10ShaderResourceView * g_pTextureShaderResourceView = NULL;
|
|||||||
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
|
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
|
||||||
ID3D10EffectMatrixVariable * g_pViewVariable = NULL;
|
ID3D10EffectMatrixVariable * g_pViewVariable = NULL;
|
||||||
ID3D10EffectMatrixVariable * g_pProjectionVariable = NULL;
|
ID3D10EffectMatrixVariable * g_pProjectionVariable = NULL;
|
||||||
|
ID3D10EffectMatrixVariable * g_pJointVariable = NULL;
|
||||||
ID3D10EffectVectorVariable * g_pLightDirVariable = NULL;
|
ID3D10EffectVectorVariable * g_pLightDirVariable = NULL;
|
||||||
ID3D10EffectVectorVariable * g_pLightColorVariable = NULL;
|
ID3D10EffectVectorVariable * g_pLightColorVariable = NULL;
|
||||||
ID3D10EffectVectorVariable * g_pOutputColorVariable = NULL;
|
ID3D10EffectVectorVariable * g_pOutputColorVariable = NULL;
|
||||||
@ -39,15 +43,6 @@ HRESULT InitDirect3DDevice();
|
|||||||
void Render();
|
void Render();
|
||||||
BOOL Resize();
|
BOOL Resize();
|
||||||
|
|
||||||
struct SimpleVertex {
|
|
||||||
D3DXVECTOR3 Pos;
|
|
||||||
D3DXVECTOR3 Normal;
|
|
||||||
D3DXVECTOR2 Texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "gltf.h"
|
|
||||||
#include "minimal.h"
|
|
||||||
|
|
||||||
struct WindowSize {
|
struct WindowSize {
|
||||||
UINT Width;
|
UINT Width;
|
||||||
UINT Height;
|
UINT Height;
|
||||||
@ -276,6 +271,31 @@ HRESULT InitDirect3DDevice()
|
|||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// rasterizer state
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
D3D10_RASTERIZER_DESC RSDesc;
|
||||||
|
RSDesc.FillMode = D3D10_FILL_SOLID;
|
||||||
|
//RSDesc.CullMode = D3D10_CULL_BACK;
|
||||||
|
RSDesc.CullMode = D3D10_CULL_NONE;
|
||||||
|
RSDesc.FrontCounterClockwise = FALSE;
|
||||||
|
RSDesc.DepthBias = 0;
|
||||||
|
RSDesc.SlopeScaledDepthBias = 0.0f;
|
||||||
|
RSDesc.DepthBiasClamp= 0;
|
||||||
|
RSDesc.DepthClipEnable = TRUE;
|
||||||
|
RSDesc.ScissorEnable = FALSE;
|
||||||
|
RSDesc.AntialiasedLineEnable = FALSE;
|
||||||
|
RSDesc.MultisampleEnable = FALSE;
|
||||||
|
|
||||||
|
ID3D10RasterizerState* pRState = NULL;
|
||||||
|
hr = g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
g_pd3dDevice->RSSetState(pRState);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
InitDirect3DViews();
|
InitDirect3DViews();
|
||||||
|
|
||||||
// texture
|
// texture
|
||||||
@ -342,6 +362,7 @@ HRESULT InitDirect3DDevice()
|
|||||||
g_pWorldVariable = g_pEffect->GetVariableByName("World")->AsMatrix();
|
g_pWorldVariable = g_pEffect->GetVariableByName("World")->AsMatrix();
|
||||||
g_pViewVariable = g_pEffect->GetVariableByName("View")->AsMatrix();
|
g_pViewVariable = g_pEffect->GetVariableByName("View")->AsMatrix();
|
||||||
g_pProjectionVariable = g_pEffect->GetVariableByName("Projection")->AsMatrix();
|
g_pProjectionVariable = g_pEffect->GetVariableByName("Projection")->AsMatrix();
|
||||||
|
g_pJointVariable = g_pEffect->GetVariableByName("mJoint")->AsMatrix();
|
||||||
g_pLightDirVariable = g_pEffect->GetVariableByName("vLightDir")->AsVector();
|
g_pLightDirVariable = g_pEffect->GetVariableByName("vLightDir")->AsVector();
|
||||||
g_pLightColorVariable = g_pEffect->GetVariableByName("vLightColor")->AsVector();
|
g_pLightColorVariable = g_pEffect->GetVariableByName("vLightColor")->AsVector();
|
||||||
g_pOutputColorVariable = g_pEffect->GetVariableByName("vOutputColor")->AsVector();
|
g_pOutputColorVariable = g_pEffect->GetVariableByName("vOutputColor")->AsVector();
|
||||||
@ -350,6 +371,8 @@ HRESULT InitDirect3DDevice()
|
|||||||
// input layout
|
// input layout
|
||||||
D3D10_INPUT_ELEMENT_DESC layout[] = {
|
D3D10_INPUT_ELEMENT_DESC layout[] = {
|
||||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D10_INPUT_PER_VERTEX_DATA, 0},
|
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||||
|
{"TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||||
|
{"TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 2, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||||
//{"NORMAL" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
//{"NORMAL" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||||
//{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
//{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||||
};
|
};
|
||||||
@ -374,39 +397,70 @@ HRESULT InitDirect3DDevice()
|
|||||||
D3D10_SUBRESOURCE_DATA initData;
|
D3D10_SUBRESOURCE_DATA initData;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// vertex buffer
|
// vertex buffers
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#define VERTEX_ACCESSOR accessor_1
|
#define MESH mesh_0
|
||||||
|
|
||||||
|
ID3D10Buffer * pVertexBuffers[3];
|
||||||
|
|
||||||
|
// position
|
||||||
bd.Usage = D3D10_USAGE_DEFAULT;
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
||||||
bd.ByteWidth = (sizeof (VERTEX_ACCESSOR));
|
bd.ByteWidth = MESH.position_size;
|
||||||
//bd.ByteWidth = (sizeof (SimpleVertex)) * vertices_length;
|
|
||||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
bd.CPUAccessFlags = 0;
|
bd.CPUAccessFlags = 0;
|
||||||
bd.MiscFlags = 0;
|
bd.MiscFlags = 0;
|
||||||
initData.pSysMem = VERTEX_ACCESSOR;
|
initData.pSysMem = MESH.position;
|
||||||
//initData.pSysMem = vertices;
|
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &pVertexBuffers[0]);
|
||||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pVertexBuffer);
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
print("CreateBuffer\n");
|
print("CreateBuffer\n");
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
UINT stride = (sizeof (VERTEX_ACCESSOR[0]));
|
|
||||||
UINT offset = 0;
|
// weights
|
||||||
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
||||||
|
bd.ByteWidth = MESH.weights_0_size;
|
||||||
|
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
|
bd.CPUAccessFlags = 0;
|
||||||
|
bd.MiscFlags = 0;
|
||||||
|
initData.pSysMem = MESH.weights_0;
|
||||||
|
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &pVertexBuffers[1]);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
print("CreateBuffer\n");
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// joints
|
||||||
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
||||||
|
bd.ByteWidth = MESH.joints_0_size;
|
||||||
|
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
|
bd.CPUAccessFlags = 0;
|
||||||
|
bd.MiscFlags = 0;
|
||||||
|
initData.pSysMem = MESH.joints_0;
|
||||||
|
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &pVertexBuffers[2]);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
print("CreateBuffer\n");
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT stride[] = {
|
||||||
|
(sizeof (MESH.position[0])),
|
||||||
|
(sizeof (MESH.weights_0[0])),
|
||||||
|
(sizeof (MESH.joints_0[0])),
|
||||||
|
};
|
||||||
|
UINT offset[] = { 0, 0, 0 };
|
||||||
|
g_pd3dDevice->IASetVertexBuffers(0, 3, pVertexBuffers, stride, offset);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// index buffer
|
// index buffer
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#define INDEX_ACCESSOR accessor_0
|
|
||||||
|
|
||||||
bd.Usage = D3D10_USAGE_DEFAULT;
|
bd.Usage = D3D10_USAGE_DEFAULT;
|
||||||
bd.ByteWidth = (sizeof (INDEX_ACCESSOR));
|
bd.ByteWidth = MESH.indices_size;
|
||||||
//bd.ByteWidth = (sizeof (DWORD)) * indices_length;
|
//bd.ByteWidth = (sizeof (DWORD)) * indices_length;
|
||||||
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||||
bd.CPUAccessFlags = 0;
|
bd.CPUAccessFlags = 0;
|
||||||
bd.MiscFlags = 0;
|
bd.MiscFlags = 0;
|
||||||
initData.pSysMem = INDEX_ACCESSOR;
|
initData.pSysMem = MESH.indices;
|
||||||
//initData.pSysMem = indices;
|
//initData.pSysMem = indices;
|
||||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pIndexBuffer);
|
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pIndexBuffer);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
@ -416,11 +470,13 @@ HRESULT InitDirect3DDevice()
|
|||||||
|
|
||||||
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
// transform matrices
|
// transform matrices
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
D3DXMatrixIdentity(&g_World1);
|
D3DXMatrixIdentity(&g_World1);
|
||||||
D3DXMatrixIdentity(&g_World2);
|
D3DXMatrixIdentity(&g_World2);
|
||||||
|
|
||||||
D3DXVECTOR3 Eye(0.0f, 0.0f, -2.0f);
|
D3DXVECTOR3 Eye(0.0f, 0.0f, -3.0f);
|
||||||
D3DXVECTOR3 At(0.0f, 0.0f, 0.0f);
|
D3DXVECTOR3 At(0.0f, 0.0f, 0.0f);
|
||||||
D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);
|
D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);
|
||||||
D3DXMatrixLookAtLH(&g_View, &Eye, &At, &Up);
|
D3DXMatrixLookAtLH(&g_View, &Eye, &At, &Up);
|
||||||
@ -478,6 +534,7 @@ BOOL Resize()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void Animate(float t)
|
void Animate(float t)
|
||||||
{
|
{
|
||||||
const float * frames = accessor_2;
|
const float * frames = accessor_2;
|
||||||
@ -514,19 +571,104 @@ void Animate(float t)
|
|||||||
|
|
||||||
D3DXMatrixRotationQuaternion(&g_World1, &rotation);
|
D3DXMatrixRotationQuaternion(&g_World1, &rotation);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static inline void MatrixTRS(D3DXMATRIX * transform,
|
||||||
|
const D3DXVECTOR3 * translation,
|
||||||
|
const D3DXQUATERNION * rotation,
|
||||||
|
const D3DXVECTOR3 * scaling)
|
||||||
|
{
|
||||||
|
D3DXMATRIX mTranslation;
|
||||||
|
D3DXMatrixTranslation(&mTranslation, translation->x, translation->y, translation->z);
|
||||||
|
|
||||||
|
D3DXMATRIX mRotation;
|
||||||
|
D3DXMatrixRotationQuaternion(&mRotation, rotation);
|
||||||
|
|
||||||
|
D3DXMATRIX mScaling;
|
||||||
|
D3DXMatrixScaling(&mScaling, scaling->x, scaling->y, scaling->z);
|
||||||
|
|
||||||
|
D3DXMatrixMultiply(transform, &mRotation, &mTranslation);
|
||||||
|
D3DXMatrixMultiply(transform, transform, &mScaling);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float fract(float f)
|
||||||
|
{
|
||||||
|
return f - floor(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float loop(float f, float n)
|
||||||
|
{
|
||||||
|
return fract(f / n) * n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int FindFrame(const float * frames, int length, float t)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < length - 1; i++) {
|
||||||
|
if (frames[i] <= t && frames[i+1] >= t) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float Lerp(const float * frames, float t, int frame_ix)
|
||||||
|
{
|
||||||
|
return (t - frames[frame_ix]) / (frames[frame_ix + 1] - frames[frame_ix]);
|
||||||
|
}
|
||||||
|
|
||||||
|
D3DXMATRIX mJoints[2];
|
||||||
|
|
||||||
|
void Animate(float t)
|
||||||
|
{
|
||||||
|
t = loop(t, 5.5);
|
||||||
|
|
||||||
|
// animation_0__sampler_0
|
||||||
|
const AnimationSampler * sampler = &animation_0__sampler_0;
|
||||||
|
const float * input = sampler->input;
|
||||||
|
const D3DXQUATERNION * output = (D3DXQUATERNION *)sampler->output;
|
||||||
|
|
||||||
|
int frame_ix = FindFrame(sampler->input, sampler->length, t);
|
||||||
|
float lerp = Lerp(sampler->input, t, frame_ix);
|
||||||
|
D3DXQUATERNION rotation;
|
||||||
|
D3DXQuaternionSlerp(&rotation,
|
||||||
|
&output[frame_ix],
|
||||||
|
&output[frame_ix+1],
|
||||||
|
lerp);
|
||||||
|
|
||||||
|
// joint 1
|
||||||
|
const Skin * skin = &skin_0;
|
||||||
|
const Node * node = skin->joints[1];
|
||||||
|
|
||||||
|
// T * R * S
|
||||||
|
|
||||||
|
D3DXMATRIX global_transform;
|
||||||
|
MatrixTRS(&global_transform, &node->translation, &rotation, &node->scale);
|
||||||
|
|
||||||
|
D3DXMatrixIdentity(&mJoints[0]);
|
||||||
|
D3DXMatrixIdentity(&mJoints[1]);
|
||||||
|
|
||||||
|
const D3DXMATRIX * inverse_bind_matrix = &skin->inverse_bind_matrices[1];
|
||||||
|
//D3DXMatrixMultiply(&mJoints[1], &global_transform, inverse_bind_matrix);
|
||||||
|
//D3DXMatrixIdentity(&mJoints[1]);
|
||||||
|
//g_World1 = global_transform;
|
||||||
|
|
||||||
|
D3DXMatrixMultiply(&mJoints[1], inverse_bind_matrix, &global_transform);
|
||||||
|
//mJoints[1] = global_transform;
|
||||||
|
//g_World1 = *inverse_bind_matrix;
|
||||||
|
}
|
||||||
|
|
||||||
void Render()
|
void Render()
|
||||||
{
|
{
|
||||||
static float t = 0.0f;
|
static float t = 0.0f;
|
||||||
if (1) {
|
#ifdef _DEBUG
|
||||||
t += (float)D3DX_PI * 0.0125f * 0.5;
|
t += (float)D3DX_PI * 0.0125f * 0.5;
|
||||||
} else {
|
#else
|
||||||
static DWORD dwTimeStart = 0;
|
static DWORD dwTimeStart = 0;
|
||||||
DWORD dwTimeCur = GetTickCount();
|
DWORD dwTimeCur = GetTickCount();
|
||||||
if (dwTimeStart == 0)
|
if (dwTimeStart == 0)
|
||||||
dwTimeStart = dwTimeCur;
|
dwTimeStart = dwTimeCur;
|
||||||
t = (dwTimeCur - dwTimeStart) / 1000.0f;
|
t = (dwTimeCur - dwTimeStart) / 1000.0f;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
Animate(t);
|
Animate(t);
|
||||||
|
|
||||||
@ -563,6 +705,8 @@ void Render()
|
|||||||
g_pWorldVariable->SetMatrix((float *)&g_World1);
|
g_pWorldVariable->SetMatrix((float *)&g_World1);
|
||||||
g_pDiffuseVariable->SetResource(g_pTextureShaderResourceView);
|
g_pDiffuseVariable->SetResource(g_pTextureShaderResourceView);
|
||||||
|
|
||||||
|
g_pJointVariable->SetMatrixArray((float *)mJoints, 0, 2);
|
||||||
|
|
||||||
// color
|
// color
|
||||||
g_pOutputColorVariable->SetFloatVector((float *)&vLightColors[0]);
|
g_pOutputColorVariable->SetFloatVector((float *)&vLightColors[0]);
|
||||||
|
|
||||||
@ -575,7 +719,7 @@ void Render()
|
|||||||
g_pTechniqueRender->GetDesc(&techDesc);
|
g_pTechniqueRender->GetDesc(&techDesc);
|
||||||
for (UINT p = 0; p < techDesc.Passes; p++) {
|
for (UINT p = 0; p < techDesc.Passes; p++) {
|
||||||
g_pTechniqueRender->GetPassByIndex(p)->Apply(0);
|
g_pTechniqueRender->GetPassByIndex(p)->Apply(0);
|
||||||
g_pd3dDevice->DrawIndexed(3, 0, 0);
|
g_pd3dDevice->DrawIndexed(accessor_0_length, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the lights
|
// render the lights
|
||||||
|
|||||||
23
main.fx
23
main.fx
@ -2,6 +2,8 @@ matrix World;
|
|||||||
matrix View;
|
matrix View;
|
||||||
matrix Projection;
|
matrix Projection;
|
||||||
|
|
||||||
|
matrix mJoint[2];
|
||||||
|
|
||||||
float4 vLightDir[2];
|
float4 vLightDir[2];
|
||||||
float4 vLightColor[2];
|
float4 vLightColor[2];
|
||||||
float4 vOutputColor;
|
float4 vOutputColor;
|
||||||
@ -16,6 +18,8 @@ SamplerState samLinear {
|
|||||||
struct VS_INPUT
|
struct VS_INPUT
|
||||||
{
|
{
|
||||||
float4 Pos : POSITION;
|
float4 Pos : POSITION;
|
||||||
|
float4 Weight : TEXCOORD0;
|
||||||
|
float4 Joint : TEXCOORD1;
|
||||||
//float3 Normal : NORMAL;
|
//float3 Normal : NORMAL;
|
||||||
//float2 Tex : TEXCOORD;
|
//float2 Tex : TEXCOORD;
|
||||||
};
|
};
|
||||||
@ -23,6 +27,8 @@ struct VS_INPUT
|
|||||||
struct PS_INPUT
|
struct PS_INPUT
|
||||||
{
|
{
|
||||||
float4 Pos : SV_POSITION;
|
float4 Pos : SV_POSITION;
|
||||||
|
float4 Weight : TEXCOORD0;
|
||||||
|
float4 Joint : TEXCOORD1;
|
||||||
//float3 Normal : TEXCOORD0;
|
//float3 Normal : TEXCOORD0;
|
||||||
//float2 Tex : TEXCOORD1;
|
//float2 Tex : TEXCOORD1;
|
||||||
};
|
};
|
||||||
@ -30,10 +36,22 @@ struct PS_INPUT
|
|||||||
PS_INPUT VS(VS_INPUT input)
|
PS_INPUT VS(VS_INPUT input)
|
||||||
{
|
{
|
||||||
PS_INPUT output = (PS_INPUT)0;
|
PS_INPUT output = (PS_INPUT)0;
|
||||||
output.Pos = mul(input.Pos, World);
|
|
||||||
|
matrix mSkin
|
||||||
|
= input.Weight.x * mJoint[int(input.Joint.x)]
|
||||||
|
+ input.Weight.y * mJoint[int(input.Joint.y)]
|
||||||
|
+ input.Weight.z * mJoint[int(input.Joint.z)]
|
||||||
|
+ input.Weight.w * mJoint[int(input.Joint.w)]
|
||||||
|
;
|
||||||
|
|
||||||
|
output.Pos = mul(input.Pos, mSkin);
|
||||||
|
output.Pos = mul(output.Pos, World);
|
||||||
output.Pos = mul(output.Pos, View);
|
output.Pos = mul(output.Pos, View);
|
||||||
output.Pos = mul(output.Pos, Projection);
|
output.Pos = mul(output.Pos, Projection);
|
||||||
|
|
||||||
|
output.Weight = input.Weight;
|
||||||
|
output.Joint = input.Joint;
|
||||||
|
|
||||||
//output.Normal = mul(input.Normal, World);
|
//output.Normal = mul(input.Normal, World);
|
||||||
//output.Tex = input.Tex;
|
//output.Tex = input.Tex;
|
||||||
return output;
|
return output;
|
||||||
@ -56,7 +74,8 @@ float4 PS(PS_INPUT input) : SV_Target
|
|||||||
|
|
||||||
float4 PSSolid(PS_INPUT input) : SV_Target
|
float4 PSSolid(PS_INPUT input) : SV_Target
|
||||||
{
|
{
|
||||||
return vOutputColor;
|
//return vOutputColor;
|
||||||
|
return float4(input.Weight.xy, input.Joint.y, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
technique10 Render
|
technique10 Render
|
||||||
|
|||||||
39
minimal.h
39
minimal.h
@ -1,39 +0,0 @@
|
|||||||
const DWORD accessor_0[] = {
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const int accessor_0_length = (sizeof (accessor_0)) / (sizeof (accessor_0[0]));
|
|
||||||
|
|
||||||
const D3DXVECTOR3 accessor_1[] = {
|
|
||||||
D3DXVECTOR3( 0.000f, 0.000f, 0.000f),
|
|
||||||
D3DXVECTOR3( 1.000f, 0.000f, 0.000f),
|
|
||||||
D3DXVECTOR3( 0.000f, 1.000f, 0.000f),
|
|
||||||
};
|
|
||||||
|
|
||||||
const int accessor_1_length = (sizeof (accessor_1)) / (sizeof (accessor_1[0]));
|
|
||||||
|
|
||||||
const float accessor_2[] = {
|
|
||||||
0.0,
|
|
||||||
0.25,
|
|
||||||
0.5,
|
|
||||||
0.75,
|
|
||||||
1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const int accessor_2_length = (sizeof (accessor_2)) / (sizeof (accessor_2[0]));
|
|
||||||
|
|
||||||
const D3DXVECTOR4 accessor_3[] = {
|
|
||||||
D3DXVECTOR4( 0.000f, 0.000f, 0.000f, 1.000f),
|
|
||||||
D3DXVECTOR4( 0.000f, 0.000f, 0.707f, 0.707f),
|
|
||||||
D3DXVECTOR4( 0.000f, 0.000f, 1.000f, 0.000f),
|
|
||||||
D3DXVECTOR4( 0.000f, 0.000f, 0.707f, -0.707f),
|
|
||||||
D3DXVECTOR4( 0.000f, 0.000f, 0.000f, 1.000f),
|
|
||||||
};
|
|
||||||
|
|
||||||
const int accessor_3_length = (sizeof (accessor_3)) / (sizeof (accessor_3[0]));
|
|
||||||
|
|
||||||
const Mesh mesh_0 = {
|
|
||||||
1, -1, -1, 0,
|
|
||||||
};
|
|
||||||
187
skin.hpp
Normal file
187
skin.hpp
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
const DWORD accessor_0[] = {
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
5,
|
||||||
|
2,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
7,
|
||||||
|
4,
|
||||||
|
7,
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
9,
|
||||||
|
6,
|
||||||
|
9,
|
||||||
|
8,
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_0_length = (sizeof (accessor_0)) / (sizeof (accessor_0[0]));
|
||||||
|
|
||||||
|
const D3DXVECTOR3 accessor_1[] = {
|
||||||
|
D3DXVECTOR3(-0.5000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3( 0.5000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3(-0.5000000f, 0.5000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3( 0.5000000f, 0.5000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3(-0.5000000f, 1.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3( 0.5000000f, 1.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3(-0.5000000f, 1.5000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3( 0.5000000f, 1.5000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3(-0.5000000f, 2.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR3( 0.5000000f, 2.0000000f, 0.0000000f),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_1_length = (sizeof (accessor_1)) / (sizeof (accessor_1[0]));
|
||||||
|
|
||||||
|
const D3DXVECTOR4 accessor_2[] = {
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_2_length = (sizeof (accessor_2)) / (sizeof (accessor_2[0]));
|
||||||
|
|
||||||
|
const D3DXVECTOR4 accessor_3[] = {
|
||||||
|
D3DXVECTOR4( 1.0000000f, 0.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 1.0000000f, 0.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.7500000f, 0.2500000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.7500000f, 0.2500000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.5000000f, 0.5000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.5000000f, 0.5000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.2500000f, 0.7500000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.2500000f, 0.7500000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_3_length = (sizeof (accessor_3)) / (sizeof (accessor_3[0]));
|
||||||
|
|
||||||
|
const D3DXMATRIX accessor_4[] = {
|
||||||
|
D3DXMATRIX( 1.0000000f, 0.0000000f, 0.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, 0.0000000f, 1.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
D3DXMATRIX( 1.0000000f, 0.0000000f, 0.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, 1.0000000f, 0.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, 0.0000000f, 1.0000000f, 0.0000000f,
|
||||||
|
0.0000000f, -1.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_4_length = (sizeof (accessor_4)) / (sizeof (accessor_4[0]));
|
||||||
|
|
||||||
|
const float accessor_5[] = {
|
||||||
|
0.0,
|
||||||
|
0.5,
|
||||||
|
1.0,
|
||||||
|
1.5,
|
||||||
|
2.0,
|
||||||
|
2.5,
|
||||||
|
3.0,
|
||||||
|
3.5,
|
||||||
|
4.0,
|
||||||
|
4.5,
|
||||||
|
5.0,
|
||||||
|
5.5,
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_5_length = (sizeof (accessor_5)) / (sizeof (accessor_5[0]));
|
||||||
|
|
||||||
|
const D3DXVECTOR4 accessor_6[] = {
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.3830000f, 0.9240000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.7070000f, 0.7070000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.7070000f, 0.7070000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.3830000f, 0.9240000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, -0.3830000f, 0.9240000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, -0.7070000f, 0.7070000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, -0.7070000f, 0.7070000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, -0.3830000f, 0.9240000f),
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int accessor_6_length = (sizeof (accessor_6)) / (sizeof (accessor_6[0]));
|
||||||
|
|
||||||
|
const Mesh mesh_0 = {
|
||||||
|
accessor_1, // position
|
||||||
|
(sizeof (accessor_1)),
|
||||||
|
NULL, // normal
|
||||||
|
0,
|
||||||
|
NULL, // texcoord_0
|
||||||
|
0,
|
||||||
|
accessor_3, // weights_0
|
||||||
|
(sizeof (accessor_3)),
|
||||||
|
accessor_2, // joints_0
|
||||||
|
(sizeof (accessor_2)),
|
||||||
|
accessor_0, // indices
|
||||||
|
(sizeof (accessor_0)),
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const Skin skin_0;
|
||||||
|
const Node node_0 = {
|
||||||
|
&skin_0, // skin
|
||||||
|
&mesh_0, // mesh
|
||||||
|
D3DXVECTOR3( 0.0000000f, 0.0000000f, 0.0000000f), // translation
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f), // rotation
|
||||||
|
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), // scale
|
||||||
|
};
|
||||||
|
|
||||||
|
const Node node_1 = {
|
||||||
|
NULL, // skin
|
||||||
|
NULL, // mesh
|
||||||
|
D3DXVECTOR3( 0.0000000f, 0.0000000f, 0.0000000f), // translation
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f), // rotation
|
||||||
|
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), // scale
|
||||||
|
};
|
||||||
|
|
||||||
|
const Node node_2 = {
|
||||||
|
NULL, // skin
|
||||||
|
NULL, // mesh
|
||||||
|
D3DXVECTOR3( 0.0000000f, 1.0000000f, 0.0000000f), // translation
|
||||||
|
D3DXVECTOR4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f), // rotation
|
||||||
|
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), // scale
|
||||||
|
};
|
||||||
|
|
||||||
|
const Node * skin_0__joints[] = {
|
||||||
|
&node_1,
|
||||||
|
&node_2,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Skin skin_0 = {
|
||||||
|
accessor_4, // inverse bind matrices
|
||||||
|
skin_0__joints, // joints
|
||||||
|
2, // joints length
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnimationSampler animation_0__sampler_0 = {
|
||||||
|
accessor_5, // input, keyframe timestamps
|
||||||
|
accessor_6, // output, keyframe values (void *)
|
||||||
|
accessor_5_length, // length
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnimationChannel animation_0__channels[] = {
|
||||||
|
&animation_0__sampler_0, // animation sampler
|
||||||
|
{
|
||||||
|
&node_2, // target node
|
||||||
|
ACP__ROTATION, // target path
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user