/// <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; }
/// <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); } } } } } } }