public void Execute() { if (roadObject == null) { roadObject = new RoadObject(name, parent, app, halfWidth); } parent.Add(roadObject); for (int i = app.SelectedObject.Count - 1; i >= 0; i--) { app.SelectedObject[i].Node.UnSelect(); } if (roadObject.Node != null) { roadObject.Node.Select(); } if (placing) { dragMarker = new DisplayObject("RoadDrag", app, "Dragging", app.Scene, app.Config.RoadPointMeshName, Vector3.Zero, Vector3.UnitScale, Vector3.Zero, null); dragMarker.MaterialName = app.Config.RoadPointMaterial; dragMarker.ScaleWithCameraDistance = true; new MultiPointPlacementHelper(app, dragMarker, new MultiPointValidate(PointValidate), new MultiPointComplete(PointPlacementComplete)); placing = false; } }
public void Clone(IWorldContainer copyParent) { RoadObject clone = new RoadObject(app, name, copyParent, halfWidth); clone.NameValue = new NameValueObject(nameValuePairs); foreach (IWorldObject child in children) { child.Clone(clone); } copyParent.Add(clone); }
protected void FromXml(XmlReader r, bool loadall) { string colfilename = ""; string baseName = WorldFilePath.Substring(0, WorldFilePath.LastIndexOf('\\')); do { r.Read(); } while ((r.NodeType != XmlNodeType.Element) || !(String.Equals(r.Name, "WorldObjectCollection"))); while (r.Read()) { // look for the start of an element if (r.NodeType == XmlNodeType.Whitespace) { continue; } if (r.NodeType == XmlNodeType.EndElement) { break; } if (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "Road": RoadObject road = new RoadObject(r, this, app); Add(road); break; case "StaticObject": StaticObject obj = new StaticObject(this, app, r); Add(obj); break; case "Waypoint": Waypoint wp = new Waypoint(r, this, app); Add(wp); break; case "Boundary": Boundary b = new Boundary(r, this, app); Add(b); break; case "PointLight": PointLight pl = new PointLight(app, this, app.Scene, r); Add(pl); break; case "TerrainDecal": TerrainDecal d = new TerrainDecal(app, this, r); Add(d); break; case "WorldCollection": string collectionName = null; colfilename = ""; for (int i = 0; i < r.AttributeCount; i++) { r.MoveToAttribute(i); switch (r.Name) { case "Name": collectionName = r.Value; break; case "Filename": colfilename = r.Value; break; } } baseName = this.Path; if (!loadall) { if (colfilename != "") { if (colfilename.EndsWith("~.mwc")) { string autofilepath = String.Format("{0}\\{1}", baseName, colfilename); string normalfilepath = String.Format("{0}\\{1}", baseName, colfilename.Remove(colfilename.LastIndexOf("~"), 1)); if ((File.Exists(autofilepath) && File.Exists(normalfilepath) && (new FileInfo(autofilepath)).LastWriteTime < (new FileInfo(normalfilepath).LastWriteTime)) || (!File.Exists(autofilepath) && File.Exists(normalfilepath))) { colfilename = colfilename.Remove(filename.LastIndexOf("~"), 1); } } XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}", baseName, colfilename), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName, false); while (colfilename.Contains("~")) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"),1); } coll.Filename = colfilename; Add(coll); childReader.Close(); } else { XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}.mwc", baseName, collectionName), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName, false); coll.Filename = collectionName + ".mwc"; Add(coll); childReader.Close(); } } else { if (colfilename != "") { if (colfilename.EndsWith("~.mwc")) { string autofilepath = String.Format("{0}\\{1}", baseName, colfilename); string normalfilepath = String.Format("{0}\\{1}", baseName, colfilename.Remove(filename.LastIndexOf("~"), 1)); if ((File.Exists(autofilepath) && File.Exists(normalfilepath) && (new FileInfo(autofilepath)).LastWriteTime < (new FileInfo(normalfilepath).LastWriteTime)) || (!File.Exists(autofilepath) && File.Exists(normalfilepath))) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"), 1); } } XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}", baseName, colfilename), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName); while (colfilename.Contains("~")) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"), 1); } coll.Filename = colfilename; Add(coll); childReader.Close(); } else { XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}.mwc", baseName, collectionName), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName); coll.Filename = collectionName + ".mwc"; Add(coll); childReader.Close(); } } r.MoveToElement(); break; } } } while(filename.Contains("~")) { filename = filename.Remove(filename.IndexOf("~"), 1); } }
protected void FromXml(XmlReader r, bool loadall) { string colfilename = ""; string baseName = WorldFilePath.Substring(0, WorldFilePath.LastIndexOf('\\')); do { r.Read(); } while ((r.NodeType != XmlNodeType.Element) || !(String.Equals(r.Name, "WorldObjectCollection"))); while (r.Read()) { // look for the start of an element if (r.NodeType == XmlNodeType.Whitespace) { continue; } if (r.NodeType == XmlNodeType.EndElement) { break; } if (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "Road": RoadObject road = new RoadObject(r, this, app); Add(road); break; case "StaticObject": StaticObject obj = new StaticObject(this, app, r); Add(obj); break; case "Waypoint": Waypoint wp = new Waypoint(r, this, app); Add(wp); break; case "Boundary": Boundary b = new Boundary(r, this, app); Add(b); break; case "PointLight": PointLight pl = new PointLight(app, this, app.Scene, r); Add(pl); break; case "TerrainDecal": TerrainDecal d = new TerrainDecal(app, this, r); Add(d); break; case "WorldCollection": string collectionName = null; colfilename = ""; for (int i = 0; i < r.AttributeCount; i++) { r.MoveToAttribute(i); switch (r.Name) { case "Name": collectionName = r.Value; break; case "Filename": colfilename = r.Value; break; } } baseName = this.Path; if (!loadall) { if (colfilename != "") { if (colfilename.EndsWith("~.mwc")) { string autofilepath = String.Format("{0}\\{1}", baseName, colfilename); string normalfilepath = String.Format("{0}\\{1}", baseName, colfilename.Remove(colfilename.LastIndexOf("~"), 1)); if ((File.Exists(autofilepath) && File.Exists(normalfilepath) && (new FileInfo(autofilepath)).LastWriteTime < (new FileInfo(normalfilepath).LastWriteTime)) || (!File.Exists(autofilepath) && File.Exists(normalfilepath))) { colfilename = colfilename.Remove(filename.LastIndexOf("~"), 1); } } XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}", baseName, colfilename), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName, false); while (colfilename.Contains("~")) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"), 1); } coll.Filename = colfilename; Add(coll); childReader.Close(); } else { XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}.mwc", baseName, collectionName), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName, false); coll.Filename = collectionName + ".mwc"; Add(coll); childReader.Close(); } } else { if (colfilename != "") { if (colfilename.EndsWith("~.mwc")) { string autofilepath = String.Format("{0}\\{1}", baseName, colfilename); string normalfilepath = String.Format("{0}\\{1}", baseName, colfilename.Remove(filename.LastIndexOf("~"), 1)); if ((File.Exists(autofilepath) && File.Exists(normalfilepath) && (new FileInfo(autofilepath)).LastWriteTime < (new FileInfo(normalfilepath).LastWriteTime)) || (!File.Exists(autofilepath) && File.Exists(normalfilepath))) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"), 1); } } XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}", baseName, colfilename), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName); while (colfilename.Contains("~")) { colfilename = colfilename.Remove(colfilename.LastIndexOf("~"), 1); } coll.Filename = colfilename; Add(coll); childReader.Close(); } else { XmlReader childReader = XmlReader.Create(String.Format("{0}\\{1}.mwc", baseName, collectionName), app.XMLReaderSettings); WorldObjectCollection coll = new WorldObjectCollection(childReader, collectionName, this, app, baseName); coll.Filename = collectionName + ".mwc"; Add(coll); childReader.Close(); } } r.MoveToElement(); break; } } } while (filename.Contains("~")) { filename = filename.Remove(filename.IndexOf("~"), 1); } }
protected void LoadOldRoad(XmlNode node, WorldObjectCollection collection) { string name = null; int halfWidth = 1; XmlNode pointsNode = null; // get the name foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "Name": name = childNode.InnerText; break; case "Points": pointsNode = childNode; break; case "HalfWidth": halfWidth = int.Parse(childNode.InnerText); break; default: break; } } // if the road has no points, just call it bogus and return if (pointsNode == null) { return; } // create and add the road to the world RoadObject road = new RoadObject(name, collection, this, halfWidth); collection.Add(road); // set up the points foreach (XmlNode pointNode in pointsNode.ChildNodes) { if (pointNode.Name == "Point") { XmlNode locNode = pointNode.SelectSingleNode("Position"); Vector3 pointPos = GetVectorAttributes(locNode); int pointnum; road.Points.AddPoint(pointPos, out pointnum); } } }