Ejemplo n.º 1
0
        void DoPaintSymmetryPaint()
        {
            if (Invert)
            {
                float Tolerance = SymmetryWindow.GetTolerance();

                BrushGenerator.Current.GenerateSymmetry(BrushPos, 0, Scatter.value, size);

                float SearchSize = Mathf.Clamp(size, MinimumRenderBrushSize, MaximumBrushSize);

                PropGameObject ClosestInstance = SearchClosestProp(BrushGenerator.Current.PaintPositions[0], SearchSize);

                if (ClosestInstance == null)
                {
                    return;                     // No props found
                }
                BrushPos = ClosestInstance.transform.position;
                BrushGenerator.Current.GenerateSymmetry(BrushPos, 0, 0, 0);

                for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++)
                {
                    if (i == 0)
                    {
                        RegisterUndo();

                        TotalMassCount   -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimMassMax;
                        TotalEnergyCount -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimEnergyMax;
                        TotalReclaimTime -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimTime;

                        ClosestInstance.Connected.Group.PropsInstances.Remove(ClosestInstance.Connected);
                        Destroy(ClosestInstance.gameObject);
                    }
                    else
                    {
                        PropGameObject TestObj = SearchClosestProp(BrushGenerator.Current.PaintPositions[i], Tolerance);
                        if (TestObj != null)
                        {
                            TotalMassCount   -= TestObj.Connected.Group.PropObject.BP.ReclaimMassMax;
                            TotalEnergyCount -= TestObj.Connected.Group.PropObject.BP.ReclaimEnergyMax;
                            TotalReclaimTime -= TestObj.Connected.Group.PropObject.BP.ReclaimTime;

                            TestObj.Connected.Group.PropsInstances.Remove(TestObj.Connected);
                            Destroy(TestObj.gameObject);
                        }
                    }
                }
            }
            else
            {
                RandomProp = GetRandomProp();

                BrushGenerator.Current.GenerateSymmetry(BrushPos, size, Scatter.value, size);

                float RotMin = PaintButtons[RandomProp].RotationMin.intValue;
                float RotMax = PaintButtons[RandomProp].RotationMax.intValue;

                BrushGenerator.Current.GenerateRotationSymmetry(Quaternion.Euler(Vector3.up * Random.Range(RotMin, RotMax)));



                // Search group id
                RandomPropGroup = -1;
                for (int i = 0; i < AllPropsTypes.Count; i++)
                {
                    if (AllPropsTypes[i].LoadBlueprint == PaintPropObjects[RandomProp].BP.Path)
                    {
                        RandomPropGroup = i;
                        break;
                    }
                }
                if (RandomPropGroup < 0)                 // Create new group
                {
                    PropTypeGroup NewGroup = new PropTypeGroup(PaintPropObjects[RandomProp]);
                    RandomPropGroup = AllPropsTypes.Count;
                    AllPropsTypes.Add(NewGroup);
                }

                //float BrushSlope = ScmapEditor.Current.Teren.
                int Min = BrushMini.intValue;
                int Max = BrushMax.intValue;

                if (Min > 0 || Max < 90)
                {
                    Vector3 LocalPos = ScmapEditor.Current.Teren.transform.InverseTransformPoint(BrushGenerator.Current.PaintPositions[0]);
                    LocalPos.x /= ScmapEditor.Current.Teren.terrainData.size.x;
                    LocalPos.z /= ScmapEditor.Current.Teren.terrainData.size.z;

                    float angle = Vector3.Angle(Vector3.up, ScmapEditor.Current.Teren.terrainData.GetInterpolatedNormal(LocalPos.x, LocalPos.z));
                    if ((angle < Min && Min > 0) || (angle > Max && Max < 90))
                    {
                        return;
                    }
                }

                if (!AllowWaterLevel.isOn && ScmapEditor.Current.map.Water.HasWater)
                {
                    if (ScmapEditor.Current.Teren.SampleHeight(BrushGenerator.Current.PaintPositions[0]) <= ScmapEditor.Current.WaterLevel.position.y)
                    {
                        return;
                    }
                }

                for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++)
                {
                    Paint(BrushGenerator.Current.PaintPositions[i], BrushGenerator.Current.PaintRotations[i]);
                }
            }
        }
        void GenerateSymmetry()
        {
            LastSym = SymmetryWindow.GetSymmetryType();
            //if (LastSym > 8)
            //	LastSym = 8;

            LastTolerance = SymmetryWindow.GetTolerance();


            switch (LastSym)
            {
            case 1:                     // X
                SymetrySelection    = new SelectedObjects[1];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);
                break;

            case 2:                     // Z
                SymetrySelection    = new SelectedObjects[1];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);
                break;

            case 3:                     // XZ
                SymetrySelection    = new SelectedObjects[1];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, -1));
                SymetrySelection[0].InverseRotation = false;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);
                break;

            case 4:                     // X Z XZ
                SymetrySelection    = new SelectedObjects[3];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);

                SymetrySelection[1] = new SelectedObjects();
                SymetrySelection[1].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1));
                SymetrySelection[1].InverseRotation = true;
                SymetrySelection[1].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[1]);

                SymetrySelection[2] = new SelectedObjects();
                SymetrySelection[2].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, -1));
                SymetrySelection[2].InverseRotation = false;
                SymetrySelection[2].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[2]);
                break;

            case 5:                    // Diagonal1
                SymetrySelection    = new SelectedObjects[1];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * 90), new Vector3(-1, 1, 1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);
                break;

            case 6:                     // Diagonal 2
                SymetrySelection    = new SelectedObjects[1];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.down * 90), new Vector3(-1, 1, 1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);
                break;

            case 7:                     // Diagonal 3
                SymetrySelection    = new SelectedObjects[3];
                SymetrySelection[0] = new SelectedObjects();
                SymetrySelection[0].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * 90), new Vector3(-1, 1, 1));
                SymetrySelection[0].InverseRotation = true;
                SymetrySelection[0].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[0]);

                SymetrySelection[1] = new SelectedObjects();
                SymetrySelection[1].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.down * 90), new Vector3(-1, 1, 1));
                SymetrySelection[1].InverseRotation = true;
                SymetrySelection[1].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[1]);

                SymetrySelection[2] = new SelectedObjects();
                SymetrySelection[2].SymmetryMatrix = SymetrySelection[0].SymmetryMatrix * SymetrySelection[1].SymmetryMatrix;
                //SymetrySelection[2].SymmetryMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.down * 180), new Vector3(-1, 1, -1));
                SymetrySelection[2].InverseRotation = false;
                SymetrySelection[2].LoadSymetryIds();
                GenerateSymmetrySelectionRing(SymetrySelection[2]);

                break;

            case 8:                     // Rotation
                int   RotCount = SymmetryWindow.GetRotationSym() - 1;
                float angle    = 360.0f / (float)(RotCount + 1);
                SymetrySelection = new SelectedObjects[RotCount];

                for (int i = 0; i < RotCount; i++)
                {
                    SymetrySelection[i] = new SelectedObjects();
                    SymetrySelection[i].SymmetryMatrix  = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * (angle * (i + 1))), Vector3.one);
                    SymetrySelection[i].InverseRotation = false;
                    SymetrySelection[i].LoadSymetryIds();
                    GenerateSymmetrySelectionRing(SymetrySelection[i]);
                }
                break;

            default:
                SymetrySelection = new SelectedObjects[0];
                break;
            }
        }