Commit ad56876e authored by Alfakhori's avatar Alfakhori
Browse files

Update public/webXR/three.html

parent 274ec007
Pipeline #7504 passed with stages
in 10 seconds
...@@ -14,50 +14,53 @@ ...@@ -14,50 +14,53 @@
<!-- Starting an immersive WebXR session requires user interaction. <!-- Starting an immersive WebXR session requires user interaction.
We start this one with a simple button. --> We start this one with a simple button. -->
<script> <script>
// create a Scene // ------------------------------------------------
const scene = new Scene(); // BASIC SETUP
// ------------------------------------------------
// Set the background color // Create an empty scene
scene.background = new Color('skyblue'); var scene = new THREE.Scene();
// Create a camera // Create a basic perspective camera
const fov = 35; // AKA Field of View var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
const aspect = container.clientWidth / container.clientHeight; camera.position.z = 4;
const near = 0.1; // the near clipping plane
const far = 100; // the far clipping plane
const camera = new PerspectiveCamera(fov, aspect, near, far); // Create a renderer with Antialiasing
var renderer = new THREE.WebGLRenderer({antialias:true});
// every object is initially created at ( 0, 0, 0 ) // Configure renderer clear color
// move the camera back so we can view the scene renderer.setClearColor("#000000");
camera.position.set(0, 0, 10);
// create a geometry // Configure renderer size
const geometry = new BoxBufferGeometry(2, 2, 2); renderer.setSize( window.innerWidth, window.innerHeight );
// create a default (white) Basic material // Append Renderer to DOM
const material = new MeshBasicMaterial(); document.body.appendChild( renderer.domElement );
// create a Mesh containing the geometry and material // ------------------------------------------------
const cube = new Mesh(geometry, material); // FUN STARTS HERE
// ------------------------------------------------
// add the mesh to the scene // Create a Cube Mesh with basic material
scene.add(cube); var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: "#433F81" } );
var cube = new THREE.Mesh( geometry, material );
// create the renderer // Add cube to Scene
const renderer = new WebGLRenderer(); scene.add( cube );
// next, set the renderer to the same size as our container element // Render Loop
renderer.setSize(container.clientWidth, container.clientHeight); var render = function () {
requestAnimationFrame( render );
// finally, set the pixel ratio so that our scene will look good on HiDPI displays cube.rotation.x += 0.01;
renderer.setPixelRatio(window.devicePixelRatio); cube.rotation.y += 0.01;
// add the automatically created <canvas> element to the page // Render the scene
container.append(renderer.domElement); renderer.render(scene, camera);
};
// render, or 'create a still image', of the scene render();
renderer.render(scene, camera);
</script> </script>
</body> </body>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment