예제 #1
0
        /// <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);
        }
예제 #2
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);
        }
예제 #3
0
파일: Context.cs 프로젝트: senny970/2007
        public static OpsModel FromFile(Device device, string path)
        {
            OpsModel result = new OpsModel();

            OpsAllocateHierarchy alloc = new OpsAllocateHierarchy();

            AnimationRootFrame arf = Mesh.LoadHierarchyFromFile(path, MeshFlags.SystemMemory | MeshFlags.Use32Bit, device, alloc, null);

            result.HierarchyRoot  = arf.FrameHierarchy;
            result.AnimationMixer = arf.AnimationController;

            result.Name = System.IO.Path.GetFileNameWithoutExtension(path);

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Nacteni animovaneho modelu
        /// </summary>
        /// <param name="loaded">>Entita do ktere bude pridan parametr s animaci</param>
        /// <param name="objectUrl">Adresa k souboru .X s animaci</param>
        /// <param name="name">Jmeno modelu</param>
        /// <returns>Entitu s animaci</returns>
        private Entity LoadAnimatedObject(Entity loaded, string objectUrl, string name)
        {
            AllocateHierarchy alloc;

            alloc = new WiccanRede.Graphics.Scene.SpecialObjects.AnimatedObject.AnimationAllocation();

            try
            {
                rootFrame = Mesh.LoadHierarchyFromFile(objectUrl, MeshFlags.Managed, dev, alloc, null);
            }
            catch (Exception)
            {
                Console.WriteLine("Chyba pri nacitani ze souboru");
            }

            SetupBoneMatrices(rootFrame.FrameHierarchy as anim.AnimationFrame);

            List <MeshContainer> meshes = new List <MeshContainer>();
            Frame rf = rootFrame.FrameHierarchy;

            getAnimationMesh(rf, meshes);

            MeshContainer mc = meshes[0];

            ExtendedMaterial[] materials = mc.GetMaterials();
            Texture[]          textures  = new Texture[materials.Length];
            string             pathname  = Path.GetDirectoryName(objectUrl) + @"\";

            // load textures
            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i].TextureFilename != null)
                {
                    if (File.Exists((pathname + materials[i].TextureFilename)))
                    {
                        textures[i] = TextureLoader.FromFile(dev, (pathname + materials[i].TextureFilename),
                                                             0, 0, 0, Usage.None, Format.R8G8B8, Pool.Managed, Filter.Linear, Filter.Linear, 0);
                    }
                }
            }

            loaded.AddParametr(new Parametr("Objekt[]", "textures", textures));
            loaded.AddParametr(new Parametr("Microsoft.DirectX.Direct3D.AnimationRootFrame", name, rootFrame));
            loaded.AddParametr(new Parametr("Microsoft.DirectX.Direct3D.ProgressiveMesh", "pMesh", GetMesh(rootFrame)));
            return(loaded);
        }
예제 #5
0
        /// <summary>
        /// Create the animation hierarchy for this file
        /// </summary>
        private void carregarModeloAnimado(string file, PresentParameters presentParams)
        {
            // Create our allocate hierarchy derived class
            HierarquiaAlojamento alloc = new HierarquiaAlojamento(this);

            // Load our file
            quadroRaiz = Mesh.LoadHierarchyFromFile(file, MeshFlags.Managed,
                                                    device, alloc, null);

            // Calculate the center and radius of a bounding sphere
            objetoRaio = Frame.CalculateBoundingSphere(quadroRaiz.FrameHierarchy,
                                                       out objetoCentro);

            // Setup the matrices for animation
            ossos_ConfigurarMatrizes((QuadroDerivado)quadroRaiz.FrameHierarchy);

            // Start the timer
            DXUtil.Timer(DirectXTimer.Start);
        } // carregarModeloAnimado().fim
예제 #6
0
        public AnimatedObject(Device device, Matrix world, AnimationRootFrame rootFrame, Texture[] textures, ProgressiveMesh pMesh)
            : base(pMesh, world, textures, null, null, null)
        {
            meshes = new List <AnimationFrame>();
            Frame rf = rootFrame.FrameHierarchy;

            if (rootFrame.FrameHierarchy != null)
            {
                getAnimationMesh(rf, meshes);
            }

            this.world     = world;
            this.rootFrame = rootFrame;
            this.device    = device;

            if (meshes.Count > 0)
            {
                animation = meshes[0];
            }

            this.pMesh = pMesh;
            //pMesh.NumberFaces = pMesh.MaxFaces;
        }
예제 #7
0
        public Player(ProgressiveMesh pMesh, Matrix world, Texture[] textures, Matrix handWorld, AnimationRootFrame rootFrame)
            : base(pMesh.Device, world, rootFrame, textures, pMesh)
        {
            try
            {
                this.handPosition = new Vector3(handWorld.M41, handWorld.M42, handWorld.M43);
                this.handScale    = new Vector3(handWorld.M11, handWorld.M22, handWorld.M33);

                haveHand = !(handWorld.M44 == 0);

                Init(pMesh);

                EnableAnimation(false);
            }
            catch (Exception ex)
            {
                Logging.Logger.AddError(ex.Message);
            }
        }
예제 #8
0
        /// <summary>Create the mesh data</summary>
        public void Create(Device device, string name)
        {
            defaultMaterial.Diffuse = System.Drawing.Color.White;
            defaultMaterial.Ambient = System.Drawing.Color.White;

            shadowMaterial.Diffuse = System.Drawing.Color.Black;
            shadowMaterial.Ambient = System.Drawing.Color.Black;

            // Hook the device events
            System.Diagnostics.Debug.Assert(device != null, "Device should not be null.");
            this.device         = device;
            device.DeviceLost  += new EventHandler(OnLostDevice);
            device.DeviceReset += new EventHandler(OnResetDevice);
            device.Disposing   += new EventHandler(OnDeviceDisposing);

            GraphicsStream adjacency;     // Adjacency information

            ExtendedMaterial[] materials; // Mesh material information

            // First try to find the filename
            string path = string.Empty;

            try
            {
                path = Utility.FindMediaFile(name);
            }
            catch (MediaNotFoundException)
            {
                // The media was not found, maybe a full path was passed in?
                if (System.IO.File.Exists(name))
                {
                    path = name;
                }
                else
                {
                    // No idea what this is trying to find
                    throw new MediaNotFoundException(name);
                }
            }

            // Now load the mesh
            systemMemoryMesh = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out adjacency,
                                             out materials);

            using (adjacency)
            {
                // Optimize the mesh for performance
                systemMemoryMesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact |
                                                 MeshFlags.OptimizeAttributeSort, adjacency);

                // Find the folder of where the mesh file is located
                string folder = Utility.AppendDirectorySeparator(new System.IO.FileInfo(path).DirectoryName);

                // Create the materials
                CreateMaterials(folder, device, adjacency, materials);
            }

            // Finally call reset
            OnResetDevice(device, EventArgs.Empty);
            BonsaiAllocateHierarchy allocH = new BonsaiAllocateHierarchy(path);

            animationRoot       = Mesh.LoadHierarchyFromFile(path, MeshFlags.Managed, device, allocH, null);
            animationController = animationRoot.AnimationController;
            AnimationSet set = animationController.GetAnimationSet(0);

            animationController.SetTrackAnimationSet(0, set);

            animationController.SetTrackEnable(0, true);
            animationController.SetTrackPosition(0, 0.0);
            animationController.SetTrackPriority(0, PriorityType.Low);
            animationController.SetTrackSpeed(0, 1.0f);
            animationController.SetTrackPriority(0, PriorityType.Low);
            animationController.PriorityBlend = 1.0f;
            set.Dispose(); // will this fix the very sporadic crashes?
        }