protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Site != null && Site.DesignMode) { return; } if (WorldFrame.Instance == null || WorldFrame.Instance.GraphicsContext == null) { return; } mTarget = new RenderTarget(WorldFrame.Instance.GraphicsContext); mMatrixBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext); mCamera = new PerspectiveCamera(); mCamera.ViewChanged += ViewChanged; mCamera.ProjectionChanged += ProjChanged; mCamera.SetClip(0.2f, 1000.0f); mCamera.SetParameters(Vector3.Zero, Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); mCamControl = new CameraControl(this) { TurnFactor = 0.1f, SpeedFactor = 20.0f }; MouseDown += OnClick; Resize += OnResize; renderTimer.Tick += OnRenderTimerTick; OnResize(this, null); renderTimer.Start(); }
void LoadModel() { string model; mModels.TryDequeue(out model); var file = ModelFactory.Instance.CreateM2(model); if (file.Load() == false) { if (mModels.Count > 0) { LoadModel(); } else { return; } } mRenderer = new M2Renderer(file); var bboxMin = file.BoundingBox.Minimum.Z; var bboxMax = file.BoundingBox.Maximum.Z; WorldFrame.Instance.Dispatcher.BeginInvoke(() => { mCamera.SetParameters(new Vector3(file.BoundingRadius * 1.5f, 0, bboxMin + (bboxMax - bboxMin) / 2), new Vector3(0, 0, bboxMin + (bboxMax - bboxMin) / 2), Vector3.UnitZ, Vector3.UnitY); }); mThumbnailCaptureFrame = CAPTURE_FRAME; renderTimer.Start(); }
public ThumbnailCapture(int Width, int Height) { ImgWidth = Width; ImgHeight = Height; if (WorldFrame.Instance == null || WorldFrame.Instance.GraphicsContext == null) { return; } mTarget = new RenderTarget(WorldFrame.Instance.GraphicsContext); mMatrixBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext); mCamera = new PerspectiveCamera(); mCamera.ViewChanged += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); }; mCamera.ProjectionChanged += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); }; mCamera.SetClip(0.2f, 1000.0f); mCamera.SetParameters(new Vector3(10, 0, 0), Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); renderTimer = new Timer(); renderTimer.Interval = 10; renderTimer.Tick += OnRenderTimerTick; var texDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.None, Format = Format.B8G8R8A8_UNorm, Height = ImgWidth, Width = ImgWidth, Usage = ResourceUsage.Default, SampleDescription = new SampleDescription(1, 0), OptionFlags = ResourceOptionFlags.None, MipLevels = 1 }; if (mResolveTexture != null) { mResolveTexture.Dispose(); } mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc); if (mMapTexture != null) { mMapTexture.Dispose(); } texDesc.CpuAccessFlags = CpuAccessFlags.Read; texDesc.Usage = ResourceUsage.Staging; mMapTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc); mTarget.Resize(ImgWidth, ImgHeight, true); mCamera.SetAspect((float)ImgWidth / ImgHeight); }
public void SetModel(string model, int variation = 0) { var root = ModelFactory.Instance.CreateWmo(); if (root.Load(model) == false) { return; } var file = new WmoRootRender(); file.OnAsyncLoad(root); mRender = new WmoBatchRender(file); mRender.AddInstance(1, Vector3.Zero, Vector3.Zero); mCamera.SetParameters(file.BoundingBox.Maximum, Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); }
public ModelRenderControl() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque | ControlStyles.UserPaint, true); mTarget = new RenderTarget(WorldFrame.Instance.GraphicsContext); mMatrixBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext); mCamera = new PerspectiveCamera(); mCamera.ViewChanged += ViewChanged; mCamera.ProjectionChanged += ProjChanged; mCamera.SetClip(0.2f, 1000.0f); mCamera.SetParameters(new Vector3(10, 0, 0), Vector3.Zero, Vector3.UnitZ, -Vector3.UnitY); mCamControl = new CameraControl(this); InitializeComponent(); MouseClick += OnClick; Resize += OnResize; renderTimer.Tick += OnRenderTimerTick; OnResize(this, null); renderTimer.Start(); }
private void SetModelCameraParameters(M2File file) { var bboxMin = file.BoundingBox.Minimum.Z; var bboxMax = file.BoundingBox.Maximum.Z; WorldFrame.Instance.Dispatcher.BeginInvoke(() => { mCamera.SetParameters(new Vector3(file.BoundingRadius * 1.5f, 0, bboxMin + (bboxMax - bboxMin) / 2), new Vector3(0, 0, bboxMin + (bboxMax - bboxMin) / 2), Vector3.UnitZ, Vector3.UnitY); comboBox1.Items.Clear(); var values = Enum.GetValues(typeof(AnimationType)); if (file.AnimationLookup.Length > 0) //Animation Lookup { foreach (int anim in values) { if (anim >= file.AnimationLookup.Length) { continue; } if (file.AnimationLookup[anim] < 0) { continue; } comboBox1.Items.Add(new AnimationIndexEntry { AnimationIndex = anim, Name = Enum.GetName(typeof(AnimationType), anim) }); } } else if (file.AnimationIds.Length > 0) //Raw Animation Check { foreach (int anim in values) { if (Array.IndexOf(file.AnimationIds, (ushort)anim) == -1) { continue; } comboBox1.Items.Add(new AnimationIndexEntry { AnimationIndex = anim, Name = Enum.GetName(typeof(AnimationType), anim) }); } } if (comboBox1.Items.Count > 0) //Preset combobox and animator state { comboBox1.SelectedIndex = 0; mRenderer.PortraitRenderer.Animator.SetAnimation((AnimationType)((AnimationIndexEntry)comboBox1.Items[0]).AnimationIndex); } }); if (file.DisplayOptions.TextureVariationFiles.Count > 1) { nudVariation.ReadOnly = false; nudVariation.Maximum = file.DisplayOptions.TextureVariationFiles.Count; nudVariation.Value = file.DisplayOptions.TextureVariation + 1; nudVariation.Increment = 1; } else { nudVariation.Increment = 0; nudVariation.ReadOnly = true; } }