-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexOnward2.html
85 lines (71 loc) · 3.1 KB
/
indexOnward2.html
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
<!DOCTYPE html>
<title>Beatsaber Space</title>
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected]/build/three.min.js,npm/[email protected]/dist/altspace.min.js,npm/[email protected]/js/altspaceutil.min.js">
</script>
<script>
altspaceutil.getFullspaceApp().then(app => {
altspace.getUser().then(user => {
let whitelistedUserIds = [/* list of userids to whitelist (in per-domain format) */];
let isWhitelistedUser = (user.isModerator || (whitelistedUserIds.length > 0 && whitelistedUserIds.indexOf(user.userId) >= 0));;
console.log(altspace.getUser());
if(altspace.inClient) {
if(!isWhitelistedUser) {
let nboxcollider = new THREE.Mesh(new THREE.BoxBufferGeometry(24.9, 38.66379, 24.84183), new THREE.MeshBasicMaterial({ color: 0xff0000, visible: false }));
nboxcollider.position.set(59.49, 5.51, 63);
app.anchor.add(nboxcollider);
nboxcollider.addBehaviors(
new altspaceutil.behaviors.NativeComponent('n-box-collider', { size: { x: 24.9, y: 38.66379, z: 24.84183 } }),
new UserWhitelistRestrictedVolume(kickTarget, whitelistedUserIds)
);
// Add Restricted Zone For Whitelisted Users
let kickTarget = new THREE.Object3D();
kickTarget.position.set(-36.69, 0.813, -61.341);
app.anchor.add(kickTarget);
let restrictedArea = new THREE.Mesh(new THREE.BoxBufferGeometry(24.9, 38.66379, 24.84183), new THREE.MeshBasicMaterial({ visible: false }));
altspaceutil.setCursorCollider(this.object3d, false);
restrictedArea.position.set(59.49, 5.51, 63);
restrictedArea.addBehavior(new UserWhitelistRestrictedVolume(kickTarget, whitelistedUserIds));
app.anchor.add(restrictedArea);
}
}
});
class UserWhitelistRestrictedVolume {
constructor(target, whitelistedUserIds) {
this.target = target;
this.userids = whitelistedUserIds || [];
this.enabled = true;
}
awake(o, s) {
this.loading = true;
this.scene = s;
this.object3d = o;
this.object3d.visible = false;
Promise.all([altspace.getUser(), altspace.getThreeJSTrackingSkeleton()]).then(resolvers => {
let [user, skeleton] = resolvers;
if(this.loading) {
this.loading = false;
this.user = user;
if(!skeleton.parent) this.scene.add(skeleton);
this.avatar = skeleton.getJoint('Spine');
this.portal = new THREE.Object3D();
this.portal.visible = false;
this.portal.addBehavior(new altspaceutil.behaviors.NativeComponent('n-portal', {}, { targetEntity: this.target }));
this.scene.add(this.portal);
this.box = new THREE.Box3();
}
});
}
update(deltaTime) {
if(this.box) {
this.box.setFromObject(this.object3d);
if(altspace.inClient) {this.portal.position.copy(this.avatar.position);}
let isWhitelistedUser = (!this.enabled || this.user.isModerator || (this.userids.length > 0 && this.userids.indexOf(this.user.userId) >= 0));
this.portal.visible = (!isWhitelistedUser && this.avatar && this.box.containsPoint(this.avatar.position));
}
}
dispose() {
if(this.loading) this.loading = false;
}
};
}).catch(e => console.log(e));
</script>