PDA

View Full Version : spheres on vertex


number2
04-10-2006, 01:12 PM
hello

I want to place spheres of equal size at every vertex of my model. ive "attempted" to do this myself with scripting but got in a complete mess. Can anyone give me a hand?

Thanks
number2

sciics
04-11-2006, 03:11 AM
its 'snap to points' as on i would do it like holding the ctrl key and drag. (if the area were not so big i.e.)

ThE_JacO
04-11-2006, 03:21 AM
if you search on XSIbase, I posted a snippet on how to derive a transformation matrix from a vertex.
just use that snippet in a loop on all points in a mesh to align a sphere's transformation to each point.

also there's bound to be some scripts to do it already, surely xsibase.com tools section will have something, and if not there something is bound to be in their coding section (as I remember helping several people out with similar problems, which is why I ultimately posted the mini-tut about derivating transforms from single vectors). Did you look there already?

ShadowM8
04-11-2006, 03:49 AM
Searching XSIBase forums sometimes can be a nightmare.... :banghead:
Here's a snipet of code that should get you started in the right direction, just select and object and run it.

var obj = Selection(0);
var points = obj.activeprimitive.geometry.points;
for (i = 0; i < points.count; i++) {
var pos = XSIMath.CreateVector3();
var pos = points.item(i).position
CreatePrim("Sphere", "MeshSurface", null, null);
Translate(null, pos.x, pos.y, pos.z, siRelative, siGlobalSym, siObj, siXYZ, null, null, null, null, null, null, null, null, null, 0, null);
}

Edit: this doesn't take into account any live transformations on the object
Done in JScript

ThE_JacO
04-11-2006, 03:58 AM
doing it by translating, the way you're doing it, means running a command for each point, that turns out very quickly to be under-performing.
you'd be better off using that vector to manipulate the sphere's kinematics.

you're also dealing with translation only, which is not an alignment operation.

aligning to a vertex normally means aligning an object's position to that vertex, and aligning the Y axis with the vertex normal, and eventually the X axis with the projection of the first edge on the normal plane, if you want to fully emulate XSI's SRT frameset for points.

if you need the maths, they are trivial

Y = point's normal (which really is the average of the nearby triangles normals)
X = projection of a vector representing the 1st edge neighbor on the plane orthogonal to Y
Z = YxX or XxY

if a roll doesn't need consistancy with the full point's frameset, but can be arbitrary, then you can simplify and remove the projection and just do it by upvectoring:

Y= point's normal
UpVector = vector parallel to the normal's axis of least magnitude
X = YxUpVector
Z = YxX or XxY

ShadowM8
04-11-2006, 04:40 AM
Well you've got me all intrigued now, I'll give this a run down tomorrow and see if I can do a fully functioning align to vertex script.
Thanks for the tips.

ThE_JacO
04-11-2006, 04:49 AM
here's the original post for the vector2matrix snippet, couple good comments and links by Andrea and Helge too I seem to remember.
http://www.xsibase.com/forum/index.php?board=6;action=display;threadid=19609;start=0#msg128098

Ordibble-Plop
04-11-2006, 09:28 AM
If by any chance you want/don't mind the spheres being constrained and don't need them to be aligned to the vertices of your model you might try the script ntmonkey wrote for me here (http://forums.cgsociety.org/showthread.php?t=332795)

You'd have to rename your model or parts thereof to 'grid' or edit the script to get it to work.

number2
04-11-2006, 09:50 AM
thanks for you help guys, lots to try out and play with there

number2

CGTalk Moderation
04-11-2006, 09:50 AM
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.