
! script name: parasolids.d/threefaceblend
! solids: create a blend between three faces.

!A
!A NAME:
!A
!A 	Three Face Blend
!A
!A~ image location - images/pkthreefaceblend.gif
!A DESCRIPTION:
!A
!A 	This script creates a blend between three faces. 	
!A
!A
!B INSTRUCTIONS:
!B
!B	PICK LEFT FACE: Pick the left face.
!B
!B	PICK CENTER FACE: pick the center face.
!B
!B	PICK RIGHT FACE: pick the right face.
!B
!B	PICK GUIDE ENTITY:  Contour pick the guide entity or contour.
!B
!B NOTES:
!B
!B	This script creates a blend surface between three faces. 
!B	The blend surface is created by generating planes normal to the
!B	guide entity, each plane then intersects the faces in three curves.
!B	The blend surface is then generated by circles created tangent to
!B	the three curves and lying in the normal plane.
!B
!B      If the faces come from different sheet bodies then the sheet
!B      normals must be oriented before using this script.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: three face blend ")

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

ActivateUndo
Stat= GLPlotOn

IF ARGC> 1 THEN
        Propagate= VAL(ARGV(1))
ELSE
	Propagate= WsTrue  ! propagate blend
END IF


Start:!
Right_color= 3
Center_color= 4
Left_color= 5

Left_face:!
Stat=SetInputFormat("n0","")
E1=WPKPickEntity("PICK LEFT FACE",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

UVpoint=LastUVSurfPick(E1)
IF ValidGeometry(UVpoint) THEN 
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)
P1= SurfParameterPt(E1,U,V)
Stat= SetColor(P1,Left_color,WsTrue)
END IF

Center_face:!
Stat=SetInputFormat("n0","")
E2=WPKPickEntity("PICK CENTER FACE",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

UVpoint=LastUVSurfPick(E2)
IF ValidGeometry(UVpoint) THEN
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)
P2= SurfParameterPt(E2,U,V)
Stat= SetColor(P2,Center_color,WsTrue)
END IF

Right_face:!
Stat=SetInputFormat("n0","")
E3=WPKPickEntity("PICK RIGHT FACE",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

UVpoint=LastUVSurfPick(E3)
IF ValidGeometry(UVpoint) THEN 
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)
P3= SurfParameterPt(E3,U,V)
Stat= SetColor(P3,Left_color,WsTrue)
END IF

Pick_guide:Delete_axis=0
Stat=SetInputFormat("a1=",",C,")
Guide=PickEntity("PICK GUIDE ENTITY:  Contour", Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "C" THEN
Pick_contour:!
	Guide=PickGroupEnt("PICK GUIDE CONTOUR ")
	IF (ExitScript(Destination$)) THEN Leave
END IF


Make_blend:!
WPKClearErrorFlag
Stat= WPK3FaceBlend(E1,E2,E3,Guide)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)

ActivateUndo
Stat= AdvanceUndoNumber("three face blend")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Start


Leave:!
Stat=SetInputFormat("n4","")
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
