<<>> <> <> <> <> DIRECTORY Ascii, Args, Buttons, Commander, Controls, Convert, CtBasic, CtFile, CtMap, Draw2d, FileNames, FS, G2dBasic, G3dBasic, G3dFunction, G3dIO, G3dNormalCoding, G3dTool, G3dVector, Icons, Imager, ImagerColor, ImagerFont, ImagerSample, IO, MessageWindow, Process, Random, Real, RealFns, Rope, TiogaAccess, VFonts, ViewerClasses, ViewerOps, ViewerSpecs; G3dLightingCmdsImpl: CEDAR PROGRAM IMPORTS Args, Buttons, Controls, Convert, CtBasic, CtFile, CtMap, FileNames, FS, G3dIO, G3dNormalCoding, G3dTool, G3dVector, ImagerColor, ImagerSample, Icons, IO, MessageWindow, Process, Random, Real, RealFns, Rope, TiogaAccess, VFonts, ViewerOps, ViewerSpecs ~ BEGIN <> CommandProc: TYPE ~ Commander.CommandProc; ButtonList: TYPE ~ Controls.ButtonList; Button: TYPE ~ Controls.Button; ClickProc: TYPE ~ Controls.ClickProc; Control: TYPE ~ Controls.Control; ControlList: TYPE ~ Controls.ControlList; DestroyProc: TYPE ~ Controls.DestroyProc; Mouse: TYPE ~ Controls.Mouse; MouseProc: TYPE ~ Controls.MouseProc; OuterData: TYPE ~ Controls.OuterData; Typescript: TYPE ~ Controls.Typescript; Viewer: TYPE ~ Controls.Viewer; SampleMap: TYPE ~ CtBasic.SampleMap; SampleMaps: TYPE ~ CtBasic.SampleMaps; Cmap: TYPE ~ CtMap.Cmap; SRGB: TYPE ~ CtMap.RGB; -- scaled RGB: Cardinals [0-255] (rgb) DrawProc: TYPE ~ G3dTool.DrawProc; Pair: TYPE ~ G2dBasic.Pair; Triple: TYPE ~ G3dBasic.Triple; URGB: TYPE ~ ImagerColor.RGB; -- unscaled RGB: Reals [0-1] (RGB) Font: TYPE ~ ImagerFont.Font; Box: TYPE ~ ImagerSample.Box; STREAM: TYPE ~ IO.STREAM; ROPE: TYPE ~ Rope.ROPE; Writer: TYPE ~ TiogaAccess.Writer; <> Color: TYPE ~ RECORD [rgb: URGB]; ColorArray: TYPE ~ ARRAY [0..255] OF Color; RealArray: TYPE ~ ARRAY [0..255] OF REAL; LightAccelerators: TYPE ~ RECORD [ cached, cachep: REF RealArray ¬ NIL, cacheD, cacheS: REF ColorArray ¬ NIL]; Light: TYPE ~ RECORD [ name: ROPE ¬ NIL, direction: Triple ¬ [0.0, 0.0, 1.0], spread: REAL ¬ 1.0, color: Color ¬ [rgb: [1.0, 1.0, 1.0]], accelerators: REF LightAccelerators ¬ NIL]; MaterialProps: TYPE ~ RECORD [ kd: REAL ¬ 1.0, ks: REAL ¬ 1.0, kr: REAL ¬ 1.0, ke: REAL ¬ 20.0, kt: REAL ¬ 1.0, km: REAL ¬ 1.0, kc: REAL ¬ 1.0]; MaterialAccelerators: TYPE ~ RECORD [cacheMw: Color]; Material: TYPE ~ RECORD [ name: ROPE ¬ NIL, materialProps: MaterialProps ¬ [], color: Color ¬ [rgb: [1.0, 1.0, 1.0]], accelerators: REF MaterialAccelerators ¬ NIL]; MaterialSequence: TYPE ~ REF MaterialSequenceRep; MaterialSequenceRep: TYPE ~ RECORD [ length: CARDINAL ¬ 0, element: SEQUENCE maxLength: CARDINAL OF Material]; LightSequence: TYPE ~ REF LightSequenceRep; LightSequenceRep: TYPE ~ RECORD [ length: CARDINAL ¬ 0, element: SEQUENCE maxLength: CARDINAL OF Light]; ToolState: TYPE ~ REF ToolStateRep; ToolStateRep: TYPE ~ RECORD [ <<-- debug flags>> redrawSphere: BOOLEAN ¬ FALSE, use24bits: BOOLEAN ¬ FALSE, radius: INTEGER ¬ 203, <<-- image file>> imageFileName: ROPE ¬ NIL, <<-- normal flags>> nextPressSpecial: BOOLEAN ¬ TRUE, pointDirection: BOOLEAN ¬ TRUE, pointHighlight: BOOLEAN ¬ FALSE, placeInvertZ: BOOLEAN ¬ FALSE, lightFocus: BOOLEAN ¬ TRUE, rs: Random.RandomStream, maps: SampleMaps ¬ NIL]; LightingTool: TYPE ~ REF LightingToolRep; LightingToolRep: TYPE ~ RECORD [ <<-- light source data>> lights: LightSequence, activeLight: INT ¬ 0, <<-- material data>> materials: MaterialSequence, activeMaterial: INT ¬ 0, <<-- lighting controls>> thetaControl: Control ¬ NIL, psiControl: Control ¬ NIL, spreadControl: Control ¬ NIL, falloffControl: Control ¬ NIL, lightColorSlider1: Control ¬ NIL, lightColorSlider2: Control ¬ NIL, lightColorSlider3: Control ¬ NIL, lightSpectrum: Control ¬ NIL, <<-- surface controls>> kdControl: Control ¬ NIL, ksControl: Control ¬ NIL, krControl: Control ¬ NIL, keControl: Control ¬ NIL, ktControl: Control ¬ NIL, kmControl: Control ¬ NIL, kcControl: Control ¬ NIL, materialColorSlider1: Control ¬ NIL, materialColorSlider2: Control ¬ NIL, materialColorSlider3: Control ¬ NIL, materialSpectrum: Control ¬ NIL, <> activeLightButton: Button, activeMaterialButton: Button, <<-- tool state>> state: ToolState, <<-- viewer stuff>> outer: Viewer ¬ NIL, -- the parent viewer outerData: OuterData ¬ NIL, -- controls information ts: Typescript ¬ NIL, -- for user io lightColorPatch: Box, -- place for color sample materialColorPatch: Box, -- place for color sample myButtons: ButtonList ¬ NIL, -- my buttons graphics: Viewer ¬ NIL]; -- for drawing the sphere <> fgColor: INT = 0; bgColor: INT = 255; lightColor: INT = 1; materialColor: INT = 2; pi: REAL = 3.1415926535; twoPi: REAL = 6.283185; piOver2: REAL = 1.570796; piOver4: REAL = 0.7853982; program: ROPE ¬ "3dLighting Designer"; version: ROPE ¬ "v1.0"; <> NotANormal: ERROR = CODE; <> LightingCmd: CommandProc ~ { <> fileName: ROPE ¬ NIL; fileNameA: Args.Arg; [fileNameA] ¬ Args.ArgsGet[cmd, "%[s"]; IF fileNameA.ok THEN fileName ¬ fileNameA.rope; <> <> <> }; <> CreateMyTool: PROC [fileName: ROPE] ~ { lt: LightingTool ¬ NEW[LightingToolRep ¬ []]; <> lt.state ¬ NEW[ToolStateRep ¬ []]; lt.state.imageFileName ¬ fileName; MakeControls[lt]; lt.outer ¬ Controls.OuterViewer[ name: "3dLighting Designer", column: color, buttons: lt.myButtons, graphicsHeight: 300, -- height of color display's sphere mouseProc: LightingMouse, -- select a point on the sphere drawProc: LightingDraw, -- draw the sphere destroyProc: LightingDestroy, typescriptHeight: 36, clientData: lt, noOpen: TRUE].parent; InitializeMaterials[lt]; InitializeLights[lt]; lt.lightColorPatch ¬ [[90, 425], [180, 460]]; lt.materialColorPatch ¬ [[280, 425], [365, 460]]; lt.outer.icon ¬ lightingIcon; DrawInitialControls[lt]; lt.state.redrawSphere ¬ TRUE; lt.state.use24bits ¬ FALSE; lt.outerData ¬ NARROW[lt.outer.data]; lt.graphics ¬ lt.outerData.graphics; lt.ts ¬ lt.outerData.typescript; ViewerOps.OpenIcon[lt.outer]; lt.state.rs ¬ Random.Create[range: 500, seed: 1989]; UpdateActiveLight[lt]; UpdateActiveMaterial[lt]; UpdateLightColorSliders[lt]; UpdateMaterialColorSliders[lt]; BuildColormap[lt]; }; MakeControls: PROC [lt: LightingTool] ~ { <> myFont: Font ¬ VFonts.DefaultFont[]; lt.lightColorSlider1 ¬ Controls.NewControl[name: "H:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: LightColorSliders, x: 520, y: 375, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.lightColorSlider2 ¬ Controls.NewControl[name: "S:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: LightColorSliders, x: 520, y: 360, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.lightColorSlider3 ¬ Controls.NewControl[name: "L:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: LightColorSliders, x: 520, y: 345, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.lightSpectrum ¬ Controls.NewControl[type: function, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: LightSpectrumFunction, x: 520, y: 305, w: 105, h: 35, textLocation: [left, down], font: myFont]; lt.psiControl ¬ Controls.NewControl[name: "Psi", type: vSlider, clientData: lt, min: -pi/2.0, max: pi/2.0, init: 0.0, proc: PsiControl, x: 540, y: 225, w: 30, h: 45, font: myFont]; lt.thetaControl ¬ Controls.NewControl[name: "Theta", type: dial, clientData: lt, min: pi, max: -pi, init: 0.0, proc: ThetaControl, x: 585, y: 225, w: 45, h: 60, font: myFont]; lt.spreadControl ¬ Controls.NewControl[name: "S:", type: hSlider, clientData: lt, min: 0., max: 80.0, init: 1.0, proc: SpreadControl, x: 475, y: 225, w: 50, h: 13, textLocation: [left, down, TRUE], font: myFont, taper: exp]; lt.materialColorSlider1 ¬ Controls.NewControl[name: "H:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialColorSliders, x: 520, y: 190, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.materialColorSlider2 ¬ Controls.NewControl[name: "S:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialColorSliders, x: 520, y: 175, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.materialColorSlider3 ¬ Controls.NewControl[name: "L:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialColorSliders, x: 520, y: 160, w: 105, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.materialSpectrum ¬ Controls.NewControl[ type: function, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialSpectrumFunction, x: 520, y: 120, w: 105, h: 35, textLocation: [left, down], font: myFont]; lt.kdControl ¬ Controls.NewControl[name: "kd:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialControls, x: 545, y: 100, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.ksControl ¬ Controls.NewControl[name: "ks:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialControls, x: 545, y: 85, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.keControl ¬ Controls.NewControl[name: "ke:", type: hSlider, clientData: lt, min: 0.0, max: 80.0, init: 20.0, proc: MaterialControls, x: 545, y: 70, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont, taper: exp]; lt.kmControl ¬ Controls.NewControl[name: "km:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialControls, x: 545, y: 55, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont]; <> lt.krControl ¬ Controls.NewControl[name: "kr:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialControls, x: 545, y: 25, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.ktControl ¬ Controls.NewControl[name: "kt:", type: hSlider, clientData: lt, min: 0.0, max: 1.0, init: 1.0, proc: MaterialControls, x: 545, y: 10, w: 85, h: 13, textLocation: [left, down, TRUE], font: myFont]; lt.myButtons ¬ CONS[Controls.ClickButton["Debug", DebugOps, lt], lt.myButtons]; lt.myButtons ¬ CONS[Controls.ClickButton["Sphere", SphereOps, lt], lt.myButtons]; lt.myButtons ¬ CONS[Controls.ClickButton["IO", IOOps, lt], lt.myButtons]; lt.myButtons ¬ CONS[Controls.ClickButton["Material Ops", MaterialOps, lt], lt.myButtons]; lt.myButtons ¬ CONS[Controls.ClickButton["Lighting Ops", LightingOps, lt], lt.myButtons]; lt.myButtons ¬ CONS[Controls.ClickButton["Place Light", PlacingOps, lt], lt.myButtons]; lt.activeLightButton ¬ Controls.ClickButton[name: "Default", proc: SelectLightOps, clientData: lt, x: 435, y: 255]; lt.activeMaterialButton ¬ Controls.ClickButton[name: "Default", proc: SelectMaterialOps, clientData: lt, x: 435, y: 75]; <> <> }; <> DrawInitialControls: PROC [lt: LightingTool] ~ { DrawLightingControls[lt]; DrawMaterialControls[lt]; }; DrawLightingControls: PROC [lt: LightingTool] ~ { DrawControl[lt, lt.lightColorSlider1]; DrawControl[lt, lt.lightColorSlider2]; DrawControl[lt, lt.lightColorSlider3]; DrawControl[lt, lt.lightSpectrum]; DrawControl[lt, lt.psiControl]; DrawControl[lt, lt.thetaControl]; DrawControl[lt, lt.spreadControl]; ViewerOps.PaintViewer[lt.outer, client]; }; EraseLightingControls: PROC [lt: LightingTool] ~ { EraseControl[lt, lt.lightColorSlider1]; EraseControl[lt, lt.lightColorSlider2]; EraseControl[lt, lt.lightColorSlider3]; EraseControl[lt, lt.lightSpectrum]; EraseControl[lt, lt.psiControl]; EraseControl[lt, lt.thetaControl]; EraseControl[lt, lt.spreadControl]; ViewerOps.PaintViewer[lt.outer, client]; }; DrawMaterialControls: PROC [lt: LightingTool] ~ { DrawControl[lt, lt.materialColorSlider1]; DrawControl[lt, lt.materialColorSlider2]; DrawControl[lt, lt.materialColorSlider3]; DrawControl[lt, lt.materialSpectrum]; DrawControl[lt, lt.kdControl]; DrawControl[lt, lt.ksControl]; DrawControl[lt, lt.krControl]; DrawControl[lt, lt.keControl]; DrawControl[lt, lt.ktControl]; DrawControl[lt, lt.kmControl]; <> ViewerOps.PaintViewer[lt.outer, client]; }; EraseMaterialControls: PROC [lt: LightingTool] ~ { EraseControl[lt, lt.materialColorSlider1]; EraseControl[lt, lt.materialColorSlider2]; EraseControl[lt, lt.materialColorSlider3]; EraseControl[lt, lt.materialSpectrum]; EraseControl[lt, lt.kdControl]; EraseControl[lt, lt.ksControl]; EraseControl[lt, lt.krControl]; EraseControl[lt, lt.keControl]; EraseControl[lt, lt.ktControl]; EraseControl[lt, lt.kmControl]; <> ViewerOps.PaintViewer[lt.outer, client]; }; DrawControl: PROC [lt: LightingTool, control: Control] ~ { Controls.ControlViewer[lt.outer, control, NIL, lt.outerData]; }; EraseControl: PROC [lt: LightingTool, control: Control] ~ { ViewerOps.DestroyViewer[control.viewer, FALSE]; ViewerOps.DestroyViewer[control.title, FALSE]; ViewerOps.DestroyViewer[control.status, FALSE]; }; <