sasha240100 a0471c9e8c Replace swig rendering engine with pug
Former-commit-id: 1180e65c0209b26897944c7f4e920f8dbfe7db2a
2017-01-09 03:54:10 +02:00

102 lines
2.0 KiB
JavaScript

import * as UTILS from '../../globals';
WHS.Component.prototype.changeColor = function (world) {
const object = this,
color = new THREE.Color();
const animation = new WHS.Loop(() => {
object.material.color = color;
if (color.r <= 1)
color.r += 0.01;
if (color.g >= 0)
color.g -= 0.01;
if (color.b >= 0)
color.b -= 0.01;
if (color.r >= 1) {
animation.stop(world);
object.material.color.setRGB(1, 0, 0);
const animation2 = new WHS.Loop(() => {
object.material.color = color;
if (color.r >= 0)
color.r -= 0.01;
if (color.g <= 1)
color.g += 0.01;
if (color.b >= 0)
color.b -= 0.01;
if (color.r <= 0 && color.g >= 1) {
animation2.stop(world);
object.material.color.setRGB(1, 0, 0);
const animation3 = new WHS.Loop(() => {
object.material.color = color;
if (color.r >= 0)
color.r -= 0.01;
if (color.g >= 0)
color.g -= 0.01;
if (color.b <= 1)
color.b += 0.01;
if (color.g <= 0 && color.b >= 1) {
animation3.stop(world);
object.material.color.setRGB(0, 0, 1);
animation.start(world);
}
});
animation3.start(world);
}
});
animation2.start(world);
}
});
animation.start(world);
};
const world = new (PHYSICS.$world(WHS.World))({
...UTILS.$world,
physics: {
ammo: process.ammoPath
},
camera: {
far: 10000,
position: [0, 10, 30]
}
});
const torus = new WHS.Torus({
geometry: {
radius: 5,
tube: 2
},
mass: 0,
material: {
color: UTILS.$colors.mesh,
kind: 'phong'
},
position: {
x: 0,
y: 10,
z: 0
}
});
world.add(torus);
torus.changeColor(world);
UTILS.addBoxPlane(world, 250);
UTILS.addBasicLights(world);
world.setControls(new WHS.OrbitControls());
world.start();