Experimenting with three.js and bootstrap, I encountered an issue where the cube appears flattened when using bootstrap grids:
https://i.sstatic.net/M2G4D.jpg
Oddly, resizing the window fixes the problem:
https://i.sstatic.net/E09BL.jpg
Attempts to remedy this in css were unsuccessful, here's what I tried:
CSS
@media(min-width:768px) {
canvas {
display: block;
width: 100% !important;
height: 33% !important;
}
}
canvas {
display: block;
width: 100% !important;
height: 100% !important;
}
Any suggestions on how to fix this?
EDIT:
I also attempted to adjust the js code without success:
JS:
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.getElementById('render').appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
render();
}
function onWindowResize() {
if (window.matchMedia('(min-width:768px)').matches) {
renderer.setSize(window.innerWidth, window.innerHeight * 0.33);
camera.updateProjectionMatrix();
camera.aspect = window.innerWidth / window.innerHeight;
render();
}
else {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
}