@ndmspc/ndmvr 0.20220401.0 → 0.20220401.1
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/dist/index.js +100 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +100 -1
- package/dist/index.modern.js.map +1 -1
- package/package.json +9 -4
package/dist/index.modern.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { Subject } from 'rxjs';
|
|
3
3
|
import AFRAME$1 from 'aframe';
|
|
4
|
+
import { io } from 'socket.io-client';
|
|
5
|
+
import { Vector3, Quaternion } from 'three';
|
|
4
6
|
|
|
5
7
|
function _defineProperties(target, props) {
|
|
6
8
|
for (var i = 0; i < props.length; i++) {
|
|
@@ -3263,6 +3265,103 @@ function NdmVrLaboratory() {
|
|
|
3263
3265
|
}));
|
|
3264
3266
|
}
|
|
3265
3267
|
|
|
3268
|
+
var Controller = function Controller(_ref) {
|
|
3269
|
+
var socket = _ref.socket;
|
|
3270
|
+
|
|
3271
|
+
var _useState = useState(0),
|
|
3272
|
+
time = _useState[0],
|
|
3273
|
+
setTime = _useState[1];
|
|
3274
|
+
|
|
3275
|
+
useEffect(function () {
|
|
3276
|
+
var camera = document.getElementById('camera');
|
|
3277
|
+
var absolutePosition = new Vector3();
|
|
3278
|
+
var rotationQuaternion = new Quaternion();
|
|
3279
|
+
camera.object3D.getWorldPosition(absolutePosition);
|
|
3280
|
+
var id = socket.id;
|
|
3281
|
+
var interval = setInterval(function () {
|
|
3282
|
+
camera.object3D.getWorldPosition(absolutePosition);
|
|
3283
|
+
camera.object3D.getWorldQuaternion(rotationQuaternion);
|
|
3284
|
+
socket.emit('move', {
|
|
3285
|
+
id: id,
|
|
3286
|
+
position: absolutePosition.toArray(),
|
|
3287
|
+
rotation: rotationQuaternion.toArray()
|
|
3288
|
+
});
|
|
3289
|
+
setTime(function (prevTime) {
|
|
3290
|
+
return prevTime + 1;
|
|
3291
|
+
});
|
|
3292
|
+
}, 10);
|
|
3293
|
+
return function () {
|
|
3294
|
+
return clearInterval(interval);
|
|
3295
|
+
};
|
|
3296
|
+
}, [time]);
|
|
3297
|
+
return /*#__PURE__*/React.createElement("a-entity", null);
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3300
|
+
var UserWrapper = function UserWrapper(_ref) {
|
|
3301
|
+
var position = _ref.position,
|
|
3302
|
+
rotation = _ref.rotation,
|
|
3303
|
+
id = _ref.id;
|
|
3304
|
+
useEffect(function () {
|
|
3305
|
+
var quaternionToApply = new Quaternion().fromArray(rotation);
|
|
3306
|
+
var user = document.getElementById(id).object3D;
|
|
3307
|
+
user.setRotationFromQuaternion(quaternionToApply);
|
|
3308
|
+
}, [rotation]);
|
|
3309
|
+
return /*#__PURE__*/React.createElement("a-box", {
|
|
3310
|
+
position: position,
|
|
3311
|
+
id: id,
|
|
3312
|
+
color: "#4CC3D9"
|
|
3313
|
+
});
|
|
3314
|
+
};
|
|
3315
|
+
|
|
3316
|
+
var NetworkingComponent = function NetworkingComponent(_ref) {
|
|
3317
|
+
var socketClient = _ref.socketClient,
|
|
3318
|
+
clients = _ref.clients;
|
|
3319
|
+
return /*#__PURE__*/React.createElement("a-entity", null, /*#__PURE__*/React.createElement(Controller, {
|
|
3320
|
+
socket: socketClient
|
|
3321
|
+
}), Object.keys(clients).filter(function (clientKey) {
|
|
3322
|
+
return clientKey !== socketClient.id;
|
|
3323
|
+
}).map(function (client) {
|
|
3324
|
+
var _clients$client = clients[client],
|
|
3325
|
+
position = _clients$client.position,
|
|
3326
|
+
rotation = _clients$client.rotation;
|
|
3327
|
+
var positionParse = position.join(' ');
|
|
3328
|
+
return /*#__PURE__*/React.createElement(UserWrapper, {
|
|
3329
|
+
key: client,
|
|
3330
|
+
id: client,
|
|
3331
|
+
position: positionParse,
|
|
3332
|
+
rotation: rotation
|
|
3333
|
+
});
|
|
3334
|
+
}));
|
|
3335
|
+
};
|
|
3336
|
+
|
|
3337
|
+
var NdmVrShared = function NdmVrShared() {
|
|
3338
|
+
var _useState = useState(0),
|
|
3339
|
+
socketClient = _useState[0],
|
|
3340
|
+
setSocketClient = _useState[1];
|
|
3341
|
+
|
|
3342
|
+
var _useState2 = useState({}),
|
|
3343
|
+
clients = _useState2[0],
|
|
3344
|
+
setClients = _useState2[1];
|
|
3345
|
+
|
|
3346
|
+
useEffect(function () {
|
|
3347
|
+
setSocketClient(io.connect('http://localhost:3001'));
|
|
3348
|
+
return function () {
|
|
3349
|
+
if (socketClient) socketClient.disconnect();
|
|
3350
|
+
};
|
|
3351
|
+
}, []);
|
|
3352
|
+
useEffect(function () {
|
|
3353
|
+
if (socketClient) {
|
|
3354
|
+
socketClient.on('move', function (clients) {
|
|
3355
|
+
setClients(clients);
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
}, [socketClient]);
|
|
3359
|
+
return socketClient && /*#__PURE__*/React.createElement(NetworkingComponent, {
|
|
3360
|
+
socketClient: socketClient,
|
|
3361
|
+
clients: clients
|
|
3362
|
+
});
|
|
3363
|
+
};
|
|
3364
|
+
|
|
3266
3365
|
var NdmVrScene = function NdmVrScene(_ref) {
|
|
3267
3366
|
var data = _ref.data,
|
|
3268
3367
|
info = _ref.info;
|
|
@@ -3284,7 +3383,7 @@ var NdmVrScene = function NdmVrScene(_ref) {
|
|
|
3284
3383
|
projections: data.projections,
|
|
3285
3384
|
range: data.range,
|
|
3286
3385
|
theme: info.theme
|
|
3287
|
-
}));
|
|
3386
|
+
}), /*#__PURE__*/React.createElement(NdmVrShared, null));
|
|
3288
3387
|
};
|
|
3289
3388
|
|
|
3290
3389
|
var EntityBuilder = /*#__PURE__*/function () {
|