How to overlay HTML text/buttons on three.js?

前端 未结 2 928
有刺的猬
有刺的猬 2021-02-14 19:00

Ok, very new to three.js here but I am trying to achieve what Google has with https://beinternetawesome.withgoogle.com/interland

See - they have their F

2条回答
  •  余生分开走
    2021-02-14 19:41

    Creativity is up to you, as there are many ways to achieve the desired result.

    You could've started from looking at the source code of examples from the official web site of Three.js. There you can see how the info section of an example sets on a web page.

    var buttons = document.getElementsByTagName("button");
    for (let i = 0; i < buttons.length; i++) {
      buttons[i].addEventListener("click", onButtonClick, false);
    };
    
    function onButtonClick(event) {
      alert(event.target.id);
    }
    
    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 controls = new THREE.OrbitControls(camera, renderer.domElement);
    
    var geometry = new THREE.BoxGeometry(1, 1, 1);
    var material = new THREE.MeshBasicMaterial({
      color: 0x00ff00,
      wireframe: true
    });
    var cube = new THREE.Mesh(geometry, material);
    scene.add(cube);
    
    camera.position.z = 5;
    
    var animate = function() {
      requestAnimationFrame(animate);
      renderer.render(scene, camera);
    };
    
    animate();
    body {
      overflow: hidden;
      margin: 0;
    }
    
    .ui {
      position: absolute;
    }
    
    button{
      margin: 20px;
    }
    
    
    
    
    Info header

提交回复
热议问题