Example #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj is GmdcElementValueBase)
            {
                float epsilon          = float.Epsilon * 10;
                GmdcElementValueBase g = (GmdcElementValueBase)obj;
                if (g.data.Length != data.Length)
                {
                    return(false);
                }

                for (int i = 0; i < data.Length; i++)
                {
                    if (Math.Abs(g.data[i] - data[i]) > epsilon)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            return(base.Equals(obj));
        }
Example #2
0
        void BuildAliasMap(Hashtable alias, ArrayList list)
        {
            Hashtable fv = new Hashtable();

            //remove duplicates
            for (int i = 0; i < list.Count; i++)
            {
                //get an Element we can use to compare the current Content
                GmdcElementValueBase e = (GmdcElementValueBase)list[i];

                //check if we already have this combination
                object o = fv[e];

                //if not found so far, add it to the map
                if (o == null)
                {
                    alias[i] = i;
                    fv[e]    = i;
                }
                else
                {
                    alias[i] = (int)o;
                }
            }
        }
Example #3
0
 /// <summary>
 /// This Method supports the Internal process of creating a Clone
 /// </summary>
 /// <param name="dest">The object that should receive the copied Data</param>
 protected void Clone(GmdcElementValueBase dest)
 {
     for (int i = 0; i < data.Length; i++)
     {
         dest.Data[i] = data[i];
     }
 }
Example #4
0
        /// <summary>
        /// Scalar Multiplication
        /// </summary>
        /// <param name="evb">First Value</param>
        /// <param name="d">Scalar Factor</param>
        /// <returns>The resulting Value</returns>
        public static GmdcElementValueBase operator *(GmdcElementValueBase evb, double d)
        {
            GmdcElementValueBase n = evb.Clone();

            for (int i = 0; i < n.data.Length; i++)
            {
                n.data[i] = (float)(n.data[i] * d);
            }
            return(n);
        }
Example #5
0
        /// <summary>
        /// Returns a List with all available Vertices
        /// </summary>
        /// <returns></returns>
        public SimPe.Geometry.Vectors4f GetVectors(ElementIdentity id)
        {
            SimPe.Geometry.Vectors4f ret = new SimPe.Geometry.Vectors4f();
            if (this.Link != null)
            {
                GmdcElement e = this.Link.FindElementType(id);
                if (e != null)
                {
                    int nr = this.Link.GetElementNr(e);

                    for (int i = 0; i < Link.ReferencedSize; i++)
                    {
                        GmdcElementValueBase    vb = Link.GetValue(nr, i);
                        SimPe.Geometry.Vector4f v;
                        if (vb is GmdcElementValueOneInt)
                        {
                            GmdcElementValueOneInt oi = (GmdcElementValueOneInt)vb;
                            byte[] data = oi.Bytes;
                            if (data.Length == 4)
                            {
                                v = new SimPe.Geometry.Vector4f(data[0], data[1], data[2], data[3]);
                            }
                            else if (data.Length == 3)
                            {
                                v = new SimPe.Geometry.Vector4f(data[0], data[1], data[2]);
                            }
                            else if (data.Length == 2)
                            {
                                v = new SimPe.Geometry.Vector4f(data[0], data[1], 0);
                            }
                            else
                            {
                                v = new SimPe.Geometry.Vector4f(data[0], 0, 0);
                            }
                        }
                        else if (vb.Data.Length == 3)
                        {
                            v = new SimPe.Geometry.Vector4f(vb.Data[0], vb.Data[1], vb.Data[2]);
                        }
                        else if (vb.Data.Length == 2)
                        {
                            v = new SimPe.Geometry.Vector4f(vb.Data[0], vb.Data[1], 0);
                        }
                        else
                        {
                            v = new SimPe.Geometry.Vector4f(vb.Data[0], 0, 0);
                        }

                        ret.Add(v);
                    }
                }
            }

            return(ret);
        }
Example #6
0
        void AddEnvelopes(GmdcGroup g, Ambertation.Scenes.Mesh m, GmdcElement bonee, GmdcElement bonewighte, Hashtable jointmap)
        {
            if (bonee != null && true)
            {
                int pos = 0;
                foreach (SimPe.Plugin.Gmdc.GmdcElementValueOneInt vi in bonee.Values)
                {
                    byte[]       data = vi.Bytes;
                    IntArrayList used = new IntArrayList();

                    for (int datapos = 0; datapos < 3; datapos++)                 //we can only store 3 bone weights
                    {
                        byte b = data[datapos];
                        if (b != 0xff && b < g.UsedJoints.Count)
                        {
                            int bnr = g.UsedJoints[b];
                            if (used.Contains(bnr))
                            {
                                continue;
                            }


                            used.Add(bnr);
                            Ambertation.Scenes.Joint nj = jointmap[bnr] as Ambertation.Scenes.Joint;
                            if (nj != null)
                            {
                                double w = 1;
                                if (bonewighte != null)
                                {
                                    if (bonewighte.Values.Count > pos)
                                    {
                                        SimPe.Plugin.Gmdc.GmdcElementValueBase v = bonewighte.Values[pos];
                                        if (datapos < v.Data.Length)
                                        {
                                            w = v.Data[datapos];
                                        }
                                    }
                                }

                                //if there is no envelope for nj, make sure we get a new one
                                //with pos 0-Weights inserted
                                Ambertation.Scenes.Envelope e = m.GetJointEnvelope(nj, pos);
                                e.Weights.Add(w);
                                //added = true;
                            }
                        }
                    }

                    pos++;
                    m.SyncEnvelopeLenghts(pos); //fill all unset EnvelopeWeights with 0
                }                               // bonee.Values
            }
        }
Example #7
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        public void Unserialize(System.IO.BinaryReader reader)
        {
            number = reader.ReadInt32();
            uint id = reader.ReadUInt32();

            identity    = (ElementIdentity)id;
            repeat      = reader.ReadInt32();
            blockformat = (SimPe.Plugin.Gmdc.BlockFormat)reader.ReadInt32();
            setformat   = (SimPe.Plugin.Gmdc.SetFormat)reader.ReadInt32();

            GmdcElementValueBase dummy = GetValueInstance();
            int len = reader.ReadInt32() / (4 * dummy.Size);

            data.Clear();
            for (int i = 0; i < len; i++)
            {
                dummy = GetValueInstance();
                dummy.Unserialize(reader);
                data.Add(dummy);
            }

            this.ReadBlock(reader, items);
        }
Example #8
0
 public ElementSetCompare(GmdcElementValueBase v, GmdcElementValueBase vn, GmdcElementValueBase vu)
 {
     V  = v;
     VN = vn;
     VU = vu;
 }
Example #9
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(GmdcElementValueBase item)
 {
     return(base.Contains(item));
 }
Example #10
0
 /// <summary>
 /// remove an Element
 /// </summary>
 /// <param name="item">The object that should be removed</param>
 public void Remove(GmdcElementValueBase item)
 {
     base.Remove(item);
 }
Example #11
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, GmdcElementValueBase item)
 {
     base.Insert(index, item);
 }
Example #12
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(GmdcElementValueBase item)
 {
     return(base.Add(item));
 }