/// <summary> /// Read an XFile and create the objects defined in it /// </summary> /// <param name="filespec"></param> public void Load(string filespec) { Debug.WriteLine("Loading XFile: "+filespec); manager = new XFileManager(); manager.RegisterDefaultTemplates(); // register standard templates BEFORE opening file try { xfile = manager.FromFile(filespec); // create an XFile object from file } catch (GraphicsException e) { if (e.ErrorCode == (int)XFileErrorCodes.ParseError) Debug.WriteLine("ERROR in CellLoader.Load() - Couldn't parse Xfile "+filespec); else Debug.WriteLine("ERROR in CellLoader.Load() - Failed to load "+filespec); throw; } manager.RegisterXFileTemplates(xfile); // register any custom templates in the file //manager.RegisterTemplates(data); // register any templates defined in my code for (int i=0; i<xfile.NumberChildren; i++) // iterate through the root-level objects { using (XFileData rootObject = xfile.GetChild(i)) { LoadDataObject(rootObject,0,null,null); } } // Dispose of everything xfile.Dispose(); manager.Dispose(); }
/// <summary> /// Read an XFile and create the objects defined in it, /// i.e. the frame hierarchy and Cytoplasm meshes. /// The animationSet objects in the X file are used to set joint limits in the frames /// </summary> /// <param name="group">Group that cell belongs to (i.e. DLL and folder name)</param> /// <param name="name">Cell type (i.e. filename minus extension, and CellType-derived class name)</param> /// <param name="variantName">NAME of the variant (i.e. name of the .X file)</param> /// <returns>The root frame of the loaded hierarchy</returns> public static JointFrame Load(string group, string type, string variantName) { CellLoader.folder = "cells" + "\\" + group + "\\" + type; // store subfolder name so that textures can be found string fsp = FileResource.Fsp(CellLoader.folder, variantName + ".X"); // .X file will be ../cells/group/type/variant.x // Debug.WriteLine("Loading XFile: "+fsp); filespec = fsp; manager = new XFileManager(); manager.RegisterDefaultTemplates(); // register standard templates BEFORE opening file try { xfile = manager.FromFile(filespec); // create an XFile object from file } catch (GraphicsException e) { if (e.ErrorCode == (int)XFileErrorCodes.ParseError) throw new SDKException("ERROR in CellLoader.Load() - Couldn't parse Xfile "+filespec); else throw new SDKException("ERROR in CellLoader.Load() - Failed to load " + filespec); } manager.RegisterXFileTemplates(xfile); // register any custom templates in the file //////// RegisterCustomTemplates(); // register any templates in this code for (int i=0; i<xfile.NumberChildren; i++) // iterate through the root-level objects { using (XFileData rootObject = xfile.GetChild(i)) { LoadRootObject(rootObject); } } // Dispose of everything xfile.Dispose(); manager.Dispose(); // return the completed hierarchy return rootFrame; }