
! script name: 3dmacros.d/randomsurface
! EXAMPLE: construct nurb surface on a grid of random points

!A
!A NAME:
!A
!A 	Random Surface
!A
!A DESCRIPTION:
!A
!A 	This script constructs a nurb surface on a grid of random points.
!A
!B INSTRUCTIONS:
!B
!B 	LENGTH: Length of grid rectangle
!B
!B 	WIDTH: Width of grid rectangle
!B
!B 	HEIGHT: Height of grid rectangle
!B
!B	NUMBER OF POINTS IN A ROW: Enter the number of points in a row.
!B
!B 	NUMBER OF ROWS OF POINTS: Enter the number of rows of points.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: random surface ")

DIM Answer$[256]
DIM Destination$[256]
DEG

ActivateUndo
Group_loop:!
Group=CreateGroup("TEMPGROUP")
Pt_count=1

Stat=SetInputFormat("n4","")

Stat= SetInputFormat("n4","")

Xlen=GetValue("LENGTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Ylen=GetValue("WIDTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Height=GetValue("HEIGHT",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Numx=GetValue("NUMBER OF POINTS IN A ROW",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Numy=GetValue("NUMBER OF ROWS OF POINTS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Point_loop:!

DEG


Xcen= 0
Ycen= 0
Zcen= 0

Delx= Xlen/Numx
Dely= Ylen/Numy

FOR I=0 TO Numx
	FOR J= 0 TO Numy

	X= I*Delx
	Y= J*Dely
	Z= Height*RND

        Pt=PointXYZ(X,Y,Z)
        Stat=AddToGroup(Group,Pt)
        Pt_count=Pt_count+1
	NEXT J
NEXT I

surf= GridSurface(WsNurbSurfEnt,Group,"HELICAL SURF",(Numy+1),(Numx+1))

ActivateUndo
Stat= AdvanceUndoNumber("nurb surf")
Stat= AddItemToUndo(WsUBCreateMode,Surf)

stat= DeleteGroup(Group,1)

Leave:!
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

