Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 6:58:23 PM (14 years ago)
Author:
rgrieder
Message:

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1818#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
    1919#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
     20#include "LinearMath/btSerializer.h"
    2021
    2122///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
     
    2425:btTriangleMeshShape(meshInterface),
    2526m_bvh(0),
     27m_triangleInfoMap(0),
    2628m_useQuantizedAabbCompression(useQuantizedAabbCompression),
    2729m_ownsBvh(false)
     
    3133#ifndef DISABLE_BVH
    3234
    33         btVector3 bvhAabbMin,bvhAabbMax;
    34         if(meshInterface->hasPremadeAabb())
    35         {
    36                 meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);
    37         }
    38         else
    39         {
    40                 meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
    41         }
    42        
    4335        if (buildBvh)
    4436        {
    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();
    4938        }
    5039
     
    5645:btTriangleMeshShape(meshInterface),
    5746m_bvh(0),
     47m_triangleInfoMap(0),
    5848m_useQuantizedAabbCompression(useQuantizedAabbCompression),
    5949m_ownsBvh(false)
     
    344334   {
    345335      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();
    357337   }
     338}
     339
     340void   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;
    358353}
    359354
     
    373368
    374369
     370
     371///fills the dataBuffer and returns the struct name (and 0 on failure)
     372const 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
     442void    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
     453void    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.