
! script name: 3drender.d/shadesurface
! 3dtopic: shade a group of surfaces

!A
!A NAME:
!A
!A 	SHADE SURFACE
!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
!B 		    to be 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:!


Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("a1",",C,")
Surface=PickEntity("PICK SURFACE , Colors ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
        CASE "C"
                Stat=RaiseShade("data")
                GOTO Pick_loop
END SELECT
IF NOT ValidGeometry(Surface) THEN Pick_loop

Part_group= CreateGroup("TEMP")
stat= AddToGroup(Part_group,Surface)

Vnum= LastPickView


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("storage dir",WsSystemVars,"/usr/weber/ST/pics",Dir$)
	Jobname1$=FileNameString(Dir$,Jobname$)


Stat=Setup3dShade(Vnum,Tol)
Smooth=1

! Axis_line=PickSpecificEnt("PICK AXIS LINE",WsPickLines)
! IF (ExitScript(Destination$)) THEN Leave
! IF NOT ValidGeometry(Axis_line) THEN Line_loop

! Angle=InputAngle("ROTATION ANGLE")
! IF (ExitScript(Destination$)) THEN Leave


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)
stat= DeleteEntity(Part_group)

! Stat=RaiseShade("data")

GOTO Start

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