The Perfect Capsule

Hey Hello!

I was following this thread: polyUnite (or combine) and Scaling -> need help

We need to have capsules in Maya as well. ODE has capsules as physics primitives and we want to have appropiate placeholders in Maya to arrange them for the export. Currently there are just cylinders that represent the capsules, but if there is a cool implementation.. why not replace them with nice and smart capsules?

I did a different approach before: I use expressions on 2 Spheres that are children of a Cylinder.

CODE
{
    string $cylinder[] = polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 0;
    string $sphere1[] = polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 0;
    string $sphere2[] = polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 0;
    parent $sphere1[0] $sphere2[0] $cylinder[0];
    setAttr ($sphere1[0] + ".ty") 1;
    setAttr ($sphere2[0] + ".ty") -1;
    expression -s ($sphere1[0] + ".scaleY = 1/" + $cylinder[0] + ".scaleY * " + $cylinder[0] + ".scaleX")  -o $sphere1[0] -ae 1 -uc all;
    expression -s ($sphere2[0] + ".scaleY = 1/" + $cylinder[0] + ".scaleY * " + $cylinder[0] + ".scaleX")  -o $sphere2[0] -ae 1 -uc all;
    expression -s ($cylinder[0] + ".scaleZ = " + $cylinder[0] + ".scaleX")  -o $cylinder[0] -ae 1 -uc all;
    int $sjNr = scriptJob -event SelectionChanged ("redirectSelection {\"" + $sphere1[0] + "\", \"" + $sphere2[0] + "\"} " + $cylinder[0]);
    print ("$sjNr: " + $sjNr + "\n");
}

global proc redirectSelection(string $objects[], string $target)
{
    string $sel[] = ls -sl;
    string $x;
    string $object;
    for ($x in $sel)
    {
        for ($object in $objects)
        {
            if ($object == $x)
            {
                select -d $object;
                select -add $target;
            }
        }
    }
}

  1. Now there is that scriptjob, that checks the selection for the spheres and redirects it to the cylinder... feels ok for now, but that scriptjob of course is not part of the scene, is it? Can I attach this funktion somehow to my scene?

  2. Capsules in ODE cannot be scaled in X and Y differently, so I locked the scaleZ to the scaleX with another expression. If I now grab the red scaleX modifier and drag everything is cool, but of course I can't touch the blue for scaleY anymore... can this be achieved somehow else?

  3. I played around a little with the bool function: I can bool that shit together and but the expressions on the groups that remain from the booling.
    + This results in just ONE selectable object whats more handy than the above approach.
    - Unfortunately its a lot slower because of the on-the-fly-bool-calculation I guess.
    - And: I have these darn 2 Groups (have to bool twice!) that hang around in the outliner that I can't parent somewhere without destroing the scale calculation.
    I could do ca combine as well! Guess thats faster and I could delete some faces too...

Ahhh! I did the extrude approach described by Joojaa a little different:

CODE
{
    string $sph[0] = polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 0;
    string $extr1[0] = polyExtrudeFacet -ch 1 -kft 1 -pvy 1 -ty 1   ($sph[0] + ".f[180:359]") ($sph[0] + ".f[380:399]");
    string $extr2[0] = polyExtrudeFacet -ch 1 -kft 1 -pvy -1 -ty -1 ($sph[0] + ".f[0:179]")   ($sph[0] + ".f[360:379]");
    expression -s ($extr1[0] + ".scaleY = 1/" + $sph[0] + ".scaleY * " + $sph[0] + ".scaleX")  -o $extr1[0] -ae 1 -uc all;
    expression -s ($extr2[0] + ".scaleY = 1/" + $sph[0] + ".scaleY * " + $sph[0] + ".scaleX")  -o $extr2[0] -ae 1 -uc all;
    expression -s ($sph[0] + ".scaleZ = " + $sph[0] + ".scaleX")  -o $sph[0] -ae 1 -uc all;
    transformLimits -sx 0 1 -esx 1 0 $sph[0];
    transformLimits -sy 0 1 -esy 1 0 $sph[0];
}

For sure: So far the smartest solution...
- I have that 2 extrudes (but ... pff who cares?)
- there is an extra ring in the middle of the capsule (yaawn .. any news?)
+ Questions 1. and 2. are slayed with this.
- Question 2. is still alive!

tesetd this it works! Just didnt bother to do a scruipt out of it.

make a nurbs circle ajust its creaton parameters so its in the orientation you need the default capsule to start at. offset it by 0.5 upwards using its center attribute!

Make a new shape pipe the same create to thet shape make the tarsform negative on one axis.

make a linear curve that snaps to both circles endpoints. attach them (you may wish to delete the extra sshape thets created between attach 1 and 2 in hypershade). revoleve this curve.

Now 1/capsule.scale withe a multiply divide node the scale to your full curve.connect scale AND to the linear segments scatle (the firts thpet os counterscale by the way). connect scale y multiplied by 0.5 to the center y of your protocircle reator, scale x to its radius.

then connect scale x to scale y lock scale y and hide it for the view.

If you have succeded right, or i have succeded in telling the right sequence of affairs. you now have a capsule that retains behaves well to scale and your doing it all you just wished.

With NO scriptjobs or anything esle thats nasty.

MArk shaoes intermediate and hide the extra transforms somewhere handy.

But yeh the extrude thing can also be counterscaled to suit the need i didnt realy sit and thinkof the real need, but the longer way i described can now adjust the amount of segments as needed. Wich was what i needed

But yeah the extrude works just as long as you dont change spans.

haahaa... i can get it to work but as soon as i save it bacng maya crahses, blim must further ivestigate. uuh ooh it does thsi on aempty scene too... Something funkys going on! Yes well its was private joke took 10 minutes of my life away.

But yeah it can be done works fine interactively inside maya. And yes z is free to do something else.

okay still no time to mellify this but... hees a sample file that refined to only have 1 Shape. Note scale Z is free to use for something esle it des not affect scale at all. Note understanding matrices is of help to decipher thione.

capsule.zip (~7kb 7.0 ma file)

uh oh! The link was fcked somehow.. But I made a / out of the ( and it worked..

multiplyDevide?!
fourByFourMatrix?!?
..
Yea I don't get it

but locking/hiding is a cool Idea, better than just leaving it blue.
what do you think about this:

CODE
{
    string $sph[0] = polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 0;
    string $ex1[0] = polyExtrudeFacet -ch 1 -kft 1 -pvy 1 -ty 1   ($sph[0] + ".f[180:359]") ($sph[0] + ".f[380:399]");
    string $ex2[0] = polyExtrudeFacet -ch 1 -kft 1 -pvy -1 -ty -1 ($sph[0] + ".f[0:179]")   ($sph[0] + ".f[360:379]");
    expression -s ($ex1[0] + ".sy = 1/" + $sph[0] + ".sy * " + $sph[0] + ".sx")  -o $ex1[0] -ae 1 -uc all;
    expression -s ($ex2[0] + ".sy = 1/" + $sph[0] + ".sy * " + $sph[0] + ".sx")  -o $ex2[0] -ae 1 -uc all;
    expression -s ($sph[0] + ".sz = " + $sph[0] + ".sx")  -o $sph[0] -ae 1 -uc all;
    transformLimits -sx 0.001 1 -esx 1 0 $sph[0];
    transformLimits -sy 0.001 1 -esy 1 0 $sph[0];
    setAttr -lock true -keyable false ($sph[0] + ".sz");
    select $sph[0];
}

I limited the scaleX and Y to 0.001 so it can't look odd in negative scale and doesn't stuck when scaled down to zero.

but: why is it that I have a time node in my history stack?! If I cut it from my expressions it works anyway.. .nah Its cool like it is, thanks a real lot! :]

your .ma example turns black if scaled big... why is that?

QUOTE(ewerybody @ 02/03/06, 07:10 PM) [snapback]227255[/snapback]
your .ma example turns black if scaled big... why is that?

No idea? Does not do for me whats real big? yeah i frixed the link.

2 aswers first time, well it does not realy matter what time you use if you dont specify your allwauys using teh default time. BUt having a extra time node can be usefull, you can remap the time. theres allways one time in your scene.

fourByFourMatrix well yes the trick here is to make sure scale does not come into play. So if you scale the object up by A then mutiply that scaling factor by 1/A then no scaling will occour. Now this frees me to use the scaling for something else such as controlling the extrusion depths, and radius instead of actualy scaling the object in question. So no ovel endings nomatter how you scale. Theres s slight numeric inprecicion here but...

The data is just packed to the matrix
CODE
1/a 0  0  0
0 1/a  0  0
0  0  1/a 0
0  0   0   1

this defines the counterscaling, i use matrix directly because trasform geometry wants a matrix as input. BUt unlike in a freezei need a adaptive one.

note countering rotation isnt as easy bot dooable, traslate is easyttough but a full movement combo isnt. Thing is this can be used fro all sorts of proceduralgeometries such as wheels and so on.