public Vector2 PosToUv(Vector3 diff) { var uv = new Vector2(); switch (GridNavigator.Inst().gSide) { case Gridside.xy: uv.x = diff.x; uv.y = diff.y; break; case Gridside.xz: uv.x = diff.x; uv.y = diff.z; break; case Gridside.zy: uv.x = diff.z; uv.y = diff.y; break; } uv = (uv + offset); uv.Scale(tiling); return(uv); }
public void MoveVertexToGrid(PainterMesh.MeshPoint vp) { UpdateLocalSpaceMousePosition(); var diff = onGridLocal - vp.localPos; diff.Scale(GridNavigator.Inst().GetGridPerpendicularVector()); vp.localPos += diff; }
public void StopEditingMesh() { if (target) { MeshTool.OnDeSelectTool(); target.SavedEditableMesh = new CfgData(editedMesh.Encode().ToString()); target = null; targetTransform = null; } Grid.DeactivateVertices(); GridNavigator.Inst().SetEnabled(false, false); UndoMoves.Clear(); RedoMoves.Clear(); }
public override void ManageDragging() { var m = MeshMGMT; var beforeCouldDrag = m.DragDelay <= 0; if (EditorInputManager.GetMouseButtonUp(0) || !EditorInputManager.GetMouseButton(0)) { m.Dragging = false; if (beforeCouldDrag) { EditedMesh.dirtyPosition = true; } else { OnClickDetected(); } } else { var canDrag = m.DragDelay <= 0; if (beforeCouldDrag != canDrag && EditorInputManager.Alt && m.SelectedUv.meshPoint.vertices.Count > 1) { m.DisconnectDragged(); } if (!canDrag || !(GridNavigator.Inst().AngGridToCamera(GridNavigator.onGridPos) < 82)) { return; } var delta = GridNavigator.onGridPos - _originalPosition; if (delta.magnitude == 0) { return; } m.TriVertices = 0; foreach (var v in _draggedVertices) { v.WorldPos += delta; } _originalPosition = GridNavigator.onGridPos; } }
public void DrowLinesAroundTargetPiece() { var piecePos = targetTransform.TransformPoint(-Vector3.one / 2);//PositionScripts.PosUpdate(_target.getpos(), false); var projected = GridNavigator.Inst().ProjectToGrid(piecePos); // piecePos * getGridMaskVector() + ptdPos.ToV3(false)*getGridPerpendicularVector(); var gridMask = GridNavigator.Inst().GetGridMaskVector() * 128 + projected; Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(gridMask.x, projected.y, projected.z), Color.red); Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(projected.x, gridMask.y, projected.z), Color.red); Debug.DrawLine(new Vector3(projected.x, projected.y, projected.z), new Vector3(projected.x, projected.y, gridMask.z), Color.red); Debug.DrawLine(new Vector3(projected.x, gridMask.y, gridMask.z), new Vector3(gridMask.x, gridMask.y, gridMask.z), Color.red); Debug.DrawLine(new Vector3(gridMask.x, projected.y, gridMask.z), new Vector3(gridMask.x, gridMask.y, gridMask.z), Color.red); Debug.DrawLine(new Vector3(gridMask.x, gridMask.y, projected.z), new Vector3(gridMask.x, gridMask.y, gridMask.z), Color.red); DrawTransformedCubeDebug(targetTransform, Color.blue); }
private void AutoProjectUVs(EditableMesh eMesh) { var trgPos = MeshEditorManager.targetTransform.position; var gn = GridNavigator.Inst(); if (projectorNormalThreshold01 == 1) { foreach (var t in eMesh.triangles) { for (var i = 0; i < 3; i++) { var v = t.vertexes[i]; v.SetUvIndexBy(PosToUv(v.meshPoint.WorldPos - trgPos)); } } } else { foreach (var t in eMesh.triangles) { var norm = t.GetSharpNormal(); // var pv = gn.InPlaneVector(norm); var perp = gn.PerpendicularToPlaneVector(norm); if ((Mathf.Abs(perp) < projectorNormalThreshold01) || (perp > 0 != projectFront)) { continue; } for (var i = 0; i < 3; i++) { var v = t.vertexes[i]; v.SetUvIndexBy(PosToUv(v.meshPoint.WorldPos - trgPos)); } } } eMesh.Dirty = true; }
private bool RayCastVertexIsPointed() { PointedUv = null; if (editedMesh.meshPoints.Count <= 0) { return(false); } var alt = EditorInputManager.Alt; if (alt) { GridNavigator.collisionPos = GridNavigator.onGridPos; } RaycastHit hit; var vertexIsPointed = false; if (GridNavigator.RaycastMouse(out hit)) { vertexIsPointed = (hit.transform.tag == VertexEditorUiElementTag); if (!alt) { if (vertexIsPointed) { GridNavigator.collisionPos = hit.transform.position; UpdateLocalSpaceMousePosition(); editedMesh.SortAround(collisionPosLocal, true); } else { GridNavigator.collisionPos = hit.point; UpdateLocalSpaceMousePosition(); editedMesh.SortAround(collisionPosLocal, true); GetPointedTriangleOrLine(); } } } UpdateLocalSpaceMousePosition(); return(vertexIsPointed); }
private void OnEnable() => _inst = this;