Nekaj dodatnih funkcij

kegel
Jurij Podgoršek 2022-11-30 16:25:09 +01:00
parent 7053531f40
commit 83e7b42ce9
2 changed files with 65 additions and 14 deletions

View File

@ -10,6 +10,7 @@ function sendAll (address, args) {
oscPort.on("ready", function () {
console.log("OSC listening!")
oscPort.on("message", function (msg) {
//console.log('msg!', msg);
var cb = oscCallbacks[msg.address]
if (cb) {
cb(msg.args)

78
test.js
View File

@ -23,6 +23,8 @@ var accX = 0.000;
var accY = 0.000;
var accZ = 0.000;
var deformiraj = false;
// Scena, kamera in render
var scene = new THREE.Scene;
window.scene = scene;
@ -47,7 +49,9 @@ renderer.setClearColor(0xFFFFFF, 1);
//var skupina = new THREE.Group();
// Dodaj test skatlo
/********
* KEGEL *
*********/
// Sirina in visina test objekta
var width = 16;
@ -55,6 +59,7 @@ var height = 128;
var radialnihSegmentov = 4;
var visinskihSegmentov = 128;
var geo = new THREE.BufferGeometry();
var offset = width;
var polozaji = [];
@ -86,8 +91,6 @@ for (i = 0; i <= konecSegmentov; i++) {
faktor.push((7.4 - i / konecSegmentov * 4.4) / sirinaSegmentov);
}
console.log(faktor);
// spodnji krog
for (var s = 0; s < radialnihSegmentov; s++) {
polozaji.push(
@ -148,15 +151,6 @@ geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
window.geo = geo;
/*
// Deformiramo za kegel
for (var n = 0; n < radialnihSegmentov; n += 1) {
geo.attributes.position.array[1 + n * 3] += 10;
geo.attributes.position.array[1 + n * 3 + 1] += 30;
geo.attributes.position.needsUpdate = true
}
*/
var barva = new THREE.Color(0, 0, 0);
var barvaDodatni = new THREE.Color();
barvaDodatni.setHSL(0.6, 1.0, 0.5);
@ -168,7 +162,7 @@ var mat = new THREE.MeshBasicMaterial({
});
window.mat = mat;
//var mat = new THREE.LineBasicMaterial({ color: 0xff00ff });
var kegel = new THREE.Mesh(geo, mat);
var kegel = new THREE.Mesh(geo.clone(), mat);
kegel.position.z += 64;
//kegel.position.y += 32;
kegel.position.y = -100;
@ -178,10 +172,28 @@ if (izbranKegel == 0) {
kegel.position.x = 40;
}
/*********
* ZOGICE *
*********/
var barvnaPaleta = [
new THREE.Color(0x003F5C),
new THREE.Color(0x58508D),
new THREE.Color(0xBC5090),
new THREE.Color(0xFF6361),
new THREE.Color(0xFFA600),
// Simetrija
new THREE.Color(0xFF6361),
new THREE.Color(0xBC5090),
new THREE.Color(0x58508D),
];
console.log(barvnaPaleta);
var barvnaPaletaIdx = 0;
var barvaKrogleO = new THREE.Color();
barvaKrogleO.setHSL(Math.random(), 0.8, 0.5);
function novaKrogla () {
var barvaKrogle = barvaKrogleO.clone();
//var barvaKrogle = barvaKrogleO.clone();
var barvaKrogle = barvnaPaleta[barvnaPaletaIdx];
var mat = new THREE.MeshBasicMaterial({
color: barvaKrogle,
wireframe: true,
@ -249,6 +261,13 @@ function inputHandle () {
calibrate = true;
sendAll('/ww/calibrate');
}
if (kbdPressed['-']) {
sendAll('/ww/reload');
window.location.reload();
}
if (kbdPressed.d) {
deformiraj = !deformiraj
}
}
@ -262,6 +281,12 @@ function render () {
if (stevec % 10 == 0) {
novaKrogla();
barvnaPaletaIdx = (barvnaPaletaIdx + 1) % barvnaPaleta.length;
while (krogle.length > 50) {
scene.remove(krogle[0]);
krogle.shift();
}
}
};
@ -275,6 +300,24 @@ function objAnim() {
obj.setRotationFromQuaternion(qObj);
AX.scale.x = accX / 1000;
// Deformiranje kegla!
// Random 500 zamaknemo
if (deformiraj) {
var koti = obj.geometry.attributes.position.array;
var faktorD = 5;
for (var i = 0; i < 500; i++) {
koti[Math.floor(Math.random() * koti.length)] += (Math.random() - 1) * faktorD;
}
}
// In priblizamo osnovni geometriji
var koti = kegel.geometry.attributes.position.array;
for (var i = 0; i < koti.length; i++) {
koti[i] = (geo.attributes.position.array[i] - koti[i]) * 0.75;
}
obj.geometry.attributes.position.needsUpdate = true;
});
// Ce jih je prevec, pucaj
while (dodatniObjekti.length > 100) {
@ -311,6 +354,10 @@ function objAnim() {
barvaKrogleO.offsetHSL(-(2/1000), 0, 0);
krogle.map(function (obj) {
obj.material.opacity *= 0.98;
var scaleF = 0.05;
obj.scale.x += scaleF;
obj.scale.y += scaleF;
obj.scale.z += scaleF;
});
// Kalibracija rotacije kegla
@ -409,6 +456,9 @@ oscCallbacks[`${prepend}/gyro`] = function (args) {
oscCallbacks['/ww/calibrate'] = function () {
calibrate = true;
};
oscCallbacks['/ww/reload'] = function () {
window.location.reload();
};
oscCallbacks['/midi'] = function (args) {
//console.log("MAMOMO MIDI!", args);
var minus = (izbranKegel == 1) ? -1 : 1;