Mesh Csg.h 6.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /******************************************************************************/
  2. enum SEL_FLAG // Selection Flag
  3. {
  4. SEL_A =0x1, // if A present
  5. SEL_B =0x2, // if B present
  6. SEL_AB=0x4, // if AB present
  7. SEL_OR =SEL_A|SEL_B|SEL_AB, // A|B
  8. SEL_XOR =SEL_A|SEL_B , // A^B
  9. SEL_AND = SEL_AB, // A&B
  10. SEL_ADD =SEL_A|SEL_B|SEL_AB, // A+B
  11. SEL_SUB =SEL_A , // A-B
  12. SEL_SUBR= SEL_B , // B-A
  13. SEL_MUL = SEL_AB, // A*B
  14. };
  15. /******************************************************************************/
  16. #if EE_PRIVATE
  17. enum SIDE_TYPE
  18. {
  19. SIDE_NONE=-1,
  20. SIDE_L = 0,
  21. SIDE_R = 1,
  22. };
  23. enum
  24. {
  25. TYPE_A=0,
  26. TYPE_B=1,
  27. };
  28. enum SOLID_FLAG
  29. {
  30. SOLID_AL =0x01,
  31. SOLID_AR =0x02,
  32. SOLID_BL =0x04,
  33. SOLID_BR =0x08,
  34. SOLID_NAL=0x10,
  35. SOLID_NAR=0x20,
  36. SOLID_NBL=0x40,
  37. SOLID_NBR=0x80,
  38. SOLID_A =SOLID_AL|SOLID_AR| SOLID_NAL|SOLID_NAR ,
  39. SOLID_B = SOLID_BL|SOLID_BR| SOLID_NBL|SOLID_NBR,
  40. SOLID_L =SOLID_AL| SOLID_BL| SOLID_NAL| SOLID_NBL ,
  41. SOLID_R = SOLID_AR| SOLID_BR| SOLID_NAR| SOLID_NBR,
  42. SOLID_YES=SOLID_AL|SOLID_AR|SOLID_BL|SOLID_BR ,
  43. SOLID_NO = SOLID_NAL|SOLID_NAR|SOLID_NBL|SOLID_NBR,
  44. SOLID_ALL=SOLID_AL|SOLID_AR|SOLID_BL|SOLID_BR|SOLID_NAL|SOLID_NAR|SOLID_NBL|SOLID_NBR,
  45. };
  46. /******************************************************************************/
  47. inline UInt SolidT ( Bool type ) {return (type==TYPE_A) ? SOLID_A : SOLID_B ;}
  48. inline UInt SolidS ( Bool side ) {return (side==SIDE_L) ? SOLID_L : SOLID_R ;}
  49. inline UInt SolidI ( Bool is) {return is ? SOLID_YES : SOLID_NO;}
  50. inline UInt SolidTI ( Bool type, Bool is) {return SolidT(type)& SolidI(is);}
  51. inline UInt SolidTSI ( Bool type, Bool side, Bool is) {return SolidT(type)&SolidS(side)&SolidI(is);}
  52. inline UInt SolidT (UInt flag, Bool type ) {return flag&SolidT(type) ;}
  53. inline UInt SolidS (UInt flag, Bool side ) {return flag& SolidS(side);}
  54. inline UInt SolidTS (UInt flag, Bool type, Bool side ) {return flag&SolidT(type)&SolidS(side);}
  55. inline Bool IsSolidTS (UInt flag, Bool type, Bool side ) {return (SolidTS(flag, type, side)&SOLID_YES)!=0;}
  56. UInt SolidSwap(UInt flag);
  57. #endif
  58. /******************************************************************************/
  59. void Csg(MeshBase &a, C MeshBase &b, UInt sel, MeshBase *dest=null, Bool detect_self_intersections=false, Flt weld_pos_eps=0.0001f); // perform a CSG operation on 'a b' meshes, 'sel'=SEL_FLAG, 'dest'=output mesh (if set to null then it will be set to 'a'), 'detect_self_intersections'=if detect self intestections between 'a' mesh faces, and self intersections between 'b' mesh faces (this will make Csg perform slower but correctly handle situations where 'a' mesh faces intersect each other or 'b' mesh faces intersect each other), 'weld_pos_eps'=epsilon used for final vertex position welding, if you're getting incorrect results you can try calling first 'removeDegenerateFaces' on meshes
  60. void Csg(MeshLod &a, C MeshLod &b, UInt sel, MeshLod *dest=null, Bool detect_self_intersections=false, Flt weld_pos_eps=0.0001f); // perform a CSG operation on 'a b' meshes, 'sel'=SEL_FLAG, 'dest'=output mesh (if set to null then it will be set to 'a'), 'detect_self_intersections'=if detect self intestections between 'a' mesh faces, and self intersections between 'b' mesh faces (this will make Csg perform slower but correctly handle situations where 'a' mesh faces intersect each other or 'b' mesh faces intersect each other), 'weld_pos_eps'=epsilon used for final vertex position welding, if you're getting incorrect results you can try calling first 'removeDegenerateFaces' on meshes
  61. void ClipMesh (C MeshBase &src, C Matrix *matrix, MeshBase &dest , C Plane *clip_plane, Int clip_planes, UInt flag_and=~0, Flt weld_pos_eps=EPS); // generate 'src' mesh transformed by 'matrix' and then clipped by 'clip_planes' (if the 'matrix' is null then the mesh is not transformed), result is stored in 'dest' , 'weld_pos_eps'=epsilon used for final vertex position welding, 'flag_and'=elements to include in 'dest' creation (MESH_BASE_FLAG)
  62. void ClipMesh (C Mesh &src, C Matrix *matrix, Mesh &dest , C Plane *clip_plane, Int clip_planes, UInt flag_and=~0, Flt weld_pos_eps=EPS); // generate 'src' mesh transformed by 'matrix' and then clipped by 'clip_planes' (if the 'matrix' is null then the mesh is not transformed), result is stored in 'dest' , 'weld_pos_eps'=epsilon used for final vertex position welding, 'flag_and'=elements to include in 'dest' creation (MESH_BASE_FLAG)
  63. void SplitMesh (C Mesh &src, C Matrix *matrix, Mesh &dest_positive, Mesh &dest_negative, C Plane &clip_plane, UInt flag_and=~0, Flt weld_pos_eps=EPS); // generate 'src' mesh transformed by 'matrix' and then split by 'clip_plane' (if the 'matrix' is null then the mesh is not transformed), result is stored in 'dest_positive' and 'dest_negative', 'weld_pos_eps'=epsilon used for final vertex position welding, 'flag_and'=elements to include in 'dest_*' creation (MESH_BASE_FLAG)
  64. void SplitMeshSolid(C Mesh &src, C Matrix *matrix, Mesh &dest_positive, Mesh &dest_negative, C Plane &clip_plane, C MaterialPtr &material, Flt tex_scale=1, UInt flag_and=~0, Flt weld_pos_eps=EPS); // generate 'src' mesh transformed by 'matrix' and then split by 'clip_plane' (if the 'matrix' is null then the mesh is not transformed), result is stored in 'dest_positive' and 'dest_negative', 'weld_pos_eps'=epsilon used for final vertex position welding, 'flag_and'=elements to include in 'dest_*' creation (MESH_BASE_FLAG), 'material'=material used to fill the "solid inside" created because of the splitting, 'tex_scale'=texture coordinates scale of the "solid inside" part
  65. /******************************************************************************/