/// <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); }
public override void SetUserDataInMeshContainer(MeshContainer meshcontainer) { G3DMesh g3dmesh = new G3DMesh(); ExtendedMaterial[] materials = meshcontainer.GetMaterials(); if (materials != null) { g3dmesh.Materials = new Material[materials.Length]; g3dmesh.Textures = new Texture[materials.Length]; for (int i = 0; i < materials.Length; i++) { // Load texture from file or resource if (materials[i].TextureFilename != null) { Texture texture; try { texture = TextureLoader.FromFile(meshcontainer.MeshData.Mesh.Device, materials[i].TextureFilename); } catch { try { texture = TextureLoader.FromStream(meshcontainer.MeshData.Mesh.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(materials[i].TextureFilename)); } catch { texture = null; } } g3dmesh.Textures[i] = texture; } // Load material g3dmesh.Materials[i] = materials[i].Material3D; g3dmesh.Materials[i].Ambient = g3dmesh.Materials[i].Diffuse; } } g3dmesh.Mesh = meshcontainer.MeshData.Mesh; meshcontainer.UserData = g3dmesh; }