# Duplicate Objects Inside Of Curve

**URL:** https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953
**Category:** Maya
**Tags:** mel
**Created:** [August 9, 2006, 6:01pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953 "2006-08-09T18:01:38Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![3dimentia](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/3/7cd45c/32.png) [@3dimentia](https://forum.highend3d.com/u/3dimentia)
#### Post date: [August 9, 2006, 6:01pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/1 "2006-08-09T18:01:38Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 9, 2006, 8:12pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/2 "2006-08-09T20:12:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![3dimentia](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/3/7cd45c/32.png) [@3dimentia](https://forum.highend3d.com/u/3dimentia)
#### Post date: [August 9, 2006, 10:45pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/3 "2006-08-09T22:45:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 10, 2006, 6:59am UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/4 "2006-08-10T06:59:14Z")

</div>

Sure but its expensive like hell!

But tell me again how is a curve defining volume?

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [August 11, 2006, 7:58am UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/5 "2006-08-11T07:58:27Z")

</div>

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 ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/smile.gif)

---

<div class="post-metadata">

### Author: ![3dimentia](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/3/7cd45c/32.png) [@3dimentia](https://forum.highend3d.com/u/3dimentia)
#### Post date: [August 12, 2006, 2:16am UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/6 "2006-08-12T02:16:04Z")

</div>

ah just a simple closed 2D nurbs curve. I kind of gave up on this idea, as it was hurting my brain ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/wink.gif)

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 12, 2006, 7:10am UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/7 "2006-08-12T07:10:51Z")

</div>

QUOTE(ewerybody @ 08/11/06, 10:58 AM) [snapback]244861[/snapback]  
but .. i got no solution anyway ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/smile.gif)

Yes you do! just use the exact same code as your legoize but just for one layer ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/wink.gif)

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [August 12, 2006, 12:05pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/8 "2006-08-12T12:05:19Z")

</div>

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 ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/biggrin.gif)

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..

---

<div class="post-metadata">

### Author: ![ever-desperate](https://forum.highend3d.com/user_avatar/forum.highend3d.com/ever-desperate/32/54685_2.png) [@ever-desperate](https://forum.highend3d.com/u/ever-desperate)
#### Post date: [August 12, 2006, 7:06pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/9 "2006-08-12T19:06:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 13, 2006, 7:51pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/10 "2006-08-13T19:51:22Z")

</div>

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):

![](http://users.tkk.fi/~joojala2/highend/trisort.gif)

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

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [August 15, 2006, 1:57pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/11 "2006-08-15T13:57:11Z")

</div>

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  
{&nbsp;&nbsp; // to make the curve flat  
&nbsp;&nbsp;&nbsp;&nbsp;string $curveSel[] = `filterExpand -sm 9`;  
&nbsp;&nbsp;&nbsp;&nbsp;select ($curveSel[0] + ".cv[\*]");  
&nbsp;&nbsp;&nbsp;&nbsp;move -a -moveY 0;  
&nbsp;&nbsp;&nbsp;&nbsp;select $curveSel;  
}

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

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

Now it seems building the surface cannot be setup so easily:  
CODE  
{  
&nbsp;&nbsp;&nbsp;&nbsp;string $curveSel[] = `filterExpand -sm 9`;  
&nbsp;&nbsp;&nbsp;&nbsp;planarSrf -ch 0 -d 3 -ko 0 -tol 0 -rn 0 -po 1 $curveSel;  
&nbsp;&nbsp;&nbsp;&nbsp;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](http://mel.goodsoul.de/temp/rayIntersect.zip) (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)   
{   
&nbsp;&nbsp;&nbsp;&nbsp; string $unit = `currentUnit -query -linear`;   
&nbsp;&nbsp;&nbsp;&nbsp; string $curUnitValueString = $curUnitValue;   
&nbsp;&nbsp;&nbsp;&nbsp; string $centimeterString = `convertUnit -fromUnit $unit -toUnit "cm" $curUnitValueString`;   
&nbsp;&nbsp;&nbsp;&nbsp; return substitute("cm", $centimeterString, "");   
}

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

uncomment // refresh; to see it place the locators on your surface instantly ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/biggrin.gif)

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.

![](http://img125.imageshack.us/img125/4471/duplicatedobjectsincurvech8.gif)  
1600 locators in curve. took less than 3 seconds.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 15, 2006, 6:44pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/12 "2006-08-15T18:44:00Z")

</div>

![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/biggrin.gif) 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.

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [August 15, 2006, 11:16pm UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/13 "2006-08-15T23:16:12Z")

</div>

what a pity :[  
DARN! know what ad I just see on top of the page: "Changing the face of 3D" How does that fit? ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/biggrin.gif)  
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.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [August 16, 2006, 5:34am UTC](https://forum.highend3d.com/t/duplicate-objects-inside-of-curve/2953/14 "2006-08-16T05:34:46Z")

</div>

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