I'm currently learning three.js and experimenting with image transformations.
After seeing a cool effect demonstrated here, I'm interested in replicating it.
Can anyone provide guidance on the steps to achieve similar image transformations?
So far, I've set up a loader:
// instantiate a loader
var loader = new THREE.TextureLoader();
// load a resource
loader.load(
// resource URL
'clouds.jpg',
// Function when resource is loaded
function (texture) {
init(new THREE.MeshBasicMaterial({
map: texture
}));
},
// Function called when download progresses
function (xhr) {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
// Function called when download errors
function (xhr) {
console.log('An error happened');
}
);
var init = function(material) {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var rectLength = window.innerHeight;
var rectWidth = window.innerWidth;
var rectShape = new THREE.Shape();
rectShape.moveTo(0,0);
rectShape.lineTo(0, rectWidth);
rectShape.lineTo(rectLength, rectWidth);
rectShape.lineTo(rectLength, 0);
rectShape.lineTo(0, 0);
var geometry = new THREE.ShapeGeometry(rectShape);
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 1;
var render = function () {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
render();
}
Currently, the image renders as a flat 2D shape but I'm unsure how to implement effects within the render
function.
Would it be better to handle this in plain WebGL?
Any advice, tips, or tutorials would be greatly appreciated!