Skip to content

Instantly share code, notes, and snippets.

View Utopiah's full-sized avatar

Fabien Benetou Utopiah

View GitHub Profile
// see the alternative that fetch directly from the room to clone
// https://gist.github.com/Utopiah/8eb0d83e467d13994fd69c4631130561
function getObjects(){
var myObjects = []
for (var media of document.querySelectorAll("[media-loader]")){
if (media.components.pinnable && media.components.pinnable.attrValue.pinned)
myObjects.push({
src:media.components['media-loader'].attrValue.src,
position: media.getAttribute('position'),
var board_bbox = {
x_min: -1.2, x_max: -0.8,
z_min: -6, z_max: -2,
}
var player = document.querySelector("#avatar-rig") // only works for the current device running the script
player = document.querySelector("#naf-z83mq48") // Fabien - Utopiah on Quest
var intervalExecuteCheck = setInterval(checkProximityAndExecute, 500)
/* examples of usage :
slides.setupSlides() // load and layout slides with links
slides.nextSlide() // switch to the next slide (loops)
slides.removeAllMedia() // remove all slides
slides.startAutoPresent() // move from slide to slide in the allotated time then drops them all
slides.dropAllContent()
*/
var slides = {
timer:20000, //ms
for (var drawing of document.querySelectorAll("[networked-drawing]")){
drawing.components["networked-drawing"].serializeDrawing().then( pinLastDrawingAsGlb )
drawing.remove()
}
function pinLastDrawingAsGlb(){
var networked = document.querySelectorAll("[networked][animation__pin-end]")
networked[networked.length-1].setAttribute("pinnable", {pinned:true})
}
@Utopiah
Utopiah / hubs_utils.js
Last active November 28, 2022 14:08
Utils functions for Mozilla Hubs scripting
const hubs_utils = {
removeEntitiesFromMediaList,
setPinEntities,
loadAssetsFromURLs,
getAvatarFromName,
getFirstElementFromHash,
objects3DFromPartialName,
getFirstElementFromPartialURL,
getAvatarFromName,
resetUserMediaRotation,
// mandatory settings on authorship
const account_id = 0000000000000000000000 // 18 digits found in /admin#/accounts of the scripting enabled Cloud instance
const email = '[email protected]' // the email account you used to register on that instance
// mandatory settings on execution
const room_ids = ['abc1234', 'def5678'] // the rooms you created and that you want your script to run on
const script_name = 'hubs cloud scripting template'
// optional parameters to restrict execution
const run_only_for_author = true // with false the script is run on every client connecting to that room
var done = '8742' // hashes of objects already in the room
var inprogress = '9125'
var todo = '28d4'
var ideas = {
left: ['InnovateIdeas1', 'InnovateIdeas2'], // to do
right: ['InnovateIdeas3', 'InnovateIdeas4'], // done
back: ['InnovateIdeas5', 'InnovateIdeas6', 'InnovateIdeas7', 'InnovateIdeas8', 'InnovateIdeas9', 'InnovateIdeas10' ], // in progress
}
// examples of animations https://gist.github.com/Utopiah/7b6be1814abc25f027a85878859ed28a#file-collaborative_game_design_demo_hubs-js-L79
var FizzyText = function() {
this.message = 'dat.gui x Mozilla Hubs';
this.jump_anim = 0;
this.scale_anim = 0;
};
var text = new FizzyText();
var gui = new dat.GUI();
// make sure you have DATgui available (e.g execute the code from the console then delete it)
// -------------- object setup
var gramoURL = 'https://poly.google.com/view/9MZ0sCt1REv'
loadAssetsFromURLs([gramoURL])
var obj = getFirstElementFromHash('9MZ0')
// --------
// to execute on the Twitch chat room that will control the Hubs room
var chatHistory = []
function pimvrSaveRemote(page, data) {
// removed to go live, use instead WebSockets or a JSON store e.g. https://jsonbox.io
}
const watchedNode = document.querySelector("[role=log]")
const observer = new MutationObserver(function(mutations) {