G3dInterpretImpl.mesa
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 19, 1992 11:20 am PDT
Heckbert, August 10, 1988 6:36:38 pm PDT
Glassner, November 18, 1989 12:25:38 pm PST
DIRECTORY FileInterpreter, FS, G3dInterpret, G3dBasic, G3dRender, G3dScene, G3dShape, G3dTool, ImagerColor, IO, List, Rope, StatementInterpreter, ViewerClasses;
G3dInterpretImpl: CEDAR PROGRAM
IMPORTS FileInterpreter, FS, G3dRender, G3dScene, G3dTool, IO, Rope, StatementInterpreter
EXPORTS G3dInterpret
~ BEGIN
Type Declarations
InterpretTool: TYPE ~ G3dInterpret.InterpretTool;
RenderTool: TYPE ~ G3dTool.Tool;
ROPE:   TYPE ~ Rope.ROPE;
Error:   PUBLIC SIGNAL [reason: ROPE] = CODE;
Tool Creation and Use
Draw: G3dScene.SceneProc ~ {
tool: G3dTool.Tool ¬ NARROW[data];
tool.shapes ¬ ps.context.shapes;
G3dTool.PrepareForDrawing[tool];
G3dTool.Repaint[tool];
};
MakeInterpretTool: PUBLIC PROC [
fileName: ROPE,
column: ViewerClasses.Column ¬ left,
log: BOOL ¬ TRUE,
renderTool: RenderTool ¬ NIL]
RETURNS [a: InterpretTool]
~ {
IF fileName # NIL THEN {
symbols: FileInterpreter.Symbols ¬ FileInterpreter.CreateSymbolTable[NIL];
err: ROPE ¬ StatementInterpreter.InterpretStatement[
"{ OPEN G3dInterpret; NULL }",, LIST[symbols]];
IF err # NIL THEN Error[err];
a ¬ NEW[G3dInterpret.InterpretToolRep];
a.fileTool ¬ FileInterpreter.CreateTool[
symbols, fileName, "3dInterpret", column, a, log,,, Repeat, Abort, LIST[["Help", Help]]];
IF a.fileTool = NIL THEN Error["Can't find file"];
IF (a.renderTool ¬ renderTool) = NIL THEN a.renderTool ¬
G3dTool.MakeTool[name: "3dInterpret", nViews: 0, client: [data: a]];
IF NOT G3dTool.Context3dOk[a.renderTool] THEN Error["Bad 3d context!"];
G3dScene.RegisterProc["Draw", Draw, a.renderTool];
FileInterpreter.Execute[a.fileTool];
};
};
Log: G3dScene.LogProc ~ {
a: InterpretTool ¬ NARROW[clientData];
FileInterpreter.WriteToLog[a.fileTool, rope];
};
Parse: PUBLIC PROC [rope: ROPE] ~ {
a: InterpretTool ¬ GetInterpretTool[];
{
ENABLE {
FS.Error => {Log[error.explanation, a]; CONTINUE};
G3dScene.ParseError => {Log[explanation, a]; CONTINUE};
};
IF NOT G3dTool.Context3dOk[a.renderTool] THEN Error["Can't create 3d context"];
a.parseState ¬ G3dScene.Parse[
a.renderTool.context3d, rope, a.fileTool.cmd.out, Log,, a.fileTool.fileName, a, a.parseState];
IF a.parseState.errorMessage # NIL THEN Log[a.parseState.errorMessage, a];
};
};
Parses: PROC [key: ROPE, reals: LIST OF REAL ¬ NIL, ints: LIST OF INT ¬ NIL] ~ {
AddToList: PROC [value: IO.Value] ~ {
IF tail = NIL
THEN values ¬ tail ¬ LIST[value]
ELSE {tail.rest ¬ LIST[value]; tail ¬ tail.rest};
};
format: ROPE ¬ Rope.Cat[key, ": "];
values, tail: LIST OF IO.Value ¬ NIL;
IF reals # NIL
THEN FOR l: LIST OF REAL ¬ reals, l.rest WHILE l # NIL DO
AddToList[IO.real[l.first]];
format ¬ Rope.Cat[format, "%g "];
ENDLOOP
ELSE FOR l: LIST OF INT ¬ ints, l.rest WHILE l # NIL DO
AddToList[IO.int[l.first]];
format ¬ Rope.Cat[format, "%g "];
ENDLOOP;
IF values # NIL THEN Parse[IO.PutFLR[format, values]];
};
ParseReals: PUBLIC PROC [key: ROPE, values: LIST OF REAL] ~ {Parses[key, values]};
ParseInts: PUBLIC PROC [key: ROPE, values: LIST OF INT] ~ {Parses[key,, values]};
GetInterpretTool: PUBLIC PROC RETURNS [InterpretTool] ~ {
RETURN[NARROW[FileInterpreter.GetClientData[]]];
};
Help: ViewerClasses.ClickProc ~ {G3dTool.OpenHelp["3dInterpret"]};
Repeat: FileInterpreter.ClientProc ~ {
renderTool: G3dTool.Tool ¬ NARROW[clientData, InterpretTool].renderTool;
renderTool.context3d ¬ NIL;
renderTool.shapes ¬ NIL;
};
Abort: FileInterpreter.ClientProc ~ {
G3dRender.AbortRender[NARROW[clientData, InterpretTool].renderTool.context3d];
};
END.
..
Previous procs used before we relied on OPEN
MakeInterpretTool: PUBLIC PROC [script: ROPE, log: BOOLTRUE, fork: BOOLFALSE]
RETURNS [data: InterpretTool]
~ {
IF script # NIL THEN {
FillTable: FileInterpreter.ClientFillTableProc ~ {
RegisterProc[NEW[RealProc    ← CameraFieldOfView]];
RegisterProc[NEW[Real3Proc    ← CameraPosition]];
RegisterProc[NEW[Real3Proc    ← CameraLookAt]];
RegisterProc[NEW[Real3Proc    ← CameraUpDirection]];
RegisterProc[NEW[RopeReal7Proc   ← ShapeRotate]];
RegisterProc[NEW[RopeReal3Proc   ← ShapePlace]];
RegisterProc[NEW[RopeProc    ← AddShape]];
RegisterProc[NEW[RopeProc    ← DeleteShape]];
RegisterProc[NEW[RopeSwitchProc  ← BackFaces]];
RegisterProc[NEW[RopeProc    ← InvertShapeNormals]];
RegisterProc[NEW[RopeRealProc   ← SetShapeShininess]];
RegisterProc[NEW[RopeReal3Proc   ← SetShapeColor]];
RegisterProc[NEW[RopeRenderModeProc ← SetShapeRenderMode]];
RegisterProc[NEW[RopeRenderStyleProc ← SetShapeRenderStyle]];
RegisterProc[NEW[Rope2Proc    ← ReadTextureMap]];
RegisterProc[NEW[Rope2Proc    ← ReadBumpMap]];
RegisterProc[NEW[RopeRealProc   ← SetBumpScale]];
RegisterProc[NEW[RopeReal2Proc   ← ScaleTextureMap]];
RegisterProc[NEW[RopeProc    ← RemoveTextureAndBumpMapping]];
RegisterProc[NEW[RopeLightStyleProc ← SetShapeLighting]];
RegisterProc[NEW[RopeReal6Proc   ← AddLight]];
RegisterProc[NEW[RopeProc    ← DeleteLight]];
RegisterProc[NEW[Real3Proc    ← SetAmbientLight]];
RegisterProc[NEW[PROC      ← Render]];
RegisterProc[NEW[RopeProc    ← RenderToFile]];
RegisterProc[NEW[RopeProc    ← SavePicture]];
RegisterProc[NEW[Real3Proc    ← SetBackground]];
RegisterProc[NEW[SwitchProc    ← SetAntiAliasing]];
RegisterProc[NEW[Real4Proc    ← SetViewPort]];
RegisterProc[NEW[DisplayModeProc  ← SetDisplayMode]];
FOR l: List.LORA ← G3dInterpret.GetScriptProcRegistry[], l.rest WHILE l # NIL DO
RegisterProc[l.first];
ENDLOOP;
};
symbols: FileInterpreter.Symbols ← FileInterpreter.CreateSymbolTable[FillTable];
data ← NEW[InterpretToolRep];
data.tool ← FileInterpreter.CreateTool[
symbols, script, "G3dInterpret", cmd, data, log,, AbortProc, LIST[["Help", Help]]];
IF data.tool = NIL THEN Error["Can't find file"];
IF log THEN data.tool.out ← cmd.out;
FileInterpreter.Execute[data.tool, fork];
};
};
scriptProcRegistry: LIST OF REF ANYNIL;
RegisterScriptProc: PUBLIC PROC [refAny: REF ANY] ~ {
scriptProcRegistry ← LIST[scriptProcRegistry, refAny];
};
UnRegisterAllScriptProcs: PUBLIC PROC ~ {
scriptProcRegistry ← NIL;
};
GetScriptProcRegistry: PUBLIC PROC RETURNS [LIST OF REF ANY] ~ {
RETURN[scriptProcRegistry];
};