From e6f861c5342e92e3f91ef05f0583afa21a4cf909 Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Mon, 24 Jun 2024 10:52:33 +0200 Subject: [PATCH] [Vrml97] - removed AttributeAnnotator - cleanup hardcoded strings - removed obsolete Parse arguments: annotate, resolveDefUse, duplicateMaps - cleanup PloyMesh creating: * removed out-of-spec texture and texCoordTransform processing * restored AddPerFaceNormals and AddCreaseNormals Options * removed PixTexture --- .../AttributeAnnotator.cs | 282 -------- src/Aardvark.Data.Vrml97/DefUseResolver.cs | 15 +- src/Aardvark.Data.Vrml97/Parser.cs | 653 +++++++++++------- src/Aardvark.Data.Vrml97/PixTexture.cs | 174 ----- .../PolyMeshFromVrml97.cs | 305 ++------ src/Aardvark.Data.Vrml97/SceneLoader.cs | 26 +- src/Aardvark.Data.Vrml97/Vrml97Scene.cs | 24 +- src/Aardvark.Data.Vrml97/VrmlHelpers.cs | 97 +++ src/Aardvark.Data.Vrml97/VrmlNodeTypes.cs | 112 ++- 9 files changed, 629 insertions(+), 1059 deletions(-) delete mode 100644 src/Aardvark.Data.Vrml97/AttributeAnnotator.cs delete mode 100644 src/Aardvark.Data.Vrml97/PixTexture.cs create mode 100644 src/Aardvark.Data.Vrml97/VrmlHelpers.cs diff --git a/src/Aardvark.Data.Vrml97/AttributeAnnotator.cs b/src/Aardvark.Data.Vrml97/AttributeAnnotator.cs deleted file mode 100644 index c0742db..0000000 --- a/src/Aardvark.Data.Vrml97/AttributeAnnotator.cs +++ /dev/null @@ -1,282 +0,0 @@ -using Aardvark.Base; -using System; -using System.Collections.Generic; -using System.IO; - -namespace Aardvark.Data.Vrml97 -{ - /// - /// The AttributeAnnotator is used to annotate all - /// geometry nodes with material and transform - /// attributes. - /// - /// Example: - /// - /// Parser parser = new Parser("myVrmlFile.wrl"); - /// SymMapBase parseTree = parser.Perform(); - /// - /// AttributeAnnotator resolver = new AttributeAnnotator(); - /// SymMapBase annotatedParseTree = resolver.Perform(parseTree); - /// - /// - internal class AttributeAnnotator - { - private Stack m_material; - private Stack m_texture; - private Stack m_textureTransform; - private Stack m_transform; - private string m_path = ""; - private Dictionary m_visited = new Dictionary(); - - public static Vrml97Scene Annotate(Vrml97Scene vrmlParseTree) - => new AttributeAnnotator().Perform(vrmlParseTree); - - /// - /// Takes a Vrml97 parse tree (see also ) - /// and augments all geometry nodes with material and - /// transform attributes. - /// - /// Parse tree. - /// Augmented parse tree. - public Vrml97Scene Perform(Vrml97Scene root) - { - root.ParseTree["AttributeAnnotator.Performed"] = true; // leave hint - - if (root.ParseTree.TypeName == "Vrml97") - { - string filename = root.ParseTree.Get(Vrml97Sym.filename); - m_path = Path.GetDirectoryName(filename); - } - - m_material = new Stack(); - m_texture = new Stack(); - m_textureTransform = new Stack(); - m_transform = new Stack(); - - m_transform.Push(Trafo3d.Identity); - - var trav = new SymMapBaseTraversal(SymMapBaseTraversal.Mode.Modifying, SymMapBaseTraversal.Visit.PreAndPost); - - trav.PerNameVisitors["ImageTexture"] = - delegate(SymMapBase m, SymMapBaseTraversal.Visit visit) - { - if (visit == SymMapBaseTraversal.Visit.Pre) - { - if (m_visited.ContainsKey(m)) return m; - List urls = m.Get>(Vrml97Sym.url); - if (urls != null) - { - for (int i = 0; i < urls.Count; i++) - { - urls[i] = Path.Combine(m_path, urls[i]); - } - } - m_visited[m] = m; - } - return m; - }; - - // geometry nodes - SymMapBase foo(SymMapBase m, SymMapBaseTraversal.Visit visit) - { - if (visit == SymMapBaseTraversal.Visit.Post) return m; - - if (m_material.Count == 0 - && m_texture.Count == 0 - && m_textureTransform.Count == 0 - && m_transform.Count == 0) - return m; - - var map = new SymMapBase(m); - - if (m_material.Count > 0) - { - string key = "material"; - // while (m.Contains(key)) key += "X"; - map[key] = m_material.Peek(); - } - - if (m_texture.Count > 0) - { - string key = "texture"; - // while (m.Contains(key)) key += "X"; - map[key] = m_texture.Peek(); - } - - if (m_textureTransform.Count > 0) - { - string key = "textureTransform"; - // while (m.Contains(key)) key += "X"; - var tt = m_textureTransform.Peek(); - - map[key] = tt.ExtractVrmlTextureTrafo(); - } - - if (m_transform.Count > 1) // [0] contains initial identity - { - string key = "transform"; - // while (m.Contains(key)) key += "X"; - if (m.Contains(key)) - { - Report.Warn("[Vrml97]: trying to annotate annotated node!"); - } - map[key] = m_transform.Peek(); - } - - return map; - } - - trav.PerNameVisitors["IndexedFaceSet"] = foo; - trav.PerNameVisitors["IndexedLineSet"] = foo; - - - // attributes - trav.PerNameVisitors["Shape"] = - delegate(SymMapBase m, SymMapBaseTraversal.Visit visit) - { - bool hasMaterial = false; - bool hasTexture = false; - bool hasTextureTransform = false; - SymMapBase app = null; - - if (m.Contains("appearance")) - { - app = m.Get(Vrml97Sym.appearance); - hasMaterial = app.Contains(Vrml97Sym.material); - hasTexture = app.Contains(Vrml97Sym.texture); - hasTextureTransform = app.Contains(Vrml97Sym.textureTransform); - } - - if (visit == SymMapBaseTraversal.Visit.Pre) - { - if (hasMaterial) m_material.Push(app.Get(Vrml97Sym.material)); - if (hasTexture) m_texture.Push(app.Get(Vrml97Sym.texture)); - if (hasTextureTransform) m_textureTransform.Push(app.Get(Vrml97Sym.textureTransform)); - } - else if (visit == SymMapBaseTraversal.Visit.Post) - { - if (hasMaterial) m_material.Pop(); - if (hasTexture) m_texture.Pop(); - if (hasTextureTransform) m_textureTransform.Pop(); - } - - return m; - }; - - trav.PerNameVisitors["Transform"] = - delegate(SymMapBase m, SymMapBaseTraversal.Visit visit) - { - if (visit == SymMapBaseTraversal.Visit.Pre) - { - var trafo = m.ExtractVrmlGeometryTrafo(); - - m["trafo"] = trafo; - - m_transform.Push(trafo * m_transform.Peek()); - } - else if (visit == SymMapBaseTraversal.Visit.Post) - { - m_transform.Pop(); - } - - return m; - }; - - root.ParseTree = trav.Traverse(root.ParseTree); - return root; - } - } - - /// - /// Various helper methods. - /// - public static class VrmlHelpers - { - /// - /// Build a texture coordinate transformation from the given parameters as specified in TextureTransform - /// http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html#TextureTransform - /// - public static Trafo2d BuildVrmlTextureTrafo(V2d center, double rotation, V2d scale, V2d translation) - { - M33d C = M33d.Translation(center), Ci = M33d.Translation(-center); - M33d R = M33d.Rotation(rotation), Ri = M33d.Rotation(-rotation); - M33d S = M33d.Scale(scale), Si = M33d.Scale(1 / scale); - M33d T = M33d.Translation(translation), Ti = M33d.Translation(-translation); - - return new Trafo2d( - Ci * S * R * C * T, - Ti * Ci * Ri * Si * C); - } - - /// - /// Extracts texture transform from given node. - /// - public static Trafo2d ExtractVrmlTextureTrafo(this SymMapBase m) - { - if (m == null) return Trafo2d.Identity; - - // get trafo parts - var c = (V2d)m.Get(Vrml97Sym.center, V2f.Zero); - var r = (double)m.Get(Vrml97Sym.rotation, 0.0f); - var s = (V2d)m.Get(Vrml97Sym.scale, new V2f(1, 1)); - var t = (V2d)m.Get(Vrml97Sym.translation, V2f.Zero); - - M33d C = M33d.Translation(c), Ci = M33d.Translation(-c); - M33d R = M33d.Rotation(r), Ri = M33d.Rotation(-r); - M33d S = M33d.Scale(s), Si = M33d.Scale(1 / s); - M33d T = M33d.Translation(t), Ti = M33d.Translation(-t); - - return new Trafo2d( - Ci * S * R * C * T, - Ti * Ci * Ri * Si * C); - } - - /// - /// Build a geometry transformation from the given parameters as specified in Transform - /// http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html#Transform - /// - public static Trafo3d BuildVrmlGeometryTrafo(V3d center, V4d rotation, V3d scale, V4d scaleOrientation, V3d translation) - { - // create composite trafo (naming taken from vrml97 spec) - M44d C = M44d.Translation(center), Ci = M44d.Translation(-center); - var scaleRotAxis = scaleOrientation.XYZ.Normalized; // NOTE: values in the vrml (limited number of digits) are often not normalized - M44d SR = M44d.Rotation(scaleRotAxis, scaleOrientation.W), SRi = M44d.Rotation(scaleRotAxis, -scaleOrientation.W); - M44d T = M44d.Translation(translation), Ti = M44d.Translation(-translation); - - //if (m_aveCompatibilityMode) r.W = -r.W; - var rotationAxis = rotation.XYZ.Normalized; // NOTE: values in the vrml (limited number of digits) are often not normalized - M44d R = M44d.Rotation(rotationAxis, rotation.W), Ri = M44d.Rotation(rotationAxis, -rotation.W); - - // in case some axis scales by 0 the best thing for the inverse scale is also 0 - var si = new V3d(scale.X.IsTiny() ? 0 : 1 / scale.X, - scale.Y.IsTiny() ? 0 : 1 / scale.Y, - scale.Z.IsTiny() ? 0 : 1 / scale.Z); - M44d S = M44d.Scale(scale), Si = M44d.Scale(si); - - return new Trafo3d( - T * C * R * SR * S * SRi * Ci, - C * SR * Si * SRi * Ri * Ci * Ti); - } - - /// - /// Returns geometry transform from given node. - /// - public static Trafo3d ExtractVrmlGeometryTrafo(this SymMapBase m) - { - // get trafo parts - var c = (V3d)m.Get(Vrml97Sym.center, V3f.Zero); - - var r = (V4d)m.Get(Vrml97Sym.rotation, V4f.Zero); - if (r.X == 0 && r.Y == 0 && r.Z == 0) r.Z = 1; - - var s = (V3d)m.Get(Vrml97Sym.scale, new V3f(1, 1, 1)); - - var sr = (V4d)m.Get(Vrml97Sym.scaleOrientation, V4f.Zero); - if (sr.X == 0 && sr.Y == 0 && sr.Z == 0) sr.Z = 1; - - var t = (V3d)m.Get(Vrml97Sym.translation, V3f.Zero); - - return BuildVrmlGeometryTrafo(c, r, s, sr, t); - } - } -} diff --git a/src/Aardvark.Data.Vrml97/DefUseResolver.cs b/src/Aardvark.Data.Vrml97/DefUseResolver.cs index ba460b4..71e27a6 100644 --- a/src/Aardvark.Data.Vrml97/DefUseResolver.cs +++ b/src/Aardvark.Data.Vrml97/DefUseResolver.cs @@ -22,25 +22,24 @@ namespace Aardvark.Data.Vrml97 internal class DefUseResolver { public static Vrml97Scene Resolve(Vrml97Scene vrmlParseTree, - out Dictionary namedNodes, bool duplicateMaps = true) - => new DefUseResolver().Perform(vrmlParseTree, out namedNodes, duplicateMaps); + out Dictionary namedNodes) + => new DefUseResolver().Perform(vrmlParseTree, out namedNodes); /// /// Takes a VRML97 parse tree (see also ) /// and resolves all DEF and USE nodes. /// /// Parse tree. - /// /// /// Parse tree without DEF and USE nodes. - public Vrml97Scene Perform(Vrml97Scene root, out Dictionary namedNodes, bool duplicateMaps) + public Vrml97Scene Perform(Vrml97Scene root, out Dictionary namedNodes) { root.ParseTree["DefUseResolver.Performed"] = true; // leave hint m_defs = new Dictionary(); SymMapBaseTraversal trav = new SymMapBaseTraversal(); - trav.PerNameVisitors["USE"] = (map, visit) => + trav.PerNameVisitors[Vrml97Sym.USE] = (map, visit) => { // Lookup USE name and return associated node. var name = map.Get(Vrml97Sym.name); @@ -52,17 +51,17 @@ public Vrml97Scene Perform(Vrml97Scene root, out Dictionary //throw new Exception("DefUseResolver: USE " + name + ": Unknown!"); } - return duplicateMaps ? new SymMapBase(node) : node; + return node; }; - trav.PerNameVisitors["DEF"] = (map, visit) => + trav.PerNameVisitors[Vrml97Sym.DEF] = (map, visit) => { // Register name/node pair. string defName = map.Get(Vrml97Sym.name); SymMapBase node = map.Get(Vrml97Sym.node); m_defs[defName] = node; - node["DEFname"] = defName; + node[Vrml97Sym.DEFname] = defName; return node; }; diff --git a/src/Aardvark.Data.Vrml97/Parser.cs b/src/Aardvark.Data.Vrml97/Parser.cs index 4c87e39..e869584 100644 --- a/src/Aardvark.Data.Vrml97/Parser.cs +++ b/src/Aardvark.Data.Vrml97/Parser.cs @@ -15,20 +15,174 @@ public static class Vrml97Sym { #pragma warning disable 1591 public static readonly Symbol Vrml97 = "Vrml97"; - public static readonly Symbol url = "url"; public static readonly Symbol texture = "texture"; public static readonly Symbol name = "name"; + public static readonly Symbol title = "title"; + public static readonly Symbol info = "info"; public static readonly Symbol filename = "filename"; + public static readonly Symbol description = "description"; + public static readonly Symbol parameter = "parameter"; public static readonly Symbol node = "node"; public static readonly Symbol root = "root"; + public static readonly Symbol point = "point"; + public static readonly Symbol coord = "coord"; + public static readonly Symbol collide = "collide"; + public static readonly Symbol proxy = "proxy"; + public static readonly Symbol geometry = "geometry"; public static readonly Symbol appearance = "appearance"; public static readonly Symbol material = "material"; + public static readonly Symbol image = "image"; public static readonly Symbol textureTransform = "textureTransform"; public static readonly Symbol center = "center"; public static readonly Symbol rotation = "rotation"; public static readonly Symbol scale = "scale"; public static readonly Symbol translation = "translation"; public static readonly Symbol scaleOrientation = "scaleOrientation"; + public static readonly Symbol axisOfRotation = "axisOfRotation"; + + public static readonly Symbol ccw = "ccw"; + public static readonly Symbol colorIndex = "colorIndex"; + public static readonly Symbol colorPerVertex = "colorPerVertex"; + public static readonly Symbol convex = "convex"; + public static readonly Symbol coordIndex = "coordIndex"; + public static readonly Symbol creaseAngle = "creaseAngle"; + public static readonly Symbol DEFname = "DEFname"; + public static readonly Symbol normal = "normal"; + public static readonly Symbol normalIndex = "normalIndex"; + public static readonly Symbol normalPerVertex = "normalPerVertex"; + public static readonly Symbol solid = "solid"; + public static readonly Symbol texCoord = "texCoord"; + public static readonly Symbol texCoordIndex = "texCoordIndex"; + public static readonly Symbol transform = "transform"; + public static readonly Symbol vector = "vector"; + + public static readonly Symbol edgeSharpness = "edgeSharpness"; + public static readonly Symbol edgeSharpnessIndex = "edgeSharpnessIndex"; + public static readonly Symbol neighborMesh = "neighborMesh"; + public static readonly Symbol neighborIndex = "neighborIndex"; + public static readonly Symbol neighborSide = "neighborSide"; + public static readonly Symbol neighborFace = "neighborFace"; + public static readonly Symbol meshName = "meshName"; + public static readonly Symbol topologyHoles = "topologyHoles"; + + public static readonly Symbol xDimension = "xDimension"; + public static readonly Symbol xSpacing = "xSpacing"; + public static readonly Symbol zDimension = "zDimension"; + public static readonly Symbol zSpacing = "zSpacing"; + + public static readonly Symbol beginCap = "beginCap"; + public static readonly Symbol crossSection = "crossSection"; + public static readonly Symbol endCap = "endCap"; + public static readonly Symbol orientation = "orientation"; + public static readonly Symbol spine = "spine"; + + public static readonly Symbol fogType = "fogType"; + public static readonly Symbol visibilityRange = "visibilityRange"; + + public static readonly Symbol bboxCenter = "bboxCenter"; + public static readonly Symbol bboxSize = "bboxSize"; + + public static readonly Symbol children = "children"; + + public static readonly Symbol size = "size"; + public static readonly Symbol radius = "radius"; + public static readonly Symbol bottomRadius = "bottomRadius"; + public static readonly Symbol height = "height"; + public static readonly Symbol side = "side"; + public static readonly Symbol bottom = "bottom"; + public static readonly Symbol top = "top"; + + public static readonly Symbol autoOffset = "autoOffset"; + public static readonly Symbol diskAngle = "diskAngle"; + public static readonly Symbol maxAngle = "maxAngle"; + public static readonly Symbol minAngle = "minAngle"; + public static readonly Symbol offset = "offset"; + + public static readonly Symbol groundAngle = "groundAngle"; + public static readonly Symbol groundColor = "groundColor"; + public static readonly Symbol backUrl = "backUrl"; + public static readonly Symbol bottomUrl = "bottomUrl"; + public static readonly Symbol frontUrl = "frontUrl"; + public static readonly Symbol leftUrl = "leftUrl"; + public static readonly Symbol rightUrl = "rightUrl"; + public static readonly Symbol topUrl = "topUrl"; + public static readonly Symbol skyAngle = "skyAngle"; + public static readonly Symbol skyColor = "skyColor"; + + public static readonly Symbol level = "level"; + public static readonly Symbol range = "range"; + + public static readonly Symbol avatarSize = "avatarSize"; + public static readonly Symbol headlight = "headlight"; + public static readonly Symbol type = "type"; + public static readonly Symbol visibilityLimit = "visibilityLimit"; + + public static readonly Symbol maxPosition = "maxPosition"; + public static readonly Symbol minPosition = "minPosition"; + public static readonly Symbol maxBack = "maxBack"; + public static readonly Symbol maxFront = "maxFront"; + public static readonly Symbol minBack = "minBack"; + public static readonly Symbol minFront = "minFront"; + public static readonly Symbol priority = "priority"; + public static readonly Symbol source = "source"; + public static readonly Symbol spatialize = "spatialize"; + + public static readonly Symbol fieldOfView = "fieldOfView"; + public static readonly Symbol jump = "jump"; + public static readonly Symbol position = "position"; + + public static readonly Symbol color = "color"; + public static readonly Symbol intensity = "intensity"; + public static readonly Symbol on = "on"; + public static readonly Symbol attenuation = "attenuation"; + public static readonly Symbol beamWidth = "beamWidth"; + public static readonly Symbol cutOffAngle = "cutOffAngle"; + public static readonly Symbol direction = "direction"; + public static readonly Symbol location = "location"; + + public static readonly Symbol choice = "choice"; + public static readonly Symbol whichChoice = "whichChoice"; + + public static readonly Symbol diffuseColor = "diffuseColor"; + public static readonly Symbol emissiveColor = "emissiveColor"; + public static readonly Symbol ambientIntensity = "ambientIntensity"; + public static readonly Symbol specularColor = "specularColor"; + public static readonly Symbol transparency = "transparency"; + public static readonly Symbol shininess = "shininess"; + + public static readonly Symbol key = "key"; + public static readonly Symbol keyValue = "keyValue"; + + public static readonly Symbol cycleInterval = "cycleInterval"; + public static readonly Symbol enabled = "enabled"; + public static readonly Symbol loop = "loop"; + public static readonly Symbol speed = "speed"; + public static readonly Symbol startTime = "startTime"; + public static readonly Symbol stopTime = "stopTime"; + + public static readonly Symbol pitch = "pitch"; + + public static readonly Symbol family = "family"; + public static readonly Symbol horizontal = "horizontal"; + public static readonly Symbol justify = "justify"; + public static readonly Symbol language = "language"; + public static readonly Symbol leftToRight = "leftToRight"; + public static readonly Symbol spacing = "spacing"; + public static readonly Symbol style = "style"; + public static readonly Symbol topToBottom = "topToBottom"; + + public static readonly Symbol stringSym = "string"; + public static readonly Symbol fontStyle = "fontStyle"; + public static readonly Symbol length = "length"; + public static readonly Symbol maxExtent = "maxExtent"; + + public static readonly Symbol inSym = "in"; + public static readonly Symbol outSym = "out"; + + public static readonly Symbol url = "url"; + public static readonly Symbol path = "path"; + public static readonly Symbol repeatS = "repeatS"; + public static readonly Symbol repeatT = "repeatT"; public static readonly Symbol DEF = "DEF"; public static readonly Symbol USE = "USE"; @@ -231,410 +385,411 @@ static Parser() s_parseInfoMap[Vrml97NodeName.Anchor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "children", fd(MFNode) }, - { "description", fd(SFString) }, - { "parameter", fd(MFString) }, - { "url", fd(MFString) }, - { "bboxCenter", defaultBBoxCenter}, - { "bboxSize", defaultBBoxSize} + { Vrml97Sym.children, fd(MFNode) }, + { Vrml97Sym.description, fd(SFString) }, + { Vrml97Sym.parameter, fd(MFString) }, + { Vrml97Sym.url, fd(MFString) }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter}, + { Vrml97Sym.bboxSize, defaultBBoxSize} }); // Appearance s_parseInfoMap[Vrml97NodeName.Appearance] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "material", fd(SFNode) }, - { "texture", fd(SFNode) }, - { "textureTransform", fd(SFNode) } + { Vrml97Sym.material, fd(SFNode) }, + { Vrml97Sym.texture, fd(SFNode) }, + { Vrml97Sym.textureTransform, fd(SFNode) } }); // AudioClip s_parseInfoMap[Vrml97NodeName.AudioClip] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "description", fd(SFString) }, - { "loop", (SFBool, false) }, - { "pitch", (SFFloat, 1.0f) }, - { "startTime", (SFTime, 0.0f)}, - { "stopTime", (SFTime, 0.0f)}, - { "url", fd(MFString)} + { Vrml97Sym.description, fd(SFString) }, + { Vrml97Sym.loop, (SFBool, false) }, + { Vrml97Sym.pitch, (SFFloat, 1.0f) }, + { Vrml97Sym.startTime, (SFTime, 0.0f)}, + { Vrml97Sym.stopTime, (SFTime, 0.0f)}, + { Vrml97Sym.url, fd(MFString)} }); // Background s_parseInfoMap[Vrml97NodeName.Background] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "groundAngle", fd(MFFloat) }, - { "groundColor", fd(MFColor) }, - { "backUrl", fd(MFString) }, - { "bottomUrl", fd(MFString) }, - { "frontUrl", fd(MFString) }, - { "leftUrl", fd(MFString) }, - { "rightUrl", fd(MFString) }, - { "topUrl", fd(MFString) }, - { "skyAngle", fd(MFFloat) }, - { "skyColor", (MFColor, C3f.Black) } + { Vrml97Sym.groundAngle, fd(MFFloat) }, + { Vrml97Sym.groundColor, fd(MFColor) }, + { Vrml97Sym.backUrl, fd(MFString) }, + { Vrml97Sym.bottomUrl, fd(MFString) }, + { Vrml97Sym.frontUrl, fd(MFString) }, + { Vrml97Sym.leftUrl, fd(MFString) }, + { Vrml97Sym.rightUrl, fd(MFString) }, + { Vrml97Sym.topUrl, fd(MFString) }, + { Vrml97Sym.skyAngle, fd(MFFloat) }, + { Vrml97Sym.skyColor, (MFColor, C3f.Black) } }); // Billboard s_parseInfoMap[Vrml97NodeName.Billboard] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "axisOfRotation", (SFVec3f, new V3f(0.0f, 1.0f, 0.0f)) }, - { "children", fd(MFNode) }, - { "bboxCenter", defaultBBoxCenter}, - { "bboxSize", defaultBBoxSize} + { Vrml97Sym.axisOfRotation, (SFVec3f, new V3f(0.0f, 1.0f, 0.0f)) }, + { Vrml97Sym.children, fd(MFNode) }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter}, + { Vrml97Sym.bboxSize, defaultBBoxSize} }); // Box s_parseInfoMap[Vrml97NodeName.Box] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "size", (SFVec3f, new V3f(2.0f, 2.0f, 2.0f)) } + { Vrml97Sym.size, (SFVec3f, new V3f(2.0f, 2.0f, 2.0f)) } }); // Collision s_parseInfoMap[Vrml97NodeName.Collision] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "children", fd(MFNode) }, - { "collide", (SFBool, true) }, - { "bboxCenter", defaultBBoxCenter}, - { "bboxSize", defaultBBoxSize}, - { "proxy", fd(SFNode) } + { Vrml97Sym.children, fd(MFNode) }, + { Vrml97Sym.collide, (SFBool, true) }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter}, + { Vrml97Sym.bboxSize, defaultBBoxSize}, + { Vrml97Sym.proxy, fd(SFNode) } }); // Color s_parseInfoMap[Vrml97NodeName.Color] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", fd(MFColor) } + { Vrml97Sym.color, fd(MFColor) } }); // ColorInterpolator s_parseInfoMap[Vrml97NodeName.ColorInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFColor) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFColor) } }); // Cone s_parseInfoMap[Vrml97NodeName.Cone] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "bottomRadius", (SFFloat, 1.0f) }, - { "height", (SFFloat, 2.0f) }, - { "side", (SFBool, true) }, - { "bottom", (SFBool, true) } + { Vrml97Sym.bottomRadius, (SFFloat, 1.0f) }, + { Vrml97Sym.height, (SFFloat, 2.0f) }, + { Vrml97Sym.side, (SFBool, true) }, + { Vrml97Sym.bottom, (SFBool, true) } }); // Coordinate s_parseInfoMap[Vrml97NodeName.Coordinate] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "point", fd(MFVec3f) } + { Vrml97Sym.point, fd(MFVec3f) } }); // CoordinateInterpolator s_parseInfoMap[Vrml97NodeName.CoordinateInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFVec3f) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFVec3f) } }); // Cylinder s_parseInfoMap[Vrml97NodeName.Cylinder] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "bottom", (SFBool, true) }, - { "height", (SFFloat, 2.0f) }, - { "radius", (SFFloat, 1.0f) }, - { "side", (SFBool, true) }, - { "top", (SFBool, true) } + { Vrml97Sym.bottom, (SFBool, true) }, + { Vrml97Sym.height, (SFFloat, 2.0f) }, + { Vrml97Sym.radius, (SFFloat, 1.0f) }, + { Vrml97Sym.side, (SFBool, true) }, + { Vrml97Sym.top, (SFBool, true) } }); // CylinderSensor s_parseInfoMap[Vrml97NodeName.CylinderSensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "autoOffset", (SFBool, true) }, - { "diskAngle", (SFFloat, 0.262f) }, - { "enabled", (SFBool, true) }, - { "maxAngle", (SFFloat, -1.0f) }, - { "minAngle", (SFFloat, 0.0f) }, - { "offset", (SFFloat, 0.0f) } + { Vrml97Sym.autoOffset, (SFBool, true) }, + { Vrml97Sym.diskAngle, (SFFloat, 0.262f) }, + { Vrml97Sym.enabled, (SFBool, true) }, + { Vrml97Sym.maxAngle, (SFFloat, -1.0f) }, + { Vrml97Sym.minAngle, (SFFloat, 0.0f) }, + { Vrml97Sym.offset, (SFFloat, 0.0f) } }); // DirectionalLight s_parseInfoMap[Vrml97NodeName.DirectionalLight] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "ambientIntensity", (SFFloat, 0.0f) }, - { "color", (SFColor, C3f.White) }, - { "direction", (SFVec3f, new V3f(0.0f, 0.0f, -1.0f)) }, - { "intensity", (SFFloat, 1.0f) }, - { "on", (SFBool, true) } + { Vrml97Sym.ambientIntensity, (SFFloat, 0.0f) }, + { Vrml97Sym.color, (SFColor, C3f.White) }, + { Vrml97Sym.direction, (SFVec3f, new V3f(0.0f, 0.0f, -1.0f)) }, + { Vrml97Sym.intensity, (SFFloat, 1.0f) }, + { Vrml97Sym.on, (SFBool, true) } }); // ElevationGrid s_parseInfoMap[Vrml97NodeName.ElevationGrid] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", fd(SFNode) }, - { "normal", fd(SFNode) }, - { "texCoord", fd(SFNode) }, - { "height", fd(MFFloat) }, - { "ccw", (SFBool, true) }, - { "colorPerVertex", (SFBool, true) }, - { "creaseAngle", (SFFloat, 0.0f) }, - { "normalPerVertex", (SFBool, true) }, - { "solid", (SFBool, true) }, - { "xDimension", (SFInt32, 0) }, - { "xSpacing", (SFFloat, 1.0f) }, - { "zDimension", (SFInt32, 0) }, - { "zSpacing", (SFFloat, 1.0f) } + { Vrml97Sym.color, fd(SFNode) }, + { Vrml97Sym.normal, fd(SFNode) }, + { Vrml97Sym.texCoord, fd(SFNode) }, + { Vrml97Sym.height, fd(MFFloat) }, + { Vrml97Sym.ccw, (SFBool, true) }, + { Vrml97Sym.colorPerVertex, (SFBool, true) }, + { Vrml97Sym.creaseAngle, (SFFloat, 0.0f) }, + { Vrml97Sym.normalPerVertex, (SFBool, true) }, + { Vrml97Sym.solid, (SFBool, true) }, + { Vrml97Sym.xDimension, (SFInt32, 0) }, + { Vrml97Sym.xSpacing, (SFFloat, 1.0f) }, + { Vrml97Sym.zDimension, (SFInt32, 0) }, + { Vrml97Sym.zSpacing, (SFFloat, 1.0f) } }); // Extrusion s_parseInfoMap[Vrml97NodeName.Extrusion] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "beginCap", (SFBool, true) }, - { "ccw", (SFBool, true) }, - { "convex", (SFBool, true) }, - { "creaseAngle", (SFFloat, 0.0f) }, - { "crossSection", (MFVec2f, new List() {new V2f(1.0f, 1.0f), new V2f(1.0f, -1.0f), new V2f(-1.0f, -1.0f), new V2f(-1.0f, 1.0f), new V2f(1.0f, 1.0f) }) }, - { "endCap", (SFBool, true) }, - { "orientation", (MFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, - { "scale", (MFVec2f, new V2f(1.0f, 1.0f)) }, - { "solid", (SFBool, true) }, - { "spine", (MFVec3f, new List() { V3f.Zero, new V3f(0.0f, 1.0f, 0.0f) }) } + { Vrml97Sym.beginCap, (SFBool, true) }, + { Vrml97Sym.ccw, (SFBool, true) }, + { Vrml97Sym.convex, (SFBool, true) }, + { Vrml97Sym.creaseAngle, (SFFloat, 0.0f) }, + { Vrml97Sym.crossSection, (MFVec2f, new List() {new V2f(1.0f, 1.0f), new V2f(1.0f, -1.0f), new V2f(-1.0f, -1.0f), new V2f(-1.0f, 1.0f), new V2f(1.0f, 1.0f) }) }, + { Vrml97Sym.endCap, (SFBool, true) }, + { Vrml97Sym.orientation, (MFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, + { Vrml97Sym.scale, (MFVec2f, new V2f(1.0f, 1.0f)) }, + { Vrml97Sym.solid, (SFBool, true) }, + { Vrml97Sym.spine, (MFVec3f, new List() { V3f.Zero, new V3f(0.0f, 1.0f, 0.0f) }) } }); // Fog s_parseInfoMap[Vrml97NodeName.Fog] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", (SFColor, C3f.White) }, - { "fogType", (SFString, "LINEAR") }, - { "visibilityRange", (SFFloat, 0.0f) } + { Vrml97Sym.color, (SFColor, C3f.White) }, + { Vrml97Sym.fogType, (SFString, "LINEAR") }, + { Vrml97Sym.visibilityRange, (SFFloat, 0.0f) } }); // FontStyle s_parseInfoMap[Vrml97NodeName.FontStyle] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "family", (MFString, "SERIF") }, - { "horizontal", (SFBool, true) }, - { "justify", (MFString, "BEGIN") }, - { "language", fd(SFString) }, - { "leftToRight", (SFBool, true) }, - { "size", (SFFloat, 1.0f) }, - { "spacing", (SFFloat, 1.0f) }, - { "style", (SFString, "PLAIN") }, - { "topToBottom", (SFBool, true) } + { Vrml97Sym.family, (MFString, "SERIF") }, + { Vrml97Sym.horizontal, (SFBool, true) }, + { Vrml97Sym.justify, (MFString, "BEGIN") }, + { Vrml97Sym.language, fd(SFString) }, + { Vrml97Sym.leftToRight, (SFBool, true) }, + { Vrml97Sym.size, (SFFloat, 1.0f) }, + { Vrml97Sym.spacing, (SFFloat, 1.0f) }, + { Vrml97Sym.style, (SFString, "PLAIN") }, + { Vrml97Sym.topToBottom, (SFBool, true) } }); // Group s_parseInfoMap[Vrml97NodeName.Group] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "children", fd(MFNode) }, - { "bboxCenter", defaultBBoxCenter }, - { "bboxSize", defaultBBoxSize } + { Vrml97Sym.children, fd(MFNode) }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter }, + { Vrml97Sym.bboxSize, defaultBBoxSize } }); // ImageTexture s_parseInfoMap[Vrml97NodeName.ImageTexture] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "url", fd(MFString) }, - { "repeatS", (SFBool, true) }, - { "repeatT", (SFBool, true) } + { Vrml97Sym.url, fd(MFString) }, + { Vrml97Sym.repeatS, (SFBool, true) }, + { Vrml97Sym.repeatT, (SFBool, true) } }); // IndexedFaceSet s_parseInfoMap[Vrml97NodeName.IndexedFaceSet] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", fd(SFNode) }, - { "coord", fd(SFNode) }, - { "normal", fd(SFNode) }, - { "texCoord", fd(SFNode) }, - { "ccw", (SFBool, true) }, - { "colorIndex", fd(MFInt32) }, - { "colorPerVertex", (SFBool, true) }, - { "convex", (SFBool, true) }, - { "coordIndex", fd(MFInt32) }, - { "creaseAngle", (SFFloat, 0.0f) }, - { "normalIndex", fd(MFInt32) }, - { "normalPerVertex", (SFBool, true) }, - { "solid", (SFBool, true) }, - { "texCoordIndex", fd(MFInt32) }, - { "edgeSharpness", fd(MFFloat) }, - { "edgeSharpnessIndex", fd(MFInt32) }, - { "neighborMesh", fd(MFString) }, - { "neighborIndex", fd(MFInt32) }, - { "neighborSide", fd(MFInt32) }, - { "neighborFace", fd(MFInt32) }, - { "meshName", fd(SFString) }, - { "topologyHoles", fd(SFInt32) } + { Vrml97Sym.color, fd(SFNode) }, + { Vrml97Sym.coord, fd(SFNode) }, + { Vrml97Sym.normal, fd(SFNode) }, + { Vrml97Sym.texCoord, fd(SFNode) }, + { Vrml97Sym.ccw, (SFBool, true) }, + { Vrml97Sym.colorIndex, fd(MFInt32) }, + { Vrml97Sym.colorPerVertex, (SFBool, true) }, + { Vrml97Sym.convex, (SFBool, true) }, + { Vrml97Sym.coordIndex, fd(MFInt32) }, + { Vrml97Sym.creaseAngle, (SFFloat, 0.0f) }, + { Vrml97Sym.normalIndex, fd(MFInt32) }, + { Vrml97Sym.normalPerVertex, (SFBool, true) }, + { Vrml97Sym.solid, (SFBool, true) }, + { Vrml97Sym.texCoordIndex, fd(MFInt32) }, + // NOTE: the following attributes are not found in the spec ??? + { Vrml97Sym.edgeSharpness, fd(MFFloat) }, + { Vrml97Sym.edgeSharpnessIndex, fd(MFInt32) }, + { Vrml97Sym.neighborMesh, fd(MFString) }, + { Vrml97Sym.neighborIndex, fd(MFInt32) }, + { Vrml97Sym.neighborSide, fd(MFInt32) }, + { Vrml97Sym.neighborFace, fd(MFInt32) }, + { Vrml97Sym.meshName, fd(SFString) }, + { Vrml97Sym.topologyHoles, fd(SFInt32) } }); // IndexedLineSet s_parseInfoMap[Vrml97NodeName.IndexedLineSet] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", fd(SFNode) }, - { "coord", fd(SFNode) }, - { "colorIndex", fd(MFInt32) }, - { "colorPerVertex", (SFBool, true) }, - { "coordIndex", fd(MFInt32) } + { Vrml97Sym.color, fd(SFNode) }, + { Vrml97Sym.coord, fd(SFNode) }, + { Vrml97Sym.colorIndex, fd(MFInt32) }, + { Vrml97Sym.colorPerVertex, (SFBool, true) }, + { Vrml97Sym.coordIndex, fd(MFInt32) } }); // Inline s_parseInfoMap[Vrml97NodeName.Inline] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "url", fd(MFString) }, - { "bboxCenter", defaultBBoxCenter }, - { "bboxSize", defaultBBoxSize } + { Vrml97Sym.url, fd(MFString) }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter }, + { Vrml97Sym.bboxSize, defaultBBoxSize } }); // LOD s_parseInfoMap[Vrml97NodeName.LOD] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "level", fd(MFNode) }, - { "center", defaultBBoxCenter }, - { "range", fd(MFFloat) } + { Vrml97Sym.level, fd(MFNode) }, + { Vrml97Sym.center, defaultBBoxCenter }, + { Vrml97Sym.range, fd(MFFloat) } }); // Material s_parseInfoMap[Vrml97NodeName.Material] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "ambientIntensity", (SFFloat, 0.2f) }, - { "diffuseColor", (SFColor, new C3f(0.8f, 0.8f, 0.8f)) }, - { "emissiveColor", (SFColor, C3f.Black) }, - { "shininess", (SFFloat, 0.2f) }, - { "specularColor", (SFColor, C3f.Black) }, - { "transparency", (SFFloat, 0.0f) } + { Vrml97Sym.ambientIntensity, (SFFloat, 0.2f) }, + { Vrml97Sym.diffuseColor, (SFColor, new C3f(0.8f, 0.8f, 0.8f)) }, + { Vrml97Sym.emissiveColor, (SFColor, C3f.Black) }, + { Vrml97Sym.shininess, (SFFloat, 0.2f) }, + { Vrml97Sym.specularColor, (SFColor, C3f.Black) }, + { Vrml97Sym.transparency, (SFFloat, 0.0f) } }); // MovieTexture s_parseInfoMap[Vrml97NodeName.MovieTexture] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "loop", (SFBool, false) }, - { "speed", (SFFloat, 1.0f) }, - { "startTime", (SFTime, 1.0f) }, - { "stopTime", (SFTime, 1.0f) }, - { "url", fd(MFString) }, - { "repeatS", (SFBool, true) }, - { "repeatT", (SFBool, true) } + { Vrml97Sym.loop, (SFBool, false) }, + { Vrml97Sym.speed, (SFFloat, 1.0f) }, + { Vrml97Sym.startTime, (SFTime, 1.0f) }, + { Vrml97Sym.stopTime, (SFTime, 1.0f) }, + { Vrml97Sym.url, fd(MFString) }, + { Vrml97Sym.repeatS, (SFBool, true) }, + { Vrml97Sym.repeatT, (SFBool, true) } }); // NavigationInfo s_parseInfoMap[Vrml97NodeName.NavigationInfo] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "avatarSize", (MFFloat, new List() {0.25f, 1.6f, 0.75f}) }, - { "headlight", (SFBool, true) }, - { "speed", (SFFloat, 1.0f) }, - { "type", (MFString, new List() {"WALK", "ANY"}) }, - { "visibilityLimit", (SFFloat, 0.0f) } + { Vrml97Sym.avatarSize, (MFFloat, new List() {0.25f, 1.6f, 0.75f}) }, + { Vrml97Sym.headlight, (SFBool, true) }, + { Vrml97Sym.speed, (SFFloat, 1.0f) }, + { Vrml97Sym.type, (MFString, new List() {"WALK", "ANY"}) }, + { Vrml97Sym.visibilityLimit, (SFFloat, 0.0f) } }); // Normal s_parseInfoMap[Vrml97NodeName.Normal] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "vector", fd(MFVec3f) } + { Vrml97Sym.vector, fd(MFVec3f) } }); // NormalInterpolator s_parseInfoMap[Vrml97NodeName.NormalInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFVec3f) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFVec3f) } }); // OrientationInterpolator s_parseInfoMap[Vrml97NodeName.OrientationInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFRotation) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFRotation) } }); // PixelTexture s_parseInfoMap[Vrml97NodeName.PixelTexture] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "image", (SFImage, new List() {0, 0, 0}) }, - { "repeatS", (SFBool, true) }, - { "repeatT", (SFBool, true) } + { Vrml97Sym.image, (SFImage, new List() {0, 0, 0}) }, + { Vrml97Sym.repeatS, (SFBool, true) }, + { Vrml97Sym.repeatT, (SFBool, true) } }); // PlaneSensor s_parseInfoMap[Vrml97NodeName.PlaneSensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "autoOffset", (SFBool, true) }, - { "enabled", (SFBool, true) }, - { "maxPosition", (SFVec2f, new V2f(-1.0f, -1.0f)) }, - { "minPosition", (SFVec2f, V2f.Zero) }, - { "offset", defaultBBoxCenter } + { Vrml97Sym.autoOffset, (SFBool, true) }, + { Vrml97Sym.enabled, (SFBool, true) }, + { Vrml97Sym.maxPosition, (SFVec2f, new V2f(-1.0f, -1.0f)) }, + { Vrml97Sym.minPosition, (SFVec2f, V2f.Zero) }, + { Vrml97Sym.offset, defaultBBoxCenter } }); // PointLight s_parseInfoMap[Vrml97NodeName.PointLight] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "ambientIntensity", (SFFloat, 0.0f) }, - { "attenuation", (SFVec3f, new V3f(1.0f, 0.0f, 0.0f)) }, - { "color", (SFColor, C3f.White) }, - { "intensity", (SFFloat, 1.0f) }, - { "location", defaultBBoxCenter }, - { "on", (SFBool, true) }, - { "radius", (SFFloat, 100.0f) } + { Vrml97Sym.ambientIntensity, (SFFloat, 0.0f) }, + { Vrml97Sym.attenuation, (SFVec3f, new V3f(1.0f, 0.0f, 0.0f)) }, + { Vrml97Sym.color, (SFColor, C3f.White) }, + { Vrml97Sym.intensity, (SFFloat, 1.0f) }, + { Vrml97Sym.location, defaultBBoxCenter }, + { Vrml97Sym.on, (SFBool, true) }, + { Vrml97Sym.radius, (SFFloat, 100.0f) } }); // PointSet s_parseInfoMap[Vrml97NodeName.PointSet] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "color", fd(SFNode) }, - { "coord", fd(SFNode) } + { Vrml97Sym.color, fd(SFNode) }, + { Vrml97Sym.coord, fd(SFNode) } }); // PositionInterpolator s_parseInfoMap[Vrml97NodeName.PositionInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFVec3f) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFVec3f) } }); // ProximitySensor s_parseInfoMap[Vrml97NodeName.ProximitySensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "center", defaultBBoxCenter }, - { "size", defaultBBoxCenter }, - { "enabled", (SFBool, true) } + { Vrml97Sym.center, defaultBBoxCenter }, + { Vrml97Sym.size, defaultBBoxCenter }, + { Vrml97Sym.enabled, (SFBool, true) } }); // ScalarInterpolator s_parseInfoMap[Vrml97NodeName.ScalarInterpolator] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "key", fd(MFFloat) }, - { "keyValue", fd(MFFloat) } + { Vrml97Sym.key, fd(MFFloat) }, + { Vrml97Sym.keyValue, fd(MFFloat) } }); // Script @@ -644,166 +799,166 @@ static Parser() s_parseInfoMap[Vrml97NodeName.Shape] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "appearance", fd(SFNode) }, - { "geometry", fd(SFNode) }, + { Vrml97Sym.appearance, fd(SFNode) }, + { Vrml97Sym.geometry, fd(SFNode) }, }); // Sound s_parseInfoMap[Vrml97NodeName.Sound] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "direction", (SFVec3f, new V3f(0.0f, 0.0f, 1.0f)) }, - { "intensity", (SFFloat, 1.0f) }, - { "location", defaultBBoxCenter }, - { "maxBack", (SFFloat, 10.0f) }, - { "maxFront", (SFFloat, 10.0f) }, - { "minBack", (SFFloat, 1.0f) }, - { "minFront", (SFFloat, 1.0f) }, - { "priority", (SFFloat, 0.0f) }, - { "source", fd(SFNode) }, - { "spatialize", (SFBool, true) } + { Vrml97Sym.direction, (SFVec3f, new V3f(0.0f, 0.0f, 1.0f)) }, + { Vrml97Sym.intensity, (SFFloat, 1.0f) }, + { Vrml97Sym.location, defaultBBoxCenter }, + { Vrml97Sym.maxBack, (SFFloat, 10.0f) }, + { Vrml97Sym.maxFront, (SFFloat, 10.0f) }, + { Vrml97Sym.minBack, (SFFloat, 1.0f) }, + { Vrml97Sym.minFront, (SFFloat, 1.0f) }, + { Vrml97Sym.priority, (SFFloat, 0.0f) }, + { Vrml97Sym.source, fd(SFNode) }, + { Vrml97Sym.spatialize, (SFBool, true) } }); // Sphere s_parseInfoMap[Vrml97NodeName.Sphere] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "radius", (SFFloat, 1.0f) } + { Vrml97Sym.radius, (SFFloat, 1.0f) } }); // SphereSensor s_parseInfoMap[Vrml97NodeName.SphereSensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "autoOffset", (SFBool, true) }, - { "enabled", (SFBool, true) }, - { "offset", (SFRotation, new V4f(0.0f, 1.0f, 0.0f, 0.0f)) } + { Vrml97Sym.autoOffset, (SFBool, true) }, + { Vrml97Sym.enabled, (SFBool, true) }, + { Vrml97Sym.offset, (SFRotation, new V4f(0.0f, 1.0f, 0.0f, 0.0f)) } }); // SpotLight s_parseInfoMap[Vrml97NodeName.SpotLight] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "ambientIntensity", (SFFloat, 0.0f) }, - { "attenuation", (SFVec3f, new V3f(1.0f, 0.0f, 0.0f)) }, - { "beamWidth", (SFFloat, 1.570796f) }, - { "color", (SFColor, C3f.White) }, - { "cutOffAngle", (SFFloat, 0.785398f) }, - { "direction", (SFVec3f, new V3f(0.0f, 0.0f, -1.0f)) }, - { "intensity", (SFFloat, 1.0f) }, - { "location", defaultBBoxCenter }, - { "on", (SFBool, true) }, - { "radius", (SFFloat, 100.0f) } + { Vrml97Sym.ambientIntensity, (SFFloat, 0.0f) }, + { Vrml97Sym.attenuation, (SFVec3f, new V3f(1.0f, 0.0f, 0.0f)) }, + { Vrml97Sym.beamWidth, (SFFloat, 1.570796f) }, + { Vrml97Sym.color, (SFColor, C3f.White) }, + { Vrml97Sym.cutOffAngle, (SFFloat, 0.785398f) }, + { Vrml97Sym.direction, (SFVec3f, new V3f(0.0f, 0.0f, -1.0f)) }, + { Vrml97Sym.intensity, (SFFloat, 1.0f) }, + { Vrml97Sym.location, defaultBBoxCenter }, + { Vrml97Sym.on, (SFBool, true) }, + { Vrml97Sym.radius, (SFFloat, 100.0f) } }); // Switch s_parseInfoMap[Vrml97NodeName.Switch] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "choice", fd(MFNode) }, - { "whichChoice", (SFInt32, -1) } + { Vrml97Sym.choice, fd(MFNode) }, + { Vrml97Sym.whichChoice, (SFInt32, -1) } }); // Text s_parseInfoMap[Vrml97NodeName.Text] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "string", fd(MFString) }, - { "fontStyle", fd(SFNode) }, - { "length", fd(MFFloat) }, - { "maxExtent", (SFFloat, 0.0f) } + { Vrml97Sym.stringSym, fd(MFString) }, + { Vrml97Sym.fontStyle, fd(SFNode) }, + { Vrml97Sym.length, fd(MFFloat) }, + { Vrml97Sym.maxExtent, (SFFloat, 0.0f) } }); // TextureCoordinate s_parseInfoMap[Vrml97NodeName.TextureCoordinate] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "point", fd(MFVec2f) } + { Vrml97Sym.point, fd(MFVec2f) } }); // TextureTransform s_parseInfoMap[Vrml97NodeName.TextureTransform] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "center", (SFVec2f, V2f.Zero) }, - { "rotation", (SFFloat, 0.0f) }, - { "scale", (SFVec2f, new V2f(1.0f, 1.0f)) }, - { "translation", (SFVec2f, V2f.Zero) } + { Vrml97Sym.center, (SFVec2f, V2f.Zero) }, + { Vrml97Sym.rotation, (SFFloat, 0.0f) }, + { Vrml97Sym.scale, (SFVec2f, new V2f(1.0f, 1.0f)) }, + { Vrml97Sym.translation, (SFVec2f, V2f.Zero) } }); // TimeSensor s_parseInfoMap[Vrml97NodeName.TimeSensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "cycleInterval", (SFTime, 1.0f) }, - { "enabled", (SFBool, true) }, - { "loop", (SFBool, false) }, - { "startTime", (SFTime, 0.0f) }, - { "stopTime", (SFTime, 0.0f) } + { Vrml97Sym.cycleInterval, (SFTime, 1.0f) }, + { Vrml97Sym.enabled, (SFBool, true) }, + { Vrml97Sym.loop, (SFBool, false) }, + { Vrml97Sym.startTime, (SFTime, 0.0f) }, + { Vrml97Sym.stopTime, (SFTime, 0.0f) } }); // TouchSensor s_parseInfoMap[Vrml97NodeName.TouchSensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "enabled", (SFBool, true) } + { Vrml97Sym.enabled, (SFBool, true) } }); // Transform s_parseInfoMap[Vrml97NodeName.Transform] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "center", defaultBBoxCenter }, - { "children", fd(MFNode) }, - { "rotation", (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, - { "scale", (SFVec3f, new V3f(1.0f, 1.0f, 1.0f)) }, - { "scaleOrientation", (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, - { "translation", defaultBBoxCenter }, - { "bboxCenter", defaultBBoxCenter }, - { "bboxSize", defaultBBoxSize } + { Vrml97Sym.center, defaultBBoxCenter }, + { Vrml97Sym.children, fd(MFNode) }, + { Vrml97Sym.rotation, (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, + { Vrml97Sym.scale, (SFVec3f, new V3f(1.0f, 1.0f, 1.0f)) }, + { Vrml97Sym.scaleOrientation, (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, + { Vrml97Sym.translation, defaultBBoxCenter }, + { Vrml97Sym.bboxCenter, defaultBBoxCenter }, + { Vrml97Sym.bboxSize, defaultBBoxSize } }); // Viewpoint s_parseInfoMap[Vrml97NodeName.Viewpoint] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "fieldOfView", (SFFloat, 0.785398f) }, - { "jump", (SFBool, true) }, - { "orientation", (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, - { "position", (SFVec3f, new V3f(0.0f, 0.0f, 10.0f)) }, - { "description", fd(SFString) } + { Vrml97Sym.fieldOfView, (SFFloat, 0.785398f) }, + { Vrml97Sym.jump, (SFBool, true) }, + { Vrml97Sym.orientation, (SFRotation, new V4f(0.0f, 0.0f, 1.0f, 0.0f)) }, + { Vrml97Sym.position, (SFVec3f, new V3f(0.0f, 0.0f, 10.0f)) }, + { Vrml97Sym.description, fd(SFString) } }); // VisibilitySensor s_parseInfoMap[Vrml97NodeName.VisibilitySensor] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "center", defaultBBoxCenter }, - { "enabled", (SFBool, true) }, - { "size", defaultBBoxCenter } + { Vrml97Sym.center, defaultBBoxCenter }, + { Vrml97Sym.enabled, (SFBool, true) }, + { Vrml97Sym.size, defaultBBoxCenter } }); // WorldInfo s_parseInfoMap[Vrml97NodeName.WorldInfo] = new NodeParseInfo( new SymbolDict<(FieldParser, object)>() { - { "title", fd(SFString) }, - { "info", fd(MFString) } + { Vrml97Sym.title, fd(SFString) }, + { Vrml97Sym.info, fd(MFString) } }); } private static SymMapBase ParseDEF(Tokenizer t) { var result = new SymMapBase(); - result["name"] = t.NextNameToken().ToString(); - result["node"] = ParseNode(t); + result[Vrml97Sym.name] = t.NextNameToken().ToString(); + result[Vrml97Sym.node] = ParseNode(t); return result; } private static SymMapBase ParseUSE(Tokenizer t) { var result = new SymMapBase(); - result["name"] = t.NextNameToken().ToString(); + result[Vrml97Sym.name] = t.NextNameToken().ToString(); return result; } @@ -812,11 +967,11 @@ private static SymMapBase ParseROUTE(Tokenizer t) var result = new SymMapBase(); // nodeNameId.eventOutId - result["out"] = t.NextNameToken().ToString(); + result[Vrml97Sym.outSym] = t.NextNameToken().ToString(); // "TO" t.NextToken(); // nodeNameId.eventInId - result["in"] = t.NextNameToken().ToString(); + result[Vrml97Sym.inSym] = t.NextNameToken().ToString(); return result; } diff --git a/src/Aardvark.Data.Vrml97/PixTexture.cs b/src/Aardvark.Data.Vrml97/PixTexture.cs deleted file mode 100644 index 1bf5a60..0000000 --- a/src/Aardvark.Data.Vrml97/PixTexture.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Aardvark.Base; -using System; - -namespace Aardvark.Data.Vrml97 -{ - public enum TexRepeatMode - { - Clamped, - Cyclic, - Mirrored, - } - - public struct TexInfo2d - { - public (TexRepeatMode, TexRepeatMode) RepeatMode; - public bool DoMipMap; - - public TexInfo2d(TexRepeatMode repeatModeU, TexRepeatMode repeatModeV, bool doMipMap) - { - RepeatMode = (repeatModeU, repeatModeV); - DoMipMap = doMipMap; - } - public TexInfo2d((TexRepeatMode, TexRepeatMode) repeatMode, bool doMipMap) - { - RepeatMode = repeatMode; - DoMipMap = doMipMap; - } - - public static readonly TexInfo2d CyclicMipMap = - new TexInfo2d(TexRepeatMode.Cyclic, TexRepeatMode.Cyclic, true); - - public static readonly TexInfo2d ClampedMipMap = - new TexInfo2d(TexRepeatMode.Clamped, TexRepeatMode.Clamped, true); - - public static readonly TexInfo2d MirroredMipMap = - new TexInfo2d(TexRepeatMode.Mirrored, TexRepeatMode.Mirrored, true); - - public static readonly TexInfo2d CyclicNoMipMap = - new TexInfo2d(TexRepeatMode.Cyclic, TexRepeatMode.Cyclic, false); - - public static readonly TexInfo2d ClampedNoMipMap = - new TexInfo2d(TexRepeatMode.Clamped, TexRepeatMode.Clamped, false); - - public static readonly TexInfo2d MirroredNoMipMap = - new TexInfo2d(TexRepeatMode.Mirrored, TexRepeatMode.Mirrored, false); - - public static TexInfo2d Create(TexRepeatMode mode, bool doMipMap = true) - { - return new TexInfo2d(mode, mode, doMipMap); - } - } - - public struct TexInfo3d - { - public (TexRepeatMode, TexRepeatMode, TexRepeatMode) RepeatMode; - public bool DoMipMap; - - public TexInfo3d(TexRepeatMode repeatModeU, TexRepeatMode repeatModeV, TexRepeatMode repeatModeW, bool doMipMap) - { - RepeatMode = (repeatModeU, repeatModeV, repeatModeW); - DoMipMap = doMipMap; - } - public TexInfo3d((TexRepeatMode, TexRepeatMode, TexRepeatMode) repeatMode, bool doMipMap) - { - RepeatMode = repeatMode; - DoMipMap = doMipMap; - } - } - - //[Flags] - //public enum CubeSide - //{ - // PositiveX = 0, - // NegativeX = 1, - // PositiveY = 2, - // NegativeY = 3, - // PositiveZ = 4, - // NegativeZ = 5, - //} - - public interface IPixTexture - { - } - - public class Texture2d : IPixTexture - { - public readonly Func PixMipMapFun; - public readonly TexInfo2d TexInfo; - - #region Constructor - - public Texture2d(Func pixMipMapFun, TexInfo2d texInfo) - { - PixMipMapFun = pixMipMapFun; - TexInfo = texInfo; - } - - #endregion - } - - public class FileTexture2d : Texture2d - { - public readonly string Path; - - #region Constructor - - public FileTexture2d(string path, TexInfo2d texInfo) - : base(() => LoadFun(path), texInfo) - { - Path = path; - } - - private static volatile Func[] s_loadFunArray = null; - private static object s_loadFunArrayLock = new object(); - - public static void RegisterLoadFun(Func loadFun) - { - lock (s_loadFunArrayLock) - { - s_loadFunArray = s_loadFunArray.WithAdded(loadFun); - } - } - - public static IPixMipMap2d LoadFun(string s) - { - var loadFunArray = s_loadFunArray; - int funIndex = loadFunArray.Length; - while (--funIndex >= 0) - { - var result = loadFunArray[funIndex](s); - if (result != null) return result; - } - throw new ArgumentException(String.Format("could not load image \"{0}\"", s)); - } - - #endregion - - } - - - public class Texture3d : IPixTexture - { - public readonly Func PixMipMapFun; - public readonly TexInfo3d TexInfo; - - #region Constructor - - public Texture3d(Func pixMipMapFun, TexInfo3d texInfo) - { - PixMipMapFun = pixMipMapFun; - TexInfo = texInfo; - } - - #endregion - } - - - public class TextureCube2d : IPixTexture - { - public Func PixCubeFun; - public TexInfo2d TexInfo; - - #region Constructor - - public TextureCube2d(Func pixCubeFun, TexInfo2d texInfo) - { - PixCubeFun = pixCubeFun; - TexInfo = texInfo; - } - - #endregion - } - -} diff --git a/src/Aardvark.Data.Vrml97/PolyMeshFromVrml97.cs b/src/Aardvark.Data.Vrml97/PolyMeshFromVrml97.cs index 9609d63..2525054 100644 --- a/src/Aardvark.Data.Vrml97/PolyMeshFromVrml97.cs +++ b/src/Aardvark.Data.Vrml97/PolyMeshFromVrml97.cs @@ -20,65 +20,22 @@ public enum Options SkipDegenerateFaces = 0x08, PreMultiplyTransform = 0x10, - PreMultiplyTextureTransform = 0x20, TryFixSpecViolations = 0x100, IgnorePresentNormals = 0x200, - FixTextureWrapping = 0x400, - IgnoreTextures = 0x800, NoVertexColorsFromMaterial = 0x1000, AddPerFaceNormalsAndPreMultiplyTransform = - AddPerFaceNormals | PreMultiplyTransform | PreMultiplyTextureTransform, + AddPerFaceNormals | PreMultiplyTransform , AddCreaseNormalsAndPreMultiplyTransform = - AddPerFaceNormals | PreMultiplyTransform | PreMultiplyTextureTransform, + AddPerFaceNormals | PreMultiplyTransform, StandardSettings = AddCreaseNormalsAndPreMultiplyTransform | SkipDegenerateFaces, } - public static partial class Vrml97Property - { - public static readonly Symbol ccw = "ccw"; - public static readonly Symbol color = "color"; - public static readonly Symbol colorIndex = "colorIndex"; - public static readonly Symbol colorPerVertex = "colorPerVertex"; - public static readonly Symbol convex = "convex"; - public static readonly Symbol coord = "coord"; - public static readonly Symbol coordIndex = "coordIndex"; - public static readonly Symbol creaseAngle = "creaseAngle"; - public static readonly Symbol DEFname = "DEFname"; - public static readonly Symbol normal = "normal"; - public static readonly Symbol normalIndex = "normalIndex"; - public static readonly Symbol normalPerVertex = "normalPerVertex"; - public static readonly Symbol diffuseColor = "diffuseColor"; - public static readonly Symbol material = "material"; - public static readonly Symbol point = "point"; - public static readonly Symbol repeatS = "repeatS"; - public static readonly Symbol repeatT = "repeatT"; - public static readonly Symbol repeatU = "repeatU"; - public static readonly Symbol repeatV = "repeatV"; - public static readonly Symbol solid = "solid"; - public static readonly Symbol texture = "texture"; - public static readonly Symbol texCoord = "texCoord"; - public static readonly Symbol texCoordIndex = "texCoordIndex"; - public static readonly Symbol textureTransform = "textureTransform"; - public static readonly Symbol transform = "transform"; - public static readonly Symbol transparency = "transparency"; - public static readonly Symbol url = "url"; - public static readonly Symbol vector = "vector"; - } - - public static readonly Symbol[] Vrml97SingleAttributeNames = new[] - { - Vrml97Property.material, - Vrml97Property.texture, - // Vrml97Property.textureTransform, - // Vrml97Property.transform, - }; - public static PolyMesh CreateFromIfs(SymMapBase ifs) { return CreateFromIfs( @@ -110,34 +67,28 @@ Options options * MFInt32 texCoordIndex [] # [-1,) * } */ - SymMapBase color = ifs.Get(Vrml97Property.color); - SymMapBase coord = ifs.Get(Vrml97Property.coord); - SymMapBase normal = ifs.Get(Vrml97Property.normal); - SymMapBase texCoord = ifs.Get(Vrml97Property.texCoord); - SymMapBase texture = ifs.Get(Vrml97Property.texture); - bool ccw = ifs.Get(Vrml97Property.ccw, true); - var colorIndex = ifs.Get>(Vrml97Property.colorIndex); - bool colorPerVertex = ifs.Get(Vrml97Property.colorPerVertex, true); - bool convex = ifs.Get(Vrml97Property.convex, true); - var coordIndex = ifs.Get>(Vrml97Property.coordIndex); - float creaseAngle = ifs.Get(Vrml97Property.creaseAngle, 0.0f); - var normalIndex = ifs.Get>(Vrml97Property.normalIndex); - bool normalPerVertex = ifs.Get(Vrml97Property.normalPerVertex, true); - bool solid = ifs.Get(Vrml97Property.solid, true); - var texCoordIndex = ifs.Get>(Vrml97Property.texCoordIndex); + SymMapBase color = ifs.Get(Vrml97Sym.color); + SymMapBase coord = ifs.Get(Vrml97Sym.coord); + SymMapBase normal = ifs.Get(Vrml97Sym.normal); + SymMapBase texCoord = ifs.Get(Vrml97Sym.texCoord); + bool ccw = ifs.Get(Vrml97Sym.ccw, true); + var colorIndex = ifs.Get>(Vrml97Sym.colorIndex); + bool colorPerVertex = ifs.Get(Vrml97Sym.colorPerVertex, true); + bool convex = ifs.Get(Vrml97Sym.convex, true); + var coordIndex = ifs.Get>(Vrml97Sym.coordIndex); + float creaseAngle = ifs.Get(Vrml97Sym.creaseAngle, 0.0f); + var normalIndex = ifs.Get>(Vrml97Sym.normalIndex); + bool normalPerVertex = ifs.Get(Vrml97Sym.normalPerVertex, true); + bool solid = ifs.Get(Vrml97Sym.solid, true); + var texCoordIndex = ifs.Get>(Vrml97Sym.texCoordIndex); bool skipDegenerates = (options & Options.SkipDegenerateFaces) != 0; bool addPerFaceNormals = (options & Options.AddPerFaceNormals) != 0; bool addCreaseNormals = (options & Options.AddCreaseNormals) != 0; bool ignorePresentNormals = (options & Options.IgnorePresentNormals) != 0; - bool fixTextureWrapping = (options & Options.FixTextureWrapping) != 0; - bool ignoreTextures = (options & Options.IgnoreTextures) != 0; - bool forceNoTextureWrapping = false; bool performCreateNormals = false; bool preMultiplyTransform = (options & Options.PreMultiplyTransform) != 0; - bool preMultiplyTextureTransform - = (options & Options.PreMultiplyTextureTransform) != 0; if ((options & Options.ReverseTriangles) != 0) ccw = !ccw; @@ -153,13 +104,13 @@ bool preMultiplyTextureTransform "Vrml97 spec violation!" + "IndexedFaceSet node: field 'coord' MUST NOT be null." ); - if (!coord.Contains(Vrml97Property.point)) + if (!coord.Contains(Vrml97Sym.point)) throw new Exception( "Vrml97 spec violation!" + "Coordinate node: field 'coord' MUST NOT be null." ); - List vertexPositionList = coord.Get>(Vrml97Property.point); + List vertexPositionList = coord.Get>(Vrml97Sym.point); int vertexCount = vertexPositionList.Count; if (vertexCount == 0) @@ -170,9 +121,9 @@ bool preMultiplyTextureTransform var positionArray = new V3d[vertexCount]; - if (ifs.Contains(Vrml97Property.transform)) + if (ifs.Contains(Vrml97Sym.transform)) { - Trafo3d trafo = ifs.Get(Vrml97Property.transform, Trafo3d.Identity); + Trafo3d trafo = ifs.Get(Vrml97Sym.transform, Trafo3d.Identity); if (preMultiplyTransform) { M44d mat = trafo.Forward; @@ -348,7 +299,7 @@ bool preMultiplyTextureTransform "Color node: field 'color' MUST NOT be null." ); - List colorList = color.Get>(Vrml97Property.color); + List colorList = color.Get>(Vrml97Sym.color); if (colorPerVertex == false) { @@ -489,11 +440,11 @@ var colorArray "Normal node: field 'vector' MUST NOT be null." ); - List normalList = normal.Get>(Vrml97Property.vector); + List normalList = normal.Get>(Vrml97Sym.vector); - if (preMultiplyTransform && ifs.Contains(Vrml97Property.transform)) + if (preMultiplyTransform && ifs.Contains(Vrml97Sym.transform)) { - Trafo3d trafo = ifs.Get(Vrml97Property.transform, Trafo3d.Identity); + Trafo3d trafo = ifs.Get(Vrml97Sym.transform, Trafo3d.Identity); M44d transposedInverse = trafo.Backward.Transposed; int imax = normalList.Count; @@ -630,8 +581,8 @@ var colorArray * creaseAngle to determine if and how normals are smoothed * across shared vertices (see 4.6.3.5, Crease angle field). */ - // if (addPerFaceNormals || addCreaseNormals) - // performCreateNormals = true; + if (addPerFaceNormals || addCreaseNormals) + performCreateNormals = true; } #endregion @@ -647,65 +598,20 @@ var colorArray * node are applied to the vertices of the IndexedFaceSet * as follows: */ - if ((texCoord != null) && (ignoreTextures == false)) + if (texCoord != null) { - Func texTrafo = v => v; - - if (ifs.Contains(Vrml97Property.textureTransform)) - { - Trafo2d trafo = ifs.Get(Vrml97Property.textureTransform, - Trafo2d.Identity); - if (preMultiplyTransform) - { - texTrafo = v => (V2f)Mat.TransformPos(trafo.Forward, (V2d)v); - } - else - { - m.InstanceAttributes[PolyMesh.Property.DiffuseColorTrafo2d] = trafo; - } - } - - if (!texCoord.Contains(Vrml97Property.point)) + if (!texCoord.Contains(Vrml97Sym.point)) throw new Exception( "Vrml97 spec violation!" + "TextureCoordinate node: field 'point' MUST NOT be null." ); // texCoord array (from texCoord node) - var texCoordList = texCoord.Get>(Vrml97Property.point); - + var texCoordList = texCoord.Get>(Vrml97Sym.point); int texCoordCount = texCoordList.Count; - // remap is only required if asked for. will be set to false if encountered triangles are incompatible. - bool remapTCs = fixTextureWrapping; - // clamp texture coordinates if we know repeatU/V is false - bool clampU = false; - bool clampV = false; - if (texture != null) - { - if (!texture.Get(Vrml97Property.repeatU, true)) - clampU = true; - if (!texture.Get(Vrml97Property.repeatV, true)) - clampV = true; - } - for (int i = 0; i < texCoordList.Count; i++) - { - var tc = texCoordList[i]; - // clip precision - tc.X = (float)(Fun.Floor(tc.X * (double)10000) / 10000); - // clip precision - tc.Y = (float)(Fun.Floor(tc.Y * (double)10000) / 10000); - if (clampU) tc.X = Fun.Clamp(tc.X, 0.0f, 1.0f); - if (clampV) tc.Y = Fun.Clamp(tc.Y, 0.0f, 1.0f); - texCoordList[i] = tc; - } - - var tcBounds = new Box2f(texCoordList); - var tcMin = tcBounds.Min; - var tcMax = tcBounds.Max; - tcMin = new V2f(Fun.Floor(tcMin.X), Fun.Floor(tcMin.Y)); - if (!Box2f.Unit.Contains(tcMax - tcMin)) - remapTCs = false; + // map texture coordinates to Aardvark texture coordinate system (flip Y) + var texCoordArray = texCoordList.MapToArray(crd => new V2f(crd.X, 1 - crd.Y)).ToArray(); // if texCoordIndex is empty, then the coordIndex array is used to choose texture coordinates. if (texCoordIndex == null) @@ -746,8 +652,6 @@ var colorArray for (int xbi = xi - 1, i = 0; i < fvc; i++) texCoordIndexArray[vii++] = texCoordIndex[xbi - i]; } - remapTCs = remapTCs - && TexCoordsRemappable(texCoordList, texCoordIndex, xi - fvc, fvc); } ++vrmlFaceIndex; fvc = 0; @@ -757,7 +661,6 @@ var colorArray } m.FaceVertexAttributes[PolyMesh.Property.DiffuseColorCoordinates] = texCoordIndexArray; - /* * and shall contain end-of-face markers (-1) in exactly * the same places as the coordIndex field. @@ -810,34 +713,10 @@ var colorArray } } - /* ..., then it is used to choose texture coordinates for - * each vertex of the IndexedFaceSet in exactly the same - * manner that the coordIndex field is used to choose - * coordinates for each vertex from the Coordinate node. - */ - forceNoTextureWrapping = remapTCs; - - Func texFun; - if (remapTCs) - texFun = (V2f t) => texTrafo(new V2f(t.X - tcMin.X, 1.0f - t.Y - tcMin.Y)); - else - texFun = (V2f t) => texTrafo(new V2f(t.X, 1.0f - t.Y)); - - var texCoordArray = texCoordList.MapToArray(texCoordCount, texFun); - m.FaceVertexAttributes[-PolyMesh.Property.DiffuseColorCoordinates] = texCoordArray; } else { - forceNoTextureWrapping = remapTCs; - - Func texFun; - if (remapTCs) - texFun = (V2f t) => texTrafo(new V2f(t.X - tcMin.X, 1.0f - t.Y - tcMin.Y)); - else - texFun = (V2f t) => texTrafo(new V2f(t.X, 1.0f - t.Y)); - - var texCoordArray = texCoordList.MapToArray(texCoordCount, texFun); m.VertexAttributes[PolyMesh.Property.DiffuseColorCoordinates] = texCoordArray; } @@ -857,11 +736,9 @@ var colorArray * the ratio of the second greatest dimension of the * bounding box to the greatest dimension. */ - if (ifs.Contains("texture")) // texture annotation? - { - // [future cleanup ISSUE 20080209 rft] unimplented VRML spec - // throw new NotImplementedException(); - } + + // [TODO] unimplented VRML spec + // throw new NotImplementedException(); } #endregion @@ -872,101 +749,27 @@ var colorArray { if ((options & Options.AddPerFaceNormals) != 0) { - // m.AddTriangleNormals(); + m.AddPerFaceNormals(); } if ((options & Options.AddCreaseNormals) != 0) { - // m.AddPerVertexIndexedNormals(creaseAngle); + m = m.WithPerVertexIndexedNormals(creaseAngle); } } #endregion - #region Texture - - // ------------------------------------ semantic texture creation - if ((texture != null) && (ignoreTextures == false)) - { - string fileName = texture.Get>(Vrml97Property.url)[0]; - - if (File.Exists(fileName)) - { - var repeatS = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatS) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - var repeatT = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatT) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - - m.InstanceAttributes[PolyMesh.Property.DiffuseColorTexture] - = new FileTexture2d(fileName, new TexInfo2d((repeatS, repeatT), true)); - } - else - { - Report.Warn("MeshFromVrml97: texture '{0}' not found", fileName); - } - - #region check for normal map texture - string normalMapFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + "_n" + Path.GetExtension(fileName)); - if (!File.Exists(normalMapFileName)) - normalMapFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + "_n.png"); - if (File.Exists(normalMapFileName)) - { - Report.Line(5, "MeshFromVrml97: loading normal map texture '{0}'", normalMapFileName); - - var repeatS = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatS) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - var repeatT = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatT) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - - m.InstanceAttributes[PolyMesh.Property.NormalMapTexture] - = new FileTexture2d(fileName, new TexInfo2d((repeatS, repeatT), false)); - // TODO// copy texture coordinates for separate packing - //m.AddAttributeSet(Mesh.Property.NormalMapCoordinates, m.GetAttributeSet(Mesh.Property.DiffuseColorCoordinates).Copy()); - - //// normal map also requires tangent space vectors - //IAttributeSet tan, bin; - //Report.Line(5, "MeshFromVrml97: calculating tangent space for normal map ..."); - //if ((options & FromVrml97Options.FloatNormals) != 0) - // m.ComputePerVertexTangentsAndBiNormals(m.DiffuseColorCoordinates, out tan, out bin); - //else - // m.ComputePerVertexTangentsAndBiNormals(m.DiffuseColorCoordinates, out tan, out bin); - } - #endregion - - #region check for luminance map texture - string lightMapFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + "_i" + Path.GetExtension(fileName)); - if (!File.Exists(lightMapFileName)) - lightMapFileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + "_i.png"); - - if (File.Exists(lightMapFileName)) - { - Report.Line(5, "MeshFromVrml97: loading light map texture '{0}'", lightMapFileName); - - var repeatS = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatS) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - var repeatT = forceNoTextureWrapping ? TexRepeatMode.Clamped - : texture.Get(Vrml97Property.repeatT) ? TexRepeatMode.Cyclic : TexRepeatMode.Clamped; - - m.InstanceAttributes[PolyMesh.Property.LightMapTexture] - = new FileTexture2d(lightMapFileName, new TexInfo2d((repeatS, repeatT), false)); - - // TODO: Copy Attribute DiffuseColorCoordinates to LightMapCoordinates - } - #endregion - } - - #endregion - #region Instance Color from Material - var material = ifs.Get(Vrml97Property.material); + var material = ifs.Get(Vrml97Sym.material); if (material != null) { if (!m.HasColors && (options & Options.NoVertexColorsFromMaterial) == 0) { - var opacity = 1 - material.Get(Vrml97Property.transparency); - var diffuse = material.Get(Vrml97Property.diffuseColor); + var opacity = 1 - material.Get(Vrml97Sym.transparency); + var diffuse = material.Get(Vrml97Sym.diffuseColor); m.InstanceAttributes[PolyMesh.Property.Colors] = new C4f(diffuse.R, diffuse.G, diffuse.B, opacity); } @@ -976,35 +779,25 @@ var colorArray #region Instance Attributes - if (ifs.Contains(Vrml97Property.creaseAngle)) + // store name, creaseAngle, windingOrder and solid attributes as PolyMesh instance attributes + + if (ifs.Contains(Vrml97Sym.creaseAngle)) m.InstanceAttributes[PolyMesh.Property.CreaseAngle] = creaseAngle; - - m.InstanceAttributes[PolyMesh.Property.WindingOrder] = !ifs.Contains(Vrml97Property.ccw) ? ccw ? + + if (ifs.Contains(Vrml97Sym.solid)) + m.InstanceAttributes[Vrml97Sym.solid] = solid; + + m.InstanceAttributes[PolyMesh.Property.WindingOrder] = !ifs.Contains(Vrml97Sym.ccw) ? ccw ? PolyMesh.WindingOrder.Undefined : PolyMesh.WindingOrder.CounterClockwise : PolyMesh.WindingOrder.Clockwise; - + // add name for string definition of the vertex geometry - var DefName = ifs.Get(Vrml97Property.DEFname); + var DefName = ifs.Get(Vrml97Sym.DEFname); if (DefName != null) m.InstanceAttributes[PolyMesh.Property.Name] = DefName; - // NOTE: copies material node as single attirbute - foreach (var name in Vrml97SingleAttributeNames) - { - if (ifs.Contains(name)) - m.InstanceAttributes[name] = ifs[name]; - } - #endregion return m; } - - static bool TexCoordsRemappable(List tcl, List il, int start, int count) - { - Box2f bb = Box2f.Invalid; - for (int i = start; i < start + count; i++) bb.ExtendBy(tcl[il[i]]); - bb = bb.Translated(new V2f(-Fun.Floor(bb.Min.X), -Fun.Floor(bb.Min.Y))); - return Box2f.Unit.Contains(bb.Max); - } } } diff --git a/src/Aardvark.Data.Vrml97/SceneLoader.cs b/src/Aardvark.Data.Vrml97/SceneLoader.cs index 6309c1f..f61ab0c 100644 --- a/src/Aardvark.Data.Vrml97/SceneLoader.cs +++ b/src/Aardvark.Data.Vrml97/SceneLoader.cs @@ -17,7 +17,7 @@ public class SceneLoader public static VrmlScene Load(string filename) { Report.BeginTimed("parsing vrml"); - var vrmlParseTree = Vrml97Scene.FromFile(filename, true, false, false); + var vrmlParseTree = Vrml97Scene.FromFile(filename); Report.End(); Report.BeginTimed("creating scene graph"); var scene = new SceneLoader().Perform(vrmlParseTree); @@ -109,7 +109,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Transform"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Transform] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -129,7 +129,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Group"] = trav.PerNameVisitors["Collision"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Group] = trav.PerNameVisitors[Vrml97NodeName.Collision] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -149,7 +149,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Switch"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Switch] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -167,7 +167,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Shape"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Shape] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -186,7 +186,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["IndexedFaceSet"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.IndexedFaceSet] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -201,7 +201,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Box"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Box] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -216,7 +216,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Sphere"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Sphere] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -231,7 +231,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["Cone"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Cone] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -247,7 +247,7 @@ VrmlScene Perform(Vrml97Scene root) }; - trav.PerNameVisitors["Cylinder"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.Cylinder] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -262,7 +262,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["PointLight"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.PointLight] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -273,7 +273,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["SpotLight"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.SpotLight] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { @@ -284,7 +284,7 @@ VrmlScene Perform(Vrml97Scene root) return returnFunc(map, visit); }; - trav.PerNameVisitors["DirectionalLight"] = (map, visit) => + trav.PerNameVisitors[Vrml97NodeName.DirectionalLight] = (map, visit) => { if ((visit & SymMapBaseTraversal.Visit.Pre) != 0) { diff --git a/src/Aardvark.Data.Vrml97/Vrml97Scene.cs b/src/Aardvark.Data.Vrml97/Vrml97Scene.cs index cc750a2..f3514ad 100644 --- a/src/Aardvark.Data.Vrml97/Vrml97Scene.cs +++ b/src/Aardvark.Data.Vrml97/Vrml97Scene.cs @@ -13,24 +13,14 @@ public class Vrml97Scene private SymMapBase m_parseTree; private Dictionary m_namedNodes; - /// - /// Creates a Vrml97Scene from given VRML97 file. - /// Supports text based and Gzip compressed files. - /// Gzip is detected independent of the file extension by checking if the file contains a gzip header. - /// - public static Vrml97Scene FromFile(string fileName) => FromFile(fileName, true, true); - /// /// Creates a Vrml97Scene from given VRML97 file. /// Supports text based and Gzip compressed files. /// Gzip is detected independent of the file extension by checking if the file contains a gzip header. /// /// file name - /// - /// - /// /// Parsed Vrml97 scene - public static Vrml97Scene FromFile(string fileName, bool resolveDefUse, bool annotate, bool duplicateDefUseMaps = true) + public static Vrml97Scene FromFile(string fileName) { if (fileName == null) return null; using var fileStream = new FileStream( @@ -50,7 +40,7 @@ public static Vrml97Scene FromFile(string fileName, bool resolveDefUse, bool ann fileStream.Position = 0; var inputStream = h1 == 0x1f && h2 == 0x8b ? (Stream)new GZipStream(fileStream, CompressionMode.Decompress, true) : fileStream; - return Parse(new Parser.State(inputStream, fileName), resolveDefUse, annotate, duplicateDefUseMaps); + return Parse(new Parser.State(inputStream, fileName)); } /// @@ -60,7 +50,7 @@ public static Vrml97Scene FromFile(string fileName, bool resolveDefUse, bool ann /// Optional filename used to build absolute texture file paths /// Parsed Vrml97 scene public static Vrml97Scene FromStream(Stream stream, string fileName) - => Parse(new Parser.State(stream, fileName), true, true); + => Parse(new Parser.State(stream, fileName)); /// /// Constructor. @@ -159,15 +149,11 @@ in SymMapBaseCollectionTraversal.Collect(ParseTree, "TimeSensor")) /// public Dictionary NamedNodes => m_namedNodes; - private static Vrml97Scene Parse(Parser.State parser, bool resolveDefUse, bool annotate, bool duplicateMaps = true) + private static Vrml97Scene Parse(Parser.State parser) { var root = parser.Perform(); - if (resolveDefUse) - root = DefUseResolver.Resolve(root, out root.m_namedNodes, duplicateMaps); - - if (annotate) - root = AttributeAnnotator.Annotate(root); + root = DefUseResolver.Resolve(root, out root.m_namedNodes); return root; } diff --git a/src/Aardvark.Data.Vrml97/VrmlHelpers.cs b/src/Aardvark.Data.Vrml97/VrmlHelpers.cs new file mode 100644 index 0000000..6ac5ad0 --- /dev/null +++ b/src/Aardvark.Data.Vrml97/VrmlHelpers.cs @@ -0,0 +1,97 @@ +using Aardvark.Base; + +namespace Aardvark.Data.Vrml97 +{ + /// + /// Various helper methods. + /// + public static class VrmlHelpers + { + /// + /// Build a texture coordinate transformation from the given parameters as specified in TextureTransform + /// http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html#TextureTransform + /// + public static Trafo2d BuildVrmlTextureTrafo(V2d center, double rotation, V2d scale, V2d translation) + { + M33d C = M33d.Translation(center), Ci = M33d.Translation(-center); + M33d R = M33d.Rotation(rotation), Ri = M33d.Rotation(-rotation); + M33d S = M33d.Scale(scale), Si = M33d.Scale(1 / scale); + M33d T = M33d.Translation(translation), Ti = M33d.Translation(-translation); + + return new Trafo2d( + Ci * S * R * C * T, + Ti * Ci * Ri * Si * C); + } + + /// + /// Extracts texture transform from given node. + /// + public static Trafo2d ExtractVrmlTextureTrafo(this SymMapBase m) + { + if (m == null) return Trafo2d.Identity; + + // get trafo parts + var c = (V2d)m.Get(Vrml97Sym.center, V2f.Zero); + var r = (double)m.Get(Vrml97Sym.rotation, 0.0f); + var s = (V2d)m.Get(Vrml97Sym.scale, new V2f(1, 1)); + var t = (V2d)m.Get(Vrml97Sym.translation, V2f.Zero); + + M33d C = M33d.Translation(c), Ci = M33d.Translation(-c); + M33d R = M33d.Rotation(r), Ri = M33d.Rotation(-r); + M33d S = M33d.Scale(s), Si = M33d.Scale(1 / s); + M33d T = M33d.Translation(t), Ti = M33d.Translation(-t); + + return new Trafo2d( + Ci * S * R * C * T, + Ti * Ci * Ri * Si * C); + } + + /// + /// Build a geometry transformation from the given parameters as specified in Transform + /// http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html#Transform + /// + public static Trafo3d BuildVrmlGeometryTrafo(V3d center, V4d rotation, V3d scale, V4d scaleOrientation, V3d translation) + { + // create composite trafo (naming taken from vrml97 spec) + M44d C = M44d.Translation(center), Ci = M44d.Translation(-center); + var scaleRotAxis = scaleOrientation.XYZ.Normalized; // NOTE: values in the vrml (limited number of digits) are often not normalized + M44d SR = M44d.Rotation(scaleRotAxis, scaleOrientation.W), SRi = M44d.Rotation(scaleRotAxis, -scaleOrientation.W); + M44d T = M44d.Translation(translation), Ti = M44d.Translation(-translation); + + //if (m_aveCompatibilityMode) r.W = -r.W; + var rotationAxis = rotation.XYZ.Normalized; // NOTE: values in the vrml (limited number of digits) are often not normalized + M44d R = M44d.Rotation(rotationAxis, rotation.W), Ri = M44d.Rotation(rotationAxis, -rotation.W); + + // in case some axis scales by 0 the best thing for the inverse scale is also 0 + var si = new V3d(scale.X.IsTiny() ? 0 : 1 / scale.X, + scale.Y.IsTiny() ? 0 : 1 / scale.Y, + scale.Z.IsTiny() ? 0 : 1 / scale.Z); + M44d S = M44d.Scale(scale), Si = M44d.Scale(si); + + return new Trafo3d( + T * C * R * SR * S * SRi * Ci, + C * SR * Si * SRi * Ri * Ci * Ti); + } + + /// + /// Returns geometry transform from given node. + /// + public static Trafo3d ExtractVrmlGeometryTrafo(this SymMapBase m) + { + // get trafo parts + var c = (V3d)m.Get(Vrml97Sym.center, V3f.Zero); + + var r = (V4d)m.Get(Vrml97Sym.rotation, V4f.Zero); + if (r.X == 0 && r.Y == 0 && r.Z == 0) r.Z = 1; + + var s = (V3d)m.Get(Vrml97Sym.scale, new V3f(1, 1, 1)); + + var sr = (V4d)m.Get(Vrml97Sym.scaleOrientation, V4f.Zero); + if (sr.X == 0 && sr.Y == 0 && sr.Z == 0) sr.Z = 1; + + var t = (V3d)m.Get(Vrml97Sym.translation, V3f.Zero); + + return BuildVrmlGeometryTrafo(c, r, s, sr, t); + } + } +} diff --git a/src/Aardvark.Data.Vrml97/VrmlNodeTypes.cs b/src/Aardvark.Data.Vrml97/VrmlNodeTypes.cs index fafc465..5c371b7 100644 --- a/src/Aardvark.Data.Vrml97/VrmlNodeTypes.cs +++ b/src/Aardvark.Data.Vrml97/VrmlNodeTypes.cs @@ -212,7 +212,6 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion - } public class VrmlBox : VrmlGeometry @@ -221,7 +220,7 @@ public class VrmlBox : VrmlGeometry internal override void Init(SymMapBase map) { - Size = map.Get((Symbol)"size", new V3f(2, 2, 2)); + Size = map.Get(Vrml97Sym.size, new V3f(2, 2, 2)); base.Init(map); } @@ -236,7 +235,6 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion - } public class VrmlSphere : VrmlGeometry @@ -245,7 +243,7 @@ public class VrmlSphere : VrmlGeometry internal override void Init(SymMapBase map) { - Radius = map.Get((Symbol)"radius", 1.0f); + Radius = map.Get(Vrml97Sym.radius, 1.0f); base.Init(map); } @@ -260,7 +258,6 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion - } public class VrmlCone : VrmlGeometry @@ -272,10 +269,10 @@ public class VrmlCone : VrmlGeometry internal override void Init(SymMapBase map) { - BottomRadius = map.Get((Symbol)"bottomRadius", 1); - Height = map.Get((Symbol)"height", 2); - Side = map.Get((Symbol)"side", true); - Bottom = map.Get((Symbol)"bottom", true); + BottomRadius = map.Get(Vrml97Sym.bottomRadius, 1); + Height = map.Get(Vrml97Sym.height, 2); + Side = map.Get(Vrml97Sym.side, true); + Bottom = map.Get(Vrml97Sym.bottom, true); base.Init(map); } @@ -292,7 +289,6 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion - } public class VrmlCylinder : VrmlGeometry @@ -305,11 +301,11 @@ public class VrmlCylinder : VrmlGeometry internal override void Init(SymMapBase map) { - Bottom = map.Get((Symbol)"bottom", true); - Height = map.Get((Symbol)"height", 2); - Radius = map.Get((Symbol)"radius", 1); - Side = map.Get((Symbol)"side", true); - Top = map.Get((Symbol)"top", true); + Bottom = map.Get(Vrml97Sym.bottom, true); + Height = map.Get(Vrml97Sym.height, 2); + Radius = map.Get(Vrml97Sym.radius, 1); + Side = map.Get(Vrml97Sym.side, true); + Top = map.Get(Vrml97Sym.top, true); base.Init(map); } @@ -327,7 +323,6 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion - } public abstract class VrmlLight : VrmlNode @@ -339,10 +334,10 @@ public abstract class VrmlLight : VrmlNode internal override void Init(SymMapBase map) { - AmbientIntensity = map.Get((Symbol)"ambientIntensity", 0.0f); - Color = map.Get((Symbol)"color", C3f.White); - Intensity = map.Get((Symbol)"intensity", 1); - IsOn = map.Get((Symbol)"on", true); + AmbientIntensity = map.Get(Vrml97Sym.ambientIntensity, 0.0f); + Color = map.Get(Vrml97Sym.color, C3f.White); + Intensity = map.Get(Vrml97Sym.intensity, 1); + IsOn = map.Get(Vrml97Sym.on, true); base.Init(map); } @@ -375,12 +370,12 @@ public VrmlSpotLight() { } internal override void Init(SymMapBase map) { - Attenuation = map.Get((Symbol)"attenuation", V3f.IOO); - BeamWidth = map.Get((Symbol)"beamWidth", (float)Constant.PiHalf); - CutOffAngle = map.Get((Symbol)"cutOffAngle", (float)Constant.PiQuarter); - Direction = map.Get((Symbol)"direction", -V3f.OOI); - Location = map.Get((Symbol)"location", V3f.OOO); - Radius = map.Get((Symbol)"radius", 1); + Attenuation = map.Get(Vrml97Sym.attenuation, V3f.IOO); + BeamWidth = map.Get(Vrml97Sym.beamWidth, (float)Constant.PiHalf); + CutOffAngle = map.Get(Vrml97Sym.cutOffAngle, (float)Constant.PiQuarter); + Direction = map.Get(Vrml97Sym.direction, -V3f.OOI); + Location = map.Get(Vrml97Sym.location, V3f.OOO); + Radius = map.Get(Vrml97Sym.radius, 1); base.Init(map); } @@ -410,7 +405,7 @@ public VrmlDirectionalLight() { } internal override void Init(SymMapBase map) { - Direction = map.Get((Symbol)"direction", -V3f.OOI); + Direction = map.Get(Vrml97Sym.direction, -V3f.OOI); base.Init(map); } @@ -437,9 +432,9 @@ public VrmlPointLight() { } internal override void Init(SymMapBase map) { - Attenuation = map.Get((Symbol)"attenuation", V3f.IOO); - Location = map.Get((Symbol)"location", V3f.OOO); - Radius = map.Get((Symbol)"radius", 1f); + Attenuation = map.Get(Vrml97Sym.attenuation, V3f.IOO); + Location = map.Get(Vrml97Sym.location, V3f.OOO); + Radius = map.Get(Vrml97Sym.radius, 1f); base.Init(map); } @@ -475,11 +470,11 @@ public VrmlTransform() { } internal override void Init(SymMapBase map) { - Center = map.Get((Symbol)"center"); - Rotation = map.Get((Symbol)"rotation"); - ScaleRotation = map.Get((Symbol)"scaleOrientation"); - Scale = map.Get((Symbol)"scale"); - Translation = map.Get((Symbol)"translation"); + Center = map.Get(Vrml97Sym.center); + Rotation = map.Get(Vrml97Sym.rotation); + ScaleRotation = map.Get(Vrml97Sym.scaleOrientation); + Scale = map.Get(Vrml97Sym.scale); + Translation = map.Get(Vrml97Sym.translation); base.Init(map); } @@ -509,7 +504,7 @@ public VrmlSwitch() { } internal override void Init(SymMapBase map) { - SelectionIndex = map.Get((Symbol)"whichChoice"); + SelectionIndex = map.Get(Vrml97Sym.whichChoice); base.Init(map); } @@ -569,12 +564,12 @@ public VrmlMaterial() { } internal override void Init(SymMapBase map) { - DiffuseColor = map.Get((Symbol)"diffuseColor"); - EmissiveColor = map.Get((Symbol)"emissiveColor"); - SpecularColor = map.Get((Symbol)"specularColor"); - AmbientIntensity = map.Get((Symbol)"ambientIntensity"); - Opacity = 1 - map.Get((Symbol)"transparency"); - Shininess = map.Get((Symbol)"shininess"); + DiffuseColor = map.Get(Vrml97Sym.diffuseColor); + EmissiveColor = map.Get(Vrml97Sym.emissiveColor); + SpecularColor = map.Get(Vrml97Sym.specularColor); + AmbientIntensity = map.Get(Vrml97Sym.ambientIntensity); + Opacity = 1 - map.Get(Vrml97Sym.transparency); + Shininess = map.Get(Vrml97Sym.shininess); base.Init(map); } @@ -605,8 +600,8 @@ public VrmlPositionInterpolator() { } internal override void Init(SymMapBase map) { - Key = map.Get>((Symbol) "key"); - KeyValue = map.Get>((Symbol)"keyValue"); + Key = map.Get>(Vrml97Sym.key); + KeyValue = map.Get>(Vrml97Sym.keyValue); base.Init(map); } @@ -634,8 +629,8 @@ public VrmlOrientationInterpolator() { } internal override void Init(SymMapBase map) { - Key = map.Get>((Symbol)"key"); - KeyValue = map.Get>((Symbol)"keyValue"); + Key = map.Get>(Vrml97Sym.key); + KeyValue = map.Get>(Vrml97Sym.keyValue); base.Init(map); } @@ -666,11 +661,11 @@ public VrmlTimeSensor() { } internal override void Init(SymMapBase map) { - CycleInterval = map.Get((Symbol)"cycleInterval"); - Enabled = map.Get((Symbol)"enabled"); - Loop = map.Get((Symbol)"loop"); - StartTime = map.Get((Symbol)"startTime"); - StopTime = map.Get((Symbol)"stopTime"); + CycleInterval = map.Get(Vrml97Sym.cycleInterval); + Enabled = map.Get(Vrml97Sym.enabled); + Loop = map.Get(Vrml97Sym.loop); + StartTime = map.Get(Vrml97Sym.startTime); + StopTime = map.Get(Vrml97Sym.stopTime); base.Init(map); } @@ -707,8 +702,8 @@ public VrmlRoute() { } internal override void Init(SymMapBase map) { - var inputIdentifiers = map.Get((Symbol)"in").Split('.'); - var outputIdentifiers = map.Get((Symbol)"out").Split('.'); + var inputIdentifiers = map.Get(Vrml97Sym.inSym).Split('.'); + var outputIdentifiers = map.Get(Vrml97Sym.outSym).Split('.'); SourceNode = outputIdentifiers[0]; SinkNode = inputIdentifiers[0]; @@ -732,6 +727,7 @@ public override IEnumerable GetFieldCoders(int coderVersion) } #endregion + private static string RemovePrefix(string identifier, string vrmlPropertyIdentifier) { return identifier.StartsWith(vrmlPropertyIdentifier) ? @@ -757,7 +753,7 @@ public IEnumerable Filenames internal override void Init(SymMapBase map) { - var value = map.Get((Symbol)"url"); + var value = map.Get(Vrml97Sym.url); if (value != null) { IEnumerable filenames; @@ -769,15 +765,15 @@ internal override void Init(SymMapBase map) else throw new Exception("vrml texture node: invalid url type"); - var path = map.Get((Symbol)"path"); + var path = map.Get(Vrml97Sym.path); if (!path.IsNullOrEmpty()) filenames = filenames.Select(fp => Path.Combine(path, fp)); m_filenames = new List(filenames); } - RepeatS = map.Get((Symbol)"repeatS"); - RepeatT = map.Get((Symbol)"repeatT"); + RepeatS = map.Get(Vrml97Sym.repeatS); + RepeatT = map.Get(Vrml97Sym.repeatT); base.Init(map); } @@ -802,7 +798,7 @@ public VrmlInline() { } internal override void Init(SymMapBase map) { - var x = map.Get>((Symbol)"url"); + var x = map.Get>(Vrml97Sym.url); Url = x != null ? x.FirstOrDefault() : null; base.Init(map);