/// <summary> /// Draws animated model to the screen. /// </summary> /// <param name="worldTransform">Transformation of model in to place in world space.</param> protected override void Draw(Matrix worldTransform, Color overlayColor, float overlayColorWeight, bool tryCull) { AnimateModelRenderer.AnimateModelParameters parameters = new AnimateModelRenderer.AnimateModelParameters(); parameters.BoundingBox = BoundingBox; parameters.Spaghettify = mSpaghettify; parameters.MaxWormholeDistance = mMaxWormholeDistance; parameters.Name = Name; parameters.OverlayColor = overlayColor; parameters.OverlayWeight = overlayColorWeight; parameters.SkinTransforms = AnimationPlayer.GetSkinTransforms(); ; parameters.TryCull = tryCull; parameters.World = worldTransform; parameters.WormholePosition = mWormholePosition; GraphicsManager.EnqueueRenderable(parameters, RendererType); }
/// <summary> /// Renders to texture a centered image of a given renderer. /// </summary> public static Texture2D RenderPreviewImage(ModelRenderer renderer) { RenderTarget2D previewTexture = new RenderTarget2D(mDevice, 256, 256, false, SurfaceFormat.Color, DepthFormat.Depth24); mDevice.SetRenderTarget(previewTexture); mDevice.Clear(Color.DimGray); mDevice.SamplerStates[0] = SamplerState.PointClamp; mDevice.SamplerStates[1] = SamplerState.PointClamp; RasterizerState cull = new RasterizerState(); cull.CullMode = CullMode.None; mDevice.RasterizerState = cull; mDevice.BlendState = BlendState.AlphaBlend; mDevice.DepthStencilState = DepthStencilState.Default; AnimateModelRenderer.AnimateModelParameters parameters = new AnimateModelRenderer.AnimateModelParameters(); parameters.SkinTransforms = new Matrix[] { Matrix.Identity }; parameters.World = Matrix.Identity; Vector3 cameraOffset = new Vector3(1.7f * renderer.BoundingSphere.Radius, 1.0f * renderer.BoundingSphere.Radius, 1.7f * renderer.BoundingSphere.Radius); Vector3 cameraPosition = renderer.BoundingSphere.Center + cameraOffset; float offsetLength = cameraOffset.Length(); float nearDistance = offsetLength - renderer.BoundingSphere.Radius; float farDistance = offsetLength + renderer.BoundingSphere.Radius; renderer.ClearAllInstances(); renderer.AddInstance(parameters); if (mCamera != null) { renderer.RenderAllInstancesWithoutShadows( Matrix.CreateLookAt(cameraPosition, renderer.BoundingSphere.Center, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(mCamera.FieldOfView, 1.0f, nearDistance, farDistance), new Light(Vector3.Up, -Vector3.Up, Color.White.ToVector3(), Color.White.ToVector3(), Color.White.ToVector3())); } mDevice.SetRenderTarget(null); return previewTexture; }