Example #1
0
        /// <summary>
        /// In order to build a BspTree, you have to supply the
        /// BspTreeBuilder with index an position arrays that are copies of
        /// the originals, so that they can be modified during the build
        /// process. The supplied epsilon parameter specifies the absolute
        /// tolerance value for coplanar triangles.
        /// </summary>
        public BspTreeBuilder(int[] triangleVertexIndexArray,
                              V3d[] vertexPositionArray,
                              double absoluteEpsilon,
                              int[] triangleAttributeIndexArray)
            : base(null, triangleVertexIndexArray, triangleAttributeIndexArray)
        {
            m_weightsArray  = new WeightedIndex[0][];
            m_positionArray = vertexPositionArray;

            TriangleCountMul3 = m_triangleVertexIndexArray.Length;
            int triangleCount = TriangleCountMul3 / 3;

            VertexCount = m_positionArray.Length;

            m_absoluteEpsilon     = absoluteEpsilon;
            m_originalVertexCount = VertexCount;

            // simple shuffle-algorithm (imagine the array as a square
            // from left->right, top->bottom)
            // address the array now top->bottom, left->right
            int stride = (int)Fun.Ceiling(Fun.Sqrt(triangleCount + 1.0));

            for (int offset = 0; offset < stride; offset++)
            {
                for (int ti = offset; ti < triangleCount; ti += stride)
                {
                    BspNode.AddTriangle(this, ti * 3, ref m_tree);
                }
            }

            TriangleCountMul3 = m_tree.TriangleCount() * 3;
        }
Example #2
0
 internal BspTree(BspNode tree,
                  int[] triangleVertexIndexArray,
                  int[] triangleAttributeIndexArray)
 {
     m_tree = tree;
     m_triangleVertexIndexArray    = triangleVertexIndexArray;
     m_triangleAttributeIndexArray = triangleAttributeIndexArray;
 }
Example #3
0
 internal static void AddTriangle(
     BspTreeBuilder builder, int tiMul3, ref Triangle3d tr, V3d triangleNormal,
     ref BspNode node)
 {
     if (node != null)
     {
         node.AddTriangle(builder, tiMul3, ref tr, triangleNormal);
     }
     else
     {
         node = new BspNode(tiMul3, tr.P0, triangleNormal);
     }
 }
Example #4
0
 internal BspNode(int tiMul3, V3d point, V3d normal)
 {
     m_point    = point;
     m_normal   = normal;
     m_zeroList = new List <int>(1)
     {
         tiMul3
     };
     m_negativeCount = 0;
     m_positiveCount = 0;
     m_positiveTree  = null;
     m_negativeTree  = null;
 }
Example #5
0
        internal static void AddTriangle(
            BspTreeBuilder builder, int tiMul3, ref BspNode node)
        {
            Triangle3d tr;

            builder.GetTriangleVertexPositions(tiMul3, out tr.P0, out tr.P1, out tr.P2);

            V3d    e0   = tr.P1 - tr.P0;
            V3d    e1   = tr.P2 - tr.P0;
            V3d    n    = V3d.Cross(e0, e1);
            double len2 = n.LengthSquared;

            if (len2 > 0.0)
            {
                AddTriangle(builder, tiMul3, ref tr,
                            n * (1.0 / Math.Sqrt(len2)),
                            ref node);
            }
        }