BVB Source Codes

CRYENGINE Show AttachmentVClothPreProcess.h Source code

Return Download CRYENGINE: download AttachmentVClothPreProcess.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <vector>
  6. #include "CryMath/Cry_Vector3.h"
  7. #include <Cry3DEngine/CGF/CGFContent.h>
  8.  
  9. namespace VClothPreProcessUtils {
  10. struct STriInfo;
  11. }
  12.  
  13. struct AttachmentVClothPreProcessLra
  14. {
  15.         // long range attachments
  16.         int   lraIdx;        // index of closest constraint / attached vtx
  17.         float lraDist;       // distance to closest constraint
  18.         int   lraNextParent; // index of next parent on path to closest constraint
  19.         AttachmentVClothPreProcessLra() : lraIdx(-1), lraDist(0), lraNextParent(-1) {}
  20. };
  21.  
  22. struct SBendTriangle // one triangle which is used for bending forces by neighboring triangle angle
  23. {
  24.         int  p0, p1, p2; // indices of according triangle
  25.         Vec3 normal;
  26.         SBendTriangle(int _p0, int _p1, int _p2) : p0(_p0), p1(_p1), p2(_p2), normal(0) {}
  27.         SBendTriangle() : p0(-1), p1(-1), p2(-1), normal(0) {}
  28.         //std::string toString() { std::stringstream ss; ss << "Bend Triangle: " << p0 << ":" << p1 << ":" << p2; return ss.str(); }
  29. };
  30.  
  31. struct SBendTrianglePair // a pair of triangles which share one edge and is used for bending forces by neighboring triangle angle
  32. {
  33.         int   p0, p1;     // shared edge
  34.         int   p2;         // first triangle // oriented 0,1,2
  35.         int   p3;         // second triangle // reverse oriented 1,0,3
  36.         int   idxNormal0; // idx of BendTriangle for first triangle
  37.         int   idxNormal1; // idx of BendTriangle for second triangle
  38.         float phi0;       // initial angle
  39.         SBendTrianglePair(int _e0, int _e1, int _p2, int _p3, int _idxNormal0, int _idxNormal1) :
  40.                 p0(_e0), p1(_e1), p2(_p2), p3(_p3), idxNormal0(_idxNormal0), idxNormal1(_idxNormal1), phi0(0) {}
  41.         SBendTrianglePair() :
  42.                 p0(-1), p1(-1), p2(-1), p3(-1), idxNormal0(-1), idxNormal1(-1), phi0(0) {}
  43.         //std::string toString() { std::stringstream ss; ss << "BendTrianglePair: Edge: " << p0 << ":" << p1 << " VtxTriangles: " << p2 << ":" << p3; return ss.str(); }
  44. };
  45.  
  46. struct SLink
  47. {
  48.         int   i1, i2;
  49.         float lenSqr, weight1, weight2;
  50.         bool  skip;
  51.  
  52.         SLink() : i1(0), i2(0), lenSqr(0.0f), weight1(0.f), weight2(0.f), skip(false) {}
  53. };
  54.  
  55. struct SAttachmentVClothPreProcessData
  56. {
  57.         // Lra
  58.         std::vector<AttachmentVClothPreProcessLra> m_lra;
  59.         std::vector<int>                           m_lraNotAttachedOrderedIdx;
  60.  
  61.         // Bending by triangle angles, not springs
  62.         std::vector<SBendTrianglePair> m_listBendTrianglePairs; // triangle pairs sharing an edge
  63.         std::vector<SBendTriangle>     m_listBendTriangles;     // triangles which are used for bending
  64.  
  65.         // Links
  66.         std::vector<SLink> m_links[eVClothLink_COUNT];
  67. };
  68.  
  69. struct STopology
  70. {
  71.         int iStartEdge, iEndEdge, iSorted;
  72.         int bFullFan;
  73.  
  74.         STopology() : iStartEdge(0), iEndEdge(0), iSorted(0), bFullFan(0) {}
  75. };
  76.  
  77. struct AttachmentVClothPreProcess
  78. {
  79.         bool                                              PreProcess(std::vector<Vec3> const& vtx, std::vector<int> const& idx, std::vector<bool> const& attached);
  80.  
  81.         std::vector<AttachmentVClothPreProcessLra> const& GetLra() const                      { return m_lra; }
  82.         std::vector<int> const&                           GetLraNotAttachedOrderedIdx() const { return m_lraNotAttachedOrderedIdx; }
  83.  
  84.         std::vector<SBendTrianglePair> const&             GetListBendTrianglePair() const     { return m_listBendTrianglePairs; }
  85.         std::vector<SBendTriangle> const&                 GetListBendTriangle() const         { return m_listBendTriangles; }
  86.  
  87.         std::vector<SLink> const&                         GetLinksStretch() const             { return m_linksStretch; }
  88.         std::vector<SLink> const&                         GetLinksShear() const               { return m_linksShear; }
  89.         std::vector<SLink> const&                         GetLinksBend() const                { return m_linksBend; }
  90.         std::vector<SLink> const&                         GetLinks(int idx) const
  91.         {
  92.                 switch (idx)
  93.                 {
  94.                 default:
  95.                 case 0:
  96.                         return GetLinksStretch();
  97.                 case 1:
  98.                         return GetLinksShear();
  99.                 case 2:
  100.                         return GetLinksBend();
  101.                 }
  102.         }
  103.  
  104.         // helpers which are used in the RC as well as in the engine
  105.         static bool IsAttached(float weight);
  106.         static bool PruneWeldedVertices(std::vector<Vec3>& vtx, std::vector<int>& idx, std::vector<bool>& attached);
  107.         static bool RemoveDegeneratedTriangles(std::vector<Vec3>& vtx, std::vector<int>& idx, std::vector<bool>& attached);
  108.         static bool DetermineTriangleNormals(std::vector<Vec3> const& vtx, std::vector<SBendTriangle>& tri);
  109.         static bool DetermineTriangleNormals(int nVertices, strided_pointer<Vec3> const& pVertices, std::vector<SBendTriangle>& tri);
  110.  
  111. private:
  112.  
  113.         bool LraDijkstra(std::vector<Vec3> const& vtx, std::vector<int> const& idx, std::vector<bool> const& attached);
  114.         bool BendByTriangleAngle(std::vector<Vec3> const& vtx, std::vector<int> const& idx, std::vector<bool> const& attached);
  115.         // links
  116.         bool CreateLinks(std::vector<Vec3> const& vtx, std::vector<int> const& idx);
  117.         bool CalculateTopology(std::vector<Vec3> const& vtx, std::vector<int> const& idx, std::vector<VClothPreProcessUtils::STriInfo>& pTopology); // determine neighboring triangles
  118.  
  119.         // Lra
  120.         std::vector<AttachmentVClothPreProcessLra> m_lra;
  121.         std::vector<int>                           m_lraNotAttachedOrderedIdx;
  122.  
  123.         // Bending by triangle angles, not springs
  124.         std::vector<SBendTrianglePair> m_listBendTrianglePairs; // triangle pairs sharing an edge
  125.         std::vector<SBendTriangle>     m_listBendTriangles;     // triangles which are used for bending
  126.  
  127.         // Links
  128.         std::vector<SLink> m_linksStretch;
  129.         std::vector<SLink> m_linksShear;
  130.         std::vector<SLink> m_linksBend;
  131.  
  132. };
  133.  
  134. inline bool AttachmentVClothPreProcess::IsAttached(float weight)
  135. {
  136.         const float attachedThresh = 0.99f; // weights with a value higher than this are handled as weight=1.0f -> attached
  137.         return weight > attachedThresh;
  138. }
  139.  
downloadAttachmentVClothPreProcess.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top