private static void RenderNodeEqual(RenderNode left, RenderNode right) { Assert.Equal(left.Task, right.Task); Assert.Equal(left.Position, right.Position); Assert.Equal(left.Dimensions, right.Dimensions); Assert.Equal(left.Elements, right.Elements); }
private async Task DrawNode(RenderNode node) { await _context.StrokeRectAsync(node.Position.X, node.Position.Y, node.Dimensions.Width, node.Dimensions.Height); await DrawNodeComponents(node); }
public MeshElem(RenderNode n) { //Name = n.CurrentObject.name; this.Name = string.Format("{0}_{1}", n.CurrentObject.name, Type); // shadow : cast + receive }
public void SetPositionAndSize(Vector2Int pos, Vector2Int size) { Collider = new RectInt(pos, size); RenderNode.SetPosition(pos); RenderNode.SetSize(size); Image.Node.SetSize(size); }
protected void CreateBoardModels(ContentPackage package) { MeshGroup group = package.LoadMeshGroup(BoardMeshSource); int texture = package.LoadTexture(BoardTextureSource); DiffuseMaterial material = new DiffuseMaterial(texture, BoardMaterialName); material.Load(package); RenderScene.AddMaterial(material); Model pawn = new Model() { Name = BoardModelName, Material = material, MeshGroup = group }; RenderScene.AddModel(pawn); RenderNode node = new RenderNode() { Model = pawn, Transform = Matrix4.Identity }; RenderScene.AddRenderNode(node); }
MeshElem RegisterToThreeScene(RenderNode n) { var hasLightmap = (n.Value.lightmapIndex >= 0); var geoKey = n.Mesh.InstanceId; var mtlKey = n.Material.InstanceId; if (hasLightmap) { geoKey = ConvertKeyForBufferGeometryElem(n.Value); mtlKey = ConvertKeyForMaterialELem(n.Value); } var geometryNode = root.SharedNodeTable.Get <AbstractGeometryElem>(geoKey); var materialNode = root.SharedNodeTable.Get <MaterialElem>(mtlKey); Debug.Assert(geometryNode != null); Debug.Assert(materialNode != null); var meshNode = new MeshElem(n) { Geometry = geometryNode, Material = materialNode, }; var parent = objNodeTable[n.CurrentObject.GetInstanceID().ToString()]; parent.AddChild(meshNode); return(meshNode); }
//2.在摄像机开始渲染场景之前调用,按照渲染的优先顺序调用(unity 先调用depth小的相机) public void OnPreRender(RenderNode node) { Camera cam = node.camera; if (!renderStart) { //第一个渲染,添加所有的相机,移除渲染开始时不激活的相机 //渲染开始后,有新的相机激活,不会触发渲染 //渲染开始后,有相机关闭,这个相机这帧不会渲染 //frameCameras在开始的时候,记录所有这一帧要发生渲染的相机,每个相机渲染完后,移除这个相机 //并且删掉不激活的相机,如果frameCamears空,则说明是最后一个相机,blit到屏幕 renderStart = true; FrameNodes.Clear(); FrameNodes.AddRange(AllNodes); FrameNodes.RemoveAll(NotValidCamera); cam.clearFlags = CameraClearFlags.Skybox; PrepareRT(); } else { //不清理 cam.clearFlags = CameraClearFlags.Nothing; } }
public Text(GBXMLContainer initData, RenderNode parent) : base(initData, parent) { text = InitData["Text"].Text; font = ProcessManager.ActiveProcess.rManager.GetOrCreateFont(InitData["Font"].Text); autoText = bool.Parse(InitData["AutoText","true"].Text); }
//3.在摄像机完成场景渲染之后调用 public void OnPostRender(RenderNode node) { FrameNodes.Remove(node); FrameNodes.RemoveAll(NotValidCamera); if (FrameNodes.Count == 0) { //后续没有相机了,渲染到屏幕 if (true) { //处理后效 Graphics.Blit(sceneCameraRt, null as RenderTexture); } else { // Graphics.Blit(sceneCameraRt, null as RenderTexture); } //每帧用rt,记得释放 防止内存泄漏 RenderTexture.ReleaseTemporary(sceneCameraRt); sceneCameraRt = null; //处理渲染完成之后的逻辑,回调可以在这个后面加 } }
public async Task Render() { await Prepare(); RenderNode node = manager.GetNodeByName(THIS_NAME); long lastFileChange = new FileInfo(BLEND_FILE).LastWriteTime.Ticks; SyncResponse respSync = null; using (FileStream stream = new FileStream(BLEND_FILE, FileMode.Open)) respSync = await node.SyncFile(SESSION, lastFileChange, stream, Compression.Raw); Assert.IsTrue(respSync.Success); RenderResponse respRender = await node.Render(new RenderRequest() { FileID = lastFileChange, SessionID = SESSION, TaskID = "Whatever", Version = BLEND_VERSION, Settings = new Shared.RenderPacketModel() { Width = 640, Height = 360, Samples = 8 } }); Assert.IsTrue(respRender.Success); File.WriteAllBytes($"{RESULTS_DIRECTORY}/Test.Render.png", respRender.Data); Assert.IsTrue(respRender.Data != null && respRender.Data.Length > 0); //Check equality }
public async Task SyncCompressed() { await BasicConnect(); RenderNode node = manager.GetNodeByName(THIS_NAME); long lastFileChange = new FileInfo(BLEND_FILE).LastWriteTime.Ticks; SyncResponse resp = null; using (MemoryStream str = new MemoryStream()) using (GZipStream zip = new GZipStream(str, CompressionMode.Compress)) using (FileStream stream = new FileStream(BLEND_FILE, FileMode.Open)) { byte[] buffer = new byte[4096]; int read = 0; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { zip.Write(buffer, 0, read); } str.Seek(0, SeekOrigin.Begin); resp = await node.SyncFile(SESSION, lastFileChange, str, Compression.GZip); } Assert.IsTrue(resp.Success); }
private async Task DrawNodeComponents(RenderNode node) { var index = 0; RenderElement NextElement() => node.Elements[index++]; await DrawElement(NextElement(), node.Task.Content.Title ?? "?", _config.TitleFont); await DrawElement(NextElement(), node.Task.Content.Description ?? "?", _config.DescriptionFont); if (node.Task.Participants.Author is { } author) { await DrawRect(NextElement(), "green"); await DrawElement(NextElement(), author, _config.ComponentFont); } if (node.Task.ExecutionTime is { } time) { await DrawRect(NextElement(), "blue"); var estimated = time.EstimatedTime?.ToShortString() ?? "?"; var spent = time.TimeSpent?.ToShortString() ?? "?"; await DrawElement(NextElement(), $"Time: {estimated} / {spent}", _config.ComponentFont); } if (node.Task.Deadlines is { } deadlines) { await DrawRect(NextElement(), "red"); var hd = deadlines.HardDeadline?.ToString() ?? "?"; var sd = deadlines.SoftDeadline.ToString() ?? "?"; await DrawElement(NextElement(), $"Deadlines: {sd} : {hd}", _config.ComponentFont); } if (node.Task.Iterations is { } iterations) { await DrawRect(NextElement(), "yellow"); var perIteration = iterations.TimePerIteration?.ToShortString() ?? "?"; await DrawElement(NextElement(), $"Iterations: {iterations.Executed} / {iterations.Required} x{perIteration}", _config.ComponentFont); } if (node.Task.Metrics is { } metrics) { await DrawRect(NextElement(), "purple"); await DrawElement(NextElement(), $"Metrics: C={metrics.Complexity}, I={metrics.Importance}", _config.ComponentFont); } if (node.Task.References.Count > 0) { await DrawRect(NextElement(), "grey"); await DrawElement(NextElement(), $"References: {node.Task.References.Count}", _config.ComponentFont); } }
public static async Task Show(Window owner, RenderNode node) { var window = new DeviceSettingsWindow(node); window.Position = new PixelPoint((int)(owner.Position.X + ((owner.Width / 2) - window.Width / 2)), (int)(owner.Position.Y + ((owner.Height / 2) - window.Height / 2))); await window.ShowDialog(owner); }
public override void Process(RenderNodeReference renderNodeReference, ref RenderNode renderNode, RenderObject renderObject, PipelineStateDescription pipelineState) { if (renderNode.RenderStage == RenderStage) { pipelineState.BlendState = BlendStates.AlphaBlend; pipelineState.DepthStencilState = DepthStencilStates.DepthRead; } }
public override void Process(RenderNodeReference renderNodeReference, ref RenderNode renderNode, RenderObject renderObject, PipelineStateDescription pipelineState) { if (renderNode.RenderStage == RenderStage) { pipelineState.BlendState = BlendStates.NonPremultiplied; pipelineState.DepthStencilState = DepthStencilStates.DepthRead; pipelineState.RasterizerState.MultisampleAntiAliasLine = true; } }
public void SelectBranch(int branchIndex) { RenderNode renderNode = currentNode as RenderNode; if (renderNode != null) { currentNode = renderNode.GetConnectedNode(branchIndex); } currentNode.Execute(); }
public async Task Prepare() { await BasicConnect(); RenderNode node = manager.GetNodeByName(THIS_NAME); PrepareResponse resp = await node.PrepareVersion(BLEND_VERSION); Assert.IsTrue((await node.PrepareVersion(BLEND_VERSION))?.Success ?? false, resp.Message); Assert.IsTrue(await node.CheckVersion(BLEND_VERSION)); }
public async Task BasicConnect() { manager.AddNode(THIS_NAME, THIS_ADDRESS); RenderNode node = await manager.Connect(THIS_NAME); string hostname = Environment.MachineName; Assert.AreEqual(hostname, node.ComputerName); Assert.AreEqual(Environment.ProcessorCount, node.Cores); }
public void TestSerializeNullException() { IGraphController graphController = new GraphController(null); IStorage storage = null; IVisualNode node = new RenderNode(graphController, 1); Assert.Throws <ArgumentNullException>(() => { node.Serialize(storage); }); }
/// <summary> /// Async executes a batch of subtasks on node /// </summary> private async Task <SubTaskBatchResult> ExecuteSubTasksAsync(RenderNode node, Action <RenderSubTask, RenderBatchResult> onResult, params RenderSubTask[] tasks) { List <RenderRequest> reqs = tasks.Select(x => x.GetRenderRequest()).ToList(); List <RenderBatchResult> results = new List <RenderBatchResult>(); Action <RenderNode, RenderBatchResult> onAnyResult = (bnode, result) => { RenderSubTask task = tasks.FirstOrDefault(x => x.ID == result.TaskID); if (task != null) { lock (results) results.Add(result); onResult(task, result); } }; Stopwatch time = new Stopwatch(); time.Start(); try { node.OnBatchResult += onAnyResult; RenderBatchRequest req = RenderSubTask.GetRenderBatchRequest(ID, tasks); req.Settings.ForEach(x => x.RenderType = node.RenderType); RenderBatchResponse resp = await node.RenderBatch(req); if (resp == null) { return(new SubTaskBatchResult(new Exception("Render fail: (null)"))); } if (resp.Success == false) { return(new SubTaskBatchResult(new Exception("Render fail: " + resp.Message))); } if (req.Settings.Count > 0) { decimal pixelsRendered = req.Settings.Sum(x => (x.Height * (x.Y2 - x.Y)) * (x.Width * (x.X2 - x.X))); node.UpdatePerformance((int)pixelsRendered, (int)time.ElapsedMilliseconds); } } finally { node.OnBatchResult -= onAnyResult; time.Stop(); } return(new SubTaskBatchResult(results.ToArray())); }
public override void update(float time, Graphics g) { if (runnable) { foreach (Node n in lst) { RenderNode rn = (RenderNode)n; if (g != null) { Draw(rn, g); } } } }
/** * Adds/Removes Nodes based on LOD Setting **/ private void CalculateActiveNodes() { if (FileManager.MasteryFile == null) { //clear all nodes RenderNodeLayers.Clear(); ChunkLODStates.Clear(); } else if (ChunkLODStates.Count > 0) { int LayerCount = Settings.LOD.Length; if (LayerCount > RenderNodeLayers.Count) { //add nodes for (int i = 0; i < LayerCount; i++) { bool HasLayer = false; for (int j = 0; j < RenderNodeLayers.Count; j++) { int LayerLOD = Int32.Parse(RenderNodeLayers[j].Name.Replace("Layer:", "")); if (i == LayerLOD) { HasLayer = true; break; } } if (!HasLayer) { Node3D NewNode = new Node3D("Layer:" + i); RenderNode.Attach(NewNode); RenderNodeLayers.Add(NewNode); } } } else if (LayerCount < RenderNodeLayers.Count) { //remove nodes for (int i = 0; i < RenderNodeLayers.Count; i++) { int LayerLOD = Int32.Parse(RenderNodeLayers[i].Name.Replace("Layer:", "")); if (LayerLOD > LayerCount) { RenderNodeLayers.RemoveAt(i); } } } } }
public async Task Sync() { await BasicConnect(); RenderNode node = manager.GetNodeByName(THIS_NAME); long lastFileChange = new FileInfo(BLEND_FILE).LastWriteTime.Ticks; SyncResponse resp = null; using (FileStream stream = new FileStream(BLEND_FILE, FileMode.Open)) resp = await node.SyncFile(SESSION, lastFileChange, stream, Compression.Raw); Assert.IsTrue(resp.Success); }
public DeviceSettingsWindow() { Node = new RenderNode() { Name = "Some Device Name", Activity = "SomeActivity", Cores = 16, ComputerName = "SomeDesktopName", OS = "windows64", RenderType = RenderType.CPU, Address = "192.168.1.123:15000" }; DataContext = this; this.InitializeComponent(); }
public virtual void Initialize(World2D world, RectInt collider) { Collider = collider; World = world; RenderNode = UINode.Engine.Instance.CreateNode(Collider, World.WorldStaticNode, "Static-Node"); var canvas = RenderNode.AddUIComponent <SingleColorCanvas>(); canvas.CanvasPixelColor = new PixelColor(ConsoleColor.Gray, ConsoleColor.Blue); var imageNode = UINode.Engine.Instance.CreateNode(new RectInt(Vector2Int.Zero, Collider.Size), RenderNode, "Wall-Image"); Image = imageNode.AddUIComponent <UnlitBox>(); Image.UnlitCharacter = ' '; }
public void TestDeserilaizeOperationException() { IGraphController graphController = new GraphController(null); IStorage storage = new BinaryStorage(); IVisualNode node = new RenderNode(graphController, 1); ulong signature = Utilities.MakeEightCC('T', 'E', 'S', 'T', ' ', ' ', ' ', ' '); storage.WriteUnsignedInteger(signature, 21); storage.Seek(0, SeekOrigin.Begin); bool result = node.Deserialize(storage); Assert.AreEqual(result, false); }
public virtual void Initialize(World2D world, RectInt collider) { Collider = collider; World = world; RenderNode = UINode.Engine.Instance.CreateNode(Collider, World.PlatformNode, "Platform-Node"); var canvas = RenderNode.AddUIComponent <SingleColorCanvas>(); canvas.CanvasPixelColor = new PixelColor(ConsoleColor.Gray, ConsoleColor.Blue); var imageNode = UINode.Engine.Instance.CreateNode(new RectInt(Vector2Int.Zero, Collider.Size), RenderNode, "Platform-Image"); Image = imageNode.AddUIComponent <Bitmap>(); Image.LoadFromFile(m_ImgFilePath); }
public MasterFileRenderManager(WorldFileManager WorldFileManager, RenderManager RenderManager, CameraManager CameraManager) { Render = RenderManager; FileManager = WorldFileManager; RenderNode = Render.RootNode; Camera = CameraManager; ReflectionNode = new Node3D("WorldReflection"); RefractionNode = new Node3D("WorldRefraction"); PropNode = new Node3D("PropNode"); SkyBox = new SkyBoxModel(Render, 1000, "SkyBox"); RenderNode.Attach(SkyBox.Geom); ReflectionNode.Attach(SkyBox.Geom); }
public void Initialize(World2D world, RectInt collider, bool withSpikeGraphics) { Collider = collider; World = world; RenderNode = UINode.Engine.Instance.CreateNode(Collider, World.WorldStaticNode, "DeathZone-Node"); var canvas = RenderNode.AddUIComponent <SingleColorCanvas>(); canvas.CanvasPixelColor = new PixelColor(ConsoleColor.Black, ConsoleColor.Red); if (withSpikeGraphics) { var imageNode = UINode.Engine.Instance.CreateNode(new RectInt(Vector2Int.Zero, Collider.Size), RenderNode, "DeathZone-Image"); Image = imageNode.AddUIComponent <UnlitBox>(); Image.UnlitCharacter = 'V'; } }
MeshElem RegisterToThreeScene(RenderNode n) { var geometryNode = root.SharedNodeTable.Get <BufferGeometryElem>(n.Mesh.InstanceId); var materialNode = root.SharedNodeTable.Get <MaterialElem>(n.Material.InstanceId); Debug.Assert(geometryNode != null); Debug.Assert(materialNode != null); var meshNode = new MeshElem(n) { Geometry = geometryNode, Material = materialNode, }; var parent = objNodeTable[n.CurrentObject.GetInstanceID()]; parent.AddChild(meshNode); return(meshNode); }
public override void Process(RenderNodeReference renderNodeReference, ref RenderNode renderNode, RenderObject renderObject, PipelineStateDescription pipelineState) { // Disable culling and depth clip if (VoxelRenderStage.Contains(renderNode.RenderStage)) { pipelineState.RasterizerState = new RasterizerStateDescription(CullMode.None) { DepthClipEnable = DepthClipping }; pipelineState.DepthStencilState.DepthBufferEnable = false; pipelineState.DepthStencilState.DepthBufferWriteEnable = false; pipelineState.DepthStencilState.StencilEnable = false; pipelineState.DepthStencilState.StencilWriteMask = 0; pipelineState.DepthStencilState.StencilMask = 0; pipelineState.BlendState.RenderTarget0.BlendEnable = false; pipelineState.BlendState.IndependentBlendEnable = false; } }
public Image(GBXMLContainer initData, RenderNode parent) : base(initData, parent) { string textureName = InitData["Image",string.Empty].Text; size = GBXMLContainer.ReadSizeF(InitData); borderColors[0] = new GBColor(InitData["BorderColors"]["TopLeft"]); borderColors[1] = new GBColor(InitData["BorderColors"]["TopRight"]); borderColors[2] = new GBColor(InitData["BorderColors"]["BottomLeft"]); borderColors[3] = new GBColor(InitData["BorderColors"]["BottomRight"]); if (InitData["BorderColors"].Exists("Top")) { borderColors[0] = new GBColor(InitData["BorderColors"]["Top"]); borderColors[1] = new GBColor(InitData["BorderColors"]["Top"]); } if (InitData["BorderColors"].Exists("Bottom")) { borderColors[2] = new GBColor(InitData["BorderColors"]["Bottom"]); borderColors[3] = new GBColor(InitData["BorderColors"]["Bottom"]); } if (InitData["BorderColors"].Exists("Left")) { borderColors[0] = new GBColor(InitData["BorderColors"]["Left"]); borderColors[2] = new GBColor(InitData["BorderColors"]["Left"]); } if (InitData["BorderColors"].Exists("Right")) { borderColors[1] = new GBColor(InitData["BorderColors"]["Right"]); borderColors[3] = new GBColor(InitData["BorderColors"]["Right"]); } borderColors[0].Multiply(color); borderColors[1].Multiply(color); borderColors[2].Multiply(color); borderColors[3].Multiply(color); if (textureName != string.Empty) textures.Add(ProcessManager.ActiveProcess.rManager.GetOrCreateTexture(textureName)); }
protected override void ProcessPipelineState(RenderContext context, RenderNodeReference renderNodeReference, ref RenderNode renderNode, RenderObject renderObject, PipelineStateDescription pipelineState) { // Bind VAO pipelineState.InputElements = PrimitiveQuad.VertexDeclaration.CreateInputElements(); pipelineState.PrimitiveType = PrimitiveQuad.PrimitiveType; // Don't clip nor write Z value (we are writing at 1.0f = infinity) pipelineState.DepthStencilState = DepthStencilStates.DepthRead; }