Skip to content

Commit

Permalink
Floor Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanmodha committed Sep 2, 2017
1 parent 127e2be commit efe8e9c
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 134 deletions.
22 changes: 16 additions & 6 deletions src/public/component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let c = 0;

let cinj = "";

let RenderedFloor = 1;

function Main()
{
graph = new Graph();
Expand All @@ -50,6 +52,7 @@ function Main()
window.addEventListener("_event_modal_element_delete_", _event_modal_onElementDelete);
window.addEventListener("_event_modal_bindtonode_", _event_modal_onBindToNode);
window.addEventListener("_event_onInjectChange", _event_onInjectChange);
window.addEventListener("_event_onSignalFloorChange", _event_onSignalFloorChange);
RC2.addEventListener("mousedown", _event_onMouseDown);
RC2.addEventListener("touchstart", _event_onTouchDown);
RC2.addEventListener("mouseup", _event_onMouseUp);
Expand Down Expand Up @@ -77,7 +80,7 @@ function EnableCodeInjection()
}
function UpdateURL()
{
let url = "?@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + ((RenderedFloor / 2) + 1);
let url = "?@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + RenderedFloor;
//url += "&graph=" + JSON.stringify(graph.ToJson());

window.dispatchEvent(new CustomEvent("_event_onURLChange", {
Expand Down Expand Up @@ -113,20 +116,20 @@ function ParseURL()
{
tmp_location = new Vertex(parseFloat(param[0]), parseFloat(param[1]), parseFloat(param[2].substring(0, param[2].indexOf("z"))));
tmp_rotation = new Vertex(0, 0, 0);
RenderedFloor = (parseInt(param[2].substring(param[2].indexOf("z") + 1)) - 1) * 2;
RenderedFloor = (parseInt(param[2].substring(param[2].indexOf("z") + 1)));
}
else
{
tmp_location = new Vertex(0, 0, 5);
tmp_rotation = new Vertex(0, 0, 0);
RenderedFloor = 0;
RenderedFloor = 1;
}
}
else
{
tmp_location = new Vertex(0, 0, 5);
tmp_rotation = new Vertex(0, 0, 0);
RenderedFloor = 0;
RenderedFloor = 1;
}
let url_search = new URL(url);
json = url_search.searchParams.get("graph");
Expand Down Expand Up @@ -377,7 +380,7 @@ function _event_onNavigationSelect(event)
{
console.log(window.location);
let url = window.location.origin;
url += "/bench/?@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + ((RenderedFloor / 2) + 1);
url += "/bench/?@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + RenderedFloor;
url += "&graph=" + JSON.stringify(graph.ToJson());
window.dispatchEvent(new CustomEvent("_event_onSignalURL", { detail: { url: url } }));
}
Expand All @@ -395,7 +398,7 @@ function _event_onNavigationSelect(event)
}
else if (navigation === "_navigation_view_floors")
{
window.dispatchEvent(new CustomEvent("_event_onSignalFloors", { detail: { floor: RenderedFloor } }));
window.dispatchEvent(new CustomEvent("_event_onSignalFloors", { detail: { floor: RenderedFloor, floors: graph.Floors } }));
}
}
function _event_onMouseDown(event)
Expand Down Expand Up @@ -576,6 +579,13 @@ function _event_onInjectChange(event)
{
cinj = event.detail.cinj;
}
function _event_onSignalFloorChange(event)
{
console.log(event.detail.floor);
RenderedFloor = parseFloat(event.detail.floor);
graph.RenderedFloor = parseFloat(event.detail.floor);
UpdateURL();
}
function MainLoop()
{
requestAnimFrame(MainLoop);
Expand Down
172 changes: 102 additions & 70 deletions src/public/component/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ let Graph = class Graph
{
this.Nodes = [];
this.Elements = [];
this.RenderedFloor = 1;
this.Floors = [
["Default", -100, 100]
];
}
CreateNode(_location)
{
Expand Down Expand Up @@ -90,103 +94,131 @@ let Graph = class Graph
}
this.SelectedPath.unshift(n);
}
NodeInFloor(n)
{
if (this.RenderedFloor - 1 >= this.Floors.length)
{
return false;
}
if (this.RenderedFloor < 1)
{
return false;
}
if ((n.Location.Z > this.Floors[this.RenderedFloor - 1][1]) && (n.Location.Z < this.Floors[this.RenderedFloor - 1][2]))
{
return true;
}
else
{
return false;
}
}
Render(ME, z_rotation)
{
for (let i = 0; i < this.Elements.length; i++)
{
if (this.Elements[i].Node != null)
{
this.Elements[i].Render(ME);
if (this.Elements[i].Node != null && this.NodeInFloor(this.Elements[i].Node))
{
this.Elements[i].Render(ME);
}
}
}
for (let i = 0; i < this.Nodes.length; i++)
{
let p = ME.ProjectVertex(this.Nodes[i].Location, z_rotation);
let selected = false;
if (this.SelectedPath)
if (this.NodeInFloor(this.Nodes[i]))
{
for (let j = 0; j < this.SelectedPath.length; j++)
let p = ME.ProjectVertex(this.Nodes[i].Location, z_rotation);
let selected = false;
if (this.SelectedPath)
{
if (this.SelectedPath[j] == this.Nodes[i])
for (let j = 0; j < this.SelectedPath.length; j++)
{
selected = true;
if (this.SelectedPath[j] == this.Nodes[i])
{
selected = true;
}
}
}
}
for (let j = 0; j < this.Nodes[i].Neighbors.length; j++)
{
ME.Device2D.beginPath();
ME.Device2D.moveTo(p.X, p.Y);
let p1 = ME.ProjectVertex(this.Nodes[i].Neighbors[j].EndNode.Location, z_rotation);
ME.Device2D.lineTo(p1.X, p1.Y);
if (selected && this.NodeInList(this.Nodes[i].Neighbors[j].EndNode, this.SelectedPath))
for (let j = 0; j < this.Nodes[i].Neighbors.length; j++)
{
ME.Device2D.strokeStyle = '#4682B4';
ME.Device2D.beginPath();
ME.Device2D.moveTo(p.X, p.Y);
let p1 = ME.ProjectVertex(this.Nodes[i].Neighbors[j].EndNode.Location, z_rotation);
ME.Device2D.lineTo(p1.X, p1.Y);
if (selected && this.NodeInList(this.Nodes[i].Neighbors[j].EndNode, this.SelectedPath))
{
ME.Device2D.strokeStyle = '#4682B4';
}
ME.Device2D.stroke();
ME.Device2D.strokeStyle = '#000000';
}
ME.Device2D.stroke();
ME.Device2D.strokeStyle = '#000000';
}
}
}
for (let i = 0; i < this.Nodes.length; i++)
{
ME.Device2D.beginPath();
let p = ME.ProjectVertex(this.Nodes[i].Location, z_rotation);
this.Nodes[i].ProjectedLocation = new Vertex(p.X, p.Y, p.Z);
ME.Device2D.arc(p.X, p.Y, 5, 0, Math.PI * 2, true);
let selected = false;
let style = "#000000";
if (this.SelectedPath)
if (this.NodeInFloor(this.Nodes[i]))
{
for (let j = 0; j < this.SelectedPath.length; j++)
ME.Device2D.beginPath();
let p = ME.ProjectVertex(this.Nodes[i].Location, z_rotation);
this.Nodes[i].ProjectedLocation = new Vertex(p.X, p.Y, p.Z);
ME.Device2D.arc(p.X, p.Y, 5, 0, Math.PI * 2, true);
let selected = false;
let style = "#000000";
if (this.SelectedPath)
{
if (this.SelectedPath[j] == this.Nodes[i])
for (let j = 0; j < this.SelectedPath.length; j++)
{
selected = true;
if (j == 0)
if (this.SelectedPath[j] == this.Nodes[i])
{
style = '#9ACD32';
selected = true;
if (j == 0)
{
style = '#9ACD32';
}
else if (j == this.SelectedPath.length - 1)
{
style = '#B22222';
}
else
{
style = '#4682B4';
}
break;
}
else if (j == this.SelectedPath.length - 1)
{
style = '#B22222';
}
else
{
style = '#4682B4';
}
break;
}
}
}
let sel = false;
if (this.Nodes[i].Selected == true)
{
sel = true;
style = '#FFA500';
}
else if (this.Nodes[i].Hovered == true)
{
sel = true;
style = '#C8A500';
}
if (sel || selected)
{
ME.Device2D.fillStyle = style;
ME.Device2D.fill();
}
else
{
ME.Device2D.strokeStyle = style;
ME.Device2D.stroke();
}
ME.Device2D.textAlign = "center";
let x = new Number(this.Nodes[i].Location.X).toFixed(1);
let y = new Number(this.Nodes[i].Location.Y).toFixed(1);
let z = new Number(this.Nodes[i].Location.Z).toFixed(1);
this.Nodes[i].Location = new Vertex(parseFloat(x), parseFloat(y), parseFloat(z));
ME.Device2D.fillText("'" + this.Nodes[i].Name + "' = (" + x + ", " + y + ", " + z + ")", p.X, p.Y + 20);
ME.Device2D.fillStyle = '#000000';
ME.Device2D.strokeStyle = '#000000';
let sel = false;
if (this.Nodes[i].Selected == true)
{
sel = true;
style = '#FFA500';
}
else if (this.Nodes[i].Hovered == true)
{
sel = true;
style = '#C8A500';
}
if (sel || selected)
{
ME.Device2D.fillStyle = style;
ME.Device2D.fill();
}
else
{
ME.Device2D.strokeStyle = style;
ME.Device2D.stroke();
}
ME.Device2D.textAlign = "center";
let x = new Number(this.Nodes[i].Location.X).toFixed(1);
let y = new Number(this.Nodes[i].Location.Y).toFixed(1);
let z = new Number(this.Nodes[i].Location.Z).toFixed(1);
this.Nodes[i].Location = new Vertex(parseFloat(x), parseFloat(y), parseFloat(z));
ME.Device2D.fillText("'" + this.Nodes[i].Name + "' = (" + x + ", " + y + ", " + z + ")", p.X, p.Y + 20);
ME.Device2D.fillStyle = '#000000';
ME.Device2D.strokeStyle = '#000000';
}
}
}
ToJson()
Expand Down
Loading

0 comments on commit efe8e9c

Please sign in to comment.