I’m just trying to implement a simple test scene in WordPress.
If I implement this in the header of my child theme, I can render the scene, but it is not animated. The timer doesn’t seem to be working. What can that be?
When I insert the test scene into my WPBakery Page Builder using raw js, the scene is rendered and the timer works too, but it is always rendered after the footer, regardless of whether I insert it before the content. Does anyone have any experience with this?
My test code looks like this:
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js"></script>
<script>
var camera, scene, renderer;
var geometry, material, mesh;
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.z = 3;
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
geometry = new THREE.SphereGeometry( 1 );
material = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate( time ) {
mesh.rotation.x = time * 0.0005;
mesh.rotation.y = time * 0.001;
renderer.render( scene, camera );
requestAnimationFrame( animate );
}
init();
requestAnimationFrame( animate );
</script>