public void Shot(string outputDirectory, [CanBeNull] IProgress <double> progress, CancellationToken cancellation) { if (!Initialized) { Initialize(); } using (var replacement = FileUtils.RecycleOriginal(Path.Combine(outputDirectory, "body_shadow.png"))) { // body shadow PrepareBuffers(BodySize + BodyPadding * 2, 1024); SetBodyShadowCamera(); Draw(BodyMultipler, BodySize, BodyPadding, Fade ? 0.5f : 0f, progress.Subrange(0.01, 0.59), cancellation); if (cancellation.IsCancellationRequested) { return; } SaveResultAs(replacement.Filename, BodySize, BodyPadding); } // wheels shadows PrepareBuffers(WheelSize + WheelPadding * 2, 128); SetWheelShadowCamera(); _wheelMode = true; var nodes = new[] { "WHEEL_LF", "WHEEL_RF", "WHEEL_LR", "WHEEL_RR" }; foreach (var entry in nodes.Select(x => CarNode.GetDummyByName(x)).NonNull().Select((x, i) => new { Node = x, Matrix = Matrix.Translation(-(CarData?.GetWheelGraphicOffset(x.Name) ?? Vector3.Zero) + new Vector3(0f, x.Matrix.GetTranslationVector().Y - (x.BoundingBox?.Minimum.Y ?? 0f), 0f)), FileName = $"tyre_{i}_shadow.png", Progress = progress.Subrange(0.6 + i * 0.1, 0.099) })) { using (var replacement = FileUtils.RecycleOriginal(Path.Combine(outputDirectory, entry.FileName))) { Scene.Clear(); _flattenNodes = null; Scene.Add(entry.Node); entry.Node.LocalMatrix = entry.Matrix; Scene.UpdateBoundingBox(); Draw(WheelMultipler, WheelSize, WheelPadding, 1f, entry.Progress, cancellation); if (cancellation.IsCancellationRequested) { return; } SaveResultAs(replacement.Filename, WheelSize, WheelPadding); } } }
public void Shot(string outputDirectory, [CanBeNull] IProgress <double> progress, CancellationToken cancellation) { if (!Initialized) { Initialize(); } using (var replacement = FileUtils.RecycleOriginal(Path.Combine(outputDirectory, "body_shadow.png"))) { // body shadow PrepareBuffers(BodySize + BodyPadding * 2, 1024); SetBodyShadowCamera(); Draw(BodyMultiplier, BodySize, BodyPadding, Fade ? 0.5f : 0f, progress.SubrangeDouble(0.01, 0.59), cancellation); if (cancellation.IsCancellationRequested) { return; } SaveResultAs(replacement.Filename, BodySize, BodyPadding); } // wheels shadows if (_flattenNodesFix != null) { foreach (var tuple in _flattenNodesFix) { tuple.Item1.ParentMatrix = tuple.Item2; } } PrepareBuffers(WheelSize + WheelPadding * 2, 128); SetWheelShadowCamera(); _wheelMode = true; var nodes = new[] { "WHEEL_LF", "WHEEL_RF", "WHEEL_LR", "WHEEL_RR" }; var list = nodes.Select(x => CarNode.GetDummyByName(x)).NonNull().Select((x, i) => new { Node = x, GlobalMatrix = x.Matrix, Matrix = Matrix.Translation(-(CarData?.GetWheelGraphicOffset(x.Name) ?? Vector3.Zero) + new Vector3(0f, x.Matrix.GetTranslationVector().Y - (x.BoundingBox?.Minimum.Y ?? 0f), 0f)), FileName = $"tyre_{i}_shadow.png", Progress = progress.SubrangeDouble(0.6 + i * 0.1, 0.099) }).ToList(); foreach (var entry in list) { using (var replacement = FileUtils.RecycleOriginal(Path.Combine(outputDirectory, entry.FileName))) { var m = Matrix.Invert(entry.GlobalMatrix); _flattenNodes = list.SelectMany(x => { x.Node.ParentMatrix = Matrix.Identity; x.Node.LocalMatrix = entry.Matrix * x.GlobalMatrix * m; return(Flatten(x.Node).OfType <Kn5RenderableDepthOnlyObject>()); }).ToArray(); Draw(WheelMultiplier, WheelSize, WheelPadding, 1f, entry.Progress, cancellation); if (cancellation.IsCancellationRequested) { return; } SaveResultAs(replacement.Filename, WheelSize, WheelPadding); } } }