Jump to content
Developer Wiki and Function Reference Links ×

Random dimension in-between 2 values


pixel2

Recommended Posts

  • 1 month later...
  • 1 year later...

Try this. Note that is scales the object around the 3D center. If you need the bottoms to stay in place I will have to give it some more thought.

Procedure RandomScaleSelected;

Var H1: Handle;
   R1: Real;
   X1,Y1,Z1  :Real;

Begin
 H1:=FSActLayer;
 While H1<>Nil do
   Begin
     R1:=Random*4/10+0.6;
     Get3DCntr(H1,X1,Y1,Z1);
     HScale3D(H1,X1,Y1,Z1,R1,R1,R1); 
     H1:=NextSObj(H1);
   End;
RedrawAll;
End;

Run(RandomScaleSelected);

Link to comment

I tried the same thing. It works well when the extrudes are perpendicular to the ground plane, but It doesn't work with rotated extrudes that aren't perpendicular to the ground plane (check the attach).

Edited by Mr. Gog
Link to comment

Send me a file with a sample of the extrudes that don't scale. Either post it here or email it directly to me and I will take a look and see what I can do.

What do you want varied? Height or area and height? Do you want the bases to stay in place (scale around the 3D Center) or something else?

Link to comment

These are the needed things:

1. Scale Area

2. Around the center

3. Scale other shapes. no only extrudes.

The example was obtained with duplicate along path.

The cylinders (extrudes) need to be scaled. The example contains cylinders forms, but could be another shape.

Thanks!!

Edited by Mr. Gog
Link to comment

If you replace HScale3D() with the following procedure, you will be able to scale 3D objects in place, even if they are rotated.

Raymond

procedure ScaleIt3D(H :Handle; X, Y, Z, SF :Real);
{ Scale a 3D object by scale factor SF around point (X, Y, Z) }
Var
mirror :Boolean;
Xrot, Yrot, Zrot :Real;
Begin
if Get3DOrientation(H, Xrot, Yrot, Zrot, mirror) then begin
	{ unrotate it }
	Set3DRot(H, 0, 0, -Zrot, X, Y, Z);
	Set3DRot(H, 0, -Yrot, 0, X, Y, Z);
	Set3DRot(H, -Xrot, 0, 0, X, Y, Z);

	{ scale it }
	HScale3D(H, X, Y, Z, SF, SF, SF);		

	{ re-rotate it }
	Set3DRot(H,?Xrot, Yrot, Zrot, X, Y, Z);
end;		{ if }
End;		{ ScaleIt3D }

Link to comment

Thanks Raymond. Thanks Pat.

This is the working script:

{FROM HERE}

Procedure RandomScaleSelected;

Var

H1: Handle;

R1: Real;

X1,Y1,Z1 :Real;

xr, yr, zr :Real;

mrr :Boolean;

Begin

H1:=FSActLayer;

While H1<>Nil do

Begin

R1:=Random*4/10+0.6;

if Get3DOrientation(H1, xr, yr, zr, mrr)then begin

Get3DCntr(H1,X1,Y1,Z1);

Set3DRot(H1, 0, 0, -zr, X1, Y1, Z1);

Set3DRot(H1, 0, -yr, 0, X1, Y1, Z1);

Set3DRot(H1, -xr, 0, 0, X1, Y1, Z1);

HScale3D(H1,X1,Y1,Z1,R1,R1,R1);

Set3DRot(H1,?xr, yr, zr, X1, Y1, Z1);

H1:=NextSObj(H1);

End;

End;

RedrawAll;

End;

Run(RandomScaleSelected);

{TO HERE}

Edited by Mr. Gog
Link to comment

Mr. Gog,

You are going to run into trouble if Get3DOrientation() ever fails. In such a case, your code will never move to the next object and will wind up in an endless loop. You need to put

H1:=NextSObj(H1);

outside the IF statement and place it as the last statement in the WHILE loop.

Raymond

PS - Why did you create inline code and not use a user defined function? For small programs such as this, it's not a real issue, but as soon as you get up to 50 lines or more, user defined procedures and function will make the main body of your code read much more easily.

In the following example, the main routine becomes 3 lines inside the WHILE loop: generate a random number, scale the object by that number, get the next selected object. In a year or two, which version of the script do you think will be easier to read?

Procedure RandomScaleSelected;

{ Scale selected 3D objects by a random factor between 0.6 and 1.0 }

Var

???H1: Handle;

???R1: Real;

???procedure ScaleIt3D(H :Handle; SF :Real);

???{ Scale a 3D object around its center by scale factor SF. }

???Var

??????mirror :Boolean;

??????X, Y, Z, Xrot, Yrot, Zrot :Real;

???Begin

??????if Get3DOrientation(H, Xrot, Yrot, Zrot, mirror) then begin

?????????Get3DCntr(H1, X, Y, Z);?????????????????????{ Get 3D center }

?????????Set3DRot(H, 0, 0, -Zrot, X, Y, Z);????????{ unrotate it }

?????????Set3DRot(H, 0, -Yrot, 0, X, Y, Z);

?????????Set3DRot(H, -Xrot, 0, 0, X, Y, Z);

?????????HScale3D(H, X, Y, Z, SF, SF, SF);???????{ scale it }

?????????Set3DRot(H,?Xrot, Yrot, Zrot, X, Y, Z);???{ re-rotate it }

??????end;??????{ if }

???End;??????{ ScaleIt3D }

Begin

???H1 := FSActLayer;

???While (H1<>Nil) do Begin

??????R1 := Random * 0.4 + 0.6;

??????ScaleIt3D(H1, R1);

??????H1 := NextSObj(H1);

???End;

???RedrawAll;

End;

Run(RandomScaleSelected);

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...