Skip to content

Commit

Permalink
Merge pull request #159 from SuperViz/fix/matterport-circle
Browse files Browse the repository at this point in the history
fix: matterport circle
  • Loading branch information
carlossantos74 authored Dec 4, 2024
2 parents ec99c92 + e85437e commit af3e48f
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/autodesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/autodesk-viewer-plugin",
"version": "1.22.4-lab.1",
"version": "1.22.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/matterport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/matterport-plugin",
"version": "1.2.4-lab.1",
"version": "1.2.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
1 change: 1 addition & 0 deletions packages/matterport/src/common/types/coordinates.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export interface Simple2DPoint {
}

export type Coordinates = Simple2DPoint & { z: number }
export type CirclePosition = Coordinates & { slot: number }
69 changes: 41 additions & 28 deletions packages/matterport/src/services/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isEqual } from 'lodash';
import { Vector3, Quaternion } from 'three';

import { Avatar, AvatarsConstants, Name } from '../common/types/avatars.types';
import { Coordinates, DefaultCoordinates, Simple2DPoint } from '../common/types/coordinates.types';
import { CirclePosition, Coordinates, DefaultCoordinates, Simple2DPoint } from '../common/types/coordinates.types';
import { Laser } from '../common/types/lasers.types';
import type { MpSdk as Matterport, Rotation } from '../common/types/matterport.types';
import { Logger } from '../common/utils/logger';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Presence3D {
private currentLocalFloorId: number;
private currentLocalMode: Matterport.Mode.Mode;
private currentLocalLaserDest: Coordinates = DefaultCoordinates;
private circlePositions: Coordinates[] = [];
private circlePositions: CirclePosition[] = [];
private currentSweepId: string;

private THREE;
Expand Down Expand Up @@ -475,6 +475,8 @@ export class Presence3D {
if (unsubscribe) {
this.presence3DManager?.unsubscribeFromUpdates(participant.id, this.onParticipantUpdated);
}

this.createCircleOfPositions();
};

private addParticipant = async (participant): Promise<void> => {
Expand Down Expand Up @@ -506,6 +508,8 @@ export class Presence3D {
this.config.isAvatarsEnabled && (await this.createAvatar(participantOn3D));
this.config.isLaserEnabled && this.createLaser(participantOn3D);
this.config.isNameEnabled && this.createName(participantOn3D, this.avatars[participant.id]);

this.createCircleOfPositions();
};

/**
Expand Down Expand Up @@ -889,58 +893,67 @@ export class Presence3D {
if (!this.presence3DManager) {
return position;
}

this.localSlot = this.localParticipant.slot?.index ?? -1;

if (!this.THREE || this.localSlot === -1) {
return position;
}

const calculatedPos = new this.THREE.Vector3(position?.x, position?.y, position?.z);
if (!this.circlePositions[this.localSlot]) {
const positionInTheCircle = this.circlePositions.find(
(position) => position.slot === this.localSlot,
);

if (!positionInTheCircle) {
return position;
}

if (!this.currentCirclePosition?.isVector3) {
this.currentCirclePosition = new this.THREE.Vector3(
this.circlePositions[this.localSlot].x,
positionInTheCircle.x,
position.y,
this.circlePositions[this.localSlot].z,
positionInTheCircle.z,
);
}

this.currentCirclePosition.set(
this.circlePositions[this.localSlot].x,
positionInTheCircle.x,
position.y,
this.circlePositions[this.localSlot].z,
positionInTheCircle.z,
);

calculatedPos.add(
this.currentCirclePosition.multiplyScalar(AvatarsConstants.DISTANCE_BETWEEN_AVATARS),
);

return { x: calculatedPos.x, y: position.y, z: calculatedPos.z };
};

private createCircleOfPositions(): void {
const amountOfPeople = 50;
let radiusOfCircle = amountOfPeople * 0.3;
this.circlePositions = [];
const participants = [
...Object.values(this.participants),
this.localParticipant,
].sort((a, b) => {
return (a.slot?.index || 0) - (b.slot?.index || 0);
});

let degrees = 0;
const participantCount = participants.length;
if (participantCount === 0) return;

// minimum radius
if (radiusOfCircle < 2) {
radiusOfCircle = 2;
}
const radius = Math.max(participantCount * 0.3, 2);
const angleStep = (2 * Math.PI) / participantCount;

for (let i = 0; i < amountOfPeople; i++) {
degrees = i * (360 / amountOfPeople);
const radian = degrees * (Math.PI / 180);
const x = radiusOfCircle * Math.cos(radian);
const y = 0;
const z = radiusOfCircle * Math.sin(radian);
if (i !== 0) {
const pos = { x, y, z };
if (i % 2 === 0) {
this.circlePositions.push(pos);
} else {
this.circlePositions.unshift(pos);
}
}
for (let i = 0; i < participantCount; i++) {
const angle = i * angleStep;
const x = radius * Math.cos(angle);
const z = radius * Math.sin(angle);
this.circlePositions.push({ x, y: 0, z, slot: participants[i]?.slot?.index ?? -1 });
}

this.adjustMyPositionToCircle(this.currentLocalPosition);
this.logger.log('Updated circle positions:', this.circlePositions);
}

private onParticipantsUpdated = (participants) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@superviz/react-sdk",
"private": false,
"version": "1.14.4-lab.3",
"version": "1.14.4",
"type": "module",
"scripts": {
"watch": "./node_modules/typescript/bin/tsc && vite build --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/realtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/realtime",
"version": "1.2.4-lab.1",
"version": "1.2.4",
"description": "SuperViz Real-Time",
"main": "./dist/node/index.cjs.js",
"module": "./dist/browser/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/sdk",
"version": "6.7.4-lab.3",
"version": "6.7.4",
"description": "SuperViz SDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/socket-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/socket-client",
"version": "1.13.4-lab.3",
"version": "1.13.4",
"description": "SuperViz Socket Client",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/three/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/threejs-plugin",
"version": "1.2.4-lab.1",
"version": "1.2.4",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/yjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/yjs",
"version": "1.0.4-lab.1",
"version": "1.0.4",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit af3e48f

Please sign in to comment.