public override bool DoProcess() { //Debug2.Push(); Debug.Assert(this.WorldcraftFileName != null); Debug.Assert(this.World == null); this.BeginTask("Loading Worldcraft Map..."); WorldcraftMap wm = WorldcraftMap.FromFile(this.WorldcraftFileName, ExoEngine.sTexturePath); if (wm == null) { this.Finished(false, "Error loading WorldcraftMap from file '" + this.WorldcraftFileName + "'."); //Debug2.Pop(); return(false); } this.BeginTask("Converting Worldcraft Map to internal representation..."); World world = World.FromWorldcraftMap(wm); if (world == null) { this.Finished(false, "Error converting WorldcraftMap to World."); //Debug2.Pop(); return(false); } this.Finished(true); this.World = world; //Debug2.Pop(); return(true); }
//----------------------------------------------------------------------------- static public World FromWorldcraftMap(WorldcraftMap wm) { // create new world World world = new World(); world.Textures = wm.Textures; world.SkyBox = new SkyBox("redSky"); world.FileName = Path.Combine(ExoEngine.sWorldPath, Path.ChangeExtension(Path.GetFileName(wm.FileName), ExoEngine.sWorldExtension)); world.Dirty = true; // find the starting location WorldcraftObject woStartPosition = wm.Objects.FindByClassName("StartPosition"); if (woStartPosition == null) { return(null); } Vector3D ptStartPosition; FaceUtils.GetMidPoint(woStartPosition.Faces, out ptStartPosition); world.StartPosition = ptStartPosition; world.StartOrientation = woStartPosition.GetPropertyInteger("orientation", 0); // find the main light WorldcraftObject woLight = wm.Objects.FindByClassName("Light"); if (woLight == null) { return(null); } Vector3D ptLight; FaceUtils.GetMidPoint(woLight.Faces, out ptLight); world.Light = ptLight; // find "Default" group... it is the static world WorldcraftObject woDefault = wm.Objects.FindByClassName("Default"); if (woDefault == null) { return(null); } // setup BSP tree Faces faces = new Faces(); // handle the other objects foreach (WorldcraftObject wo in wm.Objects) { if (wo.ClassName == "Water") { Vector3D ptMin, ptMax; FaceUtils.GetExtents(wo.Faces, out ptMin, out ptMax); Water water = new Water(ptMin, ptMax, wo.GetPropertyFloat("waveHeight", 100)); water.Color = wo.GetPropertyColor("color", Color.Azure); world.Entities.Add(water); } else if (wo.ClassName == "Duck") { Vector3D ptMin, ptMax; FaceUtils.GetExtents(wo.Faces, out ptMin, out ptMax); Duck duck = new Duck(ptMin, ptMax); duck.LoadDataSet(Path.Combine(ExoEngine.sSpritePath, "duck.odf"), wo.GetPropertyColor("color", Color.Yellow)); world.Entities.Add(duck); foreach (Face face in wo.Faces) { face.Visible = false; } faces.AddRange(wo.Faces); } } world.Entities.SortByPriority(); faces.AddRange(woDefault.Faces); FaceUtils.OptimizeFaces(faces); world.BSPTreeRoot = BSPTreeNode.FromFaces(faces); return(world); }