コード例 #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;
        }
コード例 #2
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);
     }
 }