| 347 | } |
| 348 | |
| 349 | void TerrainObject::PreparePhysicsMesh() { |
| 350 | static const bool kCachePhysicsShape = false; |
| 351 | if (!added_to_physics_scene_) { |
| 352 | btBvhTriangleMeshShape* cached_shape = NULL; |
| 353 | const char* cache_path = "terrain_serialize.bullet"; |
| 354 | if (kCachePhysicsShape) { |
| 355 | /*char abs_path[kPathSize]; |
| 356 | if(FindFilePath(cache_path, abs_path, kPathSize, kDataPaths|kModPaths|kWriteDir|kModWriteDirs) != -1) { |
| 357 | btBulletWorldImporter import(0);//don't store info into the world |
| 358 | PROFILER_ZONE(g_profiler_ctx, "Loading cache file"); |
| 359 | if (import.loadFile(abs_path)){ |
| 360 | int numShape = import.getNumCollisionShapes(); |
| 361 | if (numShape) { |
| 362 | cached_shape = (btBvhTriangleMeshShape*)import.getCollisionShapeByIndex(0); |
| 363 | } |
| 364 | } |
| 365 | }*/ |
| 366 | } |
| 367 | if (cached_shape) { |
| 368 | PROFILER_ZONE(g_profiler_ctx, "Adding cached shape to physics scene"); |
| 369 | SharedShapePtr shape; |
| 370 | shape.reset(cached_shape); |
| 371 | BulletObject* obj = scenegraph_->bullet_world_->CreateRigidBody(shape, 0.0f, BW_NO_FLAGS); |
| 372 | obj->body->setCollisionFlags(obj->body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); |
| 373 | bullet_object_ = obj; |
| 374 | } else { |
| 375 | PROFILER_ZONE(g_profiler_ctx, "Creating new static mesh"); |
| 376 | bullet_object_ = scenegraph_->bullet_world_->CreateStaticMesh(&terrain_.GetModel(), -1, BW_NO_FLAGS); |
| 377 | |
| 378 | if (kCachePhysicsShape) { |
| 379 | /*PROFILER_ZONE(g_profiler_ctx, "Serializing cached mesh to disk"); |
| 380 | int maxSerializeBufferSize = 1024*1024*10; |
| 381 | btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize); |
| 382 | |
| 383 | serializer->startSerialization(); |
| 384 | bullet_object_->shape->serializeSingleShape(serializer); |
| 385 | serializer->finishSerialization(); |
| 386 | |
| 387 | char path[kPathSize]; |
| 388 | FormatString(path, kPathSize, "%s%s", GetWritePath(CoreGameModID).c_str(), cache_path); |
| 389 | FILE* file = my_fopen(path, "wb"); |
| 390 | fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file); |
| 391 | fclose(file); |
| 392 | |
| 393 | delete serializer;*/ |
| 394 | } |
| 395 | } |
| 396 | bullet_object_->owner_object = this; |
| 397 | added_to_physics_scene_ = true; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | const Model* TerrainObject::GetModel() const { |
| 402 | return &terrain_.GetModel(); |
no test coverage detected