Exemplo n.º 1
0
        private void ClearExisting()
        {
            if (_car != null && CacheSize > 0)
            {
                var existing = _previousCars.FirstOrDefault(x => x.Id == _car.MainKn5File);
                if (existing != null)
                {
                    _previousCars.Remove(existing);
                    _previousCars.Add(existing);
                }
                else if (_carWrapper.OfType <Kn5RenderableCar>().Any())
                {
                    if (_previousCars.Count >= CacheSize)
                    {
                        var toRemoval = _previousCars[0];
                        toRemoval.Objects.DisposeEverything();
                        _previousCars.RemoveAt(0);
                    }

                    _previousCars.Add(new PreviousCar {
                        Id      = _car.MainKn5File,
                        Objects = _carWrapper.ToList()
                    });

                    _carWrapper.Clear();
                    return;
                }
            }

            _carWrapper.DisposeEverything();
        }
        public void Shot(string outputDirectory)
        {
            if (!Initialized)
            {
                Initialize();
            }

            BackupAndRecycle(outputDirectory);

            // body shadow
            PrepareBuffers(BodySize + BodyPadding * 2, 1024);
            SetBodyShadowCamera();
            Draw(BodyMultipler, BodySize, BodyPadding, Fade);

            // return;
            SaveResultAs(outputDirectory, "body_shadow.png", 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(0f, x.Matrix.GetTranslationVector().Y - (x.BoundingBox?.Minimum.Y ?? 0f), 0f),
                Filename = $"tyre_{i}_shadow.png"
            }))
            {
                _scene.Clear();
                _scene.Add(entry.Node);
                entry.Node.LocalMatrix = entry.Matrix;
                _scene.UpdateBoundingBox();

                Draw(WheelMultipler, WheelSize, WheelPadding, false);
                SaveResultAs(outputDirectory, entry.Filename, WheelSize, WheelPadding);
            }
        }