Esempio n. 1
0
 private void AddAllTrianglesInChildren(OctMeshTreeSearch search,
                                        ref TreeNode node,
                                        Vector3 center,
                                        Vector3 extents)
 {
     if (node.m_triangles != null && 0 < node.m_triangles.Length)
     {
         search.AddTriangles(node.m_triangles, center, extents);
     }
     else if (0 <= node.m_childIndex)
     {
         var childIndex    = node.childIndex;
         var collapseFlags = node.collapseFlags;
         for (var i = 0; i < 8; ++i)
         {
             if ((collapseFlags & i) == 0)
             {
                 AddAllTrianglesInChildren(search, ref m_treeNodes[childIndex++], center, extents);
             }
         }
     }
 }
Esempio n. 2
0
        private void Search(OctMeshTreeSearch search, ref TreeNode node, Vector3 center, Vector3 extents)
        {
            var noTriangles = (node.m_triangles == null || node.m_triangles.Length == 0);

            if (node.childIndex < 0 && noTriangles)
            {
                return;
            }
            bool isPartial;
            var  flags = search.IsInView(center, extents, out isPartial);

            if (flags == 0)
            {
                return;
            }
            if (isPartial && 0 <= node.m_childIndex)
            {
                var childIndex    = node.childIndex;
                var collapseFlags = node.collapseFlags;
                var halfExtents   = extents;
                if (collapseFlags != 0)
                {
                    if ((collapseFlags & 0x1) != 0)
                    {
                        flags = (flags | (flags >> 1)) & OctMeshTreeSearch.FLAGS_LEFT;
                    }
                    else
                    {
                        halfExtents.x *= 0.5f;
                    }
                    if ((collapseFlags & 0x2) != 0)
                    {
                        flags = (flags | (flags >> 2)) & OctMeshTreeSearch.FLAGS_BOTTOM;
                    }
                    else
                    {
                        halfExtents.y *= 0.5f;
                    }
                    if ((collapseFlags & 0x4) != 0)
                    {
                        flags = (flags | (flags >> 4)) & OctMeshTreeSearch.FLAGS_FRONT;
                    }
                    else
                    {
                        halfExtents.z *= 0.5f;
                    }
                }
                else
                {
                    halfExtents *= 0.5f;
                }
                center = center - extents + halfExtents;
                for (var i = 0; i < 8 && flags != 0; ++i, flags >>= 1)
                {
                    if ((collapseFlags & i) == 0)
                    {
                        if ((flags & 1) != 0)
                        {
                            var p = center;
                            if ((i & 1) != 0)
                            {
                                p.x += extents.x;
                            }
                            if ((i & 2) != 0)
                            {
                                p.y += extents.y;
                            }
                            if ((i & 4) != 0)
                            {
                                p.z += extents.z;
                            }
                            if (0 <= m_treeNodes[childIndex].m_childIndex)
                            {
                                Search(search, ref m_treeNodes[childIndex], p, halfExtents);
                            }
                            else if (m_treeNodes[childIndex].m_triangles != null)
                            {
                                search.AddTriangles(m_treeNodes[childIndex].m_triangles, p, halfExtents);
                            }
                        }
                        ++childIndex;
                    }
                }
            }
            else
            {
                if (noTriangles)
                {
                    var childIndex    = node.childIndex;
                    var collapseFlags = node.collapseFlags;
                    for (var i = 0; i < 8; ++i)
                    {
                        if ((collapseFlags & i) == 0)
                        {
                            AddAllTrianglesInChildren(search, ref m_treeNodes[childIndex++], center, extents);
                        }
                    }
                }
                else
                {
                    search.AddTriangles(node.m_triangles, center, extents);
                }
            }
        }