/// <summary> /// Creates the new scene file. The default scene contains set of simple actors. /// </summary> /// <param name="path">The path.</param> public void CreateSceneFile(string path) { // Create a sample scene var scene = Scene.New(); var sky = Sky.New(); var sun = DirectionalLight.New(); var floor = ModelActor.New(); // scene.AddChild(sky); scene.AddChild(sun); scene.AddChild(floor); // sky.Name = "Sky"; sky.LocalPosition = new Vector3(40, 150, 0); sky.SunLight = sun; sky.StaticFlags = StaticFlags.FullyStatic; // sun.Name = "Sun"; sun.LocalPosition = new Vector3(40, 160, 0); sun.LocalEulerAngles = new Vector3(45, 0, 0); sun.StaticFlags = StaticFlags.FullyStatic; // floor.Name = "Floor"; floor.Scale = new Vector3(4, 0.5f, 4); floor.Model = FlaxEngine.Content.LoadAsync <Model>(StringUtils.CombinePaths(Globals.EditorFolder, "Primitives/Cube.flax")); if (floor.Model) { floor.Model.WaitForLoaded(); floor.Entries[0].Material = FlaxEngine.Content.LoadAsync <MaterialBase>(StringUtils.CombinePaths(Globals.EngineFolder, "WhiteMaterial.flax")); } floor.StaticFlags = StaticFlags.FullyStatic; // Serialize var bytes = SceneManager.SaveSceneToBytes(scene); // Cleanup Object.Destroy(scene); if (bytes == null || bytes.Length == 0) { throw new Exception("Failed to serialize scene."); } // Write to file using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) fileStream.Write(bytes, 0, bytes.Length); }
/// <summary> /// Initializes a new instance of the <see cref="AssetPreview"/> class. /// </summary> /// <param name="useWidgets">if set to <c>true</c> use widgets.</param> public AssetPreview(bool useWidgets) : base(RenderTask.Create <SceneRenderTask>(), new ArcBallCamera(Vector3.Zero, 50), useWidgets) { DockStyle = DockStyle.Fill; Task.Flags = ViewFlags.DefaulAssetPreview; Task.AllowGlobalCustomPostFx = false; ((ArcBallCamera)ViewportCamera).SetView(new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f)); // Setup preview scene PreviewLight = DirectionalLight.New(); PreviewLight.Brightness = 6.0f; PreviewLight.ShadowsMode = ShadowsCastingMode.None; PreviewLight.Orientation = Quaternion.Euler(new Vector3(52.1477f, -109.109f, -111.739f)); // EnvProbe = EnvironmentProbe.New(); EnvProbe.AutoUpdate = false; EnvProbe.CustomProbe = FlaxEngine.Content.LoadAsyncInternal <CubeTexture>(EditorAssets.DefaultSkyCubeTexture); // Sky = Sky.New(); Sky.SunLight = PreviewLight; Sky.SunPower = 8.0f; // SkyLight = SkyLight.New(); SkyLight.Mode = SkyLight.Modes.CustomTexture; SkyLight.Brightness = 2.0f; SkyLight.CustomTexture = EnvProbe.CustomProbe; // PostFxVolume = PostFxVolume.New(); PostFxVolume.IsBounded = false; PostFxVolume.Settings.Eye_MinLuminance = 0.1f; // Link actors for rendering Task.ActorsSource = ActorsSources.CustomActors; Task.CustomActors.Add(PreviewLight); Task.CustomActors.Add(EnvProbe); Task.CustomActors.Add(Sky); Task.CustomActors.Add(SkyLight); Task.CustomActors.Add(PostFxVolume); }