public CoordDir Max(CoordDir pos, Voxeland.EditMode mode = Voxeland.EditMode.none) //note taht Max is never reached { switch (form) { //case Form.single: if (mode==Voxeland.EditMode.add) pos = pos.opposite; break; //shifting pos to opposite if single add mode case Form.blob: pos.x += extent + 1; pos.y += extent + 1; pos.z += extent + 1; break; //getting 1-block boundary on opposite case Form.volume: pos.x += extent; pos.y += extent; pos.z += extent; break; case Form.stamp: if (stamp == null) { return(pos + 1); } if (getStamp) { pos += getStampMax; } else { pos += stamp.cube.offset + stamp.cube.size; } break; } pos.x++; pos.y++; pos.z++; return(pos); }
public void Process(CoordDir[] poses, Matrix3 <byte> matrix, Voxeland.EditMode mode, byte type) { for (int i = 0; i < poses.Length; i++) { Process(poses[i], matrix, mode, type); } }
//public enum EditMode {none, standard, dig, add, replace, smooth}; //standard mode is similar to add one, except the preliminary switch to opposite in add public CoordDir Min(CoordDir pos, Voxeland.EditMode mode = Voxeland.EditMode.none) { switch (form) { //case Form.single: if (mode==Voxeland.EditMode.add) pos = pos.opposite; break; //shifting pos to opposite if single add mode //in Alter case Form.blob: pos.x -= extent + 1; pos.y -= extent + 1; pos.z -= extent + 1; break; //getting 1-block boundary for opposites case Form.volume: pos.x -= extent; pos.y -= extent; pos.z -= extent; break; case Form.stamp: if (stamp == null) { return(pos); } if (getStamp) { pos += getStampMin; } else { pos += stamp.cube.offset; } break; } return(pos); }
public void OnSceneGUI () { //updating Inspector GUI if thread is working (it lags less if done from OnSceneGUI... somehow) if (ThreadWorker.IsWorking("Voxeland") || gaugeDisplayed) Repaint(); Voxeland voxeland = (Voxeland)target; if (voxeland.data == null) return; //disabling selection if (voxeland.guiLockSelection) { HandleUtility.AddDefaultControl( GUIUtility.GetControlID(FocusType.Passive) ); Tools.current = Tool.None; } //hiding wireframe //voxeland.transform.ToggleDisplayWireframe(!voxeland.guiHideWireframe); //switching highlight intensity mode if (voxeland.highlight != null && voxeland.highlight.material != null && voxeland.highlight.meshRenderer.sharedMaterial != null && voxeland.highlight.meshRenderer.sharedMaterial.HasProperty("_Linear")) voxeland.highlight.meshRenderer.sharedMaterial.SetInt("_Linear", PlayerSettings.colorSpace==ColorSpace.Linear? 1 : 0); //getting mouse button if (Event.current.type == EventType.MouseDown) mouseButton = Event.current.button; if (Event.current.rawType == EventType.MouseUp) mouseButton = -1; //getting mouse pos SceneView sceneview = UnityEditor.SceneView.lastActiveSceneView; if (sceneview==null || sceneview.camera==null) return; Vector2 mousePos = Event.current.mousePosition; mousePos = new Vector2(mousePos.x/sceneview.camera.pixelWidth, mousePos.y/sceneview.camera.pixelHeight); #if UNITY_5_4_OR_NEWER mousePos *= EditorGUIUtility.pixelsPerPoint; #endif mousePos.y = 1 - mousePos.y; //aiming Ray aimRay = sceneview.camera.ViewportPointToRay(mousePos); CoordDir aimCoord = voxeland.PointOut(aimRay); //focusing on brush if(Event.current.commandName == "FrameSelected") { Event.current.Use(); if (aimCoord.exists) UnityEditor.SceneView.lastActiveSceneView.LookAt( voxeland.transform.TransformPoint( aimCoord.vector3 ), UnityEditor.SceneView.lastActiveSceneView.rotation, Mathf.Max(voxeland.brush.extent*6, 20), UnityEditor.SceneView.lastActiveSceneView.orthographic, false); else { Coord rectCenter = voxeland.chunks.deployedRects[0].Center * voxeland.chunkSize; int rectExtend = voxeland.chunks.deployedRects[0].size.x * voxeland.chunkSize; int height; byte temp; voxeland.data.GetTopTypePoint(rectCenter.x, rectCenter.z, out height, out temp); UnityEditor.SceneView.lastActiveSceneView.LookAt( voxeland.transform.TransformPoint( new Vector3(rectCenter.x, height, rectCenter.z) ), UnityEditor.SceneView.lastActiveSceneView.rotation, rectExtend, UnityEditor.SceneView.lastActiveSceneView.orthographic, false); } } //if any change if (prevAimCoord != aimCoord || mouseButton==0) { //getting edit mode Voxeland.EditMode editMode = Voxeland.EditMode.none; bool buttonDown = false; if (!voxeland.continuousPainting) buttonDown = Event.current.type==EventType.MouseDown && Event.current.button==0; else buttonDown = mouseButton==0; if (buttonDown && !Event.current.alt) { if (Event.current.control && Event.current.shift) editMode = voxeland.controlShiftEditMode; else if (Event.current.shift) editMode = voxeland.shiftEditMode; else if (Event.current.control) editMode = voxeland.controlEditMode; else editMode = voxeland.standardEditMode; } //highlight if (voxeland.highlight!=null) // && Event.current.type!=EventType.KeyDown && Event.current.type!=EventType.mouseDrag) //do not redraw highlight on alt pressed { if (aimCoord.exists) voxeland.Highlight(aimCoord, voxeland.brush, isEditing:editMode!=Voxeland.EditMode.none); else voxeland.highlight.Clear(); //clearing highlight if nothing aimed or voxeland not selected } //altering if (editMode!=Voxeland.EditMode.none && aimCoord.exists) { voxeland.Alter(aimCoord, voxeland.brush, editMode, landType:voxeland.landTypes.selected, objectType:voxeland.objectsTypes.selected, grassType:voxeland.grassTypes.selected); } prevAimCoord = aimCoord; SceneView.lastActiveSceneView.Repaint(); } //if coord or button change }
public void Process(CoordDir pos, Matrix3 <byte> matrix, Voxeland.EditMode mode, Form formOverride, byte type) //overriding brush form to place objects and grass { //blurring matrix in case of blur mode Matrix3 <float> blurredExist = null; if (mode == Voxeland.EditMode.smooth) { blurredExist = new Matrix3 <float>(matrix.cube); for (int i = 0; i < blurredExist.array.Length; i++) { if (matrix.array[i] != Data.emptyByte) { blurredExist.array[i] = 1; } else { blurredExist.array[i] = 0; } } BlurExistMatrix(blurredExist); } //single brush if (formOverride == Form.single) { switch (mode) { case Voxeland.EditMode.add: case Voxeland.EditMode.replace: matrix[pos.x, pos.y, pos.z] = type; break; //already switched add to opposite, so add==replace case Voxeland.EditMode.dig: matrix[pos.x, pos.y, pos.z] = Data.emptyByte; break; } } //blob brush if (formOverride == Form.blob) { CoordDir[] neigCoords = ChunkMesh.NeighbourCoordinates(pos, matrix, extent, round: round); for (int i = 0; i < neigCoords.Length; i++) { int x = neigCoords[i].x; int y = neigCoords[i].y; int z = neigCoords[i].z; CoordDir neigOpposite = neigCoords[i].opposite; int ox = neigOpposite.x; int oy = neigOpposite.y; int oz = neigOpposite.z; switch (mode) { case Voxeland.EditMode.add: matrix[ox, oy, oz] = type; break; case Voxeland.EditMode.replace: matrix[x, y, z] = type; break; case Voxeland.EditMode.dig: matrix[x, y, z] = Data.emptyByte; break; case Voxeland.EditMode.smooth: if (blurredExist[ox, oy, oz] > 0.5f && matrix[ox, oy, oz] == Data.emptyByte) { matrix[ox, oy, oz] = ClosestExistingType(matrix, ox, oy, oz); //TODO: exist check } if (blurredExist[x, y, z] < 0.5f && matrix[x, y, z] != Data.emptyByte) { matrix[x, y, z] = Data.emptyByte; } break; } } } //volume brush else if (formOverride == Form.volume) { CoordDir min = matrix.cube.Min; CoordDir max = matrix.cube.Max; for (int x = min.x; x < max.x; x++) { for (int y = min.y; y < max.y; y++) { for (int z = min.z; z < max.z; z++) { //ignoring out-of-sphere if (round) { int dx = x - pos.x; int dy = y - pos.y; int dz = z - pos.z; if (dx * dx + dy * dy + dz * dz > (extent + 0.5f) * (extent + 0.5f)) { continue; } } //setting block int i = matrix.cube.GetPos(x, y, z); switch (mode) { case Voxeland.EditMode.add: matrix.array[i] = type; break; case Voxeland.EditMode.dig: matrix.array[i] = Data.emptyByte; break; case Voxeland.EditMode.replace: if (matrix.array[i] != Data.emptyByte) { matrix.array[i] = type; } break; //TODO: exists check case Voxeland.EditMode.smooth: if (blurredExist.array[i] > 0.5f && (matrix.array[i] == Data.emptyByte || matrix.array[i] >= Data.constructorByte)) { matrix.array[i] = ClosestExistingType(matrix, x, y, z); //if blured exists but matrix empty adding closest //TODO: exist check } if (blurredExist.array[i] < 0.5f && (matrix.array[i] != Data.emptyByte && matrix.array[i] < Data.constructorByte)) { matrix.array[i] = Data.emptyByte; //if blured empty but matrix exists } break; } } } } } else if (formOverride == Form.stamp) { if (getStamp) { stamp = new Matrix3 <bool>(getStampMin, matrix.cube.size); for (int x = 0; x < matrix.cube.size.x; x++) { for (int y = 0; y < matrix.cube.size.y; y++) { for (int z = 0; z < matrix.cube.size.z; z++) { if (matrix[x + matrix.cube.offset.x, y + matrix.cube.offset.y, z + matrix.cube.offset.z] != Data.emptyByte) { stamp[x + stamp.cube.offset.x, y + stamp.cube.offset.y, z + stamp.cube.offset.z] = true; //TODO: exists check } } } } } else if (stamp != null) { for (int x = 0; x < stamp.cube.size.x; x++) { for (int y = 0; y < stamp.cube.size.y; y++) { for (int z = 0; z < stamp.cube.size.z; z++) { CoordDir s = new CoordDir(x, y, z) + stamp.cube.offset; CoordDir m = new CoordDir(x, y, z) + matrix.cube.offset; switch (mode) { case Voxeland.EditMode.add: if (stamp[s]) { matrix[m] = type; } break; case Voxeland.EditMode.dig: if (stamp[s]) { matrix[m] = Data.emptyByte; } break; case Voxeland.EditMode.replace: if (matrix[m] != 0 && stamp[s]) { matrix[m] = type; } break; //TODO: exists check case Voxeland.EditMode.smooth: if (stamp[s]) { if (blurredExist[m] > 0.5f && (matrix[m] == Data.emptyByte || matrix[m] >= Data.constructorByte)) { matrix[m] = ClosestExistingType(matrix, x, y, z); //if blured exists but matrix empty adding closest //TODO: exist check } if (blurredExist[m] < 0.5f && (matrix[m] != Data.emptyByte && matrix[m] < Data.constructorByte)) { matrix[m] = Data.emptyByte; //if blured empty but matrix exists } } break; } } } } } } }
public void Process(CoordDir pos, Matrix3 <byte> matrix, Voxeland.EditMode mode, byte type) { Process(pos, matrix, mode, form, type); }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } //showing help panel if (Input.GetKeyDown(KeyCode.F1)) { helpPanel.SetActive(!helpPanel.activeSelf); } //selecting tool if (Input.GetKey("`")) { vertGrassInstrument.isOn = true; } if (Input.GetKey("1")) { brightCliffInstrument.isOn = true; } if (Input.GetKey("2")) { darkCliffInstrument.isOn = true; } if (Input.GetKey("3")) { grassInstrument.isOn = true; } if (Input.GetKey("4")) { yellowGrassInstrument.isOn = true; } if (Input.GetKey("5")) { pineInstrument.isOn = true; } if (Input.GetKey("6")) { torchInstrument.isOn = true; } if (vertGrassInstrument.isOn) { voxeland.grassTypes.selected = 0; voxeland.landTypes.selected = -1; voxeland.objectsTypes.selected = -1; } if (darkCliffInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = 0; voxeland.objectsTypes.selected = -1; } if (brightCliffInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = 1; voxeland.objectsTypes.selected = -1; } if (grassInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = 2; voxeland.objectsTypes.selected = -1; } if (yellowGrassInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = 3; voxeland.objectsTypes.selected = -1; } if (pineInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = -1; voxeland.objectsTypes.selected = 0; } if (torchInstrument.isOn) { voxeland.grassTypes.selected = -1; voxeland.landTypes.selected = -1; voxeland.objectsTypes.selected = 1; } if (voxeland.landTypes.selected == -1) { instrumentWarning.SetActive(true); } else { instrumentWarning.SetActive(false); } //mouselook and gravity if (Input.GetKeyDown("g")) { useGravity.isOn = !useGravity.isOn; } if (Input.GetKeyDown("m")) { useMouselook.isOn = !useMouselook.isOn; } if (Input.GetKeyDown("f")) { SwitchFullscreen(); } //if (Input.GetKeyDown(KeyCode.Escape)) { useMouselook.isOn = false; useFullscreen.isOn = false; } charController.gravity = useGravity.isOn; cameraController.lockCursor = useMouselook.isOn; crosshair.SetActive(cameraController.lockCursor); //fullscreen - reverse order, setting toggle from current fullscreen state //useFullscreen.isOn = Screen.fullScreen; fullscreenCheckmark.SetActive(Screen.fullScreen); //displaing build progress float calculatedSum; float completeSum; float totalSum; ThreadWorker.GetProgresByTag("VoxelandChunk", out totalSum, out calculatedSum, out completeSum); buildProgress.maxValue = totalSum; buildProgress.value = completeSum; //editing if (cameraController.lockCursor || !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) //IsPointerOverGameObject returns true if mouse hidden { //reading controls bool leftMouse = Input.GetMouseButtonDown(0); //bool middleMouse = Input.GetMouseButtonDown(2); bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); //bool alt = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); //not used bool control = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); //getting edit mode Voxeland.EditMode editMode = Voxeland.EditMode.none; if (leftMouse && !shift && !control) { editMode = Voxeland.EditMode.dig; } else if (leftMouse && control) { editMode = Voxeland.EditMode.add; } else if (leftMouse && shift) { editMode = Voxeland.EditMode.replace; } //getting aiming ray Ray aimRay; if (cameraController.lockCursor) { aimRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.5f)); } else { aimRay = Camera.main.ScreenPointToRay(Input.mousePosition); } //aiming terrain block CoordDir aimCoord = voxeland.PointOut(aimRay); //if any change if (prevAimCoord != aimCoord || editMode != Voxeland.EditMode.none) { //highlight if (voxeland.highlight != null) { if (aimCoord.exists) { voxeland.Highlight(aimCoord, voxeland.brush, isEditing: editMode != Voxeland.EditMode.none); } else { voxeland.highlight.Clear(); //clearing highlight if nothing aimed or voxeland not selected } } //altering if (editMode != Voxeland.EditMode.none && aimCoord.exists) { voxeland.Alter(aimCoord, voxeland.brush, editMode, landType: voxeland.landTypes.selected, objectType: voxeland.objectsTypes.selected, grassType: voxeland.grassTypes.selected); } prevAimCoord = aimCoord; } //if coord or button change } }