public void Read(XmlNode root) { count = int.Parse((string)root.Attributes["count"].Value); foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("input")) { ColladaInput input = new ColladaInput(); input.Read(node); inputs.Add(input); } if (node.Name.Equals("vcount")) { string[] ps = node.InnerText.Trim().Split(' '); vcount = new int[ps.Length]; for (int i = 0; i < ps.Length; i++) { vcount[i] = int.Parse(ps[i]); } } if (node.Name.Equals("v")) { string[] ps = node.InnerText.Trim().Split(' '); v = new int[ps.Length]; for (int i = 0; i < ps.Length; i++) { v[i] = int.Parse(ps[i]); } } } }
public void Read(XmlNode root) { foreach (XmlAttribute att in root.Attributes) { if (att.Name.Equals("material")) { materialid = (string)att.Value; } if (att.Name.Equals("count")) { int.TryParse((string)att.Value, out count); } } foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("input")) { ColladaInput input = new ColladaInput(); input.Read(node); inputs.Add(input); } if (node.Name.Equals("p")) { string[] ps = node.InnerText.Trim().Split(' '); p = new int[ps.Length]; for (int i = 0; i < ps.Length; i++) { p[i] = int.Parse(ps[i]); } } } }
public void Read(XmlNode root) { foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("input")) { ColladaInput input = new ColladaInput(); input.Read(node); inputs.Add(input); } } }
public void Read(XmlNode root) { id = (string)root.Attributes["id"].Value; foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("input")) { ColladaInput input = new ColladaInput(); input.Read(node); inputs.Add(input); } } }
static ModelMeshPartData LoadPolygons(ModelData data, ColladaPolygons polygons) { c__DisplayClass3_0 c__DisplayClass3_ = new c__DisplayClass3_0(); ModelMeshPartData modelMeshPartData = new ModelMeshPartData(); int num = 0; Dictionary <VertexElement, ColladaInput> dictionary = new Dictionary <VertexElement, ColladaInput>(); foreach (ColladaInput current in polygons.Inputs) { string str = (current.Set == 0) ? string.Empty : current.Set.ToString(CultureInfo.InvariantCulture); if (current.Semantic == "POSITION") { dictionary[new VertexElement(num, VertexElementFormat.Vector3, "POSITION" + str)] = current; num += 12; } else if (current.Semantic == "NORMAL") { dictionary[new VertexElement(num, VertexElementFormat.Vector3, "NORMAL" + str)] = current; num += 12; } else if (current.Semantic == "TEXCOORD") { dictionary[new VertexElement(num, VertexElementFormat.Vector2, "TEXCOORD" + str)] = current; num += 8; } else if (current.Semantic == "COLOR") { dictionary[new VertexElement(num, VertexElementFormat.NormalizedByte4, "COLOR" + str)] = current; num += 4; } } c__DisplayClass3_.vertexDeclaration = new VertexDeclaration(dictionary.Keys.ToArray <VertexElement>()); ModelBuffersData modelBuffersData = data.Buffers.FirstOrDefault(new Func <ModelBuffersData, bool>(c__DisplayClass3_.b__0)); if (modelBuffersData == null) { modelBuffersData = new ModelBuffersData(); data.Buffers.Add(modelBuffersData); modelBuffersData.VertexDeclaration = c__DisplayClass3_.vertexDeclaration; } modelMeshPartData.BuffersDataIndex = data.Buffers.IndexOf(modelBuffersData); int num2 = polygons.P.Count / polygons.InputCount; List <int> list = new List <int>(); if (polygons.VCount.Count == 0) { int num3 = 0; for (int i = 0; i < num2 / 3; i++) { list.Add(num3); list.Add(num3 + 2); list.Add(num3 + 1); num3 += 3; } } else { int num4 = 0; foreach (int current2 in polygons.VCount) { if (current2 == 3) { list.Add(num4); list.Add(num4 + 2); list.Add(num4 + 1); num4 += 3; } else { if (current2 != 4) { throw new NotSupportedException("Collada polygons with less than 3 or more than 4 vertices are not supported."); } list.Add(num4); list.Add(num4 + 2); list.Add(num4 + 1); list.Add(num4 + 2); list.Add(num4); list.Add(num4 + 3); num4 += 4; } } } int vertexStride = modelBuffersData.VertexDeclaration.VertexStride; int num5 = modelBuffersData.Vertices.Length; modelBuffersData.Vertices = ExtendArray <byte>(modelBuffersData.Vertices, list.Count * vertexStride); using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(modelBuffersData.Vertices, num5, list.Count * vertexStride))) { bool flag = false; foreach (KeyValuePair <VertexElement, ColladaInput> current3 in dictionary) { VertexElement key = current3.Key; ColladaInput value = current3.Value; if (key.Semantic.StartsWith("POSITION")) { for (int j = 0; j < list.Count; j++) { float[] arg_3EF_0 = value.Source.Accessor.Source.Array; int offset = value.Source.Accessor.Offset; int stride = value.Source.Accessor.Stride; int num6 = polygons.P[list[j] * polygons.InputCount + value.Offset]; binaryWriter.BaseStream.Position = (long)(j * vertexStride + key.Offset); float num7 = arg_3EF_0[offset + stride * num6]; float num8 = arg_3EF_0[offset + stride * num6 + 1]; float num9 = arg_3EF_0[offset + stride * num6 + 2]; modelMeshPartData.BoundingBox = (flag ? BoundingBox.Union(modelMeshPartData.BoundingBox, new Vector3(num7, num8, num9)) : new BoundingBox(num7, num8, num9, num7, num8, num9)); flag = true; binaryWriter.Write(num7); binaryWriter.Write(num8); binaryWriter.Write(num9); } } else if (key.Semantic.StartsWith("NORMAL")) { for (int k = 0; k < list.Count; k++) { float[] arg_51E_0 = value.Source.Accessor.Source.Array; int offset2 = value.Source.Accessor.Offset; int stride2 = value.Source.Accessor.Stride; int num10 = polygons.P[list[k] * polygons.InputCount + value.Offset]; binaryWriter.BaseStream.Position = (long)(k * vertexStride + key.Offset); float num11 = arg_51E_0[offset2 + stride2 * num10]; float num12 = arg_51E_0[offset2 + stride2 * num10 + 1]; float num13 = arg_51E_0[offset2 + stride2 * num10 + 2]; float num14 = 1f / MathUtils.Sqrt(num11 * num11 + num12 * num12 + num13 * num13); binaryWriter.Write(num14 * num11); binaryWriter.Write(num14 * num12); binaryWriter.Write(num14 * num13); } } else if (key.Semantic.StartsWith("TEXCOORD")) { for (int l = 0; l < list.Count; l++) { float[] array = value.Source.Accessor.Source.Array; int offset3 = value.Source.Accessor.Offset; int stride3 = value.Source.Accessor.Stride; int num15 = polygons.P[list[l] * polygons.InputCount + value.Offset]; binaryWriter.BaseStream.Position = (long)(l * vertexStride + key.Offset); binaryWriter.Write(array[offset3 + stride3 * num15]); binaryWriter.Write(1f - array[offset3 + stride3 * num15 + 1]); } } else { if (!key.Semantic.StartsWith("COLOR")) { throw new Exception(); } for (int m = 0; m < list.Count; m++) { float[] array2 = value.Source.Accessor.Source.Array; int offset4 = value.Source.Accessor.Offset; int stride4 = value.Source.Accessor.Stride; int num16 = polygons.P[list[m] * polygons.InputCount + value.Offset]; binaryWriter.BaseStream.Position = (long)(m * vertexStride + key.Offset); Color color = new Color(array2[offset4 + stride4 * num16], array2[offset4 + stride4 * num16 + 1], array2[offset4 + stride4 * num16 + 2], array2[offset4 + stride4 * num16 + 3]); binaryWriter.Write(color.PackedValue); } } } } modelMeshPartData.StartIndex = num5 / vertexStride; modelMeshPartData.IndicesCount = list.Count; return(modelMeshPartData); }