Skip to content

Commit

Permalink
for Return to Clear Sky
Browse files Browse the repository at this point in the history
  • Loading branch information
nouverbe authored and Xottab-DUTY committed Jan 20, 2018
1 parent 7875d92 commit eb1b637
Show file tree
Hide file tree
Showing 41 changed files with 1,751 additions and 190 deletions.
286 changes: 207 additions & 79 deletions src/Layers/xrRender/FSkinned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,111 +1142,239 @@ void CSkeletonX_ext::_FillVerticesHW4W(const Fmatrix& view, CSkeletonWallmark& w

#else // USE_DX10

void CSkeletonX_ext::_FillVerticesHW1W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
void CSkeletonX_ext::_FillVerticesHW1W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
{
vertHW_1W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));
for (auto it = faces.begin(); it != faces.end(); ++it)
{
vertHW_1W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));
for (auto it = faces.begin(); it != faces.end(); it++)
Fvector p[3];
u32 idx = *it * 3;
CSkeletonWallmark::WMFace F;

for (u32 k = 0; k < 3; k++)
{
vertHW_1W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone();
F.bone_id[k][1] = F.bone_id[k][0];
F.bone_id[k][2] = F.bone_id[k][0];
F.bone_id[k][3] = F.bone_id[k][0];
F.weight[k][0] = 0.f;
F.weight[k][1] = 0.f;
F.weight[k][2] = 0.f;

const Fmatrix& xform = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
vert.get_pos(F.vert[k]);
xform.transform_tiny(p[k], F.vert[k]);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
vertHW_1W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone();
F.bone_id[k][1] = F.bone_id[k][0];
F.weight[k] = 0.f;
const Fmatrix& xform = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
vert.get_pos(F.vert[k]);
xform.transform_tiny(p[k], F.vert[k]);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
CHK_DX(V->p_rm_Vertices->Unlock());
}
void CSkeletonX_ext::_FillVerticesHW2W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
CHK_DX(V->p_rm_Vertices->Unlock());
}

void CSkeletonX_ext::_FillVerticesHW2W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
{
vertHW_2W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));

for (auto it = faces.begin(); it != faces.end(); ++it)
{
vertHW_2W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));
Fvector p[3];
u32 idx = *it * 3;
CSkeletonWallmark::WMFace F;

for (auto it = faces.begin(); it != faces.end(); ++it)
for (u32 k = 0; k < 3; k++)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;
Fvector P0, P1;

vertHW_2W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone(0);
F.bone_id[k][1] = vert.get_bone(1);
F.bone_id[k][2] = F.bone_id[k][1];
F.bone_id[k][3] = F.bone_id[k][1];
F.weight[k][0] = vert.get_weight();
F.weight[k][1] = 0.f;
F.weight[k][2] = 0.f;

Fmatrix& xform0 = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
Fmatrix& xform1 = Parent->LL_GetBoneInstance(F.bone_id[k][1]).mRenderTransform;
vert.get_pos(F.vert[k]);
xform0.transform_tiny(P0, F.vert[k]);
xform1.transform_tiny(P1, F.vert[k]);
p[k].lerp(P0, P1, F.weight[k][0]);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS) continue;

if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector P0, P1;
vertHW_2W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone(0);
F.bone_id[k][1] = vert.get_bone(1);
F.weight[k] = vert.get_weight();
Fmatrix& xform0 = Parent->LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
Fmatrix& xform1 = Parent->LL_GetBoneInstance(F.bone_id[k][1]).mRenderTransform;
vert.get_pos(F.vert[k]);
xform0.transform_tiny(P0, F.vert[k]);
xform1.transform_tiny(P1, F.vert[k]);
p[k].lerp(P0, P1, F.weight[k]);
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;
wm.m_Faces.push_back(F);
}
}
CHK_DX(V->p_rm_Vertices->Unlock());
}

void CSkeletonX_ext::_FillVerticesHW3W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
{
vertHW_3W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));

for (auto it = faces.begin(); it != faces.end(); ++it)
{
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;

if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
for (u32 k = 0; k < 3; k++)
{
vertHW_3W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone(0);
F.bone_id[k][1] = vert.get_bone(1);
F.bone_id[k][2] = vert.get_bone(2);
F.bone_id[k][3] = F.bone_id[k][2];
F.weight[k][0] = vert.get_weight0();
F.weight[k][1] = vert.get_weight1();
F.weight[k][2] = 0.f;
vert.get_pos(F.vert[k]);
vert.get_pos_bones(p[k], Parent);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;

if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
CHK_DX(V->p_rm_Vertices->Unlock());
}
CHK_DX(V->p_rm_Vertices->Unlock());
}

void CSkeletonX_ext::_FillVerticesHW3W(const Fmatrix& /*view*/, CSkeletonWallmark& /*wm*/, const Fvector& /*normal*/,
float /*size*/, Fvisual* /*V*/, u16* /*indices*/, CBoneData::FacesVec& /*faces*/)
{
R_ASSERT2(0, "CSkeletonX_ext::_FillVerticesHW3W not implemented");
}
void CSkeletonX_ext::_FillVerticesHW4W(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16* indices, CBoneData::FacesVec& faces)
{
vertHW_4W* vertices;
CHK_DX(V->p_rm_Vertices->Lock(V->vBase, V->vCount, (void**)&vertices, D3DLOCK_READONLY));

void CSkeletonX_ext::_FillVerticesHW4W(const Fmatrix& /*view*/, CSkeletonWallmark& /*wm*/, const Fvector& /*normal*/,
float /*size*/, Fvisual* /*V*/, u16* /*indices*/, CBoneData::FacesVec& /*faces*/)
for (auto it = faces.begin(); it != faces.end(); ++it)
{
R_ASSERT2(0, "CSkeletonX_ext::_FillVerticesHW4W not implemented");
Fvector p[3];
u32 idx = (*it) * 3;
CSkeletonWallmark::WMFace F;

for (u32 k = 0; k < 3; k++)
{
vertHW_4W& vert = vertices[indices[idx + k]];
F.bone_id[k][0] = vert.get_bone(0);
F.bone_id[k][1] = vert.get_bone(1);
F.bone_id[k][2] = vert.get_bone(2);
F.bone_id[k][3] = vert.get_bone(3);
F.weight[k][0] = vert.get_weight0();
F.weight[k][1] = vert.get_weight1();
F.weight[k][2] = vert.get_weight2();
vert.get_pos(F.vert[k]);
vert.get_pos_bones(p[k], Parent);
}
Fvector test_normal;
test_normal.mknormal(p[0], p[1], p[2]);
float cosa = test_normal.dotproduct(normal);
if (cosa < EPS)
continue;

if (CDB::TestSphereTri(wm.ContactPoint(), size, p))
{
Fvector UV;
for (u32 k = 0; k < 3; k++)
{
Fvector2& uv = F.uv[k];
view.transform_tiny(UV, p[k]);
uv.x = (1 + UV.x) * .5f;
uv.y = (1 - UV.y) * .5f;
}
wm.m_Faces.push_back(F);
}
}
CHK_DX(V->p_rm_Vertices->Unlock());
}
#endif // USE_DX10

void CSkeletonX_ext::_FillVertices(const Fmatrix& /*view*/, CSkeletonWallmark& /*wm*/, const Fvector& /*normal*/,
float /*size*/, Fvisual* /*V*/, u16 /*bone_id*/, u32 /*iBase*/, u32 /*iCount*/)
void CSkeletonX_ext::_FillVertices(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal,
float size, Fvisual* V, u16 bone_id, u32 iBase, u32 /*iCount*/)
{
R_ASSERT2(0, "CSkeletonX_ext::_FillVertices not implemented");
VERIFY(Parent && ChildIDX != u16(-1));
CBoneData& BD = Parent->LL_GetData(bone_id);
CBoneData::FacesVec* faces = &BD.child_faces[ChildIDX];
u16* indices = nullptr;
#if defined(USE_DX10) || defined(USE_DX11)
indices = *m_Indices;
#else // USE_DX10
CHK_DX(V->p_rm_Indices->Lock(0, V->dwPrimitives * 3, (void**)&indices, D3DLOCK_READONLY));
// fill vertices
switch (RenderMode)
{
case RM_SKINNING_SOFT:
#endif // USE_DX10
if (*Vertices1W) _FillVerticesSoft1W(view, wm, normal, size, indices + iBase, *faces);
else if (*Vertices2W) _FillVerticesSoft2W(view, wm, normal, size, indices + iBase, *faces);
else if (*Vertices3W) _FillVerticesSoft3W(view, wm, normal, size, indices + iBase, *faces);
else
{
VERIFY(!!*Vertices4W);
_FillVerticesSoft4W(view, wm, normal, size, indices + iBase, *faces);
}
#if !defined(USE_DX10) && !defined(USE_DX11)
break;
case RM_SINGLE:
case RM_SKINNING_1B: _FillVerticesHW1W(view, wm, normal, size, V, indices + iBase, *faces);
break;
case RM_SKINNING_2B: _FillVerticesHW2W(view, wm, normal, size, V, indices + iBase, *faces);
break;
case RM_SKINNING_3B: _FillVerticesHW3W(view, wm, normal, size, V, indices + iBase, *faces);
break;
case RM_SKINNING_4B: _FillVerticesHW4W(view, wm, normal, size, V, indices + iBase, *faces);
break;
}
CHK_DX(V->p_rm_Indices->Unlock());
#endif // USE_DX10
}
/*
void CSkeletonX_ext::_FillVertices(const Fmatrix& view, CSkeletonWallmark& wm, const Fvector& normal, float size,
Expand Down
47 changes: 44 additions & 3 deletions src/Layers/xrRender/SkeletonCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ void CKinematics::AddWallmark(
intrusive_ptr<CSkeletonWallmark> wm = new CSkeletonWallmark(this, parent_xform, shader, cp, RDEVICE.fTimeGlobal);
wm->m_LocalBounds.set(cp, size * 2.f);
wm->XFORM()->transform_tiny(wm->m_Bounds.P, cp);
wm->m_Bounds.R = wm->m_Bounds.R;
wm->m_Bounds.R = wm->m_LocalBounds.R;

Fvector tmp;
tmp.invert(D);
Expand Down Expand Up @@ -786,15 +786,56 @@ void CKinematics::RenderWallmark(intrusive_ptr<CSkeletonWallmark> wm, FVF::LIT*&
Fmatrix& xform0 = LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
xform0.transform_tiny(P, F.vert[k]);
}
else
else if (F.bone_id[k][1] == F.bone_id[k][2])
{
// 2-link
Fvector P0, P1;
Fmatrix& xform0 = LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
Fmatrix& xform1 = LL_GetBoneInstance(F.bone_id[k][1]).mRenderTransform;
xform0.transform_tiny(P0, F.vert[k]);
xform1.transform_tiny(P1, F.vert[k]);
P.lerp(P0, P1, F.weight[k]);
P.lerp(P0, P1, F.weight[k][0]);
}
else if (F.bone_id[k][2] == F.bone_id[k][3])
{
// 3-link
Fvector P0, P1, P2;
Fmatrix& xform0 = LL_GetBoneInstance(F.bone_id[k][0]).mRenderTransform;
Fmatrix& xform1 = LL_GetBoneInstance(F.bone_id[k][1]).mRenderTransform;
Fmatrix& xform2 = LL_GetBoneInstance(F.bone_id[k][2]).mRenderTransform;
xform0.transform_tiny(P0, F.vert[k]);
xform1.transform_tiny(P1, F.vert[k]);
xform2.transform_tiny(P2, F.vert[k]);
float w0 = F.weight[k][0];
float w1 = F.weight[k][1];
P0.mul(w0);
P1.mul(w1);
P2.mul(1 - w0 - w1);
P = P0;
P.add(P1);
P.add(P2);
}
else
{
// 4-link
Fvector PB[4];
for (int i = 0; i < 4; ++i)
{
Fmatrix& xform = LL_GetBoneInstance(F.bone_id[k][i]).mRenderTransform;
xform.transform_tiny(PB[i], F.vert[k]);
}

float s = 0.f;
for (int i = 0; i < 3; ++i)
{
PB[i].mul(F.weight[k][i]);
s += F.weight[k][i];
}
PB[3].mul(1 - s);

P = PB[0];
for (int i = 1; i < 4; ++i)
P.add(PB[i]);
}
wm->XFORM()->transform_tiny(V->p, P);
V->t.set(F.uv[k]);
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/SkeletonCustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class CSkeletonWallmark : public intrusive_base // 4+4+4+12+4+16+16 = 60 + 4 = 6
{
Fvector3 vert[3];
Fvector2 uv[3];
u16 bone_id[3][2];
float weight[3];
u16 bone_id[3][4];
float weight[3][3];
};
using WMFacesVec = xr_vector<WMFace>;
WMFacesVec m_Faces; // 16
Expand Down
Loading

2 comments on commit eb1b637

@Xottab-DUTY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #382

@Xottab-DUTY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original commit: morrey/xray-16@4a988aa

Please sign in to comment.