Пример #1
0
 /// <summary>
 /// Create a new Instance
 /// </summary>
 /// <param name="parent">The gmdc that should act as Parent</param>
 public ImportedGroup(GeometryDataContainer parent) : base()
 {
     keeporder  = true;
     group      = new GmdcGroup(parent);
     link       = new GmdcLink(parent);
     elements   = new GmdcElements();
     useinbmesh = false;
 }
Пример #2
0
        /// <summary>
        /// Load Data into the Vertex, Normal an UVCoordinateElement members
        /// </summary>
        /// <param name="group"></param>
        void LoadSpecialElements(GmdcGroup group)
        {
            vertex     = null;
            normal     = null;
            uvmap      = null;
            link       = null;
            this.group = group;

            if (group == null)
            {
                return;
            }
            if (gmdc == null)
            {
                return;
            }

            if (group.LinkIndex < Gmdc.Links.Length)
            {
                link = Gmdc.Links[group.LinkIndex];
                foreach (int i in link.ReferencedElement)
                {
                    if (i < Gmdc.Elements.Length)
                    {
                        GmdcElement e = Gmdc.Elements[i];
                        if (e.Identity == ElementIdentity.Vertex)
                        {
                            vertex = e;
                        }
                        else if (e.Identity == ElementIdentity.Normal)
                        {
                            normal = e;
                        }
                        else if (e.Identity == ElementIdentity.UVCoordinate)
                        {
                            uvmap = e;
                        }
                    }
                }                 //foreach
            }
        }
Пример #3
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;
        }
Пример #4
0
        public void BuildGroup()
        {
            if (this.Group == null && this.Action == GenericMeshImport.ImportAction.Replace)
            {
                this.Action = GenericMeshImport.ImportAction.Add;
            }
            if (this.Group == null && this.Action == GenericMeshImport.ImportAction.Update)
            {
                this.Action = GenericMeshImport.ImportAction.Add;
            }
            if (Action == GenericMeshImport.ImportAction.Ignore)
            {
                return;
            }

            GmdcGroup g;

            if (Action == GenericMeshImport.ImportAction.Update)
            {
                g = Group;
            }
            else if (Action == GenericMeshImport.ImportAction.Replace)
            {
                int gindex = gmi.Gmdc.FindGroupByName(Group.Name);
                gmi.Gmdc.RemoveGroup(gindex);

                g = new GmdcGroup(gmi.Gmdc);
                gmi.Gmdc.Groups.Add(g);
            }
            else
            {
                g = new GmdcGroup(gmi.Gmdc);
                gmi.Gmdc.Groups.Add(g);
            }

            //make sure the Group references a Link
            if (g.Link == null)
            {
                GmdcLink l = new GmdcLink(gmi.Gmdc);
                gmi.Gmdc.Links.Add(l);
                g.LinkIndex = gmi.Gmdc.Links.Count - 1;
            }

            g.Name = mesh.Name;
            if (Shadow)
            {
                g.Opacity = 0x10;
            }
            else
            {
                g.Opacity = 0xffffffff;
            }
            g.PrimitiveType = PrimitiveType.Triangle;

            mesh.Tag = new object[] { this, g };

            AddElement(this.BuildVertexElement(), g, Action == GenericMeshImport.ImportAction.Update);
            AddElement(this.BuildNormalElement(), g, Action == GenericMeshImport.ImportAction.Update);
            AddElement(this.BuildTextureElement(), g, Action == GenericMeshImport.ImportAction.Update);

            SetFaces(g);
            if (this.ImportEnvelope)
            {
                SetUsedJoints(g);
            }
        }
Пример #5
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(GmdcLink item)
 {
     return(base.Contains(item));
 }
Пример #6
0
 /// <summary>
 /// remove an Element
 /// </summary>
 /// <param name="item">The object that should be removed</param>
 public void Remove(GmdcLink item)
 {
     base.Remove(item);
 }
Пример #7
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, GmdcLink item)
 {
     base.Insert(index, item);
 }
Пример #8
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(GmdcLink item)
 {
     return(base.Add(item));
 }
Пример #9
0
        /// <summary>
        /// Adjusts the Vertex List, from all Elements Vertices that are assigned to this joint
        /// </summary>
        public void CollectVertices()
        {
            //first get my Number in the Parent
            int index = Index;

            this.Vertices.Clear();
            this.Items.Clear();

            if (index == -1)
            {
                return;                        //not within Parent!
            }
            //scan all Groups in the Parent for Joint Assignements
            foreach (GmdcGroup g in parent.Groups)
            {
                GmdcLink    l      = parent.Links[g.LinkIndex];
                GmdcElement joints = l.FindElementType(ElementIdentity.BoneAssignment);

                GmdcElement vertices = l.FindElementType(ElementIdentity.Vertex);
                int         vindex   = l.GetElementNr(vertices);

                if (joints == null || vertices == null)
                {
                    continue;
                }
                for (int i = 0; i < g.UsedJoints.Count; i++)
                {
                    //this Bone is a Match, so add all assigned vertices
                    if (g.UsedJoints[i] == index)
                    {
                        Hashtable indices = new Hashtable();
                        Hashtable empty   = new Hashtable();

                        //load the vertices
                        for (int k = 0; k < joints.Values.Count; k++)
                        {
                            GmdcElementValueOneInt voi = (GmdcElementValueOneInt)joints.Values[k];

                            //All vertices either are within the empty or indices map
                            if (voi.Bytes[0] == (byte)i)
                            {
                                indices.Add(k, this.Vertices.Count);
                                this.Vertices.Add(Transform(index, new Vector3f(vertices.Values[k].Data[0], vertices.Values[k].Data[1], vertices.Values[k].Data[2])));
                            }
                            else                             //all unassigned Vertices get 0
                            {
                                empty.Add(k, this.Vertices.Count);
                                this.Vertices.Add(new Vector3f(0, 0, 0));
                            }
                        }

                        //now all faces where at least one vertex is assigned to a Bone
                        for (int f = 0; f < g.Faces.Count - 2; f += 3)
                        {
                            if (indices.ContainsKey(l.GetRealIndex(vindex, g.Faces[f])) ||
                                indices.ContainsKey(l.GetRealIndex(vindex, g.Faces[f + 1])) ||
                                indices.ContainsKey(l.GetRealIndex(vindex, g.Faces[f + 2])))
                            {
                                for (int k = 0; k < 3; k++)
                                {
                                    int nr         = l.GetRealIndex(vindex, g.Faces[f + k]);
                                    int face_index = -1;

                                    //this Vertex was empty and is now needed,
                                    //so add it to the available List
                                    if (!indices.ContainsKey(nr))
                                    {
                                        if (empty.ContainsKey(nr))
                                        {
                                            face_index = (int)empty[nr];
                                        }
                                        else
                                        {
                                            face_index = nr;
                                        }

                                        indices.Add(nr, face_index);
                                        this.Vertices[face_index] = Transform(index, new Vector3f(vertices.Values[nr].Data[0], vertices.Values[nr].Data[1], vertices.Values[nr].Data[2]));
                                    }

                                    face_index = (int)indices[nr];
                                    this.Items.Add(face_index);
                                }
                            }
                        }
                    }
                }
            }
        }