forked from hbb1/2d-gaussian-splatting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork_gui.py
98 lines (87 loc) · 3.05 KB
/
network_gui.py
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
#
# Copyright (C) 2023, Inria
# GRAPHDECO research group, https://team.inria.fr/graphdeco
# All rights reserved.
#
# This software is free for non-commercial, research and evaluation use
# under the terms of the LICENSE.md file.
#
# For inquiries contact [email protected]
#
import torch
import traceback
import socket
import json
import struct
from scene.cameras import MiniCam
host = "127.0.0.1"
port = 6009
conn = None
addr = None
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def init(wish_host, wish_port):
global host, port, listener
host = wish_host
port = wish_port
listener.bind((host, port))
listener.listen()
listener.settimeout(0)
def send_json_data(conn, data):
# Serialize the list of strings to JSON
serialized_data = json.dumps(data)
# Convert the serialized data to bytes
bytes_data = serialized_data.encode('utf-8')
# Send the length of the serialized data first
conn.sendall(struct.pack('I', len(bytes_data)))
# Send the actual serialized data
conn.sendall(bytes_data)
def try_connect(render_items):
global conn, addr, listener
try:
conn, addr = listener.accept()
# print(f"\nConnected by {addr}")
conn.settimeout(None)
send_json_data(conn, render_items)
except Exception as inst:
pass
# raise inst
def read():
global conn
messageLength = conn.recv(4)
messageLength = int.from_bytes(messageLength, 'little')
message = conn.recv(messageLength)
return json.loads(message.decode("utf-8"))
def send(message_bytes, verify, metrics):
global conn
if message_bytes != None:
conn.sendall(message_bytes)
conn.sendall(len(verify).to_bytes(4, 'little'))
conn.sendall(bytes(verify, 'ascii'))
send_json_data(conn, metrics)
def receive():
message = read()
width = message["resolution_x"]
height = message["resolution_y"]
if width != 0 and height != 0:
try:
do_training = bool(message["train"])
fovy = message["fov_y"]
fovx = message["fov_x"]
znear = message["z_near"]
zfar = message["z_far"]
keep_alive = bool(message["keep_alive"])
scaling_modifier = message["scaling_modifier"]
world_view_transform = torch.reshape(torch.tensor(message["view_matrix"]), (4, 4)).cuda()
world_view_transform[:,1] = -world_view_transform[:,1]
world_view_transform[:,2] = -world_view_transform[:,2]
full_proj_transform = torch.reshape(torch.tensor(message["view_projection_matrix"]), (4, 4)).cuda()
full_proj_transform[:,1] = -full_proj_transform[:,1]
custom_cam = MiniCam(width, height, fovy, fovx, znear, zfar, world_view_transform, full_proj_transform)
render_mode = message["render_mode"]
except Exception as e:
print("")
traceback.print_exc()
# raise e
return custom_cam, do_training, keep_alive, scaling_modifier, render_mode
else:
return None, None, None, None, None