Math.random() generates a number in [0;1[
so Math.random() * (0.4 - 0.2) + 0.2 would result in a value in the
range [0.2;0.4[
Cheers
Kai
Am 14.03.2006 um 15:29 Uhr haben Sie geschrieben:
> Hi,
>
> thanks a lot. It's working like a charm now. Since I'm using nulls as
> parents for my book geometry, I could get away with a much easier
script:
>
> // align books in x with a specified distance
> function AlignObjectsX(objects, distance)
> {
> for (i=0; i<objects.Count-1; i++)
> {
> objects(i+1).Kinematics.Local.Parameters("posx").value =
> objects(i).Kinematics.Local.Parameters("posx").value +
> objects(i).Kinematics.Local.Parameters("sclx").value + distance;
> }
> }
>
> AlignObjectsX(Selection, 0.2);
>
> I also tried to randomize the distance value but couldn't figure out
how
> to do it. It's not so important because it won't make a difference,
but
> just out of curiosity - how would I do that?
> I tried with RAND(0.2, 0.4) but that didn't work.
>
> Thanks a lot for your help,
> Chris
>
> Kai Wolter schrieb:
>
> > don't think it works with expressions because you would need them in
> > both directions and that will lead to a circle.
> > but i liked the task, so here are a few helper functions:
> >
> > // align books in x with a specified distance
> > function AlignObjectsX(objects, distance)
> > {
> > for (i=0; i<objects.Count-1; i++)
> > {
> > //xmin, ymin, zmin, xmax, ymax,
> > zmax col1 = GetBBox (objects(i) , false, null, null, null,
> > null, null, null );
> > col2 = GetBBox (objects(i+1) , false, null, null, null, null,
> > null, null );
> > objects(i+1).Kinematics.Global.Parameters( "posx" ).Value =
> > col1(3) + (col2(3) - col2(0))/2 + distance;
> > }
> > }
> >
> > // align books in y
> > function AlignToObjectY(objects, object)
> > {
> > col = GetBBox (object, false, null, null, null, null, null, null
);
> > for (i=0; i<objects.Count; i++)
> > {
> > col2 = GetBBox (objects(i) , false, null, null, null, null,
> > null, null );
> > objects(i).Kinematics.Global.Parameters( "posy" ).Value =
> > objects(i).Kinematics.Global.Parameters( "posy" ).Value +
> > object.Kinematics.Global.Parameters( "posy" ).Value - (col2(1) -
col(1));
> > }
> > }
> >
> > // sample scene
> > CreatePrim("Cube", "MeshSurface", null, null);
> > Scale(null, 9.47775628626693E-02, 1, 1, siRelative, siLocal, siObj,
> > siXYZ, null, null, null, null, null, null, null, 0);
> > Scale(null, 1, 1, 0.720870034294196, siRelative, siLocal, siObj,
> > siXYZ, null, null, null, null, null, null, null, 0);
> > Duplicate("cube", null, siDuplicateHistory, siSharedParent,
> > siShareGrouping, siDuplicateProperties, siDuplicateAnimation,
> > siShareConstraints, siSetSelection, siApplyRepeatXForm, null, null,
> > null, null, null, null, null, null, null, null,
> > siDuplicateSelectedTextureSupports);
> > Scale(null, 2.08001760680689, 1, 1, siRelative, siLocal, siObj,
siXYZ,
> > null, null, null, null, null, null, null, 0);
> > Duplicate("cube1", null, siDuplicateHistory, siSharedParent,
> > siShareGrouping, siDuplicateProperties, siDuplicateAnimation,
> > siShareConstraints, siSetSelection, siApplyRepeatXForm, null, null,
> > null, null, null, null, null, null, null, null,
> > siDuplicateSelectedTextureSupports);
> > Scale(null, 0.709690205494565, 1, 1, siRelative, siLocal, siObj,
> > siXYZ, null, null, null, null, null, null, null, 0);
> > Scale(null, 1, 1.11605415860735, 1, siRelative, siLocal, siObj,
siXYZ,
> > null, null, null, null, null, null, null, 0);
> > DeleteObj("cube2");
> > SelectObj("cube,cube1", null, true);
> > SelectObj("cube1", null, true);
> > Duplicate("cube1", null, siDuplicateHistory, siSharedParent,
> > siShareGrouping, siDuplicateProperties, siDuplicateAnimation,
> > siShareConstraints, siSetSelection, siApplyRepeatXForm, null, null,
> > null, null, null, null, null, null, null, null,
> > siDuplicateSelectedTextureSupports);
> > Scale(null, 1.49986352670082, 1, 1, siRelative, siLocal, siObj,
siXYZ,
> > null, null, null, null, null, null, null, 0);
> > SelectObj("cube1", null, true);
> > Scale(null, 1, 2.29980657640232, 1, siRelative, siLocal, siObj,
siXYZ,
> > null, null, null, null, null, null, null, 0);
> > SelectObj("cube2", null, true);
> > Scale(null, 1, 0.686653771760155, 1, siRelative, siLocal, siObj,
> > siXYZ, null, null, null, null, null, null, null, 0);
> > DeselectAll();
> > SelectObj("cube", null, null);
> > ToggleSelection("cube1", null, null);
> > ToggleSelection("cube2", null, null);
> >
> > AlignObjectsX(Selection, 1.5);
> > AlignToObjectY(Selection, Selection(0));
> >
> >
> > Cheers,
> > Kai
> >
> > Christian Götzinger schrieb:
> >
> >> Hi List,
> >>
> >> I also posted this on XSIBase but seeing as this mailing list is
> >> probably the best place to get answers to technical questions, here
> >> goes:
> >>
> >> I'm in the process of creating several bookshelves filled with
books.
> >>
> >> I have created one book which I'm going to duplicate off many
times.
> >> Basically, I've parented that one book to a null and I'm using the
> >> null to scale the book up and down. This way I can lateron
randomize
> >> the sizes of all my books very easily.
> >>
> >> Now, what I'd like to do is for XSI to align my books automatically
> >> next to each other.
> >> Here's my basic setup:
> >>
> >> BookP1 (Null) -> Scale X = 5 -- Scale Y = 25 -- Scale Z = 15
> >> Child: Book1 (which is the actual book)
> >>
> >> To test things out I have duplicated the hierarchy to create BookP2
> >> and its child Book2
> >>
> >> I have set this expression on BookP2's local position X:
> >> Valid expression : BookP2.kine.local.posx =
> >> BookP1.kine.local.posx+BookP1.kine.local.sclx
> >>
> >> This works very well. If I scale BookP1 up in X, the second book
gets
> >> aligned automatically.
> >>
> >> Now my question: how can I generalize this expression so that it'll
> >> be valid for all books once I've mass duplicated them?
> >>
> >> I'm not into scripting or anything, so this may seem like a piece
of
> >> cake to you
> >>
> >> Thanks,
> >> Chris
> >
> >
> >
> >
> >
> > ---
> > Unsubscribe? Mail <a
href='email_neu.php?writeTo=Majordomo(at)Softimage.COM'>Majordomo(at)Softimage.COM</a>
with the following text in
> > body:
> > unsubscribe xsi
> >
> >
>
>
>
> ---
> Unsubscribe? Mail <a
href='email_neu.php?writeTo=Majordomo(at)Softimage.COM'>Majordomo(at)Softimage.COM</a>
with the following text in body:
> unsubscribe xsi
>
>
>
>
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi