/// <summary>
        /// Serialize coalesced objects to Xml
        /// </summary>
        /// <param name="coa"></param>
        /// <param name="doScriptStates">
        /// If true then serialize script states.  This will halt any running scripts
        /// </param>
        /// <returns></returns>
        public static string ToXml(CoalescedSceneObjects coa, bool doScriptStates)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    Vector3 size;

                    List <SceneObjectGroup> coaObjects = coa.Objects;

                    //                    m_log.DebugFormat(
                    //                        "[COALESCED SCENE OBJECTS SERIALIZER]: Writing {0} objects for coalesced object",
                    //                        coaObjects.Count);

                    // This is weak - we're relying on the set of coalesced objects still being identical
                    Vector3[] offsets = coa.GetSizeAndOffsets(out size);

                    writer.WriteStartElement("CoalescedObject");

                    writer.WriteAttributeString("x", size.X.ToString(Culture.FormatProvider));
                    writer.WriteAttributeString("y", size.Y.ToString(Culture.FormatProvider));
                    writer.WriteAttributeString("z", size.Z.ToString(Culture.FormatProvider));

                    // Embed the offsets into the group XML
                    for (int i = 0; i < coaObjects.Count; i++)
                    {
                        SceneObjectGroup obj = coaObjects[i];

                        //                        m_log.DebugFormat(
                        //                            "[COALESCED SCENE OBJECTS SERIALIZER]: Writing offset for object {0}, {1}",
                        //                            i, obj.Name);

                        writer.WriteStartElement("SceneObjectGroup");
                        writer.WriteAttributeString("offsetx", offsets[i].X.ToString(Culture.FormatProvider));
                        writer.WriteAttributeString("offsety", offsets[i].Y.ToString(Culture.FormatProvider));
                        writer.WriteAttributeString("offsetz", offsets[i].Z.ToString(Culture.FormatProvider));

                        SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, doScriptStates);

                        writer.WriteEndElement(); // SceneObjectGroup
                    }

                    writer.WriteEndElement(); // CoalescedObject
                }

                string output = sw.ToString();

                //                Console.WriteLine(output);

                return(output);
            }
        }
        /// <summary>
        /// Serialize coalesced objects to Xml
        /// </summary>
        /// <param name="coa"></param>
        /// <param name="doScriptStates">
        /// If true then serialize script states.  This will halt any running scripts
        /// </param>
        /// <returns></returns>
        public static string ToXml(CoalescedSceneObjects coa, bool doScriptStates)
        {            
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {                                        
                    Vector3 size;
                    
                    List<SceneObjectGroup> coaObjects = coa.Objects;
                    
//                    m_log.DebugFormat(
//                        "[COALESCED SCENE OBJECTS SERIALIZER]: Writing {0} objects for coalesced object", 
//                        coaObjects.Count);
                    
                    // This is weak - we're relying on the set of coalesced objects still being identical
                    Vector3[] offsets = coa.GetSizeAndOffsets(out size);

                    writer.WriteStartElement("CoalescedObject");
                    
                    writer.WriteAttributeString("x", size.X.ToString());
                    writer.WriteAttributeString("y", size.Y.ToString());
                    writer.WriteAttributeString("z", size.Z.ToString());                    
                    
                    // Embed the offsets into the group XML
                    for (int i = 0; i < coaObjects.Count; i++)
                    {
                        SceneObjectGroup obj = coaObjects[i];
                        
//                        m_log.DebugFormat(
//                            "[COALESCED SCENE OBJECTS SERIALIZER]: Writing offset for object {0}, {1}", 
//                            i, obj.Name);                        
                        
                        writer.WriteStartElement("SceneObjectGroup");
                        writer.WriteAttributeString("offsetx", offsets[i].X.ToString());
                        writer.WriteAttributeString("offsety", offsets[i].Y.ToString());
                        writer.WriteAttributeString("offsetz", offsets[i].Z.ToString());
                        
                        SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, doScriptStates);
                        
                        writer.WriteEndElement(); // SceneObjectGroup
                    }  
                    
                    writer.WriteEndElement(); // CoalescedObject
                }

                string output = sw.ToString();
                
//                Console.WriteLine(output);
                
                return output;
            }
        }