123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #ifndef TRIANGLE_MESH_H
- #define TRIANGLE_MESH_H
- #include "face3.h"
- #include "reference.h"
- class TriangleMesh : public Reference {
- GDCLASS(TriangleMesh, Reference);
- struct Triangle {
- Vector3 normal;
- int indices[3];
- };
- PoolVector<Triangle> triangles;
- PoolVector<Vector3> vertices;
- struct BVH {
- AABB aabb;
- Vector3 center;
- int left;
- int right;
- int face_index;
- };
- struct BVHCmpX {
- bool operator()(const BVH *p_left, const BVH *p_right) const {
- return p_left->center.x < p_right->center.x;
- }
- };
- struct BVHCmpY {
- bool operator()(const BVH *p_left, const BVH *p_right) const {
- return p_left->center.y < p_right->center.y;
- }
- };
- struct BVHCmpZ {
- bool operator()(const BVH *p_left, const BVH *p_right) const {
- return p_left->center.z < p_right->center.z;
- }
- };
- int _create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc);
- PoolVector<BVH> bvh;
- int max_depth;
- bool valid;
- public:
- bool is_valid() const;
- bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const;
- bool intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal) const;
- Vector3 get_area_normal(const AABB &p_aabb) const;
- PoolVector<Face3> get_faces() const;
- void create(const PoolVector<Vector3> &p_faces);
- TriangleMesh();
- };
- #endif
|