void AddElement(GmdcElement e, GmdcGroup g, bool update) { if (e == null) { return; } if (update) { GmdcElement eo = g.Link.FindElementType(e.Identity); if (eo != null) { int index = g.Link.GetElementNr(eo); index = g.Link.ReferencedElement[index]; gmi.Gmdc.Elements[index] = eo; return; } } gmi.Gmdc.Elements.Add(e); g.Link.ReferencedElement.Add(gmi.Gmdc.Elements.Count - 1); g.Link.ReferencedSize = g.Link.GetReferencedSize(); g.Link.ActiveElements = g.Link.ReferencedElement.Count; }
void SetFaces(GmdcGroup g) { g.Faces.Clear(); foreach (Ambertation.Geometry.Vector3i v in mesh.FaceIndices) { g.Faces.Add(v.X); g.Faces.Add(v.Y); g.Faces.Add(v.Z); } }
/// <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; }
/// <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 } }
/// <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; }
void SetUsedJoints(GmdcGroup g) { g.UsedJoints.Clear(); GmdcElement be = this.BuildBoneElement(); GmdcElement bw = this.BuildWeightElement(); AddElement(be, g, Action == GenericMeshImport.ImportAction.Update); AddElement(bw, g, Action == GenericMeshImport.ImportAction.Update); if (be != null && bw != null) { foreach (Ambertation.Scenes.Envelope e in mesh.Envelopes) { if (e.Joint.Tag != null) { if ((int)e.Joint.Tag >= 0) { g.UsedJoints.Add((int)e.Joint.Tag); SetBones(e, g.UsedJoints.Count - 1, be, bw); } } } } }
/// <summary> /// Add the passed Group to the BoundingMesh Definition /// </summary> /// <param name="g"></param> public void AddGroupToBoundingMesh(GmdcGroup g) { if (g == null) { return; } if (g.Link == null) { return; } int nr = g.Link.GetElementNr(g.Link.FindElementType(ElementIdentity.Vertex)); int offset = this.BoundingMesh.VertexCount; for (int i = 0; i < g.Link.ReferencedSize; i++) { Vector3f v = new Vector3f(g.Link.GetValue(nr, i).Data[0], g.Link.GetValue(nr, i).Data[1], g.Link.GetValue(nr, i).Data[2]); this.BoundingMesh.Vertices.Add(v); } for (int i = 0; i < g.Faces.Count; i++) { this.BoundingMesh.Items.Add(g.Faces[i] + offset); } }
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); } }
/// <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(GmdcGroup item) { return(base.Contains(item)); }
/// <summary> /// remove an Element /// </summary> /// <param name="item">The object that should be removed</param> public void Remove(GmdcGroup item) { base.Remove(item); }
/// <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, GmdcGroup item) { base.Insert(index, item); }
/// <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(GmdcGroup item) { return(base.Add(item)); }