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