Page 1 of 1

### Use of api（CreateFromTriMesh）

Posted: Wed Mar 24, 2021 2:28 am
static btSoftBody* CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo,
const btScalar* vertices,
const int* triangles,
int ntriangles,
bool randomizeConstraints = true);
Hello, can you help me explain what these parameters represent and how to obtain them?
const btScalar* vertices,
const int* triangles,
int ntriangles,
thank you very much

### Re: Use of api（CreateFromTriMesh）

Posted: Wed Mar 24, 2021 2:46 pm
You should examine the implementation of btSoftBodyHelpers::CreateFromTriMesh() inside the CPP file to see how they are used. But I would guess:

const btScalar* vertices is a pointer to a buffer of btScalar representing the float or double (depending on if btScaler is a float or double) values the vertices. I would assume (but you can verify by looking at the code) the vertices are in order: xyzxyzxyx..., where each set of three represents a 3D point.

const int* triangles is a pointer to a buffer of int indices representing offsets to points inside the vertices buffer. I would assume (but you can verify by looking at the code) the indices are ordered in sets of three: abcabcabc... where each abc indexes the three points of a triangle.

int ntriangles is "number of triangles". This means the triangles buffer must be 3*ntriangles long. The length of the vertices buffer doesn't matter to the function call: if done correctly the triangles indices should never offset outside of it.

bool randomizeConstraints = true determines if the constraints in the soft body should be solved randomly or systematically. I think: best to leave this true unless you really know how the SoftBody solver works.

### Re: Use of api（CreateFromTriMesh）

Posted: Wed Mar 31, 2021 6:35 am

I tried to use btSoftBodyHelpers::CreateFromTriMesh and btSoftBodyHelpers::CreateFromConvexHull to create the softbody but it has been unsuccessful. Could you please tell me why?

m_size=0 and - m_softBodySolver 0x0000000000000000 <NULL> btSoftBodySolver *

### Re: Use of api（CreateFromTriMesh）

Posted: Wed Mar 31, 2021 2:43 pm
I looked at the code for btSoftBody. AFAICT the m_collisionDisabledObjects vector date member of that class is used when linking soft bodies together with "anchors". If you're not doing that then you would expect that vector container to be empty.

The m_bodySolver is set internally, implicitly when adding the body to the world. The code for setting it looks like this:

Code: Select all

``````        // Set the solver that handles this soft body
// Should not be allowed to get out of sync with reality
// Currently called internally on addition to the world
void setSoftBodySolver(btSoftBodySolver* softBodySolver)
{
m_softBodySolver = softBodySolver;
}``````