Example #1
0
    void GizmosDrawABrushOfLeaf(int brushIndex)
    {
        Color tc = Gizmos.color;

        // Draw Brush
        Gizmos.color = Color.white;
        BSPFileParser.Brush bsh = _brushes[brushIndex];
        for (int k = bsh.brushside; k < bsh.brushside + bsh.n_brushsides; k++)
        {
            BSPFileParser.Brushside bsd   = _brushsides[k];
            UnityEngine.Plane       plane = planes[bsd.plane];
            GizmosDrawPlane(GetOnePointOnPlane(plane), plane.normal, 5000.0f);
        }
        // Draw Leaf which hold the brushIndex
        Gizmos.color = Color.red;
        for (int i = 0; i < _leafs.Length; i++)
        {
            BSPFileParser.BSPTreeLeaf lf = _leafs[i];
            for (int j = lf.leafbrush; j < lf.leafbrush + lf.n_leafbrushes; j++)
            {
                if (_leafbrushes[j] == brushIndex)
                {
                    Bounds temp = new Bounds();
                    temp.SetMinMax(new Vector3(lf.mins[0], lf.mins[1], lf.mins[2]),
                                   new Vector3(lf.maxs[0], lf.maxs[1], lf.maxs[2]));
                    temp = Right2Left(temp);
                    Gizmos.DrawWireCube(temp.center, temp.size);
                }
            }
        }
        Gizmos.color = tc;
    }
Example #2
0
    void LoadCollider(GameObject gmObject)
    {
        for (int i = 0; i < _leafs.Length; i++)
        {
            for (int j = _leafs[i].leafbrush; j < _leafs[i].leafbrush + _leafs[i].n_leafbrushes; j++)
            {
                int brushIndex          = _leafbrushes[j];
                BSPFileParser.Brush bsh = _brushes[brushIndex];

                if (bsh.n_brushsides == 6)
                {
                    // Generate Box Collider directly by the 6 bounding planes
                    UnityEngine.Plane[] ps = new UnityEngine.Plane[bsh.n_brushsides];
                    for (int k = bsh.brushside; k < bsh.brushside + bsh.n_brushsides; k++)
                    {
                        UnityEngine.Plane plane = planes[_brushsides[k].plane];
                        ps[k - bsh.brushside] = new UnityEngine.Plane(plane.normal, plane.distance);
                    }
                    Bounds b = GenerateBoxFromPlanes(ps);

                    GameObject obj = new GameObject();
                    obj.name = "BoxCollider";
                    obj.AddComponent <BoxCollider>();
                    obj.GetComponent <BoxCollider>().center = b.center;
                    obj.GetComponent <BoxCollider>().size   = b.size;
                    obj.transform.SetParent(gmObject.transform);
                }
                else
                {
                    // Generate Box Collider by leaf bounding box which brush in it
                    for (int m = 0; m < _leafs.Length; m++)
                    {
                        BSPFileParser.BSPTreeLeaf lf = _leafs[m];
                        for (int n = lf.leafbrush; n < lf.leafbrush + lf.n_leafbrushes; n++)
                        {
                            if (_leafbrushes[n] == brushIndex)
                            {
                                Bounds b = new Bounds();
                                b.SetMinMax(new Vector3(lf.mins[0], lf.mins[1], lf.mins[2]),
                                            new Vector3(lf.maxs[0], lf.maxs[1], lf.maxs[2]));
                                b = Right2Left(b);
                                GameObject obj = new GameObject();
                                obj.name = "BoxCollider";
                                obj.AddComponent <BoxCollider>();
                                obj.GetComponent <BoxCollider>().center = b.center;
                                obj.GetComponent <BoxCollider>().size   = b.size;
                                obj.transform.SetParent(gmObject.transform);
                            }
                        }
                    }
                }
            }
        }
    }
Example #3
0
    void GizmosDrawLeafBrushes(int whichLeaf)
    {
        Color tc = Gizmos.color;

        Color[] cs         = new Color[] { Color.gray, Color.yellow, Color.magenta, Color.red }; // from light to dark
        int     colorIndex = 0;

        if (whichLeaf >= 0)
        {
            BSPFileParser.BSPTreeLeaf lf = _leafs[whichLeaf];
            for (int j = lf.leafbrush; j < lf.leafbrush + lf.n_leafbrushes; j++)
            {
                int brushIndex          = _leafbrushes[j];
                BSPFileParser.Brush bsh = _brushes[brushIndex];
                Gizmos.color = cs[colorIndex++ % cs.Length];

                for (int k = bsh.brushside; k < bsh.brushside + bsh.n_brushsides; k++)
                {
                    BSPFileParser.Brushside bsd   = _brushsides[k];
                    UnityEngine.Plane       plane = planes[bsd.plane];
                    GizmosDrawPlane(GetOnePointOnPlane(plane), plane.normal, 5000.0f);
                }
            }
            Gizmos.color = tc;
            return;
        }
        // Draw All brushes for leaves
        int len = _leafs.Length;

        for (int i = 0; i < len; i++)
        {
            BSPFileParser.BSPTreeLeaf lf = _leafs[i];
            for (int j = lf.leafbrush; j < lf.leafbrush + lf.n_leafbrushes; j++)
            {
                int brushIndex          = _leafbrushes[j];
                BSPFileParser.Brush bsh = _brushes[brushIndex];
                Gizmos.color = cs[colorIndex++ % cs.Length];
                for (int k = bsh.brushside; k < bsh.brushside + bsh.n_brushsides; k++)
                {
                    BSPFileParser.Brushside bsd   = _brushsides[k];
                    UnityEngine.Plane       plane = planes[bsd.plane];
                    GizmosDrawPlane(GetOnePointOnPlane(plane), plane.normal, 5000.0f);
                }
            }
        }
        Gizmos.color = tc;
    }