public static void RegeneratePaintBrushIfNeeded(bool BrushChanged = false) { if (BrushChanged || SymmetryWindow.GetSymmetryType() != Current.LastSym || (Current.LastSym == 8 && Current.LastRot != SymmetryWindow.GetRotationSym())) { Current.GeneratePaintBrushesh(); } }
void Update() { if (!PlacementObject) { enabled = false; return; } if (!SelectionManager.Current.IsPointerOnGameplay()) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, RaycastMask)) { if (LastSym != SymmetryWindow.GetSymmetryType()) { GenerateSymmetry(); } if (!PlacementObject.activeSelf) { PlacementObject.SetActive(true); for (int i = 0; i < PlacementSymmetry.Length; i++) { PlacementSymmetry[i].SetActive(true); } } // Rotate bool Rotating = false; if (SelectionManager.AllowRotation) { if (Input.GetKeyDown(KeyCode.E)) { /*if (MinRotAngle > 1) * { * PlaceAngle += MinRotAngle; * if (PlaceAngle >= 360) * PlaceAngle = 0; * PlacementObject.transform.rotation = Quaternion.Euler(Vector3.up * PlaceAngle); * } * else*/ { RotationStartMousePos = Input.mousePosition; StartRotation = PlacementObject.transform.eulerAngles; } } else if (Input.GetKeyUp(KeyCode.E)) { ChangeControlerType.ChangeCurrentControler(0); } else if (Input.GetKey(KeyCode.E)) { Rotating = true; Vector3 NewRot = StartRotation + Vector3.down * ((Input.mousePosition.x - RotationStartMousePos.x) * 0.5f); if (MinRotAngle > 1) { int ClampedRot = (int)(NewRot.y / MinRotAngle); NewRot.y = MinRotAngle * ClampedRot; } PlacementObject.transform.eulerAngles = NewRot; } } //Scale bool Scaling = false; if (!Rotating && SelectionManager.AllowScale) { if (Input.GetKeyDown(KeyCode.R)) { RotationStartMousePos = Input.mousePosition; StartScale = PlacementObject.transform.localScale; LastHitPoint = hit.point; } else if (Input.GetKeyUp(KeyCode.R)) { ChangeControlerType.ChangeCurrentControler(0); } else if (Input.GetKey(KeyCode.R)) { Scaling = true; Vector3 Scale = StartScale; float ScalingScale = (Scale.x + Scale.y + Scale.z) / 3f; float ScalePower = (Input.mousePosition.x - RotationStartMousePos.x) * 0.003f * ScalingScale; Scale.x = Mathf.Clamp(Scale.x + ScalePower, 0.005f, 100); Scale.y = Mathf.Clamp(Scale.y + ScalePower, 0.005f, 100); Scale.z = Mathf.Clamp(Scale.z + ScalePower, 0.005f, 100); PlacementObject.transform.localScale = Scale; } } if (!Rotating) { Vector3 Point = hit.point; if (Scaling) { Point = LastHitPoint; } if (SelectionManager.Current.SnapToGrid) { PlacementObject.transform.position = ScmapEditor.SnapToGridCenter(Point, true, SnapToWater); } else if (SnapToWater) { PlacementObject.transform.position = ScmapEditor.ClampToWater(Point); } else { PlacementObject.transform.position = Point; } } UpdateSymmetryObjects(); // Action if (Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.B) || Input.GetKey(KeyCode.M)) { } else if (Input.GetMouseButtonDown(0)) { Place(); } } else if (PlacementObject.activeSelf) { PlacementObject.SetActive(false); for (int i = 0; i < PlacementSymmetry.Length; i++) { PlacementSymmetry[i].SetActive(false); } } }
public void GenerateSymmetry() { LastSym = SymmetryWindow.GetSymmetryType(); //LastTolerance = SymmetryWindow.GetTolerance(); for (int i = 0; i < PlacementSymmetry.Length; i++) { Destroy(PlacementSymmetry[i]); } switch (LastSym) { case 1: // X SymmetryMatrix = new Matrix4x4[1]; InvertRotation = new bool[1]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1)); InvertRotation[0] = true; break; case 2: // Z SymmetryMatrix = new Matrix4x4[1]; InvertRotation = new bool[1]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1)); InvertRotation[0] = true; break; case 3: // XZ SymmetryMatrix = new Matrix4x4[1]; InvertRotation = new bool[1]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, -1)); InvertRotation[0] = false; break; case 4: // X Z XZ SymmetryMatrix = new Matrix4x4[3]; InvertRotation = new bool[3]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, 1)); InvertRotation[0] = true; SymmetryMatrix[1] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1)); InvertRotation[1] = true; SymmetryMatrix[2] = SymmetryMatrix[0] * SymmetryMatrix[1]; InvertRotation[2] = false; //SymmetryMatrix[2] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1, 1, -1)); break; case 5: // Diagonal1 SymmetryMatrix = new Matrix4x4[1]; InvertRotation = new bool[1]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * 90), new Vector3(-1, 1, 1)); InvertRotation[0] = true; break; case 6: // Diagonal 2 SymmetryMatrix = new Matrix4x4[1]; InvertRotation = new bool[1]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.down * 90), new Vector3(-1, 1, 1)); InvertRotation[0] = true; break; case 7: // Diagonal 3 SymmetryMatrix = new Matrix4x4[3]; InvertRotation = new bool[3]; SymmetryMatrix[0] = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * 90), new Vector3(-1, 1, 1)); InvertRotation[0] = true; SymmetryMatrix[1] = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.down * 90), new Vector3(-1, 1, 1)); InvertRotation[1] = true; SymmetryMatrix[2] = SymmetryMatrix[0] * SymmetryMatrix[1]; InvertRotation[2] = false; break; case 8: // Rotation int RotCount = SymmetryWindow.GetRotationSym() - 1; float angle = 360.0f / (float)(RotCount + 1); SymmetryMatrix = new Matrix4x4[RotCount]; InvertRotation = new bool[RotCount]; for (int i = 0; i < RotCount; i++) { SymmetryMatrix[i] = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(Vector3.up * (angle * (i + 1))), Vector3.one); InvertRotation[i] = false; } break; default: SymmetryMatrix = new Matrix4x4[0]; break; } PlacementSymmetry = new GameObject[SymmetryMatrix.Length]; for (int i = 0; i < PlacementSymmetry.Length; i++) { PlacementSymmetry[i] = Instantiate(PlacementObject) as GameObject; if (InstantiateAction != null) { InstantiateAction(PlacementSymmetry[i]); } } }
public void UpdateSymmetryType() { int SymmetryCode = SymmetryWindow.GetSymmetryType(); LastSym = SymmetryCode; }
// Generate brush textures for all symmetry - need to be done only once, when changing symmetry // It mirrors and rotate brush texture // Generating textures is slow and make lag when generating // Need to find something to speed it up void GeneratePaintBrushesh() { int SymmetryCode = SymmetryWindow.GetSymmetryType(); LastSym = SymmetryCode; switch (SymmetryCode) { case 1: PaintImage = new Texture2D[2]; PaintImage[0] = RotatedBrush; PaintImage[1] = MirrorTexture(RotatedBrush, true, false); break; case 2: PaintImage = new Texture2D[2]; PaintImage[0] = RotatedBrush; PaintImage[1] = MirrorTexture(RotatedBrush, false, true); break; case 3: PaintImage = new Texture2D[2]; PaintImage[0] = RotatedBrush; PaintImage[1] = MirrorTexture(RotatedBrush, true, true); break; case 4: PaintImage = new Texture2D[4]; PaintImage[0] = RotatedBrush; PaintImage[1] = MirrorTexture(RotatedBrush, true, false); PaintImage[2] = MirrorTexture(RotatedBrush, false, true); PaintImage[3] = MirrorTexture(RotatedBrush, true, true); break; case 5: PaintImage = new Texture2D[2]; PaintImage[0] = RotatedBrush; PaintImage[1] = rotateTexture(RotatedBrush, 90); PaintImage[1] = MirrorTexture(PaintImage[1], true, false); break; case 6: PaintImage = new Texture2D[2]; PaintImage[0] = RotatedBrush; PaintImage[1] = rotateTexture(RotatedBrush, 90); PaintImage[1] = MirrorTexture(PaintImage[1], false, true); break; case 7: PaintImage = new Texture2D[4]; PaintImage[0] = RotatedBrush; PaintImage[1] = rotateTexture(RotatedBrush, 90); PaintImage[1] = MirrorTexture(PaintImage[1], true, false); PaintImage[2] = rotateTexture(RotatedBrush, 90); PaintImage[2] = MirrorTexture(PaintImage[2], false, true); PaintImage[3] = MirrorTexture(RotatedBrush, true, true); break; case 8: LastRot = SymmetryWindow.GetRotationSym(); PaintImage = new Texture2D[LastRot]; PaintImage[0] = RotatedBrush; float angle = 360.0f / (float)LastRot; for (int i = 1; i < LastRot; i++) { PaintImage[i] = rotateTexture(RotatedBrush, -angle * i); } break; default: PaintImage = new Texture2D[1]; PaintImage[0] = RotatedBrush; break; } PaintImageWidths = new int[PaintImage.Length]; PaintImageHeights = new int[PaintImage.Length]; Pixels = new Color[PaintImage.Length][]; Values = new float[PaintImage.Length][]; for (int i = 0; i < PaintImage.Length; i++) { Pixels[i] = PaintImage[i].GetPixels(); Values[i] = new float[Pixels[i].Length]; for (int v = 0; v < Values[i].Length; v++) { Values[i][v] = Pixels[i][v].r; } PaintImageWidths[i] = PaintImage[i].width; PaintImageHeights[i] = PaintImage[i].height; } }
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; } }