File: SVFileoutPolyImpl.mesa
Last edited by Bier on July 30, 1984 0:57:20 am PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Author: Eric Bier on July 22, 1987 5:29:02 pm PDT
Contents: Facilities for creating human-readable version of a polygon approximation to a 3d scene.
DIRECTORY
SVCoordSys, SVGraphics, SVScene, SVSceneToTree, FileNames, IO, Rope, SV3d, SVFileoutPoly, SVModelTypes, SVSceneTypes, SVSweepGeometry, SVParseOut;
SVFileoutPolyImpl:
CEDAR PROGRAM
IMPORTS SVCoordSys, SVGraphics, IO, SVScene, SVSceneToTree, FileNames, Rope, SVParseOut
EXPORTS SVFileoutPoly =
BEGIN
Artwork: TYPE = SVModelTypes.Artwork;
Slice: TYPE = SVSceneTypes.Slice;
SliceList: TYPE = SVSceneTypes.SliceList;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CoordSysList: TYPE = SVModelTypes.CoordSysList;
FileCamera: TYPE = SVSceneTypes.FileCamera;
FileCameraList: TYPE = SVSceneTypes.FileCameraList;
LightSource: TYPE = SVModelTypes.LightSource;
LightSourceList: TYPE = LIST OF LightSource;
LinearMesh: TYPE = REF LinearMeshRecord;
LinearMeshArray: TYPE = SVSweepGeometry.LinearMeshArray;
LinearMeshRecord: TYPE = SVSweepGeometry.LinearMeshRecord;
MasterObject: TYPE = SVSceneTypes.MasterObject;
MasterObjectList: TYPE = SVSceneTypes.MasterObjectList;
Matrix4by4: TYPE = SV3d.Matrix4by4;
Point3d: TYPE = SV3d.Point3d;
RevoluteMesh: TYPE = REF RevoluteMeshRecord;
RevoluteMeshArray: TYPE = SVSweepGeometry.RevoluteMeshArray;
RevoluteMeshRecord: TYPE = SVSweepGeometry.RevoluteMeshRecord;
Scene: TYPE = SVSceneTypes.Scene;
Shape: TYPE = SVSceneTypes.Shape;
FileoutMatrix:
PROC [f:
IO.
STREAM, mat: Matrix4by4] = {
f.PutF[" %g, %g, %g, 0.0\n", IO.real[mat[1][1]], IO.real[mat[2][1]], IO.real[mat[3][1]] ];
f.PutF[" %g, %g, %g, 0.0\n", IO.real[mat[1][2]], IO.real[mat[2][2]], IO.real[mat[3][2]] ];
f.PutF[" %g, %g, %g, 0.0\n", IO.real[mat[1][3]], IO.real[mat[2][3]], IO.real[mat[3][3]] ];
f.PutF[" %g, %g, %g, 1.0\n", IO.real[mat[1][4]], IO.real[mat[2][4]], IO.real[mat[3][4]] ];
};
StorePolyScene:
PUBLIC
PROC [scene: Scene, f:
IO.
STREAM, fileName: Rope.
ROPE] = {
csList: CoordSysList;
fileName ← FileNames.GetShortName[fileName];
f.PutF["File: %g\n",[rope[fileName]]];
f.PutF["3D file for scene: %g\n",[rope[fileName]]];
f.PutF["Produced by %g\n\n", [rope[SVScene.versionRope]]];
csList ← SVSceneToTree.CoordSysListFromScene[scene];
FileoutLightSources[f, scene.lightSources];
FileoutObjects[f, scene.masterObjects];
FileoutAssembly[f, scene.assembly, scene.masterObjects];
FileoutCameras[f, scene.cameras, scene];
f.PutF["END"];
f.Close[];
scene.dirty ← FALSE;
};
CountCoordSystems:
PROC [csl: CoordSysList]
RETURNS [count:
NAT] = {
count ← 0;
FOR list: CoordSysList ← csl, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
CountLightSources:
PROC [lsl: LightSourceList]
RETURNS [count:
NAT] = {
count ← 0;
FOR list: LightSourceList ← lsl, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
FileoutLightSources:
PUBLIC
PROC [f:
IO.
STREAM, lsl: LightSourceList] = {
count: NAT ← CountLightSources[lsl];
thisLS: LightSource;
f.PutF["LightSources [%g]:\n",[integer[count]]];
FOR thisLSL: LightSourceList ← lsl, thisLSL.rest
UNTIL thisLSL =
NIL
DO
thisLS ← thisLSL.first;
FileoutLightSource[f, thisLS];
f.PutChar[IO.CR];
ENDLOOP;
f.PutChar[IO.CR];
};
FileoutLightSource:
PROC [f:
IO.
STREAM, lightSource: LightSource] = {
f.PutF["LightSource: %g position: ",[rope[lightSource.name]]];
SVParseOut.FileoutPoint3d[f,lightSource.position];
f.PutF[" color: "];
SVParseOut.FileoutColor[f, lightSource.color];
};
FileoutCameras:
PUBLIC
PROC [f:
IO.
STREAM, cameras: FileCameraList, scene: Scene] = {
thisCamera: FileCamera;
FOR list: FileCameraList ← cameras, list.rest
UNTIL list =
NIL
DO
thisCamera ← list.first;
IF Rope.Equal[thisCamera.name, scene.cameraOrder.first]
THEN {
FileoutCamera[f, thisCamera];
EXIT;
};
ENDLOOP;
f.PutChar[IO.CR];
};
FileoutCamera:
PUBLIC
PROC [f:
IO.
STREAM, fileCamera: FileCamera] = {
f.PutRope["Camera: "];
f.PutRope[fileCamera.name];
f.PutChar[IO.CR];
f.PutRope[" origin: "];
SVParseOut.FileoutPoint3d[f, fileCamera.origin];
f.PutRope[" focusPoint: "];
SVParseOut.FileoutPoint3d[f, fileCamera.focusPoint];
f.PutF[" slant: %g", [real[fileCamera.slant]]];
f.PutChar[IO.CR];
f.PutF[" focalLength: %g", [real[fileCamera.focalLength]]];
f.PutF[" projection: %g", [rope[SVGraphics.ProjectionToRope[fileCamera.projection]]]];
f.PutChar[IO.CR];
};
FileoutArtwork:
PRIVATE
PROC [f:
IO.
STREAM, artwork: Artwork] = {
f.PutF["color: "];
SVParseOut.FileoutColor[f, artwork.color];
};
FileoutAssembly:
PROC [f:
IO.
STREAM, assem: Slice, mol: MasterObjectList] = {
WITH assem.shape SELECT FROM
alist: SliceList => {
File out subassembly information.
FileoutAssemblies[f,alist,mol];
f.PutF["Composite Slice: %g\n transform:\n", IO.rope[assem.name]];
FileoutMatrix[f, SVCoordSys.GetMat[assem.coordSys]];
f.PutChar[IO.TAB];
FileoutArtwork[f, assem.artwork];
f.PutChar[IO.CR];
FileoutSubassemblyNames[f, alist];
f.PutChar[IO.CR];
};
shape: Shape => {
f.PutF["Primitive Slice: %g\n scalars: ", IO.rope[assem.name]];
SVParseOut.FileoutPoint3d[f, SVCoordSys.GetScalars[shape.coordSys]];
f.PutChar[IO.CR]; f.PutChar[IO.TAB];
FileoutArtwork[f, assem.artwork];
f.PutChar[IO.CR]; f.PutChar[IO.TAB];
f.PutF["object: "];
f.PutRope[shape.mo.name];
f.PutChar[IO.CR]; f.PutChar[IO.TAB];
f.PutF["transform:\n"];
FileoutMatrix[f, SVCoordSys.GetMat[assem.coordSys]];
f.PutChar[IO.CR];
};
ENDCASE => ERROR;
}; -- end of FileoutAssembly
FileoutAssemblies:
PROC [f:
IO.
STREAM, as: SliceList, mol: MasterObjectList] = {
FOR aso:
LIST
OF Slice ← as.list, aso.rest
UNTIL aso =
NIL
DO
FileoutAssembly[f, aso.first, mol];
f.PutChar[IO.CR];
ENDLOOP; -- next assembly
f.PutChar[IO.CR];
}; -- end of FileoutAssemblies
FileoutSubassemblyNames:
PROC [f:
IO.
STREAM, asl: SliceList] = {
thisA: Slice;
FOR list:
LIST
OF Slice ← asl.list, list.rest
UNTIL list =
NIL
DO
thisA ← list.first;
f.PutF[" call %g\n",[rope[thisA.name]]];
ENDLOOP;
f.PutChar[IO.CR];
};
CountObjects:
PROC [ol: MasterObjectList]
RETURNS [count:
NAT] = {
count ← 0;
FOR list: MasterObjectList ← ol, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
FileoutObjects:
PROC [f:
IO.
STREAM, ol: MasterObjectList] = {
mo: MasterObject;
count: NAT ← CountObjects[ol];
f.PutF["Objects [%g]:\n",[integer[count-2]]];
FOR mol: MasterObjectList← ol, mol.rest
UNTIL mol =
NIL
DO
mo ← mol.first;
IF Rope.Equal[mo.name, "halfSpace"] OR Rope.Equal[mo.name, "jack"] THEN LOOP;
f.PutF["Master Object: %g\n", [rope[mo.name]] ];
mo.class.fileoutPoly[f, mo];
ENDLOOP;
f.PutChar[IO.CR];
};
END.