Just starting with Hugo. Chose the tranquilpeak theme and am simply trying to place a webGL/Three.js canvas on a page, but it appears with a 2D offset:
I simply put three.js in static/js and put this in my second post’s markdown. Fairy straight forward and blunt; what’s causing the offset?
<div id="webGlDiv" style="
background-color: #FFF;
width: 600px;
height: 600px;
border: 1px solid black;"/>
<script src="/js/three.js"></script>
<script>
var camera, scene, renderer;
var mesh;
init();
animate();
function init() {
var bsjnk = 600;
camera = new THREE.PerspectiveCamera( 70, bsjnk / bsjnk, 1, 1000 );
camera.position.z = 400;
scene = new THREE.Scene();
var texture = new THREE.TextureLoader().load( '/images/tex.jpg' );
var geometry = new THREE.BoxBufferGeometry( 225, 225, 100 );
var material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
var webGlCanvas = document.getElementById( 'webGlDiv' );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( bsjnk, bsjnk );
webGlCanvas.appendChild( renderer.domElement );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.005;
mesh.rotation.y += 0.01;
renderer.render( scene, camera );
}
</script>