diff options
Diffstat (limited to 'source/gameengine/Physics/Bullet/CcdPhysicsController.cpp')
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 98e67afdd44..767854e5725 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -214,6 +214,7 @@ bool CcdPhysicsController::CreateSoftbody() } } else { + int numtris = 0; if (m_cci.m_collisionShape->getShapeType() ==SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) { btScaledBvhTriangleMeshShape* scaledtrimeshshape = (btScaledBvhTriangleMeshShape*) m_cci.m_collisionShape; @@ -228,7 +229,6 @@ bool CcdPhysicsController::CreateSoftbody() int vertexstride; unsigned char* indexbase; int indexstride; - int numtris; PHY_ScalarType indexType; trimeshshape->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numverts,vertexType,vertexstride,&indexbase,indexstride,numtris,indexType); @@ -246,14 +246,21 @@ bool CcdPhysicsController::CreateSoftbody() int vertexstride; unsigned char* indexbase; int indexstride; - int numtris; PHY_ScalarType indexType; trimeshshape->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numverts,vertexType,vertexstride,&indexbase,indexstride,numtris,indexType); psb = btSoftBodyHelpers::CreateFromTriMesh(worldInfo,(const btScalar*)vertexBase,(const int*)indexbase,numtris); } } - + // store face tag so that we can find our original face when doing ray casting + btSoftBody::Face* ft; + int i; + for (i=0, ft=&psb->m_faces[0]; i<numtris; ++i, ++ft) + { + // Hack!! use m_tag to store the face number, normally it is a pointer + // add 1 to make sure it is never 0 + ft->m_tag = (void*)((uintptr_t)(i+1)); + } } if (m_cci.m_margin > 0.f) { @@ -1402,6 +1409,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, m_vertexArray.clear(); m_polygonIndexArray.clear(); m_triFaceArray.clear(); + m_triFaceUVcoArray.clear(); return false; } @@ -1415,6 +1423,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, numpolys = dm->getNumFaces(dm); numverts = dm->getNumVerts(dm); int* index = (int*)dm->getFaceDataArray(dm, CD_ORIGINDEX); + MTFace *tface = (MTFace *)dm->getFaceDataArray(dm, CD_MTFACE); m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH; @@ -1515,14 +1524,23 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, m_vertexArray.resize(tot_bt_verts*3); m_polygonIndexArray.resize(tot_bt_tris); m_triFaceArray.resize(tot_bt_tris*3); - btScalar *bt= &m_vertexArray[0]; int *poly_index_pt= &m_polygonIndexArray[0]; int *tri_pt= &m_triFaceArray[0]; + UVco *uv_pt = NULL; + if (tface) + { + m_triFaceUVcoArray.resize(tot_bt_tris*3); + uv_pt = &m_triFaceUVcoArray[0]; + } + else + m_triFaceUVcoArray.clear(); + for (int p2=0; p2<numpolys; p2++) { MFace* mf = &mface[p2]; + MTFace* tf = (tface) ? &tface[p2] : NULL; RAS_Polygon* poly= meshobj->GetPolygon(index[p2]); // only add polygons that have the collisionflag set @@ -1537,6 +1555,16 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, tri_pt[1]= vert_remap_array[mf->v2]; tri_pt[2]= vert_remap_array[mf->v3]; tri_pt= tri_pt+3; + if (tf) + { + uv_pt[0].uv[0] = tf->uv[0][0]; + uv_pt[0].uv[1] = tf->uv[0][1]; + uv_pt[1].uv[0] = tf->uv[1][0]; + uv_pt[1].uv[1] = tf->uv[1][1]; + uv_pt[2].uv[0] = tf->uv[2][0]; + uv_pt[2].uv[1] = tf->uv[2][1]; + uv_pt += 3; + } // m_polygonIndexArray *poly_index_pt= index[p2]; @@ -1570,6 +1598,16 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, tri_pt[1]= vert_remap_array[mf->v3]; tri_pt[2]= vert_remap_array[mf->v4]; tri_pt= tri_pt+3; + if (tf) + { + uv_pt[0].uv[0] = tf->uv[0][0]; + uv_pt[0].uv[1] = tf->uv[0][1]; + uv_pt[1].uv[0] = tf->uv[2][0]; + uv_pt[1].uv[1] = tf->uv[2][1]; + uv_pt[2].uv[0] = tf->uv[3][0]; + uv_pt[2].uv[1] = tf->uv[3][1]; + uv_pt += 3; + } // m_polygonIndexArray *poly_index_pt= index[p2]; @@ -1728,10 +1766,12 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA m_triFaceArray.resize(tot_bt_tris*3); int *tri_pt= &m_triFaceArray[0]; + m_triFaceUVcoArray.resize(tot_bt_tris*3); + UVco *uv_pt= &m_triFaceUVcoArray[0]; + m_polygonIndexArray.resize(tot_bt_tris); int *poly_index_pt= &m_polygonIndexArray[0]; - for(mf= mface, tf= tface, i=0; i < numpolys; mf++, tf++, i++) { if(tf->mode & TF_DYNAMIC) @@ -1760,6 +1800,9 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA vert_tag_array[v_orig]= false; } *tri_pt++ = vert_remap_array[v_orig]; + uv_pt->uv[0] = tf->uv[*fv_pt][0]; + uv_pt->uv[1] = tf->uv[*fv_pt][1]; + uv_pt++; } } } @@ -1782,6 +1825,8 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA m_polygonIndexArray.resize(tot_bt_tris); int *poly_index_pt= &m_polygonIndexArray[0]; + m_triFaceUVcoArray.clear(); + for(mv= mvert, i=0; i < numverts; mv++, i++) { *bt++ = mv->co[0]; *bt++ = mv->co[1]; *bt++ = mv->co[2]; } |