File: Fileout3dImpl.mesa
Last edited by Bier on May 23, 1985 11:10:00 pm PDT
Copyright © 1984 by Xerox Corporation. All rights reserved.
Contents: Facilities for creating text files and writing out a human-readable version of a 3d object database
DIRECTORY
CoordSys,
CSG,
DisplayList3d,
DisplayListToTree,
Fileout3d,
FileNames,
IO,
Rope,
SV3d,
SVModelTypes,
SVSceneTypes,
SweepGeometry,
TFO3d;
Fileout3dImpl:
PROGRAM
IMPORTS CoordSys, CSG, IO, DisplayList3d, DisplayListToTree, FileNames, Rope, TFO3d
EXPORTS Fileout3d =
BEGIN
Artwork: TYPE = SVModelTypes.Artwork;
ArtworkClass: TYPE = SVModelTypes.ArtworkClass;
Assembly: TYPE = SVSceneTypes.Assembly;
AssemblyList: TYPE = SVSceneTypes.AssemblyList;
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 = SweepGeometry.LinearMeshArray;
LinearMeshRecord: TYPE = SweepGeometry.LinearMeshRecord;
MasterObject: TYPE = SVSceneTypes.MasterObject;
MasterObjectList: TYPE = SVSceneTypes.MasterObjectList;
Matrix4by4: TYPE = SV3d.Matrix4by4;
Point3d: TYPE = SV3d.Point3d;
RevoluteMesh: TYPE = REF RevoluteMeshRecord;
RevoluteMeshArray: TYPE = SweepGeometry.RevoluteMeshArray;
RevoluteMeshRecord: TYPE = SweepGeometry.RevoluteMeshRecord;
Scene: TYPE = SVSceneTypes.Scene;
Shape: TYPE = SVSceneTypes.Shape;
SpaceFunction: TYPE = SVModelTypes.SpaceFunction;
FileoutScene:
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[DisplayList3d.versionRope]]];
f.PutF["Background color: "];
TFO3d.FileoutColor[f, scene.backgroundColor];
f.PutChar[IO.CR];
f.PutF["Shadows: "];
TFO3d.FileoutBOOL[f, scene.shadows];
f.PutChar[IO.CR];
f.PutF["Ambient: "];
TFO3d.FileoutColor[f, scene.lightSources.first.color];
f.PutChar[IO.CR];
f.PutChar[IO.CR];
csList ← DisplayListToTree.CoordSysListFromScene[scene];
FileoutCoordSystems[f, csList];
FileoutLightSources[f, scene.lightSources.rest];
FileoutObjects[f, scene.masterObjects];
FileoutAssembly[f, scene.assembly, scene.masterObjects];
FileoutCameras[f, scene.cameras];
FileoutCameraOrder[f, scene.cameraOrder];
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;
};
FileoutCoordSystems:
PROC [f:
IO.
STREAM, csl: CoordSysList] = {
count: NAT ← CountCoordSystems[csl];
thisCS: CoordSystem;
f.PutF["CoordSystems [%g]:\n",[integer[count]]];
FOR thisCSL: CoordSysList ← csl, thisCSL.rest
UNTIL thisCSL =
NIL
DO
thisCS ← thisCSL.first;
f.PutF["CoordSys: %g mat: ",[rope[thisCS.name]]];
TFO3d.FileoutMatrix[f,thisCS.mat];
f.PutF[" withRespectTo: "];
IF thisCS.parent = NIL THEN f.PutF["NIL"]
ELSE f.PutRope[thisCS.parent.name];
f.PutChar[IO.CR];
ENDLOOP;
f.PutChar[IO.CR];
};
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]]];
TFO3d.FileoutPoint3d[f,lightSource.position];
f.PutF[" color: "];
TFO3d.FileoutColor[f, lightSource.color];
};
FileoutCameras:
PUBLIC
PROC [f:
IO.
STREAM, cameras: FileCameraList] = {
count: NAT ← CountCameras[cameras];
thisCamera: FileCamera;
f.PutF["Cameras [%g]:\n",[integer[count]]];
FOR list: FileCameraList ← cameras, list.rest
UNTIL list =
NIL
DO
thisCamera ← list.first;
TFO3d.FileoutCamera[f, thisCamera];
f.PutChar[IO.CR];
ENDLOOP;
f.PutChar[IO.CR];
};
FileoutCameraOrder:
PUBLIC
PROC [f:
IO.
STREAM, cameraOrder:
LIST
OF Rope.
ROPE] = {
count: NAT ← CountRopes[cameraOrder];
f.PutF["Initial Camera Order [%g]: ", [integer[count]]];
IF count > 0
THEN {
f.PutRope[cameraOrder.first];
FOR list:
LIST
OF Rope.
ROPE ← cameraOrder.rest, list.rest
UNTIL list =
NIL
DO
f.PutF[", %g", [rope[list.first]]];
ENDLOOP;
f.PutChar[IO.CR];
f.PutChar[IO.CR];
};
};
CountRopes:
PROC [ropes:
LIST
OF Rope.
ROPE]
RETURNS [count:
NAT] = {
count ← 0;
FOR list:
LIST
OF Rope.
ROPE ← ropes, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
CountCameras:
PROC [cameras: FileCameraList]
RETURNS [count:
NAT] = {
count ← 0;
FOR list: FileCameraList ← cameras, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
CountAssemblies:
PROC [asl: AssemblyList]
RETURNS [count:
NAT] = {
count ← 0;
FOR list:
LIST
OF Assembly ← asl.list, list.rest
UNTIL list =
NIL
DO
count ← count + 1;
ENDLOOP;
};
FileoutArtwork:
PRIVATE
PROC [f:
IO.
STREAM, artwork: Artwork] = {
IF artwork.coordSys = NIL THEN f.PutF["coordSys: %g class: %g ", IO.rope["NIL"], IO.rope[ArtworkClassToRope[artwork.class]]]
ELSE f.PutF["coordSys: %g class: %g ", IO.rope[artwork.coordSys.name], IO.rope[ArtworkClassToRope[artwork.class]]];
f.PutF["material: "];
TFO3d.FileoutMaterial[f, artwork.material];
f.PutF[" surface: "];
TFO3d.FileoutSurface[f, artwork.surface];
SELECT artwork.class FROM
justColor => {
f.PutF[" color: "];
TFO3d.FileoutColor[f, artwork.color];
};
simpleSurface => {
aisName: Rope.ROPE;
f.PutChar[IO.CR];
f.PutF["SMap: "];
TFO3d.FileoutSMap[f, artwork.sMap];
f.PutF[" OMap: "];
TFO3d.FileoutOMap[f, artwork.oMap];
f.PutChar[IO.SP];
aisName ← FileNames.GetShortName[artwork.source];
f.PutF["source: %g ", [rope[aisName]]];
IF artwork.isColorFile THEN f.PutF["colorFile"] ELSE f.PutF["bwFile"];
f.PutF[" resolution: %g\n", [real[artwork.resolution]]];
f.PutF["mat: "];
TFO3d.FileoutMatrix3by3[f, artwork.artWRTPad.mat];
f.PutF[" color: "];
TFO3d.FileoutColor[f, artwork.color];
};
spaceFunction => {
spaceFunction: SpaceFunction ← NARROW[artwork.surface];
f.PutF[" scalars: "];
TFO3d.FileoutPoint3d[f, spaceFunction.scalars];
f.PutF[" func: colorcube"];
};
ENDCASE => ERROR;
};
ArtworkClassToRope:
PROC [class: ArtworkClass]
RETURNS [className: Rope.
ROPE] = {
SELECT class FROM
justColor => className ← "justColor";
simpleSurface => className ← "simpleSurface";
spaceFunction => className ← "spaceFunction";
ENDCASE => ERROR;
};
FileoutAssembly:
PROC [f:
IO.
STREAM, assem: Assembly, mol: MasterObjectList] = {
pointSetOp: Rope.ROPE;
f.PutF["Assembly: %g, coordSys: %g",
[rope[assem.name]],[rope[assem.coordSys.name]]];
WITH assem.shape SELECT FROM
alist: AssemblyList => {
f.PutF[", Composite"];
f.PutChar[IO.CR];
f.PutChar[IO.TAB];
f.PutF["artwork: "];
FileoutArtwork[f, assem.artwork];
f.PutChar[
IO.
CR];
File out subassembly information.
f.PutChar[IO.TAB];
pointSetOp ← CSG.PointSetOpToRope[alist.pointSetOp];
f.PutF["subassemblies [%g]\n", [rope[pointSetOp]]];
FileoutSubassemblyNames[f, alist];
f.PutChar[IO.CR];
FileoutAssemblies[f,alist,mol];
};
shape: Shape => {
f.PutF[", Primitive scalars: "];
TFO3d.FileoutPoint3d[f, CoordSys.GetScalars[shape.coordSys]];
f.PutChar[IO.CR]; f.PutChar[IO.TAB];
f.PutF["artwork: "];
FileoutArtwork[f, assem.artwork];
f.PutChar[IO.CR]; f.PutChar[IO.TAB];
f.PutF["object: "];
f.PutRope[shape.mo.name];
IF Rope.Equal[shape.mo.name, "jack",
FALSE]
THEN {
f.PutF[" sittingOn: "];
IF assem.sittingOn = NIL THEN f.PutF["NIL"]
ELSE f.PutRope[assem.sittingOn];
};
f.PutChar[IO.CR];
};
ENDCASE => ERROR;
}; -- end of FileoutAssembly
FileoutAssemblies:
PROC [f:
IO.
STREAM, as: AssemblyList, mol: MasterObjectList] = {
count: NAT ← CountAssemblies[as];
f.PutF["Subassemblies [%g]:\n",[integer[count]]];
FOR aso:
LIST
OF Assembly ← as.list, aso.rest
UNTIL aso =
NIL
DO
FileoutAssembly[f, aso.first, mol];
ENDLOOP; -- next assembly
f.PutChar[IO.CR];
}; -- end of FileoutAssemblies
FileoutSubassemblyNames:
PROC [f:
IO.
STREAM, asl: AssemblyList] = {
count: NAT ← CountAssemblies[asl];
thisA: Assembly;
f.PutF[" [%g]: (", [integer[count]]];
IF count = 0 THEN {f.PutF[")\n"]; RETURN};
thisA ← asl.list.first;
f.PutRope[thisA.name];
FOR list:
LIST
OF Assembly ← asl.list.rest, list.rest
UNTIL list =
NIL
DO
thisA ← list.first;
f.PutF[", %g",[rope[thisA.name]]];
ENDLOOP;
f.PutF[")\n"];
};
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]]];
FOR mol: MasterObjectList← ol, mol.rest
UNTIL mol =
NIL
DO
mo ← mol.first;
f.PutF["Master Object: %g class: %g\n", [rope[mo.name]], [rope[mo.class.name]]];
mo.class.fileout[f, mo];
ENDLOOP;
f.PutChar[IO.CR];
};
END.