
! script name: surfaces.d/foursidecubic
! 3dtopic: construct a four sided cubic surface

!A
!A NAME:
!A
!A 	Bicubic: Four Sides
!A
!A DESCRIPTION:
!A
!A 	This script will construct a four sided cubic surface.  There must be
!A 	four sides which intersect is 3D space.  The four sided surface formed
!A 	may be thought of as a rubber rectangle in 2D space that has been
!A 	stretched, pushed, and pulled.
!A
!B INSTRUCTIONS:
!B
!B 	PICK U CONTOUR #1, Point: Pick one of the sides
!B 		to be used to determine the U curves.
!B
!B 	INPUT U CORNER POINT #1 ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as a corner.
!B
!B 	PICK U CONTOUR #2, Point: Pick the other side to
!B 		be used to determine the U curves.  The U
!B 		contour #1 and the U contour #2 may NOT
!B 		be adjacent sides.
!B
!B 	INPUT U CORNER POINT #2 ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as a corner.
!B
!B 	PICK V CONTOUR #1, Point: Pick one of the sides to
!B 		be used to determine the V curves.  The U and V
!B 		contours may NOT be the same.
!B
!B 	INPUT V CORNER POINT #1 ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as a corner.
!B
!B 	PICK V CONTOUR #2, Point: Pick the other side to be
!B 		used to determine the V curves.  The V contour #1
!B 		and the V contour #2 may NOT be adjacent sides.
!B
!B 	INPUT V CORNER POINT #2 ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as a corner.
!B
!B 	U PATCH WIDTH: Enter the patch width to be used for
!B 		the U curves.
!B
!B 	V PATCH WIDTH: Enter the patch width to be used for
!B 		the V curves.
!B
!C NOTES:
!C
!C 	Only one corner may be a point.
!C
!C 	Problems may occur from over patching.  Avoid over patching by giving
!C 	patch widths appropriate to the sections.  Remember, the patch widths
!C 	for U and V do not have to be the same.  When a corner point is used,
!C 	the patches converge at that point.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: four sided cubic blend ")

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

ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)

Upatch=Patch_width
Vpatch=Patch_width

Stat=SetInputFormat("n4","")
Pick_loop: !

Stat=SetPickMask(WsPickNoSurf)

Pick_u1:Stat=SetInputFormat("a1",",P,")
UContour1=PickEntity("PICK U CONTOUR #1, Point",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN
	UPt1=XyzInput("INPUT U CORNER POINT #1",WsXyzInput)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetLastPoint(UPt1,WsXyzInput)
	UContour1=UPt1
ELSE
	IF NOT ValidContourEnt(UContour1) THEN Pick_u1
	G1= ParentGroup(UContour1,0)
	IF ValidGeometry(G1) THEN UContour1= G1
END IF
IF NOT ValidGeometry(UContour1) THEN Pick_u1
Stat=Highlight(UContour1,WsPickPen,WsDirArrowOff)

Pick_u2:Stat=SetInputFormat("a1",",P,")
UContour2=PickEntity("PICK U CONTOUR #2, Point",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN
	UPt2=XyzInput("INPUT U CORNER POINT #2",WsXyzInput)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetLastPoint(UPt2,WsXyzInput)
	UContour2=UPt2
ELSE
	IF NOT ValidContourEnt(UContour2) THEN Pick_u2
        G1= ParentGroup(UContour2,0)
        IF ValidGeometry(G1) THEN UContour2= G1
END IF
IF NOT ValidGeometry(UContour2) THEN Pick_u2
Stat=Highlight(UContour2,WsPickPen,WsDirArrowOff)

Pick_v1:Stat=SetInputFormat("a1",",P,")
VContour1=PickEntity("PICK V CONTOUR #1, Point",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN
	VPt1=XyzInput("INPUT V CORNER POINT #1",WsXyzInput)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetLastPoint(VPt1,WsXyzInput)
	VContour1=VPt1
ELSE
	IF NOT ValidContourEnt(VContour1) THEN Pick_v1
        G1= ParentGroup(VContour1,0)
        IF ValidGeometry(G1) THEN VContour1= G1
END IF
IF NOT ValidGeometry(VContour1) THEN Pick_v1
Stat=Highlight(VContour1,WsPickPen,WsDirArrowOff)

Pick_v2:Stat=SetInputFormat("a1",",P,")
VContour2=PickEntity("PICK V CONTOUR #2, Point",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN
	VPt2=XyzInput("INPUT V CORNER POINT #2",WsXyzInput)
	IF ExitScript(Destination$) THEN Leave
	Stat=SetLastPoint(VPt2,WsXyzInput)
	VContour2=VPt2
ELSE
	IF NOT ValidContourEnt(VContour2) THEN Pick_v2
        G1= ParentGroup(VContour2,0)
        IF ValidGeometry(G1) THEN VContour2= G1
END IF
IF NOT ValidGeometry(VContour2) THEN Pick_v2
Stat=Highlight(VContour2,WsPickPen,WsDirArrowOff)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Upatch)
Upatch=GetValue("U PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Vpatch)
Vpatch=GetValue("V PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Surf=FourCurveSurf(WsCubicSurfEnt,UContour1,UContour2,VContour1,Vcontour2,Upatch,Vpatch)

ActivateUndo
Stat= AdvanceUndoNumber("bicubic surface")
Stat= AddItemToUndo(WsUBCreateMode,Surf)

Stat=DeleteEntity(UPt1)
Stat=DeleteEntity(UPt2)
Stat=DeleteEntity(VPt1)
Stat=DeleteEntity(VPt2)

GOTO Pick_loop

Leave:!
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(UPt1)
Stat=DeleteEntity(UPt2)
Stat=DeleteEntity(VPt1)
Stat=DeleteEntity(VPt2)
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
