repo: janusweb action: commit revision: path_from: revision_from: e6c4b89e5ce68bf43538b3b499ca3be1255b8f34: path_to: revision_to:
commit e6c4b89e5ce68bf43538b3b499ca3be1255b8f34 Author: James BaicoianuDate: Thu Oct 22 23:06:42 2020 -0700 Support for URL hash pointing to 3d world spawnpoint diff --git a/scripts/room.js b/scripts/room.js
--- a/scripts/room.js
+++ b/scripts/room.js
@@ -19,6 +19,7 @@ elation.require([
this.defineProperties({
'janus': { type: 'object' },
'url': { type: 'string', default: false },
+ 'urlfragment': { type: 'string', default: false },
'referrer': { type: 'string' },
'deferload': { type: 'boolean', default: false },
'roomid': { type: 'string' },
@@ -126,6 +127,11 @@ elation.require([
};
if (this.url) {
+ let hashidx = this.url.indexOf('#');
+ if (hashidx != -1) {
+ this.urlhash = this.url.substr(hashidx+1);
+ this.url = this.url.substr(0, hashidx);
+ }
this.roomid = md5(this.url);
if (!this.deferload) {
this.load(this.url, this.baseurl);
@@ -220,9 +226,19 @@ elation.require([
player.properties.movestrength = 80 * this.properties.walk_speed;
player.properties.runstrength = 80 * this.properties.run_speed;
player.cursor_visible = elation.utils.any(this.cursor_visible, true);
+ player.cursor_opacity = 1;
// FIXME - for some reason the above call sometimes orients the player backwards. Doing it on a delay fixes it...
//setTimeout(elation.bind(player, player.reset_position), 0);
}
+ this.setHash = function(hash) {
+ this.urlhash = hash;
+ if (document.location.origin + document.location.pathname == this.url) {
+ document.location.hash = hash;
+ }
+ let spawnpoint = this.getSpawnpoint();
+ player.startposition.copy(spawnpoint.position);
+ player.startorientation.copy(spawnpoint.orientation);
+ }
this.getSpawnpoint = function(referrer) {
let spawnpoint = {
position: this.spawnpoint.position,
@@ -238,6 +254,12 @@ elation.require([
break;
}
}
+ } else if (this.urlhash) {
+ let obj = this.getObjectById(this.urlhash);
+ if (obj) {
+ obj.localToWorld(spawnpoint.position.set(0,0,0));
+ spawnpoint.orientation.setFromRotationMatrix(obj.objects['3d'].matrixWorld);
+ }
}
return spawnpoint;
}
-----END OF PAGE-----