Changeset 8284 for code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
- Timestamp:
- Apr 21, 2011, 6:58:23 PM (14 years ago)
- Location:
- code/branches/kicklib2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib2
- Property svn:mergeinfo changed
-
code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
r5781 r8284 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 18 18 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" 19 19 #include "BulletCollision/CollisionShapes/btOptimizedBvh.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 ///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization. … … 24 25 :btTriangleMeshShape(meshInterface), 25 26 m_bvh(0), 27 m_triangleInfoMap(0), 26 28 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 27 29 m_ownsBvh(false) … … 31 33 #ifndef DISABLE_BVH 32 34 33 btVector3 bvhAabbMin,bvhAabbMax;34 if(meshInterface->hasPremadeAabb())35 {36 meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);37 }38 else39 {40 meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);41 }42 43 35 if (buildBvh) 44 36 { 45 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 46 m_bvh = new (mem) btOptimizedBvh(); 47 m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax); 48 m_ownsBvh = true; 37 buildOptimizedBvh(); 49 38 } 50 39 … … 56 45 :btTriangleMeshShape(meshInterface), 57 46 m_bvh(0), 47 m_triangleInfoMap(0), 58 48 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 59 49 m_ownsBvh(false) … … 344 334 { 345 335 btTriangleMeshShape::setLocalScaling(scaling); 346 if (m_ownsBvh) 347 { 348 m_bvh->~btOptimizedBvh(); 349 btAlignedFree(m_bvh); 350 } 351 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 352 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 353 m_bvh = new(mem) btOptimizedBvh(); 354 //rebuild the bvh... 355 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 356 m_ownsBvh = true; 336 buildOptimizedBvh(); 357 337 } 338 } 339 340 void btBvhTriangleMeshShape::buildOptimizedBvh() 341 { 342 if (m_ownsBvh) 343 { 344 m_bvh->~btOptimizedBvh(); 345 btAlignedFree(m_bvh); 346 } 347 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 348 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 349 m_bvh = new(mem) btOptimizedBvh(); 350 //rebuild the bvh... 351 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 352 m_ownsBvh = true; 358 353 } 359 354 … … 373 368 374 369 370 371 ///fills the dataBuffer and returns the struct name (and 0 on failure) 372 const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const 373 { 374 btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer; 375 376 btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer); 377 378 m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer); 379 380 trimeshData->m_collisionMargin = float(m_collisionMargin); 381 382 383 384 if (m_bvh && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_BVH)) 385 { 386 void* chunk = serializer->findPointer(m_bvh); 387 if (chunk) 388 { 389 #ifdef BT_USE_DOUBLE_PRECISION 390 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk; 391 trimeshData->m_quantizedFloatBvh = 0; 392 #else 393 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)chunk; 394 trimeshData->m_quantizedDoubleBvh= 0; 395 #endif //BT_USE_DOUBLE_PRECISION 396 } else 397 { 398 399 #ifdef BT_USE_DOUBLE_PRECISION 400 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 401 trimeshData->m_quantizedFloatBvh = 0; 402 #else 403 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 404 trimeshData->m_quantizedDoubleBvh= 0; 405 #endif //BT_USE_DOUBLE_PRECISION 406 407 int sz = m_bvh->calculateSerializeBufferSizeNew(); 408 btChunk* chunk = serializer->allocate(sz,1); 409 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 410 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh); 411 } 412 } else 413 { 414 trimeshData->m_quantizedFloatBvh = 0; 415 trimeshData->m_quantizedDoubleBvh = 0; 416 } 417 418 419 420 if (m_triangleInfoMap && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_TRIANGLEINFOMAP)) 421 { 422 void* chunk = serializer->findPointer(m_triangleInfoMap); 423 if (chunk) 424 { 425 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk; 426 } else 427 { 428 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap); 429 int sz = m_triangleInfoMap->calculateSerializeBufferSize(); 430 btChunk* chunk = serializer->allocate(sz,1); 431 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 432 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,m_triangleInfoMap); 433 } 434 } else 435 { 436 trimeshData->m_triangleInfoMap = 0; 437 } 438 439 return "btTriangleMeshShapeData"; 440 } 441 442 void btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const 443 { 444 if (m_bvh) 445 { 446 int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place 447 btChunk* chunk = serializer->allocate(len,1); 448 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 449 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh); 450 } 451 } 452 453 void btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const 454 { 455 if (m_triangleInfoMap) 456 { 457 int len = m_triangleInfoMap->calculateSerializeBufferSize(); 458 btChunk* chunk = serializer->allocate(len,1); 459 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 460 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap); 461 } 462 } 463 464 465 466
Note: See TracChangeset
for help on using the changeset viewer.