[Closed] align object to Nurbs Surface
Hello guys, i have a small problem with a script. I wanted to be able to know the exact real world position of a certain UV point of a NurbsCVSurface. That is the easy part, maxscript has already a method for that. My question is how can i align another object on that exact uv surface position ? I have to match the surface normal of that particular point to the dir of my object. I know how to do it with polys or meshes. But i cant find any help in the Maxscript helpfile to do it with nurbs surfaces. I cant find any method or function like GetNormal <nurbs_surface> <u_param> <v_param> or something like that.
Here is my code:
myNurbsNode = selection[1];
if classof myNurbsNode == NURBSSurf do
(
-- if the selection was succesful then
-- get the nurbs set for it
ns = getnurbsset myNurbsNode #relational;
-- extract the first object from the set getobject <Nurbset> <object index>
mySurface = getobject ns 1;
reparameterize mySurface #uniform;
numPointsU = 25;
numPointsV = 25;
_stepU = 1/numPointsU as float;
_stepV = 1/numPointsV as float;
for i = 0 to 1 by _stepU do
(
for j = 0 to 1 by _stepV do
(
-- extract point3 coordinates from U direction
thepos1 = evalpos mySurface i j;
-- extract point3 coordinates from V direction
thepos2 = evalpos mySurface j i;
)
)
)
I am basically creating a grid with specified resolution on a selected Nurbs surface. And at each point on the surface i wanted to align another object.
Thanks.
would this give the normal ?
cross (evalutangent mysurface i j) (evalvtangent mysurface i j)
Hello, again. I don’t know what is going on with the coord sys but when i assign the direction that i get from the normal calculation to an object’s .dir value, for some reason it keeps positioning it around 0,0,0 point and not on the relative surface as it should. I am posting an image in order to make it more clear. Two paradigms, one with a weaving effect and one with a bunch of cylinders.
Uploaded with ImageShack.us
Here is the code that i used the last time (with the cylinders):
pointsUArray = #();
pointsVArray = #();
myNurbsNode = selection[1];
if myNurbsNode != undefined then
(
if classof myNurbsNode == NURBSSurf do
(
-- if the selection was succesful then
-- get the nurbs set for it
ns = getnurbsset myNurbsNode #relational;
-- extract the first object from the set getobject <Nurbset> <object index>
mySurface = getobject ns 1;
reparameterize mySurface #uniform;
-- calculate the weaving analysis, how many weaving threads in U and V direction
numPointsU = 25;
numPointsV = 25;
-- according to the num of points in each direction, calculate the step for the following loops
-- step must be inside the range [0,1].
_stepU = 1/numPointsU as float;
_stepV = 1/numPointsV as float;
for i = 0 to 1 by _stepU do
(
for j = 0 to 1 by _stepV do
(
-- extract point3 coordinates from U direction
thepos1 = evalpos mySurface i j;
append pointsUArray thepos1;
nrm = cross (evalutangent mySurface i j) (evalvtangent mySurface i j);
cylinder radius:1.0 height:3.0 pos:thepos1 dir:nrm;
/*-- extract point3 coordinates from V direction
thepos2 = evalpos mySurface j i;
append pointsVArray thepos2;*/
)
)
)
)
Yes it now works, so the objects inside a nurbs set keep as a default coord sys the 0,0,0 ?
no not really as such
evalpos mySurface i j;
just returns the position in the local coordinate system of the nurbs node.
you could equally code
in coordsys world
(
pos = evalpos mySurface i j;
)
and it should give the same result
So you first calculate the position of uv on the nurbs object in local coords with evalpos method, and then you use myNurbsNode.transform to acurately map the coords of the object in the coords of the NurbsNode right?