Beispiel #1
0
    public PatchTree(Vector3 Up, Vector3 Front, PatchSphere Sphere)
    {
        this.Sphere = Sphere;

        this.Up    = UpProjected = Up;
        this.Front = FrontProjected = Front;
        this.Right = -Vector3.Cross(this.Up, this.Front);

        Parent     = null;
        SplitLevel = 0;
        Size       = this.Sphere.Radius * 2;

        Neighbors[0].Node    = Neighbors[1].Node = Neighbors[2].Node = Neighbors[3].Node = null;
        Neighbors[0].isFixed = Neighbors[1].isFixed = Neighbors[2].isFixed = Neighbors[3].isFixed = false;
        Children[0]          = Children[1] = Children[2] = Children[3] = null;

        NeedsRejoinCount = 0;
        HasChildren      = false;
        NeedsReedge      = true;
        NeedsTerrain     = true;
        GapFixMask       = 15;

        GenerateVolume();

        Plane = new Plane(Volume.Vertices[0], Volume.Vertices[2], Volume.Vertices[1]);
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        PatchSphere myTarget = (PatchSphere)target;

        myTarget.Cells = EditorGUILayout.IntField("Cells", myTarget.Cells);
        //EditorGUILayout.LabelField( "Cells", myTarget.Level.ToString() );
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        PatchSphere p = (PatchSphere)target;

        DrawDefaultInspector();

        if (GUI.changed)
        {
            p.Rebuild();
        }
    }
Beispiel #4
0
    private void OnSceneGUI()
    {
        PatchSphere p = (PatchSphere)target;

        p.CallUpdate();
    }
Beispiel #5
0
    public PatchTree(PatchTree Parent, PatchAABB Volume)
    {
        this.Parent = Parent;
        this.Volume = Volume;
        this.Sphere = Parent.Sphere;

        SplitLevel = (ushort)(this.Parent.SplitLevel + 1);

        if (SplitLevel > Sphere.HighestSplitLevel)
        {
            Sphere.HighestSplitLevel = SplitLevel;
        }

        Size = this.Parent.Size / 2;

        var v1 = this.Volume.Vertices[0];
        var v2 = this.Volume.Vertices[1];
        var v3 = this.Volume.Vertices[2];
        var v4 = this.Volume.Vertices[3];

        var uv1 = this.Volume.UVs[0];
        var uv2 = this.Volume.UVs[1];
        var uv3 = this.Volume.UVs[2];
        var uv4 = this.Volume.UVs[3];

        VolumeProjected = new PatchAABB();

        VolumeProjected.Vertices.Add(v1.NormalizeToRadius(Sphere.Radius));
        VolumeProjected.Vertices.Add(v2.NormalizeToRadius(Sphere.Radius));
        VolumeProjected.Vertices.Add(v3.NormalizeToRadius(Sphere.Radius));
        VolumeProjected.Vertices.Add(v4.NormalizeToRadius(Sphere.Radius));

        VolumeProjected.UVs.Add(uv1);
        VolumeProjected.UVs.Add(uv2);
        VolumeProjected.UVs.Add(uv3);
        VolumeProjected.UVs.Add(uv4);

        Neighbors[0].Node    = Neighbors[1].Node = Neighbors[2].Node = Neighbors[3].Node = null;
        Neighbors[0].isFixed = Neighbors[1].isFixed = Neighbors[2].isFixed = Neighbors[3].isFixed = false;
        Children[0]          = Children[1] = Children[2] = Children[3] = null;

        NeedsRejoinCount = 0;
        HasChildren      = false;
        NeedsReedge      = true;
        NeedsTerrain     = true;
        GapFixMask       = 15;

        Normal = this.Parent.Normal;

        Middle          = (Volume.Vertices[0] + Volume.Vertices[1] + Volume.Vertices[2] + Volume.Vertices[3]) / 4;
        MiddleProjected = Middle;
        MiddleProjected = MiddleProjected.NormalizeToRadius(Sphere.Radius);

        UpProjected = MiddleProjected;
        UpProjected.Normalize();

        FrontProjected = Vector3.Lerp(VolumeProjected.Vertices[0], VolumeProjected.Vertices[1], 0.5f) - MiddleProjected;
        FrontProjected.Normalize();

        Plane = this.Parent.Plane;

        Front = this.Parent.Front;
        Up    = this.Parent.Up;
        Right = this.Parent.Right;
    }