[Closed] Align Edge Rotation to Direction Vector?
I have this working but it’s hacky.
I’m wondering how to take a direction vector and face normal
And align an edge to that…
Meaning rotate the edge about a normal so that the edge
Is rotated in the direction of the direction vector.
So if u took 2 normalized mouse positions for the direction and
Used a hit normal of a face, how would I align the edge
Using that. I’m doing this in polyop.
Now that I think about it, not being at my pc, would the cross
Product of those give me that transform?
the question would have been more clear had you illustrated it with images…
I tried using this code below, but it’s not rotating properly.
I’m currently using it to rotate a spline to the surface of a mesh for testing purposes.
local UpVector = normalize (worldPos - StartPos)
rightVector = normalize (cross UpVector worldNormal)
theMatrix = (matrix3 rightVector upVector worldNormal worldPos)
local theScale = theSpline.Scale
theSpline.transform = theMatrix
theSpline.Scale = theScale*/
This is what I want to do… but preferably without making a spline and aligning verts to the ends of the spline like I am now…
So I found out that doing an Edge Extrude gives me extra edges I don’t want sometimes.
So now I am having to figure out how to do the same as what Shift+Drag an Edge does. This works different from the Edge Extrude option in Editable Poly.
Ah, nice. I’ll take a look. I’ve used this before, its a great script!
I just need to figure out how he’s getting the proper direction/distance
Thanks!
Well I got this code now, which is what I was looking at before somewhat. This creates a new edge extrusion, in a sense, in the direction/place I want it to be. Now it’s just back to the rotation again.
Since I’m creating 2 Verts and a Face from that, I could set the Verts properly in the first place before creating the face to get the rotation. That’s the tricky part now…
(
SetCommandPanelTaskMode#modify
subObjectLevel = 2
local verts = polyop.getVertsUsingEdge $ (polyop.getEdgeSelection $)
local edgeCenter = [0,0,0]
for vert in verts do
(
edgeCenter += polyop.getVert $ vert node:$
)
edgeCenter = edgeCenter / (verts as array).count
local dir = normalize ($Teapot01.pos - edgeCenter )
local newVerts = #()
local offset = distance edgeCenter $Teapot01.pos
local offset2 = offset * 0.25
local cnt = 1
for vert in verts do
(
theVertPos = polyop.getVert $ vert node:$
--if cnt == 1 then newPos = theVertPos+(dir*offset2)
newPos = theVertPos+(dir*offset)
append newVerts ($.createVertex newPos pointInLocalCoords:false select:true)
cnt += 1
)
verts = verts as array
selection[1].createFace #(verts[2],newVerts[2],newVerts[1],verts[1]) select:true
)
I figured it out Here it is.
local theEdge
if (theEdge == 0) do
(
theEdge = tTGetNearestEdgeToPoint_PolyMesh face worldPos
)
local edgeCenter = [0,0,0]
local theVerts = polyop.getVertsUsingEdge selection[1] theEdge
local pGetVert = polyop.getVert
local psetVert = polyop.setVert
for vert in theVerts do
(
edgeCenter += pGetVert selection[1] vert node:Selection[1]
)
edgeCenter = edgeCenter/(theVerts as array).count
local extrudeDist = distance worldPos edgeCenter
local extrudeDir = (normalize (worldPos - edgeCenter))
polyop.setEdgeSelection selection[1] theEdge
local newVerts = #()
for vert in theVerts do
(
theVertPos = polyop.getVert selection[1] vert node:selection[1]
newPos = theVertPos+(extrudeDir*extrudeDist)
append newVerts (selection[1].createVertex newPos pointInLocalCoords:false select:true)
)
verts = theVerts as array
selection[1].createFace #(verts[2],newVerts[2],newVerts[1],verts[1]) select:true
--Select New Edge
edges = polyop.getEdgesUsingVert selection[1] newVerts[1]
polyop.setEdgeSelection selection[1] (edges as array)[2]
--ROTATE EDGE TO DIRECTION OF WORLD POS FROM EXTRUDE POS
---------------------------------------------------------------------------------------------
local verts = polyop.getVertsUsingEdge selection[1] (polyop.getEdgeSelection selection[1])
local edgeCenter = [0,0,0]
local sampleVert
for vert in verts do
(
sampleVert = polyop.getVert selection[1] vert node:selection[1]
edgeCenter += polyop.getVert selection[1] vert node:selection[1]
)
local edgeCenter = edgeCenter / (verts as array).count
local rightVector = normalize (cross extrudeDir worldNormal)
width = width /2 -- Brush Size
local cnt = 1
for vert in verts do
(
if cnt == 1 then
(
theMatrix = matrix3 extrudeDir worldNormal (rightVector) edgeCenter
theVertPos = polyop.getVert selection[1] vert node:selection[1]
newPos = edgeCenter+(theMatrix.row3*width)
polyop.setVert selection[1] vert newPos node:selection[1]
)
else
(
theMatrix = matrix3 extrudeDir worldNormal (rightVector * -1) edgeCenter
theVertPos = polyop.getVert selection[1] vert node:selection[1]
newPos = edgeCenter+(theMatrix.row3*width)
polyop.setVert selection[1] vert newPos node:selection[1]
)
cnt +=1
)
-----------------------------------------------------------------------------------------------
update selection[1]
This is what I was using this for,
http://www.matthewlichy.com/retopoTools/retopoTools.html
However sometimes it flips, so I need to see if I can fix that… I’m always using the same verts/creating verts the same way. But I guess sometimes I get the wrong/opposite vert on the edge and create from there. I guess what I could do, is create the face, if the Normal.Z of the new Face is < the World Hit Normal, then re-create the face using a new Vertex Order?