/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } // Check if drag sth Vector3 hitLocation = ViewPosition; SceneGraphNode hit = null; if (_dragHandlers.HasValidDrag()) { // Get mouse ray and try to hit any object var ray = ConvertMouseToRay(ref location); hit = _window.Graph.Root.RayCast(ref ray, out var closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders); if (hit != null) { // Use hit location hitLocation = ray.Position + ray.Direction * closest; } else { // Use area in front of the viewport hitLocation = ViewPosition + ViewDirection * 100; } } // Drag assets if (_dragAssets.HasValidDrag) { result = _dragAssets.Effect; // Process items for (int i = 0; i < _dragAssets.Objects.Count; i++) { var item = _dragAssets.Objects[i]; Spawn(item, hit, ref hitLocation); } } // Drag actor type else if (_dragActorType.HasValidDrag) { result = _dragActorType.Effect; // Process items for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; Spawn(item, hit, ref hitLocation); } } return(result); }
/// <summary> /// Deselects given object. /// </summary> public void Deselect(SceneGraphNode node) { if (!Selection.Contains(node)) return; var before = Selection.ToArray(); Selection.Remove(node); SelectionChange(before); }
public Island(Level level, SceneGraphNode node) { Level = level; Inventory = new Inventory(); Node = node; var ent = level.CreateEntityNode(node.CreateChild()); entity = ent; SpaceAllocator = new IslandSpaceAllocator(); }
public MeshAddon(IMesh mesh, Level level, SceneGraphNode node) { this.mesh = mesh; this.level = level; Node = node; Node.AssociatedObject = this; var ent = level.CreateEntityNode(node); ent.Mesh = mesh; }
public static List <SceneGraphNode> QueryBFS(SceneGraphNode root, Predicate <SceneGraphNode> compareFunct) { List <SceneGraphNode> result; SceneGraph sg; sg = new SceneGraph(root); result = sg.Query(compareFunct, GraphQueryTraversalType.BredthFirst); return(result); }
public static ScriptingEngine CreateFromDocument(SceneGraphNode document) { ScriptingEngine engine; engine = new ScriptingEngine(); engine.StartV8(document); CurrentContext = engine; return(engine); }
public Tower(Level level, SceneGraphNode node) { this.level = level; Node = node; node.AssociatedObject = this; var ent = level.CreateEntityNode(node); ent.Mesh = TW.Assets.LoadMesh("Scattered\\Models\\Tower"); level.AddBehaviour(Node, stepBehaviour()); }
public TextPanelNode CreateTextPanelNode(SceneGraphNode node) { var ret = new TextPanelNode(this, node); TextPanelNodes.Add(ret); node.ObserveDestroy(() => { TextPanelNodes.Remove(ret); ret.Dispose(); }); return(ret); }
private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector3 hitLocation) { var actor = item.CreateInstance() as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); return; } actor.Name = item.Name; Spawn(actor, ref hitLocation); }
private void Spawn(Type item, SceneGraphNode hit, ref Vector3 hitLocation) { var actor = FlaxEngine.Object.New(item) as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.FullName); return; } actor.Name = item.Name; actor.Position = PostProcessSpawnedActorLocation(actor, ref hitLocation); Spawn(actor); }
/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { ClearDragEffects(); var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } // Check if drag sth Vector3 hitLocation = ViewPosition; SceneGraphNode hit = null; if (DragHandlers.HasValidDrag()) { GetHitLocation(ref location, out hit, out hitLocation); } // Drag assets if (_dragAssets.HasValidDrag) { result = _dragAssets.Effect; // Process items for (int i = 0; i < _dragAssets.Objects.Count; i++) { var item = _dragAssets.Objects[i]; Spawn(item, hit, ref hitLocation); } } // Drag actor type else if (_dragActorType.HasValidDrag) { result = _dragActorType.Effect; // Process items for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; Spawn(item, hit, ref hitLocation); } } DragHandlers.OnDragDrop(new DragDropEventArgs() { Hit = hit, HitLocation = hitLocation }); return(result); }
public ResourceGenerator(Level level, SceneGraphNode node, ItemType type) { this.level = level; this.type = type; Node = node; node.AssociatedObject = this; level.CreateEntityNode(node.CreateChild()) .Alter(k => k.Mesh = TW.Assets.LoadMesh("Scattered\\Models\\Infuser")) .Alter(k => k.CreateInteractable(onInteract)); containsResourcesSince = TW.Graphics.TotalRunTime; }
public void DestroyNode(SceneGraphNode node) { if (node.Children == null) { return; // already disposed } foreach (var c in node.Children.ToArray()) { DestroyNode(c); } node.Dispose(); }
private static void leave(SceneGraphNode node, RenderingContext rc) { #if DEBUG_SCENE_GRAPH_RENDERING #if DEBUG_SCENE_GRAPH_RENDERING_VERBOSE //Console.WriteLine("~"+node.ToString()); #else Console.WriteLine("".PadLeft(node.Depth, '\t') + "</" + node.GetNodeName() + ">"); #endif #endif if (!node.Hidden) { node.PostRender(rc); } }
public JumpPadLocator(Level level, SceneGraphNode node, Matrix extratransform, JumpPad parentPad, JumpPad targetPad, bool isCurrentlySelected) { this.level = level; this.parentPad = parentPad; this.targetPad = targetPad; var mesh = isCurrentlySelected ? TW.Assets.LoadMesh("Scattered\\Models\\JumpPadLocatorSelected") : TW.Assets.LoadMesh("Scattered\\Models\\JumpPadLocator"); renderNode = node.CreateChild(); renderNode.Relative = extratransform; level.CreateEntityNode(renderNode).Alter(c => c.Mesh = mesh) .Alter(c => c.CreateInteractable(onInteract)); }
/// <summary> /// TODO: fix for better DI /// </summary> /// <param name="sceneGraphNode"></param> /// <returns></returns> public EntityNode CreateEntityNode(SceneGraphNode node) { var ret = new EntityNode(this, node, worldOctree); EntityNodes.Add(ret); worldOctree.AddWorldObject(ret); node.ObserveDestroy(() => { EntityNodes.Remove(ret); worldOctree.RemoveWorldObject(ret); ret.Dispose(); }); return(ret); }
private MyNode GetNode(SceneGraphNode root, string name) { if (root.Name == name) { return(root as MyNode); } for (int i = 0; i < root.ChildNodes.Count; i++) { var node = GetNode(root.ChildNodes[i], name); if (node != null) { return(node); } } return(null); }
public JumpPad(Level level, SceneGraphNode node) { this.level = level; Node = node; node.AssociatedObject = this; var mesh = TW.Assets.LoadMesh("Scattered\\Models\\JumpPad"); var renderNode = node.CreateChild(); level.CreateEntityNode(renderNode).Alter(c => c.Mesh = mesh) .Alter(c => c.CreateInteractable(onInteract)); landingNode = node.CreateChild(); landingNode.Relative = Matrix.Translation(new Vector3(0, 2f, 5f)); level.AddBehaviour(node, update); }
public Bullet(IObjectHandle handle, SceneGraphNode node, Vector3 position, Vector3 direction, float speed, float lifetime) { Node = node; node.Absolute = Matrix.Translation(position); Position = position; this.handle = handle; this.direction = direction; this.direction.Normalize(); this.speed = speed; this.lifetime = lifetime; var ent = handle.CreateEntityNode(node.CreateChild()); ent.Mesh = TW.Assets.LoadMesh("Scattered\\Models\\Bullet"); ent.Node.Relative = Matrix.Scaling(2, 2, 2); handle.AddBehaviour(node, Update); }
/// <summary> /// Selects the specified object. /// </summary> /// <param name="selection">The selection.</param> /// <param name="additive">if set to <c>true</c> will use additive mode, otherwise will clear previous selection.</param> public void Select(SceneGraphNode selection, bool additive = false) { if (selection == null) throw new ArgumentNullException(); // Check if won't change if (!additive && Selection.Count == 1 && Selection[0] == selection) return; if (additive && Selection.Contains(selection)) return; var before = Selection.ToArray(); if (!additive) Selection.Clear(); Selection.Add(selection); SelectionChange(before); }
private static bool HasBackEdge(SceneGraphNode node, Stack <SceneGraphNode> work_items) { //This method takes up too much time without my FastStack if (node.Parents == null || node.Parents.Count == 0) { return(false); } /* If the node's parent(s) are still in the work items * (then we can infer that this node has a back edge to one of its parents) */ foreach (SceneGraphNode parent in node.Parents) { if (work_items.Any(n => n._id == parent._id)) { return(true); } } return(false); }
public IEnumerable <T> FindInRange <T>(SceneGraphNode node, int range, Func <T, bool> wherePredicate) where T : class, IHasNode { if (typeof(IIslandAddon).IsAssignableFrom(typeof(T))) { // Search the addons return(Islands.SelectMany(i => i.Addons).OfType <T>() .Where(r => Vector3.Distance(node.Position, r.Node.Position) < range)); } if (typeof(ScatteredPlayer).IsAssignableFrom(typeof(T))) { // Search players (eg player) if (Vector3.Distance(node.Position, LocalPlayer.Position) < range) { return new[] { LocalPlayer as T } } ; return(new T[0]); } throw new NotImplementedException(); }
/// <summary> /// Removes nodes classed as invalid from the Scene Graph /// </summary> private static void pruneBadRelationships(SceneGraphNode parent, List <SceneGraphNode> invalidNodes) { for (int i = 0; i < invalidNodes.Count(); i++) { SceneGraphNode invalidNode = invalidNodes[i]; //if(invalidNode.isValid.HasValue && invalidNode.isValid.Value == false) { parent.Children.Remove(invalidNode); } } if (debug) { Console.Write("pruned bad relationships "); } if (debug) { Console.WriteLine(parent.ErrorStringWithLineNumbers()); } }
private void ProcessSceneNodes(Regex nameRegex, Regex typeRegex, SceneGraphNode root, List <SearchResult> matches) { root.ChildNodes.ForEach(node => { var type = node.GetType(); if (typeRegex.Match(type.Name).Success&& nameRegex.Match(node.Name).Success) { string finalName = type.Name; if (Aliases.TryGetValue(finalName, out var alias)) { finalName = alias; } matches.Add(new SearchResult { Name = node.Name, Type = finalName, Item = node }); } if (node.ChildNodes.Count != 0) { node.ChildNodes.ForEach(n => { ProcessSceneNodes(nameRegex, typeRegex, n, matches); }); } }); }
public FlightEngine(Level level, SceneGraphNode node, ItemType coalType) { this.level = level; this.coalType = coalType; Node = node; node.AssociatedObject = this; var renderNode = node.CreateChild(); level.CreateEntityNode(renderNode.CreateChild()) .Alter(e => e.Node.Relative = Matrix.RotationY(-MathHelper.PiOver2) * Matrix.Translation(new Vector3(1.5f, 0, 0))) .Alter(ent => ent.Mesh = TW.Assets.LoadMesh("Scattered\\Models\\PropellorEngine")) .Alter(e => e.CreateInteractable(onInteract)); level.CreateEntityNode(renderNode.CreateChild()) .Alter(e => e.Node.Relative = Matrix.RotationY(-MathHelper.PiOver2) * Matrix.Translation(new Vector3(-1.5f, 0, 0))) .Alter(ent => ent.Mesh = TW.Assets.LoadMesh("Scattered\\Models\\PropellorEngine")) .Alter(e => e.CreateInteractable(onInteract)); level.AddBehaviour(node, update); }
private void GetHitLocation(ref Vector2 location, out SceneGraphNode hit, out Vector3 hitLocation) { // Get mouse ray and try to hit any object var ray = ConvertMouseToRay(ref location); var gridPlane = new Plane(Vector3.Zero, Vector3.Up); hit = Editor.Instance.Scene.Root.RayCast(ref ray, out var closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders); if (hit != null) { // Use hit location hitLocation = ray.Position + ray.Direction * closest; } else if (Grid.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f) { // Use grid location hitLocation = ray.Position + ray.Direction * closest; } else { // Use area in front of the viewport hitLocation = ViewPosition + ViewDirection * 100; } }
public Resource(Level level, SceneGraphNode node, ItemType type) { this.level = level; this.Type = type; Node = node; node.AssociatedObject = this; var renderNode = node.CreateChild(); entityNode = level.CreateEntityNode(renderNode.CreateChild()) .Alter(k => k.Node.Relative = Matrix.Identity) .Alter(k => k.CreateInteractable(onInteract)); panelNode = level.CreateTextPanelNode(renderNode.CreateChild()); panelNode.Node.Relative = Matrix.Translation(0, 2.5f, 0); panelNode.TextRectangle.IsBillboard = true; panelNode.TextRectangle.Radius = 0.35f; Amount = 1; level.AddBehaviour(node, AttemptMerge); }
/// <summary> /// Validate relationships in scene at runtime and make adjustments instantly as necessary. /// </summary> /// <returns> /// True, if the types of children of the current node are allowable under this type of SceneGraphNode /// Otherwise false, if there were any children found that arent valid relationships. /// </returns> public static bool Validate(SceneGraphNode node) { bool passed = true; bool warned0 = false; bool warned1 = false; node.hasValid = null; // X3D VALIDATION // Test Appearance Component appearanceValidationConstraints(node, out passed, out warned0); // Test Shader Component shaderValidationConstraints(node, out passed, out warned1); //TODO: test other X3D node relationships node.hasValid = passed; node.alreadyWarned = warned0 || warned1; return(passed); }
private void StartV8(SceneGraphNode root) { // ensure v8.net dependencies are fine for instantiation of V8Engine deps(); v8 = new V8Engine(); v8.RegisterType(typeof(X3DConsole), null, true, ScriptMemberSecurity.Locked); // Scene Access Interface // See: http://www.web3d.org/documents/specifications/19775-2/V3.3/Part02/servRef.html HookTypeSystem(); v8.GlobalObject.SetProperty("console", X3DConsole.Current); v8.GlobalObject.SetProperty("document", root); v8.DynamicGlobalObject.window = v8.CreateFunctionTemplate("window").GetFunctionObject <WindowFunction>(); v8.DynamicGlobalObject.browser = v8.CreateFunctionTemplate("browser").GetFunctionObject <BrowserFunction>(); MapKeyValues(); Console.WriteLine("X3D Scripting [enabled]"); }
private static void SelectActorsUsingAsset(Guid assetId, SceneGraphNode node, List <SceneGraphNode> selection, Dictionary <Guid, bool> scannedAssets) { if (node is ActorNode actorNode && actorNode.Actor) { // To detect if this actor uses the given asset simply serialize it to json and check used asset ids // TODO: check scripts too var json = actorNode.Actor.ToJson(); JsonAssetBase.GetReferences(json, out var ids); for (var i = 0; i < ids.Length; i++) { if (SelectActorsUsingAsset(assetId, ref ids[i], scannedAssets)) { selection.Add(actorNode); break; } } } // Recursive check for children for (int i = 0; i < node.ChildNodes.Count; i++) { SelectActorsUsingAsset(assetId, node.ChildNodes[i], selection, scannedAssets); } }