@@ -461,9 +461,9 @@ static int InjectVertices(CMesh* pMesh, int nNewVtx, SMeshBoneMapping_uint8*& pB
461
461
return nVtx0;
462
462
}
463
463
464
- IStatObj* C3DEngine::UpdateDeformableStatObj (IGeometry* pPhysGeom, bop_meshupdate* pLastUpdate, IFoliage* pSrcFoliage)
464
+ IStatObj* C3DEngine::UpdateDeformableStatObj (IGeometry* pPhysGeom, bop_meshupdate* pLastUpdate, IFoliage* pSrcFoliage, IMaterial* pMtlOverride )
465
465
{
466
- int i, j, j1, itri, iop, itriOrg, ivtx, ivtxNew, nTris0, nVtx0, iSubsetB = 0 , nNewVtx, nNewPhysVtx, ivtxRef, bEmptyObj, ibox;
466
+ int i, j, j1, itri, iop, itriOrg, ivtx, ivtxNew, nTris0, nVtx0, iSubsetB = 0 , nNewVtx, nNewPhysVtx, ivtxRef, bEmptyObj, ibox, bSubtract = 1 ;
467
467
int * pIdx2iTri, * piTri2Idx, * pSubsets, * pSubsets0, * pVtxWeld;
468
468
int bHasColors[2 ] = { 0 , 0 };
469
469
vtx_idx* pIdx0, * pIdx;
@@ -522,6 +522,7 @@ IStatObj* C3DEngine::UpdateDeformableStatObj(IGeometry* pPhysGeom, bop_meshupdat
522
522
(pStatObj[0 ] = CreateStatObj ());// ->AddRef();
523
523
pStatObj[0 ]->SetFlags (STATIC_OBJECT_CLONE | STATIC_OBJECT_GENERATED);
524
524
((CStatObj*)pStatObj[0 ])->m_bTmpIndexedMesh = true ;
525
+ bSubtract = 0 ;
525
526
}
526
527
else if (!(pStatObj[0 ]->GetFlags () & STATIC_OBJECT_CLONE))
527
528
{
@@ -613,7 +614,7 @@ IStatObj* C3DEngine::UpdateDeformableStatObj(IGeometry* pPhysGeom, bop_meshupdat
613
614
for (i = 0 ; i < (int )pMesh[0 ]->m_subsets .size (); i++)
614
615
for (j = pMesh[0 ]->m_subsets [i].nFirstIndexId / 3 ; j*3 < pMesh[0 ]->m_subsets [i].nFirstIndexId + pMesh[0 ]->m_subsets [i].nNumIndices ; j++)
615
616
pSubsets[j] = i + (0x1000 & ~-iszero (pMesh[0 ]->m_subsets [i].nPhysicalizeType - PHYS_GEOM_TYPE_DEFAULT));
616
- pMaterial[0 ] = pStatObj[0 ]->GetMaterial ();
617
+ pMaterial[0 ] = pMtlOverride ? pMtlOverride : pStatObj[0 ]->GetMaterial ();
617
618
618
619
for (pmu = pmu0; pmu; pmu = pmu->next )
619
620
{
@@ -876,7 +877,7 @@ IStatObj* C3DEngine::UpdateDeformableStatObj(IGeometry* pPhysGeom, bop_meshupdat
876
877
pmu->pNewVtx [ivtxNew].idxTri [iop] = -(ivtx + 1 );
877
878
878
879
Quat qrot = Quat (IDENTITY) * (1 .0f - iop) + pmu->relRot * (float )iop;
879
- int flip = 1 - (iop & isneg (-pmu->relScale )) * 2 ;
880
+ int flip = 1 - (iop & bSubtract & isneg (-pmu->relScale )) * 2 ;
880
881
881
882
pTexCoord[0 ][ivtx] = SMeshTexCoord (Coord);
882
883
pTangents[0 ][ivtx] = SMeshTangents (qrot * Tangent, qrot * Bitangent, NormalFlip * (int16)flip);
@@ -1460,7 +1461,7 @@ static inline float qmax(float op1, float op2) { return (op1 + op2 + fabsf(op1 -
1460
1461
1461
1462
static int __s_pvtx_map_dummy = 0 ;
1462
1463
1463
- void SyncToRenderMesh (SSyncToRenderMeshContext* ctx, volatile int * updateState )
1464
+ void SyncToRenderMesh (SSyncToRenderMeshContext* ctx)
1464
1465
{
1465
1466
IGeometry* pPhysGeom = ctx->pObj ->GetPhysGeom () ? ctx->pObj ->GetPhysGeom ()->pGeom : 0 ;
1466
1467
if (pPhysGeom)
@@ -1469,14 +1470,7 @@ void SyncToRenderMesh(SSyncToRenderMeshContext* ctx, volatile int* updateState)
1469
1470
IStatObj* pObjSrc = (IStatObj*)pPhysGeom->GetForeignData (0 );
1470
1471
if (pPhysGeom->GetForeignData (DATA_MESHUPDATE) || !ctx->pObj ->m_hasClothTangentsData || pObjSrc != ctx->pObj && pObjSrc != ctx->pObj ->GetCloneSourceObject ())
1471
1472
{
1472
- // skip all updates if the mesh was altered
1473
- if (updateState)
1474
- CryInterlockedDecrement (updateState);
1475
1473
pPhysGeom->Unlock (0 );
1476
-
1477
- if (ctx->pObj ->m_hasClothTangentsData && ctx->pObj ->m_pClothTangentsData )
1478
- ctx->mesh ->UnlockStream (VSF_TANGENTS);
1479
- ctx->mesh ->UnlockStream (VSF_GENERAL);
1480
1474
return ;
1481
1475
}
1482
1476
}
@@ -1487,9 +1481,13 @@ void SyncToRenderMesh(SSyncToRenderMeshContext* ctx, volatile int* updateState)
1487
1481
strided_pointer<Vec3> pVtx = ctx->pVtx ;
1488
1482
int * pVtxMap = (mask == ~0 ) ? &__s_pvtx_map_dummy : ctx->pVtxMap ;
1489
1483
float rscale = ctx->rscale ;
1484
+ ctx->mesh ->LockForThreadAccess ();
1490
1485
SClothTangentVtx* ctd = ctx->ctd ;
1491
- strided_pointer<Vec3> pMeshVtx = ctx->pMeshVtx ;
1492
- strided_pointer<SPipTangents> pTangents = ctx->pTangents ;
1486
+ strided_pointer<Vec3> pMeshVtx;
1487
+ pMeshVtx.data = (Vec3*)ctx->mesh ->GetPosPtr (pMeshVtx.iStride , FSL_SYSTEM_UPDATE);
1488
+ strided_pointer<SPipTangents> pTangents;
1489
+ if (ctx->pObj ->m_hasClothTangentsData && ctx->pObj ->m_pClothTangentsData )
1490
+ pTangents.data = (SPipTangents*)ctx->mesh ->GetTangentPtr (pTangents.iStride , FSL_SYSTEM_UPDATE);
1493
1491
strided_pointer<Vec3> pNormals = ctx->pNormals ;
1494
1492
1495
1493
AABB bbox;
@@ -1532,24 +1530,23 @@ void SyncToRenderMesh(SSyncToRenderMeshContext* ctx, volatile int* updateState)
1532
1530
}
1533
1531
}
1534
1532
1535
- if (updateState)
1536
- CryInterlockedDecrement (updateState);
1537
1533
if (pPhysGeom)
1538
1534
pPhysGeom->Unlock (0 );
1539
1535
1540
1536
if (ctx->pObj ->m_hasClothTangentsData && ctx->pObj ->m_pClothTangentsData )
1541
1537
ctx->mesh ->UnlockStream (VSF_TANGENTS);
1542
1538
ctx->mesh ->UnlockStream (VSF_GENERAL);
1539
+ ctx->mesh ->UnLockForThreadAccess ();
1543
1540
}
1544
1541
1545
1542
DECLARE_JOB (
1546
1543
" StatObj_SyncToRenderMesh"
1547
1544
, TStatObj_SyncToRenderMesh
1548
1545
, SyncToRenderMesh);
1549
1546
1550
- void SkinVertices (SSyncToRenderMeshContext* ctx, volatile int * ready )
1547
+ void SkinVertices (SSyncToRenderMeshContext* ctx)
1551
1548
{
1552
- ctx->pObj ->SkinVertices (ctx->pVtx , Matrix34 (IDENTITY), ready );
1549
+ ctx->pObj ->SkinVertices (ctx->pVtx , Matrix34 (IDENTITY));
1553
1550
}
1554
1551
1555
1552
DECLARE_JOB (
@@ -1562,8 +1559,6 @@ IStatObj* CStatObj::UpdateVertices(strided_pointer<Vec3> pVtx, strided_pointer<V
1562
1559
CStatObj* pObj = this ;
1563
1560
if (m_pRenderMesh)
1564
1561
{
1565
- strided_pointer<Vec3> pMeshVtx;
1566
- strided_pointer<SPipTangents> pTangents;
1567
1562
int i, j, mask = 0 , dummy = 0 , nVtxFull;
1568
1563
if (!pVtxMap)
1569
1564
pVtxMap = &dummy, mask = ~0 ;
@@ -1580,6 +1575,7 @@ IStatObj* CStatObj::UpdateVertices(strided_pointer<Vec3> pVtx, strided_pointer<V
1580
1575
memset (m_pClothTangentsData, 0 , sizeof (SClothTangentVtx) * nVtxFull);
1581
1576
mesh_data* pmd = (mesh_data*)GetPhysGeom ()->pGeom ->GetData ();
1582
1577
m_pRenderMesh->LockForThreadAccess ();
1578
+ strided_pointer<SPipTangents> pTangents;
1583
1579
pTangents.data = (SPipTangents*)m_pRenderMesh->GetTangentPtr (pTangents.iStride , FSL_READ);
1584
1580
for (i = 0 ; i < pmd->nTris ; i++)
1585
1581
for (j = 0 ; j < 3 ; j++)
@@ -1665,11 +1661,9 @@ IStatObj* CStatObj::UpdateVertices(strided_pointer<Vec3> pVtx, strided_pointer<V
1665
1661
{
1666
1662
if (GetCVars ()->e_RenderMeshUpdateAsync )
1667
1663
{
1668
- IRenderMesh* mesh = pObj->m_pRenderMesh ;
1669
- mesh->LockForThreadAccess ();
1670
1664
m_pAsyncUpdateContext->pObj = pObj;
1671
1665
m_pAsyncUpdateContext->pVtx = pVtx;
1672
- TStatObj_SkinVertices job (m_pAsyncUpdateContext, mesh-> SetAsyncUpdateState () );
1666
+ TStatObj_SkinVertices job (m_pAsyncUpdateContext);
1673
1667
job.RegisterJobState (&m_pAsyncUpdateContext->jobState );
1674
1668
job.Run ();
1675
1669
}
@@ -1684,29 +1678,19 @@ IStatObj* CStatObj::UpdateVertices(strided_pointer<Vec3> pVtx, strided_pointer<V
1684
1678
if (!pVtx)
1685
1679
return pObj;
1686
1680
1687
- IRenderMesh* mesh = pObj->m_pRenderMesh ;
1688
- mesh->LockForThreadAccess ();
1689
- pMeshVtx.data = (Vec3*)((mesh = pObj->m_pRenderMesh )->GetPosPtr (pMeshVtx.iStride , FSL_SYSTEM_UPDATE));
1690
- if (m_hasClothTangentsData && m_pClothTangentsData)
1691
- {
1692
- pTangents.data = (SPipTangents*)mesh->GetTangentPtr (pTangents.iStride , FSL_SYSTEM_UPDATE);
1693
- }
1694
-
1695
1681
m_pAsyncUpdateContext->Set (&pObj->m_AABB .min , &pObj->m_AABB .max , iVtx0, nVtx, pVtx, pVtxMap, mask, rscale
1696
- , m_pClothTangentsData, pMeshVtx, pTangents , pNormals, pObj, mesh );
1682
+ , m_pClothTangentsData, nullptr , nullptr , pNormals, pObj, pObj-> m_pRenderMesh );
1697
1683
1698
1684
if (GetCVars ()->e_RenderMeshUpdateAsync )
1699
1685
{
1700
- TStatObj_SyncToRenderMesh job (m_pAsyncUpdateContext, mesh-> SetAsyncUpdateState () );
1686
+ TStatObj_SyncToRenderMesh job (m_pAsyncUpdateContext);
1701
1687
job.RegisterJobState (&m_pAsyncUpdateContext->jobState );
1702
1688
job.Run ();
1703
1689
}
1704
1690
else
1705
1691
{
1706
- SyncToRenderMesh (m_pAsyncUpdateContext, NULL );
1692
+ SyncToRenderMesh (m_pAsyncUpdateContext);
1707
1693
}
1708
-
1709
- mesh->UnLockForThreadAccess ();
1710
1694
}
1711
1695
return pObj;
1712
1696
}
0 commit comments