/// <summary> /// Vytvoreni progressive meshe /// </summary> /// <param name="rootFrame">rootframe animace</param> /// <returns>vztvoreni progressive mesh</returns> private ProgressiveMesh GetMesh(AnimationRootFrame rootFrame) { ProgressiveMesh pm = null; Frame rf = rootFrame.FrameHierarchy; List <MeshContainer> meshes = new List <MeshContainer>(); getAnimationMesh(rf, meshes); anim.AnimationMeshContainer container = meshes[0] as anim.AnimationMeshContainer; int use32Bit = (int)(container.MeshData.Mesh.Options.Value & MeshFlags.Use32Bit); GraphicsStream adjacency = container.GetAdjacencyStream();//container.adjency; using (Mesh currentmesh = Mesh.Clean(CleanType.Simplification, container.MeshData.Mesh, adjacency, adjacency)) { WeldEpsilons epsilons = new WeldEpsilons(); currentmesh.WeldVertices(0, epsilons, adjacency, adjacency); currentmesh.Validate(adjacency); Mesh newmesh = currentmesh.Optimize(MeshFlags.OptimizeStripeReorder | MeshFlags.OptimizeAttributeSort, adjacency); using (newmesh = currentmesh.Clone(MeshFlags.Managed | (MeshFlags)use32Bit, GeneralObject.GeneralVertex.vertexElements, container.MeshData.Mesh.Device)) { newmesh.ComputeNormals(); pm = new ProgressiveMesh(newmesh, adjacency, null, 1, MeshFlags.SimplifyFace); } } return(pm); }
/// <summary> /// nastaveni kosti animace /// </summary> /// <param name="mesh">frame s animaci</param> private void SetupBoneMatrices(anim.AnimationMeshContainer mesh) { // Is there skin information? If so, setup the matrices if (mesh.SkinInformation != null) { int numberBones = mesh.SkinInformation.NumberBones; anim.AnimationFrame[] frameMatrices = new anim.AnimationFrame[numberBones]; for (int i = 0; i < numberBones; i++) { anim.AnimationFrame frame = Frame.Find(rootFrame.FrameHierarchy, mesh.SkinInformation.GetBoneName(i)) as anim.AnimationFrame; if (frame == null) { throw new InvalidOperationException("Could not find valid bone."); } frameMatrices[i] = frame; } mesh.SetFrames(frameMatrices); } }