[Closed] mesh-vert. manipulation problem
Hello everybody, i have a small problem with the following script.
What i do is,
create a custom mesh
randomly pick a few vertices from the created mesh
“pull” the surface from that vertices (like there were some kind of arbitrary attractor points), according to the normal vector at that points, and given a custom threshold of affection.
Its something like automating the soft selection option that one can have from editMesh or editPoly. Now the problem is that i have a small supplementary wrong-extrusion of the (random) vertices that i consider as attractor points. If one has time, and runs the code i believe its pretty easy to get it. In case the code’s methodology is not understandable
please ask me. Thank you in advance.
----Manipulate a Surface with Random attractorVertices-------------------------------------------------------
clearListener()
seed 12345
------------ MESH CREATION-----------------------------------------------------------------------------------------
--mesh length
myLen = 250; myWid = 250; lenSeg = 30; widSeg = 18
myObj = mesh length:myLen width:myWid lengthsegs:lenSeg widthsegs:widSeg
myObj.name = uniqueName "surfaceTension_"
myObj.wirecolor = color 0 255 0
--convert object to polygons
convertTo myObj PolyMeshObject
------------------------------------------------------------------------------------------------------------------------------
----(random) Selection Filters----------------------------------------------------------------------------------------
filterArray = #()
step = 1
for i in 1 to lenSeg do
(
for j in 1 to widSeg do
(
g = random 1 40
if g == 10 then
(
append filterArray (step as float)
)
else (append filterArray 0.)
step = step + 1
)--end for j loop
)--end for i loop
----------------------------------------------------------------------------------------------------------------------------
----Select AttractorVertices and Move-----------------------------------------------------------------------------
selectedPosition = #(); _pull = #()
for i = 1 to filterArray.count do
(
_move = random 30. 150.
if filterArray[i] != 0 do
(
_pos = polyop.getVert myObj i
--point box:on size:10. pos:_pos wirecolor:[0,0,255]
theVec = normalize _pos
toMove = noise3 [theVec.x, theVec.y, theVec.z]
_Moveamount = (toMove*_move) as float
polyop.setVertSelection myObj #{i}
move myObj.selectedVerts [0,0, _Moveamount]
point box:on size:10. pos:(_pos+[0,0,_Moveamount]) wirecolor:[255,0,0]
--append epilegmena true
append selectedPosition _pos
--format "epilegmenaPosition = %
" epilegmenaPosition
append _pull _Moveamount;
--format "_Moveamount = %
" _Moveamount
)
)
----------------------------------------------------------------------------------------------------------------------------
----Move Neigbors-----------------------------------------------------------------------------------------------------
count = 1; tolerance = 40.
for ep = 1 to selectedPosition.count do
(
for i in 1 to lenSeg do
(
for j in 1 to widSeg do
(
_pos2 = polyop.getVert myObj count
--format "_pos2 = %
" _pos2
if selectedPosition[ep] != _pos2 then
(
--format "_pos2 = %
" _pos2
dist = distance selectedPosition[ep] _pos2
--format "dist = %
" dist
if dist <= tolerance then
(
polyop.setVertSelection myObj #{count}
_neighborMove = ((((tolerance)-dist)/tolerance)*_pull[ep]) as float
--format "neighbormove = %
" _neighborMove
move myObj.selectedVerts [0,0, _neighborMove]
)
)
count = count + 1
)
)
count = 1;
)
---------------------------------------------------------------------------------------------------------------------------
In this part of the code, what i do is filter out the already selected as attractors, vertices. so that they will not get a weird extra extrusion in the end which actually didnt work.
if selectedPosition[ep] != _pos2 then
(
.............
)
so i replaced “selectedPosition[ep] != _pos2” with “count !=ep “
I just compare the indices, instead of comparing their world position.
But here is a better code of the same methodology, and runs faster.
----Manipulate a Surface with Random attractorVertices-------------------------------------------------------
clearListener(); seed 12345
------------ MESH CREATION-----------------------------------------------------------------------------------------
--mesh length
myLen = 250; myWid = 160; lenSeg = 30; widSeg = 18
myObj = mesh length:myLen width:myWid lengthsegs:lenSeg widthsegs:widSeg
myObj.name = uniqueName "surfaceTension_"
myObj.wirecolor = color 0 255 0
--convert object to polygons
convertTo myObj PolyMeshObject
------------------------------------------------------------------------------------------------------------------------------
----(random) Selection Filters----------------------------------------------------------------------------------------
filterArray = #(); step = 1
for i in 1 to lenSeg do
(
for j in 1 to widSeg do
(
g = random 1 40
if g == 10 then
(
append filterArray (step as float)
)
else (append filterArray 0.)
step = step + 1
)--end for j loop
)--end for i loop
----------------------------------------------------------------------------------------------------------------------------
----Select attractorVertices according to Filters and Move---------------------------------------------------
count = 1; tolerance = 40.
for i = 1 to filterArray.count do
(
_move = random 30. 250. -- move min | max strength
if filterArray[i] != 0 do
(
_pos = polyop.getVert myObj i
--point box:on size:10. pos:_pos wirecolor:[0,0,255]
theVec = normalize _pos
toMove = noise3 [theVec.x, theVec.y, theVec.z]
_Moveamount = (toMove*_move) as float
polyop.setVertSelection myObj #{i}
move myObj.selectedVerts [0,0, _Moveamount]
point box:on size:10. pos:(_pos+[0,0,_Moveamount]) wirecolor:[255,0,0]
--format "_Moveamount = %
" _Moveamount
for j in 1 to lenSeg do
(
for k in 1 to widSeg do
(
_pos2 = polyop.getVert myObj count
--format "_pos2 = %
" _pos2
if count != i then
(
dist = distance _pos2 _pos
--format "dist = %
" dist
if dist <= tolerance then
(
polyop.setVertSelection myObj #{count}
_neighborMove = ((((tolerance)-dist)/tolerance)*_Moveamount) as float
--format "neighbormove = %
" _neighborMove
move myObj.selectedVerts [0,0, _neighborMove]
)
)
count = count + 1
)
)
count = 1
)
)