Beispiel #1
0
        bool loadModelsSet(ZipArchive zip)
        {
            AbstractFile file = zip.GetFile("modelPositions.xml");

            if (!file.Exists)
            {
                return(false);
            }


            SceneObjectsXML objectsXLM = new SceneObjectsXML();
            Stream          stream     = null;

            try
            {
                stream = file.OpenRead();
                XmlSerializer s = new XmlSerializer(typeof(SceneObjectsXML), new Type[] { });
                objectsXLM = (SceneObjectsXML)s.Deserialize(stream);
                stream.Close();
            }
            catch (Exception e)
            {
                if (stream != null)
                {
                    stream.Close();
                }
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error serializing the modelPositions.xml file");
                Console.ForegroundColor = ConsoleColor.White;
                return(false);
            }


            try
            {
                AbstractFolder fold = zip.GetFolder("models");

                for (int modelIdx = 0; modelIdx < objectsXLM.objectGR2Names.Count; modelIdx++)
                {
                    if (!ModelManager.loadModelFromDisk(TerrainGlobals.mGameDir + objectsXLM.objectGR2Names[modelIdx]))
                    {
                        // if(!ModelManager.loadModelFromArchive(objectsXLM.objectGR2Names[modelIdx], fold))
                        Console.WriteLine("Error loading model " + objectsXLM.objectGR2Names[modelIdx]);
                    }
                }

                for (int instIdx = 0; instIdx < objectsXLM.objectinstances.Count; instIdx++)
                {
                    Matrix orient = objectsXLM.objectinstances[instIdx].getMatrix();
                    ModelManager.addInstance(TerrainGlobals.mGameDir + objectsXLM.objectinstances[instIdx].GR2Filename, orient);
                }

                ModelManager.calcModelInstanceBuffers();

                if (objectsXLM.aabbmin != null)
                {
                    ModelManager.mAABBMin = Vec3FromString(objectsXLM.aabbmin);
                }
                if (objectsXLM.aabbmax != null)
                {
                    ModelManager.mAABBMax = Vec3FromString(objectsXLM.aabbmax);
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error loading gr2 model data from source file");
                Console.ForegroundColor = ConsoleColor.White;
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        void writeTempModelsToZip(ZipArchive zip)
        {
            SceneObjectsXML sceneObjects = new SceneObjectsXML();

            BBoundingBox objectAABB = new BBoundingBox();

            objectAABB.empty();

            string baseDir = CoreGlobals.getWorkPaths().mGameDirectory;

            if (mIncludeObjects)
            {
                //searalize an XML file to memorystream holding position and model names

                List <EditorObject> editObjs = SimGlobals.getSimMain().getEditorObjects(false, SimMain.eFilterTypes.cFilterAll, -1, false);
                for (int objIdx = 0; objIdx < editObjs.Count; objIdx++)
                {
                    if (editObjs[objIdx] == null)
                    {
                        continue;
                    }

                    if (editObjs[objIdx].GetType() == typeof(SimObject))
                    {
                        SimObject obj = editObjs[objIdx] as SimObject;

                        if (obj.IgnoreToAO)
                        {
                            continue;
                        }


                        if (obj != null && obj.ProtoObject != null)
                        {
                            string grannyName = obj.ProtoObject.getGrannyFileName();
                            if (grannyName == "")
                            {
                                continue;
                            }

                            if (grannyName.Contains(baseDir))
                            {
                                grannyName = grannyName.Remove(0, baseDir.Length);
                            }

                            //if this GR2 isn't already listed, then list it.
                            if (!sceneObjects.objectGR2Names.Contains(grannyName))
                            {
                                sceneObjects.objectGR2Names.Add(grannyName);
                            }


                            //add our instance
                            ObjectInstanceXML inst = new ObjectInstanceXML();
                            inst.GR2Filename = grannyName;
                            inst.setOrientation(obj.getMatrix());
                            sceneObjects.objectinstances.Add(inst);


                            //add our transformed BB to the global BB list
                            if (obj != null && obj.mVisual != null)
                            {
                                if (!obj.IgnoreToAO)
                                {
                                    objectAABB.addPoint(obj.mAABB.max + obj.getPosition());
                                    objectAABB.addPoint(obj.mAABB.min + obj.getPosition());
                                }
                            }
                        }
                    }
                }

                sceneObjects.aabbmin = TextVectorHelper.ToString(objectAABB.min);
                sceneObjects.aabbmax = TextVectorHelper.ToString(objectAABB.max);
            }

            //write it to an XML stream
            AbstractFile  md     = zip.CreateFile("modelPositions.xml", true);
            Stream        stream = md.OpenWrite(true);
            XmlSerializer s      = new XmlSerializer(typeof(SceneObjectsXML), new Type[] { });

            s.Serialize(stream, sceneObjects);
            stream.Close();

            //Create a folder and copy our GR2s into it
            //AbstractFolder fold = zip.CreateFolder("models");

            //if (mIncludeObjects)
            //{
            //   for (int modelIdx = 0; modelIdx < sceneObjects.objectGR2Names.Count; modelIdx++)
            //   {
            //      if (mWorkerThread.CancellationPending)
            //         return;


            //      try
            //      {
            //         if (fullGR2Names[modelIdx] == "")
            //            continue;
            //         DiskFile modelFile = new DiskFile(fullGR2Names[modelIdx]);
            //         modelFile.CopyTo(fold, true);
            //      }
            //      catch (Exception e)
            //      {
            //         continue;
            //      }
            //   }
            //}
        }