
! script name: vpksolids.d/vpkthreefaceblend
! var_solids: create a blend between three faces.

!A
!A NAME:
!A
!A 	Three Face Blend  VARIATIONAL
!A
!A~ image location - images/pkthreefaceblend.gif
!A
!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 thre 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
!B	The face orient flags can have the values 0,1 and 2 for
!B	unknown, before and behind the face. These will only produce
!B	different results when the faces come from different sheet bodies.
!B
!# see also - htdocs/help.d/parasolids.htm

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Bodyname$[256]
DIM Face1$[256]
DIM Face2$[256]
DIM Face3$[256]
DIM Guide$[256]

ActivateUndo
Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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
Stat= EntityNameCheck(E1,Face1$)
Bodyname$= WPKBodyName(E1)

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
Stat= EntityNameCheck(E2,Face2$)

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
Stat= EntityNameCheck(E3,Face3$)

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
	Stat= EntityNameCheck(Guide,Guide$)
END IF
Stat= EntityNameCheck(Guide,Guide$)


Make_blend:!
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)


WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BLEND: three face blend")
V1= FreeParameter("Propagate on",1)
V2= FreeParameter("Left face orient",1)
V3= FreeParameter("Center face orient",1)
V4= FreeParameter("Right face orient",1)
Stat= WPK3FaceBlend(Face1$,Face2$,Face3$,Guide$,V2,V3,V4,1)
Stat= WPKNameBody(Bodyname$,Bodyname$)
Stat= WPKSetBodyParent(Bodyname$,1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("three face blend")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
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
