Get coordinate of any point on a polygon

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2013   #1
Get coordinate of any point on a polygon

Hey, just wondering if there's something, maybe similar to pointonsurface, which will get the location of any point on a polygon?

Not much more to say really, I'd like to try make something which will randomly place objects on a surface like a plane (so you could have a forest or something)

Cheers
 
Old 02 February 2013   #2
look up MFnMesh.getPointAtUV(). There are a few different ways to do this but the one that comes to mind is to create random UV values and then use the UV value on a mesh to query the world space position.
 
Old 02 February 2013   #3
Quote:
Originally Posted by Chrisgibbs
the one that comes to mind is to create random UV values and then use the UV value on a mesh to query the world space position.


Nice. I'm going to go try this. I've been working on something similar for distribution per polygon or vertex, but I hadn't considered the UV values.
__________________
maya and zbrush training
creating CG3D since 2001

3D Models
@ Turbosquid

my Scripts
 
Old 02 February 2013   #4
Quote:
Originally Posted by Stoehr
Nice. I'm going to go try this. I've been working on something similar for distribution per polygon or vertex, but I hadn't considered the UV values.

cool beans
 
Old 02 February 2013   #5
Quote:
Originally Posted by Chrisgibbs
look up MFnMesh.getPointAtUV(). There are a few different ways to do this but the one that comes to mind is to create random UV values and then use the UV value on a mesh to query the world space position.


Thanks, I did give it a shot but couldn't seem to get it to work properly lol

I came across this code, but it only works on individual faces and not with every value (eg. 0.1, 0.6 doesn't exist on the shape)

Do you know any way to get around this, or should I just set it to loop until it finds a valid value?

Code:
import pymel.core as py from maya.cmds import * cube = polyCube()[0] select(cube) sel = py.ls(selection=True)[0] faces = sel.faces for f in faces: try: print f.getPointAtUV( (0.5, 0.6), space="world") except: print 'the uvs are not inside of '+f
 
Old 02 February 2013   #6
Even if there would be a function to get points this way this wouldnt give you a halfway even distribution of points across a surface if your UVs do not match the surface area of the corresponding faces of a mesh. Consider a mesh with 2 rectangle faces of same size where the first UV rectangle covers 99% of the UV space...
I think the simplest way to get random points across your surface is to create a particle system and let the emitter emit from that object, set the particle speed to zero and create as much points as you need, then query the particle positions. You even could combine the particles with a instancer and a smart particle creation script involving surface properties to get things like a forest done quick.
 
Old 02 February 2013   #7
I believe you are using the wrong example. getPointAtUV should be related to MFnMesh and not a face, e.g.:

http://www.mail-archive.com/python_...m/msg00865.html
http://download.autodesk.com/us/may...6ee3fd9968 426

If you want to ensure uniform distribution, like @zaskar suggested, you can get a random face, and weigh the distribution by a face area, and then get two random values between [0,1] for barycentric coordinates inside the triangle face.
 
Old 02 February 2013   #8
Thanks both of you

It sounds like it should work, but I'm new to particles and can only seem to make an object emit from it's vertexes, is there some setting I'm missing in the emitter?
 
Old 02 February 2013   #9
Currently, you have the emitter type set incorrectly. To make it achieve the effect you want, switch the emitter type to surface. That will make it emit randomly across the surface.
 
Old 03 March 2013   #10
Cheers, that did the trick, will have to try turn it into code now though lol
 
Old 03 March 2013   #11
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.
 
Thread Closed share thread



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 04:52 PM.


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