Notifications
Clear all

[Closed] Get Grow function

Hi everyone,

I’m currently working on a script, where each vertex of a selected object are running in a for loop to calculate their Normal vector. I would like to get the surrounding vertex to calculate the distance between the vertex of the loop and the surrounding ( it’s the easiest way i found to get the polygon density locally).

Here is a piece of the script :


 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
 
 objetSourcePoly = $ 
 objetSource = snapshotasmesh$ 
 model = #($Brush_01,$Brush_02,$Brush_03,$Brush_04)
 
 
 for vertIndex = 1 to objetSource.numverts do
 (
 
 	vertFaces = meshop.getFacesUsingVert objetSource vertIndex 
 	vertNorm = point3 0 0 0
 
 	for face = 1 to vertFaces.count do
 	(
 		if vertFaces[face] then 
 		(
 			faceNormal = getFaceNormal objetSource face
 			vertNorm = vertNorm + faceNormal
 		)
 	vertNorm = normalize vertNorm
 	)
   	 
 	r = random 1 (model.count)
 
 	localModel = instance model[r]
 	localModel.dir = vertNorm 
 	in coordsys local rotate localModel (angleaxis -90 [0,1,0]) 
 	localModel.pos = getVert objetSource vertIndex
 	
 	 -- I need to select the vertex "vertIndex" in the Poly object
 	VertPoly = polyop.setVertSelection objetSourcePoly vertIndex
 	objetSourcePoly.EditablePoly.SetSelection #Vertex #{vertIndex}

       -- Then grow the selection
       VertAround = objetSourcePoly.EditablePoly.GrowSelection ()
 	-- Finaly delete from selection the "VertIndex" to get only the surrounding vertex
       AroundVertPoly = AroundVertPoly - VertPoly
 
   -- After that i need a for loop for each surrounding vertex to calculate distance between each of them and the "vertIndex"
 	
 )

I hope you’ll be able to help me, i think i just missed an easy part to call the Grow button in the command panel, or an other function

Thank you

5 Replies

I found an other way to do it, slower but it works

vertDistanceArray = #() --create an empty array for distance

	for i = 1 to objetSource.numVerts do
		(
		vertDistanceArray[i] = distance (getVert objetSource i) (getVert objetSource vertIndex)
		)

--till here, the distance of all the vertices has been stored in the array.

vertDistanceArray = sort vertDistanceArray

-- Calculate the medium lenght
VertDistance = vertDistanceArray[2] + vertDistanceArray[3] + vertDistanceArray[4] + vertDistanceArray[5] + vertDistanceArray[6]
		
VertMoy = VertDistance / 5 

everything is much easier… because you already have a snapshot mesh (i will call it mesh in my sample) the neighbors of a vertex (v) are:
by edges:

(meshop.getvertsusingedge mesh (meshop.getedgesusingvert mesh v)) - #{v}

by faces:

(meshop.getvertsusingface mesh (meshop.getfacesusingvert mesh v)) - #{v}

ps. polyop.getfacenormal is much faster then getfacenormal (mesh method)

btw… who can show the fastest way how to get all neighbors of every mesh vertex?

Thank you, i was sure there was an other way to write it faster. Testing it

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

if you need to compute all vertices the way that i showed above is not fastest.