/// <summary> /// Creates a new <see cref="ImportedGroup"/> Instance with Default Settings /// </summary> /// <returns>a new Container for an Imported MeshGroup</returns> /// <remarks> /// You should use this whenever you have to add a new Group! /// </remarks> protected ImportedGroup PrepareGroup() { ImportedGroup g = new ImportedGroup(Gmdc); //Vertex Element----- GmdcElement e = new GmdcElement(Gmdc); g.Elements.Add(e); e.Identity = ElementIdentity.Vertex; e.BlockFormat = BlockFormat.ThreeFloat; e.SetFormat = SetFormat.Secondary; //Normal Element----- e = new GmdcElement(Gmdc); g.Elements.Add(e); e.Identity = ElementIdentity.Normal; e.BlockFormat = BlockFormat.ThreeFloat; e.SetFormat = SetFormat.Normals; //UVCoord Element----- e = new GmdcElement(Gmdc); g.Elements.Add(e); e.Identity = ElementIdentity.UVCoordinate; e.BlockFormat = BlockFormat.TwoFloat; e.SetFormat = SetFormat.Mapping; g.Group.PrimitiveType = PrimitiveType.Triangle; g.Group.Opacity = 0xffffffff; return(g); }
/// <summary> /// Returns a specific Value /// </summary> /// <param name="nr">The Number of the referenced Element (index to the ReferencedElement Member)</param> /// <param name="index">The index of the value you want to read from thet Element</param> /// <returns>-1 or an Element Index</returns> /// <remarks>To retrieve the correct number for an Element, see the GetElementNr() Method</remarks> public int GetRealIndex(int nr, int index) { try { int enr = this.items1[nr]; GmdcElement e = this.parent.Elements[enr]; //Higher Number if (nr >= refs.Length) { return(index); } //Do we have aliases? if (refs[nr].Length == 0) { return(index); } else { return(refs[nr][index]); } } catch { return(-1); } }
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 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]; } } }
/// <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); }
/// <summary> /// Returns the nr (as it can be used in GetValue() Method) of the passed Element in this Link Section /// </summary> /// <param name="e">Element you are looking for</param> /// <returns> /// -1 if the Element is not referenced from this Link or the index of that Element in the /// ReferenceElement Member /// </returns> public int GetElementNr(GmdcElement e) { if (e == null) { return(-1); } for (int i = 0; i < this.items1.Length; i++) { if (parent.Elements[items1[i]] == e) { return(i); } } return(-1); }
/// <summary> /// Add the passed Group to the Gmdc /// </summary> /// <param name="g"></param> protected virtual void AddGroup(ImportedGroup g) { 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; gmdc.Elements.Add(e); g.Link.ReferencedElement[i] = gmdc.Elements.Length - 1; } g.Group.LinkIndex = gmdc.Links.Length; gmdc.Links.Add(g.Link); gmdc.Groups.Add(g.Group); g.Link.ReferencedSize = g.Link.GetReferencedSize(); g.Link.ActiveElements = g.Link.ReferencedElement.Count; }
/// <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; }
GmdcElement BuildBoneElement() { if (mesh.Envelopes.Count == 0) { return(null); } GmdcElement e = new GmdcElement(gmi.Gmdc); e.SetFormat = SetFormat.Secondary; e.BlockFormat = BlockFormat.OneDword; e.Identity = ElementIdentity.BoneAssignment; e.GroupId = 0; e.Number = mesh.Vertices.Count; for (int i = 0; i < mesh.Vertices.Count; i++) { e.Values.Add(new GmdcElementValueOneInt(-1)); } return(e); }
GmdcElement BuildTextureElement() { if (mesh.TextureCoordinates.Count == 0) { return(null); } GmdcElement e = new GmdcElement(gmi.Gmdc); e.SetFormat = SetFormat.Secondary; e.BlockFormat = BlockFormat.TwoFloat; e.Identity = ElementIdentity.UVCoordinate; e.GroupId = 0; e.Number = mesh.Normals.Count; foreach (Ambertation.Geometry.Vector2 v in mesh.TextureCoordinates) { e.Values.Add(new GmdcElementValueTwoFloat((float)v.X, (float)(1 - v.Y))); } return(e); }
GmdcElement BuildWeightElement() { if (mesh.Envelopes.Count == 0) { return(null); } GmdcElement e = new GmdcElement(gmi.Gmdc); e.SetFormat = SetFormat.Secondary; e.BlockFormat = BlockFormat.ThreeFloat; e.Identity = ElementIdentity.BoneWeights; e.GroupId = 0; e.Number = mesh.Vertices.Count; for (int i = 0; i < mesh.Vertices.Count; i++) { e.Values.Add(new GmdcElementValueThreeFloat(0, 0, 0)); } return(e); }
GmdcElement BuildNormalElement() { if (mesh.Normals.Count == 0) { return(null); } GmdcElement e = new GmdcElement(gmi.Gmdc); e.SetFormat = SetFormat.Secondary; e.BlockFormat = BlockFormat.ThreeFloat; e.Identity = ElementIdentity.Normal; e.GroupId = 0; e.Number = mesh.Normals.Count; foreach (Ambertation.Geometry.Vector3 v in mesh.Normals) { Ambertation.Geometry.Vector3 vt = gmi.Component.InverseTransformNormal(v); e.Values.Add(new GmdcElementValueThreeFloat((float)vt.X, (float)vt.Y, (float)vt.Z)); } return(e); }
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> /// Returns a specific Value /// </summary> /// <param name="nr">The Number of the referenced Element (index to the ReferencedElement Member)</param> /// <param name="index">The index of the value you want to read from thet Element</param> /// <returns>The stored Value or null on error</returns> /// <remarks>To retrieve the correct number for an Element, see the GetElementNr() Method</remarks> public SimPe.Plugin.Gmdc.GmdcElementValueBase GetValue(int nr, int index) { try { //if (nr>=this.items1.Length) return null; int enr = this.items1[nr]; //if (enr>=this.parent.Elements.Length) return null; GmdcElement e = this.parent.Elements[enr]; //Higher Number if (nr >= refs.Length) { //if (index>=e.Values.Length) return null; return(e.Values[index]); } //Do we have aliases? if (refs[nr].Length == 0) //no { //if (index>=e.Values.Length) return null; return(e.Values[index]); } else //yes { //if (index>=this.refs.Length) return null; index = refs[nr][index]; //if (index>=e.Values.Length) return null; return(e.Values[index]); } } catch { return(null); } }
/// <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(GmdcElement item) { return(base.Add(item)); }
/// <summary> /// remove an Element /// </summary> /// <param name="item">The object that should be removed</param> public void Remove(GmdcElement item) { base.Remove(item); }
/// <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(GmdcElement item) { return(base.Contains(item)); }
/// <summary> /// Makes sure that the Aliaslists are not used! /// </summary> public void Flatten() { GmdcElement vn = new GmdcElement(this.parent); GmdcElement vt = new GmdcElement(this.parent); GmdcElement ovn = this.FindElementType(ElementIdentity.Normal); GmdcElement ovt = this.FindElementType(ElementIdentity.UVCoordinate); //contains a List of all additional Elements assigned to this Link, which //are related to the Vertex Element (like BoneWeights) GmdcElements ovelements = new GmdcElements(); GmdcElements velements = new GmdcElements(); ovelements.Add(this.FindElementType(ElementIdentity.Vertex)); velements.Add(new GmdcElement(this.Parent)); int nv = this.GetElementNr(ovelements[0]); int nvn = this.GetElementNr(ovn); int nvt = this.GetElementNr(ovt); //add all other Elements foreach (int i in this.ReferencedElement) { if (ovelements.Contains(parent.Elements[i]) || parent.Elements[i] == ovn || parent.Elements[i] == ovt) { continue; } ovelements.Add(parent.Elements[i]); velements.Add(new GmdcElement(this.Parent)); } for (int i = 0; i < this.ReferencedSize; i++) { for (int j = 0; j < velements.Length; j++) { velements[j].Values.Add(ovelements[j].Values[this.GetRealIndex(nv, i)]); } if (ovn != null) { vn.Values.Add(ovn.Values[this.GetRealIndex(nvn, i)]); } if (ovt != null) { vt.Values.Add(ovt.Values[this.GetRealIndex(nvt, i)]); } } for (int i = 0; i < velements.Length; i++) { ovelements[i].Values = velements[i].Values; ovelements[i].Number = velements[i].Number; } if (ovn != null) { ovn.Values = vn.Values; ovn.Number = ReferencedSize; } if (ovt != null) { ovt.Values = vt.Values; ovt.Number = ReferencedSize; } for (int i = 0; i < this.AliasValues.Length; i++) { this.AliasValues[i].Clear(); } }
/// <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); } } } } } } }
/// <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, GmdcElement item) { base.Insert(index, item); }