Ejemplo n.º 1
0
        protected override void InitializeInner()
        {
            DeviceContextHolder.Set <IMaterialsFactory>(new TrackMapMaterialsFactory());

            if (_aiLane != null)
            {
                RootNode = new RenderableList("_root", Matrix.Identity, new [] {
                    AiLaneObject.Create(_aiLane, AiLaneActualWidth ? (float?)null : AiLaneWidth)
                });
                _aiLaneDirty = false;
            }
            else if (_kn5 != null)
            {
                RootNode = ToRenderableList(Convert(_kn5.RootNode));
            }
            else if (_description != null)
            {
                RootNode = new RenderableList("_root", Matrix.Identity, _description.GetEntries().Select(x => {
                    var node         = ToRenderableList(Convert(x.Kn5.RootNode));
                    node.LocalMatrix = x.Matrix;
                    return(node);
                }));
            }
            else
            {
                RootNode = new RenderableList();
            }

            _buffer0 = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _buffer1 = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
        }
Ejemplo n.º 2
0
 protected static IEnumerable <IKn5RenderableObject> Flatten(RenderableList root, Func <IRenderableObject, bool> filter = null)
 {
     return(root
            .SelectManyRecursive(x => x is Kn5RenderableList list && list.IsEnabled ? (filter?.Invoke(list) == false ? null : list) : null)
            .OfType <IKn5RenderableObject>()
            .Where(x => x.IsEnabled && filter?.Invoke(x) != false));
 }
Ejemplo n.º 3
0
        public static IRenderableObject Create(AiLane aiLane, float?fixedWidth)
        {
            // four vertices per sector
            const int verticesPerSector = 4;

            // actually, I think it’s 65535, but let’s not go there
            const int maxVertices = 30000;

            var aiPoints      = aiLane.Points;
            var sectorsNumber = aiPoints.Length - 1;

            if (sectorsNumber < 1)
            {
                return(new InvisibleObject());
            }

            if (sectorsNumber * verticesPerSector <= maxVertices)
            {
                return(Create(aiPoints, fixedWidth, 0, aiPoints.Length));
            }

            var pointsPerObject = maxVertices / verticesPerSector + 1;
            var result          = new RenderableList();

            for (var i = 0; i < aiPoints.Length; i += pointsPerObject)
            {
                result.Add(Create(aiPoints, fixedWidth, i, Math.Min(i + pointsPerObject, aiPoints.Length)));
            }

            AcToolsLogging.Write("Objects: " + result.Count);
            return(result);
        }
Ejemplo n.º 4
0
        // Holder only used for FS watching and update
        public void SetTarget(RenderableList parent, float position, [CanBeNull] IDeviceContextHolder holder)
        {
            if (_parent != parent)
            {
                _holder = holder == null ? null : new WeakReference <IDeviceContextHolder>(holder);
                _parent = parent;
                Initialize(parent);

                if (Equals(position, _currentPosition))
                {
                    Set(position);
                    return;
                }
            }

            _loopsRemain = 0;

            if (_duration <= 0f)
            {
                Set(position);
            }
            else
            {
                _targetPosition = position;
            }
        }
Ejemplo n.º 5
0
 private RenderableList Filter(RenderableList source, Func <IRenderableObject, bool> fn)
 {
     return(new RenderableList(source.Name, source.LocalMatrix, source.Where(fn).Select(x => {
         var list = x as RenderableList;
         return list != null ? Filter(list, fn) : x;
     })));
 }
Ejemplo n.º 6
0
        public void SetTarget(RenderableList parent, float position)
        {
            if (_parent != parent)
            {
                _parent = parent;
                Initialize(parent);

                if (Equals(position, _currentPosition))
                {
                    Set(position);
                    return;
                }
            }

            _loopsRemain = 0;

            if (_duration <= 0f)
            {
                Set(position);
            }
            else
            {
                _targetPosition = position;
            }
        }
Ejemplo n.º 7
0
        public static bool SetCockpitLrActive([NotNull] RenderableList parent, bool value)
        {
            var changed = false;

            foreach (var child in parent.GetAllChildren().OfType <Kn5RenderableList>())
            {
                switch (child.OriginalNode.Name)
                {
                case "COCKPIT_LR":
                case "STEER_LR":
                case "SHIFT_LD":
                    if (child.IsEnabled != value)
                    {
                        child.IsEnabled = value;
                        changed         = true;
                    }
                    break;

                case "COCKPIT_HR":
                case "STEER_HR":
                case "SHIFT_HD":
                    if (child.IsEnabled != !value)
                    {
                        child.IsEnabled = !value;
                        changed         = true;
                    }
                    break;
                }
            }

            return(changed);
        }
        private void LocalTexturePatchTestForm_Load( object sender, System.EventArgs e )
        {
            IRenderable scene = new RenderableList( new PlanetSurface( planetRadius ), new AtmosphereSurface( model ) );

            Viewer viewer = new Viewer( this, CreateCamera( CommandUser.Default ), scene );
            display1.AddViewer( viewer );
        }
        /// <summary>
        ///		Internal method for adding a solid renderable
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        /// <param name="noShadows">True to add to the no shadow group, false otherwise.</param>
        protected void AddSolidRenderable(Technique technique, IRenderable renderable, bool noShadows)
        {
            SortedList passMap = null;

            if (noShadows)
            {
                passMap = solidPassesNoShadow;
            }
            else
            {
                passMap = solidPasses;
            }

            for (int i = 0; i < technique.NumPasses; i++)
            {
                Pass pass = technique.GetPass(i);

                if (passMap[pass] == null)
                {
                    // add a new list to hold renderables for this pass
                    passMap.Add(pass, new RenderableList());
                }

                // add to solid list for this pass
                RenderableList solidList = (RenderableList)passMap[pass];

                solidList.Add(renderable);
            }
        }
Ejemplo n.º 10
0
        public static bool SetSeatbeltActive([NotNull] RenderableList parent, bool value)
        {
            var changed = false;

            var onNode = parent.GetDummyByName("CINTURE_ON");

            if (onNode != null)
            {
                if (onNode.IsEnabled != value)
                {
                    onNode.IsEnabled = value;
                    changed          = true;
                }
            }

            var offNode = parent.GetDummyByName("CINTURE_OFF");

            if (offNode != null)
            {
                if (offNode.IsEnabled != !value)
                {
                    offNode.IsEnabled = !value;
                    changed           = true;
                }
            }

            return(changed);
        }
        protected override void InitializeInner() {
            Camera = new CameraOrbit(45) {
                Alpha = 30.0f,
                Beta = 25.0f,
                NearZ = 0.1f,
                Radius = 5.5f,
                Target = Vector3.Zero
            };

            Scene.Add(_box1 = new RenderableList {
                new TestingCube()
            });

            _box2s = new RenderableList(null, Matrix.RotationX(90.5f) * Matrix.Translation(0.0f, 0.0f, 3.0f)) {new TestingCube()};
            Scene.Add(_box2 = new RenderableList {
                new TestingCube(),
                _box2s
            });
            
            Scene.Add(_box3 = new RenderableList {
                new TestingCube()
            });

            Scene.Add(_box4 = new RenderableList {
                new TestingCube()
            });
        }
Ejemplo n.º 12
0
        protected override void InitializeInner()
        {
            Camera = new CameraOrbit(45)
            {
                Alpha  = 30.0f,
                Beta   = 25.0f,
                NearZ  = 0.1f,
                Radius = 5.5f,
                Target = Vector3.Zero
            };

            Scene.Add(_box1 = new RenderableList {
                new TestingCube()
            });

            _box2s = new RenderableList(null, Matrix.RotationX(90.5f) * Matrix.Translation(0.0f, 0.0f, 3.0f))
            {
                new TestingCube()
            };
            Scene.Add(_box2 = new RenderableList {
                new TestingCube(),
                _box2s
            });

            Scene.Add(_box3 = new RenderableList {
                new TestingCube()
            });

            Scene.Add(_box4 = new RenderableList {
                new TestingCube()
            });
        }
Ejemplo n.º 13
0
            public Wrapper(RenderableList parent, KsAnimEntryBase entry)
            {
                _object = parent.GetDummyByName(entry.NodeName);

                var v2 = entry as KsAnimEntryV2;

                _frames = v2 != null?ConvertFrames(v2.KeyFrames) : ConvertFrames(((KsAnimEntryV1)entry).Matrices);
            }
Ejemplo n.º 14
0
            internal CarSlot([NotNull] ForwardKn5ObjectRenderer renderer, [CanBeNull] CarDescription car, int?id)
            {
                Id = id ?? ++_id;

                _renderer  = renderer;
                _car       = car;
                CarWrapper = new RenderableList();
            }
Ejemplo n.º 15
0
 private void RebuildAiLane()
 {
     RootNode.Dispose();
     RootNode = new RenderableList("_root", Matrix.Identity, new[] {
         AiLaneObject.Create(_aiLane, AiLaneActualWidth ? (float?)null : AiLaneWidth)
     });
     UpdateFiltered();
     _aiLaneDirty = false;
 }
Ejemplo n.º 16
0
 public void SetParent(RenderableList parent, [CanBeNull] IDeviceContextHolder holder)
 {
     if (_parent != parent)
     {
         _holder = holder == null ? null : new WeakReference <IDeviceContextHolder>(holder);
         _parent = parent;
         Initialize(parent);
     }
 }
Ejemplo n.º 17
0
        protected override void InitializeInner()
        {
            DeviceContextHolder.Set <IMaterialsFactory>(new DepthMaterialsFactory());
            DeviceContextHolder.Set <IAlphaTexturesProvider>(new AlphaTexturesProvider(Kn5));
            CarNode = (RenderableList)Kn5DepthOnlyConverter.Instance.Convert(Kn5.RootNode);
            Scene.Add(CarNode);

            ApplyCarState();
            Scene.UpdateBoundingBox();
        }
        private void LoadAndAdjustKn5()
        {
            DeviceContextHolder.Set <IMaterialsFactory>(new DepthMaterialsFactory());

            _carNode = (RenderableList)Kn5RenderableDepthOnlyObject.Convert(_kn5.RootNode);
            _scene.Add(_carNode);

            _carNode.UpdateBoundingBox();
            _carNode.LocalMatrix = Matrix.Translation(0, UpDelta - (_carNode.BoundingBox?.Minimum.Y ?? 0f), 0) * _carNode.LocalMatrix;
            _scene.UpdateBoundingBox();
        }
Ejemplo n.º 19
0
        protected override void InitializeInner()
        {
            base.InitializeInner();

            DeviceContextHolder.Set(GetMaterialsFactory());

            if (_showroomKn5Filename != null)
            {
                ShowroomNode = LoadShowroom(_showroomKn5Filename);
                Scene.Insert(0, ShowroomNode);
            }

            _carWrapper = new RenderableList();
            Scene.Add(_carWrapper);

            if (_car != null)
            {
                var carNode = new Kn5RenderableCar(_car, Matrix.Identity, _selectSkinLater ? _selectSkin : Kn5RenderableCar.DefaultSkin,
                                                   asyncTexturesLoading: AsyncTexturesLoading, asyncOverrideTexturesLoading: AsyncOverridesLoading,
                                                   allowSkinnedObjects: AllowSkinnedObjects);
                CarNode = carNode;
                CopyValues(carNode, null);

                _selectSkinLater = false;
                _carWrapper.Add(carNode);
                _carBoundingBox = null;

                ExtendCar(CarNode, _carWrapper);
            }

            // Scene.Add(new Kn5RenderableFile(Kn5.FromFile(_carKn5), Matrix.Identity));

            Scene.UpdateBoundingBox();

            _reflectionCubemap?.Initialize(DeviceContextHolder);

            if (EnableShadows)
            {
                _shadows = CreateShadows();
                _shadows?.Initialize(DeviceContextHolder);
            }

            if (Camera == null)
            {
                Camera       = CreateCamera(CarNode);
                _resetCamera = (CameraOrbit)Camera.Clone();
                PrepareCamera(Camera);
            }

            DeviceContextHolder.SceneUpdated    += OnSceneUpdated;
            DeviceContextHolder.TexturesUpdated += OnTexturesUpdated;
        }
Ejemplo n.º 20
0
        public Kn5RenderableFile(Kn5 kn5, Matrix matrix, bool asyncTexturesLoading = true, bool allowSkinnedObjects = false) : base(kn5.OriginalFilename, matrix)
        {
            AllowSkinnedObjects  = allowSkinnedObjects;
            OriginalFile         = kn5;
            AsyncTexturesLoading = asyncTexturesLoading;

            var obj = Convert(kn5.RootNode, AllowSkinnedObjects);

            RootObject = obj as RenderableList ?? new RenderableList {
                obj
            };
            Add(RootObject);
        }
Ejemplo n.º 21
0
 protected static IEnumerable <Kn5RenderableDepthOnlyObject> Flatten(RenderableList root, Func <IRenderableObject, bool> filter = null)
 {
     return(root
            .SelectManyRecursive(x => {
         var list = x as Kn5RenderableList;
         if (list == null || !list.IsEnabled)
         {
             return null;
         }
         return filter?.Invoke(list) == false ? null : list;
     })
            .OfType <Kn5RenderableDepthOnlyObject>()
            .Where(x => x.IsEnabled && filter?.Invoke(x) != false));
 }
Ejemplo n.º 22
0
        public static void UpdateModelMatrixInverted(RenderableList root)
        {
            var inverted = Matrix.Invert(root.Matrix);

            foreach (var dummy in root.GetAllChildren().OfType <Kn5RenderableList>())
            {
                dummy.ModelMatrixInverted = inverted;
            }

            foreach (var dummy in root.GetAllChildren().OfType <IKn5RenderableObject>())
            {
                dummy.ModelMatrixInverted = inverted;
            }
        }
Ejemplo n.º 23
0
        public override void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            if (_dirNode != null && !_dirTargetSet)
            {
                _dirTargetSet = true;

                var model = holder.TryToGet <IKn5Model>();
                if (model != null)
                {
                    _dirTarget = model.GetDummyByName(_dirNode);
                    _dirTarget?.LookAt(this);
                }
            }

            base.Draw(holder, camera, mode, filter);
        }
Ejemplo n.º 24
0
        public void Loop(RenderableList parent, int limit = -1)
        {
            if (_parent != parent)
            {
                _parent = parent;
                Initialize(parent);

                if (_loopsRemain != 0)
                {
                    Set(_currentPosition);
                    return;
                }
            }

            _loopsRemain = limit;
        }
Ejemplo n.º 25
0
        public static IEnumerable <IRenderableObject> GetAllChildren([NotNull] this RenderableList list)
        {
            foreach (var obj in list)
            {
                yield return(obj);

                var l = obj as RenderableList;
                if (l == null)
                {
                    continue;
                }
                foreach (var o in GetAllChildren(l))
                {
                    yield return(o);
                }
            }
        }
Ejemplo n.º 26
0
        protected override void InitializeInner()
        {
            base.InitializeInner();

            DeviceContextHolder.Set <IMaterialsFactory>(new MaterialsProviderSimple());

            if (_showroom != null)
            {
                var kn5 = Kn5.FromFile(_showroom.Kn5Filename);
                Scene.Insert(0, new Kn5RenderableFile(kn5, Matrix.Identity));
            }

            _carWrapper = new RenderableList();
            Scene.Add(_carWrapper);

            if (_car != null)
            {
                var kn5 = Kn5.FromFile(FileUtils.GetMainCarFilename(_car.Location));
                CarNode          = new Kn5RenderableCar(kn5, _car.Location, Matrix.Identity, _selectSkinLater ? _selectSkin : Kn5RenderableCar.DefaultSkin);
                _selectSkinLater = false;
                _carWrapper.Add(CarNode);

                var reflection = new FlatMirror(CarNode, new Plane(Vector3.Zero, Vector3.UnitY));
                _carWrapper.Add(reflection);
            }

            Scene.UpdateBoundingBox();

            if (CubemapReflection)
            {
                _reflectionCubemap = new ReflectionCubemap(1024);
                _reflectionCubemap.Initialize(DeviceContextHolder);
            }

            if (EffectDarkMaterial.EnableShadows)
            {
                _shadows = new ShadowsDirectional(2048, new[] { 5f });
                _shadows.Initialize(DeviceContextHolder);
            }

            if (Camera == null)
            {
                Camera       = CreateCamera(CarNode);
                _resetCamera = (CameraOrbit)Camera.Clone();
            }
        }
Ejemplo n.º 27
0
        public void SetImmediate(RenderableList parent, float position)
        {
            if (_parent != parent)
            {
                _parent = parent;
                Initialize(parent);

                if (Equals(position, _currentPosition))
                {
                    Set(position);
                    return;
                }
            }

            if (!Equals(position, _currentPosition))
            {
                Set(position);
                _currentPosition = position;
            }
        }
Ejemplo n.º 28
0
 private void GetCameraOffsetForCenterAlignmentUsingVertices_ProcessList(RenderableList list, Matrix matrix, ref Vector3 min, ref Vector3 max)
 {
     for (var i = 0; i < list.Count; i++)
     {
         var child = list[i];
         var li    = child as RenderableList;
         if (li != null)
         {
             GetCameraOffsetForCenterAlignmentUsingVertices_ProcessList(li, matrix, ref min, ref max);
         }
         else
         {
             var ro = child as Kn5RenderableObject;
             if (ro != null)
             {
                 GetCameraOffsetForCenterAlignmentUsingVertices_ProcessObject(ro, matrix, ref min, ref max);
             }
         }
     }
 }
Ejemplo n.º 29
0
        public void SetImmediate(RenderableList parent, float position, [CanBeNull] IDeviceContextHolder holder)
        {
            if (_parent != parent)
            {
                _holder = holder == null ? null : new WeakReference <IDeviceContextHolder>(holder);
                _parent = parent;
                Initialize(parent);

                if (Equals(position, _currentPosition))
                {
                    Set(position);
                    return;
                }
            }

            if (!Equals(position, _currentPosition))
            {
                Set(position);
                _currentPosition = position;
            }
        }
        private void AtmosphereTestForm_Load( object sender, System.EventArgs e )
        {
            float planetRadius = 1000.0f;
            float atmosphereThickness = 10.0f;

            AtmosphereCalculatorModel model = new AtmosphereCalculatorModel( );
            model.PlanetRenderRadius = planetRadius;
            model.AtmosphereRenderRadius = planetRadius + atmosphereThickness;
            model.Samples = 10;

            propertyGrid1.SelectedObject = model;

            IRenderable scene = new RenderableList( new PlanetSurface( planetRadius ), new AtmosphereSurface( model ) );

            Viewer viewer = new Viewer( this, CreateCamera( CommandUser.Default ), scene );
            viewer.ClearColour = Color.Black;
            display.AddViewer( viewer );

            //	TODO: AP: Horrible bodge to work around InteractionUpdateTimer not working properly without manual intervention
            display.OnBeginRender += delegate { InteractionUpdateTimer.Instance.OnUpdate( ); };
        }
Ejemplo n.º 31
0
        public static IEnumerable <IKn5RenderableObject> GetByNameAll([NotNull] this RenderableList list, [NotNull] string name)
        {
            foreach (var obj in list)
            {
                var r = obj as IKn5RenderableObject;
                if (r?.OriginalNode.Name == name)
                {
                    yield return(r);
                }

                var l = obj as RenderableList;
                if (l == null)
                {
                    continue;
                }
                foreach (var o in GetByNameAll(l, name))
                {
                    yield return(o);
                }
            }
        }
Ejemplo n.º 32
0
        private void GetCameraOffsetForCenterAlignmentUsingVertices_ProcessList(RenderableList list, Matrix matrix, ref Vector3 min, ref Vector3 max)
        {
            for (var i = 0; i < list.Count; i++)
            {
                var child = list[i];
                switch (child)
                {
                case RenderableList li:
                    GetCameraOffsetForCenterAlignmentUsingVertices_ProcessList(li, matrix, ref min, ref max);
                    break;

                case Kn5RenderableObject ro:
                    if (!IsAlignableNode(ro))
                    {
                        continue;
                    }
                    GetCameraOffsetForCenterAlignmentUsingVertices_ProcessObject(ro, matrix, ref min, ref max);
                    break;
                }
            }
        }
Ejemplo n.º 33
0
        public override void Draw(IDeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            if (_dirNode != null && !_dirTargetSet)
            {
                _dirTargetSet = true;

                var model = contextHolder.TryToGet <IKn5Model>();
                if (model != null)
                {
                    _dirTarget = model.GetDummyByName(_dirNode);
                    _dirTarget?.LookAt(this);
                }
            }

            base.Draw(contextHolder, camera, mode, filter);

            if (HighlightDummy && mode == SpecialRenderMode.SimpleTransparent)
            {
                _lines.ParentMatrix = Matrix;
                _lines.Draw(contextHolder, camera, SpecialRenderMode.Simple);
            }
        }
 public AmbientShadowKn5ObjectRenderer(Kn5 kn5, string carLocation = null) {
     _kn5 = kn5;
     _carHelper = new CarHelper(_kn5, carLocation);
     _scene = new RenderableList();
 }
        /// <summary>
        ///		Internal method for adding a solid renderable ot the group based on lighting stage.
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        protected void AddSolidRenderableSplitByLightType(Technique technique, IRenderable renderable)
        {
            // Divide the passes into the 3 categories
            for (int i = 0; i < technique.IlluminationPassCount; i++)
            {
                // Insert into solid list
                IlluminationPass illpass = technique.GetIlluminationPass(i);
                SortedList passMap = null;

                switch(illpass.Stage)
                {
                    case IlluminationStage.Ambient:
                        passMap = solidPasses;
                        break;
                    case IlluminationStage.PerLight:
                        passMap = solidPassesDiffuseSpecular;
                        break;
                    case IlluminationStage.Decal:
                        passMap = solidPassesDecal;
                        break;
                }

                RenderableList solidList = (RenderableList)passMap[illpass.Pass];

                if(solidList == null)
                {
                    // add a new list to hold renderables for this pass
                    solidList = new RenderableList();
                    passMap.Add(illpass.Pass, solidList);
                }

                solidList.Add(renderable);
            }
        }
Ejemplo n.º 36
0
 protected SceneRenderer() {
     Scene = new RenderableList();
 }
Ejemplo n.º 37
0
 private RenderableList Filter(RenderableList source, Func<IRenderableObject, bool> fn) {
     return new RenderableList(source.Name, source.LocalMatrix, source.Where(fn).Select(x => {
         var list = x as RenderableList;
         return list != null ? Filter(list, fn) : x;
     }));
 }