Duplicate Objects Inside Of Curve

ok, I already looked through the help files, and search here on highend, and I'm not sure where to start with this idea.

What I want to know if it's possible, is if I can do this:

  1. Draw a curve
  2. Select an object
  3. Duplicate this object INSIDE of the curve (a closed curve)
  4. Take those objects that have been duped and conform them to a "terriain" object.

Basically, I'm just looking to find out if its possible to dupe objects to be bound inside of a curve. It seems like it would be possible, but im not sure of the place to start.

Is there any way to put all the coordinates ( or at least a list of whole numbers or .5 fractions ) into an array? If I could do that then this would probably be possible....

Hope someone can give me some insight.

Thanks!

Contained how, i mean a curve even a closed one does not bound anything particular in 3d.

basically just use the curve as a bounding volume in which objects would be duplicated. I know its possible to just duplicate an objects randomly in any direction, but im wondering if it would be possible to dupe only inside the bounding volume.

thx

Sure but its expensive like hell!

But tell me again how is a curve defining volume?

maybe he means in 2d. If you draw a curve its 2d anyway. So maybe define a 2d area with the closed curve. A terriain is kinda 2d, isn't it?

but .. i got no solution anyway

ah just a simple closed 2D nurbs curve. I kind of gave up on this idea, as it was hurting my brain

QUOTE(ewerybody @ 08/11/06, 10:58 AM) [snapback]244861[/snapback]
but .. i got no solution anyway

Yes you do! just use the exact same code as your legoize but just for one layer

hmm.. yes, that whould fit. but then it whould have to be a poly and furthermore the legolizer work in a grid and maybe 3dimentia wants it randomly... if he still wants it at all

to say short: if your curve could also be a polysurface you could shot rays with rayIntersect all over the surface boundingbox, if the ray hits it create an object..

I dont know if this is what the question is:

there is a closed curve in your scene and you want to duplicate an object a number of times such that all the dupes get randomly placed in the region enclosed by the curve. Well if that is the question then I can probably give a few inputs from my side:

I am just explaining a basic algorithm. Its up to you how you plan to implement it through MEL.

In my opinion to begin with you must have all the world-space co-ordinates of the vertexes of the curve.

now lets talk about the vertexes in 2D plane as in lets consider the z-coordinate to be 0 for the time being (the curve lies in the xy-plane). Let the vertexes be : (x1,y1) (x2,y2) (x3,y3)...(xmin,ymin)...(xmax,ymax)...(x10,y10)

Now once you have the vertices, get the maximum value of X and the minimum value of X. Lets suppose they are xmin and xmax. So now you know the x coordinates of the final position of the duplicated copies should lie in the range xmin to xmax.

Now using an in built random function in MEL generate values between xmax and xmin. Let these be the x coordinates of the duplicated copies.

For every x in xmin to xmax range you got to calculate the ymin and ymax. so you better make a function to calculate that. It can be done but will take a little effort.

Wont work if the curves turs in on itself.

The shoot ray method is more ropoust since it can also nagdle selfintersecting faces. Is offcourse slight coarse estimation if you need to sue extruded poly hedge but it will work. For examle the dark green obne in the imege would not work.

Idea is this (digs out a old picture used in legoize discussion):

idea is if the ray passes the shape a odd amount of times its inside and if 0 times its outside.

Ayway if you dig out the legoize therads they tell you how to implement the precent thing with raycasting, but thing is ist odes not realy do uniform placement (se because the first attrib allways hits som height then if its thiner in width than middle it gets more likely hits). If you wnat truly uniform its
better to place them truly randomly and dicard the rest. And hop

hehe :] this is actually fun!

the curve must be quite clean to make it a poly plane. But there is everything aboard to make it so:

CODE
{   // to make the curve flat
    string $curveSel[] = filterExpand -sm 9;
    select ($curveSel[0] + ".cv[*]");
    move -a -moveY 0;
    select $curveSel;
}

CODE
{   // to uniformly rebuid the curve
    string $curveSel[] = filterExpand -sm 9;
    rebuildCurve -ch 0 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 30 -d 3 -tol 0 $curveSel;
    select $curveSel;
}

CODE
{   // to close the curve: // mind: this toggles closed/open
    string $curveSel[] = filterExpand -sm 9;
    closeCurve -ch 0 -ps 1 -rpo 1 -bb 0.5 -bki 0 -p 0.1 $curveSel;
    select $curveSel;
}

Now it seems building the surface cannot be setup so easily:
CODE
{
    string $curveSel[] = filterExpand -sm 9;
    planarSrf -ch 0 -d 3 -ko 0 -tol 0 -rn 0 -po 1 $curveSel;
    select $curveSel;
}
it can be performed this way, but at the first look it seems you have to adjust the Initial Tessellation Controls by yourself. I set U and V type to "Per Span # of Iso Params" and 10.

Now here is rayIntersect for Maya 7 (I have to admit feel bad about giving this around this way. But seems the autor didn't update it for Maya7 by now. This is still the one compiled by Naughty! credits to him too!). Its sometimes a bitch. If it refuses to work set it to autoload and restart maya.

rayIntersect always works with centimeters: so here a little helper:
CODE
global proc float toCm(float $curUnitValue)
{
     string $unit = currentUnit -query -linear;
     string $curUnitValueString = $curUnitValue;
     string $centimeterString = convertUnit -fromUnit $unit -toUnit "cm" $curUnitValueString;
     return substitute("cm", $centimeterString, "");
}

and now the fun part:
CODE
{
    int $count = 1600;
    string $polySel[] = filterExpand -sm 12;
    if (size($polySel))
    {
        float $bboxMin[] = getAttr ($polySel[0] + ".boundingBoxMin");
        float $bboxMax[] = getAttr ($polySel[0] + ".boundingBoxMax");
        int $i;
        int $hit = 0;
        for ($i = 0; $i < $count; $i += $hit)
        {
            $hit = 0;
            float $rPosX = rand($bboxMax[0], $bboxMin[0]);
            float $rPosZ = rand($bboxMax[2], $bboxMin[2]);
            if (rayIntersect -ip (toCm($rPosX)) 100 (toCm($rPosZ)) -di 0.0 -1.0 0.0 -q -i1 $polySel[0])
            {
                $hit = 1;
                spaceLocator -p $rPosX 0 $rPosZ;
                // refresh;
            }
        }
    }
}

uncomment // refresh; to see it place the locators on your surface instantly

I mean .. this is all messed up but put into a little UI and streamline it a little this can be as simple as a buttonclick.


1600 locators in curve. took less than 3 seconds.

nice. Try not to rebuild and use this to extrude, its quick hack, but dont rebuild the curve!

CODE
{
$item=extrude -ch true -rn true -po 1 -et 0 -upn 1 -length 1 -rotation 0 -scale 1 -dl 3;
$tess=listHistory -f 1 ($item[1]);

setAttr ($tess[1]+".explicitTessellationAttributes") 1;
setAttr ($tess[1]+".uNumber") 1;
setAttr ($tess[1]+".vNumber") 1;
setAttr ($tess[1]+".useChordHeight") 1;
setAttr ($tess[1]+".chordHeight") 0.01;
setAttr ($tess[1]+".useChordHeightRatio") 0;

PolySelectConvert 1;

$size=size(ls -sl -fl);
polyCloseBorder -ch 1 $item[0];
delete ($item[0]+".f[0:"+$size+"]");
//polyNormal -normalMode 0 -ch 1 ($item[0]+".e[*]");//for maya 8
polyExtrudeFacet -ltz 1 ($item[0]+".f[0]");
}

Anyway you can adjust the tesselation attribs a bit! ide a is tu sue the cord height to define tesselation instad of anything else so even facetted surfs would tesselate properly.

PS aarggh they have made the presets for polyextrude simpler in maya 8... so you can no longer set the local translates preset in the options menu! So no longer clikety click autoextrude theese 1.2 units and g form the gui. I think the entire poly menuset is a PR disaster.

what a pity :[
DARN! know what ad I just see on top of the page: "Changing the face of 3D" How does that fit?
btw autodesk: I hate your ugly little dragon-icon! Ugly-dragon-icon does not look like maya! And will never do!

But back to the topic: The plugin isn't compiled for Maya8 anyhow.
And why not rebuild? rebuild no good?

ahhh! I see, you can set the attribs after the modifier has been created.

Yes but i reextrude the face since thisway i get less polycount!