Example #1
0
        private static unsafe AiMesh[] Parse(EZMMesh ezmMesh)
        {
            EZMVertexbuffer vertexbuffer = ezmMesh.Vertexbuffer;

            vec3[]  vertexes    = GetPositions(vertexbuffer);
            vec3[]  normals     = GetNormals(vertexbuffer);
            vec2[]  texCoords   = GetTexCoords(vertexbuffer);
            vec4[]  boneWeights = GetBoneWeights(vertexbuffer);
            uvec4[] boneIndexes = GetBoneIndexes(vertexbuffer);

            EZMMeshSection[] meshSections = ezmMesh.MeshSections;
            var aiMeshes = new AiMesh[meshSections.Length];

            for (int i = 0; i < aiMeshes.Length; i++)
            {
                EZMMeshSection section = meshSections[i];
                var            aiMesh  = new AiMesh();
                aiMesh.Vertexes     = vertexes;
                aiMesh.Normals      = normals;
                aiMesh.TexCoords    = texCoords;
                aiMesh.boneWeights  = boneWeights;
                aiMesh.boneIndexes  = boneIndexes;
                aiMesh.indexes      = section.Indexbuffer;
                aiMesh.materialName = section.MaterialName;
                aiMeshes[i]         = aiMesh;
            }

            return(aiMeshes);
        }
        // <MeshSection material="character_anim:headM" ctype="fff fff ff ff ff ffff hhhh" semantic="position normal texcoord1 texcoord2 texcoord3 blendweights blendindices">
        /// <summary>
        ///
        /// </summary>
        /// <param name="xMeshSection"></param>
        /// <returns></returns>
        public static EZMMeshSection Parse(System.Xml.Linq.XElement xElement)
        {
            EZMMeshSection result = null;

            if (xElement.Name == "MeshSection")
            {
                result = new EZMMeshSection();
                {
                    var attr = xElement.Attribute("material");
                    if (attr != null)
                    {
                        result.MaterialName = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("ctype");
                    if (attr != null)
                    {
                        result.Ctype = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("semantic");
                    if (attr != null)
                    {
                        result.Semantic = attr.Value;
                    }
                }
                {
                    var aabb = xElement.Element("MeshAABB");
                    if (aabb != null)
                    {
                        var xMin = aabb.Attribute("min");
                        if (xMin != null)
                        {
                            string[] parts = xMin.Value.Split(Separator.separators, StringSplitOptions.RemoveEmptyEntries);
                            var      x     = float.Parse(parts[0]);
                            var      y     = float.Parse(parts[1]);
                            var      z     = float.Parse(parts[2]);
                            result.Min = new vec3(x, y, z);
                        }
                        var xMax = aabb.Attribute("max");
                        if (xMax != null)
                        {
                            string[] parts = xMax.Value.Split(Separator.separators, StringSplitOptions.RemoveEmptyEntries);
                            var      x     = float.Parse(parts[0]);
                            var      y     = float.Parse(parts[1]);
                            var      z     = float.Parse(parts[2]);
                            result.Max = new vec3(x, y, z);
                        }
                    }
                }
                {
                    result.Indexbuffer = ParseIndexbuffer(xElement.Element("indexbuffer"));
                }
            }

            return(result);
        }
Example #3
0
        // <Mesh name="him" skeleton="null" submesh_count="5">
        /// <summary>
        ///
        /// </summary>
        /// <param name="xElement"></param>
        /// <returns></returns>
        public static EZMMesh Parse(XElement xElement)
        {
            EZMMesh result = null;

            if (xElement.Name == "Mesh")
            {
                result = new EZMMesh();
                {
                    var attr = xElement.Attribute("name");
                    if (attr != null)
                    {
                        result.Name = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("skeleton");
                    if (attr != null)
                    {
                        result.SkeletonName = attr.Value;
                    }
                }
                {
                    result.Vertexbuffer = EZMVertexbuffer.Parse(xElement.Element("vertexbuffer"));
                }
                {
                    var xMeshSections = xElement.Elements("MeshSection");
                    var meshSections  = new EZMMeshSection[xMeshSections.Count()];
                    int index         = 0;
                    foreach (var xMeshSection in xMeshSections)
                    {
                        meshSections[index++] = EZMMeshSection.Parse(xMeshSection);
                    }
                    result.MeshSections = meshSections;
                }
            }

            return(result);
        }