From 8d42b583ddf952e97728a7af3a46e0c4bc42aebb Mon Sep 17 00:00:00 2001 From: skaljac Date: Tue, 30 Nov 2021 16:43:04 +0100 Subject: [PATCH 1/4] Wind parameters added --- plugins/rollup.js | 4 ++- type_templates/windsettings.js | 50 ++++++++++++++++++++++++++++++++++ types/windsettings.js | 22 +++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 type_templates/windsettings.js create mode 100644 types/windsettings.js diff --git a/plugins/rollup.js b/plugins/rollup.js index 8228a90..0a3ae30 100644 --- a/plugins/rollup.js +++ b/plugins/rollup.js @@ -31,6 +31,7 @@ const text = require('../types/text.js'); //const fog = require('../types/fog.js'); // const background = require('../types/background.js'); const rendersettings = require('../types/rendersettings.js'); +const windsettings = require('../types/windsettings.js'); const spawnpoint = require('../types/spawnpoint.js'); const group = require('../types/group.js'); const directory = require('../types/.js'); @@ -55,6 +56,7 @@ const loaders = { // fog, // background, rendersettings, + windsettings, spawnpoint, group, '': directory, @@ -75,7 +77,7 @@ const _getType = id => { } let extension; let match2; - if (match2 = type.match(/^application\/(light|text|rendersettings|group|spawnpoint)$/)) { + if (match2 = type.match(/^application\/(light|text|rendersettings|group|spawnpoint|windsettings)$/)) { extension = match2[1]; } else { extension = mimeTypes.extension(type); diff --git a/type_templates/windsettings.js b/type_templates/windsettings.js new file mode 100644 index 0000000..7534299 --- /dev/null +++ b/type_templates/windsettings.js @@ -0,0 +1,50 @@ +import * as THREE from 'three'; +import metaversefile from 'metaversefile'; +const {useApp, useFrame, useCleanup, useWorld} = metaversefile; + +const localVector = new THREE.Vector3(); +const localVector2 = new THREE.Vector3(); + +export default e => { + const app = useApp(); + app.appType = 'wind'; + + // const {gifLoader} = useLoaders(); + const world = useWorld(); + + const srcUrl = '${this.srcUrl}'; + + e.waitUntil((async () => { + const res = await fetch(srcUrl); + const j = await res.json(); + let {forceFactor, direction, gravity} = j; + + const windParameters = world.getWindParameters(); + windParameters.forceFactor = forceFactor; + windParameters.direction = new THREE.Vector3(); + windParameters.direction.fromArray(direction); + windParameters.gravity = new THREE.Vector3(); + windParameters.gravity.fromArray(gravity); + + console.log(forceFactor, direction, gravity); + + console.log(windParameters); + + })()); + + useFrame(() => { + + }); + + useCleanup(() => { + + const windParameters = world.getWindParameters(); + + windParameters.forceFactor = 0; + windParameters.direction.set(0,0,0); + windParameters.gravity.set(0,-1,0); + + }); + + return app; +}; \ No newline at end of file diff --git a/types/windsettings.js b/types/windsettings.js new file mode 100644 index 0000000..6955bf5 --- /dev/null +++ b/types/windsettings.js @@ -0,0 +1,22 @@ +const path = require('path'); +const fs = require('fs'); +const {fillTemplate} = require('../util.js'); + +const templateString = fs.readFileSync(path.join(__dirname, '..', 'type_templates', 'windsettings.js'), 'utf8'); +const cwd = process.cwd(); + +module.exports = { + load(id) { + if (id.startsWith(cwd)) { + id = id.slice(cwd.length); + } + const code = fillTemplate(templateString, { + srcUrl: id, + }); + // console.log('got image id', id); + return { + code, + map: null, + }; + }, +}; \ No newline at end of file From e4dcbe032694b436261efa14af145e2460ac50ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20=C5=A0kaljac?= Date: Tue, 30 Nov 2021 18:19:39 +0100 Subject: [PATCH 2/4] Console.log removed --- type_templates/windsettings.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/type_templates/windsettings.js b/type_templates/windsettings.js index 7534299..ea130ae 100644 --- a/type_templates/windsettings.js +++ b/type_templates/windsettings.js @@ -26,10 +26,6 @@ export default e => { windParameters.gravity = new THREE.Vector3(); windParameters.gravity.fromArray(gravity); - console.log(forceFactor, direction, gravity); - - console.log(windParameters); - })()); useFrame(() => { @@ -47,4 +43,4 @@ export default e => { }); return app; -}; \ No newline at end of file +}; From 7986bcee2c4e8567a7c332a3c9002ecaebff816c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20=C5=A0kaljac?= Date: Thu, 2 Dec 2021 17:37:38 +0100 Subject: [PATCH 3/4] refreshDelay parameter added --- type_templates/windsettings.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/type_templates/windsettings.js b/type_templates/windsettings.js index ea130ae..0f17d3d 100644 --- a/type_templates/windsettings.js +++ b/type_templates/windsettings.js @@ -17,10 +17,11 @@ export default e => { e.waitUntil((async () => { const res = await fetch(srcUrl); const j = await res.json(); - let {forceFactor, direction, gravity} = j; + let {forceFactor, direction, gravity, refreshDelay} = j; const windParameters = world.getWindParameters(); windParameters.forceFactor = forceFactor; + windParameters.refreshDelay = refreshDelay; windParameters.direction = new THREE.Vector3(); windParameters.direction.fromArray(direction); windParameters.gravity = new THREE.Vector3(); @@ -37,6 +38,7 @@ export default e => { const windParameters = world.getWindParameters(); windParameters.forceFactor = 0; + windParameters.refreshDelay = 10000.0; //10s windParameters.direction.set(0,0,0); windParameters.gravity.set(0,-1,0); From 2b732e3d8801e6a041879da58ca19a7748c61d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20=C5=A0kaljac?= Date: Thu, 2 Dec 2021 17:55:28 +0100 Subject: [PATCH 4/4] Gravity parameter removed --- type_templates/windsettings.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/type_templates/windsettings.js b/type_templates/windsettings.js index 0f17d3d..e93f896 100644 --- a/type_templates/windsettings.js +++ b/type_templates/windsettings.js @@ -17,15 +17,13 @@ export default e => { e.waitUntil((async () => { const res = await fetch(srcUrl); const j = await res.json(); - let {forceFactor, direction, gravity, refreshDelay} = j; + let {forceFactor, direction, refreshDelay} = j; const windParameters = world.getWindParameters(); windParameters.forceFactor = forceFactor; windParameters.refreshDelay = refreshDelay; windParameters.direction = new THREE.Vector3(); windParameters.direction.fromArray(direction); - windParameters.gravity = new THREE.Vector3(); - windParameters.gravity.fromArray(gravity); })()); @@ -40,7 +38,6 @@ export default e => { windParameters.forceFactor = 0; windParameters.refreshDelay = 10000.0; //10s windParameters.direction.set(0,0,0); - windParameters.gravity.set(0,-1,0); });