Esempio n. 1
0
        /// <summary>
        /// Gets the actor node.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <returns>Found actor node or null if missing. Actor may not be linked to the scene tree so node won't be found in that case.</returns>
        public ActorNode GetActorNode(Actor actor)
        {
            if (actor == null)
            {
                return(null);
            }

            // ActorNode has the same ID as actor does
            return(SceneGraphFactory.FindNode(actor.ID) as ActorNode);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.String)
            {
                var id = Guid.Parse((string)reader.Value);
                return(SceneGraphFactory.FindNode(id));
            }

            return(null);
        }
Esempio n. 3
0
 /// <inheritdoc />
 public void Undo()
 {
     // Remove objects
     for (int i = 0; i < _nodeParents.Count; i++)
     {
         var node = SceneGraphFactory.FindNode(_nodeParents[i]);
         Editor.Instance.Scene.MarkSceneEdited(node.ParentScene);
         node.Delete();
     }
     _nodeParents.Clear();
 }
Esempio n. 4
0
        private void OnActorParentChanged(Actor actor, Actor prevParent)
        {
            ActorNode node       = null;
            var       parentNode = GetActorNode(actor.Parent);

            // Try use previous parent actor to find actor node
            var prevParentNode = GetActorNode(prevParent);

            if (prevParentNode != null)
            {
                // If should be one of the children
                node = prevParentNode.FindChildActor(actor);

                // Search whole tree if node was not found
                if (node == null)
                {
                    node = GetActorNode(actor);
                }
            }
            else if (parentNode != null)
            {
                // Create new node for that actor (user may unlink it from the scene before and now link it)
                node = SceneGraphFactory.BuildActorNode(actor);
            }
            if (node == null)
            {
                return;
            }

            // Get the new parent node (may be missing)
            if (parentNode != null)
            {
                // Change parent
                node.TreeNode.UnlockChildrenRecursive();
                node.ParentNode = parentNode;
            }
            else
            {
                // Check if actor is selected in editor
                if (Editor.SceneEditing.Selection.Contains(node))
                {
                    Editor.SceneEditing.Deselect();
                }

                // Remove node (user may unlink actor from the scene but not destroy the actor)
                node.Dispose();
            }
        }
Esempio n. 5
0
            public static SceneGraphNode Create(StateData state)
            {
                var data   = JsonSerializer.Deserialize <Data>(state.State);
                var spline = Object.Find <Spline>(ref data.Spline);

                spline.InsertSplineLocalPoint(data.Index, data.Keyframe.Time, data.Keyframe.Value, false);
                spline.SetSplineKeyframe(data.Index, data.Keyframe);
                var splineNode = (SplineNode)SceneGraphFactory.FindNode(data.Spline);

                if (splineNode == null)
                {
                    return(null);
                }
                splineNode.OnUpdate();
                OnSplineEdited(spline);
                return(splineNode.ActorChildNodes[data.Index]);
            }
Esempio n. 6
0
        private void RemoveBone(string name)
        {
            var ragdoll          = (Ragdoll)Values[0];
            var bodies           = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var joints           = bodies.SelectMany(y => y.Children).Where(z => z is Joint && z.IsActive).Cast <Joint>();
            var body             = bodies.First(x => x.Name == name);
            var replacementJoint = joints.FirstOrDefault(x => x.Parent == body && x.Target != null);

            // Fix joints using this bone
            foreach (var joint in joints)
            {
                if (joint.Target == body)
                {
                    if (replacementJoint != null)
                    {
                        // Swap the joint target to the parent of the removed body to keep ragdoll connected
                        using (new UndoBlock(Presenter.Undo, joint, "Fix joint"))
                        {
                            joint.Target           = replacementJoint.Target;
                            joint.EnableAutoAnchor = true;
                        }
                    }
                    else
                    {
                        // Remove joint that will no longer be valid
                        var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                            SceneGraphFactory.FindNode(joint.ID)
                        });
                        action.Do();
                        Presenter.Undo?.AddAction(action);
                    }
                }
            }

            // Remove body
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                Presenter.Undo?.AddAction(action);
            }
        }
Esempio n. 7
0
        private void OnActorParentChanged(Actor actor, Actor prevParent)
        {
            ActorNode node = null;

            // Try use previous parent actor to find actor node
            var prevParentNode = GetActorNode(prevParent);

            if (prevParentNode != null)
            {
                // If should be one of the children
                node = prevParentNode.FindChildActor(actor);

                // Search whole tree if node was not found
                if (node == null)
                {
                    node = GetActorNode(actor);
                }
            }
            else
            {
                // Create new node for that actor (user may unlink it from the scene before and now link it)
                node = SceneGraphFactory.BuildActorNode(actor);
            }
            if (node == null)
            {
                return;
            }

            // Get the new parent node (may be missing)
            var parentNode = GetActorNode(actor.Parent);

            if (parentNode != null)
            {
                // Change parent
                node.ParentNode = parentNode;
            }
            else
            {
                // Remove node (user may unlink actor from the scene but not destroy the actor)
                node.Dispose();
            }
        }
Esempio n. 8
0
        private void Select(IEnumerable <Actor> list)
        {
            var selection = new List <SceneGraphNode>();

            foreach (var e in list)
            {
                var node = SceneGraphFactory.FindNode(e.ID);
                if (node != null)
                {
                    selection.Add(node);
                }
            }
            if (Presenter.Owner is Windows.PropertiesWindow propertiesWindow)
            {
                propertiesWindow.Editor.SceneEditing.Select(selection);
            }
            else if (Presenter.Owner is Windows.Assets.PrefabWindow prefabWindow)
            {
                prefabWindow.Select(selection);
            }
        }
Esempio n. 9
0
        private void RebuildBone(string name)
        {
            var ragdoll       = (Ragdoll)Values[0];
            var animatedModel = (AnimatedModel)ragdoll.Parent;

            // Remove existing body
            var bodies = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var body   = bodies.FirstOrDefault(x => x.Name == name);

            if (body != null)
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                Presenter.Undo?.AddAction(action);
            }

            // Build ragdoll
            SceneGraph.Actors.AnimatedModelNode.BuildRagdoll(animatedModel, new AnimatedModelNode.RebuildOptions(), ragdoll, name);
        }
Esempio n. 10
0
        /// <summary>
        /// Spawns the specified actor.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <param name="parent">The parent.</param>
        public void Spawn(Actor actor, Actor parent)
        {
            if (actor == null)
            {
                throw new ArgumentNullException(nameof(actor));
            }
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            // Link it
            actor.SetParent(parent);

            // Peek spawned node
            var actorNode = SceneGraphFactory.FindNode(actor.ID) as ActorNode ?? SceneGraphFactory.BuildActorNode(actor);

            if (actorNode == null)
            {
                throw new InvalidOperationException("Failed to create scene node for the spawned actor.");
            }
            var parentNode = SceneGraphFactory.FindNode(parent.ID) as ActorNode;

            if (parentNode == null)
            {
                throw new InvalidOperationException("Missing scene graph node for the spawned parent actor.");
            }
            actorNode.ParentNode = parentNode;

            // Call post spawn action (can possibly setup custom default values)
            actorNode.PostSpawn();

            // Create undo action
            var action = new CustomDeleteActorsAction(new List <SceneGraphNode>(1)
            {
                actorNode
            }, true);

            Undo.AddAction(action);
        }
Esempio n. 11
0
        private void Rebuild(AnimatedModelNode.RebuildOptions options)
        {
            var ragdoll       = (Ragdoll)Values[0];
            var animatedModel = (AnimatedModel)ragdoll.Parent;

            // Remove existing bodies
            var bodies  = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var actions = new List <IUndoAction>();

            foreach (var body in bodies)
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                actions.Add(action);
            }
            Presenter.Undo?.AddAction(new MultiUndoAction(actions));

            // Build ragdoll
            SceneGraph.Actors.AnimatedModelNode.BuildRagdoll(animatedModel, options, ragdoll);
        }
Esempio n. 12
0
        /// <summary>
        /// Restores selection.
        /// </summary>
        public void Restore()
        {
            if (_objects.Count == 0)
            {
                Editor.Instance.SceneEditing.Deselect();
                return;
            }

            var selection = new List <SceneGraph.SceneGraphNode>(_objects.Count);

            for (int i = 0; i < _objects.Count; i++)
            {
                var id   = _objects[i];
                var node = SceneGraphFactory.FindNode(id);
                if (node != null)
                {
                    selection.Add(node);
                }
            }

            _objects.Clear();

            Editor.Instance.SceneEditing.Select(selection);
        }
Esempio n. 13
0
        /// <summary>
        /// Performs the paste/duplicate action and outputs created objects nodes.
        /// </summary>
        /// <param name="nodes">The nodes.</param>
        /// <param name="nodeParents">The node parents.</param>
        public void Do(out List <ActorNode> nodes, out List <ActorNode> nodeParents)
        {
            // Restore objects
            var actors = Actor.FromBytes(_data, _idsMapping);

            if (actors == null)
            {
                nodes       = null;
                nodeParents = null;
                return;
            }
            nodes = new List <ActorNode>(actors.Length);
            Scene[] scenes = null;
            for (int i = 0; i < actors.Length; i++)
            {
                var actor = actors[i];

                // Check if has no parent linked (broken reference eg. old parent not existing)
                if (actor.Parent == null)
                {
                    // Link to the first scene root
                    if (scenes == null)
                    {
                        scenes = SceneManager.Scenes;
                    }
                    actor.SetParent(scenes[0], false);
                }

                var foundNode = SceneGraphFactory.FindNode(actor.ID);
                if (foundNode is ActorNode node)
                {
                    nodes.Add(node);
                }
            }

            nodeParents = nodes.BuildNodesParents();

            // Cache pasted nodes ids (parents only)
            _nodeParents.Clear();
            _nodeParents.Capacity = Mathf.Max(_nodeParents.Capacity, nodeParents.Count);
            for (int i = 0; i < nodeParents.Count; i++)
            {
                _nodeParents.Add(nodeParents[i].ID);
            }

            var pasteParentNode = Editor.Instance.Scene.GetActorNode(_pasteParent);

            if (pasteParentNode != null)
            {
                // Move pasted actors to the parent target (if specified and valid)
                for (int i = 0; i < nodeParents.Count; i++)
                {
                    nodeParents[i].Actor.SetParent(pasteParentNode.Actor, false);
                }
            }

            for (int i = 0; i < nodeParents.Count; i++)
            {
                // Fix name collisions (only for parents)
                var node   = nodeParents[i];
                var parent = node.Actor?.Parent;
                if (parent != null)
                {
                    string  name     = node.Name;
                    Actor[] children = parent.GetChildren();
                    if (children.Count(x => x.Name == name) > 1)
                    {
                        // Generate new name
                        node.Actor.Name = StringUtils.IncrementNameNumber(name, x => children.All(y => y.Name != x));
                    }
                }

                Editor.Instance.Scene.MarkSceneEdited(node.ParentScene);
            }
        }
Esempio n. 14
0
        /// <inheritdoc />
        protected override DragDropEffect OnDragDropHeader(DragData data)
        {
            var result = DragDropEffect.None;

            Actor myActor = Actor;
            Actor newParent;
            int   newOrder = -1;

            // Check if has no actor (only for Root Actor)
            if (myActor == null)
            {
                // Append to the last scene
                var scenes = SceneManager.Scenes;
                if (scenes == null || scenes.Length == 0)
                {
                    throw new InvalidOperationException("No scene loaded.");
                }
                newParent = scenes[scenes.Length - 1];
            }
            else
            {
                newParent = myActor;

                // Use drag positioning to change target parent and index
                if (_dragOverMode == DragItemPositioning.Above)
                {
                    if (myActor.HasParent)
                    {
                        newParent = myActor.Parent;
                        newOrder  = myActor.OrderInParent;
                    }
                }
                else if (_dragOverMode == DragItemPositioning.Below)
                {
                    if (myActor.HasParent)
                    {
                        newParent = myActor.Parent;
                        newOrder  = myActor.OrderInParent + 1;
                    }
                }
            }
            if (newParent == null)
            {
                throw new InvalidOperationException("Missing parent actor.");
            }

            // Drag actors
            if (_dragActors != null && _dragActors.HasValidDrag)
            {
                bool worldPositionLock = ParentWindow.GetKey(Keys.Control) == false;
                var  singleObject      = _dragActors.Objects.Count == 1;
                if (singleObject)
                {
                    var targetActor = _dragActors.Objects[0].Actor;
                    using (new UndoBlock(Editor.Instance.Undo, targetActor, "Change actor parent"))
                    {
                        targetActor.SetParent(newParent, worldPositionLock);
                        targetActor.OrderInParent = newOrder;
                    }
                }
                else
                {
                    var targetActors = _dragActors.Objects.ConvertAll(x => x.Actor);
                    using (new UndoMultiBlock(Editor.Instance.Undo, targetActors, "Change actors parent"))
                    {
                        for (int i = 0; i < targetActors.Count; i++)
                        {
                            var targetActor = targetActors[i];
                            targetActor.SetParent(newParent, worldPositionLock);
                            targetActor.OrderInParent = newOrder;
                        }
                    }
                }

                result = DragDropEffect.Move;
            }
            // Drag assets
            else if (_dragAssets != null && _dragAssets.HasValidDrag)
            {
                for (int i = 0; i < _dragAssets.Objects.Count; i++)
                {
                    var item = _dragAssets.Objects[i];

                    switch (item.ItemDomain)
                    {
                    case ContentDomain.Model:
                    {
                        // Create actor
                        var model = FlaxEngine.Content.LoadAsync <Model>(item.ID);
                        var actor = ModelActor.New();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = item.ShortName;
                        actor.Model       = model;
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        Editor.Instance.SceneEditing.Spawn(actor, Actor);

                        break;
                    }

                    case ContentDomain.Other:
                    {
                        if (item.TypeName == typeof(CollisionData).FullName)
                        {
                            // Create actor
                            var actor = MeshCollider.New();
                            actor.StaticFlags   = Actor.StaticFlags;
                            actor.Name          = item.ShortName;
                            actor.CollisionData = FlaxEngine.Content.LoadAsync <CollisionData>(item.ID);
                            actor.Transform     = Actor.Transform;

                            // Spawn
                            Editor.Instance.SceneEditing.Spawn(actor, Actor);
                        }

                        break;
                    }

                    case ContentDomain.Audio:
                    {
                        var actor = AudioSource.New();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = item.ShortName;
                        actor.Clip        = FlaxEngine.Content.LoadAsync <AudioClip>(item.ID);
                        actor.Transform   = Actor.Transform;
                        Editor.Instance.SceneEditing.Spawn(actor, Actor);

                        break;
                    }

                    case ContentDomain.Prefab:
                    {
                        throw new NotImplementedException("Spawning prefabs");
                    }
                    }
                }

                result = DragDropEffect.Move;
            }
            // Drag actor type
            else if (_dragActorType != null && _dragActorType.HasValidDrag)
            {
                for (int i = 0; i < _dragActorType.Objects.Count; i++)
                {
                    var item = _dragActorType.Objects[i];

                    // Create actor
                    var actor = FlaxEngine.Object.New(item) as Actor;
                    if (actor == null)
                    {
                        Editor.LogWarning("Failed to spawn actor of type " + item.FullName);
                        continue;
                    }
                    actor.StaticFlags = Actor.StaticFlags;
                    actor.Name        = item.Name;
                    actor.Transform   = Actor.Transform;

                    // Spawn
                    Editor.Instance.SceneEditing.Spawn(actor, Actor);
                }

                result = DragDropEffect.Move;
            }

            // Clear cache
            _dragActors?.OnDragDrop();
            _dragAssets?.OnDragDrop();
            _dragActorType?.OnDragDrop();

            // Check if scene has been modified
            if (result != DragDropEffect.None)
            {
                var node = SceneGraphFactory.FindNode(newParent.ID) as ActorNode;
                node?.TreeNode.Expand();
            }

            return(result);
        }
Esempio n. 15
0
 /// <summary>
 /// Gets the actor node.
 /// </summary>
 /// <param name="actorId">The actor id.</param>
 /// <returns>Found actor node or null if missing. Actor may not be linked to the scene tree so node won't be found in that case.</returns>
 public ActorNode GetActorNode(Guid actorId)
 {
     // ActorNode has the same ID as actor does
     return(SceneGraphFactory.FindNode(actorId) as ActorNode);
 }
Esempio n. 16
0
        /// <inheritdoc />
        protected override DragDropEffect OnDragDropHeader(DragData data)
        {
            var result = DragDropEffect.None;

            Actor myActor = Actor;
            Actor newParent;
            int   newOrder = -1;

            // Check if has no actor (only for Root Actor)
            if (myActor == null)
            {
                // Append to the last scene
                var scenes = Level.Scenes;
                if (scenes == null || scenes.Length == 0)
                {
                    throw new InvalidOperationException("No scene loaded.");
                }
                newParent = scenes[scenes.Length - 1];
            }
            else
            {
                newParent = myActor;

                // Use drag positioning to change target parent and index
                if (DragOverMode == DragItemPositioning.Above)
                {
                    if (myActor.HasParent)
                    {
                        newParent = myActor.Parent;
                        newOrder  = myActor.OrderInParent;
                    }
                }
                else if (DragOverMode == DragItemPositioning.Below)
                {
                    if (myActor.HasParent)
                    {
                        newParent = myActor.Parent;
                        newOrder  = myActor.OrderInParent + 1;
                    }
                }
            }
            if (newParent == null)
            {
                throw new InvalidOperationException("Missing parent actor.");
            }

            // Drag actors
            if (_dragActors != null && _dragActors.HasValidDrag)
            {
                bool worldPositionLock = Root.GetKey(KeyboardKeys.Control) == false;
                var  singleObject      = _dragActors.Objects.Count == 1;
                if (singleObject)
                {
                    var targetActor  = _dragActors.Objects[0].Actor;
                    var customAction = targetActor.HasPrefabLink ? new ReparentAction(targetActor) : null;
                    using (new UndoBlock(ActorNode.Root.Undo, targetActor, "Change actor parent", customAction))
                    {
                        targetActor.SetParent(newParent, worldPositionLock);
                        targetActor.OrderInParent = newOrder;
                    }
                }
                else
                {
                    var targetActors = _dragActors.Objects.ConvertAll(x => x.Actor);
                    var customAction = targetActors.Any(x => x.HasPrefabLink) ? new ReparentAction(targetActors) : null;
                    using (new UndoMultiBlock(ActorNode.Root.Undo, targetActors, "Change actors parent", customAction))
                    {
                        for (int i = 0; i < targetActors.Count; i++)
                        {
                            var targetActor = targetActors[i];
                            targetActor.SetParent(newParent, worldPositionLock);
                            targetActor.OrderInParent = newOrder;
                        }
                    }
                }

                result = DragDropEffect.Move;
            }
            // Drag assets
            else if (_dragAssets != null && _dragAssets.HasValidDrag)
            {
                for (int i = 0; i < _dragAssets.Objects.Count; i++)
                {
                    var assetItem = _dragAssets.Objects[i];

                    if (assetItem.IsOfType <SkinnedModel>())
                    {
                        // Create actor
                        var model = FlaxEngine.Content.LoadAsync <SkinnedModel>(assetItem.ID);
                        var actor = new AnimatedModel();
                        actor.StaticFlags  = Actor.StaticFlags;
                        actor.Name         = assetItem.ShortName;
                        actor.SkinnedModel = model;
                        actor.Transform    = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem.IsOfType <Model>())
                    {
                        // Create actor
                        var model = FlaxEngine.Content.LoadAsync <Model>(assetItem.ID);
                        var actor = new StaticModel();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = assetItem.ShortName;
                        actor.Model       = model;
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem.IsOfType <CollisionData>())
                    {
                        // Create actor
                        var actor = new MeshCollider();
                        actor.StaticFlags   = Actor.StaticFlags;
                        actor.Name          = assetItem.ShortName;
                        actor.CollisionData = FlaxEngine.Content.LoadAsync <CollisionData>(assetItem.ID);
                        actor.Transform     = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem.IsOfType <ParticleSystem>())
                    {
                        // Create actor
                        var actor = new ParticleEffect();
                        actor.StaticFlags    = Actor.StaticFlags;
                        actor.Name           = assetItem.ShortName;
                        actor.ParticleSystem = FlaxEngine.Content.LoadAsync <ParticleSystem>(assetItem.ID);
                        actor.Transform      = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem.IsOfType <SceneAnimation>())
                    {
                        // Create actor
                        var actor = new SceneAnimationPlayer();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = assetItem.ShortName;
                        actor.Animation   = FlaxEngine.Content.LoadAsync <SceneAnimation>(assetItem.ID);
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem.IsOfType <AudioClip>())
                    {
                        // Create actor
                        var actor = new AudioSource();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = assetItem.ShortName;
                        actor.Clip        = FlaxEngine.Content.LoadAsync <AudioClip>(assetItem.ID);
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);

                        break;
                    }
                    else if (assetItem.IsOfType <Prefab>())
                    {
                        // Create prefab instance
                        var prefab = FlaxEngine.Content.LoadAsync <Prefab>(assetItem.ID);
                        var actor  = PrefabManager.SpawnPrefab(prefab, null);
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = assetItem.ShortName;
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                    else if (assetItem is VisualScriptItem visualScriptItem && new ScriptType(typeof(Actor)).IsAssignableFrom(visualScriptItem.ScriptType) && visualScriptItem.ScriptType.CanCreateInstance)
                    {
                        // Create actor
                        var actor = (Actor)visualScriptItem.ScriptType.CreateInstance();
                        actor.StaticFlags = Actor.StaticFlags;
                        actor.Name        = assetItem.ShortName;
                        actor.Transform   = Actor.Transform;

                        // Spawn
                        ActorNode.Root.Spawn(actor, Actor);
                    }
                }

                result = DragDropEffect.Move;
            }
            // Drag actor type
            else if (_dragActorType != null && _dragActorType.HasValidDrag)
            {
                for (int i = 0; i < _dragActorType.Objects.Count; i++)
                {
                    var item = _dragActorType.Objects[i];

                    // Create actor
                    var actor = item.CreateInstance() as Actor;
                    if (actor == null)
                    {
                        Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
                        continue;
                    }
                    actor.StaticFlags = Actor.StaticFlags;
                    actor.Name        = item.Name;
                    actor.Transform   = Actor.Transform;

                    // Spawn
                    ActorNode.Root.Spawn(actor, Actor);
                }

                result = DragDropEffect.Move;
            }

            // Clear cache
            _dragHandlers.OnDragDrop(null);

            // Check if scene has been modified
            if (result != DragDropEffect.None)
            {
                var node = SceneGraphFactory.FindNode(newParent.ID) as ActorNode;
                node?.TreeNode.Expand();
            }

            return(result);
        }
Esempio n. 17
0
 /// <inheritdoc />
 protected override SceneGraphNode GetNode(Guid id)
 {
     return(SceneGraphFactory.GetNode(id));
 }
Esempio n. 18
0
 /// <summary>
 /// Gets the node.
 /// </summary>
 /// <param name="id">The actor id.</param>
 /// <returns>The scene graph node.</returns>
 protected virtual SceneGraphNode GetNode(Guid id)
 {
     return(SceneGraphFactory.FindNode(id));
 }
Esempio n. 19
0
        private void InitRenderingScene()
        {
            if (!d3DImage.IsFrontBufferAvailable)
                return;
            factory = new SceneGraphFactory();
            wpfRenderer = factory.CreateRenderTargetA8R8G8B8Asset();

            /////////////////////////////////////////////////////////////

            cameraAsset = factory.CreateCamera();
            cameraAsset.Perspective(34.0 , (double)RESOLUTION_X / (double)RESOLUTION_Y, Z_NEAR, 0.0);

            targetRenderer = factory.CreateRenderTargetAsset();

            clearTargetBuffer = factory.CreateClearBuffer();
            targetRenderer.SetRoot(clearTargetBuffer);
            clearLayerBuffer = factory.CreateClearBuffer();
            wpfRenderer.SetRoot(clearLayerBuffer);

            TextureLayerNode targetTextureLayer = factory.CreateTextureLayer(targetRenderer);
            targetTextureLayer.MakeParent(clearLayerBuffer);

            effectAssetMesh = factory.CreateEffect("Position.DirectX9.obj.fx");
            effectAssetMesh.SetValue("Time", 1);

            ObjMeshAsset objMeshAsset = factory.CreateObjMesh("bigguy_g.obj");
            drawMockNode = factory.CreateDrawMock();
            drawMockNode.SetMesh(objMeshAsset);
            drawmockTransformNodeFirst = factory.CreateTransform();
            drawmockTransformNodeSecond = factory.CreateTransform();
            drawmockTransformNodeFirst.MakeParent(clearTargetBuffer);
            drawmockTransformNodeSecond.MakeParent(drawmockTransformNodeFirst);
            drawMockNode.MakeParent(drawmockTransformNodeSecond);

            ///////////////////////////////////////////////

            cudaRenderer = factory.CreateCudaRaytraceRenderAsset();
            TextureLayerNode cudaTextureLayer = factory.CreateTextureLayer(cudaRenderer);
            cudaRenderer.SetRoot(drawMockNode);
            cudaTextureLayer.MakeParent(clearLayerBuffer);
            cudaRenderer.SetTextureTarget(4, factory.CreateTextureAsset(targetRenderer));

            ////////////////////////////////////

            effectAssetLayer = factory.CreateEffect("TextureLayerWpf.DirectX9.fx");

            // set the back buffer using the new scene pointer
            sceneIntPtr = (IntPtr)wpfRenderer.GetDirect3D9Surface(0);
            d3DImage.Lock();
            d3DImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, sceneIntPtr);
            d3DImage.Unlock();

            // leverage the Rendering event of WPF's composition target to
            // update the custom D3D scene
            CompositionTarget.Rendering += OnRendering;
        }