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> /// Create a Clone of this Object /// </summary> /// <returns>The Clone</returns> public override GmdcElementValueBase Clone() { GmdcElementValueBase dest = new GmdcElementValueOneInt(); Clone(dest); return(dest); }
/// <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> /// 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); } } } } } } }