// ----------------------------------------------------------------------------------------------------------------- public bool SearchNextOffset(float offset, ref Vector3 offset_pos) { // Start with with current edge and search fitting edge while (m_search_it != null) { CEdgeNode e = m_search_it.Value; float edge_len = e.GetLength(); // Check whether offset is inside the boundaries of current edge if (offset > m_search_offset && offset < m_search_offset + edge_len) { // Bingo float diff = offset - m_search_offset; offset_pos = e.GetVertex(0).GetPos() + e.GetUnitVector() * diff; return(true); } // Continue with next edge m_search_offset += edge_len; m_search_it = m_search_it.Next; } // Not found return(false); }
// ----------------------------------------------------------------------------------------------------------------- public void AddVertex(Vector3 pos, bool finalize_head) { bool rebuild_line_renderer = false; // Add first vertex if (m_vertices.Count == 0) { CVertexNode v1 = AddVertexNode(pos); CVertexNode v0 = AddVertexNode(pos); m_edges.AddFirst(new CEdgeNode(v0, v1)); rebuild_line_renderer = true; // Finalize head } else if (finalize_head) { CVertexNode v1 = m_vertices.First.Value; v1.SetPos(pos); CVertexNode v0 = AddVertexNode(pos); m_edges.AddFirst(new CEdgeNode(v0, v1)); rebuild_line_renderer = true; // Update head } else { m_vertices.First.Value.SetPos(pos); m_edges.First.Value.Update(); rebuild_line_renderer = false; } // Take care of max length if (m_vertices.Count > m_config.max_vertices) { if (m_increase_len) { m_increase_len = false; m_config.max_vertices++; } else { ReleaseVertexNode(m_vertices.Last.Value); m_vertices.RemoveLast(); m_edges.RemoveLast(); } } // Update line renderer if (m_line_renderer != null) { // Rebuild line renderer m_line_renderer.SetVertexCount(m_vertices.Count); if (rebuild_line_renderer) { int idx = 0; m_line_renderer.SetVertexCount(m_vertices.Count); // Build line renderer from edges for (LinkedListNode <CEdgeNode> it = m_edges.First; it != null; it = it.Next) { CEdgeNode e = it.Value; if (idx == 0) { m_line_renderer.SetPosition(idx++, e.GetVertex(0).GetPos()); m_line_renderer.SetPosition(idx++, e.GetVertex(1).GetPos()); } else { m_line_renderer.SetPosition(idx++, e.GetVertex(1).GetPos()); } } // Update only head } else { m_line_renderer.SetPosition(0, pos); } } }