コード例 #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);
        }
コード例 #2
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);
        }
コード例 #3
0
        // <MeshSystem asset_name="dude.fbx" asset_info="null" mesh_system_version="1" mesh_system_asset_version="0">
        /// <summary>
        ///
        /// </summary>
        /// <param name="xElement"></param>
        /// <returns></returns>
        public static EZMMeshSystem Parse(System.Xml.Linq.XElement xElement)
        {
            EZMMeshSystem result = null;

            if (xElement.Name == "MeshSystem")
            {
                result = new EZMMeshSystem();
                {
                    var attr = xElement.Attribute("asset_name");
                    if (attr != null)
                    {
                        result.AssetName = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("asset_info");
                    if (attr != null)
                    {
                        result.AssetInfo = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("mesh_system_version");
                    if (attr != null)
                    {
                        result.Version = attr.Value;
                    }
                }
                {
                    var attr = xElement.Attribute("mesh_system_asset_version");
                    if (attr != null)
                    {
                        result.AssetVersion = attr.Value;
                    }
                }
                {
                    var skeletionRoot = xElement.Element("Skeletons");
                    if (skeletionRoot != null)
                    {
                        var xSkeletons = skeletionRoot.Elements("Skeleton");
                        var skeletons  = new EZMSkeleton[xSkeletons.Count()];
                        int index      = 0;
                        foreach (var xSkeleton in xSkeletons)
                        {
                            skeletons[index++] = EZMSkeleton.Parse(xSkeleton);
                        }
                        result.Skeletons = skeletons;
                    }
                }
                {
                    var animationRoot = xElement.Element("Animations");
                    if (animationRoot != null)
                    {
                        var xAnimations = animationRoot.Elements("Animation");
                        var animations  = new EZMAnimation[xAnimations.Count()];
                        int index       = 0;
                        foreach (var xAnimation in xAnimations)
                        {
                            var animation = EZMAnimation.Parse(xAnimation);
                            foreach (var animTrack in animation.AnimTracks)
                            {
                                string name = animTrack.BoneName;
                                if (name != null)
                                {
                                    foreach (var skeleton in result.Skeletons)
                                    {
                                        EZMBone bone = null;
                                        if (skeleton.nameBoneDict.TryGetValue(name, out bone))
                                        {
                                            if (animTrack.Bone != null)
                                            {
                                                throw new Exception("More than 1 bone for the animTrack!");
                                            }

                                            animTrack.Bone = bone;
                                            //break;
                                        }
                                    }
                                }
                            }
                            animations[index++] = animation;
                        }
                        result.Animations = animations;
                    }
                }

                var nameMaterialDict = new Dictionary <string, EZMMaterial>();
                {
                    var materialsRoot = xElement.Element("Materials");
                    if (materialsRoot != null)
                    {
                        var xMaterials = materialsRoot.Elements("Material");
                        var materials  = new EZMMaterial[xMaterials.Count()];
                        int index      = 0;
                        foreach (var xMaterial in xMaterials)
                        {
                            var material = EZMMaterial.Parse(xMaterial);
                            nameMaterialDict.Add(material.Name, material);
                            materials[index++] = material;
                        }
                        result.Materials = materials;
                    }
                }
                {
                    var meshesRoot = xElement.Element("Meshes");
                    if (meshesRoot != null)
                    {
                        var xMeshes = meshesRoot.Elements("Mesh");
                        var meshes  = new EZMMesh[xMeshes.Count()];
                        int index   = 0;
                        foreach (var xMesh in xMeshes)
                        {
                            EZMMesh mesh = EZMMesh.Parse(xMesh);
                            foreach (var meshSection in mesh.MeshSections)
                            {
                                string      name     = meshSection.MaterialName;
                                EZMMaterial material = null;
                                if (nameMaterialDict.TryGetValue(name, out material))
                                {
                                    meshSection.Material = material;
                                }
                            }
                            EZMSkeleton[] skeletons = result.Skeletons;
                            if (skeletons.Length > 0)
                            {
                                if (string.IsNullOrEmpty(mesh.SkeletonName) ||
                                    mesh.SkeletonName == "null")
                                {
                                    mesh.Skeleton = skeletons[0];
                                }
                                else
                                {
                                    foreach (var skeleton in skeletons)
                                    {
                                        if (mesh.SkeletonName == skeleton.Name)
                                        {
                                            mesh.Skeleton = skeleton;
                                            break;
                                        }
                                    }
                                }
                            }
                            meshes[index++] = mesh;
                        }
                        result.Meshes = meshes;
                    }
                }
            }

            return(result);
        }