Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Vertex Positions calculated from two different meshes
  RSS 2.0 ATOM  

Vertex Positions calculated from two different meshes
Rate this thread
 
53469
 
Permlink of this thread  
avatar
  • Location: Columbus, Ohio
  • Total Posts: 434
  • Joined: 01 March 2008 04:43 AM

My math skills are not the strongest, and I am having a problem figuring out how to solve a scenario in MAXScript.

I am trying to get the Unit Vector (and other values) of vertices from the point of view of vertices in another mesh.

The situation is that there is a plane converted to Editable Poly. There is then another plane copied from that plane--so they have the same vertex count/order. The original is kept for reference and the second is used to sculpt (in this case a landscape).

I need to then retrieve various bits of information from the vertices… for example, the unit vector of vertices D1, D2, D3, etc, as well as their distances from S1, S2, S3, etc.

My understanding is weak… the values I’m getting are far far from what I expect… and I’m assuming it’s because my understanding is far far from accurate.

Here is an example snippet that generates info that is not what I want:

(d and s are both editable poly)

for 1 to (polyop.getNumVerts d) do (
 
 
 
vd polyop.getVert d i
 
 vs 
polyop.getVert s i
 
 
 dist 
distance vs vd
 
 unitVector 
vd/dist
 
 
print ("Vertex #"+(as string)+" "+((dist) as string) +" Unit Vector: "+(unitVector as string))

 
 )

The output is continuously things like:

"Vertex #20 0.0 Unit Vector: [-1.#INF,1.#INF,-1.#INF]"
"Vertex #21 5.10022 Unit Vector: [-496.488,234.999,-314.324]"
etc

But I (think) am looking for things like:

"Vertex #20 0.0 Unit Vector: [0,0,1]"
"Vertex #21 5.10022 Unit Vector: [0.5,0.25,0.25]"
etc

Attached is a screen shot example of some source to taget vertices I am trying to get data from.

Hopefully this makes sense. I am not the world’s greatest mathmatician… (came from a background in journalism)… so I’m playing catchup with some of these concepts.

Much thanks in advance for any help.



______________________________
Shawn Olson’s Creative Arts
Developer of the Wall Worm Model Tools for Source
And my Favorite Unsung Plugin: Convexity for Level Design

Max 4/Gmax, 2008 - 2013
Mudbox 2009-2011
Win 7 x64 (x4)
Geforce 480x2 | Geforce 275x1 | ATI Radeon HD 3200 | Intel Generic chip
8GB | 12GB | 4GB | 4GB
Intel Quad 6700 | i7 930 | Athlon QL-65 | Intel Quad 6700

Attachment Attachment
Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

My maths is probably about as good as yours…

But, the reason for the anomaly is if the vertices are coincident the distance will be 0. Divide by zero is an error, hence the .inf (infinity).

Try it on a simplified situation first, just 2 Planes (no extra segments so just 1 poly/4 verts) separated only in Z (X and Y the same).

Unless your code is not what you posted then it should work - it does here - though I typed it in rather than copy/pasting from the post.

You might want to test for the “coincident vertices” situation with something like

if dist == 0.0 then
   unitVector 
0.0
else
   
unitVector vd dist

Tip. Format is much more flexible than print - print can be a bit odd, sometimes, when used in a script as it’s designed for interactive use in the Listener.

format "Vertex # % Dist % Unit Vector: %\n" i dist unitVector


Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 1
/img/forum/dark/default_avatar.png

Thanks Steve… how embarassing not to think of the dividing by 0 ...

Author: Shawn Olson

Replied: 19 March 2011 06:51 AM  
avatar

Agreed, catching the coincidence is one thing (although you may want to make the unitVector [0,0,1] in that case instead of 0.0), the other thing is that there’s something weird about the way you get the vector. It’s either a vector from scene origin (which doesn’t make much sense but then it’d be unitVector = vd/dist you’re using, only the dist would be distance from the origin not another vertex) or vector from the previous vertex in which case it would be unitVector = (vd-vs)/dist or simply normalize (vd-vs)



Vojtech Cada
Max 6 - 2012
Blog :: LinkedIn profile

Replies: 2
/img/forum/dark/default_avatar.png

Aha… yes… you gave me what I wanted! Thank you!

Now if I could download knowledge like in the Matrix I wouldn’t have to waste everyone’s time!

Much thanks Swordslayer and Steve!

Author: Shawn Olson

Replied: 19 March 2011 06:55 AM  
/img/forum/dark/default_avatar.png

If you find out how to do that (the Matrix) Let me know - I always fancied of of those cortical implant thingies ;)

@Swordslayer - You’re right about setting the unitvector to a point3 - I was looking at the results (of the script) and the point3 just didn’t register :rolleyes:

Author: Steve_Curley

Replied: 19 March 2011 08:16 AM  
avatar

Steve… as soon as I figure out the interface for such a knowledge transfer device, I’ll be sure to share it with you! You’ve certainly made yourself quite helpful for many people.

Unfortunately, the odds are that the only version I’ll have any time soon will be in a .max format… so it may not do you as much good as you’d like :)



______________________________
Shawn Olson’s Creative Arts
Developer of the Wall Worm Model Tools for Source
And my Favorite Unsung Plugin: Convexity for Level Design

Max 4/Gmax, 2008 - 2013
Mudbox 2009-2011
Win 7 x64 (x4)
Geforce 480x2 | Geforce 275x1 | ATI Radeon HD 3200 | Intel Generic chip
8GB | 12GB | 4GB | 4GB
Intel Quad 6700 | i7 930 | Athlon QL-65 | Intel Quad 6700

Replies: 1
/img/forum/dark/default_avatar.png

:)

Author: Steve_Curley

Replied: 19 March 2011 11:27 PM  
avatar

I was searching the internet for an answer to a problem… and one of the first results was this thread I started many months ago on the same problem. Actually, not 100% the same but directly related.

The solution provided by Swordslayer for:

unitVector normalize (vd-vs)

is good for my original test which used a Plane as the starting mesh. But as it turned out, the scenario required me to move to starting with a Box(). And in that situation, the unitVector fails on all vertices shared between different sides of the Box().

I am certain it has something to do with the local orientation of those vertices… but I cannot figure out a way to account for that as my math skills are very flemsy.

There is an example of the problem here. As always, I am indebted to all you MAXScript masters and teachers.



______________________________
Shawn Olson’s Creative Arts
Developer of the Wall Worm Model Tools for Source
And my Favorite Unsung Plugin: Convexity for Level Design

Max 4/Gmax, 2008 - 2013
Mudbox 2009-2011
Win 7 x64 (x4)
Geforce 480x2 | Geforce 275x1 | ATI Radeon HD 3200 | Intel Generic chip
8GB | 12GB | 4GB | 4GB
Intel Quad 6700 | i7 930 | Athlon QL-65 | Intel Quad 6700

Replies: 0