Posted by Thulsadum on Thu 22nd May 22:12
download
- public class CustomFrame : Frame
- {
- public Matrix CustomTransform=Matrix.Identity;
- public CustomFrame() : base() { }
- public CustomFrame(string name)
- : this()
- {
- this.Name = name;
- }
- }
- public class CustomMeshContainer : MeshContainer
- {
- protected string xFile;
- protected Texture[] textures;
- public Texture[] Textures
- {
- get
- {
- return this.textures;
- }
- }
- public CustomMeshContainer(string xFile,string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
- : base()
- {
- this.Name = name;
- this.MeshData = meshData;
- this.SetMaterials(materials);
- this.SetEffectInstances(effectInstances);
- this.SetAdjacency(adjacency);
- if (skinInfo != null) this.SkinInformation = skinInfo;
- this.xFile = xFile;
- for (int i = 0; i < textures.Length; i++)
- if (materials[i].TextureFilename != null)
- this.textures[i] = TextureLoader.FromFile(this.MeshData.Mesh.Device, Path.Combine(Path.GetDirectoryName(this.xFile), materials[i].TextureFilename));
- }
- }
- public class CustomAllocateHierachy : AllocateHierarchy
- {
- protected string xFile;
- public CustomAllocateHierachy(string xFile)
- :base()
- {
- this.xFile = xFile;
- }
- public override Frame CreateFrame(string name)
- {
- }
- public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
- {
- return new CustomMeshContainer(this.xFile,name,meshData,materials,effectInstances,adjacency,skinInfo);
- }
- }
- public class GraphicObject
- {
- protected Device device;
- public bool Ani = false;
- public Device Device
- {
- get
- {
- return this.device;
- }
- protected set
- {
- this.device = value;
- }
- }
- protected string xFile;
- public string Xfile
- {
- get
- {
- return this.xFile;
- }
- protected set
- {
- this.xFile = value;
- }
- }
- protected AnimationRootFrame rootFrame;
- public AnimationRootFrame RootFrame
- {
- get
- {
- return this.rootFrame;
- }
- protected set
- {
- this.rootFrame = value;
- }
- }
- public void Render(double timeelapsed)
- {
- //this.rootFrame.AnimationController.SetTrackEnable(0, this.Ani);
- this.rootFrame.AnimationController.AdvanceTime(timeelapsed);
- this.RenderFrame(this.rootFrame.FrameHierarchy, Matrix.Identity);
- }
- public void Render()
- {
- this.Render(0);
- }
- protected void RenderFrame(Frame f, Matrix parentTransform)
- {
- if(f.FrameSibling!=null)
- this.RenderFrame(f.FrameSibling,parentTransform);
- Matrix transform = f.TransformationMatrix * parentTransform*((CustomFrame)f).CustomTransform;
- if (f.FrameFirstChild != null)
- this.RenderFrame(f.FrameFirstChild, transform);
- if (f.MeshContainer != null)
- this.DoRender(f, transform);
- }
- protected void DoRender(Frame f, Matrix transform)
- {
- this.Device.Transform.World = transform;
- ExtendedMaterial[] em = f.MeshContainer.GetMaterials();
- Texture[] t = ((CustomMeshContainer)f.MeshContainer).Textures;
- for (int i = 0; i < em.Length; i++)
- {
- this.Device.Material = em[i].Material3D;
- if (t[i] != null)
- this.Device.SetTexture(0, t[i]);
- f.MeshContainer.MeshData.Mesh.DrawSubset(i);
- }
- }
- public GraphicObject(string xFile, Device device)
- {
- this.Xfile = xFile;
- this.Device = device;
- this.RootFrame = Mesh.LoadHierarchyFromFile(xFile, MeshFlags.Managed, device, new CustomAllocateHierachy(this.Xfile), null);
- AnimationController aniCtrl = this.rootFrame.AnimationController;
- for (int i = 0; i < this.rootFrame.AnimationController.NumberAnimationSets; i++)
- {
- System.Diagnostics.Debug.WriteLine(aniCtrl.GetAnimationSet(i).Name);
- aniCtrl.SetTrackEnable(i, true);
- aniCtrl.SetTrackPosition(i, 0.0);
- aniCtrl.SetTrackPriority(i, PriorityType.Low);
- aniCtrl.SetTrackSpeed(i, 1f);
- AnimationSet aniset = this.rootFrame.AnimationController.GetAnimationSet(i);
- System.Diagnostics.Debug.WriteLine(aniset.NumberAnimations);
- aniCtrl.SetTrackAnimationSet(i, aniset);
- aniCtrl.SetTrackWeight(i, 1f);
- }
- }
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.