source: trunk/src/easymesh/csgbsp.h @ 2350

Last change on this file since 2350 was 2226, checked in by touky, 7 years ago

Added CSG v0.001a : not optimized, too much operation makes it slow. triangle count is not optimized.
Useage : "...[.... csg*]" equals "current mesh -CSG- the mesh in the braces".
Keywords : CsgUnion<csgu>, CsgSubstract<csgs>, CsgAnd<csga>, CsgXor<csgx>
TODO : cleanup useless code.
TODO : Some bugs are still present, some face that disappear should not.
TODO : Correct epsilon useage (see geometry files).
TODO : Coplanar face are not handled -at all-.
TODO : Vertex count goes through the roof in case of a Xor.

File size: 2.3 KB
RevLine 
[2226]1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//            (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
6//   This program is free software; you can redistribute it and/or
7//   modify it under the terms of the Do What The Fuck You Want To
8//   Public License, Version 2, as published by Sam Hocevar. See
9//   http://www.wtfpl.net/ for more details.
10//
11
12//
13// The EasyMesh class
14// ------------------
15//
16
17#if !defined __CSGBSP_CSGBSP_H__
18#define __CSGBSP_CSGBSP_H__
19
20namespace lol
21{
22
23#define LEAF_ABOVE      2
24#define LEAF_FRONT      1
25#define LEAF_BACK       0
26#define LEAF_CURRENT   -1
27
28//Naïve bsp for the poor people
29class CsgBspLeaf
30{
31    friend class CsgBsp;
32
33public:
34    CsgBspLeaf(vec3 origin, vec3 normal, int above_idx)
35    {
36        m_origin = origin;
37        m_normal = normal;
38        m_leaves[LEAF_ABOVE] = above_idx;
39
40        m_leaves[LEAF_FRONT] = -1;
41        m_leaves[LEAF_BACK] = -1;
42    }
43
44private:
45    vec3            m_origin;
46    vec3            m_normal;
47    Array< int, vec3, vec3, vec3 >    m_tri_list;
48    ivec3           m_leaves;
49};
50
51//Naïve bsp for the poor people
52class CsgBsp
53{
54public:
55    void AddTriangleToTree(int const &tri_idx, vec3 const &tri_v0, vec3 const &tri_v1, vec3 const &tri_v2);
56
57    //return 0 when no split has been done.
58    //return 1 when split has been done.
59    //return -1 when error.
60    int TestTriangleToTree(vec3 const &tri_v0, vec3 const &tri_v1, vec3 const &tri_v2,
61                            //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha.
62                            //<Point_Loc, Src_V0, Src_V1, Alpha> as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; }
63                            Array< vec3, int, int, float > &vert_list,
64                            //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point.
65                            //<{IN|OUT}side_status, v0, v1, v2>
66                            Array< int, int, int, int > &tri_list);
67
68private:
69    int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx);
70    int TestPoint(int leaf_idx, vec3 point);
71
72    Array<CsgBspLeaf> m_tree;
73};
74
75} /* namespace lol */
76
77#endif /* __CSGBSP_CSGBSP_H__ */
78
Note: See TracBrowser for help on using the repository browser.