After successfully building a panorama with three.js using the CSS3D renderer, I am now looking to achieve the same result using the WebGL renderer.
When working with CSS3D, I utilized the following code to create a seamless panorama:
var sides = [
{
url: '/assets/posx.jpg',
position: [ -644, 0, 0 ],
rotation: [ 0, Math.PI / 2, 0 ]
},
{
url: '/assets/negx.jpg',
position: [ 644, 0, 0 ],
rotation: [ 0, -Math.PI / 2, 0 ]
},
{
url: '/assets/posy.jpg',
position: [ 0, 644, 0 ],
rotation: [ Math.PI / 2, 0, Math.PI ]
},
{
url: '/assets/negy.jpg',
position: [ 0, -644, 0 ],
rotation: [ -Math.PI / 2, 0, Math.PI ]
},
{
url: '/assets/posz.jpg',
position: [ 0, 0, 644 ],
rotation: [ 0, Math.PI, 0 ]
},
{
url: '/assets/negz.jpg',
position: [ 0, 0, -644 ],
rotation: [ 0, 0, 0 ]
}
];
for (var i = 0; i < sides.length; i++) {
var side = sides[ i ];
var element = document.createElement('img');
element.width = 1300;
element.height = 1300;
element.src = side.url;
var object = new THREE.CSS3DObject(element);
object.position.fromArray(side.position);
object.rotation.fromArray(side.rotation);
scene.add(object);
}
[side question: there has to be a better way to format pasted code other than going line by line and hitting space 4 times, right?]
Now, in my attempt to achieve the same panorama effect using WebGL, the code renders the images but lacks the clean, seamless transition seen in the CSS3D version:
var sides = [
{
url: '/assets/posx.jpg'
},
{
url: '/assets/negx.jpg'
},
{
url: '/assets/posy.jpg'
},
{
url: '/assets/negy.jpg'
},
{
url: '/assets/posz.jpg'
},
{
url: '/assets/negz.jpg'
}
];
var k = 8; // Chose 8 to avoid image distortions
for (var i = 0; i < sides.length; i++) {
var side = sides[ i ];
var geometry = new THREE.SphereGeometry(10, k, k);
k += 8;
geometry.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
var material = new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture(side.url)
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
}
Is there a recommended method or standard practice for projecting six images into a panorama using Three.js and the WebGL rendering engine?