Skip to content

Commit

Permalink
Add quizz scene
Browse files Browse the repository at this point in the history
  • Loading branch information
bcopy committed Oct 8, 2024
1 parent 911da0b commit 63006c4
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 213 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ dist
*.obj
*.mtl
public/assets/skybox.png
public/assets/players/
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@tweenjs/tween.js": "25.0.0",
"aframe": "^1.6.0",
"aframe-extras": "^7.5.1",
"aframe-htmlembed-component": "^1.0.0",
"aframe-label": "^0.1.3",
"aframe-orbit-controls": "^1.3.2",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
Expand Down
10 changes: 4 additions & 6 deletions scripts/download-assets.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mkdir -p ../public/assets/coral
mkdir -p ../public/assets/players/skins

curl -o ../public/assets/bottlenose-dolphin.glb https://cmc-cdn.web.cern.ch/assets/reef-simulator/bottlenose-dolphin.glb
curl -o ../public/assets/green-turtle.glb https://cmc-cdn.web.cern.ch/assets/reef-simulator/green-turtle.glb
Expand All @@ -24,9 +25,6 @@ curl -o ../public/assets/coral/montastrea-cavernosa.glb https://cmc-cdn.w
curl -o ../public/assets/coral/pseudodiploria-strigosa.glb https://cmc-cdn.web.cern.ch/assets/reef-simulator/Coral%20Assets/pseudodiploria-strigosa.glb







>>>>>>> Stashed changes
curl -o ../public/assets/players/characterMediumAllAnimations.glb https://cmc-cdn.web.cern.ch/assets/kenney.nl/characterMediumAllAnimations.glb
curl -o /tmp/skins.zip https://cmc-cdn.web.cern.ch/assets/kenney.nl/skins.zip
unzip -o /tmp/skins.zip -d ../public/assets/players/ && rm /tmp/skins.zip
10 changes: 5 additions & 5 deletions src/aframe-scene.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AFRAME from 'aframe';
import NoolsSceneController from './NoolsSceneController';
import NoolsSceneController from './reef/NoolsSceneController';

import './components/caustics';
import './components/bubble';
Expand All @@ -25,10 +25,10 @@ AFRAME.registerComponent('scene-controller', {
this.controller = new NoolsSceneController('ws://localhost:9001');

// // Add some initial corals
this.controller.addCoral('coral1', 0.5);
this.controller.addCoral('coral2', 0.7);
this.controller.addCoral('coral3', 0.6);
// console.log("Hello Wonderful World");
// this.controller.addCoral('coral1', 0.5);
// this.controller.addCoral('coral2', 0.7);
// this.controller.addCoral('coral3', 0.6);
console.log("Hello Wonderful World");
},

// tick: function(time, timeDelta) {
Expand Down
202 changes: 0 additions & 202 deletions src/index.html

This file was deleted.

37 changes: 37 additions & 0 deletions src/quizz-scene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import AFRAME from 'aframe';
import QuizzSceneController from './quizz/QuizzSceneController';

import './components/caustics';
import './components/floating-camera';
import './components/arc-layout';
import './components/texture-map';
import './components/look-towards';

import 'aframe-orbit-controls';
import 'aframe-extras';
import 'aframe-label';
import 'aframe-htmlembed-component';


// Polyfill global Buffer
import { Buffer } from 'buffer';
window.Buffer = Buffer;

const utils = AFRAME.utils;

// AFRAME.registerComponent('scene-controller', {
// init: function() {
// // // Replace with your actual MQTT broker URL
// this.controller = new QuizzSceneController('ws://localhost:9001');

// // // Add some initial corals
// // this.controller.addCoral('coral1', 0.5);
// // this.controller.addCoral('coral2', 0.7);
// // this.controller.addCoral('coral3', 0.6);
// // console.log("Hello Wonderful World");
// },

// // tick: function(time, timeDelta) {
// // // You can add additional per-frame logic here if needed
// // }
// });
94 changes: 94 additions & 0 deletions src/quizz/QuizzSceneController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { createMqttHomieObserver, HomiePropertyBuffer } from '@cmcrobotics/homie-lit';
import * as nools from 'nools';


class PropertyUpdate {
constructor(deviceId, nodeId, propertyId, value) {
this.deviceId = deviceId;
this.nodeId = nodeId;
this.propertyId = propertyId;
this.value = value;
}
}

class Tick {
constructor(time) {
this.time = time;
}
}

class QuizzSceneController {
constructor(brokerUrl, mqttOptions = {}) {
this.homieObserver = createMqttHomieObserver(brokerUrl, mqttOptions);
this.homieObserver.subscribe("gateway/#")
this.propertyBuffer = new HomiePropertyBuffer(this.homieObserver);
this.flow = this.initNoolsFlow();
this.session = this.flow.getSession();
this.tickInterval = 5000;

this.setupPropertyGroups();
this.setupBufferedUpdates();

}

initNoolsFlow() {
const flow = nools.compile(`
rule ProcessPropertyUpdate {
when {
update: PropertyUpdate
}
then {
console.log("Processing property update:", update);
// Implement logic to update AFrame entities based on property updates
}
}
// rule GrowCoral {
// when {
// tick: Tick
// }
// then {
// console.log("Tick received, growing coral at time:", tick.time);
// // Implement coral growth logic
// // This is where you'd update the scale of coral entities
// homieObserver.publish("reef-1/asset-cluster-1/scale", "1.0");
// }
// }
`,{
define:{
PropertyUpdate : PropertyUpdate,
Tick : Tick
},
scope: {
logger: console,
homieObserver: this.homieObserver
},
name: "quizz"
});

return flow;
}

setupPropertyGroups() {
this.propertyBuffer.addPropertyGroup({
name: 'coral',
properties: ['coral/health', 'coral/size', 'coral/color'],
priority: 1
});
// Add more property groups as needed
}

setupBufferedUpdates() {
this.propertyBuffer.processBufferedUpdates((updates) => {
updates.forEach(update => {
this.session.assert(new this.flow.PropertyUpdate(update));
});
this.session.match();
});
}



}

export default QuizzSceneController;
File renamed without changes.
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
aframe: './src/aframe-scene.js',
quizz: './src/quizz-scene.js',
presentation: './src/reveal-presentation.js'
},
output: {
Expand Down

0 comments on commit 63006c4

Please sign in to comment.