コード例 #1
0
        /// <summary>
        /// Creates a new <see cref="ImportedGroup"/> Instance with Default Settings
        /// </summary>
        /// <returns>a new Container for an Imported MeshGroup</returns>
        /// <remarks>
        /// You should use this whenever you have to add a new Group!
        /// </remarks>
        protected ImportedGroup PrepareGroup()
        {
            ImportedGroup g = new ImportedGroup(Gmdc);

            //Vertex Element-----
            GmdcElement e = new GmdcElement(Gmdc);

            g.Elements.Add(e);
            e.Identity    = ElementIdentity.Vertex;
            e.BlockFormat = BlockFormat.ThreeFloat;
            e.SetFormat   = SetFormat.Secondary;

            //Normal Element-----
            e = new GmdcElement(Gmdc);
            g.Elements.Add(e);
            e.Identity    = ElementIdentity.Normal;
            e.BlockFormat = BlockFormat.ThreeFloat;
            e.SetFormat   = SetFormat.Normals;

            //UVCoord Element-----
            e = new GmdcElement(Gmdc);
            g.Elements.Add(e);
            e.Identity    = ElementIdentity.UVCoordinate;
            e.BlockFormat = BlockFormat.TwoFloat;
            e.SetFormat   = SetFormat.Mapping;

            g.Group.PrimitiveType = PrimitiveType.Triangle;
            g.Group.Opacity       = 0xffffffff;

            return(g);
        }
コード例 #2
0
 /// <summary>
 /// Make sure, that the Listing does NOT contain null References
 /// </summary>
 /// <param name="g">The current Group</param>
 /// <param name="index">Index of the Element</param>
 /// <param name="val">the Value you want to add</param>
 void FillMissingElements(ImportedGroup g, int index, Gmdc.GmdcElementValueBase val)
 {
     if (val == null)
     {
         return;
     }
     for (int i = 0; i < g.Elements[index].Values.Count; i++)
     {
         if (g.Elements[index].Values[i] == null)
         {
             g.Elements[index].Values[i] = val;
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Add a new Value to the element with the given Index
 /// </summary>
 /// <param name="g">The current Group</param>
 /// <param name="index">Index of the Element</param>
 /// <param name="val">the Value you want to add</param>
 void AddElement(ImportedGroup g, int index, object val, int slotindex)
 {
     if (slotindex == -1)
     {
         g.Elements[index].Values.Add(val);
     }
     else
     {
         while (g.Elements[index].Values.Count <= slotindex)
         {
             g.Elements[index].Values.Add(null);
         }
         g.Elements[index].Values[slotindex] = val as Gmdc.GmdcElementValueBase;
     }
 }
コード例 #4
0
        /// <summary>
        /// Add the passed Group to the Gmdc
        /// </summary>
        /// <param name="g"></param>
        protected virtual void AddGroup(ImportedGroup g)
        {
            for (int i = 0; i < g.Link.ReferencedElement.Count; i++)
            {
                GmdcElement e = g.Elements[g.Link.ReferencedElement[i]];
                //foreach (GmdcElementValueBase evb in e.Values) evb *= g.Scale;

                gmdc.Elements.Add(e);
                g.Link.ReferencedElement[i] = gmdc.Elements.Length - 1;
            }
            g.Group.LinkIndex = gmdc.Links.Length;
            gmdc.Links.Add(g.Link);
            gmdc.Groups.Add(g.Group);

            g.Link.ReferencedSize = g.Link.GetReferencedSize();
            g.Link.ActiveElements = g.Link.ReferencedElement.Count;
        }
コード例 #5
0
        /// <summary>
        /// Use the Members, that wer initialized with LoadLists() to create
        /// the Imported Group Data
        /// </summary>
        /// <param name="grps">The List that should receive the Group Data</param>
        void ProcessLists(ImportedGroups grps)
        {
            foreach (string k in groups.Keys)
            {
                faces = (ArrayList)groups[k];

                //ignore empty groups
                if (faces.Count == 0)
                {
                    continue;
                }

                ImportedGroup g = PrepareGroup();
                g.Group.Name = k;
                BuildGroup(g);

                grps.Add(g);
            }
        }
コード例 #6
0
        /// <summary>
        /// RUpdate an existing Group with  the passed Group in the current Gmdc
        /// </summary>
        /// <param name="g"></param>
        protected virtual void UpdateGroup(ImportedGroup g)
        {
            int index = g.Target.Index;

            if (index < 0 || index >= Gmdc.Groups.Length)
            {
                index = Gmdc.FindGroupByName(g.Target.Name);
            }

            GmdcGroup grp = Gmdc.Groups[index];
            GmdcLink  lnk = Gmdc.Links[grp.LinkIndex];

            g.Group.LinkIndex  = grp.LinkIndex;
            g.Group.UsedJoints = grp.UsedJoints;


            for (int i = 0; i < g.Link.ReferencedElement.Count; i++)
            {
                GmdcElement e = g.Elements[g.Link.ReferencedElement[i]];
                //foreach (GmdcElementValueBase evb in e.Values) evb *= g.Scale;
                GmdcElement old = lnk.FindElementType(e.Identity);

                //found an existing Element?
                if (old == null)
                {
                    gmdc.Elements.Add(e);
                    lnk.ReferencedElement.Add(gmdc.Elements.Length - 1);
                }
                else
                {
                    int id = lnk.GetElementNr(old);
                    Gmdc.Elements[lnk.ReferencedElement[id]] = e;
                }
            }

            Gmdc.Groups[index] = g.Group;
            lnk.ReferencedSize = lnk.GetReferencedSize();
            lnk.ActiveElements = lnk.ReferencedElement.Count;
        }
コード例 #7
0
        /// <summary>
        /// Replace an existing Group with  the passed Group in the current Gmdc
        /// </summary>
        /// <param name="gs">List of all available Groups</param>
        /// <param name="g"></param>
        protected virtual void ReplaceGroup(ImportedGroups gs, ImportedGroup g)
        {
            int index = g.Target.Index;

            if (index < 0 || index >= Gmdc.Groups.Length)
            {
                index = Gmdc.FindGroupByName(g.Target.Name);
            }
            if (index >= 0)
            {
                gmdc.RemoveGroup(index);
            }

            //make sure to update the Groups
            foreach (ImportedGroup ig in gs)
            {
                if (ig.Target.Index > index)
                {
                    ig.Target.Index--;
                }
            }

            RenameGroup(g);
        }
コード例 #8
0
        /// <summary>
        /// Build a Single Group from the Member Data generated with LoadLists()
        /// </summary>
        /// <param name="g"></param>
        /// <remarks>At this point, the faces Member contains the face List for
        /// the current Group</remarks>
        void BuildGroupOld(ImportedGroup g)
        {
            //Whenever a new Index is added, we store the index it will get in the Elements Section
            //since the Faces could have diffrent indices for normals and uvcoords, we need three maps
            Hashtable valias  = new Hashtable();
            Hashtable vnalias = new Hashtable();
            Hashtable vtalias = new Hashtable();

            for (int x = 0; x < faces.Count; x++)
            {
                GmdcElementValueThreeFloat f = (GmdcElementValueThreeFloat)faces[x];
                int  v     = (int)f.Data[0];
                int  vt    = (int)f.Data[1];
                int  vn    = (int)f.Data[2];
                bool newv  = false;
                bool newvn = false;
                bool newvt = false;

                if (v <= 0)
                {
                    throw new Exception("Zero Vertex Index Found!");
                }
                try
                {
                    //new Element, so add it to the Map and the List
                    if (!valias.ContainsKey(v))
                    {
                        ArrayList l = new ArrayList();
                        l.Add(g.Elements[0].Values.Count);
                        valias[v] = l;
                        AddElement(g, 0, vertices[v - 1], -1);
                        newv = true;
                    }


                    if (vn > 0)
                    {
                        //new Element, so add it to the Map and the List
                        if (!vnalias.ContainsKey(vn))
                        {
                            ArrayList l = new ArrayList();
                            l.Add(g.Elements[1].Values.Count);
                            vnalias[vn] = l;
                            AddElement(g, 1, normals[vn - 1], -1);
                            newvn = true;
                        }
                    }


                    if (vt > 0)
                    {
                        //new Element, so add it to the Map and the List
                        if (!vtalias.ContainsKey(vt))
                        {
                            ArrayList l = new ArrayList();
                            l.Add(g.Elements[2].Values.Count);
                            vtalias[vt] = l;
                            AddElement(g, 2, uvmaps[vt - 1], -1);
                            newvt = true;
                        }
                    }

                    //Now get a List of all position where we can find an instance of the wanted FaceItem
                    ArrayList lv = (ArrayList)valias[v];
                    if (lv == null)
                    {
                        lv = new ArrayList();
                        lv.Add(-1);
                    }
                    ArrayList lvn = (ArrayList)vnalias[vn];
                    if (lvn == null)
                    {
                        lvn = new ArrayList();
                        lvn.Add(-1);
                    }
                    ArrayList lvt = (ArrayList)vtalias[vt];
                    if (lvt == null)
                    {
                        lvt = new ArrayList();
                        lvt.Add(-1);
                    }

                    //We need something where als stored Indices are the same, so look for that
                    bool found = false;
                    if (faces.Count < 0x1000)
                    {
                        for (int i = 0; i < lv.Count; i++)
                        {
                            for (int j = 0; j < lvn.Count; j++)
                            {
                                for (int k = 0; k < lvt.Count; k++)
                                {
                                    if (
                                        ((int)lv[i] == (int)lvn[j] || (int)lv[i] == -1 || (int)lvn[j] == -1) &&
                                        ((int)lv[i] == (int)lvt[k] || (int)lv[i] == -1 || (int)lvt[k] == -1) &&
                                        ((int)lvn[j] == (int)lvt[k] || (int)lvt[k] == -1 || (int)lvn[j] == -1)
                                        )
                                    {
                                        int val = (int)lv[i];
                                        if (val == -1)
                                        {
                                            val = (int)lvn[j];
                                        }
                                        if (val == -1)
                                        {
                                            val = (int)lvt[k];
                                        }
                                        if (val != -1)
                                        {
                                            g.Group.Faces.Add(val);
                                            found = true;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //unfortunatley we did not find matching pairs, so add new Elements
                    if (!found)
                    {
                        if (!newv && v > 0)
                        {
                            lv.Add(g.Elements[0].Values.Count);
                            AddElement(g, 0, vertices[v - 1], -1);
                        }

                        if (!newvn && vn > 0)
                        {
                            lvn.Add(g.Elements[1].Values.Count);
                            AddElement(g, 1, normals[vn - 1], -1);
                        }

                        if (!newvt && vt > 0)
                        {
                            lvt.Add(g.Elements[2].Values.Count);
                            AddElement(g, 2, uvmaps[vt - 1], -1);
                        }

                        if (g.Elements[0].Values.Count != g.Elements[1].Values.Count || g.Elements[0].Values.Count != g.Elements[2].Values.Count)
                        {
                            throw new Exception("Element Lists are out of Sync");
                        }

                        g.Group.Faces.Add(g.Elements[0].Values.Count - 1);
                    }
                }
                catch (Exception ex)
                {
                    Exception nex = new Exception("Error while creating Group List", new Exception(this.ErrorMessage, ex));
                    this.error = "";
                    throw nex;
                }
            }

            /*int size = int.MaxValue;
             * //if we have an empty map, we will not add that section to the Link Element!
             * if (g.Elements[0].Values.Count>0)
             * {
             *      g.Link.ReferencedElement.Add(0);
             *      size = Math.Min(size, g.Elements[0].Values.Count);
             * }
             * if (g.Elements[1].Values.Count>0)
             * {
             *      g.Link.ReferencedElement.Add(1);
             *      size = Math.Min(size, g.Elements[1].Values.Count);
             * }
             * if (g.Elements[2].Values.Count>0)
             * {
             *      g.Link.ReferencedElement.Add(2);
             *      size = Math.Min(size, g.Elements[2].Values.Count);
             * }
             *
             * if (size==int.MaxValue) size=0;
             * g.Link.ReferencedSize = size;
             * g.Link.ActiveElements = g.Link.ReferencedElement.Count;
             *
             * g.Elements[0].Number = g.Elements[0].Values.Count;
             * g.Elements[1].Number = g.Elements[1].Values.Count;
             * g.Elements[2].Number = g.Elements[2].Values.Count;
             */
        }
コード例 #9
0
        /// <summary>
        /// Build a Single Group from the Member Data generated with LoadLists()
        /// </summary>
        /// <param name="g"></param>
        /// <remarks>At this point, the faces Member contains the face List for
        /// the current Group</remarks>
        void BuildGroup(ImportedGroup g)
        {
            ArrayList    fv        = new ArrayList();
            ElementAlias alias     = new ElementAlias();
            Hashtable    facealias = new Hashtable();

            g.SetKeepOrder(CanKeepOrder(faces));


            BuildAliasMap(alias.V, vertices);
            BuildAliasMap(alias.VN, normals);
            BuildAliasMap(alias.VU, uvmaps);


            //Build the Face/Element List
            for (int x = 0; x < faces.Count; x++)
            {
                GmdcElementValueThreeFloat f = (GmdcElementValueThreeFloat)faces[x];

                FaceSetCompare fc = new FaceSetCompare(alias, f.Data[0], f.Data[2], f.Data[1]);


                //check if we already have this combination
                object o = facealias[fc];
#if DEBUG
                try
                {
#endif
                int c = g.Elements[0].Values.Count;
                if (o == null)
                {
                    if (fc.V >= 0)
                    {
                        int cv = -1;
                        if (g.KeepOrder)
                        {
                            if (f.Data[0] > 0)
                            {
                                c = (int)f.Data[0] - 1;
                            }
                            cv = c;
                        }


                        AddElement(g, 0, vertices[fc.V], cv);
                        AddElement(g, 1, normals[fc.VN], cv);
                        AddElement(g, 2, uvmaps[fc.VU], cv);
                    }

                    facealias[fc] = c;
                }
                else
                {
                    c = (int)o;
                }

                if (fc.V >= 0 || fc.VN >= 0 || fc.VU >= 0)
                {
                    g.Group.Faces.Add(c);
                }
#if DEBUG
            }
            catch (Exception ex)
            {
                FaceSetCompare ft = new FaceSetCompare(alias, f.Data[0], f.Data[2], f.Data[1]);
                Helper.ExceptionMessage(ex);
                return;
            }
#endif
            }

            if (g.KeepOrder)
            {
                ///Make sure all slots in the Elemnts are set
                FillMissingElements(g, 0, new Gmdc.GmdcElementValueThreeFloat(0, 0, 0));
                FillMissingElements(g, 1, new Gmdc.GmdcElementValueThreeFloat(0, 0, 0));
                FillMissingElements(g, 2, new Gmdc.GmdcElementValueTwoFloat(0, 0));
            }
        }
コード例 #10
0
 /// <summary>
 /// Checks wether or not the object is already stored in the List
 /// </summary>
 /// <param name="item">The Object you are looking for</param>
 /// <returns>true, if it was found</returns>
 public bool Contains(ImportedGroup item)
 {
     return(base.Contains(item));
 }
コード例 #11
0
 /// <summary>
 /// remove an Element
 /// </summary>
 /// <param name="item">The object that should be removed</param>
 public void Remove(ImportedGroup item)
 {
     base.Remove(item);
 }
コード例 #12
0
 /// <summary>
 /// insert a new Element
 /// </summary>
 /// <param name="index">The Index where the Element should be stored</param>
 /// <param name="item">The object that should be inserted</param>
 public void Insert(int index, ImportedGroup item)
 {
     base.Insert(index, item);
 }
コード例 #13
0
 /// <summary>
 /// add a new Element
 /// </summary>
 /// <param name="item">The object you want to add</param>
 /// <returns>The index it was added on</returns>
 public int Add(ImportedGroup item)
 {
     return(base.Add(item));
 }
コード例 #14
0
 /// <summary>
 /// set the Name of the Group to a diffrent Value and Add it to the Gmdc
 /// </summary>
 /// <param name="g"></param>
 protected virtual void RenameGroup(ImportedGroup g)
 {
     g.Group.Name = g.Target.Name;
     AddGroup(g);
 }