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); }
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(); }
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; }
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(); } }
protected override void InitializeInner() { base.InitializeInner(); DeviceContextHolder.Set <IMaterialsFactory>(new MaterialsProviderDeferred()); Scene.Add(SkyObject.Create(500f)); foreach (var showroom in _kn5.Skip(1)) { Scene.Add(new Kn5RenderableFile(showroom, Matrix.Identity)); } if (_kn5.Length > 1) { _car = new DeferredRenderableCar(CarDescription.FromKn5(_kn5[0]), Matrix.Identity, shadowsHeight: 0.001f, lights: Lights) { IsReflectable = false }; Scene.Add(_car); } Scene.UpdateBoundingBox(); Camera = new CameraOrbit(32) { Alpha = 0.9f, Beta = 0.1f, Radius = _car?.BoundingBox?.GetSize().Length() * 1.2f ?? 4.8f, Target = (_car?.BoundingBox?.GetCenter() ?? Vector3.Zero) - new Vector3(0f, 0.05f, 0f) }; _resetCamera = (CameraOrbit)Camera.Clone(); Sun = new DirectionalLight { Color = FixLight(new Vector3(1.2f, 1.0f, 0.9f)) * 5f, Direction = Vector3.Normalize(new Vector3(-1.2f, -3.4f, -2.2f)) }; _effect = DeviceContextHolder.GetEffect <EffectDeferredGObject>(); }
public void Draw(DeviceContextHolder holder, EffectSpecialTrackOutline effect, Matrix mapMatrix, MapViewData max) { if (_dirty) { Initialize(holder); } if (AiLaneMode) { Kn5MaterialTrackOutline.Matrix = mapMatrix; if (!_materialsSet) { _materialsSet = true; if (holder.TryToGet <IMaterialsFactory>() == null) { holder.Set <IMaterialsFactory>(new TrackOutlineMaterialsFactory()); } } _obj.Draw(holder, max?.GetCamera(holder) ?? GetCamera(holder), SpecialRenderMode.Simple); // revert quad holder.PrepareQuad(effect.LayoutPT); } else { // local transformation matrix: global×local offset (calculated from map.ini)×local scale var localScale = Matrix.Transformation2D(Vector2.Zero, 0f, new Vector2(max.DataSize.X / DataSize.X, max.DataSize.Y / DataSize.Y) / DataScale, Vector2.Zero, 0f, Vector2.Zero); var localOffset = Matrix.AffineTransformation2D(1f, Vector2.Zero, 0f, new Vector2( (DataOffset.X - max.DataOffset.X) / max.DataSize.X, (DataOffset.Y - max.DataOffset.Y) / max.DataSize.Y)); effect.FxMatrix.SetMatrix(mapMatrix * localOffset * localScale); effect.FxInputMap.SetResource(_view); effect.TechFirstStep.DrawAllPasses(holder.DeviceContext, 6); } }
protected override void InitializeInner() { base.InitializeInner(); InitializeBuffers(); DeviceContextHolder.Set <INormalsNormalTexturesProvider>(new NormalsNormalsTexturesProvider(Kn5)); }
protected override void InitializeInner() { DeviceContextHolder.Set <IMaterialsFactory>(new UvMaterialsFactory()); _carNode = new Kn5RenderableFile(_kn5, Matrix.Identity); }