diff --git a/.gitignore b/.gitignore index 25ff48a..7ac7b26 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,6 @@ typings/ # andrew's virtual environment andrewsvenv/ + +# secrets secrets are no fun ;) +bricked_experiments/ diff --git a/coordinates/prototype2.py b/coordinates/prototype2.py new file mode 100644 index 0000000..89746e4 --- /dev/null +++ b/coordinates/prototype2.py @@ -0,0 +1,329 @@ +######################### +# Andrew Wang # +# # +######################### + +# Utility +import numpy as np +import math +from collections import deque + +# Graphing +from mpl_toolkits.mplot3d import axes3d +from matplotlib import pyplot as plt +from matplotlib import cm + + +def sample_spherical(npoints, radius, ndim=3): + ''' + source: https://stackoverflow.com/a/33977530 + ''' + vec = np.abs(np.random.randn(ndim, npoints)) + vec /= np.linalg.norm(vec, axis=0) + vec *= radius + return vec + +def draw_lines(coordinates, adj, ax): + # ax.plot([0, 1],[0, 1],[0, 1],color = 'g') + # print(adj) + for v in adj: + for n in adj[v]: + ax.plot([coordinates[v][0],coordinates[n][0]],\ + [coordinates[v][1],coordinates[n][1]],\ + [coordinates[v][2],coordinates[n][2]], color='g') + +def set_axes_equal(ax): + ''' + source: https://stackoverflow.com/a/31364297 + Make axes of 3D plot have equal scale so that spheres appear as spheres, + cubes as cubes, etc.. This is one possible solution to Matplotlib's + ax.set_aspect('equal') and ax.axis('equal') not working for 3D. + + Input + ax: a matplotlib axis, e.g., as output from plt.gca(). + ''' + + x_limits = ax.get_xlim3d() + y_limits = ax.get_ylim3d() + z_limits = ax.get_zlim3d() + + x_range = abs(x_limits[1] - x_limits[0]) + x_middle = np.mean(x_limits) + y_range = abs(y_limits[1] - y_limits[0]) + y_middle = np.mean(y_limits) + z_range = abs(z_limits[1] - z_limits[0]) + z_middle = np.mean(z_limits) + + # The plot bounding box is a sphere in the sense of the infinity + # norm, hence I call half the max range the plot radius. + plot_radius = 0.5*max([x_range, y_range, z_range]) + + ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius]) + ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius]) + ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius]) + +def graph(X, Y, Z, coordinates, adj, rev): + ''' + Visualize coordinates + ''' + + phi = np.linspace(0, np.pi/2, 20) + theta = np.linspace(0, np.pi/2, 40) + x = np.outer(np.sin(theta), np.cos(phi)) + y = np.outer(np.sin(theta), np.sin(phi)) + z = np.outer(np.cos(theta), np.ones_like(phi)) + + + #X, Y, Z = sample_spherical(npoints, radius) + fig = plt.figure() + ax = fig.add_subplot(1,1,1,projection='3d') + #ax = fig.gca(projection='3d') + ax.set_aspect('equal') + ''' + for num in range(len(rev)): # display level + ax.plot_wireframe(x*(num+1), y*(num+1), z*(num+1), color='gray', rstride=1, cstride=1) + #ax.plot_surface(x*(num+1), y*(num+1), z*(num+1),cmap=cm.gray) + ''' + draw_lines(coordinates, adj, ax) + # ax.plot([0, 1],[0, 1],[0, 1],color = 'g') + ax.scatter(X, Y, Z, s=100, c='r', zorder=10) + set_axes_equal(ax) + + +def points(adj, length, nodes, radius): + ''' + takes in: + - adj, the adjacency list, where vertices are represented as ints + - length, number of vertices + - nodes, a list of vertices + generates the points at each level + returns three dictionaries, one for + ''' + + q = deque() + initial = nodes[0] + q.append(initial) + level = [None] * length + level[initial] = radius # initial level must be 1 s.t. radius begins at 1. + combined_X = {} + combined_Y = {} + combined_Z = {} + while len(q)>0: + v = q.popleft() + e = adj[v] + l = level[v] + X, Y, Z = sample_spherical(len(e), l) + + if l not in combined_X: + combined_X[l] = list(X) + else: + combined_X[l].extend(X) + + if l not in combined_Y: + combined_Y[l] = list(Y) + else: + combined_Y[l].extend(Y) + + if l not in combined_Z: + combined_Z[l] = list(Z) + else: + combined_Z[l].extend(Z) + + for neighbor in e: + q.append(neighbor) + level[neighbor] = level[v]+1 + + # print(level) + return combined_X, combined_Y, combined_Z, level + +def reverse_level(level): + index = 0 + level_dic = {} + for l in level: + if l not in level_dic: + level_dic[l] = [index] + else: + level_dic[l].append(index) + index+=1 + return level_dic + +def distance(a, b): + ''' + arguments: a, b are 3-D points + returns: distance between a and b + ''' + return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2) + +def gen_candidates(points, origin, n=-1): + ''' + compute all the minimum distance vertices first before checking if there are duplicates + ''' + + # print(n) + # print(points) + # print(origin) + if n < 0: + return points + x = {} + for point in points: + d = distance(origin, point) + if d not in x: + x[d] = [point] + else: + x[d].append(point) + # print(x) + keys = list(x.keys()) + keys.sort(reverse=True) + # print(keys) + num = 0 + index = 0 + coordinates = [] + while num < n: + #print(num) + num+=len(x[keys[index]]) + coordinates.extend(x[keys[index]]) + index+=1 + return coordinates + +def min_distance(points, origin): + ''' + given node coordinate and candidate neighbor coordinates, returns closest point + ''' + min_d_coord = [] + min_d = 1e32 + for point in points: + d = distance(origin, point) + if d < min_d: + min_d = d + min_d_coord = point + return d, min_d_coord + +def max_distance(points, origin): + ''' + given node coordinate and candidate neighbor coordinates, returns farthest point + ''' + max_d_coord = [] + max_d = 0 + for point in points: + d = distance(origin, point) + if d > max_d: + max_d = d + max_d_coord = point + return max_d, max_d_coord + +def connect(x, y, z, level, adj): + ''' + IDEA: + + - Greedy: + + PSEUDO: + + 1) For each level + 2) order the nodes of the level by max_distance(...) + 3) for each node in the ordered nodes + 4) assign closest point + + NOTES: + + - if two vertices on different levels share the same neighbor, override + the existing level + - level matches node (as index) to its corresponding level + + all along the watchtower, princes kept the view. + + ''' + #print(adj) + rev = reverse_level(level) + coordinates = {0: [0, 0, 0]} + for l in rev.keys(): + + ## PREPROCESSING + + points = [] # candidate coordinates for next level + # print(x[l]) + for num in range(len(x[l])): + point = [x[l][num], y[l][num], z[l][num]] + points.append(point) + # print(point) + + ## DETERMINING ORDER + + # print(points) + ordered = rev[l] # nodes in level l + ''' + for v in ordered: # debugging + print(v) + print(coordinates[v]) + print(max_distance(points, coordinates[v])[0]) + ''' + ordered = sorted(ordered, key=lambda v: max_distance(points,\ + coordinates[v])[0], reverse=True) # list for order + # print(ordered) + + ## ASSIGN POINT + + # print(nodes) + for v in ordered: # for each ordered node + # if v in coordinates: + for neighbor in adj[v]: # for each neighbor to ^node + # print(neighbor, level[neighbor]) + if l+1 == level[neighbor]: # if the level of the neighbor is correct + assignment = min_distance(points, coordinates[v])[1] # min distance assignment + points.remove(assignment) + if neighbor not in coordinates: # neighbor already assigned? (ie shared neighbors) + coordinates[neighbor] = assignment + # print(nodes) + # print(matches) + # print(candidates) + # print(matches) + + + + #print(l) + #print(x[l]) + + # print(coordinates) + return coordinates + +def gen_coordinates(adj, radius=1): + nodes = list(adj.keys()) + X, Y, Z, level = points(adj, len(nodes), nodes, radius) + # print(level) + rev = reverse_level(level) + coordinates = connect(X, Y, Z, level, adj) + return coordinates + +def main(): + adj = { + 0:[1, 2], + 1:[3, 4], + 2:[3, 4], + 3:[5], + 4:[6], + 5:[6], + 6:[] + } + nodes = list(adj.keys()) + X, Y, Z, level = points(adj, len(nodes), nodes, 1) + # print(level) + rev = reverse_level(level) + coordinates = connect(X, Y, Z, level, adj) + + # verification + x = [] + y = [] + z = [] + for level in X.keys(): + x.extend(X[level]) + y.extend(Y[level]) + z.extend(Z[level]) + #print(x) + #print(y) + #print(z) + graph(x, y, z, coordinates, adj, rev) + plt.show() + + +if __name__== "__main__": + main() \ No newline at end of file diff --git a/coordinates/prototype3.py b/coordinates/prototype3.py new file mode 100644 index 0000000..5a5168e --- /dev/null +++ b/coordinates/prototype3.py @@ -0,0 +1,383 @@ +######################### +# Andrew Wang # +# # +######################### + +# Utility +import numpy as np +import math +from collections import deque +import json + +# Graphing +from mpl_toolkits.mplot3d import axes3d +from matplotlib import pyplot as plt + +json_string = None + +def sample_spherical(npoints, radius, ndim=3): + ''' + source: https://stackoverflow.com/a/33977530 + ''' + vec = np.abs(np.random.randn(ndim, npoints)) + vec /= np.linalg.norm(vec, axis=0) + vec *= radius + return vec + +def draw_lines(coordinates, adj, ax): + # ax.plot([0, 1],[0, 1],[0, 1],color = 'g') + # print(adj) + for v in adj: + for n in adj[v]: + ax.plot([coordinates[v][0],coordinates[n][0]],\ + [coordinates[v][1],coordinates[n][1]],\ + [coordinates[v][2],coordinates[n][2]], color='g') + +def set_axes_equal(ax): + ''' + source: https://stackoverflow.com/a/31364297 + Make axes of 3D plot have equal scale so that spheres appear as spheres, + cubes as cubes, etc.. This is one possible solution to Matplotlib's + ax.set_aspect('equal') and ax.axis('equal') not working for 3D. + + Input + ax: a matplotlib axis, e.g., as output from plt.gca(). + ''' + + x_limits = ax.get_xlim3d() + y_limits = ax.get_ylim3d() + z_limits = ax.get_zlim3d() + + x_range = abs(x_limits[1] - x_limits[0]) + x_middle = np.mean(x_limits) + y_range = abs(y_limits[1] - y_limits[0]) + y_middle = np.mean(y_limits) + z_range = abs(z_limits[1] - z_limits[0]) + z_middle = np.mean(z_limits) + + # The plot bounding box is a sphere in the sense of the infinity + # norm, hence I call half the max range the plot radius. + plot_radius = 0.5*max([x_range, y_range, z_range]) + + ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius]) + ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius]) + ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius]) + +def graph(X, Y, Z, coordinates, adj, rev, show_level=False): + ''' + Visualize coordinates + ''' + + phi = np.linspace(0, np.pi/2, 20) + theta = np.linspace(0, np.pi/2, 40) + x = np.outer(np.sin(theta), np.cos(phi)) + y = np.outer(np.sin(theta), np.sin(phi)) + z = np.outer(np.cos(theta), np.ones_like(phi)) + + + #X, Y, Z = sample_spherical(npoints, radius) + fig = plt.figure() + ax = fig.add_subplot(1,1,1,projection='3d') + #ax = fig.gca(projection='3d') + ax.set_aspect('equal') + if show_level: + keys = rev.keys() + radius = min(keys) + for num in range(len(rev)): + ax.plot_wireframe(x*(num+1)*radius, y*(num+1)*radius, z*(num+1)*radius, color='gray', rstride=1, cstride=1) + draw_lines(coordinates, adj, ax) + # ax.plot([0, 1],[0, 1],[0, 1],color = 'g') + ax.scatter(X, Y, Z, s=100, c='r', zorder=10) + set_axes_equal(ax) + + +def points(adj, length, nodes, radius): + ''' + takes in: + - adj, the adjacency list, where vertices are represented as ints + - length, number of vertices + - nodes, a list of vertices + generates the points at each level + returns three dictionaries, one for + ''' + + q = deque() + initial = nodes[0] + q.append(initial) + level = [None] * length + #visited = [False] * length + level[initial] = radius # initial level must be 1 s.t. radius begins at 1. + #visited[initial] = True + combined_X = {} + combined_Y = {} + combined_Z = {} + while len(q)>0: + v = q.popleft() + e = adj[v] + l = level[v] + X, Y, Z = sample_spherical(len(e), l) + + if l not in combined_X: + combined_X[l] = list(X) + else: + combined_X[l].extend(X) + + if l not in combined_Y: + combined_Y[l] = list(Y) + else: + combined_Y[l].extend(Y) + + if l not in combined_Z: + combined_Z[l] = list(Z) + else: + combined_Z[l].extend(Z) + + for neighbor in e: + q.append(neighbor) + level[neighbor] = level[v]+radius + + # Uncomment for level check: + #print(level) + return combined_X, combined_Y, combined_Z, level + +def reverse_level(level): + index = 0 + level_dic = {} + for l in level: + if l not in level_dic: + level_dic[l] = [index] + else: + level_dic[l].append(index) + index+=1 + return level_dic + +def distance(a, b): + ''' + arguments: a, b are 3-D points + returns: distance between a and b + ''' + return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2) + +def gen_candidates(points, origin, n=-1): + ''' + compute all the minimum distance vertices first before checking if there are duplicates + ''' + + #print(n) + #print(points) + #print(origin) + if n < 0: + return points + x = {} + for point in points: + d = distance(origin, point) + if d not in x: + x[d] = [point] + else: + x[d].append(point) + #print(x) + keys = list(x.keys()) + keys.sort(reverse=True) + #print(keys) + num = 0 + index = 0 + coordinates = [] + while num < n: + #print(num) + num+=len(x[keys[index]]) + coordinates.extend(x[keys[index]]) + index+=1 + return coordinates + +def min_distance(points, origin): + ''' + given node coordinate and candidate neighbor coordinates, returns closest point + ''' + min_d_coord = [] + min_d = 1e32 + for point in points: + d = distance(origin, point) + if d < min_d: + min_d = d + min_d_coord = point + return d, min_d_coord + +def max_distance(points, origin): + ''' + given node coordinate and candidate neighbor coordinates, returns farthest point + ''' + max_d_coord = [] + max_d = 0 + for point in points: + d = distance(origin, point) + if d > max_d: + max_d = d + max_d_coord = point + return max_d, max_d_coord + +def connect(x, y, z, level, adj, radius=1): + ''' + IDEA: + + - Greedy: + + PSEUDO: + + 1) For each level + 2) order the nodes of the level by max_distance(...) + 3) for each node in the ordered nodes + 4) assign closest point + + NOTES: + + - if two vertices on different levels share the same neighbor, override + the existing level + - level matches node (as index) to its corresponding level + + all along the watchtower, princes kept the view. + + ''' + #print(adj) + rev = reverse_level(level) + levels_sorted = rev.keys() + levels_sorted = sorted(levels_sorted) + # print(levels_sorted) + coordinates = {0: [0, 0, 0]} + for l in levels_sorted: + + ## PREPROCESSING + + points = [] # candidate coordinates for next level + # print(x[l]) + for num in range(len(x[l])): + point = [x[l][num], y[l][num], z[l][num]] + points.append(point) + # print(point) + + ## DETERMINING ORDER + + # print(points) + ordered = rev[l] # nodes in level l + ''' + for v in ordered: # debugging + print(v) + print(coordinates[v]) + print(max_distance(points, coordinates[v])[0]) + ''' + ordered = sorted(ordered, key=lambda v: max_distance(points,\ + coordinates[v])[0], reverse=True) # list for order + # print(ordered) + + ## ASSIGN POINT + + # print(nodes) + # to_be_assigned = [] + for v in ordered: # for each ordered node + # if v in coordinates: + for neighbor in adj[v]: # for each neighbor to ^node + # print(neighbor, level[neighbor]) + if l+radius == level[neighbor]: # if the level of the neighbor is correct + assignment = min_distance(points, coordinates[v])[1] # min distance assignment + points.remove(assignment) + if neighbor not in coordinates: # neighbor already assigned? (ie shared neighbors) + coordinates[neighbor] = assignment + # print(nodes) + # print(matches) + # candidates = gen_candidates(points, coordinates[v], n) + # print(candidates) + # print(matches) + + + + #print(l) + #print(x[l]) + + # print(coordinates) + return coordinates + +def gen_coordinates(adj_unparsed, radius=5): + ''' + arguments: json object + returns: dictionary where each node is mapped to a coordinate + ''' + adj = adjacency_list(adj_unparsed) + nodes = list(adj.keys()) + nodes.reverse() + X, Y, Z, level = points(adj, len(nodes), nodes, radius) + # print(level) + rev = reverse_level(level) + coordinates = connect(X, Y, Z, level, adj, radius) + + obj = json.loads(json_string) + root = obj['objects'][0]['nodes'][-1] + for each in obj['objects'][1:]: + each['coord-xyz'] = coordinates[root-each['_gvid']] + + return obj + +def adjacency_list(adj_string): + global json_string + # json_string = r'{"name":"%3","directed":true,"strict":false,"compound":"true","newrank":"true","_subgraph_cnt":1,"objects":[{"name":"root","compound":"true","newrank":"true","_gvid":0,"nodes":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88],"edges":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193]},{"_gvid":1,"name":"[root] aws_api_gateway_base_path_mapping.base_path","label":"aws_api_gateway_base_path_mapping.base_path","shape":"box"},{"_gvid":2,"name":"[root] aws_api_gateway_deployment.deployment","label":"aws_api_gateway_deployment.deployment","shape":"box"},{"_gvid":3,"name":"[root] aws_api_gateway_domain_name.urlapi","label":"aws_api_gateway_domain_name.urlapi","shape":"box"},{"_gvid":4,"name":"[root] aws_api_gateway_integration.fetch_integration","label":"aws_api_gateway_integration.fetch_integration","shape":"box"},{"_gvid":5,"name":"[root] aws_api_gateway_integration.generate_integration","label":"aws_api_gateway_integration.generate_integration","shape":"box"},{"_gvid":6,"name":"[root] aws_api_gateway_integration.generate_options_integration","label":"aws_api_gateway_integration.generate_options_integration","shape":"box"},{"_gvid":7,"name":"[root] aws_api_gateway_integration.upload_integration","label":"aws_api_gateway_integration.upload_integration","shape":"box"},{"_gvid":8,"name":"[root] aws_api_gateway_integration.upload_options_integration","label":"aws_api_gateway_integration.upload_options_integration","shape":"box"},{"_gvid":9,"name":"[root] aws_api_gateway_integration_response.fetch_ir_200","label":"aws_api_gateway_integration_response.fetch_ir_200","shape":"box"},{"_gvid":10,"name":"[root] aws_api_gateway_integration_response.generate_ir_400","label":"aws_api_gateway_integration_response.generate_ir_400","shape":"box"},{"_gvid":11,"name":"[root] aws_api_gateway_integration_response.generate_options_integration_response","label":"aws_api_gateway_integration_response.generate_options_integration_response","shape":"box"},{"_gvid":12,"name":"[root] aws_api_gateway_integration_response.upload_ir_400","label":"aws_api_gateway_integration_response.upload_ir_400","shape":"box"},{"_gvid":13,"name":"[root] aws_api_gateway_integration_response.upload_options_integration_response","label":"aws_api_gateway_integration_response.upload_options_integration_response","shape":"box"},{"_gvid":14,"name":"[root] aws_api_gateway_method.fetch","label":"aws_api_gateway_method.fetch","shape":"box"},{"_gvid":15,"name":"[root] aws_api_gateway_method.generate","label":"aws_api_gateway_method.generate","shape":"box"},{"_gvid":16,"name":"[root] aws_api_gateway_method.generate_options","label":"aws_api_gateway_method.generate_options","shape":"box"},{"_gvid":17,"name":"[root] aws_api_gateway_method.upload","label":"aws_api_gateway_method.upload","shape":"box"},{"_gvid":18,"name":"[root] aws_api_gateway_method.upload_options","label":"aws_api_gateway_method.upload_options","shape":"box"},{"_gvid":19,"name":"[root] aws_api_gateway_method_response.fetch_200","label":"aws_api_gateway_method_response.fetch_200","shape":"box"},{"_gvid":20,"name":"[root] aws_api_gateway_method_response.fetch_400","label":"aws_api_gateway_method_response.fetch_400","shape":"box"},{"_gvid":21,"name":"[root] aws_api_gateway_method_response.generate_200","label":"aws_api_gateway_method_response.generate_200","shape":"box"},{"_gvid":22,"name":"[root] aws_api_gateway_method_response.generate_400","label":"aws_api_gateway_method_response.generate_400","shape":"box"},{"_gvid":23,"name":"[root] aws_api_gateway_method_response.generate_401","label":"aws_api_gateway_method_response.generate_401","shape":"box"},{"_gvid":24,"name":"[root] aws_api_gateway_method_response.generate_404","label":"aws_api_gateway_method_response.generate_404","shape":"box"},{"_gvid":25,"name":"[root] aws_api_gateway_method_response.generate_500","label":"aws_api_gateway_method_response.generate_500","shape":"box"},{"_gvid":26,"name":"[root] aws_api_gateway_method_response.generate_options_200","label":"aws_api_gateway_method_response.generate_options_200","shape":"box"},{"_gvid":27,"name":"[root] aws_api_gateway_method_response.upload_200","label":"aws_api_gateway_method_response.upload_200","shape":"box"},{"_gvid":28,"name":"[root] aws_api_gateway_method_response.upload_400","label":"aws_api_gateway_method_response.upload_400","shape":"box"},{"_gvid":29,"name":"[root] aws_api_gateway_method_response.upload_401","label":"aws_api_gateway_method_response.upload_401","shape":"box"},{"_gvid":30,"name":"[root] aws_api_gateway_method_response.upload_500","label":"aws_api_gateway_method_response.upload_500","shape":"box"},{"_gvid":31,"name":"[root] aws_api_gateway_method_response.upload_options_200","label":"aws_api_gateway_method_response.upload_options_200","shape":"box"},{"_gvid":32,"name":"[root] aws_api_gateway_request_validator.fetch_validator","label":"aws_api_gateway_request_validator.fetch_validator","shape":"box"},{"_gvid":33,"name":"[root] aws_api_gateway_request_validator.generate_validator","label":"aws_api_gateway_request_validator.generate_validator","shape":"box"},{"_gvid":34,"name":"[root] aws_api_gateway_resource.fetch_resource","label":"aws_api_gateway_resource.fetch_resource","shape":"box"},{"_gvid":35,"name":"[root] aws_api_gateway_resource.generate_resource","label":"aws_api_gateway_resource.generate_resource","shape":"box"},{"_gvid":36,"name":"[root] aws_api_gateway_resource.upload_resource","label":"aws_api_gateway_resource.upload_resource","shape":"box"},{"_gvid":37,"name":"[root] aws_api_gateway_rest_api.api","label":"aws_api_gateway_rest_api.api","shape":"box"},{"_gvid":38,"name":"[root] aws_cloudwatch_event_rule.everyday","label":"aws_cloudwatch_event_rule.everyday","shape":"box"},{"_gvid":39,"name":"[root] aws_cloudwatch_event_target.clean_up_urls_everyday","label":"aws_cloudwatch_event_target.clean_up_urls_everyday","shape":"box"},{"_gvid":40,"name":"[root] aws_iam_policy.invoke","label":"aws_iam_policy.invoke","shape":"box"},{"_gvid":41,"name":"[root] aws_iam_policy.ip","label":"aws_iam_policy.ip","shape":"box"},{"_gvid":42,"name":"[root] aws_iam_policy.ip_put","label":"aws_iam_policy.ip_put","shape":"box"},{"_gvid":43,"name":"[root] aws_iam_policy.lambda_fetch_s3","label":"aws_iam_policy.lambda_fetch_s3","shape":"box"},{"_gvid":44,"name":"[root] aws_iam_role.lambda_fetch_object_role","label":"aws_iam_role.lambda_fetch_object_role","shape":"box"},{"_gvid":45,"name":"[root] aws_iam_role.lambda_generate_url_helper_role","label":"aws_iam_role.lambda_generate_url_helper_role","shape":"box"},{"_gvid":46,"name":"[root] aws_iam_role.lambda_generate_url_role","label":"aws_iam_role.lambda_generate_url_role","shape":"box"},{"_gvid":47,"name":"[root] aws_iam_role.lambda_remove_urls_role","label":"aws_iam_role.lambda_remove_urls_role","shape":"box"},{"_gvid":48,"name":"[root] aws_iam_role.lambda_upload_url_role","label":"aws_iam_role.lambda_upload_url_role","shape":"box"},{"_gvid":49,"name":"[root] aws_iam_role_policy_attachment.invokehelper_gen","label":"aws_iam_role_policy_attachment.invokehelper_gen","shape":"box"},{"_gvid":50,"name":"[root] aws_iam_role_policy_attachment.invokehelper_remove","label":"aws_iam_role_policy_attachment.invokehelper_remove","shape":"box"},{"_gvid":51,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_fetch","label":"aws_iam_role_policy_attachment.lambdabasic_fetch","shape":"box"},{"_gvid":52,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_gen","label":"aws_iam_role_policy_attachment.lambdabasic_gen","shape":"box"},{"_gvid":53,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_genhelp","label":"aws_iam_role_policy_attachment.lambdabasic_genhelp","shape":"box"},{"_gvid":54,"name":"[root] aws_iam_role_policy_attachment.s3full_gen","label":"aws_iam_role_policy_attachment.s3full_gen","shape":"box"},{"_gvid":55,"name":"[root] aws_iam_role_policy_attachment.s3full_remove","label":"aws_iam_role_policy_attachment.s3full_remove","shape":"box"},{"_gvid":56,"name":"[root] aws_iam_role_policy_attachment.s3ip_genhelp","label":"aws_iam_role_policy_attachment.s3ip_genhelp","shape":"box"},{"_gvid":57,"name":"[root] aws_iam_role_policy_attachment.s3ip_upload","label":"aws_iam_role_policy_attachment.s3ip_upload","shape":"box"},{"_gvid":58,"name":"[root] aws_iam_role_policy_attachment.s3read_fetch","label":"aws_iam_role_policy_attachment.s3read_fetch","shape":"box"},{"_gvid":59,"name":"[root] aws_lambda_function.fetch","label":"aws_lambda_function.fetch","shape":"box"},{"_gvid":60,"name":"[root] aws_lambda_function.gen","label":"aws_lambda_function.gen","shape":"box"},{"_gvid":61,"name":"[root] aws_lambda_function.genhelp","label":"aws_lambda_function.genhelp","shape":"box"},{"_gvid":62,"name":"[root] aws_lambda_function.remove","label":"aws_lambda_function.remove","shape":"box"},{"_gvid":63,"name":"[root] aws_lambda_function.upload","label":"aws_lambda_function.upload","shape":"box"},{"_gvid":64,"name":"[root] aws_lambda_permission.allow_cloudwatch_to_call_check_foo","label":"aws_lambda_permission.allow_cloudwatch_to_call_check_foo","shape":"box"},{"_gvid":65,"name":"[root] aws_lambda_permission.apigw_fetch_lambda","label":"aws_lambda_permission.apigw_fetch_lambda","shape":"box"},{"_gvid":66,"name":"[root] aws_lambda_permission.apigw_generate_lambda","label":"aws_lambda_permission.apigw_generate_lambda","shape":"box"},{"_gvid":67,"name":"[root] aws_lambda_permission.apigw_upload_lambda","label":"aws_lambda_permission.apigw_upload_lambda","shape":"box"},{"_gvid":68,"name":"[root] aws_route53_record.route","label":"aws_route53_record.route","shape":"box"},{"_gvid":69,"name":"[root] aws_route53_zone.primary","label":"aws_route53_zone.primary","shape":"box"},{"_gvid":70,"name":"[root] aws_s3_bucket.download_bucket","label":"aws_s3_bucket.download_bucket","shape":"box"},{"_gvid":71,"name":"[root] aws_s3_bucket.upload_bucket","label":"aws_s3_bucket.upload_bucket","shape":"box"},{"_gvid":72,"name":"[root] aws_s3_bucket_public_access_block.private_download_bucket","label":"aws_s3_bucket_public_access_block.private_download_bucket","shape":"box"},{"_gvid":73,"name":"[root] aws_s3_bucket_public_access_block.private_upload_bucket","label":"aws_s3_bucket_public_access_block.private_upload_bucket","shape":"box"},{"_gvid":74,"name":"[root] data.archive_file.fetch_object_code","label":"data.archive_file.fetch_object_code","shape":"box"},{"_gvid":75,"name":"[root] data.archive_file.generate_url_helper_code","label":"data.archive_file.generate_url_helper_code","shape":"box"},{"_gvid":76,"name":"[root] data.archive_file.generate_url_main_code","label":"data.archive_file.generate_url_main_code","shape":"box"},{"_gvid":77,"name":"[root] data.archive_file.remove_expired_urls_code","label":"data.archive_file.remove_expired_urls_code","shape":"box"},{"_gvid":78,"name":"[root] data.archive_file.upload_url_code","label":"data.archive_file.upload_url_code","shape":"box"},{"_gvid":79,"name":"[root] data.aws_acm_certificate.cert","label":"data.aws_acm_certificate.cert","shape":"box"},{"_gvid":80,"name":"[root] null_resource.build_image","label":"null_resource.build_image","shape":"box"},{"_gvid":81,"name":"[root] provider.archive","label":"provider.archive","shape":"diamond"},{"_gvid":82,"name":"[root] provider.aws","label":"provider.aws","shape":"diamond"},{"_gvid":83,"name":"[root] meta.count-boundary (EachMode fixup)","label":"\\N"},{"_gvid":84,"name":"[root] provider.archive (close)","label":"\\N"},{"_gvid":85,"name":"[root] provider.aws (close)","label":"\\N"},{"_gvid":86,"name":"[root] provider.null (close)","label":"\\N"},{"_gvid":87,"name":"[root] provisioner.local-exec (close)","label":"\\N"},{"_gvid":88,"name":"[root] root","label":"\\N"}],"edges":[{"_gvid":0,"tail":1,"head":2},{"_gvid":1,"tail":1,"head":3},{"_gvid":2,"tail":2,"head":4},{"_gvid":3,"tail":2,"head":5},{"_gvid":4,"tail":2,"head":7},{"_gvid":5,"tail":3,"head":79},{"_gvid":6,"tail":4,"head":14},{"_gvid":7,"tail":4,"head":59},{"_gvid":8,"tail":5,"head":15},{"_gvid":9,"tail":5,"head":60},{"_gvid":10,"tail":6,"head":16},{"_gvid":11,"tail":7,"head":17},{"_gvid":12,"tail":7,"head":63},{"_gvid":13,"tail":8,"head":18},{"_gvid":14,"tail":9,"head":4},{"_gvid":15,"tail":9,"head":19},{"_gvid":16,"tail":10,"head":22},{"_gvid":17,"tail":10,"head":70},{"_gvid":18,"tail":11,"head":26},{"_gvid":19,"tail":11,"head":70},{"_gvid":20,"tail":12,"head":28},{"_gvid":21,"tail":12,"head":71},{"_gvid":22,"tail":13,"head":31},{"_gvid":23,"tail":13,"head":71},{"_gvid":24,"tail":14,"head":32},{"_gvid":25,"tail":14,"head":34},{"_gvid":26,"tail":15,"head":33},{"_gvid":27,"tail":15,"head":35},{"_gvid":28,"tail":16,"head":35},{"_gvid":29,"tail":17,"head":36},{"_gvid":30,"tail":18,"head":36},{"_gvid":31,"tail":19,"head":14},{"_gvid":32,"tail":20,"head":14},{"_gvid":33,"tail":21,"head":15},{"_gvid":34,"tail":22,"head":15},{"_gvid":35,"tail":23,"head":15},{"_gvid":36,"tail":24,"head":15},{"_gvid":37,"tail":25,"head":15},{"_gvid":38,"tail":26,"head":16},{"_gvid":39,"tail":27,"head":17},{"_gvid":40,"tail":28,"head":17},{"_gvid":41,"tail":29,"head":17},{"_gvid":42,"tail":30,"head":17},{"_gvid":43,"tail":31,"head":18},{"_gvid":44,"tail":32,"head":37},{"_gvid":45,"tail":33,"head":37},{"_gvid":46,"tail":34,"head":37},{"_gvid":47,"tail":35,"head":37},{"_gvid":48,"tail":36,"head":37},{"_gvid":49,"tail":37,"head":82},{"_gvid":50,"tail":38,"head":82},{"_gvid":51,"tail":39,"head":38},{"_gvid":52,"tail":39,"head":62},{"_gvid":53,"tail":40,"head":61},{"_gvid":54,"tail":41,"head":82},{"_gvid":55,"tail":42,"head":82},{"_gvid":56,"tail":43,"head":82},{"_gvid":57,"tail":44,"head":82},{"_gvid":58,"tail":45,"head":82},{"_gvid":59,"tail":46,"head":82},{"_gvid":60,"tail":47,"head":82},{"_gvid":61,"tail":48,"head":82},{"_gvid":62,"tail":49,"head":40},{"_gvid":63,"tail":49,"head":46},{"_gvid":64,"tail":50,"head":40},{"_gvid":65,"tail":50,"head":47},{"_gvid":66,"tail":51,"head":44},{"_gvid":67,"tail":52,"head":46},{"_gvid":68,"tail":53,"head":45},{"_gvid":69,"tail":54,"head":46},{"_gvid":70,"tail":55,"head":47},{"_gvid":71,"tail":56,"head":41},{"_gvid":72,"tail":56,"head":45},{"_gvid":73,"tail":57,"head":42},{"_gvid":74,"tail":57,"head":48},{"_gvid":75,"tail":58,"head":43},{"_gvid":76,"tail":58,"head":44},{"_gvid":77,"tail":59,"head":44},{"_gvid":78,"tail":59,"head":70},{"_gvid":79,"tail":59,"head":74},{"_gvid":80,"tail":60,"head":46},{"_gvid":81,"tail":60,"head":70},{"_gvid":82,"tail":60,"head":76},{"_gvid":83,"tail":61,"head":45},{"_gvid":84,"tail":61,"head":75},{"_gvid":85,"tail":62,"head":47},{"_gvid":86,"tail":62,"head":70},{"_gvid":87,"tail":62,"head":77},{"_gvid":88,"tail":63,"head":48},{"_gvid":89,"tail":63,"head":71},{"_gvid":90,"tail":63,"head":78},{"_gvid":91,"tail":64,"head":38},{"_gvid":92,"tail":64,"head":62},{"_gvid":93,"tail":65,"head":14},{"_gvid":94,"tail":65,"head":59},{"_gvid":95,"tail":66,"head":15},{"_gvid":96,"tail":66,"head":60},{"_gvid":97,"tail":67,"head":17},{"_gvid":98,"tail":67,"head":63},{"_gvid":99,"tail":68,"head":3},{"_gvid":100,"tail":68,"head":69},{"_gvid":101,"tail":69,"head":82},{"_gvid":102,"tail":70,"head":82},{"_gvid":103,"tail":71,"head":70},{"_gvid":104,"tail":72,"head":70},{"_gvid":105,"tail":73,"head":71},{"_gvid":106,"tail":74,"head":81},{"_gvid":107,"tail":75,"head":81},{"_gvid":108,"tail":76,"head":81},{"_gvid":109,"tail":77,"head":81},{"_gvid":110,"tail":78,"head":81},{"_gvid":111,"tail":79,"head":82},{"_gvid":112,"tail":80,"head":71},{"_gvid":113,"tail":83,"head":1},{"_gvid":114,"tail":83,"head":6},{"_gvid":115,"tail":83,"head":8},{"_gvid":116,"tail":83,"head":9},{"_gvid":117,"tail":83,"head":10},{"_gvid":118,"tail":83,"head":11},{"_gvid":119,"tail":83,"head":12},{"_gvid":120,"tail":83,"head":13},{"_gvid":121,"tail":83,"head":20},{"_gvid":122,"tail":83,"head":21},{"_gvid":123,"tail":83,"head":23},{"_gvid":124,"tail":83,"head":24},{"_gvid":125,"tail":83,"head":25},{"_gvid":126,"tail":83,"head":27},{"_gvid":127,"tail":83,"head":29},{"_gvid":128,"tail":83,"head":30},{"_gvid":129,"tail":83,"head":39},{"_gvid":130,"tail":83,"head":49},{"_gvid":131,"tail":83,"head":50},{"_gvid":132,"tail":83,"head":51},{"_gvid":133,"tail":83,"head":52},{"_gvid":134,"tail":83,"head":53},{"_gvid":135,"tail":83,"head":54},{"_gvid":136,"tail":83,"head":55},{"_gvid":137,"tail":83,"head":56},{"_gvid":138,"tail":83,"head":57},{"_gvid":139,"tail":83,"head":58},{"_gvid":140,"tail":83,"head":64},{"_gvid":141,"tail":83,"head":65},{"_gvid":142,"tail":83,"head":66},{"_gvid":143,"tail":83,"head":67},{"_gvid":144,"tail":83,"head":68},{"_gvid":145,"tail":83,"head":72},{"_gvid":146,"tail":83,"head":73},{"_gvid":147,"tail":83,"head":80},{"_gvid":148,"tail":84,"head":74},{"_gvid":149,"tail":84,"head":75},{"_gvid":150,"tail":84,"head":76},{"_gvid":151,"tail":84,"head":77},{"_gvid":152,"tail":84,"head":78},{"_gvid":153,"tail":85,"head":1},{"_gvid":154,"tail":85,"head":6},{"_gvid":155,"tail":85,"head":8},{"_gvid":156,"tail":85,"head":9},{"_gvid":157,"tail":85,"head":10},{"_gvid":158,"tail":85,"head":11},{"_gvid":159,"tail":85,"head":12},{"_gvid":160,"tail":85,"head":13},{"_gvid":161,"tail":85,"head":20},{"_gvid":162,"tail":85,"head":21},{"_gvid":163,"tail":85,"head":23},{"_gvid":164,"tail":85,"head":24},{"_gvid":165,"tail":85,"head":25},{"_gvid":166,"tail":85,"head":27},{"_gvid":167,"tail":85,"head":29},{"_gvid":168,"tail":85,"head":30},{"_gvid":169,"tail":85,"head":39},{"_gvid":170,"tail":85,"head":49},{"_gvid":171,"tail":85,"head":50},{"_gvid":172,"tail":85,"head":51},{"_gvid":173,"tail":85,"head":52},{"_gvid":174,"tail":85,"head":53},{"_gvid":175,"tail":85,"head":54},{"_gvid":176,"tail":85,"head":55},{"_gvid":177,"tail":85,"head":56},{"_gvid":178,"tail":85,"head":57},{"_gvid":179,"tail":85,"head":58},{"_gvid":180,"tail":85,"head":64},{"_gvid":181,"tail":85,"head":65},{"_gvid":182,"tail":85,"head":66},{"_gvid":183,"tail":85,"head":67},{"_gvid":184,"tail":85,"head":68},{"_gvid":185,"tail":85,"head":72},{"_gvid":186,"tail":85,"head":73},{"_gvid":187,"tail":86,"head":80},{"_gvid":188,"tail":87,"head":80},{"_gvid":189,"tail":88,"head":83},{"_gvid":190,"tail":88,"head":84},{"_gvid":191,"tail":88,"head":85},{"_gvid":192,"tail":88,"head":86},{"_gvid":193,"tail":88,"head":87}]}' + #json_string = adj_string # r'{"name":"%3","directed":true,"strict":false,"compound":"true","newrank":"true","_subgraph_cnt":1,"objects":[{"name":"root","compound":"true","newrank":"true","_gvid":0,"nodes":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],"edges":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57]},{"_gvid":1,"name":"[root] aws_alb.main","label":"aws_alb.main","shape":"box"},{"_gvid":2,"name":"[root] aws_alb_listener.front_end","label":"aws_alb_listener.front_end","shape":"box"},{"_gvid":3,"name":"[root] aws_alb_target_group.test","label":"aws_alb_target_group.test","shape":"box"},{"_gvid":4,"name":"[root] aws_autoscaling_group.app","label":"aws_autoscaling_group.app","shape":"box"},{"_gvid":5,"name":"[root] aws_cloudwatch_log_group.app","label":"aws_cloudwatch_log_group.app","shape":"box"},{"_gvid":6,"name":"[root] aws_cloudwatch_log_group.ecs","label":"aws_cloudwatch_log_group.ecs","shape":"box"},{"_gvid":7,"name":"[root] aws_ecs_cluster.main","label":"aws_ecs_cluster.main","shape":"box"},{"_gvid":8,"name":"[root] aws_ecs_service.test","label":"aws_ecs_service.test","shape":"box"},{"_gvid":9,"name":"[root] aws_ecs_task_definition.ghost","label":"aws_ecs_task_definition.ghost","shape":"box"},{"_gvid":10,"name":"[root] aws_iam_instance_profile.app","label":"aws_iam_instance_profile.app","shape":"box"},{"_gvid":11,"name":"[root] aws_iam_role.app_instance","label":"aws_iam_role.app_instance","shape":"box"},{"_gvid":12,"name":"[root] aws_iam_role.ecs_service","label":"aws_iam_role.ecs_service","shape":"box"},{"_gvid":13,"name":"[root] aws_iam_role_policy.ecs_service","label":"aws_iam_role_policy.ecs_service","shape":"box"},{"_gvid":14,"name":"[root] aws_iam_role_policy.instance","label":"aws_iam_role_policy.instance","shape":"box"},{"_gvid":15,"name":"[root] aws_internet_gateway.gw","label":"aws_internet_gateway.gw","shape":"box"},{"_gvid":16,"name":"[root] aws_launch_configuration.app","label":"aws_launch_configuration.app","shape":"box"},{"_gvid":17,"name":"[root] aws_route_table.r","label":"aws_route_table.r","shape":"box"},{"_gvid":18,"name":"[root] aws_route_table_association.a","label":"aws_route_table_association.a","shape":"box"},{"_gvid":19,"name":"[root] aws_security_group.instance_sg","label":"aws_security_group.instance_sg","shape":"box"},{"_gvid":20,"name":"[root] aws_security_group.lb_sg","label":"aws_security_group.lb_sg","shape":"box"},{"_gvid":21,"name":"[root] aws_subnet.main","label":"aws_subnet.main","shape":"box"},{"_gvid":22,"name":"[root] aws_vpc.main","label":"aws_vpc.main","shape":"box"},{"_gvid":23,"name":"[root] data.aws_ami.stable_coreos","label":"data.aws_ami.stable_coreos","shape":"box"},{"_gvid":24,"name":"[root] data.aws_availability_zones.available","label":"data.aws_availability_zones.available","shape":"box"},{"_gvid":25,"name":"[root] data.template_file.cloud_config","label":"data.template_file.cloud_config","shape":"box"},{"_gvid":26,"name":"[root] data.template_file.instance_profile","label":"data.template_file.instance_profile","shape":"box"},{"_gvid":27,"name":"[root] data.template_file.task_definition","label":"data.template_file.task_definition","shape":"box"},{"_gvid":28,"name":"[root] provider.aws","label":"provider.aws","shape":"diamond"},{"_gvid":29,"name":"[root] provider.template","label":"provider.template","shape":"diamond"},{"_gvid":30,"name":"[root] meta.count-boundary (EachMode fixup)","label":"\\N"},{"_gvid":31,"name":"[root] provider.aws (close)","label":"\\N"},{"_gvid":32,"name":"[root] provider.template (close)","label":"\\N"},{"_gvid":33,"name":"[root] root","label":"\\N"}],"edges":[{"_gvid":0,"tail":1,"head":20},{"_gvid":1,"tail":1,"head":21},{"_gvid":2,"tail":2,"head":1},{"_gvid":3,"tail":2,"head":3},{"_gvid":4,"tail":3,"head":22},{"_gvid":5,"tail":4,"head":16},{"_gvid":6,"tail":4,"head":21},{"_gvid":7,"tail":5,"head":28},{"_gvid":8,"tail":6,"head":28},{"_gvid":9,"tail":7,"head":28},{"_gvid":10,"tail":8,"head":2},{"_gvid":11,"tail":8,"head":7},{"_gvid":12,"tail":8,"head":9},{"_gvid":13,"tail":8,"head":13},{"_gvid":14,"tail":9,"head":27},{"_gvid":15,"tail":9,"head":28},{"_gvid":16,"tail":10,"head":11},{"_gvid":17,"tail":11,"head":28},{"_gvid":18,"tail":12,"head":28},{"_gvid":19,"tail":13,"head":12},{"_gvid":20,"tail":14,"head":11},{"_gvid":21,"tail":14,"head":26},{"_gvid":22,"tail":15,"head":22},{"_gvid":23,"tail":16,"head":10},{"_gvid":24,"tail":16,"head":19},{"_gvid":25,"tail":16,"head":23},{"_gvid":26,"tail":16,"head":25},{"_gvid":27,"tail":17,"head":15},{"_gvid":28,"tail":18,"head":17},{"_gvid":29,"tail":18,"head":21},{"_gvid":30,"tail":19,"head":20},{"_gvid":31,"tail":20,"head":22},{"_gvid":32,"tail":21,"head":22},{"_gvid":33,"tail":21,"head":24},{"_gvid":34,"tail":22,"head":28},{"_gvid":35,"tail":23,"head":28},{"_gvid":36,"tail":24,"head":28},{"_gvid":37,"tail":25,"head":29},{"_gvid":38,"tail":26,"head":29},{"_gvid":39,"tail":27,"head":29},{"_gvid":40,"tail":30,"head":4},{"_gvid":41,"tail":30,"head":5},{"_gvid":42,"tail":30,"head":6},{"_gvid":43,"tail":30,"head":8},{"_gvid":44,"tail":30,"head":14},{"_gvid":45,"tail":30,"head":18},{"_gvid":46,"tail":31,"head":4},{"_gvid":47,"tail":31,"head":5},{"_gvid":48,"tail":31,"head":6},{"_gvid":49,"tail":31,"head":8},{"_gvid":50,"tail":31,"head":14},{"_gvid":51,"tail":31,"head":18},{"_gvid":52,"tail":32,"head":25},{"_gvid":53,"tail":32,"head":26},{"_gvid":54,"tail":32,"head":27},{"_gvid":55,"tail":33,"head":30},{"_gvid":56,"tail":33,"head":31},{"_gvid":57,"tail":33,"head":32}]}' + + obj = json.loads(json_string) + root = obj['objects'][0]['nodes'][-1] + + adj = {(root-i):[] for i in obj['objects'][0]['nodes']} + + for edge in obj['edges']: + adj[root-edge['tail']].insert(0, root-edge['head']) + + return adj + +def main(): + ''' + adj = { + 0:[1, 2], + 1:[3, 4], + 2:[3, 4], + 3:[5], + 4:[6], + 5:[6], + 6:[] + } + ''' + global json_string + json_string = r'{"name":"%3","directed":true,"strict":false,"compound":"true","newrank":"true","_subgraph_cnt":1,"objects":[{"name":"root","compound":"true","newrank":"true","_gvid":0,"nodes":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88],"edges":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193]},{"_gvid":1,"name":"[root] aws_api_gateway_base_path_mapping.base_path","label":"aws_api_gateway_base_path_mapping.base_path","shape":"box"},{"_gvid":2,"name":"[root] aws_api_gateway_deployment.deployment","label":"aws_api_gateway_deployment.deployment","shape":"box"},{"_gvid":3,"name":"[root] aws_api_gateway_domain_name.urlapi","label":"aws_api_gateway_domain_name.urlapi","shape":"box"},{"_gvid":4,"name":"[root] aws_api_gateway_integration.fetch_integration","label":"aws_api_gateway_integration.fetch_integration","shape":"box"},{"_gvid":5,"name":"[root] aws_api_gateway_integration.generate_integration","label":"aws_api_gateway_integration.generate_integration","shape":"box"},{"_gvid":6,"name":"[root] aws_api_gateway_integration.generate_options_integration","label":"aws_api_gateway_integration.generate_options_integration","shape":"box"},{"_gvid":7,"name":"[root] aws_api_gateway_integration.upload_integration","label":"aws_api_gateway_integration.upload_integration","shape":"box"},{"_gvid":8,"name":"[root] aws_api_gateway_integration.upload_options_integration","label":"aws_api_gateway_integration.upload_options_integration","shape":"box"},{"_gvid":9,"name":"[root] aws_api_gateway_integration_response.fetch_ir_200","label":"aws_api_gateway_integration_response.fetch_ir_200","shape":"box"},{"_gvid":10,"name":"[root] aws_api_gateway_integration_response.generate_ir_400","label":"aws_api_gateway_integration_response.generate_ir_400","shape":"box"},{"_gvid":11,"name":"[root] aws_api_gateway_integration_response.generate_options_integration_response","label":"aws_api_gateway_integration_response.generate_options_integration_response","shape":"box"},{"_gvid":12,"name":"[root] aws_api_gateway_integration_response.upload_ir_400","label":"aws_api_gateway_integration_response.upload_ir_400","shape":"box"},{"_gvid":13,"name":"[root] aws_api_gateway_integration_response.upload_options_integration_response","label":"aws_api_gateway_integration_response.upload_options_integration_response","shape":"box"},{"_gvid":14,"name":"[root] aws_api_gateway_method.fetch","label":"aws_api_gateway_method.fetch","shape":"box"},{"_gvid":15,"name":"[root] aws_api_gateway_method.generate","label":"aws_api_gateway_method.generate","shape":"box"},{"_gvid":16,"name":"[root] aws_api_gateway_method.generate_options","label":"aws_api_gateway_method.generate_options","shape":"box"},{"_gvid":17,"name":"[root] aws_api_gateway_method.upload","label":"aws_api_gateway_method.upload","shape":"box"},{"_gvid":18,"name":"[root] aws_api_gateway_method.upload_options","label":"aws_api_gateway_method.upload_options","shape":"box"},{"_gvid":19,"name":"[root] aws_api_gateway_method_response.fetch_200","label":"aws_api_gateway_method_response.fetch_200","shape":"box"},{"_gvid":20,"name":"[root] aws_api_gateway_method_response.fetch_400","label":"aws_api_gateway_method_response.fetch_400","shape":"box"},{"_gvid":21,"name":"[root] aws_api_gateway_method_response.generate_200","label":"aws_api_gateway_method_response.generate_200","shape":"box"},{"_gvid":22,"name":"[root] aws_api_gateway_method_response.generate_400","label":"aws_api_gateway_method_response.generate_400","shape":"box"},{"_gvid":23,"name":"[root] aws_api_gateway_method_response.generate_401","label":"aws_api_gateway_method_response.generate_401","shape":"box"},{"_gvid":24,"name":"[root] aws_api_gateway_method_response.generate_404","label":"aws_api_gateway_method_response.generate_404","shape":"box"},{"_gvid":25,"name":"[root] aws_api_gateway_method_response.generate_500","label":"aws_api_gateway_method_response.generate_500","shape":"box"},{"_gvid":26,"name":"[root] aws_api_gateway_method_response.generate_options_200","label":"aws_api_gateway_method_response.generate_options_200","shape":"box"},{"_gvid":27,"name":"[root] aws_api_gateway_method_response.upload_200","label":"aws_api_gateway_method_response.upload_200","shape":"box"},{"_gvid":28,"name":"[root] aws_api_gateway_method_response.upload_400","label":"aws_api_gateway_method_response.upload_400","shape":"box"},{"_gvid":29,"name":"[root] aws_api_gateway_method_response.upload_401","label":"aws_api_gateway_method_response.upload_401","shape":"box"},{"_gvid":30,"name":"[root] aws_api_gateway_method_response.upload_500","label":"aws_api_gateway_method_response.upload_500","shape":"box"},{"_gvid":31,"name":"[root] aws_api_gateway_method_response.upload_options_200","label":"aws_api_gateway_method_response.upload_options_200","shape":"box"},{"_gvid":32,"name":"[root] aws_api_gateway_request_validator.fetch_validator","label":"aws_api_gateway_request_validator.fetch_validator","shape":"box"},{"_gvid":33,"name":"[root] aws_api_gateway_request_validator.generate_validator","label":"aws_api_gateway_request_validator.generate_validator","shape":"box"},{"_gvid":34,"name":"[root] aws_api_gateway_resource.fetch_resource","label":"aws_api_gateway_resource.fetch_resource","shape":"box"},{"_gvid":35,"name":"[root] aws_api_gateway_resource.generate_resource","label":"aws_api_gateway_resource.generate_resource","shape":"box"},{"_gvid":36,"name":"[root] aws_api_gateway_resource.upload_resource","label":"aws_api_gateway_resource.upload_resource","shape":"box"},{"_gvid":37,"name":"[root] aws_api_gateway_rest_api.api","label":"aws_api_gateway_rest_api.api","shape":"box"},{"_gvid":38,"name":"[root] aws_cloudwatch_event_rule.everyday","label":"aws_cloudwatch_event_rule.everyday","shape":"box"},{"_gvid":39,"name":"[root] aws_cloudwatch_event_target.clean_up_urls_everyday","label":"aws_cloudwatch_event_target.clean_up_urls_everyday","shape":"box"},{"_gvid":40,"name":"[root] aws_iam_policy.invoke","label":"aws_iam_policy.invoke","shape":"box"},{"_gvid":41,"name":"[root] aws_iam_policy.ip","label":"aws_iam_policy.ip","shape":"box"},{"_gvid":42,"name":"[root] aws_iam_policy.ip_put","label":"aws_iam_policy.ip_put","shape":"box"},{"_gvid":43,"name":"[root] aws_iam_policy.lambda_fetch_s3","label":"aws_iam_policy.lambda_fetch_s3","shape":"box"},{"_gvid":44,"name":"[root] aws_iam_role.lambda_fetch_object_role","label":"aws_iam_role.lambda_fetch_object_role","shape":"box"},{"_gvid":45,"name":"[root] aws_iam_role.lambda_generate_url_helper_role","label":"aws_iam_role.lambda_generate_url_helper_role","shape":"box"},{"_gvid":46,"name":"[root] aws_iam_role.lambda_generate_url_role","label":"aws_iam_role.lambda_generate_url_role","shape":"box"},{"_gvid":47,"name":"[root] aws_iam_role.lambda_remove_urls_role","label":"aws_iam_role.lambda_remove_urls_role","shape":"box"},{"_gvid":48,"name":"[root] aws_iam_role.lambda_upload_url_role","label":"aws_iam_role.lambda_upload_url_role","shape":"box"},{"_gvid":49,"name":"[root] aws_iam_role_policy_attachment.invokehelper_gen","label":"aws_iam_role_policy_attachment.invokehelper_gen","shape":"box"},{"_gvid":50,"name":"[root] aws_iam_role_policy_attachment.invokehelper_remove","label":"aws_iam_role_policy_attachment.invokehelper_remove","shape":"box"},{"_gvid":51,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_fetch","label":"aws_iam_role_policy_attachment.lambdabasic_fetch","shape":"box"},{"_gvid":52,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_gen","label":"aws_iam_role_policy_attachment.lambdabasic_gen","shape":"box"},{"_gvid":53,"name":"[root] aws_iam_role_policy_attachment.lambdabasic_genhelp","label":"aws_iam_role_policy_attachment.lambdabasic_genhelp","shape":"box"},{"_gvid":54,"name":"[root] aws_iam_role_policy_attachment.s3full_gen","label":"aws_iam_role_policy_attachment.s3full_gen","shape":"box"},{"_gvid":55,"name":"[root] aws_iam_role_policy_attachment.s3full_remove","label":"aws_iam_role_policy_attachment.s3full_remove","shape":"box"},{"_gvid":56,"name":"[root] aws_iam_role_policy_attachment.s3ip_genhelp","label":"aws_iam_role_policy_attachment.s3ip_genhelp","shape":"box"},{"_gvid":57,"name":"[root] aws_iam_role_policy_attachment.s3ip_upload","label":"aws_iam_role_policy_attachment.s3ip_upload","shape":"box"},{"_gvid":58,"name":"[root] aws_iam_role_policy_attachment.s3read_fetch","label":"aws_iam_role_policy_attachment.s3read_fetch","shape":"box"},{"_gvid":59,"name":"[root] aws_lambda_function.fetch","label":"aws_lambda_function.fetch","shape":"box"},{"_gvid":60,"name":"[root] aws_lambda_function.gen","label":"aws_lambda_function.gen","shape":"box"},{"_gvid":61,"name":"[root] aws_lambda_function.genhelp","label":"aws_lambda_function.genhelp","shape":"box"},{"_gvid":62,"name":"[root] aws_lambda_function.remove","label":"aws_lambda_function.remove","shape":"box"},{"_gvid":63,"name":"[root] aws_lambda_function.upload","label":"aws_lambda_function.upload","shape":"box"},{"_gvid":64,"name":"[root] aws_lambda_permission.allow_cloudwatch_to_call_check_foo","label":"aws_lambda_permission.allow_cloudwatch_to_call_check_foo","shape":"box"},{"_gvid":65,"name":"[root] aws_lambda_permission.apigw_fetch_lambda","label":"aws_lambda_permission.apigw_fetch_lambda","shape":"box"},{"_gvid":66,"name":"[root] aws_lambda_permission.apigw_generate_lambda","label":"aws_lambda_permission.apigw_generate_lambda","shape":"box"},{"_gvid":67,"name":"[root] aws_lambda_permission.apigw_upload_lambda","label":"aws_lambda_permission.apigw_upload_lambda","shape":"box"},{"_gvid":68,"name":"[root] aws_route53_record.route","label":"aws_route53_record.route","shape":"box"},{"_gvid":69,"name":"[root] aws_route53_zone.primary","label":"aws_route53_zone.primary","shape":"box"},{"_gvid":70,"name":"[root] aws_s3_bucket.download_bucket","label":"aws_s3_bucket.download_bucket","shape":"box"},{"_gvid":71,"name":"[root] aws_s3_bucket.upload_bucket","label":"aws_s3_bucket.upload_bucket","shape":"box"},{"_gvid":72,"name":"[root] aws_s3_bucket_public_access_block.private_download_bucket","label":"aws_s3_bucket_public_access_block.private_download_bucket","shape":"box"},{"_gvid":73,"name":"[root] aws_s3_bucket_public_access_block.private_upload_bucket","label":"aws_s3_bucket_public_access_block.private_upload_bucket","shape":"box"},{"_gvid":74,"name":"[root] data.archive_file.fetch_object_code","label":"data.archive_file.fetch_object_code","shape":"box"},{"_gvid":75,"name":"[root] data.archive_file.generate_url_helper_code","label":"data.archive_file.generate_url_helper_code","shape":"box"},{"_gvid":76,"name":"[root] data.archive_file.generate_url_main_code","label":"data.archive_file.generate_url_main_code","shape":"box"},{"_gvid":77,"name":"[root] data.archive_file.remove_expired_urls_code","label":"data.archive_file.remove_expired_urls_code","shape":"box"},{"_gvid":78,"name":"[root] data.archive_file.upload_url_code","label":"data.archive_file.upload_url_code","shape":"box"},{"_gvid":79,"name":"[root] data.aws_acm_certificate.cert","label":"data.aws_acm_certificate.cert","shape":"box"},{"_gvid":80,"name":"[root] null_resource.build_image","label":"null_resource.build_image","shape":"box"},{"_gvid":81,"name":"[root] provider.archive","label":"provider.archive","shape":"diamond"},{"_gvid":82,"name":"[root] provider.aws","label":"provider.aws","shape":"diamond"},{"_gvid":83,"name":"[root] meta.count-boundary (EachMode fixup)","label":"\\N"},{"_gvid":84,"name":"[root] provider.archive (close)","label":"\\N"},{"_gvid":85,"name":"[root] provider.aws (close)","label":"\\N"},{"_gvid":86,"name":"[root] provider.null (close)","label":"\\N"},{"_gvid":87,"name":"[root] provisioner.local-exec (close)","label":"\\N"},{"_gvid":88,"name":"[root] root","label":"\\N"}],"edges":[{"_gvid":0,"tail":1,"head":2},{"_gvid":1,"tail":1,"head":3},{"_gvid":2,"tail":2,"head":4},{"_gvid":3,"tail":2,"head":5},{"_gvid":4,"tail":2,"head":7},{"_gvid":5,"tail":3,"head":79},{"_gvid":6,"tail":4,"head":14},{"_gvid":7,"tail":4,"head":59},{"_gvid":8,"tail":5,"head":15},{"_gvid":9,"tail":5,"head":60},{"_gvid":10,"tail":6,"head":16},{"_gvid":11,"tail":7,"head":17},{"_gvid":12,"tail":7,"head":63},{"_gvid":13,"tail":8,"head":18},{"_gvid":14,"tail":9,"head":4},{"_gvid":15,"tail":9,"head":19},{"_gvid":16,"tail":10,"head":22},{"_gvid":17,"tail":10,"head":70},{"_gvid":18,"tail":11,"head":26},{"_gvid":19,"tail":11,"head":70},{"_gvid":20,"tail":12,"head":28},{"_gvid":21,"tail":12,"head":71},{"_gvid":22,"tail":13,"head":31},{"_gvid":23,"tail":13,"head":71},{"_gvid":24,"tail":14,"head":32},{"_gvid":25,"tail":14,"head":34},{"_gvid":26,"tail":15,"head":33},{"_gvid":27,"tail":15,"head":35},{"_gvid":28,"tail":16,"head":35},{"_gvid":29,"tail":17,"head":36},{"_gvid":30,"tail":18,"head":36},{"_gvid":31,"tail":19,"head":14},{"_gvid":32,"tail":20,"head":14},{"_gvid":33,"tail":21,"head":15},{"_gvid":34,"tail":22,"head":15},{"_gvid":35,"tail":23,"head":15},{"_gvid":36,"tail":24,"head":15},{"_gvid":37,"tail":25,"head":15},{"_gvid":38,"tail":26,"head":16},{"_gvid":39,"tail":27,"head":17},{"_gvid":40,"tail":28,"head":17},{"_gvid":41,"tail":29,"head":17},{"_gvid":42,"tail":30,"head":17},{"_gvid":43,"tail":31,"head":18},{"_gvid":44,"tail":32,"head":37},{"_gvid":45,"tail":33,"head":37},{"_gvid":46,"tail":34,"head":37},{"_gvid":47,"tail":35,"head":37},{"_gvid":48,"tail":36,"head":37},{"_gvid":49,"tail":37,"head":82},{"_gvid":50,"tail":38,"head":82},{"_gvid":51,"tail":39,"head":38},{"_gvid":52,"tail":39,"head":62},{"_gvid":53,"tail":40,"head":61},{"_gvid":54,"tail":41,"head":82},{"_gvid":55,"tail":42,"head":82},{"_gvid":56,"tail":43,"head":82},{"_gvid":57,"tail":44,"head":82},{"_gvid":58,"tail":45,"head":82},{"_gvid":59,"tail":46,"head":82},{"_gvid":60,"tail":47,"head":82},{"_gvid":61,"tail":48,"head":82},{"_gvid":62,"tail":49,"head":40},{"_gvid":63,"tail":49,"head":46},{"_gvid":64,"tail":50,"head":40},{"_gvid":65,"tail":50,"head":47},{"_gvid":66,"tail":51,"head":44},{"_gvid":67,"tail":52,"head":46},{"_gvid":68,"tail":53,"head":45},{"_gvid":69,"tail":54,"head":46},{"_gvid":70,"tail":55,"head":47},{"_gvid":71,"tail":56,"head":41},{"_gvid":72,"tail":56,"head":45},{"_gvid":73,"tail":57,"head":42},{"_gvid":74,"tail":57,"head":48},{"_gvid":75,"tail":58,"head":43},{"_gvid":76,"tail":58,"head":44},{"_gvid":77,"tail":59,"head":44},{"_gvid":78,"tail":59,"head":70},{"_gvid":79,"tail":59,"head":74},{"_gvid":80,"tail":60,"head":46},{"_gvid":81,"tail":60,"head":70},{"_gvid":82,"tail":60,"head":76},{"_gvid":83,"tail":61,"head":45},{"_gvid":84,"tail":61,"head":75},{"_gvid":85,"tail":62,"head":47},{"_gvid":86,"tail":62,"head":70},{"_gvid":87,"tail":62,"head":77},{"_gvid":88,"tail":63,"head":48},{"_gvid":89,"tail":63,"head":71},{"_gvid":90,"tail":63,"head":78},{"_gvid":91,"tail":64,"head":38},{"_gvid":92,"tail":64,"head":62},{"_gvid":93,"tail":65,"head":14},{"_gvid":94,"tail":65,"head":59},{"_gvid":95,"tail":66,"head":15},{"_gvid":96,"tail":66,"head":60},{"_gvid":97,"tail":67,"head":17},{"_gvid":98,"tail":67,"head":63},{"_gvid":99,"tail":68,"head":3},{"_gvid":100,"tail":68,"head":69},{"_gvid":101,"tail":69,"head":82},{"_gvid":102,"tail":70,"head":82},{"_gvid":103,"tail":71,"head":70},{"_gvid":104,"tail":72,"head":70},{"_gvid":105,"tail":73,"head":71},{"_gvid":106,"tail":74,"head":81},{"_gvid":107,"tail":75,"head":81},{"_gvid":108,"tail":76,"head":81},{"_gvid":109,"tail":77,"head":81},{"_gvid":110,"tail":78,"head":81},{"_gvid":111,"tail":79,"head":82},{"_gvid":112,"tail":80,"head":71},{"_gvid":113,"tail":83,"head":1},{"_gvid":114,"tail":83,"head":6},{"_gvid":115,"tail":83,"head":8},{"_gvid":116,"tail":83,"head":9},{"_gvid":117,"tail":83,"head":10},{"_gvid":118,"tail":83,"head":11},{"_gvid":119,"tail":83,"head":12},{"_gvid":120,"tail":83,"head":13},{"_gvid":121,"tail":83,"head":20},{"_gvid":122,"tail":83,"head":21},{"_gvid":123,"tail":83,"head":23},{"_gvid":124,"tail":83,"head":24},{"_gvid":125,"tail":83,"head":25},{"_gvid":126,"tail":83,"head":27},{"_gvid":127,"tail":83,"head":29},{"_gvid":128,"tail":83,"head":30},{"_gvid":129,"tail":83,"head":39},{"_gvid":130,"tail":83,"head":49},{"_gvid":131,"tail":83,"head":50},{"_gvid":132,"tail":83,"head":51},{"_gvid":133,"tail":83,"head":52},{"_gvid":134,"tail":83,"head":53},{"_gvid":135,"tail":83,"head":54},{"_gvid":136,"tail":83,"head":55},{"_gvid":137,"tail":83,"head":56},{"_gvid":138,"tail":83,"head":57},{"_gvid":139,"tail":83,"head":58},{"_gvid":140,"tail":83,"head":64},{"_gvid":141,"tail":83,"head":65},{"_gvid":142,"tail":83,"head":66},{"_gvid":143,"tail":83,"head":67},{"_gvid":144,"tail":83,"head":68},{"_gvid":145,"tail":83,"head":72},{"_gvid":146,"tail":83,"head":73},{"_gvid":147,"tail":83,"head":80},{"_gvid":148,"tail":84,"head":74},{"_gvid":149,"tail":84,"head":75},{"_gvid":150,"tail":84,"head":76},{"_gvid":151,"tail":84,"head":77},{"_gvid":152,"tail":84,"head":78},{"_gvid":153,"tail":85,"head":1},{"_gvid":154,"tail":85,"head":6},{"_gvid":155,"tail":85,"head":8},{"_gvid":156,"tail":85,"head":9},{"_gvid":157,"tail":85,"head":10},{"_gvid":158,"tail":85,"head":11},{"_gvid":159,"tail":85,"head":12},{"_gvid":160,"tail":85,"head":13},{"_gvid":161,"tail":85,"head":20},{"_gvid":162,"tail":85,"head":21},{"_gvid":163,"tail":85,"head":23},{"_gvid":164,"tail":85,"head":24},{"_gvid":165,"tail":85,"head":25},{"_gvid":166,"tail":85,"head":27},{"_gvid":167,"tail":85,"head":29},{"_gvid":168,"tail":85,"head":30},{"_gvid":169,"tail":85,"head":39},{"_gvid":170,"tail":85,"head":49},{"_gvid":171,"tail":85,"head":50},{"_gvid":172,"tail":85,"head":51},{"_gvid":173,"tail":85,"head":52},{"_gvid":174,"tail":85,"head":53},{"_gvid":175,"tail":85,"head":54},{"_gvid":176,"tail":85,"head":55},{"_gvid":177,"tail":85,"head":56},{"_gvid":178,"tail":85,"head":57},{"_gvid":179,"tail":85,"head":58},{"_gvid":180,"tail":85,"head":64},{"_gvid":181,"tail":85,"head":65},{"_gvid":182,"tail":85,"head":66},{"_gvid":183,"tail":85,"head":67},{"_gvid":184,"tail":85,"head":68},{"_gvid":185,"tail":85,"head":72},{"_gvid":186,"tail":85,"head":73},{"_gvid":187,"tail":86,"head":80},{"_gvid":188,"tail":87,"head":80},{"_gvid":189,"tail":88,"head":83},{"_gvid":190,"tail":88,"head":84},{"_gvid":191,"tail":88,"head":85},{"_gvid":192,"tail":88,"head":86},{"_gvid":193,"tail":88,"head":87}]}' + + adj = adjacency_list(json_string) + coordinates = gen_coordinates(adj) + + # # verification + # adj = adjacency_list() + print(adj) + nodes = list(adj.keys()) + nodes.reverse() + X, Y, Z, level = points(adj, len(nodes), nodes, 1) + print(level) + rev = reverse_level(level) + coordinates = connect(X, Y, Z, level, adj) + x = [] + y = [] + z = [] + for level in X.keys(): + x.extend(X[level]) + y.extend(Y[level]) + z.extend(Z[level]) + #print(x) + #print(y) + #print(z) + graph(x, y, z, coordinates, adj, rev, show_level=False) + plt.show() + + # # return + # obj = json.loads(json_string) + # root = obj['objects'][0]['nodes'][-1] + # for each in obj['objects'][1:]: + # each['coord-xyz'] = coordinates[root-each['_gvid']] + + print(coordinates) + + +if __name__== "__main__": + main() \ No newline at end of file diff --git a/dragdrop/package-lock.json b/dragdrop/package-lock.json new file mode 100644 index 0000000..2cb9b10 --- /dev/null +++ b/dragdrop/package-lock.json @@ -0,0 +1,25 @@ +{ + "name": "dragdrop", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/node": { + "version": "12.12.20", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.20.tgz", + "integrity": "sha512-VAe+DiwpnC/g448uN+/3gRl4th0BTdrR9gSLIOHA+SUQskaYZQDOHG7xmjiE7JUhjbXnbXytf6Ih+/pA6CtMFQ==", + "dev": true + }, + "three": { + "version": "0.110.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.110.0.tgz", + "integrity": "sha512-wlurH8XBO9Sd5VIw8nBa+taLR20kqaI4e9FiuMh6tqK8eOS2q2R+ZoUyufbyDTVTHhs8GiTbv0r2CMLkwerFJg==" + }, + "typescript": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", + "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==", + "dev": true + } + } +} diff --git a/example/dist/bundle.js b/example/dist/bundle.js index 97ec7d1..bcc1de2 100644 --- a/example/dist/bundle.js +++ b/example/dist/bundle.js @@ -96,7 +96,7 @@ Object.assign(jh.prototype,{_getValue_unbound:jh.prototype.getValue,_setValue_un * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - */var n;n=function(){"use strict";var e,n="undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:{},r=function(){return/Android/i.test(navigator.userAgent)||/iPhone|iPad|iPod/i.test(navigator.userAgent)},i=function(e,t){for(var n=0,r=e.length;ne.TEXTURE31){console.error("TEXTURE_BINDING_2D or TEXTURE_BINDING_CUBE_MAP must be followed by a valid texture unit"),r.push(null,null);break}i||(i=e.getParameter(e.ACTIVE_TEXTURE)),e.activeTexture(c),r.push(e.getParameter(o),null);break;case e.ACTIVE_TEXTURE:i=e.getParameter(e.ACTIVE_TEXTURE),r.push(null);break;default:r.push(e.getParameter(o))}for(n(e),a=0;ae.TEXTURE31)break;e.activeTexture(c),e.bindTexture(e.TEXTURE_2D,s);break;case e.TEXTURE_BINDING_CUBE_MAP:var c;if((c=t[++a])e.TEXTURE31)break;e.activeTexture(c),e.bindTexture(e.TEXTURE_CUBE_MAP,s);break;case e.VIEWPORT:e.viewport(s[0],s[1],s[2],s[3]);break;case e.BLEND:case e.CULL_FACE:case e.DEPTH_TEST:case e.SCISSOR_TEST:case e.STENCIL_TEST:s?e.enable(o):e.disable(o);break;default:console.log("No GL restore behavior for 0x"+o.toString(16))}i&&e.activeTexture(i)}}else n(e)},L=["attribute vec2 position;","attribute vec3 texCoord;","varying vec2 vTexCoord;","uniform vec4 viewportOffsetScale[2];","void main() {"," vec4 viewport = viewportOffsetScale[int(texCoord.z)];"," vTexCoord = (texCoord.xy * viewport.zw) + viewport.xy;"," gl_Position = vec4( position, 1.0, 1.0 );","}"].join("\n"),R=["precision mediump float;","uniform sampler2D diffuse;","varying vec2 vTexCoord;","void main() {"," gl_FragColor = texture2D(diffuse, vTexCoord);","}"].join("\n");function C(e,t,n,r){this.gl=e,this.cardboardUI=t,this.bufferScale=n,this.dirtySubmitFrameBindings=r,this.ctxAttribs=e.getContextAttributes(),this.meshWidth=20,this.meshHeight=20,this.bufferWidth=e.drawingBufferWidth,this.bufferHeight=e.drawingBufferHeight,this.realBindFramebuffer=e.bindFramebuffer,this.realEnable=e.enable,this.realDisable=e.disable,this.realColorMask=e.colorMask,this.realClearColor=e.clearColor,this.realViewport=e.viewport,c()||(this.realCanvasWidth=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"width"),this.realCanvasHeight=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"height")),this.isPatched=!1,this.lastBoundFramebuffer=null,this.cullFace=!1,this.depthTest=!1,this.blend=!1,this.scissorTest=!1,this.stencilTest=!1,this.viewport=[0,0,0,0],this.colorMask=[!0,!0,!0,!0],this.clearColor=[0,0,0,0],this.attribs={position:0,texCoord:1},this.program=y(e,L,R,this.attribs),this.uniforms=A(e,this.program),this.viewportOffsetScale=new Float32Array(8),this.setTextureBounds(),this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),this.indexCount=0,this.renderTarget=e.createTexture(),this.framebuffer=e.createFramebuffer(),this.depthStencilBuffer=null,this.depthBuffer=null,this.stencilBuffer=null,this.ctxAttribs.depth&&this.ctxAttribs.stencil?this.depthStencilBuffer=e.createRenderbuffer():this.ctxAttribs.depth?this.depthBuffer=e.createRenderbuffer():this.ctxAttribs.stencil&&(this.stencilBuffer=e.createRenderbuffer()),this.patch(),this.onResize()}C.prototype.destroy=function(){var e=this.gl;this.unpatch(),e.deleteProgram(this.program),e.deleteBuffer(this.vertexBuffer),e.deleteBuffer(this.indexBuffer),e.deleteTexture(this.renderTarget),e.deleteFramebuffer(this.framebuffer),this.depthStencilBuffer&&e.deleteRenderbuffer(this.depthStencilBuffer),this.depthBuffer&&e.deleteRenderbuffer(this.depthBuffer),this.stencilBuffer&&e.deleteRenderbuffer(this.stencilBuffer),this.cardboardUI&&this.cardboardUI.destroy()},C.prototype.onResize=function(){var e=this.gl,t=this,n=[e.RENDERBUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0];T(e,n,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.framebuffer),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.texImage2D(e.TEXTURE_2D,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,t.bufferWidth,t.bufferHeight,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.renderTarget,0),t.ctxAttribs.depth&&t.ctxAttribs.stencil?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthStencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,t.depthStencilBuffer)):t.ctxAttribs.depth?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t.depthBuffer)):t.ctxAttribs.stencil&&(e.bindRenderbuffer(e.RENDERBUFFER,t.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.STENCIL_INDEX8,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.STENCIL_ATTACHMENT,e.RENDERBUFFER,t.stencilBuffer)),!e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer incomplete!"),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),t.realClearColor.apply(e,t.clearColor)})),this.cardboardUI&&this.cardboardUI.onResize()},C.prototype.patch=function(){if(!this.isPatched){var e=this,t=this.gl.canvas,n=this.gl;c()||(t.width=m()*this.bufferScale,t.height=v()*this.bufferScale,Object.defineProperty(t,"width",{configurable:!0,enumerable:!0,get:function(){return e.bufferWidth},set:function(n){e.bufferWidth=n,e.realCanvasWidth.set.call(t,n),e.onResize()}}),Object.defineProperty(t,"height",{configurable:!0,enumerable:!0,get:function(){return e.bufferHeight},set:function(n){e.bufferHeight=n,e.realCanvasHeight.set.call(t,n),e.onResize()}})),this.lastBoundFramebuffer=n.getParameter(n.FRAMEBUFFER_BINDING),null==this.lastBoundFramebuffer&&(this.lastBoundFramebuffer=this.framebuffer,this.gl.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer)),this.gl.bindFramebuffer=function(t,r){e.lastBoundFramebuffer=r||e.framebuffer,e.realBindFramebuffer.call(n,t,e.lastBoundFramebuffer)},this.cullFace=n.getParameter(n.CULL_FACE),this.depthTest=n.getParameter(n.DEPTH_TEST),this.blend=n.getParameter(n.BLEND),this.scissorTest=n.getParameter(n.SCISSOR_TEST),this.stencilTest=n.getParameter(n.STENCIL_TEST),n.enable=function(t){switch(t){case n.CULL_FACE:e.cullFace=!0;break;case n.DEPTH_TEST:e.depthTest=!0;break;case n.BLEND:e.blend=!0;break;case n.SCISSOR_TEST:e.scissorTest=!0;break;case n.STENCIL_TEST:e.stencilTest=!0}e.realEnable.call(n,t)},n.disable=function(t){switch(t){case n.CULL_FACE:e.cullFace=!1;break;case n.DEPTH_TEST:e.depthTest=!1;break;case n.BLEND:e.blend=!1;break;case n.SCISSOR_TEST:e.scissorTest=!1;break;case n.STENCIL_TEST:e.stencilTest=!1}e.realDisable.call(n,t)},this.colorMask=n.getParameter(n.COLOR_WRITEMASK),n.colorMask=function(t,r,i,a){e.colorMask[0]=t,e.colorMask[1]=r,e.colorMask[2]=i,e.colorMask[3]=a,e.realColorMask.call(n,t,r,i,a)},this.clearColor=n.getParameter(n.COLOR_CLEAR_VALUE),n.clearColor=function(t,r,i,a){e.clearColor[0]=t,e.clearColor[1]=r,e.clearColor[2]=i,e.clearColor[3]=a,e.realClearColor.call(n,t,r,i,a)},this.viewport=n.getParameter(n.VIEWPORT),n.viewport=function(t,r,i,a){e.viewport[0]=t,e.viewport[1]=r,e.viewport[2]=i,e.viewport[3]=a,e.realViewport.call(n,t,r,i,a)},this.isPatched=!0,b(t)}},C.prototype.unpatch=function(){if(this.isPatched){var e=this.gl,t=this.gl.canvas;c()||(Object.defineProperty(t,"width",this.realCanvasWidth),Object.defineProperty(t,"height",this.realCanvasHeight)),t.width=this.bufferWidth,t.height=this.bufferHeight,e.bindFramebuffer=this.realBindFramebuffer,e.enable=this.realEnable,e.disable=this.realDisable,e.colorMask=this.realColorMask,e.clearColor=this.realClearColor,e.viewport=this.realViewport,this.lastBoundFramebuffer==this.framebuffer&&e.bindFramebuffer(e.FRAMEBUFFER,null),this.isPatched=!1,setTimeout((function(){b(t)}),1)}},C.prototype.setTextureBounds=function(e,t){e||(e=[0,0,.5,1]),t||(t=[.5,0,.5,1]),this.viewportOffsetScale[0]=e[0],this.viewportOffsetScale[1]=e[1],this.viewportOffsetScale[2]=e[2],this.viewportOffsetScale[3]=e[3],this.viewportOffsetScale[4]=t[0],this.viewportOffsetScale[5]=t[1],this.viewportOffsetScale[6]=t[2],this.viewportOffsetScale[7]=t[3]},C.prototype.submitFrame=function(){var e=this.gl,t=this,n=[];if(this.dirtySubmitFrameBindings||n.push(e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING,e.ELEMENT_ARRAY_BUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0),T(e,n,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),t.cullFace&&t.realDisable.call(e,e.CULL_FACE),t.depthTest&&t.realDisable.call(e,e.DEPTH_TEST),t.blend&&t.realDisable.call(e,e.BLEND),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realDisable.call(e,e.STENCIL_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),(t.ctxAttribs.alpha||c())&&(t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT)),e.useProgram(t.program),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.indexBuffer),e.bindBuffer(e.ARRAY_BUFFER,t.vertexBuffer),e.enableVertexAttribArray(t.attribs.position),e.enableVertexAttribArray(t.attribs.texCoord),e.vertexAttribPointer(t.attribs.position,2,e.FLOAT,!1,20,0),e.vertexAttribPointer(t.attribs.texCoord,3,e.FLOAT,!1,20,8),e.activeTexture(e.TEXTURE0),e.uniform1i(t.uniforms.diffuse,0),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.uniform4fv(t.uniforms.viewportOffsetScale,t.viewportOffsetScale),e.drawElements(e.TRIANGLES,t.indexCount,e.UNSIGNED_SHORT,0),t.cardboardUI&&t.cardboardUI.renderNoState(),t.realBindFramebuffer.call(t.gl,e.FRAMEBUFFER,t.framebuffer),t.ctxAttribs.preserveDrawingBuffer||(t.realClearColor.call(e,0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)),t.dirtySubmitFrameBindings||t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.cullFace&&t.realEnable.call(e,e.CULL_FACE),t.depthTest&&t.realEnable.call(e,e.DEPTH_TEST),t.blend&&t.realEnable.call(e,e.BLEND),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realEnable.call(e,e.STENCIL_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),!t.ctxAttribs.alpha&&t.ctxAttribs.preserveDrawingBuffer||t.realClearColor.apply(e,t.clearColor)})),c()){var r=e.canvas;r.width==t.bufferWidth&&r.height==t.bufferHeight||(t.bufferWidth=r.width,t.bufferHeight=r.height,t.onResize())}},C.prototype.updateDeviceInfo=function(e){var t=this.gl,n=this,r=[t.ARRAY_BUFFER_BINDING,t.ELEMENT_ARRAY_BUFFER_BINDING];T(t,r,(function(t){var r=n.computeMeshVertices_(n.meshWidth,n.meshHeight,e);if(t.bindBuffer(t.ARRAY_BUFFER,n.vertexBuffer),t.bufferData(t.ARRAY_BUFFER,r,t.STATIC_DRAW),!n.indexCount){var i=n.computeMeshIndices_(n.meshWidth,n.meshHeight);t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,n.indexBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i,t.STATIC_DRAW),n.indexCount=i.length}}))},C.prototype.computeMeshVertices_=function(e,t,n){for(var r=new Float32Array(2*e*t*5),i=n.getLeftEyeVisibleTanAngles(),a=n.getLeftEyeNoLensTanAngles(),o=n.getLeftEyeVisibleScreenRect(a),c=0,l=0;l<2;l++){for(var u=0;ui-42&&r.clientXn.clientHeight-42?e(r):r.clientX<42&&r.clientY<42&&t(r)},n.addEventListener("click",this.listener,!1)},B.prototype.onResize=function(){var e=this.gl,t=this,n=[e.ARRAY_BUFFER_BINDING];T(e,n,(function(e){var n=[],r=e.drawingBufferWidth/2,i=Math.max(screen.width,screen.height)*window.devicePixelRatio,a=e.drawingBufferWidth/i*window.devicePixelRatio,o=4*a/2,s=42*a,c=28*a/2,l=14*a;function u(e,t){var i=(90-e)*I,a=Math.cos(i),o=Math.sin(i);n.push(O*a*c+r,O*o*c+c),n.push(t*a*c+r,t*o*c+c)}n.push(r-o,s),n.push(r-o,e.drawingBufferHeight),n.push(r+o,s),n.push(r+o,e.drawingBufferHeight),t.gearOffset=n.length/2;for(var h=0;h<=6;h++){var d=60*h;u(d,1),u(d+12,1),u(d+20,.75),u(d+40,.75),u(d+48,1)}function p(t,r){n.push(l+t,e.drawingBufferHeight-l-r)}t.gearVertexCount=n.length/2-t.gearOffset,t.arrowOffset=n.length/2;var f=o/Math.sin(45*I);p(0,c),p(c,0),p(c+f,f),p(f,c+f),p(f,c-f),p(0,c),p(c,2*c),p(c+f,2*c-f),p(f,c-f),p(0,c),p(f,c-o),p(28*a,c-o),p(f,c+o),p(28*a,c+o),t.arrowVertexCount=n.length/2-t.arrowOffset,e.bindBuffer(e.ARRAY_BUFFER,t.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array(n),e.STATIC_DRAW)}))},B.prototype.render=function(){var e=this.gl,t=this,n=[e.CULL_FACE,e.DEPTH_TEST,e.BLEND,e.SCISSOR_TEST,e.STENCIL_TEST,e.COLOR_WRITEMASK,e.VIEWPORT,e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING];T(e,n,(function(e){e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.colorMask(!0,!0,!0,!0),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.renderNoState()}))},B.prototype.renderNoState=function(){var e,t,n,r,i,a,o,s,c,l,u=this.gl;u.useProgram(this.program),u.bindBuffer(u.ARRAY_BUFFER,this.vertexBuffer),u.enableVertexAttribArray(this.attribs.position),u.vertexAttribPointer(this.attribs.position,2,u.FLOAT,!1,8,0),u.uniform4f(this.uniforms.color,1,1,1,1),e=this.projMat,t=0,n=u.drawingBufferWidth,r=0,i=u.drawingBufferHeight,s=1/(t-n),c=1/(r-i),l=1/((a=.1)-(o=1024)),e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*s,e[13]=(i+r)*c,e[14]=(o+a)*l,e[15]=1,u.uniformMatrix4fv(this.uniforms.projectionMat,!1,this.projMat),u.drawArrays(u.TRIANGLE_STRIP,0,4),u.drawArrays(u.TRIANGLE_STRIP,this.gearOffset,this.gearVertexCount),u.drawArrays(u.TRIANGLE_STRIP,this.arrowOffset,this.arrowVertexCount)},N.prototype.distortInverse=function(e){for(var t=0,n=1,r=e-this.distort(t);Math.abs(n-t)>1e-4;){var i=e-this.distort(n),a=n-i*((n-t)/(i-r));t=n,n=a,r=i}return n},N.prototype.distort=function(e){for(var t=e*e,n=0,r=0;r=1)return this.w=a,this.x=n,this.y=r,this.z=i,this;var s=Math.acos(o),c=Math.sqrt(1-o*o);if(Math.abs(c)<.001)return this.w=.5*(a+this.w),this.x=.5*(n+this.x),this.y=.5*(r+this.y),this.z=.5*(i+this.z),this;var l=Math.sin((1-t)*s)/c,u=Math.sin(t*s)/c;return this.w=a*l+this.w*u,this.x=n*l+this.x*u,this.y=r*l+this.y*u,this.z=i*l+this.z*u,this},setFromUnitVectors:function(e,t){return void 0===U&&(U=new z),(H=e.dot(t)+1)<1e-6?(H=0,Math.abs(e.x)>Math.abs(e.z)?U.set(-e.y,e.x,0):U.set(0,-e.z,e.y)):U.crossVectors(e,t),this.x=U.x,this.y=U.y,this.z=U.z,this.w=H,this.normalize(),this}};var j=new k({widthMeters:.11,heightMeters:.062,bevelMeters:.004}),W=new k({widthMeters:.1038,heightMeters:.0584,bevelMeters:.004}),X={CardboardV1:new Q({id:"CardboardV1",label:"Cardboard I/O 2014",fov:40,interLensDistance:.06,baselineLensDistance:.035,screenLensDistance:.042,distortionCoefficients:[.441,.156],inverseCoefficients:[-.4410035,.42756155,-.4804439,.5460139,-.58821183,.5733938,-.48303202,.33299083,-.17573841,.0651772,-.01488963,.001559834]}),CardboardV2:new Q({id:"CardboardV2",label:"Cardboard I/O 2015",fov:60,interLensDistance:.064,baselineLensDistance:.035,screenLensDistance:.039,distortionCoefficients:[.34,.55],inverseCoefficients:[-.33836704,-.18162185,.862655,-1.2462051,1.0560602,-.58208317,.21609078,-.05444823,.009177956,-.0009904169,6183535e-11,-16981803e-13]})};function q(e,t){this.viewer=X.CardboardV2,this.updateDeviceParams(e),this.distortion=new N(this.viewer.distortionCoefficients);for(var n=0;n=200&&n.status<=299?(r.dpdb=JSON.parse(n.response),r.recalculateDeviceParams_()):console.error("Error loading online DPDB!")})),n.send()}}function J(e){this.xdpi=e.xdpi,this.ydpi=e.ydpi,this.bevelMm=e.bevelMm}function K(e,t){this.set(e,t)}function $(e,t){this.kFilter=e,this.isDebug=t,this.currentAccelMeasurement=new K,this.currentGyroMeasurement=new K,this.previousGyroMeasurement=new K,c()?this.filterQ=new V(-1,0,0,1):this.filterQ=new V(1,0,0,1),this.previousFilterQ=new V,this.previousFilterQ.copy(this.filterQ),this.accelQ=new V,this.isOrientationInitialized=!1,this.estimatedGravity=new z,this.measuredGravity=new z,this.gyroIntegralQ=new V}function ee(e,t){this.predictionTimeS=e,this.isDebug=t,this.previousQ=new V,this.previousTimestampS=null,this.deltaQ=new V,this.outQ=new V}function te(e,t,n,r){this.yawOnly=n,this.accelerometer=new z,this.gyroscope=new z,this.filter=new $(e,r),this.posePredictor=new ee(t,r),this.isFirefoxAndroid=u(),this.isIOS=c();var i=h();this.isDeviceMotionInRadians=!this.isIOS&&i&&i<66,this.isWithoutDeviceMotion=d(),this.filterToWorldQ=new V,c()?this.filterToWorldQ.setFromAxisAngle(new z(1,0,0),Math.PI/2):this.filterToWorldQ.setFromAxisAngle(new z(1,0,0),-Math.PI/2),this.inverseWorldToScreenQ=new V,this.worldToScreenQ=new V,this.originalPoseAdjustQ=new V,this.originalPoseAdjustQ.setFromAxisAngle(new z(0,0,1),-window.orientation*Math.PI/180),this.setScreenTransform_(),f()&&this.filterToWorldQ.multiply(this.inverseWorldToScreenQ),this.resetQ=new V,this.orientationOut_=new Float32Array(4),this.start()}Z.prototype.getDeviceParams=function(){return this.deviceParams},Z.prototype.recalculateDeviceParams_=function(){var e=this.calcDeviceParams_();e?(this.deviceParams=e,this.onDeviceParamsUpdated&&this.onDeviceParamsUpdated(this.deviceParams)):console.error("Failed to recalculate device parameters.")},Z.prototype.calcDeviceParams_=function(){var e=this.dpdb;if(!e)return console.error("DPDB not available."),null;if(1!=e.format)return console.error("DPDB has unexpected format version."),null;if(!e.devices||!e.devices.length)return console.error("DPDB does not have a devices section."),null;var t=navigator.userAgent||navigator.vendor||window.opera,n=m(),r=v();if(!e.devices)return console.error("DPDB has no devices section."),null;for(var i=0;i1||this.run_(),this.previousGyroMeasurement.copy(this.currentGyroMeasurement)},$.prototype.run_=function(){if(!this.isOrientationInitialized)return this.accelQ=this.accelToQuaternion_(this.currentAccelMeasurement.sample),this.previousFilterQ.copy(this.accelQ),void(this.isOrientationInitialized=!0);var e=this.currentGyroMeasurement.timestampS-this.previousGyroMeasurement.timestampS,t=this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample,e);this.gyroIntegralQ.multiply(t),this.filterQ.copy(this.previousFilterQ),this.filterQ.multiply(t);var n=new V;n.copy(this.filterQ),n.inverse(),this.estimatedGravity.set(0,0,-1),this.estimatedGravity.applyQuaternion(n),this.estimatedGravity.normalize(),this.measuredGravity.copy(this.currentAccelMeasurement.sample),this.measuredGravity.normalize();var r,i=new V;i.setFromUnitVectors(this.estimatedGravity,this.measuredGravity),i.inverse(),this.isDebug&&console.log("Delta: %d deg, G_est: (%s, %s, %s), G_meas: (%s, %s, %s)",G*((r=i).w>1?(console.warn("getQuaternionAngle: w > 1"),0):2*Math.acos(r.w)),this.estimatedGravity.x.toFixed(1),this.estimatedGravity.y.toFixed(1),this.estimatedGravity.z.toFixed(1),this.measuredGravity.x.toFixed(1),this.measuredGravity.y.toFixed(1),this.measuredGravity.z.toFixed(1));var a=new V;a.copy(this.filterQ),a.multiply(i),this.filterQ.slerp(a,1-this.kFilter),this.previousFilterQ.copy(this.filterQ)},$.prototype.getOrientation=function(){return this.filterQ},$.prototype.accelToQuaternion_=function(e){var t=new z;t.copy(e),t.normalize();var n=new V;return n.setFromUnitVectors(new z(0,0,-1),t),n.inverse(),n},$.prototype.gyroToQuaternionDelta_=function(e,t){var n=new V,r=new z;return r.copy(e),r.normalize(),n.setFromAxisAngle(r,e.length()*t),n},ee.prototype.getPrediction=function(e,t,n){if(!this.previousTimestampS)return this.previousQ.copy(e),this.previousTimestampS=n,e;var r=new z;r.copy(t),r.normalize();var i=t.length();if(i<20*F)return this.isDebug&&console.log("Moving slowly, at %s deg/s: no prediction",(G*i).toFixed(1)),this.outQ.copy(e),this.previousQ.copy(e),this.outQ;var a=i*this.predictionTimeS;return this.deltaQ.setFromAxisAngle(r,a),this.outQ.copy(this.previousQ),this.outQ.multiply(this.deltaQ),this.previousQ.copy(e),this.previousTimestampS=n,this.outQ},te.prototype.getPosition=function(){return null},te.prototype.getOrientation=function(){var e=void 0;if(this.isWithoutDeviceMotion&&this._deviceOrientationQ)return this.deviceOrientationFixQ=this.deviceOrientationFixQ||(n=(new V).setFromAxisAngle(new z(0,0,-1),0),r=new V,-90===window.orientation?r.setFromAxisAngle(new z(0,1,0),Math.PI/-2):r.setFromAxisAngle(new z(0,1,0),Math.PI/2),n.multiply(r)),this.deviceOrientationFilterToWorldQ=this.deviceOrientationFilterToWorldQ||((t=new V).setFromAxisAngle(new z(1,0,0),-Math.PI/2),t),e=this._deviceOrientationQ,(i=new V).copy(e),i.multiply(this.deviceOrientationFilterToWorldQ),i.multiply(this.resetQ),i.multiply(this.worldToScreenQ),i.multiplyQuaternions(this.deviceOrientationFixQ,i),this.yawOnly&&(i.x=0,i.z=0,i.normalize()),this.orientationOut_[0]=i.x,this.orientationOut_[1]=i.y,this.orientationOut_[2]=i.z,this.orientationOut_[3]=i.w,this.orientationOut_;var t,n,r,i,a=this.filter.getOrientation();return e=this.posePredictor.getPrediction(a,this.gyroscope,this.previousTimestampS),(i=new V).copy(this.filterToWorldQ),i.multiply(this.resetQ),i.multiply(e),i.multiply(this.worldToScreenQ),this.yawOnly&&(i.x=0,i.z=0,i.normalize()),this.orientationOut_[0]=i.x,this.orientationOut_[1]=i.y,this.orientationOut_[2]=i.z,this.orientationOut_[3]=i.w,this.orientationOut_},te.prototype.resetPose=function(){this.resetQ.copy(this.filter.getOrientation()),this.resetQ.x=0,this.resetQ.y=0,this.resetQ.z*=-1,this.resetQ.normalize(),f()&&this.resetQ.multiply(this.inverseWorldToScreenQ),this.resetQ.multiply(this.originalPoseAdjustQ)},te.prototype.onDeviceOrientation_=function(e){this._deviceOrientationQ=this._deviceOrientationQ||new V;var t=e.alpha,n=e.beta,r=e.gamma;t=(t||0)*Math.PI/180,n=(n||0)*Math.PI/180,r=(r||0)*Math.PI/180,this._deviceOrientationQ.setFromEulerYXZ(n,t,-r)},te.prototype.onDeviceMotion_=function(e){this.updateDeviceMotion_(e)},te.prototype.updateDeviceMotion_=function(e){var t=e.accelerationIncludingGravity,n=e.rotationRate,r=e.timeStamp/1e3,i=r-this.previousTimestampS;return i<0?(E("fusion-pose-sensor:invalid:non-monotonic","Invalid timestamps detected: non-monotonic timestamp from devicemotion"),void(this.previousTimestampS=r)):i<=.001||i>1?(E("fusion-pose-sensor:invalid:outside-threshold","Invalid timestamps detected: Timestamp from devicemotion outside expected range."),void(this.previousTimestampS=r)):(this.accelerometer.set(-t.x,-t.y,-t.z),p()?this.gyroscope.set(-n.beta,n.alpha,n.gamma):this.gyroscope.set(n.alpha,n.beta,n.gamma),this.isDeviceMotionInRadians||this.gyroscope.multiplyScalar(Math.PI/180),this.filter.addAccelMeasurement(this.accelerometer,r),this.filter.addGyroMeasurement(this.gyroscope,r),void(this.previousTimestampS=r))},te.prototype.onOrientationChange_=function(e){this.setScreenTransform_()},te.prototype.onMessage_=function(e){var t=e.data;t&&t.type&&"devicemotion"===t.type.toLowerCase()&&this.updateDeviceMotion_(t.deviceMotionEvent)},te.prototype.setScreenTransform_=function(){switch(this.worldToScreenQ.set(0,0,0,1),window.orientation){case 0:break;case 90:this.worldToScreenQ.setFromAxisAngle(new z(0,0,1),-Math.PI/2);break;case-90:this.worldToScreenQ.setFromAxisAngle(new z(0,0,1),Math.PI/2)}this.inverseWorldToScreenQ.copy(this.worldToScreenQ),this.inverseWorldToScreenQ.inverse()},te.prototype.start=function(){var e,t,n;this.onDeviceMotionCallback_=this.onDeviceMotion_.bind(this),this.onOrientationChangeCallback_=this.onOrientationChange_.bind(this),this.onMessageCallback_=this.onMessage_.bind(this),this.onDeviceOrientationCallback_=this.onDeviceOrientation_.bind(this),c()&&(e=window.self!==window.top,t=M(document.referrer),n=M(window.location.href),e&&t!==n)&&window.addEventListener("message",this.onMessageCallback_),window.addEventListener("orientationchange",this.onOrientationChangeCallback_),this.isWithoutDeviceMotion?window.addEventListener("deviceorientation",this.onDeviceOrientationCallback_):window.addEventListener("devicemotion",this.onDeviceMotionCallback_)},te.prototype.stop=function(){window.removeEventListener("devicemotion",this.onDeviceMotionCallback_),window.removeEventListener("deviceorientation",this.onDeviceOrientationCallback_),window.removeEventListener("orientationchange",this.onOrientationChangeCallback_),window.removeEventListener("message",this.onMessageCallback_)};var ne=new z(1,0,0),re=new z(0,0,1),ie=new V;ie.setFromAxisAngle(ne,-Math.PI/2),ie.multiply((new V).setFromAxisAngle(re,Math.PI/2));var ae=function(){function e(t){i(this,e),this.config=t,this.sensor=null,this.fusionSensor=null,this._out=new Float32Array(4),this.api=null,this.errors=[],this._sensorQ=new V,this._outQ=new V,this._onSensorRead=this._onSensorRead.bind(this),this._onSensorError=this._onSensorError.bind(this),this.init()}return a(e,[{key:"init",value:function(){var e=null;try{(e=new RelativeOrientationSensor({frequency:60,referenceFrame:"screen"})).addEventListener("error",this._onSensorError)}catch(e){this.errors.push(e),"SecurityError"===e.name?(console.error("Cannot construct sensors due to the Feature Policy"),console.warn('Attempting to fall back using "devicemotion"; however this will fail in the future without correct permissions.'),this.useDeviceMotion()):"ReferenceError"===e.name?this.useDeviceMotion():console.error(e)}e&&(this.api="sensor",this.sensor=e,this.sensor.addEventListener("reading",this._onSensorRead),this.sensor.start())}},{key:"useDeviceMotion",value:function(){this.api="devicemotion",this.fusionSensor=new te(this.config.K_FILTER,this.config.PREDICTION_TIME_S,this.config.YAW_ONLY,this.config.DEBUG),this.sensor&&(this.sensor.removeEventListener("reading",this._onSensorRead),this.sensor.removeEventListener("error",this._onSensorError),this.sensor=null)}},{key:"getOrientation",value:function(){if(this.fusionSensor)return this.fusionSensor.getOrientation();if(!this.sensor||!this.sensor.quaternion)return this._out[0]=this._out[1]=this._out[2]=0,this._out[3]=1,this._out;var e=this.sensor.quaternion;this._sensorQ.set(e[0],e[1],e[2],e[3]);var t=this._outQ;return t.copy(ie),t.multiply(this._sensorQ),this.config.YAW_ONLY&&(t.x=t.z=0,t.normalize()),this._out[0]=t.x,this._out[1]=t.y,this._out[2]=t.z,this._out[3]=t.w,this._out}},{key:"_onSensorError",value:function(e){this.errors.push(e.error),"NotAllowedError"===e.error.name?console.error("Permission to access sensor was denied"):"NotReadableError"===e.error.name?console.error("Sensor could not be read"):console.error(e.error),this.useDeviceMotion()}},{key:"_onSensorRead",value:function(){}}]),e}();function oe(){this.loadIcon_();var e=document.createElement("div");(a=e.style).position="fixed",a.top=0,a.right=0,a.bottom=0,a.left=0,a.backgroundColor="gray",a.fontFamily="sans-serif",a.zIndex=1e6;var t=document.createElement("img");t.src=this.icon,(a=t.style).marginLeft="25%",a.marginTop="25%",a.width="50%",e.appendChild(t);var n=document.createElement("div");(a=n.style).textAlign="center",a.fontSize="16px",a.lineHeight="24px",a.margin="24px 25%",a.width="50%",n.innerHTML="Place your phone into your Cardboard viewer.",e.appendChild(n);var r=document.createElement("div");(a=r.style).backgroundColor="#CFD8DC",a.position="fixed",a.bottom=0,a.width="100%",a.height="48px",a.padding="14px 24px",a.boxSizing="border-box",a.color="#656A6B",e.appendChild(r);var i=document.createElement("div");i.style.float="left",i.innerHTML="No Cardboard viewer?";var a,o=document.createElement("a");o.href="https://www.google.com/get/cardboard/get-cardboard/",o.innerHTML="get one",o.target="_blank",(a=o.style).float="right",a.fontWeight=600,a.textTransform="uppercase",a.borderLeft="1px solid gray",a.paddingLeft="24px",a.textDecoration="none",a.color="#656A6B",r.appendChild(i),r.appendChild(o),this.overlay=e,this.text=n,this.hide()}oe.prototype.show=function(e){e||this.overlay.parentElement?e&&(this.overlay.parentElement&&this.overlay.parentElement!=e&&this.overlay.parentElement.removeChild(this.overlay),e.appendChild(this.overlay)):document.body.appendChild(this.overlay),this.overlay.style.display="block";var t=this.overlay.querySelector("img").style;f()?(t.width="20%",t.marginLeft="40%",t.marginTop="3%"):(t.width="50%",t.marginLeft="25%",t.marginTop="25%")},oe.prototype.hide=function(){this.overlay.style.display="none"},oe.prototype.showTemporarily=function(e,t){this.show(t),this.timer=setTimeout(this.hide.bind(this),e)},oe.prototype.disableShowTemporarily=function(){clearTimeout(this.timer)},oe.prototype.update=function(){this.disableShowTemporarily(),!f()&&x()?this.show():this.hide()},oe.prototype.loadIcon_=function(){this.icon="data:image/svg+xml,"+encodeURIComponent("")};var se="CardboardV1",ce="WEBVR_CARDBOARD_VIEWER";function le(e){try{this.selectedKey=localStorage.getItem(ce)}catch(e){console.error("Failed to load viewer profile: %s",e)}this.selectedKey||(this.selectedKey=e||se),this.dialog=this.createDialog_(q.Viewers),this.root=null,this.onChangeCallbacks_=[]}le.prototype.show=function(e){this.root=e,e.appendChild(this.dialog),this.dialog.querySelector("#"+this.selectedKey).checked=!0,this.dialog.style.display="block"},le.prototype.hide=function(){this.root&&this.root.contains(this.dialog)&&this.root.removeChild(this.dialog),this.dialog.style.display="none"},le.prototype.getCurrentViewer=function(){return q.Viewers[this.selectedKey]},le.prototype.getSelectedKey_=function(){var e=this.dialog.querySelector("input[name=field]:checked");return e?e.id:null},le.prototype.onChange=function(e){this.onChangeCallbacks_.push(e)},le.prototype.fireOnChange_=function(e){for(var t=0;t.5&&(this.noSleepVideo.currentTime=Math.random())}.bind(this)))}return r(e,[{key:"enable",value:function(){a?(this.disable(),this.noSleepTimer=window.setInterval((function(){window.location.href="/",window.setTimeout(window.stop,0)}),15e3)):this.noSleepVideo.play()}},{key:"disable",value:function(){a?this.noSleepTimer&&(window.clearInterval(this.noSleepTimer),this.noSleepTimer=null):this.noSleepVideo.pause()}}]),e}();e.exports=o},function(e,t,n){e.exports="data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAACKBtZGF0AAAC8wYF///v3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0MiByMjQ3OSBkZDc5YTYxIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxNCAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTEgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MToweDExMSBtZT1oZXggc3VibWU9MiBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0wIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MCA4eDhkY3Q9MCBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0wIHRocmVhZHM9NiBsb29rYWhlYWRfdGhyZWFkcz0xIHNsaWNlZF90aHJlYWRzPTAgbnI9MCBkZWNpbWF0ZT0xIGludGVybGFjZWQ9MCBibHVyYXlfY29tcGF0PTAgY29uc3RyYWluZWRfaW50cmE9MCBiZnJhbWVzPTMgYl9weXJhbWlkPTIgYl9hZGFwdD0xIGJfYmlhcz0wIGRpcmVjdD0xIHdlaWdodGI9MSBvcGVuX2dvcD0wIHdlaWdodHA9MSBrZXlpbnQ9MzAwIGtleWludF9taW49MzAgc2NlbmVjdXQ9NDAgaW50cmFfcmVmcmVzaD0wIHJjX2xvb2thaGVhZD0xMCByYz1jcmYgbWJ0cmVlPTEgY3JmPTIwLjAgcWNvbXA9MC42MCBxcG1pbj0wIHFwbWF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AAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAAO2lsc3QAAAAzqXRvbwAAACtkYXRhAAAAAQAAAABIYW5kQnJha2UgMC4xMC4yIDIwMTUwNjExMDA="}])}))})))&&ue.__esModule&&Object.prototype.hasOwnProperty.call(ue,"default")?ue.default:ue,de=1e3,pe=[0,0,.5,1],fe=[.5,0,.5,1],me=window.requestAnimationFrame,ve=window.cancelAnimationFrame;function ge(e){Object.defineProperties(this,{hasPosition:{writable:!1,enumerable:!0,value:e.hasPosition},hasExternalDisplay:{writable:!1,enumerable:!0,value:e.hasExternalDisplay},canPresent:{writable:!1,enumerable:!0,value:e.canPresent},maxLayers:{writable:!1,enumerable:!0,value:e.maxLayers},hasOrientation:{enumerable:!0,get:function(){return S("VRDisplayCapabilities.prototype.hasOrientation","VRDisplay.prototype.getFrameData"),e.hasOrientation}}})}function ye(e){var t=!("wakelock"in(e=e||{}))||e.wakelock;this.isPolyfilled=!0,this.displayId=de++,this.displayName="",this.depthNear=.01,this.depthFar=1e4,this.isPresenting=!1,Object.defineProperty(this,"isConnected",{get:function(){return S("VRDisplay.prototype.isConnected","VRDisplayCapabilities.prototype.hasExternalDisplay"),!1}}),this.capabilities=new ge({hasPosition:!1,hasOrientation:!1,hasExternalDisplay:!1,canPresent:!1,maxLayers:1}),this.stageParameters=null,this.waitingForPresent_=!1,this.layer_=null,this.originalParent_=null,this.fullscreenElement_=null,this.fullscreenWrapper_=null,this.fullscreenElementCachedStyle_=null,this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null,t&&x()&&(this.wakelock_=new he)}ye.prototype.getFrameData=function(e){return _(e,this._getPose(),this)},ye.prototype.getPose=function(){return S("VRDisplay.prototype.getPose","VRDisplay.prototype.getFrameData"),this._getPose()},ye.prototype.resetPose=function(){return S("VRDisplay.prototype.resetPose"),this._resetPose()},ye.prototype.getImmediatePose=function(){return S("VRDisplay.prototype.getImmediatePose","VRDisplay.prototype.getFrameData"),this._getPose()},ye.prototype.requestAnimationFrame=function(e){return me(e)},ye.prototype.cancelAnimationFrame=function(e){return ve(e)},ye.prototype.wrapForFullscreen=function(e){if(c())return e;if(!this.fullscreenWrapper_){this.fullscreenWrapper_=document.createElement("div");var t=["height: "+Math.min(screen.height,screen.width)+"px !important","top: 0 !important","left: 0 !important","right: 0 !important","border: 0","margin: 0","padding: 0","z-index: 999999 !important","position: fixed"];this.fullscreenWrapper_.setAttribute("style",t.join("; ")+";"),this.fullscreenWrapper_.classList.add("webvr-polyfill-fullscreen-wrapper")}if(this.fullscreenElement_==e)return this.fullscreenWrapper_;if(this.fullscreenElement_&&(this.originalParent_?this.originalParent_.appendChild(this.fullscreenElement_):this.fullscreenElement_.parentElement.removeChild(this.fullscreenElement_)),this.fullscreenElement_=e,this.originalParent_=e.parentElement,this.originalParent_||document.body.appendChild(e),!this.fullscreenWrapper_.parentElement){var n=this.fullscreenElement_.parentElement;n.insertBefore(this.fullscreenWrapper_,this.fullscreenElement_),n.removeChild(this.fullscreenElement_)}this.fullscreenWrapper_.insertBefore(this.fullscreenElement_,this.fullscreenWrapper_.firstChild),this.fullscreenElementCachedStyle_=this.fullscreenElement_.getAttribute("style");var r=this;return function(){if(r.fullscreenElement_){var e=["position: absolute","top: 0","left: 0","width: "+Math.max(screen.width,screen.height)+"px","height: "+Math.min(screen.height,screen.width)+"px","border: 0","margin: 0","padding: 0"];r.fullscreenElement_.setAttribute("style",e.join("; ")+";")}}(),this.fullscreenWrapper_},ye.prototype.removeFullscreenWrapper=function(){if(this.fullscreenElement_){var e=this.fullscreenElement_;this.fullscreenElementCachedStyle_?e.setAttribute("style",this.fullscreenElementCachedStyle_):e.removeAttribute("style"),this.fullscreenElement_=null,this.fullscreenElementCachedStyle_=null;var t=this.fullscreenWrapper_.parentElement;return this.fullscreenWrapper_.removeChild(e),this.originalParent_===t?t.insertBefore(e,this.fullscreenWrapper_):this.originalParent_&&this.originalParent_.appendChild(e),t.removeChild(this.fullscreenWrapper_),e}},ye.prototype.requestPresent=function(e){var t=this.isPresenting,n=this;return e instanceof Array||(S("VRDisplay.prototype.requestPresent with non-array argument","an array of VRLayers as the first argument"),e=[e]),new Promise((function(r,i){if(n.capabilities.canPresent)if(0==e.length||e.length>n.capabilities.maxLayers)i(new Error("Invalid number of layers."));else{var a=e[0];if(a.source){var o=a.leftBounds||pe,s=a.rightBounds||fe;if(t){var u=n.layer_;u.source!==a.source&&(u.source=a.source);for(var h=0;h<4;h++)u.leftBounds[h]=o[h],u.rightBounds[h]=s[h];return n.wrapForFullscreen(n.layer_.source),n.updatePresent_(),void r()}if(n.layer_={predistorted:a.predistorted,source:a.source,leftBounds:o.slice(0),rightBounds:s.slice(0)},n.waitingForPresent_=!1,n.layer_&&n.layer_.source){var d=n.wrapForFullscreen(n.layer_.source);n.addFullscreenListeners_(d,(function(){var e=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement;n.isPresenting=d===e,n.isPresenting?(screen.orientation&&screen.orientation.lock&&screen.orientation.lock("landscape-primary").catch((function(e){console.error("screen.orientation.lock() failed due to",e.message)})),n.waitingForPresent_=!1,n.beginPresent_(),r()):(screen.orientation&&screen.orientation.unlock&&screen.orientation.unlock(),n.removeFullscreenWrapper(),n.disableWakeLock(),n.endPresent_(),n.removeFullscreenListeners_()),n.fireVRDisplayPresentChange_()}),(function(){n.waitingForPresent_&&(n.removeFullscreenWrapper(),n.removeFullscreenListeners_(),n.disableWakeLock(),n.waitingForPresent_=!1,n.isPresenting=!1,i(new Error("Unable to present.")))})),function(e){if(l())return!1;if(e.requestFullscreen)e.requestFullscreen();else if(e.webkitRequestFullscreen)e.webkitRequestFullscreen();else if(e.mozRequestFullScreen)e.mozRequestFullScreen();else{if(!e.msRequestFullscreen)return!1;e.msRequestFullscreen()}return!0}(d)?(n.enableWakeLock(),n.waitingForPresent_=!0):(c()||l())&&(n.enableWakeLock(),n.isPresenting=!0,n.beginPresent_(),n.fireVRDisplayPresentChange_(),r())}n.waitingForPresent_||c()||(g(),i(new Error("Unable to present.")))}else r()}else i(new Error("VRDisplay is not capable of presenting."))}))},ye.prototype.exitPresent=function(){var e=this.isPresenting,t=this;return this.isPresenting=!1,this.layer_=null,this.disableWakeLock(),new Promise((function(n,r){e?(!g()&&c()&&(t.endPresent_(),t.fireVRDisplayPresentChange_()),l()&&(t.removeFullscreenWrapper(),t.removeFullscreenListeners_(),t.endPresent_(),t.fireVRDisplayPresentChange_()),n()):r(new Error("Was not presenting to VRDisplay."))}))},ye.prototype.getLayers=function(){return this.layer_?[this.layer_]:[]},ye.prototype.fireVRDisplayPresentChange_=function(){var e=new CustomEvent("vrdisplaypresentchange",{detail:{display:this}});window.dispatchEvent(e)},ye.prototype.fireVRDisplayConnect_=function(){var e=new CustomEvent("vrdisplayconnect",{detail:{display:this}});window.dispatchEvent(e)},ye.prototype.addFullscreenListeners_=function(e,t,n){this.removeFullscreenListeners_(),this.fullscreenEventTarget_=e,this.fullscreenChangeHandler_=t,this.fullscreenErrorHandler_=n,t&&(document.fullscreenEnabled?e.addEventListener("fullscreenchange",t,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenchange",t,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenchange",t,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenchange",t,!1)),n&&(document.fullscreenEnabled?e.addEventListener("fullscreenerror",n,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenerror",n,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenerror",n,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenerror",n,!1))},ye.prototype.removeFullscreenListeners_=function(){if(this.fullscreenEventTarget_){var e=this.fullscreenEventTarget_;if(this.fullscreenChangeHandler_){var t=this.fullscreenChangeHandler_;e.removeEventListener("fullscreenchange",t,!1),e.removeEventListener("webkitfullscreenchange",t,!1),document.removeEventListener("mozfullscreenchange",t,!1),e.removeEventListener("msfullscreenchange",t,!1)}if(this.fullscreenErrorHandler_){var n=this.fullscreenErrorHandler_;e.removeEventListener("fullscreenerror",n,!1),e.removeEventListener("webkitfullscreenerror",n,!1),document.removeEventListener("mozfullscreenerror",n,!1),e.removeEventListener("msfullscreenerror",n,!1)}this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null}},ye.prototype.enableWakeLock=function(){this.wakelock_&&this.wakelock_.enable()},ye.prototype.disableWakeLock=function(){this.wakelock_&&this.wakelock_.disable()},ye.prototype.beginPresent_=function(){},ye.prototype.endPresent_=function(){},ye.prototype.submitFrame=function(e){},ye.prototype.getEyeParameters=function(e){return null};var Ae={ADDITIONAL_VIEWERS:[],DEFAULT_VIEWER:"",MOBILE_WAKE_LOCK:!0,DEBUG:!1,DPDB_URL:"https://dpdb.webvr.rocks/dpdb.json",K_FILTER:.98,PREDICTION_TIME_S:.04,CARDBOARD_UI_DISABLED:!1,ROTATE_INSTRUCTIONS_DISABLED:!1,YAW_ONLY:!1,BUFFER_SCALE:.5,DIRTY_SUBMIT_FRAME_BINDINGS:!1},xe="left",we="right";function be(e){var t=w({},Ae);e=w(t,e||{}),ye.call(this,{wakelock:e.MOBILE_WAKE_LOCK}),this.config=e,this.displayName="Cardboard VRDisplay",this.capabilities=new ge({hasPosition:!1,hasOrientation:!0,hasExternalDisplay:!1,canPresent:!0,maxLayers:1}),this.stageParameters=null,this.bufferScale_=this.config.BUFFER_SCALE,this.poseSensor_=new ae(this.config),this.distorter_=null,this.cardboardUI_=null,this.dpdb_=new Z(this.config.DPDB_URL,this.onDeviceParamsUpdated_.bind(this)),this.deviceInfo_=new q(this.dpdb_.getDeviceParams(),e.ADDITIONAL_VIEWERS),this.viewerSelector_=new le(e.DEFAULT_VIEWER),this.viewerSelector_.onChange(this.onViewerChanged_.bind(this)),this.deviceInfo_.setViewer(this.viewerSelector_.getCurrentViewer()),this.config.ROTATE_INSTRUCTIONS_DISABLED||(this.rotateInstructions_=new oe),c()&&window.addEventListener("resize",this.onResize_.bind(this))}return be.prototype=Object.create(ye.prototype),be.prototype._getPose=function(){return{position:null,orientation:this.poseSensor_.getOrientation(),linearVelocity:null,linearAcceleration:null,angularVelocity:null,angularAcceleration:null}},be.prototype._resetPose=function(){this.poseSensor_.resetPose&&this.poseSensor_.resetPose()},be.prototype._getFieldOfView=function(e){var t;if(e==xe)t=this.deviceInfo_.getFieldOfViewLeftEye();else{if(e!=we)return console.error("Invalid eye provided: %s",e),null;t=this.deviceInfo_.getFieldOfViewRightEye()}return t},be.prototype._getEyeOffset=function(e){var t;if(e==xe)t=[.5*-this.deviceInfo_.viewer.interLensDistance,0,0];else{if(e!=we)return console.error("Invalid eye provided: %s",e),null;t=[.5*this.deviceInfo_.viewer.interLensDistance,0,0]}return t},be.prototype.getEyeParameters=function(e){var t=this._getEyeOffset(e),n=this._getFieldOfView(e),r={offset:t,renderWidth:.5*this.deviceInfo_.device.width*this.bufferScale_,renderHeight:this.deviceInfo_.device.height*this.bufferScale_};return Object.defineProperty(r,"fieldOfView",{enumerable:!0,get:function(){return S("VRFieldOfView","VRFrameData's projection matrices"),n}}),r},be.prototype.onDeviceParamsUpdated_=function(e){this.config.DEBUG&&console.log("DPDB reported that device params were updated."),this.deviceInfo_.updateDeviceParams(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_)},be.prototype.updateBounds_=function(){this.layer_&&this.distorter_&&(this.layer_.leftBounds||this.layer_.rightBounds)&&this.distorter_.setTextureBounds(this.layer_.leftBounds,this.layer_.rightBounds)},be.prototype.beginPresent_=function(){var e=this.layer_.source.getContext("webgl");e||(e=this.layer_.source.getContext("experimental-webgl")),e||(e=this.layer_.source.getContext("webgl2")),e&&(this.layer_.predistorted?this.config.CARDBOARD_UI_DISABLED||(e.canvas.width=m()*this.bufferScale_,e.canvas.height=v()*this.bufferScale_,this.cardboardUI_=new B(e)):(this.config.CARDBOARD_UI_DISABLED||(this.cardboardUI_=new B(e)),this.distorter_=new C(e,this.cardboardUI_,this.config.BUFFER_SCALE,this.config.DIRTY_SUBMIT_FRAME_BINDINGS),this.distorter_.updateDeviceInfo(this.deviceInfo_)),this.cardboardUI_&&this.cardboardUI_.listen(function(e){this.viewerSelector_.show(this.layer_.source.parentElement),e.stopPropagation(),e.preventDefault()}.bind(this),function(e){this.exitPresent(),e.stopPropagation(),e.preventDefault()}.bind(this)),this.rotateInstructions_&&(f()&&x()?this.rotateInstructions_.showTemporarily(3e3,this.layer_.source.parentElement):this.rotateInstructions_.update()),this.orientationHandler=this.onOrientationChange_.bind(this),window.addEventListener("orientationchange",this.orientationHandler),this.vrdisplaypresentchangeHandler=this.updateBounds_.bind(this),window.addEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler),this.fireVRDisplayDeviceParamsChange_())},be.prototype.endPresent_=function(){this.distorter_&&(this.distorter_.destroy(),this.distorter_=null),this.cardboardUI_&&(this.cardboardUI_.destroy(),this.cardboardUI_=null),this.rotateInstructions_&&this.rotateInstructions_.hide(),this.viewerSelector_.hide(),window.removeEventListener("orientationchange",this.orientationHandler),window.removeEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler)},be.prototype.updatePresent_=function(){this.endPresent_(),this.beginPresent_()},be.prototype.submitFrame=function(e){if(this.distorter_)this.updateBounds_(),this.distorter_.submitFrame();else if(this.cardboardUI_&&this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2"));var n=t.canvas;n.width==this.lastWidth&&n.height==this.lastHeight||this.cardboardUI_.onResize(),this.lastWidth=n.width,this.lastHeight=n.height,this.cardboardUI_.render()}},be.prototype.onOrientationChange_=function(e){this.viewerSelector_.hide(),this.rotateInstructions_&&this.rotateInstructions_.update(),this.onResize_()},be.prototype.onResize_=function(e){if(this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2")),t.canvas.setAttribute("style",["position: absolute","top: 0","left: 0","width: 100vw","height: 100vh","border: 0","margin: 0","padding: 0px","box-sizing: content-box"].join("; ")+";"),b(t.canvas)}},be.prototype.onViewerChanged_=function(e){this.deviceInfo_.setViewer(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_),this.fireVRDisplayDeviceParamsChange_()},be.prototype.fireVRDisplayDeviceParamsChange_=function(){var e=new CustomEvent("vrdisplaydeviceparamschange",{detail:{vrdisplay:this,deviceInfo:this.deviceInfo_}});window.dispatchEvent(e)},be.VRFrameData=function(){this.leftProjectionMatrix=new Float32Array(16),this.leftViewMatrix=new Float32Array(16),this.rightProjectionMatrix=new Float32Array(16),this.rightViewMatrix=new Float32Array(16),this.pose=null},be.VRDisplay=ye,be}()})),s=(e=o)&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,c={ADDITIONAL_VIEWERS:[],DEFAULT_VIEWER:"",PROVIDE_MOBILE_VRDISPLAY:!0,MOBILE_WAKE_LOCK:!0,DEBUG:!1,DPDB_URL:"https://dpdb.webvr.rocks/dpdb.json",K_FILTER:.98,PREDICTION_TIME_S:.04,CARDBOARD_UI_DISABLED:!1,ROTATE_INSTRUCTIONS_DISABLED:!1,YAW_ONLY:!1,BUFFER_SCALE:.5,DIRTY_SUBMIT_FRAME_BINDINGS:!1};function l(e){this.config=a(a({},c),e),this.polyfillDisplays=[],this.enabled=!1,this.hasNative="getVRDisplays"in navigator,this.native={},this.native.getVRDisplays=navigator.getVRDisplays,this.native.VRFrameData=window.VRFrameData,this.native.VRDisplay=window.VRDisplay,(!this.hasNative||this.config.PROVIDE_MOBILE_VRDISPLAY&&r())&&(this.enable(),this.getVRDisplays().then((function(e){e&&e[0]&&e[0].fireVRDisplayConnect_&&e[0].fireVRDisplayConnect_()})))}l.prototype.getPolyfillDisplays=function(){if(this._polyfillDisplaysPopulated)return this.polyfillDisplays;if(r()){var e=new s({ADDITIONAL_VIEWERS:this.config.ADDITIONAL_VIEWERS,DEFAULT_VIEWER:this.config.DEFAULT_VIEWER,MOBILE_WAKE_LOCK:this.config.MOBILE_WAKE_LOCK,DEBUG:this.config.DEBUG,DPDB_URL:this.config.DPDB_URL,CARDBOARD_UI_DISABLED:this.config.CARDBOARD_UI_DISABLED,K_FILTER:this.config.K_FILTER,PREDICTION_TIME_S:this.config.PREDICTION_TIME_S,ROTATE_INSTRUCTIONS_DISABLED:this.config.ROTATE_INSTRUCTIONS_DISABLED,YAW_ONLY:this.config.YAW_ONLY,BUFFER_SCALE:this.config.BUFFER_SCALE,DIRTY_SUBMIT_FRAME_BINDINGS:this.config.DIRTY_SUBMIT_FRAME_BINDINGS});this.polyfillDisplays.push(e)}return this._polyfillDisplaysPopulated=!0,this.polyfillDisplays},l.prototype.enable=function(){if(this.enabled=!0,this.hasNative&&this.native.VRFrameData){var e=this.native.VRFrameData,t=new this.native.VRFrameData,n=this.native.VRDisplay.prototype.getFrameData;window.VRDisplay.prototype.getFrameData=function(r){r instanceof e?n.call(this,r):(n.call(this,t),r.pose=t.pose,i(t.leftProjectionMatrix,r.leftProjectionMatrix),i(t.rightProjectionMatrix,r.rightProjectionMatrix),i(t.leftViewMatrix,r.leftViewMatrix),i(t.rightViewMatrix,r.rightViewMatrix))}}navigator.getVRDisplays=this.getVRDisplays.bind(this),window.VRDisplay=s.VRDisplay,window.VRFrameData=s.VRFrameData},l.prototype.getVRDisplays=function(){var e=this;return this.config,this.hasNative?this.native.getVRDisplays.call(navigator).then((function(t){return t.length>0?t:e.getPolyfillDisplays()})):Promise.resolve(this.getPolyfillDisplays())},l.version="0.10.10",l.VRFrameData=s.VRFrameData,l.VRDisplay=s.VRDisplay;var u=Object.freeze({default:l}),h=u&&l||u;return void 0!==n&&n.window&&(n.document||(n.document=n.window.document),n.navigator||(n.navigator=n.window.navigator)),h},e.exports=n()}).call(this,n(8))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t),n.d(t,"DeviceOrientationControls",(function(){return i}));var r=n(0),i=function(e){var t=this;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0;var n,i,a,o,s=function(e){t.deviceOrientation=e},c=function(){t.screenOrientation=window.orientation||0},l=(n=new r.Vector3(0,0,1),i=new r.Euler,a=new r.Quaternion,o=new r.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),function(e,t,r,s,c){i.set(r,t,-s,"YXZ"),e.setFromEuler(i),e.multiply(o),e.multiply(a.setFromAxisAngle(n,-c))});this.connect=function(){c(),window.addEventListener("orientationchange",c,!1),window.addEventListener("deviceorientation",s,!1),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",c,!1),window.removeEventListener("deviceorientation",s,!1),t.enabled=!1},this.update=function(){if(!1!==t.enabled){var e=t.deviceOrientation;if(e){var n=e.alpha?r.Math.degToRad(e.alpha)+t.alphaOffset:0,i=e.beta?r.Math.degToRad(e.beta):0,a=e.gamma?r.Math.degToRad(e.gamma):0,o=t.screenOrientation?r.Math.degToRad(t.screenOrientation):0;l(t.object.quaternion,n,i,a,o)}}},this.dispose=function(){t.disconnect()},this.connect()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseDotOutput=function(e){return JSON.parse(e.trim().replace(/\\/g,""))}}]); \ No newline at end of file +e.exports=function(){var e,t,r,i=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,t){for(var n=0;ne.TEXTURE31){console.error("TEXTURE_BINDING_2D or TEXTURE_BINDING_CUBE_MAP must be followed by a valid texture unit"),r.push(null,null);break}i||(i=e.getParameter(e.ACTIVE_TEXTURE)),e.activeTexture(c),r.push(e.getParameter(o),null);break;case e.ACTIVE_TEXTURE:i=e.getParameter(e.ACTIVE_TEXTURE),r.push(null);break;default:r.push(e.getParameter(o))}for(n(e),a=0;ae.TEXTURE31)break;e.activeTexture(c),e.bindTexture(e.TEXTURE_2D,s);break;case e.TEXTURE_BINDING_CUBE_MAP:var c;if((c=t[++a])e.TEXTURE31)break;e.activeTexture(c),e.bindTexture(e.TEXTURE_CUBE_MAP,s);break;case e.VIEWPORT:e.viewport(s[0],s[1],s[2],s[3]);break;case e.BLEND:case e.CULL_FACE:case e.DEPTH_TEST:case e.SCISSOR_TEST:case e.STENCIL_TEST:s?e.enable(o):e.disable(o);break;default:console.log("No GL restore behavior for 0x"+o.toString(16))}i&&e.activeTexture(i)}}else n(e)},L=["attribute vec2 position;","attribute vec3 texCoord;","varying vec2 vTexCoord;","uniform vec4 viewportOffsetScale[2];","void main() {"," vec4 viewport = viewportOffsetScale[int(texCoord.z)];"," vTexCoord = (texCoord.xy * viewport.zw) + viewport.xy;"," gl_Position = vec4( position, 1.0, 1.0 );","}"].join("\n"),R=["precision mediump float;","uniform sampler2D diffuse;","varying vec2 vTexCoord;","void main() {"," gl_FragColor = texture2D(diffuse, vTexCoord);","}"].join("\n");function C(e,t,n,r){this.gl=e,this.cardboardUI=t,this.bufferScale=n,this.dirtySubmitFrameBindings=r,this.ctxAttribs=e.getContextAttributes(),this.meshWidth=20,this.meshHeight=20,this.bufferWidth=e.drawingBufferWidth,this.bufferHeight=e.drawingBufferHeight,this.realBindFramebuffer=e.bindFramebuffer,this.realEnable=e.enable,this.realDisable=e.disable,this.realColorMask=e.colorMask,this.realClearColor=e.clearColor,this.realViewport=e.viewport,c()||(this.realCanvasWidth=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"width"),this.realCanvasHeight=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"height")),this.isPatched=!1,this.lastBoundFramebuffer=null,this.cullFace=!1,this.depthTest=!1,this.blend=!1,this.scissorTest=!1,this.stencilTest=!1,this.viewport=[0,0,0,0],this.colorMask=[!0,!0,!0,!0],this.clearColor=[0,0,0,0],this.attribs={position:0,texCoord:1},this.program=y(e,L,R,this.attribs),this.uniforms=A(e,this.program),this.viewportOffsetScale=new Float32Array(8),this.setTextureBounds(),this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),this.indexCount=0,this.renderTarget=e.createTexture(),this.framebuffer=e.createFramebuffer(),this.depthStencilBuffer=null,this.depthBuffer=null,this.stencilBuffer=null,this.ctxAttribs.depth&&this.ctxAttribs.stencil?this.depthStencilBuffer=e.createRenderbuffer():this.ctxAttribs.depth?this.depthBuffer=e.createRenderbuffer():this.ctxAttribs.stencil&&(this.stencilBuffer=e.createRenderbuffer()),this.patch(),this.onResize()}C.prototype.destroy=function(){var e=this.gl;this.unpatch(),e.deleteProgram(this.program),e.deleteBuffer(this.vertexBuffer),e.deleteBuffer(this.indexBuffer),e.deleteTexture(this.renderTarget),e.deleteFramebuffer(this.framebuffer),this.depthStencilBuffer&&e.deleteRenderbuffer(this.depthStencilBuffer),this.depthBuffer&&e.deleteRenderbuffer(this.depthBuffer),this.stencilBuffer&&e.deleteRenderbuffer(this.stencilBuffer),this.cardboardUI&&this.cardboardUI.destroy()},C.prototype.onResize=function(){var e=this.gl,t=this,n=[e.RENDERBUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0];T(e,n,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.framebuffer),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.texImage2D(e.TEXTURE_2D,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,t.bufferWidth,t.bufferHeight,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.renderTarget,0),t.ctxAttribs.depth&&t.ctxAttribs.stencil?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthStencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,t.depthStencilBuffer)):t.ctxAttribs.depth?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t.depthBuffer)):t.ctxAttribs.stencil&&(e.bindRenderbuffer(e.RENDERBUFFER,t.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.STENCIL_INDEX8,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.STENCIL_ATTACHMENT,e.RENDERBUFFER,t.stencilBuffer)),!e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer incomplete!"),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),t.realClearColor.apply(e,t.clearColor)})),this.cardboardUI&&this.cardboardUI.onResize()},C.prototype.patch=function(){if(!this.isPatched){var e=this,t=this.gl.canvas,n=this.gl;c()||(t.width=m()*this.bufferScale,t.height=v()*this.bufferScale,Object.defineProperty(t,"width",{configurable:!0,enumerable:!0,get:function(){return e.bufferWidth},set:function(n){e.bufferWidth=n,e.realCanvasWidth.set.call(t,n),e.onResize()}}),Object.defineProperty(t,"height",{configurable:!0,enumerable:!0,get:function(){return e.bufferHeight},set:function(n){e.bufferHeight=n,e.realCanvasHeight.set.call(t,n),e.onResize()}})),this.lastBoundFramebuffer=n.getParameter(n.FRAMEBUFFER_BINDING),null==this.lastBoundFramebuffer&&(this.lastBoundFramebuffer=this.framebuffer,this.gl.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer)),this.gl.bindFramebuffer=function(t,r){e.lastBoundFramebuffer=r||e.framebuffer,e.realBindFramebuffer.call(n,t,e.lastBoundFramebuffer)},this.cullFace=n.getParameter(n.CULL_FACE),this.depthTest=n.getParameter(n.DEPTH_TEST),this.blend=n.getParameter(n.BLEND),this.scissorTest=n.getParameter(n.SCISSOR_TEST),this.stencilTest=n.getParameter(n.STENCIL_TEST),n.enable=function(t){switch(t){case n.CULL_FACE:e.cullFace=!0;break;case n.DEPTH_TEST:e.depthTest=!0;break;case n.BLEND:e.blend=!0;break;case n.SCISSOR_TEST:e.scissorTest=!0;break;case n.STENCIL_TEST:e.stencilTest=!0}e.realEnable.call(n,t)},n.disable=function(t){switch(t){case n.CULL_FACE:e.cullFace=!1;break;case n.DEPTH_TEST:e.depthTest=!1;break;case n.BLEND:e.blend=!1;break;case n.SCISSOR_TEST:e.scissorTest=!1;break;case n.STENCIL_TEST:e.stencilTest=!1}e.realDisable.call(n,t)},this.colorMask=n.getParameter(n.COLOR_WRITEMASK),n.colorMask=function(t,r,i,a){e.colorMask[0]=t,e.colorMask[1]=r,e.colorMask[2]=i,e.colorMask[3]=a,e.realColorMask.call(n,t,r,i,a)},this.clearColor=n.getParameter(n.COLOR_CLEAR_VALUE),n.clearColor=function(t,r,i,a){e.clearColor[0]=t,e.clearColor[1]=r,e.clearColor[2]=i,e.clearColor[3]=a,e.realClearColor.call(n,t,r,i,a)},this.viewport=n.getParameter(n.VIEWPORT),n.viewport=function(t,r,i,a){e.viewport[0]=t,e.viewport[1]=r,e.viewport[2]=i,e.viewport[3]=a,e.realViewport.call(n,t,r,i,a)},this.isPatched=!0,b(t)}},C.prototype.unpatch=function(){if(this.isPatched){var e=this.gl,t=this.gl.canvas;c()||(Object.defineProperty(t,"width",this.realCanvasWidth),Object.defineProperty(t,"height",this.realCanvasHeight)),t.width=this.bufferWidth,t.height=this.bufferHeight,e.bindFramebuffer=this.realBindFramebuffer,e.enable=this.realEnable,e.disable=this.realDisable,e.colorMask=this.realColorMask,e.clearColor=this.realClearColor,e.viewport=this.realViewport,this.lastBoundFramebuffer==this.framebuffer&&e.bindFramebuffer(e.FRAMEBUFFER,null),this.isPatched=!1,setTimeout((function(){b(t)}),1)}},C.prototype.setTextureBounds=function(e,t){e||(e=[0,0,.5,1]),t||(t=[.5,0,.5,1]),this.viewportOffsetScale[0]=e[0],this.viewportOffsetScale[1]=e[1],this.viewportOffsetScale[2]=e[2],this.viewportOffsetScale[3]=e[3],this.viewportOffsetScale[4]=t[0],this.viewportOffsetScale[5]=t[1],this.viewportOffsetScale[6]=t[2],this.viewportOffsetScale[7]=t[3]},C.prototype.submitFrame=function(){var e=this.gl,t=this,n=[];if(this.dirtySubmitFrameBindings||n.push(e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING,e.ELEMENT_ARRAY_BUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0),T(e,n,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),t.cullFace&&t.realDisable.call(e,e.CULL_FACE),t.depthTest&&t.realDisable.call(e,e.DEPTH_TEST),t.blend&&t.realDisable.call(e,e.BLEND),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realDisable.call(e,e.STENCIL_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),(t.ctxAttribs.alpha||c())&&(t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT)),e.useProgram(t.program),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.indexBuffer),e.bindBuffer(e.ARRAY_BUFFER,t.vertexBuffer),e.enableVertexAttribArray(t.attribs.position),e.enableVertexAttribArray(t.attribs.texCoord),e.vertexAttribPointer(t.attribs.position,2,e.FLOAT,!1,20,0),e.vertexAttribPointer(t.attribs.texCoord,3,e.FLOAT,!1,20,8),e.activeTexture(e.TEXTURE0),e.uniform1i(t.uniforms.diffuse,0),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.uniform4fv(t.uniforms.viewportOffsetScale,t.viewportOffsetScale),e.drawElements(e.TRIANGLES,t.indexCount,e.UNSIGNED_SHORT,0),t.cardboardUI&&t.cardboardUI.renderNoState(),t.realBindFramebuffer.call(t.gl,e.FRAMEBUFFER,t.framebuffer),t.ctxAttribs.preserveDrawingBuffer||(t.realClearColor.call(e,0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)),t.dirtySubmitFrameBindings||t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.cullFace&&t.realEnable.call(e,e.CULL_FACE),t.depthTest&&t.realEnable.call(e,e.DEPTH_TEST),t.blend&&t.realEnable.call(e,e.BLEND),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realEnable.call(e,e.STENCIL_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),!t.ctxAttribs.alpha&&t.ctxAttribs.preserveDrawingBuffer||t.realClearColor.apply(e,t.clearColor)})),c()){var r=e.canvas;r.width==t.bufferWidth&&r.height==t.bufferHeight||(t.bufferWidth=r.width,t.bufferHeight=r.height,t.onResize())}},C.prototype.updateDeviceInfo=function(e){var t=this.gl,n=this,r=[t.ARRAY_BUFFER_BINDING,t.ELEMENT_ARRAY_BUFFER_BINDING];T(t,r,(function(t){var r=n.computeMeshVertices_(n.meshWidth,n.meshHeight,e);if(t.bindBuffer(t.ARRAY_BUFFER,n.vertexBuffer),t.bufferData(t.ARRAY_BUFFER,r,t.STATIC_DRAW),!n.indexCount){var i=n.computeMeshIndices_(n.meshWidth,n.meshHeight);t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,n.indexBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i,t.STATIC_DRAW),n.indexCount=i.length}}))},C.prototype.computeMeshVertices_=function(e,t,n){for(var r=new Float32Array(2*e*t*5),i=n.getLeftEyeVisibleTanAngles(),a=n.getLeftEyeNoLensTanAngles(),o=n.getLeftEyeVisibleScreenRect(a),c=0,l=0;l<2;l++){for(var u=0;ui-42&&r.clientXn.clientHeight-42?e(r):r.clientX<42&&r.clientY<42&&t(r)},n.addEventListener("click",this.listener,!1)},B.prototype.onResize=function(){var e=this.gl,t=this,n=[e.ARRAY_BUFFER_BINDING];T(e,n,(function(e){var n=[],r=e.drawingBufferWidth/2,i=Math.max(screen.width,screen.height)*window.devicePixelRatio,a=e.drawingBufferWidth/i*window.devicePixelRatio,o=4*a/2,s=42*a,c=28*a/2,l=14*a;function u(e,t){var i=(90-e)*I,a=Math.cos(i),o=Math.sin(i);n.push(O*a*c+r,O*o*c+c),n.push(t*a*c+r,t*o*c+c)}n.push(r-o,s),n.push(r-o,e.drawingBufferHeight),n.push(r+o,s),n.push(r+o,e.drawingBufferHeight),t.gearOffset=n.length/2;for(var h=0;h<=6;h++){var d=60*h;u(d,1),u(d+12,1),u(d+20,.75),u(d+40,.75),u(d+48,1)}function p(t,r){n.push(l+t,e.drawingBufferHeight-l-r)}t.gearVertexCount=n.length/2-t.gearOffset,t.arrowOffset=n.length/2;var f=o/Math.sin(45*I);p(0,c),p(c,0),p(c+f,f),p(f,c+f),p(f,c-f),p(0,c),p(c,2*c),p(c+f,2*c-f),p(f,c-f),p(0,c),p(f,c-o),p(28*a,c-o),p(f,c+o),p(28*a,c+o),t.arrowVertexCount=n.length/2-t.arrowOffset,e.bindBuffer(e.ARRAY_BUFFER,t.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array(n),e.STATIC_DRAW)}))},B.prototype.render=function(){var e=this.gl,t=this,n=[e.CULL_FACE,e.DEPTH_TEST,e.BLEND,e.SCISSOR_TEST,e.STENCIL_TEST,e.COLOR_WRITEMASK,e.VIEWPORT,e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING];T(e,n,(function(e){e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.colorMask(!0,!0,!0,!0),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.renderNoState()}))},B.prototype.renderNoState=function(){var e,t,n,r,i,a,o,s,c,l,u=this.gl;u.useProgram(this.program),u.bindBuffer(u.ARRAY_BUFFER,this.vertexBuffer),u.enableVertexAttribArray(this.attribs.position),u.vertexAttribPointer(this.attribs.position,2,u.FLOAT,!1,8,0),u.uniform4f(this.uniforms.color,1,1,1,1),e=this.projMat,t=0,n=u.drawingBufferWidth,r=0,i=u.drawingBufferHeight,s=1/(t-n),c=1/(r-i),l=1/((a=.1)-(o=1024)),e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*s,e[13]=(i+r)*c,e[14]=(o+a)*l,e[15]=1,u.uniformMatrix4fv(this.uniforms.projectionMat,!1,this.projMat),u.drawArrays(u.TRIANGLE_STRIP,0,4),u.drawArrays(u.TRIANGLE_STRIP,this.gearOffset,this.gearVertexCount),u.drawArrays(u.TRIANGLE_STRIP,this.arrowOffset,this.arrowVertexCount)},N.prototype.distortInverse=function(e){for(var t=0,n=1,r=e-this.distort(t);Math.abs(n-t)>1e-4;){var i=e-this.distort(n),a=n-i*((n-t)/(i-r));t=n,n=a,r=i}return n},N.prototype.distort=function(e){for(var t=e*e,n=0,r=0;r=1)return this.w=a,this.x=n,this.y=r,this.z=i,this;var s=Math.acos(o),c=Math.sqrt(1-o*o);if(Math.abs(c)<.001)return this.w=.5*(a+this.w),this.x=.5*(n+this.x),this.y=.5*(r+this.y),this.z=.5*(i+this.z),this;var l=Math.sin((1-t)*s)/c,u=Math.sin(t*s)/c;return this.w=a*l+this.w*u,this.x=n*l+this.x*u,this.y=r*l+this.y*u,this.z=i*l+this.z*u,this},setFromUnitVectors:function(e,t){return void 0===U&&(U=new z),(H=e.dot(t)+1)<1e-6?(H=0,Math.abs(e.x)>Math.abs(e.z)?U.set(-e.y,e.x,0):U.set(0,-e.z,e.y)):U.crossVectors(e,t),this.x=U.x,this.y=U.y,this.z=U.z,this.w=H,this.normalize(),this}};var j=new k({widthMeters:.11,heightMeters:.062,bevelMeters:.004}),W=new k({widthMeters:.1038,heightMeters:.0584,bevelMeters:.004}),X={CardboardV1:new Q({id:"CardboardV1",label:"Cardboard I/O 2014",fov:40,interLensDistance:.06,baselineLensDistance:.035,screenLensDistance:.042,distortionCoefficients:[.441,.156],inverseCoefficients:[-.4410035,.42756155,-.4804439,.5460139,-.58821183,.5733938,-.48303202,.33299083,-.17573841,.0651772,-.01488963,.001559834]}),CardboardV2:new Q({id:"CardboardV2",label:"Cardboard I/O 2015",fov:60,interLensDistance:.064,baselineLensDistance:.035,screenLensDistance:.039,distortionCoefficients:[.34,.55],inverseCoefficients:[-.33836704,-.18162185,.862655,-1.2462051,1.0560602,-.58208317,.21609078,-.05444823,.009177956,-.0009904169,6183535e-11,-16981803e-13]})};function q(e,t){this.viewer=X.CardboardV2,this.updateDeviceParams(e),this.distortion=new N(this.viewer.distortionCoefficients);for(var n=0;n=200&&n.status<=299?(r.dpdb=JSON.parse(n.response),r.recalculateDeviceParams_()):console.error("Error loading online DPDB!")})),n.send()}}function J(e){this.xdpi=e.xdpi,this.ydpi=e.ydpi,this.bevelMm=e.bevelMm}function K(e,t){this.set(e,t)}function $(e,t){this.kFilter=e,this.isDebug=t,this.currentAccelMeasurement=new K,this.currentGyroMeasurement=new K,this.previousGyroMeasurement=new K,c()?this.filterQ=new V(-1,0,0,1):this.filterQ=new V(1,0,0,1),this.previousFilterQ=new V,this.previousFilterQ.copy(this.filterQ),this.accelQ=new V,this.isOrientationInitialized=!1,this.estimatedGravity=new z,this.measuredGravity=new z,this.gyroIntegralQ=new V}function ee(e,t){this.predictionTimeS=e,this.isDebug=t,this.previousQ=new V,this.previousTimestampS=null,this.deltaQ=new V,this.outQ=new V}function te(e,t,n,r){this.yawOnly=n,this.accelerometer=new z,this.gyroscope=new z,this.filter=new $(e,r),this.posePredictor=new ee(t,r),this.isFirefoxAndroid=u(),this.isIOS=c();var i=h();this.isDeviceMotionInRadians=!this.isIOS&&i&&i<66,this.isWithoutDeviceMotion=d(),this.filterToWorldQ=new V,c()?this.filterToWorldQ.setFromAxisAngle(new z(1,0,0),Math.PI/2):this.filterToWorldQ.setFromAxisAngle(new z(1,0,0),-Math.PI/2),this.inverseWorldToScreenQ=new V,this.worldToScreenQ=new V,this.originalPoseAdjustQ=new V,this.originalPoseAdjustQ.setFromAxisAngle(new z(0,0,1),-window.orientation*Math.PI/180),this.setScreenTransform_(),f()&&this.filterToWorldQ.multiply(this.inverseWorldToScreenQ),this.resetQ=new V,this.orientationOut_=new Float32Array(4),this.start()}Z.prototype.getDeviceParams=function(){return this.deviceParams},Z.prototype.recalculateDeviceParams_=function(){var e=this.calcDeviceParams_();e?(this.deviceParams=e,this.onDeviceParamsUpdated&&this.onDeviceParamsUpdated(this.deviceParams)):console.error("Failed to recalculate device parameters.")},Z.prototype.calcDeviceParams_=function(){var e=this.dpdb;if(!e)return console.error("DPDB not available."),null;if(1!=e.format)return console.error("DPDB has unexpected format version."),null;if(!e.devices||!e.devices.length)return console.error("DPDB does not have a devices section."),null;var t=navigator.userAgent||navigator.vendor||window.opera,n=m(),r=v();if(!e.devices)return console.error("DPDB has no devices section."),null;for(var i=0;i1||this.run_(),this.previousGyroMeasurement.copy(this.currentGyroMeasurement)},$.prototype.run_=function(){if(!this.isOrientationInitialized)return this.accelQ=this.accelToQuaternion_(this.currentAccelMeasurement.sample),this.previousFilterQ.copy(this.accelQ),void(this.isOrientationInitialized=!0);var e=this.currentGyroMeasurement.timestampS-this.previousGyroMeasurement.timestampS,t=this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample,e);this.gyroIntegralQ.multiply(t),this.filterQ.copy(this.previousFilterQ),this.filterQ.multiply(t);var n=new V;n.copy(this.filterQ),n.inverse(),this.estimatedGravity.set(0,0,-1),this.estimatedGravity.applyQuaternion(n),this.estimatedGravity.normalize(),this.measuredGravity.copy(this.currentAccelMeasurement.sample),this.measuredGravity.normalize();var r,i=new V;i.setFromUnitVectors(this.estimatedGravity,this.measuredGravity),i.inverse(),this.isDebug&&console.log("Delta: %d deg, G_est: (%s, %s, %s), G_meas: (%s, %s, %s)",G*((r=i).w>1?(console.warn("getQuaternionAngle: w > 1"),0):2*Math.acos(r.w)),this.estimatedGravity.x.toFixed(1),this.estimatedGravity.y.toFixed(1),this.estimatedGravity.z.toFixed(1),this.measuredGravity.x.toFixed(1),this.measuredGravity.y.toFixed(1),this.measuredGravity.z.toFixed(1));var a=new V;a.copy(this.filterQ),a.multiply(i),this.filterQ.slerp(a,1-this.kFilter),this.previousFilterQ.copy(this.filterQ)},$.prototype.getOrientation=function(){return this.filterQ},$.prototype.accelToQuaternion_=function(e){var t=new z;t.copy(e),t.normalize();var n=new V;return n.setFromUnitVectors(new z(0,0,-1),t),n.inverse(),n},$.prototype.gyroToQuaternionDelta_=function(e,t){var n=new V,r=new z;return r.copy(e),r.normalize(),n.setFromAxisAngle(r,e.length()*t),n},ee.prototype.getPrediction=function(e,t,n){if(!this.previousTimestampS)return this.previousQ.copy(e),this.previousTimestampS=n,e;var r=new z;r.copy(t),r.normalize();var i=t.length();if(i<20*F)return this.isDebug&&console.log("Moving slowly, at %s deg/s: no prediction",(G*i).toFixed(1)),this.outQ.copy(e),this.previousQ.copy(e),this.outQ;var a=i*this.predictionTimeS;return this.deltaQ.setFromAxisAngle(r,a),this.outQ.copy(this.previousQ),this.outQ.multiply(this.deltaQ),this.previousQ.copy(e),this.previousTimestampS=n,this.outQ},te.prototype.getPosition=function(){return null},te.prototype.getOrientation=function(){var e=void 0;if(this.isWithoutDeviceMotion&&this._deviceOrientationQ)return this.deviceOrientationFixQ=this.deviceOrientationFixQ||(n=(new V).setFromAxisAngle(new z(0,0,-1),0),r=new V,-90===window.orientation?r.setFromAxisAngle(new z(0,1,0),Math.PI/-2):r.setFromAxisAngle(new z(0,1,0),Math.PI/2),n.multiply(r)),this.deviceOrientationFilterToWorldQ=this.deviceOrientationFilterToWorldQ||((t=new V).setFromAxisAngle(new z(1,0,0),-Math.PI/2),t),e=this._deviceOrientationQ,(i=new V).copy(e),i.multiply(this.deviceOrientationFilterToWorldQ),i.multiply(this.resetQ),i.multiply(this.worldToScreenQ),i.multiplyQuaternions(this.deviceOrientationFixQ,i),this.yawOnly&&(i.x=0,i.z=0,i.normalize()),this.orientationOut_[0]=i.x,this.orientationOut_[1]=i.y,this.orientationOut_[2]=i.z,this.orientationOut_[3]=i.w,this.orientationOut_;var t,n,r,i,a=this.filter.getOrientation();return e=this.posePredictor.getPrediction(a,this.gyroscope,this.previousTimestampS),(i=new V).copy(this.filterToWorldQ),i.multiply(this.resetQ),i.multiply(e),i.multiply(this.worldToScreenQ),this.yawOnly&&(i.x=0,i.z=0,i.normalize()),this.orientationOut_[0]=i.x,this.orientationOut_[1]=i.y,this.orientationOut_[2]=i.z,this.orientationOut_[3]=i.w,this.orientationOut_},te.prototype.resetPose=function(){this.resetQ.copy(this.filter.getOrientation()),this.resetQ.x=0,this.resetQ.y=0,this.resetQ.z*=-1,this.resetQ.normalize(),f()&&this.resetQ.multiply(this.inverseWorldToScreenQ),this.resetQ.multiply(this.originalPoseAdjustQ)},te.prototype.onDeviceOrientation_=function(e){this._deviceOrientationQ=this._deviceOrientationQ||new V;var t=e.alpha,n=e.beta,r=e.gamma;t=(t||0)*Math.PI/180,n=(n||0)*Math.PI/180,r=(r||0)*Math.PI/180,this._deviceOrientationQ.setFromEulerYXZ(n,t,-r)},te.prototype.onDeviceMotion_=function(e){this.updateDeviceMotion_(e)},te.prototype.updateDeviceMotion_=function(e){var t=e.accelerationIncludingGravity,n=e.rotationRate,r=e.timeStamp/1e3,i=r-this.previousTimestampS;return i<0?(E("fusion-pose-sensor:invalid:non-monotonic","Invalid timestamps detected: non-monotonic timestamp from devicemotion"),void(this.previousTimestampS=r)):i<=.001||i>1?(E("fusion-pose-sensor:invalid:outside-threshold","Invalid timestamps detected: Timestamp from devicemotion outside expected range."),void(this.previousTimestampS=r)):(this.accelerometer.set(-t.x,-t.y,-t.z),p()?this.gyroscope.set(-n.beta,n.alpha,n.gamma):this.gyroscope.set(n.alpha,n.beta,n.gamma),this.isDeviceMotionInRadians||this.gyroscope.multiplyScalar(Math.PI/180),this.filter.addAccelMeasurement(this.accelerometer,r),this.filter.addGyroMeasurement(this.gyroscope,r),void(this.previousTimestampS=r))},te.prototype.onOrientationChange_=function(e){this.setScreenTransform_()},te.prototype.onMessage_=function(e){var t=e.data;t&&t.type&&"devicemotion"===t.type.toLowerCase()&&this.updateDeviceMotion_(t.deviceMotionEvent)},te.prototype.setScreenTransform_=function(){switch(this.worldToScreenQ.set(0,0,0,1),window.orientation){case 0:break;case 90:this.worldToScreenQ.setFromAxisAngle(new z(0,0,1),-Math.PI/2);break;case-90:this.worldToScreenQ.setFromAxisAngle(new z(0,0,1),Math.PI/2)}this.inverseWorldToScreenQ.copy(this.worldToScreenQ),this.inverseWorldToScreenQ.inverse()},te.prototype.start=function(){var e,t,n;this.onDeviceMotionCallback_=this.onDeviceMotion_.bind(this),this.onOrientationChangeCallback_=this.onOrientationChange_.bind(this),this.onMessageCallback_=this.onMessage_.bind(this),this.onDeviceOrientationCallback_=this.onDeviceOrientation_.bind(this),c()&&(e=window.self!==window.top,t=M(document.referrer),n=M(window.location.href),e&&t!==n)&&window.addEventListener("message",this.onMessageCallback_),window.addEventListener("orientationchange",this.onOrientationChangeCallback_),this.isWithoutDeviceMotion?window.addEventListener("deviceorientation",this.onDeviceOrientationCallback_):window.addEventListener("devicemotion",this.onDeviceMotionCallback_)},te.prototype.stop=function(){window.removeEventListener("devicemotion",this.onDeviceMotionCallback_),window.removeEventListener("deviceorientation",this.onDeviceOrientationCallback_),window.removeEventListener("orientationchange",this.onOrientationChangeCallback_),window.removeEventListener("message",this.onMessageCallback_)};var ne=new z(1,0,0),re=new z(0,0,1),ie=new V;ie.setFromAxisAngle(ne,-Math.PI/2),ie.multiply((new V).setFromAxisAngle(re,Math.PI/2));var ae=function(){function e(t){i(this,e),this.config=t,this.sensor=null,this.fusionSensor=null,this._out=new Float32Array(4),this.api=null,this.errors=[],this._sensorQ=new V,this._outQ=new V,this._onSensorRead=this._onSensorRead.bind(this),this._onSensorError=this._onSensorError.bind(this),this.init()}return a(e,[{key:"init",value:function(){var e=null;try{(e=new RelativeOrientationSensor({frequency:60,referenceFrame:"screen"})).addEventListener("error",this._onSensorError)}catch(e){this.errors.push(e),"SecurityError"===e.name?(console.error("Cannot construct sensors due to the Feature Policy"),console.warn('Attempting to fall back using "devicemotion"; however this will fail in the future without correct permissions.'),this.useDeviceMotion()):"ReferenceError"===e.name?this.useDeviceMotion():console.error(e)}e&&(this.api="sensor",this.sensor=e,this.sensor.addEventListener("reading",this._onSensorRead),this.sensor.start())}},{key:"useDeviceMotion",value:function(){this.api="devicemotion",this.fusionSensor=new te(this.config.K_FILTER,this.config.PREDICTION_TIME_S,this.config.YAW_ONLY,this.config.DEBUG),this.sensor&&(this.sensor.removeEventListener("reading",this._onSensorRead),this.sensor.removeEventListener("error",this._onSensorError),this.sensor=null)}},{key:"getOrientation",value:function(){if(this.fusionSensor)return this.fusionSensor.getOrientation();if(!this.sensor||!this.sensor.quaternion)return this._out[0]=this._out[1]=this._out[2]=0,this._out[3]=1,this._out;var e=this.sensor.quaternion;this._sensorQ.set(e[0],e[1],e[2],e[3]);var t=this._outQ;return t.copy(ie),t.multiply(this._sensorQ),this.config.YAW_ONLY&&(t.x=t.z=0,t.normalize()),this._out[0]=t.x,this._out[1]=t.y,this._out[2]=t.z,this._out[3]=t.w,this._out}},{key:"_onSensorError",value:function(e){this.errors.push(e.error),"NotAllowedError"===e.error.name?console.error("Permission to access sensor was denied"):"NotReadableError"===e.error.name?console.error("Sensor could not be read"):console.error(e.error),this.useDeviceMotion()}},{key:"_onSensorRead",value:function(){}}]),e}();function oe(){this.loadIcon_();var e=document.createElement("div");(a=e.style).position="fixed",a.top=0,a.right=0,a.bottom=0,a.left=0,a.backgroundColor="gray",a.fontFamily="sans-serif",a.zIndex=1e6;var t=document.createElement("img");t.src=this.icon,(a=t.style).marginLeft="25%",a.marginTop="25%",a.width="50%",e.appendChild(t);var n=document.createElement("div");(a=n.style).textAlign="center",a.fontSize="16px",a.lineHeight="24px",a.margin="24px 25%",a.width="50%",n.innerHTML="Place your phone into your Cardboard viewer.",e.appendChild(n);var r=document.createElement("div");(a=r.style).backgroundColor="#CFD8DC",a.position="fixed",a.bottom=0,a.width="100%",a.height="48px",a.padding="14px 24px",a.boxSizing="border-box",a.color="#656A6B",e.appendChild(r);var i=document.createElement("div");i.style.float="left",i.innerHTML="No Cardboard viewer?";var a,o=document.createElement("a");o.href="https://www.google.com/get/cardboard/get-cardboard/",o.innerHTML="get one",o.target="_blank",(a=o.style).float="right",a.fontWeight=600,a.textTransform="uppercase",a.borderLeft="1px solid gray",a.paddingLeft="24px",a.textDecoration="none",a.color="#656A6B",r.appendChild(i),r.appendChild(o),this.overlay=e,this.text=n,this.hide()}oe.prototype.show=function(e){e||this.overlay.parentElement?e&&(this.overlay.parentElement&&this.overlay.parentElement!=e&&this.overlay.parentElement.removeChild(this.overlay),e.appendChild(this.overlay)):document.body.appendChild(this.overlay),this.overlay.style.display="block";var t=this.overlay.querySelector("img").style;f()?(t.width="20%",t.marginLeft="40%",t.marginTop="3%"):(t.width="50%",t.marginLeft="25%",t.marginTop="25%")},oe.prototype.hide=function(){this.overlay.style.display="none"},oe.prototype.showTemporarily=function(e,t){this.show(t),this.timer=setTimeout(this.hide.bind(this),e)},oe.prototype.disableShowTemporarily=function(){clearTimeout(this.timer)},oe.prototype.update=function(){this.disableShowTemporarily(),!f()&&x()?this.show():this.hide()},oe.prototype.loadIcon_=function(){this.icon="data:image/svg+xml,"+encodeURIComponent("")};var se="CardboardV1",ce="WEBVR_CARDBOARD_VIEWER";function le(e){try{this.selectedKey=localStorage.getItem(ce)}catch(e){console.error("Failed to load viewer profile: %s",e)}this.selectedKey||(this.selectedKey=e||se),this.dialog=this.createDialog_(q.Viewers),this.root=null,this.onChangeCallbacks_=[]}le.prototype.show=function(e){this.root=e,e.appendChild(this.dialog),this.dialog.querySelector("#"+this.selectedKey).checked=!0,this.dialog.style.display="block"},le.prototype.hide=function(){this.root&&this.root.contains(this.dialog)&&this.root.removeChild(this.dialog),this.dialog.style.display="none"},le.prototype.getCurrentViewer=function(){return q.Viewers[this.selectedKey]},le.prototype.getSelectedKey_=function(){var e=this.dialog.querySelector("input[name=field]:checked");return e?e.id:null},le.prototype.onChange=function(e){this.onChangeCallbacks_.push(e)},le.prototype.fireOnChange_=function(e){for(var t=0;t.5&&(this.noSleepVideo.currentTime=Math.random())}.bind(this)))}return r(e,[{key:"enable",value:function(){a?(this.disable(),this.noSleepTimer=window.setInterval((function(){window.location.href="/",window.setTimeout(window.stop,0)}),15e3)):this.noSleepVideo.play()}},{key:"disable",value:function(){a?this.noSleepTimer&&(window.clearInterval(this.noSleepTimer),this.noSleepTimer=null):this.noSleepVideo.pause()}}]),e}();e.exports=o},function(e,t,n){e.exports="data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAACKBtZGF0AAAC8wYF///v3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0MiByMjQ3OSBkZDc5YTYxIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcH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AFdtcDRhAAAAAAAAAAEAAAAAAAAAAAACABAAAAAArEQAAAAAADNlc2RzAAAAAAOAgIAiAAIABICAgBRAFQAAAAADDUAAAAAABYCAgAISEAaAgIABAgAAABhzdHRzAAAAAAAAAAEAAABYAAAEAAAAABxzdHNjAAAAAAAAAAEAAAABAAAAAQAAAAEAAAAUc3RzegAAAAAAAAAGAAAAWAAAAXBzdGNvAAAAAAAAAFgAAAOBAAADhwAAA5oAAAOtAAADswAAA8oAAAPfAAAD5QAAA/gAAAQLAAAEEQAABCgAAAQ9AAAEUAAABFYAAARpAAAEgAAABIYAAASbAAAErgAABLQAAATHAAAE3gAABPMAAAT5AAAFDAAABR8AAAUlAAAFPAAABVEAAAVXAAAFagAABX0AAAWDAAAFmgAABa8AAAXCAAAFyAAABdsAAAXyAAAF+AAABg0AAAYgAAAGJgAABjkAAAZQAAAGZQAABmsAAAZ+AAAGkQAABpcAAAauAAAGwwAABskAAAbcAAAG7wAABwYAAAcMAAAHIQAABzQAAAc6AAAHTQAAB2QAAAdqAAAHfwAAB5IAAAeYAAAHqwAAB8IAAAfXAAAH3QAAB/AAAAgDAAAICQAACCAAAAg1AAAIOwAACE4AAAhhAAAIeAAACH4AAAiRAAAIpAAACKoAAAiwAAAItgAACLwAAAjCAAAAFnVkdGEAAAAObmFtZVN0ZXJlbwAAAHB1ZHRhAAAAaG1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAAO2lsc3QAAAAzqXRvbwAAACtkYXRhAAAAAQAAAABIYW5kQnJha2UgMC4xMC4yIDIwMTUwNjExMDA="}])}))})))&&ue.__esModule&&Object.prototype.hasOwnProperty.call(ue,"default")?ue.default:ue,de=1e3,pe=[0,0,.5,1],fe=[.5,0,.5,1],me=window.requestAnimationFrame,ve=window.cancelAnimationFrame;function ge(e){Object.defineProperties(this,{hasPosition:{writable:!1,enumerable:!0,value:e.hasPosition},hasExternalDisplay:{writable:!1,enumerable:!0,value:e.hasExternalDisplay},canPresent:{writable:!1,enumerable:!0,value:e.canPresent},maxLayers:{writable:!1,enumerable:!0,value:e.maxLayers},hasOrientation:{enumerable:!0,get:function(){return S("VRDisplayCapabilities.prototype.hasOrientation","VRDisplay.prototype.getFrameData"),e.hasOrientation}}})}function ye(e){var t=!("wakelock"in(e=e||{}))||e.wakelock;this.isPolyfilled=!0,this.displayId=de++,this.displayName="",this.depthNear=.01,this.depthFar=1e4,this.isPresenting=!1,Object.defineProperty(this,"isConnected",{get:function(){return S("VRDisplay.prototype.isConnected","VRDisplayCapabilities.prototype.hasExternalDisplay"),!1}}),this.capabilities=new ge({hasPosition:!1,hasOrientation:!1,hasExternalDisplay:!1,canPresent:!1,maxLayers:1}),this.stageParameters=null,this.waitingForPresent_=!1,this.layer_=null,this.originalParent_=null,this.fullscreenElement_=null,this.fullscreenWrapper_=null,this.fullscreenElementCachedStyle_=null,this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null,t&&x()&&(this.wakelock_=new he)}ye.prototype.getFrameData=function(e){return _(e,this._getPose(),this)},ye.prototype.getPose=function(){return S("VRDisplay.prototype.getPose","VRDisplay.prototype.getFrameData"),this._getPose()},ye.prototype.resetPose=function(){return S("VRDisplay.prototype.resetPose"),this._resetPose()},ye.prototype.getImmediatePose=function(){return S("VRDisplay.prototype.getImmediatePose","VRDisplay.prototype.getFrameData"),this._getPose()},ye.prototype.requestAnimationFrame=function(e){return me(e)},ye.prototype.cancelAnimationFrame=function(e){return ve(e)},ye.prototype.wrapForFullscreen=function(e){if(c())return e;if(!this.fullscreenWrapper_){this.fullscreenWrapper_=document.createElement("div");var t=["height: "+Math.min(screen.height,screen.width)+"px !important","top: 0 !important","left: 0 !important","right: 0 !important","border: 0","margin: 0","padding: 0","z-index: 999999 !important","position: fixed"];this.fullscreenWrapper_.setAttribute("style",t.join("; ")+";"),this.fullscreenWrapper_.classList.add("webvr-polyfill-fullscreen-wrapper")}if(this.fullscreenElement_==e)return this.fullscreenWrapper_;if(this.fullscreenElement_&&(this.originalParent_?this.originalParent_.appendChild(this.fullscreenElement_):this.fullscreenElement_.parentElement.removeChild(this.fullscreenElement_)),this.fullscreenElement_=e,this.originalParent_=e.parentElement,this.originalParent_||document.body.appendChild(e),!this.fullscreenWrapper_.parentElement){var n=this.fullscreenElement_.parentElement;n.insertBefore(this.fullscreenWrapper_,this.fullscreenElement_),n.removeChild(this.fullscreenElement_)}this.fullscreenWrapper_.insertBefore(this.fullscreenElement_,this.fullscreenWrapper_.firstChild),this.fullscreenElementCachedStyle_=this.fullscreenElement_.getAttribute("style");var r=this;return function(){if(r.fullscreenElement_){var e=["position: absolute","top: 0","left: 0","width: "+Math.max(screen.width,screen.height)+"px","height: "+Math.min(screen.height,screen.width)+"px","border: 0","margin: 0","padding: 0"];r.fullscreenElement_.setAttribute("style",e.join("; ")+";")}}(),this.fullscreenWrapper_},ye.prototype.removeFullscreenWrapper=function(){if(this.fullscreenElement_){var e=this.fullscreenElement_;this.fullscreenElementCachedStyle_?e.setAttribute("style",this.fullscreenElementCachedStyle_):e.removeAttribute("style"),this.fullscreenElement_=null,this.fullscreenElementCachedStyle_=null;var t=this.fullscreenWrapper_.parentElement;return this.fullscreenWrapper_.removeChild(e),this.originalParent_===t?t.insertBefore(e,this.fullscreenWrapper_):this.originalParent_&&this.originalParent_.appendChild(e),t.removeChild(this.fullscreenWrapper_),e}},ye.prototype.requestPresent=function(e){var t=this.isPresenting,n=this;return e instanceof Array||(S("VRDisplay.prototype.requestPresent with non-array argument","an array of VRLayers as the first argument"),e=[e]),new Promise((function(r,i){if(n.capabilities.canPresent)if(0==e.length||e.length>n.capabilities.maxLayers)i(new Error("Invalid number of layers."));else{var a=e[0];if(a.source){var o=a.leftBounds||pe,s=a.rightBounds||fe;if(t){var u=n.layer_;u.source!==a.source&&(u.source=a.source);for(var h=0;h<4;h++)u.leftBounds[h]=o[h],u.rightBounds[h]=s[h];return n.wrapForFullscreen(n.layer_.source),n.updatePresent_(),void r()}if(n.layer_={predistorted:a.predistorted,source:a.source,leftBounds:o.slice(0),rightBounds:s.slice(0)},n.waitingForPresent_=!1,n.layer_&&n.layer_.source){var d=n.wrapForFullscreen(n.layer_.source);n.addFullscreenListeners_(d,(function(){var e=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement;n.isPresenting=d===e,n.isPresenting?(screen.orientation&&screen.orientation.lock&&screen.orientation.lock("landscape-primary").catch((function(e){console.error("screen.orientation.lock() failed due to",e.message)})),n.waitingForPresent_=!1,n.beginPresent_(),r()):(screen.orientation&&screen.orientation.unlock&&screen.orientation.unlock(),n.removeFullscreenWrapper(),n.disableWakeLock(),n.endPresent_(),n.removeFullscreenListeners_()),n.fireVRDisplayPresentChange_()}),(function(){n.waitingForPresent_&&(n.removeFullscreenWrapper(),n.removeFullscreenListeners_(),n.disableWakeLock(),n.waitingForPresent_=!1,n.isPresenting=!1,i(new Error("Unable to present.")))})),function(e){if(l())return!1;if(e.requestFullscreen)e.requestFullscreen();else if(e.webkitRequestFullscreen)e.webkitRequestFullscreen();else if(e.mozRequestFullScreen)e.mozRequestFullScreen();else{if(!e.msRequestFullscreen)return!1;e.msRequestFullscreen()}return!0}(d)?(n.enableWakeLock(),n.waitingForPresent_=!0):(c()||l())&&(n.enableWakeLock(),n.isPresenting=!0,n.beginPresent_(),n.fireVRDisplayPresentChange_(),r())}n.waitingForPresent_||c()||(g(),i(new Error("Unable to present.")))}else r()}else i(new Error("VRDisplay is not capable of presenting."))}))},ye.prototype.exitPresent=function(){var e=this.isPresenting,t=this;return this.isPresenting=!1,this.layer_=null,this.disableWakeLock(),new Promise((function(n,r){e?(!g()&&c()&&(t.endPresent_(),t.fireVRDisplayPresentChange_()),l()&&(t.removeFullscreenWrapper(),t.removeFullscreenListeners_(),t.endPresent_(),t.fireVRDisplayPresentChange_()),n()):r(new Error("Was not presenting to VRDisplay."))}))},ye.prototype.getLayers=function(){return this.layer_?[this.layer_]:[]},ye.prototype.fireVRDisplayPresentChange_=function(){var e=new CustomEvent("vrdisplaypresentchange",{detail:{display:this}});window.dispatchEvent(e)},ye.prototype.fireVRDisplayConnect_=function(){var e=new CustomEvent("vrdisplayconnect",{detail:{display:this}});window.dispatchEvent(e)},ye.prototype.addFullscreenListeners_=function(e,t,n){this.removeFullscreenListeners_(),this.fullscreenEventTarget_=e,this.fullscreenChangeHandler_=t,this.fullscreenErrorHandler_=n,t&&(document.fullscreenEnabled?e.addEventListener("fullscreenchange",t,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenchange",t,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenchange",t,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenchange",t,!1)),n&&(document.fullscreenEnabled?e.addEventListener("fullscreenerror",n,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenerror",n,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenerror",n,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenerror",n,!1))},ye.prototype.removeFullscreenListeners_=function(){if(this.fullscreenEventTarget_){var e=this.fullscreenEventTarget_;if(this.fullscreenChangeHandler_){var t=this.fullscreenChangeHandler_;e.removeEventListener("fullscreenchange",t,!1),e.removeEventListener("webkitfullscreenchange",t,!1),document.removeEventListener("mozfullscreenchange",t,!1),e.removeEventListener("msfullscreenchange",t,!1)}if(this.fullscreenErrorHandler_){var n=this.fullscreenErrorHandler_;e.removeEventListener("fullscreenerror",n,!1),e.removeEventListener("webkitfullscreenerror",n,!1),document.removeEventListener("mozfullscreenerror",n,!1),e.removeEventListener("msfullscreenerror",n,!1)}this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null}},ye.prototype.enableWakeLock=function(){this.wakelock_&&this.wakelock_.enable()},ye.prototype.disableWakeLock=function(){this.wakelock_&&this.wakelock_.disable()},ye.prototype.beginPresent_=function(){},ye.prototype.endPresent_=function(){},ye.prototype.submitFrame=function(e){},ye.prototype.getEyeParameters=function(e){return null};var Ae={ADDITIONAL_VIEWERS:[],DEFAULT_VIEWER:"",MOBILE_WAKE_LOCK:!0,DEBUG:!1,DPDB_URL:"https://dpdb.webvr.rocks/dpdb.json",K_FILTER:.98,PREDICTION_TIME_S:.04,CARDBOARD_UI_DISABLED:!1,ROTATE_INSTRUCTIONS_DISABLED:!1,YAW_ONLY:!1,BUFFER_SCALE:.5,DIRTY_SUBMIT_FRAME_BINDINGS:!1},xe="left",we="right";function be(e){var t=w({},Ae);e=w(t,e||{}),ye.call(this,{wakelock:e.MOBILE_WAKE_LOCK}),this.config=e,this.displayName="Cardboard VRDisplay",this.capabilities=new ge({hasPosition:!1,hasOrientation:!0,hasExternalDisplay:!1,canPresent:!0,maxLayers:1}),this.stageParameters=null,this.bufferScale_=this.config.BUFFER_SCALE,this.poseSensor_=new ae(this.config),this.distorter_=null,this.cardboardUI_=null,this.dpdb_=new Z(this.config.DPDB_URL,this.onDeviceParamsUpdated_.bind(this)),this.deviceInfo_=new q(this.dpdb_.getDeviceParams(),e.ADDITIONAL_VIEWERS),this.viewerSelector_=new le(e.DEFAULT_VIEWER),this.viewerSelector_.onChange(this.onViewerChanged_.bind(this)),this.deviceInfo_.setViewer(this.viewerSelector_.getCurrentViewer()),this.config.ROTATE_INSTRUCTIONS_DISABLED||(this.rotateInstructions_=new oe),c()&&window.addEventListener("resize",this.onResize_.bind(this))}return be.prototype=Object.create(ye.prototype),be.prototype._getPose=function(){return{position:null,orientation:this.poseSensor_.getOrientation(),linearVelocity:null,linearAcceleration:null,angularVelocity:null,angularAcceleration:null}},be.prototype._resetPose=function(){this.poseSensor_.resetPose&&this.poseSensor_.resetPose()},be.prototype._getFieldOfView=function(e){var t;if(e==xe)t=this.deviceInfo_.getFieldOfViewLeftEye();else{if(e!=we)return console.error("Invalid eye provided: %s",e),null;t=this.deviceInfo_.getFieldOfViewRightEye()}return t},be.prototype._getEyeOffset=function(e){var t;if(e==xe)t=[.5*-this.deviceInfo_.viewer.interLensDistance,0,0];else{if(e!=we)return console.error("Invalid eye provided: %s",e),null;t=[.5*this.deviceInfo_.viewer.interLensDistance,0,0]}return t},be.prototype.getEyeParameters=function(e){var t=this._getEyeOffset(e),n=this._getFieldOfView(e),r={offset:t,renderWidth:.5*this.deviceInfo_.device.width*this.bufferScale_,renderHeight:this.deviceInfo_.device.height*this.bufferScale_};return Object.defineProperty(r,"fieldOfView",{enumerable:!0,get:function(){return S("VRFieldOfView","VRFrameData's projection matrices"),n}}),r},be.prototype.onDeviceParamsUpdated_=function(e){this.config.DEBUG&&console.log("DPDB reported that device params were updated."),this.deviceInfo_.updateDeviceParams(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_)},be.prototype.updateBounds_=function(){this.layer_&&this.distorter_&&(this.layer_.leftBounds||this.layer_.rightBounds)&&this.distorter_.setTextureBounds(this.layer_.leftBounds,this.layer_.rightBounds)},be.prototype.beginPresent_=function(){var e=this.layer_.source.getContext("webgl");e||(e=this.layer_.source.getContext("experimental-webgl")),e||(e=this.layer_.source.getContext("webgl2")),e&&(this.layer_.predistorted?this.config.CARDBOARD_UI_DISABLED||(e.canvas.width=m()*this.bufferScale_,e.canvas.height=v()*this.bufferScale_,this.cardboardUI_=new B(e)):(this.config.CARDBOARD_UI_DISABLED||(this.cardboardUI_=new B(e)),this.distorter_=new C(e,this.cardboardUI_,this.config.BUFFER_SCALE,this.config.DIRTY_SUBMIT_FRAME_BINDINGS),this.distorter_.updateDeviceInfo(this.deviceInfo_)),this.cardboardUI_&&this.cardboardUI_.listen(function(e){this.viewerSelector_.show(this.layer_.source.parentElement),e.stopPropagation(),e.preventDefault()}.bind(this),function(e){this.exitPresent(),e.stopPropagation(),e.preventDefault()}.bind(this)),this.rotateInstructions_&&(f()&&x()?this.rotateInstructions_.showTemporarily(3e3,this.layer_.source.parentElement):this.rotateInstructions_.update()),this.orientationHandler=this.onOrientationChange_.bind(this),window.addEventListener("orientationchange",this.orientationHandler),this.vrdisplaypresentchangeHandler=this.updateBounds_.bind(this),window.addEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler),this.fireVRDisplayDeviceParamsChange_())},be.prototype.endPresent_=function(){this.distorter_&&(this.distorter_.destroy(),this.distorter_=null),this.cardboardUI_&&(this.cardboardUI_.destroy(),this.cardboardUI_=null),this.rotateInstructions_&&this.rotateInstructions_.hide(),this.viewerSelector_.hide(),window.removeEventListener("orientationchange",this.orientationHandler),window.removeEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler)},be.prototype.updatePresent_=function(){this.endPresent_(),this.beginPresent_()},be.prototype.submitFrame=function(e){if(this.distorter_)this.updateBounds_(),this.distorter_.submitFrame();else if(this.cardboardUI_&&this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2"));var n=t.canvas;n.width==this.lastWidth&&n.height==this.lastHeight||this.cardboardUI_.onResize(),this.lastWidth=n.width,this.lastHeight=n.height,this.cardboardUI_.render()}},be.prototype.onOrientationChange_=function(e){this.viewerSelector_.hide(),this.rotateInstructions_&&this.rotateInstructions_.update(),this.onResize_()},be.prototype.onResize_=function(e){if(this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2")),t.canvas.setAttribute("style",["position: absolute","top: 0","left: 0","width: 100vw","height: 100vh","border: 0","margin: 0","padding: 0px","box-sizing: content-box"].join("; ")+";"),b(t.canvas)}},be.prototype.onViewerChanged_=function(e){this.deviceInfo_.setViewer(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_),this.fireVRDisplayDeviceParamsChange_()},be.prototype.fireVRDisplayDeviceParamsChange_=function(){var e=new CustomEvent("vrdisplaydeviceparamschange",{detail:{vrdisplay:this,deviceInfo:this.deviceInfo_}});window.dispatchEvent(e)},be.VRFrameData=function(){this.leftProjectionMatrix=new Float32Array(16),this.leftViewMatrix=new Float32Array(16),this.rightProjectionMatrix=new Float32Array(16),this.rightViewMatrix=new Float32Array(16),this.pose=null},be.VRDisplay=ye,be}()})),s=(e=o)&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,c={ADDITIONAL_VIEWERS:[],DEFAULT_VIEWER:"",PROVIDE_MOBILE_VRDISPLAY:!0,MOBILE_WAKE_LOCK:!0,DEBUG:!1,DPDB_URL:"https://dpdb.webvr.rocks/dpdb.json",K_FILTER:.98,PREDICTION_TIME_S:.04,CARDBOARD_UI_DISABLED:!1,ROTATE_INSTRUCTIONS_DISABLED:!1,YAW_ONLY:!1,BUFFER_SCALE:.5,DIRTY_SUBMIT_FRAME_BINDINGS:!1};function l(e){this.config=a(a({},c),e),this.polyfillDisplays=[],this.enabled=!1,this.hasNative="getVRDisplays"in navigator,this.native={},this.native.getVRDisplays=navigator.getVRDisplays,this.native.VRFrameData=window.VRFrameData,this.native.VRDisplay=window.VRDisplay,(!this.hasNative||this.config.PROVIDE_MOBILE_VRDISPLAY&&r())&&(this.enable(),this.getVRDisplays().then((function(e){e&&e[0]&&e[0].fireVRDisplayConnect_&&e[0].fireVRDisplayConnect_()})))}l.prototype.getPolyfillDisplays=function(){if(this._polyfillDisplaysPopulated)return this.polyfillDisplays;if(r()){var e=new s({ADDITIONAL_VIEWERS:this.config.ADDITIONAL_VIEWERS,DEFAULT_VIEWER:this.config.DEFAULT_VIEWER,MOBILE_WAKE_LOCK:this.config.MOBILE_WAKE_LOCK,DEBUG:this.config.DEBUG,DPDB_URL:this.config.DPDB_URL,CARDBOARD_UI_DISABLED:this.config.CARDBOARD_UI_DISABLED,K_FILTER:this.config.K_FILTER,PREDICTION_TIME_S:this.config.PREDICTION_TIME_S,ROTATE_INSTRUCTIONS_DISABLED:this.config.ROTATE_INSTRUCTIONS_DISABLED,YAW_ONLY:this.config.YAW_ONLY,BUFFER_SCALE:this.config.BUFFER_SCALE,DIRTY_SUBMIT_FRAME_BINDINGS:this.config.DIRTY_SUBMIT_FRAME_BINDINGS});this.polyfillDisplays.push(e)}return this._polyfillDisplaysPopulated=!0,this.polyfillDisplays},l.prototype.enable=function(){if(this.enabled=!0,this.hasNative&&this.native.VRFrameData){var e=this.native.VRFrameData,t=new this.native.VRFrameData,n=this.native.VRDisplay.prototype.getFrameData;window.VRDisplay.prototype.getFrameData=function(r){r instanceof e?n.call(this,r):(n.call(this,t),r.pose=t.pose,i(t.leftProjectionMatrix,r.leftProjectionMatrix),i(t.rightProjectionMatrix,r.rightProjectionMatrix),i(t.leftViewMatrix,r.leftViewMatrix),i(t.rightViewMatrix,r.rightViewMatrix))}}navigator.getVRDisplays=this.getVRDisplays.bind(this),window.VRDisplay=s.VRDisplay,window.VRFrameData=s.VRFrameData},l.prototype.getVRDisplays=function(){var e=this;return this.config,this.hasNative?this.native.getVRDisplays.call(navigator).then((function(t){return t.length>0?t:e.getPolyfillDisplays()})):Promise.resolve(this.getPolyfillDisplays())},l.version="0.10.10",l.VRFrameData=s.VRFrameData,l.VRDisplay=s.VRDisplay;var u=Object.freeze({default:l}),h=u&&l||u;return void 0!==n&&n.window&&(n.document||(n.document=n.window.document),n.navigator||(n.navigator=n.window.navigator)),h},e.exports=n()}).call(this,n(8))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t),n.d(t,"DeviceOrientationControls",(function(){return i}));var r=n(0),i=function(e){var t=this;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0;var n,i,a,o,s=function(e){t.deviceOrientation=e},c=function(){t.screenOrientation=window.orientation||0},l=(n=new r.Vector3(0,0,1),i=new r.Euler,a=new r.Quaternion,o=new r.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),function(e,t,r,s,c){i.set(r,t,-s,"YXZ"),e.setFromEuler(i),e.multiply(o),e.multiply(a.setFromAxisAngle(n,-c))});this.connect=function(){c(),window.addEventListener("orientationchange",c,!1),window.addEventListener("deviceorientation",s,!1),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",c,!1),window.removeEventListener("deviceorientation",s,!1),t.enabled=!1},this.update=function(){if(!1!==t.enabled){var e=t.deviceOrientation;if(e){var n=e.alpha?r.Math.degToRad(e.alpha)+t.alphaOffset:0,i=e.beta?r.Math.degToRad(e.beta):0,a=e.gamma?r.Math.degToRad(e.gamma):0,o=t.screenOrientation?r.Math.degToRad(t.screenOrientation):0;l(t.object.quaternion,n,i,a,o)}}},this.dispose=function(){t.disconnect()},this.connect()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseDotOutput=function(e){return JSON.parse(e.trim().replace(/\\/g,""))}}]); diff --git a/example/package-lock.json b/example/package-lock.json index b60f27b..85ccffd 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -3753,10 +3753,34 @@ "scenemanager": { "version": "file:../scenemanager", "requires": { + "dragdrop": "file:../dragdrop", "three": "^0.110.0", "threeml": "file:../threeml" }, "dependencies": { + "dragdrop": { + "version": "file:../dragdrop", + "requires": { + "three": "^0.110.0" + }, + "dependencies": { + "@types/node": { + "version": "12.12.20", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.20.tgz", + "integrity": "sha512-VAe+DiwpnC/g448uN+/3gRl4th0BTdrR9gSLIOHA+SUQskaYZQDOHG7xmjiE7JUhjbXnbXytf6Ih+/pA6CtMFQ==" + }, + "three": { + "version": "0.110.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.110.0.tgz", + "integrity": "sha512-wlurH8XBO9Sd5VIw8nBa+taLR20kqaI4e9FiuMh6tqK8eOS2q2R+ZoUyufbyDTVTHhs8GiTbv0r2CMLkwerFJg==" + }, + "typescript": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", + "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==" + } + } + }, "three": { "version": "0.110.0", "resolved": "https://registry.npmjs.org/three/-/three-0.110.0.tgz", diff --git a/scenemanager/package-lock.json b/scenemanager/package-lock.json index 178d899..0a6316d 100644 --- a/scenemanager/package-lock.json +++ b/scenemanager/package-lock.json @@ -10,12 +10,27 @@ "integrity": "sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA==", "dev": true }, - "@types/three": { - "version": "0.103.2", - "resolved": "https://registry.npmjs.org/@types/three/-/three-0.103.2.tgz", - "integrity": "sha512-zhtf0Qs5wLJpIn1+VWCpzSgpKayj/GSWZ6woiuz09FW59KEDeLpnBkYz6lbblVpRmGdlnG8nd0unaASshOvcXw==", + "dragdrop": { + "version": "file:../dragdrop", "requires": { - "three": "*" + "three": "^0.110.0" + }, + "dependencies": { + "@types/node": { + "version": "12.12.20", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.20.tgz", + "integrity": "sha512-VAe+DiwpnC/g448uN+/3gRl4th0BTdrR9gSLIOHA+SUQskaYZQDOHG7xmjiE7JUhjbXnbXytf6Ih+/pA6CtMFQ==" + }, + "three": { + "version": "0.110.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.110.0.tgz", + "integrity": "sha512-wlurH8XBO9Sd5VIw8nBa+taLR20kqaI4e9FiuMh6tqK8eOS2q2R+ZoUyufbyDTVTHhs8GiTbv0r2CMLkwerFJg==" + }, + "typescript": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", + "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==" + } } }, "three": { @@ -24,12 +39,34 @@ "integrity": "sha512-wlurH8XBO9Sd5VIw8nBa+taLR20kqaI4e9FiuMh6tqK8eOS2q2R+ZoUyufbyDTVTHhs8GiTbv0r2CMLkwerFJg==" }, "threeml": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/threeml/-/threeml-1.0.11.tgz", - "integrity": "sha512-tpm6gMsDlKtlVPnM2fHc/H7JEROU/Vj80rm3oUd4gxDAqKtO40/vkNvA4UsJ2zywl5DdpS6DF9857o5o3opFvg==", + "version": "file:../threeml", "requires": { - "@types/three": "^0.103.2", "three": "^0.110.0" + }, + "dependencies": { + "@types/node": { + "version": "12.12.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.17.tgz", + "integrity": "sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA==" + }, + "@types/three": { + "version": "0.103.2", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.103.2.tgz", + "integrity": "sha512-zhtf0Qs5wLJpIn1+VWCpzSgpKayj/GSWZ6woiuz09FW59KEDeLpnBkYz6lbblVpRmGdlnG8nd0unaASshOvcXw==", + "requires": { + "three": "*" + } + }, + "three": { + "version": "0.110.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.110.0.tgz", + "integrity": "sha512-wlurH8XBO9Sd5VIw8nBa+taLR20kqaI4e9FiuMh6tqK8eOS2q2R+ZoUyufbyDTVTHhs8GiTbv0r2CMLkwerFJg==" + }, + "typescript": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", + "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==" + } } }, "typescript": {