teleportxr 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/client/client.js +26 -14
- package/client/geometry_service.js +27 -28
- package/core/core.js +1 -1
- package/package.json +2 -2
- package/scene/resources.js +8 -2
- package/scene/scene.js +5 -1
- package/server copy.js +35 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# TeleportXR
|
|
2
|
+
Teleport virtual reality server for node.js
|
|
3
3
|
|
|
4
4
|
1. Ensure node.js is installed.
|
|
5
|
-
2. Run npm install
|
|
6
|
-
3.
|
|
5
|
+
2. Run npm install teleportxr.
|
|
6
|
+
3. See https://github.com/teleportxr/teleport-nodejs-server-example.git for example usage.
|
package/client/client.js
CHANGED
|
@@ -8,6 +8,7 @@ const node_encoder= require("../protocol/encoders/node_encoder.js");
|
|
|
8
8
|
const resource_encoder= require("../protocol/encoders/resource_encoder.js");
|
|
9
9
|
const WebRtcConnectionManager = require('../connections/webrtcconnectionmanager');
|
|
10
10
|
const resources= require("../scene/resources.js");
|
|
11
|
+
const { BackgroundMode } = require("../core/core.js");
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class OriginState
|
|
@@ -110,6 +111,14 @@ class Client {
|
|
|
110
111
|
Start()
|
|
111
112
|
{
|
|
112
113
|
this.setupCommand=new command.SetupCommand();
|
|
114
|
+
if(this.scene)
|
|
115
|
+
{
|
|
116
|
+
if(this.scene.backgroundTexturePath&&this.scene.backgroundTexturePath!="")
|
|
117
|
+
{
|
|
118
|
+
this.setupCommand.BackgroundMode_backgroundMode=BackgroundMode.TEXTURE;
|
|
119
|
+
this.setupCommand.uid_backgroundTexture=resources.AddTexture(this.scene.backgroundTexturePath);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
113
122
|
this.SendCommand(this.setupCommand);
|
|
114
123
|
}
|
|
115
124
|
SendCommand(command){
|
|
@@ -223,27 +232,30 @@ class Client {
|
|
|
223
232
|
console.log("Sending node "+uid+" "+node.name+" to Client "+this.clientID+", size: "+nodeSize+" bytes");
|
|
224
233
|
this.webRtcConnection.sendGeometry(view2);
|
|
225
234
|
}
|
|
226
|
-
|
|
227
|
-
{
|
|
228
|
-
var mesh=resources.GetResource(uid);
|
|
229
|
-
}
|
|
230
|
-
SendTexture(uid)
|
|
235
|
+
SendGenericResource(uid)
|
|
231
236
|
{
|
|
232
|
-
var
|
|
233
|
-
if(!
|
|
237
|
+
var resource=resources.GetResourceFromUid(uid);
|
|
238
|
+
if(!resource)
|
|
234
239
|
{
|
|
235
|
-
console.warn("No
|
|
240
|
+
console.warn("No resource of uid ",uid," was found.")
|
|
236
241
|
return;
|
|
237
242
|
}
|
|
238
|
-
const
|
|
239
|
-
const buffer = new ArrayBuffer(
|
|
240
|
-
const
|
|
243
|
+
const MAX_BUFFER_SIZE=500;
|
|
244
|
+
const buffer = new ArrayBuffer(MAX_BUFFER_SIZE);
|
|
245
|
+
const resourceSize=resource_encoder.EncodeResource(resource,buffer);
|
|
241
246
|
this.geometryService.EncodedResource(uid);
|
|
242
|
-
const view2 = new DataView(buffer, 0,
|
|
243
|
-
console.log("Sending
|
|
247
|
+
const view2 = new DataView(buffer, 0, resourceSize);
|
|
248
|
+
console.log("Sending resource "+uid+" "+resource.url+" to Client "+this.clientID+", size: "+resourceSize+" bytes");
|
|
244
249
|
this.webRtcConnection.sendGeometry(view2);
|
|
245
250
|
}
|
|
246
|
-
|
|
251
|
+
SendMesh(uid)
|
|
252
|
+
{
|
|
253
|
+
this.SendGenericResource(uid);
|
|
254
|
+
}
|
|
255
|
+
SendTexture(uid)
|
|
256
|
+
{
|
|
257
|
+
this.SendGenericResource(uid);
|
|
258
|
+
}
|
|
247
259
|
receiveHandshake(data)
|
|
248
260
|
{
|
|
249
261
|
if(data.length<message.HandshakeMessage.sizeof()) {
|
|
@@ -130,7 +130,22 @@ class GeometryService
|
|
|
130
130
|
this.streamedNodes.delete(uid);
|
|
131
131
|
// TODO: now reduce the counts for all the dependent resources.
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
StreamOrUnstream(resourceMap,uid,diff)
|
|
134
|
+
{
|
|
135
|
+
if(uid==BigInt(0))
|
|
136
|
+
return;
|
|
137
|
+
if(uid==0)
|
|
138
|
+
return;
|
|
139
|
+
if(!resourceMap.has(uid))
|
|
140
|
+
{
|
|
141
|
+
resourceMap.set(uid,0);
|
|
142
|
+
}
|
|
143
|
+
resourceMap.set(uid,resourceMap.get(uid)+diff);
|
|
144
|
+
}
|
|
145
|
+
AddOrRemoveTexture(thisTextureUid,diff){
|
|
146
|
+
this.StreamOrUnstream(this.streamedTextures,thisTextureUid,diff);
|
|
147
|
+
}
|
|
148
|
+
|
|
134
149
|
AddMeshComponentResources(meshComponent,diff)
|
|
135
150
|
{
|
|
136
151
|
if (meshComponent.getType() != nd.NodeDataType.Mesh)
|
|
@@ -141,7 +156,7 @@ class GeometryService
|
|
|
141
156
|
{
|
|
142
157
|
return;
|
|
143
158
|
}
|
|
144
|
-
this.
|
|
159
|
+
this.StreamOrUnstream(this.streamedMeshes,meshComponent.data_uid,diff);
|
|
145
160
|
//meshNode.skeletonID = node.skeletonNodeID;
|
|
146
161
|
|
|
147
162
|
//Get joint/bone IDs, if the skeletonID is not zero.
|
|
@@ -154,7 +169,7 @@ class GeometryService
|
|
|
154
169
|
}
|
|
155
170
|
if(meshComponent.renderState.globalIlluminationUid != BigInt(0))
|
|
156
171
|
{
|
|
157
|
-
this.
|
|
172
|
+
this.StreamOrUnstream(this.streamedTextures,meshComponent.renderState.globalIlluminationUid,diff);
|
|
158
173
|
}
|
|
159
174
|
}
|
|
160
175
|
|
|
@@ -171,7 +186,7 @@ class GeometryService
|
|
|
171
186
|
{
|
|
172
187
|
continue;
|
|
173
188
|
}
|
|
174
|
-
this.
|
|
189
|
+
this.StreamOrUnstream(this.streamedMaterials,material_uid,diff);
|
|
175
190
|
|
|
176
191
|
var texture_uids =
|
|
177
192
|
[
|
|
@@ -184,7 +199,7 @@ class GeometryService
|
|
|
184
199
|
for(const tex_uid of texture_uids)
|
|
185
200
|
{
|
|
186
201
|
if(tex_uid!=0)
|
|
187
|
-
this.
|
|
202
|
+
this.StreamOrUnstream(this.streamedTextures,tex_uid,diff);
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
205
|
}
|
|
@@ -254,11 +269,11 @@ class GeometryService
|
|
|
254
269
|
if(f)
|
|
255
270
|
{
|
|
256
271
|
if(node.data_uid)
|
|
257
|
-
this.
|
|
272
|
+
this.StreamOrUnstream(this.streamedTextCanvases,f.data_uid,diff);
|
|
258
273
|
if(c.font_uid)
|
|
259
|
-
this.
|
|
274
|
+
this.StreamOrUnstream(this.streamedFontAtlases,f.font_uid,diff);
|
|
260
275
|
if(f.font_texture_uid)
|
|
261
|
-
this.
|
|
276
|
+
this.StreamOrUnstream(this.streamedTextures,f.font_texture_uid,diff);
|
|
262
277
|
}
|
|
263
278
|
}
|
|
264
279
|
}
|
|
@@ -303,22 +318,6 @@ class GeometryService
|
|
|
303
318
|
this.AddOrRemoveNodeAndResources(uid,1);
|
|
304
319
|
}
|
|
305
320
|
}
|
|
306
|
-
AddOrRemoveTexture(thisTextureUid,diff){
|
|
307
|
-
if(thisTextureUid==BigInt(0))
|
|
308
|
-
return;
|
|
309
|
-
if(thisTextureUid==0)
|
|
310
|
-
return;
|
|
311
|
-
if(this.streamedTextures.has(thisTextureUid))
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
else
|
|
316
|
-
{
|
|
317
|
-
this.streamedTextures.set(thisTextureUid,0);
|
|
318
|
-
}
|
|
319
|
-
this.streamedTextures.set(thisTextureUid,this.streamedTextures.get(thisTextureUid)+diff);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
321
|
UpdateTexturesToStream() {
|
|
323
322
|
// scene background?
|
|
324
323
|
var bg_uid=resources.GetResourceUidFromUrl(core.GeometryPayloadType.TexturePointer,this.scene.backgroundTexturePath);
|
|
@@ -375,10 +374,10 @@ class GeometryService
|
|
|
375
374
|
GetMeshesToStream()
|
|
376
375
|
{
|
|
377
376
|
var resource_uids=[];
|
|
378
|
-
|
|
377
|
+
let time_now_us=core.getTimestampUs();
|
|
378
|
+
for(const [uid, count] of this.streamedMeshes)
|
|
379
|
+
{
|
|
379
380
|
//is mesh streamed
|
|
380
|
-
if(!GeometryService.trackedResources.has(uid))
|
|
381
|
-
return;
|
|
382
381
|
var res=GeometryService.GetOrCreateTrackedResource(uid);
|
|
383
382
|
res.Sent(this.clientID,time_now_us);
|
|
384
383
|
if(res.WasSentToClient(this.clientID))
|
|
@@ -395,7 +394,7 @@ class GeometryService
|
|
|
395
394
|
// if it hasn't been sent at all to our client, we add its resources.
|
|
396
395
|
resource_uids.push(uid);
|
|
397
396
|
}
|
|
398
|
-
}
|
|
397
|
+
};
|
|
399
398
|
return resource_uids;
|
|
400
399
|
}
|
|
401
400
|
EncodedResource(resource_uid)
|
package/core/core.js
CHANGED
|
@@ -428,7 +428,7 @@ function put_vec4(dataView, byteOffset, value) {
|
|
|
428
428
|
//! Insert a string to the dataView.
|
|
429
429
|
function put_string(dataView, byteOffset, name) {
|
|
430
430
|
byteOffset = put_uint16(dataView, byteOffset, name.length);
|
|
431
|
-
//Push name.
|
|
431
|
+
// Push name.
|
|
432
432
|
for (var i = 0; i < name.length; i++) {
|
|
433
433
|
var char = name[i];
|
|
434
434
|
var code = char.charCodeAt(0);
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"microtime": "^3.1.1",
|
|
6
6
|
"underscore": "^1.13.7",
|
|
7
7
|
"uuid": "^9.0.1",
|
|
8
|
-
"wrtc": "^0.
|
|
8
|
+
"@roamhq/wrtc": "^0.8.0",
|
|
9
9
|
"ws": "^8.13.0"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"name": "teleportxr",
|
|
15
15
|
"description": "A minimal Teleport server on node.js",
|
|
16
|
-
"version": "1.0.
|
|
16
|
+
"version": "1.0.2",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+https://github.com/simul/teleport-nodejs.git"
|
package/scene/resources.js
CHANGED
|
@@ -56,7 +56,13 @@ function GetResourceFromUid(uid)
|
|
|
56
56
|
//! Add the texture url as a resource.
|
|
57
57
|
function AddTexture(url)
|
|
58
58
|
{
|
|
59
|
-
GetResourceUidFromUrl(core.GeometryPayloadType.TexturePointer,url);
|
|
59
|
+
return GetResourceUidFromUrl(core.GeometryPayloadType.TexturePointer,url);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
//! Add the texture url as a resource.
|
|
63
|
+
function AddMesh(url)
|
|
64
|
+
{
|
|
65
|
+
return GetResourceUidFromUrl(core.GeometryPayloadType.MeshPointer,url);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {Resource,GetResourceFromUrl,GetResourceUidFromUrl,GetResourceFromUid,AddTexture,AddMesh};
|
package/scene/scene.js
CHANGED
package/server copy.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const WebRtcConnectionManager = require('./connections/webrtcconnectionmanager');
|
|
4
|
+
const cm = require('./client/client_manager.js');
|
|
5
|
+
|
|
6
|
+
const signaling=require("./signaling.js");
|
|
7
|
+
const scene=require("./scene/scene.js");
|
|
8
|
+
|
|
9
|
+
var sc=new scene.Scene();
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const assetsPath = path.join(__dirname,'assets');
|
|
15
|
+
|
|
16
|
+
sc.Load(path.join(assetsPath,'scene.json'));
|
|
17
|
+
|
|
18
|
+
// This is our app's callback for when a new client is to be created.
|
|
19
|
+
// It must return the origin uid for the client.
|
|
20
|
+
function createNewClient(clientID) {
|
|
21
|
+
var origin_uid=sc.CreateNode();
|
|
22
|
+
return origin_uid;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// This will be called AFTER a client has been created, so we can access it from the clientManager.
|
|
26
|
+
function onClientPostCreate(clientID) {
|
|
27
|
+
var client=cm.getInstance().GetClient(clientID);
|
|
28
|
+
client.SetScene(sc);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const webRtcConnectionManager = WebRtcConnectionManager.getInstance();
|
|
32
|
+
webRtcConnectionManager.SetSendConfigMessage(signaling.sendConfigMessage);
|
|
33
|
+
cm.getInstance().SetNewClientCallback(createNewClient);
|
|
34
|
+
cm.getInstance().SetClientPostCreationCallback(onClientPostCreate);
|
|
35
|
+
signaling.init(webRtcConnectionManager,cm.getInstance().newClient.bind(cm.getInstance()));
|