CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-31-2013, 11:50 AM   #1
GreySize
Member
 
GreySize's Avatar
portfolio
Calvet David
Technical Director
BANDITS Collective
United Kingdom
 
Join Date: Mar 2009
Posts: 20
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 :

Code:
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 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
 
Old 03-31-2013, 10:11 PM   #2
GreySize
Member
 
GreySize's Avatar
portfolio
Calvet David
Technical Director
BANDITS Collective
United Kingdom
 
Join Date: Mar 2009
Posts: 20
I found an other way to do it, slower but it works

Code:
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
 
Old 04-01-2013, 10:28 AM   #3
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,631
Send a message via ICQ to denisT
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:
Code:
(meshop.getvertsusingedge mesh (meshop.getedgesusingvert mesh v)) - #{v}

by faces:
Code:
(meshop.getvertsusingface mesh (meshop.getfacesusingvert mesh v)) - #{v}


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

Last edited by denisT : 04-01-2013 at 10:32 AM.
 
Old 04-01-2013, 10:35 AM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,631
Send a message via ICQ to denisT
btw... who can show the fastest way how to get all neighbors of every mesh vertex?
 
Old 04-01-2013, 02:48 PM   #5
GreySize
Member
 
GreySize's Avatar
portfolio
Calvet David
Technical Director
BANDITS Collective
United Kingdom
 
Join Date: Mar 2009
Posts: 20
Thank you, i was sure there was an other way to write it faster. Testing it
 
Old 04-01-2013, 02:51 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,631
Send a message via ICQ to denisT
Quote:
Originally Posted by GreySize
Thank you, i was sure there was an other way to write it faster. Testing it

if you need to compute all vertices the way that i showed above is not fastest.
 
Old 04-01-2013, 02:51 PM   #7
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:53 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.