
! script name: 3drender.d/shadepart
! 3dtopic: shades a group of surfaces

!A
!A NAME:
!A
!A 	Fast Shading
!A
!A DESCRIPTION:
!A
!A 	This script shades a group of surfaces.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE GROUP, Colors: Pick the group of surfaces to be shaded.
!B
!B 		C - Colors sets a switch to shade the surfaces and will
!B 		return to this question for picking the surface group to be
!B 		shaded.
!B
!B 	RESOLUTION: Coarse, Medium, Fine, Extra fine:  The resolution only
!B 		pertains to the accuracy of tiling trimmed surfaces.  The plot
!B 		density can increase shading resolution.  Fine and Extra Fine
!B 		resolution may take a long time.
!B
!B 	IMAGE FILE NAME (MAX=10): Enter the name of the image to be used for
!B 		for storage purposes.  Maximum number of characters is 10.
!B
!C NOTES:
!C
!C 	Colors allows the surfaces to be shaded with a hue similar to the
!C 	original color described on the surface.  Do not use pen 0 - this
!C 	would produce a black image.
!C
!C 	There are 256 colors available in the system.  Many of the colors
!C 	are allocated to motif, the rest are allocated for shading.
!C 	Depending on the number of colors in the shaded image, pens will be
!C 	allocated accordingly.
!C
!C 	The image obtained may be improved by changing the shading tolerance
!C 	or the plot density.  If a tolerance is too small, shading will take
!C 	a very long time.  Changing the plot density may improve the image
!C 	especially on trimmed surfaces.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: shade part ")

DIM Destination$[256]
DIM Answer$[256]
DIM Jobname$[256]
DIM Jobname1$[256]
DIM Space$[20]
DIM Dir$[256]

DeActivateUndo
Space$=" "
Jobname$="shade"

Start:!

	Tol=NamedVarVal("3D Shade Tol",Ws3DSystemVars,0.06)

	StdWorkplane

Pick_loop:!

Pick_group:Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("a1",",C,S,")
Part_group=PickGroupEnt("PICK SURFACE GROUP, Surface, Colors ",WsSurfaceGroup,Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
        CASE "C"
                Stat=RaiseShade("data")
                GOTO Pick_loop
	CASE "S"
		GOTO Pick_surfaces
END SELECT
IF NOT ValidGeometry(Part_group) THEN Pick_loop
GOTO Ask_resolution

Pick_surfaces:!
	Surface_group= CreateGroup("SHADE TEMP",WsSurfaceGroup)
	Surf_count=1
Pick_surf_loop:!
	Stat=SetPickMask(WsPickSurfOnly)
	Stat=SetInputFormat("a1",",P,G,")
	Surface=PickEntity("PICK SURFACE #"&VAL$(Surf_count)&", Group, Proceed ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	IF Answer$="P" THEN 
		Part_group= Surface_group
		GOTO Ask_resolution
	END IF
	IF Answer$="G" THEN 
		Stat= DeleteEntity(Surface_group)
		GOTO Pick_group
	END IF
	IF NOT ValidGeometry(Surface) THEN Pick_surf_loop
	N1= ElementGrpNum(Surface_group,Surface)
	IF N1 THEN Pick_surf_loop
	Stat=AddToGroup(Surface_group,Surface)
	Stat=SetPickMask(WsPickAll)
	Surf_count= Surf_count+1
GOTO Pick_surf_loop


Ask_resolution:!
Vnum=LastPickView
! Stat=Highlight(Part_group,WsPickPen,WsDirArrowOff)
Stat=SetPickMask(WsPickGeometry)
Shade_res:!
	Stat=SetInputFormat("a1=",",C,M,F,E,")
        Stat=SetEqualsValue(0,"C")
        Stat=GetValue("RESOLUTION: Coarse, Medium, Fine, Extra fine",Answer$)
        IF ExitScript(Destination$) THEN Leave
	SELECT Answer$
	CASE "C"
		shade_res=WsCoarse
	CASE "M"
		shade_res=WsMedium
	CASE "F"
		shade_res=WsFine
	CASE "E"
		shade_res=WsExtraFine
	END SELECT

Question:!
        Stat=SetInputFormat("a99=","")
	Stat=SetEqualsValue(0,Jobname$)
        Stat=GetValue("IMAGE FILE NAME"&Space$&"(MAX= 10) ",Jobname$)
        IF ExitScript(Destination$) THEN Leave
        IF POS(Jobname$," ") THEN
                Space$=" (NO SPACES) "
                GOTO Question
        ELSE
                Space$=" "
        END IF
        IF LEN(Jobname$)>10 THEN Question
        IF LEN(Jobname$)=0 THEN Jobname$="shade"

	Stat=NamedVarStr("pics dir",WsSystemVars,"/usr/weber/ST/pics",Dir$)
	Jobname1$=FileNameString(Dir$,Jobname$)

Stat=Setup3dShade(Vnum,Tol)
Smooth=1

Pcenter=PointXYZ(0,0,0)
Axis_vector=PointXYZ(0,0,1)
Angle=5

Stat=ShadePart(Jobname1$,Part_group,Smooth,Shade_res,WsAutoFitOff,Pcenter,Axis_vector,Angle)

Stat=DeleteEntity(Pcenter)
Stat=DeleteEntity(Axis_vector)


GOTO Start

Leave:!
Stat= DeleteEntity(Surface_group)
Stat=LowerShade("data")
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
