private void DoBreak()
        {
            var actor = Object.Find <Actor>(ref _actorId);

            if (actor == null)
            {
                throw new FlaxException("Cannot break prefab link. Missing actor.");
            }
            if (!actor.HasPrefabLink)
            {
                throw new FlaxException("Cannot break missing prefab link.");
            }

            if (_prefabObjectIds == null)
            {
                _prefabObjectIds = new Dictionary <Guid, Guid>(1024);
            }
            else
            {
                _prefabObjectIds.Clear();
            }
            CollectIds(actor);

            _prefabId = actor.PrefabID;

            actor.BreakPrefabLink();

            Editor.Instance.Scene.MarkSceneEdited(actor.Scene);
            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }
Example #2
0
        private void OnUpdate()
        {
            if (_queue.Count == 0 || (_task != null && _task.Enabled))
            {
                return;
            }

            // TODO: add delay when processing the requests to reduce perf impact (eg. 0.2s before actual rendering)

            // Setup pipeline
            if (_atlases == null)
            {
                _atlases = new List <Atlas>(4);
            }
            if (_output == null)
            {
                _output = RenderTarget.New();
                _output.Init(PixelFormat.R8G8B8A8_UNorm, Width, Height);
            }
            if (_task == null)
            {
                _task        = Object.New <SceneRenderTask>();
                _task.Output = _output;
                _task.Begin += OnBegin;
                _task.End   += OnEnd;
            }

            // Kick off the rendering
            _task.Enabled = true;
        }
        private void DoLink()
        {
            if (_prefabObjectIds == null)
            {
                throw new FlaxException("Cannot link prefab. Missing objects Ids mapping.");
            }

            var actor = Object.Find <Actor>(ref _actorId);

            if (actor == null)
            {
                throw new FlaxException("Cannot link prefab. Missing actor.");
            }

            // Restore cached links
            foreach (var e in _prefabObjectIds)
            {
                var objId       = e.Key;
                var prefabObjId = e.Value;

                var obj = Object.Find <Object>(ref objId);
                if (obj is Actor)
                {
                    Actor.Internal_LinkPrefab(obj.unmanagedPtr, ref _prefabId, ref prefabObjId);
                }
                else if (obj is Script)
                {
                    Script.Internal_LinkPrefab(obj.unmanagedPtr, ref _prefabId, ref prefabObjId);
                }
            }

            Editor.Instance.Scene.MarkSceneEdited(actor.Scene);
            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }
Example #4
0
                public void MarkSceneEdited(SceneModule sceneModule)
                {
                    var spline = Object.Find <Spline>(ref SplineId);

                    sceneModule.MarkSceneEdited(spline.Scene);
                    OnSplineEdited(spline);
                }
        /// <inheritdoc />
        public override void OnDestroy()
        {
            base.OnDestroy();

            Object.Destroy(ref _collisionWiresShowActor);
            Object.Destroy(ref _collisionWiresModel);
        }
Example #6
0
        /// <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 = new Scene();

            scene.StaticFlags = StaticFlags.FullyStatic;
            //
            var sun = scene.AddChild <DirectionalLight>();

            sun.Name             = "Sun";
            sun.LocalPosition    = new Vector3(40, 160, 0);
            sun.LocalEulerAngles = new Vector3(45, 0, 0);
            sun.StaticFlags      = StaticFlags.FullyStatic;
            //
            var sky = scene.AddChild <Sky>();

            sky.Name          = "Sky";
            sky.LocalPosition = new Vector3(40, 150, 0);
            sky.SunLight      = sun;
            sky.StaticFlags   = StaticFlags.FullyStatic;
            //
            var skyLight = scene.AddChild <SkyLight>();

            skyLight.Mode          = SkyLight.Modes.CustomTexture;
            skyLight.Brightness    = 2.5f;
            skyLight.CustomTexture = FlaxEngine.Content.LoadAsyncInternal <CubeTexture>(EditorAssets.DefaultSkyCubeTexture);
            skyLight.StaticFlags   = StaticFlags.FullyStatic;
            //
            var floor = scene.AddChild <StaticModel>();

            floor.Name  = "Floor";
            floor.Scale = new Vector3(4, 0.5f, 4);
            floor.Model = FlaxEngine.Content.LoadAsync <Model>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Primitives/Cube.flax"));
            if (floor.Model)
            {
                floor.Model.WaitForLoaded();
                floor.SetMaterial(0, FlaxEngine.Content.LoadAsync <MaterialBase>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Engine/WhiteMaterial.flax")));
            }
            floor.StaticFlags = StaticFlags.FullyStatic;
            //
            var cam = scene.AddChild <Camera>();

            cam.Name     = "Camera";
            cam.Position = new Vector3(0, 150, -300);

            // Serialize
            var bytes = Level.SaveSceneToBytes(scene);

            // Cleanup
            Object.Destroy(ref 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);
        }
Example #7
0
        private void DoAdd()
        {
            // Restore script
            var parentActor = Object.Find <Actor>(ref _parentId);

            if (parentActor == null)
            {
                // Error
                Editor.LogWarning("Missing parent actor.");
                return;
            }
            _script = (Script)Object.New(_scriptType);
            if (_script == null)
            {
                // Error
                Editor.LogWarning("Cannot create script of type " + _scriptType);
                return;
            }
            Object.Internal_ChangeID(_script.unmanagedPtr, ref _scriptId);
            if (_scriptData != null)
            {
                FlaxEngine.Json.JsonSerializer.Deserialize(_script, _scriptData);
            }
            _script.Enabled = _enabled;
            parentActor.AddScript(_script);
            if (_orderInParent != -1)
            {
                _script.OrderInParent = _orderInParent;
            }
            if (_prefabObjectId != Guid.Empty)
            {
                Script.Internal_LinkPrefab(_script.unmanagedPtr, ref _prefabId, ref _prefabObjectId);
            }
            Editor.Instance.Scene.MarkSceneEdited(parentActor.Scene);
        }
Example #8
0
        /// <inheritdoc />
        protected override void UnlinkItem()
        {
            Object.Destroy(_textPreview.Font);
            _textPreview.Font = null;

            base.UnlinkItem();
        }
Example #9
0
        private void OnUpdate()
        {
            if (_queue.Count == 0 || (_task != null && _task.Enabled))
            {
                return;
            }

            // TODO: add delay when processing the requests to reduce perf impact (eg. 0.2s before actual rendering)

            // Setup pipeline
            if (_atlases == null)
            {
                _atlases = new List <Atlas>(4);
            }
            if (_output == null)
            {
                _output = GPUDevice.Instance.CreateTexture("CameraCutMedia.Output");
                var desc = GPUTextureDescription.New2D(Width, Height, PixelFormat.R8G8B8A8_UNorm);
                _output.Init(ref desc);
            }
            if (_task == null)
            {
                _task        = Object.New <SceneRenderTask>();
                _task.Output = _output;
                _task.Begin += OnBegin;
                _task.End   += OnEnd;
            }

            // Kick off the rendering
            _task.Enabled = true;
        }
Example #10
0
        /// <inheritdoc />
        public override bool GetBoxDebuggerTooltip(Box box, out string text)
        {
            if (Editor.Instance.Simulation.IsDuringBreakpointHang)
            {
                // Find any local variable from the current scope that matches this box
                var state = Windows.Assets.VisualScriptWindow.GetLocals();
                if (state.Locals != null)
                {
                    for (int i = 0; i < state.Locals.Length; i++)
                    {
                        ref var local = ref state.Locals[i];
                        if (local.BoxId == box.ID && local.NodeId == box.ParentNode.ID)
                        {
                            text = $"{local.Value ?? string.Empty} ({local.ValueTypeName})";
                            return(true);
                        }
                    }
                }

                // Evaluate the value using the Visual Scripting backend
                if (box.CurrentType != typeof(void))
                {
                    var local = new Editor.VisualScriptLocal
                    {
                        NodeId = box.ParentNode.ID,
                        BoxId  = box.ID,
                    };
                    var script = ((Windows.Assets.VisualScriptWindow)box.Surface.Owner).Asset;
                    if (Editor.Internal_EvaluateVisualScriptLocal(Object.GetUnmanagedPtr(script), ref local))
                    {
                        text = $"{local.Value ?? string.Empty} ({local.ValueTypeName})";
                        return(true);
                    }
                }
            }
Example #11
0
        public static bool TryGetPatchCoordToAdd(Terrain terrain, Ray ray, out Int2 patchCoord)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_TryGetPatchCoordToAdd(Object.GetUnmanagedPtr(terrain), ref ray, out patchCoord));
#endif
        }
Example #12
0
        public static bool Intersects(Foliage foliage, Ray ray, out float distance, out Vector3 normal, out int instanceIndex)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_Intersects(Object.GetUnmanagedPtr(foliage), ref ray, out distance, out normal, out instanceIndex));
#endif
        }
Example #13
0
        public static bool RayCastChunk(Terrain terrain, Ray ray, out float resultHitDistance, out Int2 resultPatchCoord, out Int2 resultChunkCoord, float maxDistance = float.MaxValue)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_RayCastChunk(Object.GetUnmanagedPtr(terrain), ref ray, out resultHitDistance, out resultPatchCoord, out resultChunkCoord, maxDistance));
#endif
        }
Example #14
0
        public static bool GenerateTerrain(Terrain terrain, ref Int2 numberOfPatches, Texture heightmap, float heightmapScale, Texture splatmap1, Texture splatmap2)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_GenerateTerrain(Object.GetUnmanagedPtr(terrain), ref numberOfPatches, Object.GetUnmanagedPtr(heightmap), heightmapScale, Object.GetUnmanagedPtr(splatmap1), Object.GetUnmanagedPtr(splatmap2)));
#endif
        }
Example #15
0
        public static IntPtr GetSplatMapData(Terrain terrain, ref Int2 patchCoord, int index)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_GetSplatMapData(Object.GetUnmanagedPtr(terrain), ref patchCoord, index));
#endif
        }
Example #16
0
        public static bool ModifySplatMap(Terrain terrain, ref Int2 patchCoord, int index, IntPtr samples, ref Int2 offset, ref Int2 size)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_ModifySplatMap(Object.GetUnmanagedPtr(terrain), ref patchCoord, index, samples, ref offset, ref size));
#endif
        }
Example #17
0
        public static bool InitializePatch(Terrain terrain, ref Int2 patchCoord)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_InitializePatch(Object.GetUnmanagedPtr(terrain), ref patchCoord));
#endif
        }
Example #18
0
        public static void Paint(Foliage foliage, int[] foliageTypesIndices, Vector3 brushPosition, float brushRadius, bool additive)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_Paint(Object.GetUnmanagedPtr(foliage), foliageTypesIndices, ref brushPosition, brushRadius, additive);
#endif
        }
Example #19
0
        public static void DeserializePatch(Terrain terrain, ref Int2 patchCoord, string value)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DeserializePatch(Object.GetUnmanagedPtr(terrain), ref patchCoord, value);
#endif
        }
Example #20
0
        public static bool ExportTerrain(Terrain terrain, string outputFolder)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_ExportTerrain(Object.GetUnmanagedPtr(terrain), outputFolder));
#endif
        }
Example #21
0
            /// <inheritdoc />
            public override void OnDestroy()
            {
                Object.Destroy(ref _floorModel);
                _showFloorButton      = null;
                _showCurrentLODButton = null;

                base.OnDestroy();
            }
 public void LogException(Exception exception, FlaxEngine.Object context)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine($"Exception: {exception.Message}");
     if (showExceptionStackTrace)
     {
         Console.WriteLine($"    {exception.StackTrace}");
     }
     Console.ResetColor();
 }
Example #23
0
        /// <inheritdoc />
        public override void OnDestroy()
        {
            // Ensure to cleanup created actor objects
            Object.Destroy(ref PreviewLight);
            Object.Destroy(ref EnvProbe);
            Object.Destroy(ref Sky);
            Object.Destroy(ref SkyLight);
            Object.Destroy(ref PostFxVolume);

            base.OnDestroy();
        }
Example #24
0
 private void DoRemove()
 {
     // Remove script (it could be removed by sth else, just check it)
     if (_script)
     {
         if (_script.Actor)
         {
             Editor.Instance.Scene.MarkSceneEdited(_script.Scene);
         }
         Object.Destroy(ref _script);
     }
 }
Example #25
0
        public void Log(LogType logType, FlaxEngine.Object context, string message)
        {
            Debug.Logger.LogHandler.Log(logType, context, message);

#if DEBUG
            string stackTrace = Environment.StackTrace;
#else
            string stackTrace = string.Empty;
#endif

            SendLog?.Invoke(logType, message, context, stackTrace);
        }
Example #26
0
        /// <inheritdoc />
        public override void OnInit()
        {
            // Create cache folder
            if (!Directory.Exists(_cacheFolder))
            {
                Directory.CreateDirectory(_cacheFolder);
            }

            // Find atlases in a Editor cache directory
            var files   = Directory.GetFiles(_cacheFolder, "cache_*.flax", SearchOption.TopDirectoryOnly);
            int atlases = 0;

            for (int i = 0; i < files.Length; i++)
            {
                // Load asset
                var asset = FlaxEngine.Content.LoadAsync(files[i]);
                if (asset == null)
                {
                    continue;
                }

                // Validate type
                if (asset is PreviewsCache atlas)
                {
                    // Cache atlas
                    atlases++;
                    _cache.Add(atlas);
                }
                else
                {
                    // Skip asset
                    Editor.LogWarning(string.Format("Asset \'{0}\' is inside Editor\'s private directory for Assets Thumbnails Cache. Please move it.", asset.Path));
                }
            }
            Editor.Log(string.Format("Previews cache count: {0} (capacity for {1} icons)", atlases, atlases * PreviewsCache.AssetIconsPerAtlas));

            // Prepare at least one atlas
            if (_cache.Count == 0)
            {
                GetValidAtlas();
            }

            // Create render task but disabled for now
            _output = GPUDevice.Instance.CreateTexture("ThumbnailsOutput");
            var desc = GPUTextureDescription.New2D(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize, PreviewsCache.AssetIconsAtlasFormat);

            _output.Init(ref desc);
            _task         = Object.New <RenderTask>();
            _task.Order   = 50; // Render this task later
            _task.Enabled = false;
            _task.Render += OnRender;
        }
Example #27
0
        private void DestroyMesh()
        {
            if (_segmentActor)
            {
                Object.Destroy(_segmentActor);
                _segmentActor = null;
            }

            if (_chunkMesh)
            {
                Object.Destroy(_chunkMesh);
                _chunkMesh = null;
            }
        }
Example #28
0
            /// <inheritdoc />
            public void Undo()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.RemovePatch(ref _patchCoord);

                Editor.Instance.Scene.MarkSceneEdited(terrain.Scene);
            }
Example #29
0
            /// <inheritdoc />
            public void Do()
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.GetPatchBounds(terrain.GetPatchIndex(ref _patchCoord), out var patchBounds);
                terrain.RemovePatch(ref _patchCoord);
                OnPatchEdit(terrain, ref patchBounds);
            }
Example #30
0
            private void Set(ref Guid id)
            {
                var terrain = Object.Find <FlaxEngine.Terrain>(ref _terrainId);

                if (terrain == null)
                {
                    Editor.LogError("Missing terrain actor.");
                    return;
                }

                terrain.SetChunkOverrideMaterial(ref _patchCoord, ref _chunkCoord, FlaxEngine.Content.LoadAsync <MaterialBase>(ref id));

                Editor.Instance.Scene.MarkSceneEdited(terrain.Scene);
            }