예제 #1
0
        void SetBones(Ambertation.Scenes.Envelope e, int index, GmdcElement be, GmdcElement bw)
        {
            for (int i = 0; i < e.Weights.Count; i++)
            {
                if (e.Weights[i] == 0)
                {
                    continue;
                }
                GmdcElementValueOneInt     a = be.Values[i] as GmdcElementValueOneInt;
                GmdcElementValueThreeFloat w = bw.Values[i] as GmdcElementValueThreeFloat;

                int k = -1;
                for (int j = 0; j < 3; j++)
                {
                    if (a.Bytes[j] == 0xff)
                    {
                        k = j; break;
                    }
                }

                if (k != -1)
                {
                    a.SetByte(k, (byte)index);
                    w.Data[k] = (float)e.Weights[i];
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Create a Clone of this Object
        /// </summary>
        /// <returns>The Clone</returns>
        public override GmdcElementValueBase Clone()
        {
            GmdcElementValueBase dest = new GmdcElementValueThreeFloat();

            Clone(dest);
            return(dest);
        }
예제 #3
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;
             */
        }
예제 #4
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));
            }
        }