/// <summary> /// Add a vertx to the Line when you know the segment to add the vertex to /// </summary> /// <param name="segment"> Linesegement to add the vertex to </param> /// <param name="position"> Vertex Position in Wordl Space coordinates</param> /// <returns></returns> public VirgisFeature AddVertex(LineSegment segment, Vector3 position) { int start = segment.vStart; int next = segment.vEnd; VertexTable.ForEach(item => { if (item.Vertex > start) { item.Vertex++; if (item.Line != null) { item.Line.vStart++; if (item.Line.vEnd != 0) { item.Line.vEnd++; } } } if (Lr && item.isVertex && item.Line.vStart == start) { item.Line.vEnd = start + 1; } if (Lr && item.isVertex && item.Line.vEnd > VertexTable.Count) { item.Line.vEnd = 0; } }); start++; int end = next; if (end != 0) { end++; } segment.MoveEnd(position); Datapoint vertex = _createVertex(position, start); _createSegment(position, VertexTable.Find(item => item.Vertex == end).Com.transform.position, start, end == 0); transform.parent.SendMessage("AddVertex", position, SendMessageOptions.DontRequireReceiver); vertex.UnSelected(SelectionType.SELECT); curve.Vector3(GetVertexPositions(), Lr); return(vertex); }
private void OnTriggerSinglePress(Vector3 posWhenSinglePress) { if (_appState.editSession.IsActive()) { IVirgisLayer editableLayer = _appState.editSession.editableLayer; FeatureType dataType = editableLayer.featureType; Datapoint[] vertexes; switch (dataType) { case FeatureType.POINT: VirgisFeature point = editableLayer.AddFeature(new Vector3[1] { posWhenSinglePress }); point.UnSelected(SelectionType.SELECT); break; case FeatureType.LINE: //Debug.Log($"ShapeAdder add Vertex"); if (_newFeature != null) { _newFeature.AddVertex(posWhenSinglePress); } else { _newFeature = editableLayer.AddFeature(new Vector3[2] { posWhenSinglePress, posWhenSinglePress + Vector3.one * 0.1f }); // get the last vertex vertexes = (_newFeature as Dataline).GetVertexes(); _firstVertex = vertexes[0]; _lastVertex.Add(vertexes[1]); _firstVertex.UnSelected(SelectionType.SELECT); } break; case FeatureType.POLYGON: if (_newFeature != null) { if (_lastVertex.Count == 1) { _newFeature.transform.GetComponentInChildren <Dataline>().AddVertex(posWhenSinglePress); } else { _lastVertex[0].UnSelected(SelectionType.SELECT); _lastVertex.RemoveAt(0); } } else { _newFeature = editableLayer.AddFeature(new Vector3[4] { posWhenSinglePress, posWhenSinglePress + Vector3.right * 0.01f, posWhenSinglePress + Vector3.up * 0.01f, posWhenSinglePress }); vertexes = (_newFeature as Datapolygon).GetVertexes(); _firstVertex = vertexes[0]; _lastVertex.Add(vertexes[1]); _lastVertex.Add(vertexes[2]); } break; } } }