[Closed] insert edge vertex
I’ve written a script which places a point based on a vector intersection. The point of intersection is calculated using two vectors, 1: vector projected from the center [0,0,0] and 2: vector representing the edge.
What I don’t know how to do is insert a vertex at that point of intersection on the selected edge?
Below is my code that will create the image shown below.
“`
delete objects
clearlistener()
fn get_world_vert_positions obj verts = for v in verts collect (polyop.getVert obj.baseObject v node:obj)
– collect each selected edge’s index, verts, edge vector, and vert positions
struct edgeData (index=0, verts=#(), pos=#(), vec=[0,0,0])
fn collect_edge_data obj edges =
(
local dataCollection = #()
for s in selEdges do
(
local verts = (polyop.GetVertsUsingEdge obj s) as array
local pos = get_world_vert_positions obj verts
local vec = normalize (pos[1] – pos[2])
append dataCollection (edgeData index:s verts:verts pos:pos vec:vec)
)
dataCollection
)
fn get_vector_intersection pointA vecA pointB vecB =
(
local vecC = pointB-pointA
local cross1 = cross vecA vecB
local cross2 = cross vecC vecB
local pt = pointA + ( vecA*( (dot cross2 cross1)/((length cross1)^2) ) )
pt
)
– setup
obj = plane width:100 length:100 widthsegs:4 lengthsegs:4 wirecolor:gray
convertToPoly obj
polyop.deleteFaces obj #{6…7, 10…11}
obj.SetSelection #Edge #{5, 8, 16…17, 22…25}
completeRedraw()
– variables
vec = [1,0,0]
rot = 20
– Build transform to rotate maxtrix easily
TM = matrix3 1
vec *= (PreRotateZ TM rot)
– display visual for vector
point dir:vec size:10 wirecolor:yellow axistripod:on box:off cross:off
– collect each selected edge’s index, verts, and vert positions
selEdges = polyop.getEdgeSelection obj
data = collect_edge_data obj selEdges
– find intersection
for d in data do
(
local dpos = d.pos[1]
local dvec = d.vec
– find edge intersection
local ivec = get_vector_intersection [0,0,0] vec dpos dvec
point pos:ivec wirecolor:green size:3 axistripod:off cross:on box:off
)
– Insert new vertex using vector projection
new_vert = obj.insertVertexInEdge 25 0.3
polyOp.setVertSelection obj #{new_vert} –select the new vertex
obj.vertexticks = true
select obj –select the plane
max modify mode –switch to modify panel
subObjectLevel = 1 –go to Vertex level and check it out
“`