Пример #1
0
 private void Init(ProgressiveMesh mesh)
 {
     if (mesh != null && mesh is ProgressiveMesh)
     {
         mesh.NumberFaces = (int)(mesh.MaxFaces * base.GetObjectQuality());
     }
 }
Пример #2
0
        public override void ApplyLOD()
        {
            BaseMesh bmesh = base.GetModel();

            if (bmesh is ProgressiveMesh)
            {
                return;
            }

            if (bmesh != null && !bmesh.Disposed)
            {
                float LODquality = 1f;

                bool enableLOD = base.isEnableLOD();

                if (enableLOD)
                {
                    LODquality = 1f / (1f + 0.003f * base.GetDistanceFromCamera());
                }

                ProgressiveMesh mesh = bmesh as ProgressiveMesh;
                int             LOD  = (int)(mesh.MaxFaces * LODquality * base.GetObjectQuality());

                if (lastLOD != LOD && enableLOD)
                {
                    mesh.NumberFaces = LOD;
                    lastLOD          = LOD;
                }
            }

            base.ApplyLOD();
        }
Пример #3
0
 public MeshInformation(ProgressiveMesh mesh, String path, Texture[] textures, String[] textUrl)
 {
     pMesh         = mesh;
     this.path     = path;
     this.textures = textures;
     texturesUrl   = textUrl;
 }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// Metoda vygeneruje geometrii pro sprite
        /// </summary>
        /// <param name="device">Zarizeni, ktere ve kterem se bude geometrie zobrazovat</param>
        /// <returns>Vraci geometrii spritu</returns>
        public static ProgressiveMesh GenerateSpriteGeometry(Device device)
        {
            positionOnlyVertex[] rectangle = new positionOnlyVertex[4];

            rectangle[0] = new positionOnlyVertex(-1, 1, 0);
            rectangle[1] = new positionOnlyVertex(1, 1, 0);
            rectangle[2] = new positionOnlyVertex(-1, -1, 0);
            rectangle[3] = new positionOnlyVertex(1, -1, 0);

            int[] indexes = new int[6];
            indexes[0] = 0;
            indexes[1] = 1;
            indexes[2] = 2;
            indexes[3] = 2;
            indexes[4] = 1;
            indexes[5] = 3;

            using (Mesh sprite = new Mesh(2, 4, MeshFlags.Managed | MeshFlags.Use32Bit, positionOnlyVertex.Format, device))
            {
                sprite.SetVertexBufferData(rectangle, LockFlags.NoSystemLock);
                sprite.SetIndexBufferData(indexes, LockFlags.NoSystemLock);

                using (Mesh temp = sprite.Clone(MeshFlags.Managed | MeshFlags.Use32Bit, GeneralObject.GeneralVertex.vertexElements, device))
                {
                    int[] adjency = new int[3 * temp.NumberFaces];
                    temp.GenerateAdjacency(0.0f, adjency);

                    ProgressiveMesh progressiveSpriteMesh = new ProgressiveMesh(temp, adjency, 2, MeshFlags.SimplifyFace);
                    progressiveSpriteMesh.NumberFaces = progressiveSpriteMesh.MaxFaces;

                    return(progressiveSpriteMesh);
                }
            }
        }
Пример #6
0
        public void OnCreateDevice(object sender, EventArgs e)
        {
            ExtendedMaterial[] materials = null;
            //设定运行程序所在目录的上两级目录为当前默认目录
            Directory.SetCurrentDirectory(Application.StartupPath + @"\..\..\..\");
            //下句从tiger.x文件中读入3D图形(立体老虎)
            GraphicsStream adjacency;

            mesh = Mesh.FromFile("tiger.x", MeshFlags.Managed, device, out adjacency, out materials);
            if (meshTextures == null)                            //如果还未设置纹理,为3D图形增加纹理和材质
            {
                meshTextures   = new Texture[materials.Length];  //纹理数组
                meshMaterials1 = new Material[materials.Length]; //材质数组
                for (int i = 0; i < materials.Length; i++)       //读入纹理和材质
                {
                    meshMaterials1[i]         = materials[i].Material3D;
                    meshMaterials1[i].Ambient = meshMaterials1[i].Diffuse;
                    meshTextures[i]           = TextureLoader.FromFile(device,
                                                                       materials[i].TextureFilename);
                }
            }   //下边首先清理Mesh,然后简化Mesh

            mesh1 = Mesh.Clean(CleanType.Simplification, mesh, adjacency, adjacency);
            mesh2 = new ProgressiveMesh(mesh1, adjacency, null, 1, MeshFlags.SimplifyVertex);

            mesh2.NumberVertices = 1000;
            mesh2.NumberFaces    = 1000;
        }
Пример #7
0
        public override void ApplyLOD()
        {
            BaseMesh bmesh = base.GetModel();

            if (bmesh != null && !bmesh.Disposed)
            {
                float LODquality = 1f;

                if (base.isEnableLOD())
                {
                    LODquality = 1f / (1f + 0.008f * base.GetDistanceFromCamera());
                }

                ProgressiveMesh mesh = bmesh as ProgressiveMesh;
                int             LOD  = (int)(mesh.MaxFaces * LODquality * base.GetObjectQuality());

                if (lastLOD != LOD)
                {
                    try
                    {
                        mesh.NumberFaces = LOD;
                        lastLOD          = LOD;
                    }
                    catch (Exception ex)
                    {
                        Logging.Logger.AddError(ex.Message);
                    }
                }
            }

            base.ApplyLOD();
        }
Пример #8
0
        public Torch(Device device, ProgressiveMesh mesh, Matrix world, Texture[] texture)
            : base(mesh, world, texture[0])
        {
            base.SetType(WiccanRede.Graphics.Scene.LightType.Point);

            fireParticle = new FireParticleSystem(device, TextureLoader.FromFile(mesh.Device, @"Resources/Textures/Fire.dds"));
        }
Пример #9
0
        }             // CarregarModelo().fim

        // ---]
        // [---
        private void gerarModeloProgressivo()
        {
            // Limpeza do objeto 3d
            mesh_limpo = Mesh.Clean(objeto3D, adj, adj);

            // Geração do modelo 3d progressivo
            mesh_progressivo = new ProgressiveMesh(mesh_limpo, adj,
                                                   null, 1, MeshFlags.SimplifyVertex);

            // O mesh é reconfigurado para o máximo nível de detalhe
            mesh_progressivo.NumberFaces    = mesh_progressivo.MaxFaces;
            mesh_progressivo.NumberVertices = mesh_progressivo.MaxVertices;
        } // gerarModeloProgressivo().fim
Пример #10
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);
            }
        }
Пример #11
0
        private void CreateLod()
        {
            ProgressiveMesh pPMesh           = null;
            int             cVerticesMin     = 0;
            int             cVerticesMax     = 0;
            int             cVerticesPerMesh = 0;

            pPMesh = new ProgressiveMesh(m_mesh, m_adj, null, 1, MeshFlags.SimplifyVertex);

            cVerticesMin = pPMesh.MinVertices;
            cVerticesMax = pPMesh.MaxVertices;

            if (m_pMeshes != null)
            {
                for (int iPMesh = 0; iPMesh < m_pMeshes.Length; iPMesh++)
                {
                    m_pMeshes[iPMesh].Dispose();
                }
            }

            cVerticesPerMesh = (cVerticesMax - cVerticesMin) / m_nNumLOD;
            m_pMeshes        = new ProgressiveMesh[m_nNumLOD];

            // clone all the separate m_pMeshes
            for (int iPMesh = 0; iPMesh < m_pMeshes.Length; iPMesh++)
            {
                m_pMeshes[m_pMeshes.Length - 1 - iPMesh] = pPMesh.Clone(MeshFlags.Managed | MeshFlags.VbShare, pPMesh.VertexFormat, CGameEngine.Device3D);
                // trim to appropriate space
                if (m_nNumLOD > 1)
                {
                    m_pMeshes[m_pMeshes.Length - 1 - iPMesh].TrimByVertices(cVerticesMin + cVerticesPerMesh * iPMesh, cVerticesMin + cVerticesPerMesh * (iPMesh + 1));
                }

                m_pMeshes[m_pMeshes.Length - 1 - iPMesh].OptimizeBaseLevelOfDetail(MeshFlags.OptimizeVertexCache);
            }
            m_currentPmesh = 0;
            m_pMeshes[m_currentPmesh].NumberVertices = cVerticesMax;
            pPMesh.Dispose();
        }
Пример #12
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;
        }
Пример #13
0
 public Building(ProgressiveMesh mesh, Matrix world, Texture[] color_textures0, Texture[] normal_textures)
     : base(mesh, world, color_textures0, null, null, normal_textures)
 {
 }
Пример #14
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Initialize the stats font
            statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
                                                                     Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
                                                                     , "Arial");

            // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the
            // shader debugger. Debugging vertex shaders requires either REF or software vertex
            // processing, and debugging pixel shaders requires REF.  The
            // ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the
            // shader debugger.  It enables source level debugging, prevents instruction
            // reordering, prevents dead code elimination, and forces the compiler to compile
            // against the next higher available software target, which ensures that the
            // unoptimized shaders do not exceed the shader model limitations.  Setting these
            // flags will cause slower rendering since the shaders will be unoptimized and
            // forced into software.  See the DirectX documentation for more information about
            // using the shader debugger.
            ShaderFlags shaderFlags = ShaderFlags.None;

#if (DEBUG_VS)
            shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
#endif
#if (DEBUG_PS)
            shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
#endif
            // Read the D3DX effect file
            string path = Utility.FindMediaFile("ProgressiveMesh.fx");
            effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device,
                                                                            path, null, null, shaderFlags, null);

            // Set the technique now, it will never be updated
            effect.Technique = "RenderScene";

            // Load the mesh
            GraphicsStream     adjacencyBuffer = null;
            ExtendedMaterial[] materials       = null;

            // Find the mesh
            path = Utility.FindMediaFile("dwarf\\dwarf.x");

            // Change the current directory to the mesh's directory so we can
            // find the textures.
            string             currentFolder = System.IO.Directory.GetCurrentDirectory();
            System.IO.FileInfo info          = new System.IO.FileInfo(path);
            System.IO.Directory.SetCurrentDirectory(info.Directory.FullName);

            using (Mesh originalMesh = Mesh.FromFile(path, MeshFlags.Managed, e.Device,
                                                     out adjacencyBuffer, out materials))
            {
                int use32Bit = (int)(originalMesh.Options.Value & MeshFlags.Use32Bit);

                // Perform simple cleansing operations on mesh
                using (Mesh mesh = Mesh.Clean(CleanType.Simplification, originalMesh, adjacencyBuffer, adjacencyBuffer))
                {
                    // Perform a weld to try and remove excess vertices.
                    // Weld the mesh using all epsilons of 0.0f.  A small epsilon like 1e-6 works well too
                    WeldEpsilons epsilons = new WeldEpsilons();
                    mesh.WeldVertices(0, epsilons, adjacencyBuffer, adjacencyBuffer);

                    // Verify validity of mesh for simplification
                    mesh.Validate(adjacencyBuffer);

                    // Allocate a material/texture arrays
                    meshMaterials = new Material[materials.Length];
                    meshTextures  = new Texture[materials.Length];

                    // Copy the materials and load the textures
                    for (int i = 0; i < meshMaterials.Length; i++)
                    {
                        meshMaterials[i] = materials[i].Material3D;
                        meshMaterials[i].AmbientColor = meshMaterials[i].DiffuseColor;

                        if ((materials[i].TextureFilename != null) && (materials[i].TextureFilename.Length > 0))
                        {
                            // Create the texture
                            meshTextures[i] = ResourceCache.GetGlobalInstance().CreateTextureFromFile(e.Device, materials[i].TextureFilename);
                        }
                    }

                    // Find the mesh's center, then generate a centering matrix
                    using (VertexBuffer vb = mesh.VertexBuffer)
                    {
                        using (GraphicsStream stm = vb.Lock(0, 0, LockFlags.NoSystemLock))
                        {
                            try
                            {
                                objectRadius = Geometry.ComputeBoundingSphere(stm,
                                                                              mesh.NumberVertices, mesh.VertexFormat, out objectCenter);

                                worldCenter = Matrix.Translation(-objectCenter);
                                float scaleFactor = 2.0f / objectRadius;
                                worldCenter *= Matrix.Scaling(scaleFactor, scaleFactor, scaleFactor);
                            }
                            finally
                            {
                                vb.Unlock();
                            }
                        }
                    }

                    // If the mesh is missing normals, generate them.
                    Mesh currentMesh = mesh;
                    if ((mesh.VertexFormat & VertexFormats.Normal) == 0)
                    {
                        currentMesh = mesh.Clone(MeshFlags.Managed | (MeshFlags)use32Bit,
                                                 mesh.VertexFormat | VertexFormats.Normal, e.Device);

                        // Compute normals now
                        currentMesh.ComputeNormals();
                    }

                    using (currentMesh)
                    {
                        // Generate progressive meshes
                        using (ProgressiveMesh pMesh = new ProgressiveMesh(currentMesh, adjacencyBuffer, null, 1, MeshFlags.SimplifyVertex))
                        {
                            int minVerts     = pMesh.MinVertices;
                            int maxVerts     = pMesh.MaxVertices;
                            int vertsPerMesh = (maxVerts - minVerts + 10) / 10;

                            // How many meshes should be in the array
                            int numMeshes = Math.Max(1, (int)Math.Ceiling((maxVerts - minVerts + 1) / (float)vertsPerMesh));
                            meshes = new ProgressiveMesh[numMeshes];

                            // Clone full sized pmesh
                            fullMesh = pMesh.Clone(MeshFlags.Managed | MeshFlags.VbShare, pMesh.VertexFormat, e.Device);

                            // Clone all the separate pmeshes
                            for (int iMesh = 0; iMesh < numMeshes; iMesh++)
                            {
                                meshes[iMesh] = pMesh.Clone(MeshFlags.Managed | MeshFlags.VbShare, pMesh.VertexFormat, e.Device);

                                // Trim to appropriate space
                                meshes[iMesh].TrimByVertices(minVerts + vertsPerMesh * iMesh, minVerts + vertsPerMesh * (iMesh + 1));
                                meshes[iMesh].OptimizeBaseLevelOfDetail(MeshFlags.OptimizeVertexCache);
                            }

                            // Set the current to be max vertices
                            currentMeshIndex = numMeshes - 1;
                            meshes[currentMeshIndex].NumberVertices = maxVerts;
                            fullMesh.NumberVertices = maxVerts;

                            // Set up the slider to reflect the vertices range the mesh has
                            sampleUi.GetSlider(Detail).SetRange(meshes[0].MinVertices,
                                                                meshes[meshes.Length - 1].MaxVertices);
                            sampleUi.GetSlider(Detail).Value = (meshes[currentMeshIndex] as BaseMesh).NumberVertices;
                        }
                    }
                }
            }

            // Restore the original folder
            System.IO.Directory.SetCurrentDirectory(currentFolder);
            // Setup the camera's view parameters
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, -5.0f), Vector3.Empty);
        }
Пример #15
0
        /// <summary>
        /// The device has been created.  Resources that are not lost on
        /// Reset() can be created here -- resources in Pool.Managed,
        /// Pool.Scratch, or Pool.SystemMemory.  Image surfaces created via
        /// CreateImageSurface are never lost and can be created here.  Vertex
        /// shaders and pixel shaders can also be created here as they are not
        /// lost on Reset().
        /// </summary>
        protected override void InitializeDeviceObjects()
        {
            // Initialize the font's internal textures
            font.InitializeDeviceObjects(device);

            string         path      = DXUtil.FindMediaFile(initialDirectory, meshFilename);
            Mesh           pMesh     = null;
            Mesh           pTempMesh = null;
            GraphicsStream adj       = null;

            ExtendedMaterial[] mtrl = null;
            MeshFlags          i32BitFlag;
            WeldEpsilons       Epsilons = new WeldEpsilons();
            ProgressiveMesh    pPMesh   = null;
            int cVerticesMin            = 0;
            int cVerticesMax            = 0;
            int cVerticesPerMesh        = 0;

            try
            {
                // Load the mesh from the specified file
                pMesh      = Mesh.FromFile(path, MeshFlags.Managed, device, out adj, out mtrl);
                i32BitFlag = pMesh.Options.Use32Bit ? MeshFlags.Use32Bit : 0;

                // perform simple cleansing operations on mesh
                pTempMesh = Mesh.Clean(pMesh, adj, adj);
                pMesh.Dispose();
                pMesh = pTempMesh;

                //  Perform a weld to try and remove excess vertices like the model bigship1.x in the DX9.0 SDK (current model is fixed)
                //    Weld the mesh using all epsilons of 0.0f.  A small epsilon like 1e-6 works well too
                pMesh.WeldVertices(0, Epsilons, adj, adj);
                // verify validity of mesh for simplification
                pMesh.Validate(adj);

                meshMaterials = new Direct3D.Material[mtrl.Length];
                meshTextures  = new Texture[mtrl.Length];
                for (int i = 0; i < mtrl.Length; i++)
                {
                    meshMaterials[i]         = mtrl[i].Material3D;
                    meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
                    if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != ""))
                    {
                        path = DXUtil.FindMediaFile(initialDirectory, mtrl[i].TextureFilename);
                        // Find the path to the texture and create that texture
                        try
                        {
                            meshTextures[i] = TextureLoader.FromFile(device, path);
                        }
                        catch
                        {
                            meshTextures[i] = null;
                        }
                    }
                }

                // Lock the vertex buffer to generate a simple bounding sphere
                VertexBuffer   vb         = pMesh.VertexBuffer;
                GraphicsStream vertexData = vb.Lock(0, 0, LockFlags.NoSystemLock);
                objectRadius = Geometry.ComputeBoundingSphere(vertexData, pMesh.NumberVertices, pMesh.VertexFormat, out objectCenter);
                vb.Unlock();
                vb.Dispose();
                if (meshMaterials.Length == 0)
                {
                    throw new Exception();
                }

                if ((pMesh.VertexFormat & VertexFormats.Normal) == 0)
                {
                    pTempMesh = pMesh.Clone(i32BitFlag | MeshFlags.Managed, pMesh.VertexFormat | VertexFormats.Normal, device);
                    pTempMesh.ComputeNormals();
                    pMesh.Dispose();
                    pMesh = pTempMesh;
                }
                pPMesh = new ProgressiveMesh(pMesh, adj, null, 1, MeshFlags.SimplifyVertex);

                cVerticesMin = pPMesh.MinVertices;
                cVerticesMax = pPMesh.MaxVertices;

                cVerticesPerMesh = (cVerticesMax - cVerticesMin) / 10;
                pmeshes          = new ProgressiveMesh[(int)Math.Max(1, Math.Ceiling((cVerticesMax - cVerticesMin) / (float)cVerticesPerMesh))];

                // clone full size pmesh
                fullPmesh = pPMesh.Clone(MeshFlags.Managed | MeshFlags.VbShare, pPMesh.VertexFormat, device);

                // clone all the separate pmeshes
                for (int iPMesh = 0; iPMesh < pmeshes.Length; iPMesh++)
                {
                    pmeshes[iPMesh] = pPMesh.Clone(MeshFlags.Managed | MeshFlags.VbShare, pPMesh.VertexFormat, device);
                    // trim to appropriate space
                    pmeshes[iPMesh].TrimByVertices(cVerticesMin + cVerticesPerMesh * iPMesh, cVerticesMin + cVerticesPerMesh * (iPMesh + 1));

                    pmeshes[iPMesh].OptimizeBaseLevelOfDetail(MeshFlags.OptimizeVertexCache);
                }
                currentPmesh = pmeshes.Length - 1;
                pmeshes[currentPmesh].NumberVertices = cVerticesMax;
                fullPmesh.NumberVertices             = cVerticesMax;
                pPMesh.Dispose();
            }
            catch
            {
                // hide error so that device changes will not cause exit, shows blank screen instead
                return;
            }
        }
Пример #16
0
 public Lights(ProgressiveMesh mesh, Matrix world, Texture texture)
     : base(mesh, world, new Texture[] { texture }, null, null, null)
 {
     lightPosition = new Vector3(world.M41, world.M42, world.M43) * (1f / world.M44);
 }
Пример #17
0
 public PickupObject(ProgressiveMesh mesh, Matrix world, Texture[] color_textures0, Texture[] normal_textures)
     : base(mesh, world, color_textures0, null, null, normal_textures)
 {
 }
Пример #18
0
        /// <summary>
        /// Nacteni meshe a textur a vytvoreni progressive meshe
        /// </summary>
        /// <param name="loaded">Entita do ktere chceme pridat mesh a texturz</param>
        /// <param name="data">pole obsahujuci nazev meshe a textur</param>
        /// <param name="name">nazev objektu</param>
        /// <returns>Entita s meshem a texturami</returns>
        private Entity LoadMeshFromFile(Entity loaded, string[] data, string name)
        {
            string[] textureUrl;

            string objectUrl = data[0];
            int    p         = FindMesh(objectUrl);

            if (p != -1)
            {
                loaded.AddParametr(new Parametr("Objekt[]", data[1], meshInf[p].textures));
                loaded.AddParametr(new Parametr("Microsoft.DirectX.Direct3D.ProgressiveMesh", name, meshInf[p].pMesh));
                loaded.AddParametr(new Parametr("Objekt[]", "SpecialTextureUrl", meshInf[p].texturesUrl));
                return(loaded);
            }
            if (data.Length < 2)
            {
                throw new Exception("Chyba pri nacitani nespravny pocet parametru");
            }

            Texture[]       textures;
            ProgressiveMesh currentLoadedMesh;

            Matrix localTransformation = Matrix.Identity;

            GraphicsStream adjency = null;

            ExtendedMaterial[] mat = null;

            using (Mesh mesh = Mesh.FromFile(objectUrl, MeshFlags.Managed, dev, out adjency, out mat))
            {
                #region Texture Loading

                textures   = new Texture[mat.Length];
                textureUrl = new string[mat.Length];

                string pathname = Path.GetDirectoryName(objectUrl) + @"\";

                for (int i = 0; i < mat.Length; i++)
                {
                    if (mat[i].TextureFilename == null)
                    {
                        continue;
                    }



                    string abspath = (pathname + mat[i].TextureFilename);
                    textureUrl[i] = abspath;
                    string path = mat[i].TextureFilename;

                    bool createtexture = true;
                    for (int t = 0; t < i; t++)
                    {
                        if (mat[t].TextureFilename == mat[i].TextureFilename)
                        {
                            textures[i]   = textures[t];
                            createtexture = false;
                            break;
                        }
                    }

                    if (createtexture)
                    {
                        if (File.Exists(path))
                        {
                            textures[i] = TextureLoader.FromFile(dev, path, 0, 0, 0, Usage.None, Format.R8G8B8, Pool.Managed, Filter.Linear, Filter.Linear, 0);
                        }
                        else if (File.Exists(abspath))
                        {
                            textures[i] = TextureLoader.FromFile(dev, abspath, 0, 0, 0, Usage.None, Format.R8G8B8, Pool.Managed, Filter.Linear, Filter.Linear, 0);
                        }
                    }
                }

                loaded.AddParametr(new Parametr("Objekt[]", "SpecialTextureUrl", textureUrl));
                #endregion


                #region Mesh clean, optimize and compute normals/tangents

                int use32Bit = (int)(mesh.Options.Value & MeshFlags.Use32Bit);

                using (Mesh currentmesh = Mesh.Clean(CleanType.Simplification, mesh, adjency, adjency))
                {
                    WeldEpsilons epsilons = new WeldEpsilons();
                    currentmesh.WeldVertices(0, epsilons, adjency, adjency);
                    currentmesh.Validate(adjency);

                    Mesh newmesh = currentmesh.Optimize(MeshFlags.OptimizeStripeReorder | MeshFlags.OptimizeAttributeSort, adjency);
                    using (newmesh = currentmesh.Clone(MeshFlags.Managed | (MeshFlags)use32Bit, GeneralObject.GeneralVertex.vertexElements, dev))
                    {
                        newmesh.ComputeNormals();

                        ProgressiveMesh pm = new ProgressiveMesh(newmesh, adjency, null, 1, MeshFlags.SimplifyFace);

                        currentLoadedMesh             = pm;
                        currentLoadedMesh.NumberFaces = currentLoadedMesh.MaxFaces;
                    }
                }
                #endregion
            }
            meshInf.Add(new MeshInformation(currentLoadedMesh, objectUrl, textures, textureUrl));

            loaded.AddParametr(new Parametr("Objekt[]", data[1], textures));
            loaded.AddParametr(new Parametr("Microsoft.DirectX.Direct3D.ProgressiveMesh", name, currentLoadedMesh));



            return(loaded);
        }