Destruct Mesh.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /******************************************************************************
  2. Use 'DestructMesh' to pre-generate destructible meshes and their physical representation.
  3. /******************************************************************************/
  4. struct DestructMesh
  5. {
  6. struct Part
  7. {
  8. Mesh mesh;
  9. PhysPart phys;
  10. #if EE_PRIVATE
  11. void del ();
  12. Bool create(Mesh &src, Int vtx_limit);
  13. Bool save (File &f)C;
  14. Bool load (File &f) ;
  15. #endif
  16. };
  17. struct Joint
  18. {
  19. Int a, b; // part indexes
  20. #if EE_PRIVATE
  21. void set(Int a, Int b) {T.a=a; T.b=b;}
  22. #endif
  23. };
  24. // get
  25. Bool is ( )C {return _parts .elms()>0;} // if has any data
  26. Part& part (Int i) {return _parts [i] ;} // get i-th part
  27. Int parts ( )C {return _parts .elms() ;} // get number of parts
  28. C Joint& joint (Int i)C {return _joints[i] ;} // get i-th joint
  29. Int joints( )C {return _joints.elms() ;} // get number of joints
  30. // manage
  31. DestructMesh& del (); // manually delete
  32. DestructMesh& create(Mesh &mesh, Int cuts, C MaterialPtr &material, Flt tex_scale=1, Int phys_vtx_limit=-1, Bool cut_affects_biggest_part=true, Bool simple_cuts=false); // create destructible object from 'mesh', use 'cuts' number of plane cuts to split the mesh, use 'material' for creating the solid inside part with 'tex_scale' texture scaling, 'phys_vtx_limit'=limit for number of vertexes in each physical body part (used only when >0), 'cut_affects_biggest_part'=if apply cutting to the biggest part only or the whole mesh, 'simple_cuts'=if use simplified mesh splitting algorithm that does not create the solid inside faces (if true then 'material' will be ignored)
  33. // operations
  34. Bool adjustStorage (Bool universal, Bool physx, Bool bullet, Bool *changed=null); // adjust the type of storage for the physical body, 'universal'=can be used for both PhysX and Bullet, 'physx'=can be used for PhysX (and when used there it is faster than 'universal'), 'bullet'=can be used for Bullet (and when used there it is faster than 'universal'), each storage uses additional space, for PhysX only games it is suggested to set 'physx' to true and others to false, for Bullet only games it is suggested to set 'bullet' to true and others to false, please note if you call this method under engine compiled with Bullet library, you won't be able to use any PhysX information (which means converting from or to PhysX storage), 'changed'=pointer to custom bool which will be set to true if any change was performed on the physical body (false otherwise), false on fail
  35. DestructMesh& freeHelperData( ); // this free's up the helper data of the physical body, which increases available memory, however it disables saving the body to file, or converting it to 'MeshBase'
  36. #if EE_PRIVATE
  37. void setShader();
  38. // draw
  39. void drawMesh(Int highlight_part=-1)C; // call in RM_PREPARE
  40. void drawPhys( )C; // call outside of Render
  41. #endif
  42. // io
  43. Bool save(C Str &name); // save, false on fail
  44. Bool load(C Str &name); // load, false on fail
  45. private:
  46. Mems<Part > _parts ;
  47. Mems<Joint> _joints;
  48. };
  49. /******************************************************************************/
  50. extern Cache<DestructMesh> DestructMeshes;
  51. /******************************************************************************/