Exemplo n.º 1
0
        public void CreateAnimation(string fileName, Device device)
        {
            AllocatedHierarchyDerived alloc = new AllocatedHierarchyDerived();

            rootFrame = Mesh.LoadHierarchy(ResourcesLoader.LoadStream(fileName), MeshFlags.Managed, device, alloc, null);

            SetupBoneMatrices((FrameDerived)rootFrame.FrameHierarchy);
        }
        public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
        {
            if (meshData.Mesh == null)
            {
                throw new ArgumentException();
            }
            if (meshData.Mesh.VertexFormat == VertexFormats.None)
            {
                throw new ArgumentException();
            }
            MeshContainerDerived mesh = new MeshContainerDerived();

            mesh.Name = name;
            int    numFaces = meshData.Mesh.NumberFaces;
            Device dev      = meshData.Mesh.Device;

            if ((meshData.Mesh.VertexFormat & VertexFormats.Normal) == 0)
            {
                Mesh tempMesh = meshData.Mesh.Clone(meshData.Mesh.Options.Value, meshData.Mesh.VertexFormat | VertexFormats.Normal, dev);
                meshData.Mesh = tempMesh;
                meshData.Mesh.ComputeNormals();
            }
            mesh.SetMaterials(materials);
            mesh.SetAdjacency(adjacency);
            Texture[] meshTextures = new Texture[materials.Length];

            for (int i = 0; i < materials.Length; i++)
            {
                if (!string.IsNullOrEmpty(materials[i].TextureFilename))
                {
                    meshTextures[i] = TextureLoader.FromStream(dev, ResourcesLoader.LoadStream(materials[i].TextureFilename));
                }
            }
            mesh.meshTextures = meshTextures;
            mesh.MeshData     = meshData;

            if (skinInfo != null)
            {
                mesh.SkinInformation = skinInfo;
                int      numBones       = skinInfo.NumberBones;
                Matrix[] offsetMatrices = new Matrix[numBones];

                for (int i = 0; i < numBones; i++)
                {
                    offsetMatrices[i] = skinInfo.GetBoneOffsetMatrix(i);
                }
                mesh.offsetMatrices = offsetMatrices;
                MeshContainerDerived.GenerateSkinnedMesh(mesh);
            }
            return(mesh);
        }
Exemplo n.º 3
0
 public void SetMesh(string file)
 {
     mesh = Mesh.FromStream(ResourcesLoader.LoadStream(file), 0x0, MainForm.device, out materials);
 }