This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

[Frubar Paste] Hosted by ReCo-Systems - Chat with us at XChannel IRC

Posted by Thulsadum Thu 22nd May 22:12 (plain text)

  1.     public class CustomFrame : Frame
  2.     {
  3.  
  4.         public Matrix CustomTransform=Matrix.Identity;
  5.  
  6.         public CustomFrame() : base() { }
  7.         public CustomFrame(string name)
  8.             : this()
  9.         {
  10.             this.Name = name;
  11.         }
  12.     }
  13.  
  14.     public class CustomMeshContainer : MeshContainer
  15.     {
  16.         protected string xFile;
  17.         protected Texture[] textures;
  18.         public Texture[] Textures
  19.         {
  20.             get
  21.             {
  22.                 return this.textures;
  23.             }
  24.         }
  25.         public CustomMeshContainer(string xFile,string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
  26.             : base()
  27.         {
  28.             this.Name = name;
  29.             this.MeshData = meshData;
  30.             this.SetMaterials(materials);
  31.             this.SetEffectInstances(effectInstances);
  32.             this.SetAdjacency(adjacency);
  33.             if (skinInfo != null) this.SkinInformation = skinInfo;
  34.             this.xFile = xFile;
  35.  
  36.             this.textures = new Texture[materials.Length];
  37.             for (int i = 0; i < textures.Length; i++)
  38.                 if (materials[i].TextureFilename != null)
  39.                     this.textures[i] = TextureLoader.FromFile(this.MeshData.Mesh.Device, Path.Combine(Path.GetDirectoryName(this.xFile), materials[i].TextureFilename));
  40.         }
  41.     }
  42.  
  43.     public class CustomAllocateHierachy : AllocateHierarchy
  44.     {
  45.         protected string xFile;
  46.  
  47.         public CustomAllocateHierachy(string xFile)
  48.             :base()
  49.         {
  50.             this.xFile = xFile;
  51.         }
  52.  
  53.         public override Frame CreateFrame(string name)
  54.         {
  55.             return new CustomFrame(name);
  56.         }
  57.         public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
  58.         {
  59.             return new CustomMeshContainer(this.xFile,name,meshData,materials,effectInstances,adjacency,skinInfo);
  60.         }
  61.  
  62.     }
  63.  
  64.  
  65.     public class GraphicObject
  66.     {
  67.         protected Device device;
  68.         public bool Ani = false;
  69.         public Device Device
  70.         {
  71.             get
  72.             {
  73.                 return this.device;
  74.             }
  75.             protected set
  76.             {
  77.                 this.device = value;
  78.             }
  79.         }
  80.         protected string xFile;
  81.         public string Xfile
  82.         {
  83.             get
  84.             {
  85.                 return this.xFile;
  86.             }
  87.             protected set
  88.             {
  89.                 this.xFile = value;
  90.             }
  91.         }
  92.         protected AnimationRootFrame rootFrame;
  93.         public AnimationRootFrame RootFrame
  94.         {
  95.             get
  96.             {
  97.                 return this.rootFrame;
  98.             }
  99.             protected set
  100.             {
  101.                 this.rootFrame = value;
  102.             }
  103.         }
  104.  
  105.         public void Render(double timeelapsed)
  106.         {
  107.             //this.rootFrame.AnimationController.SetTrackEnable(0, this.Ani);
  108.             this.rootFrame.AnimationController.AdvanceTime(timeelapsed);
  109.             this.RenderFrame(this.rootFrame.FrameHierarchy, Matrix.Identity);
  110.         }
  111.         public void Render()
  112.         {
  113.             this.Render(0);
  114.         }
  115.  
  116.         protected void RenderFrame(Frame f, Matrix parentTransform)
  117.         {
  118.             if(f.FrameSibling!=null)
  119.                 this.RenderFrame(f.FrameSibling,parentTransform);
  120.  
  121.             Matrix transform = f.TransformationMatrix * parentTransform*((CustomFrame)f).CustomTransform;
  122.  
  123.             if (f.FrameFirstChild != null)
  124.                 this.RenderFrame(f.FrameFirstChild, transform);
  125.  
  126.             if (f.MeshContainer != null)
  127.                 this.DoRender(f, transform);           
  128.         }
  129.  
  130.         protected void DoRender(Frame f, Matrix transform)
  131.         {
  132.             this.Device.Transform.World = transform;
  133.  
  134.             ExtendedMaterial[] em = f.MeshContainer.GetMaterials();
  135.             Texture[] t = ((CustomMeshContainer)f.MeshContainer).Textures;
  136.             for (int i = 0; i < em.Length; i++)
  137.             {
  138.                 this.Device.Material = em[i].Material3D;
  139.                 if (t[i] != null)
  140.                     this.Device.SetTexture(0, t[i]);
  141.                 f.MeshContainer.MeshData.Mesh.DrawSubset(i);
  142.             }
  143.         }
  144.  
  145.  
  146.  
  147.         public GraphicObject(string xFile, Device device)
  148.         {
  149.             this.Xfile = xFile;
  150.             this.Device = device;
  151.             this.RootFrame = Mesh.LoadHierarchyFromFile(xFile, MeshFlags.Managed, device, new CustomAllocateHierachy(this.Xfile), null);
  152.  
  153.             AnimationController aniCtrl = this.rootFrame.AnimationController;
  154.             for (int i = 0; i < this.rootFrame.AnimationController.NumberAnimationSets; i++)
  155.             {
  156.                 System.Diagnostics.Debug.WriteLine(aniCtrl.GetAnimationSet(i).Name);
  157.                 aniCtrl.SetTrackEnable(i, true);
  158.                 aniCtrl.SetTrackPosition(i, 0.0);
  159.                 aniCtrl.SetTrackPriority(i, PriorityType.Low);
  160.                 aniCtrl.SetTrackSpeed(i, 1f);
  161.                 AnimationSet aniset = this.rootFrame.AnimationController.GetAnimationSet(i);
  162.                 System.Diagnostics.Debug.WriteLine(aniset.NumberAnimations);
  163.                 aniCtrl.SetTrackAnimationSet(i, aniset);
  164.                 aniCtrl.SetTrackWeight(i, 1f);               
  165.             }
  166.  
  167.         }
  168.  
  169.     }


Submit a correction or amendment below. (click here to make a fresh posting)
Name

Remember my name in a cookie

Language


Code: To ensure legibility, keep your code lines under 80 characters long.
Include comments to indicate what you need feedback on.
Impressum