How-to-create-VR-content.html 2.3 KB
Newer Older
M
Mugen87 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<base href="../../../" />
	<script src="list.js"></script>
	<script src="page.js"></script>
	<link type="text/css" rel="stylesheet" href="page.css" />
</head>

<body>
	<h1>[name]</h1>

	<p>
		This guide provides a brief overview of the basic components of a web-based VR application
		made with three.js.
	</p>

	<h2>Workflow</h2>

	<p>
M
Mugen87 已提交
23
		First, you have to include [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/VRButton.js VRButton.js]
24 25 26 27
		into your project.
	</p>

	<code>
M
Mugen87 已提交
28
import { VRButton } from 'three/examples/jsm/webxr/VRButton.js';
29 30 31
	</code>

	<p>
M
Mugen87 已提交
32
		*VRButton.createButton()* does two important things: It creates a button which indicates
33
		VR compatibility. Besides, it initiates a VR session if the user activates the button. The only thing you have
M
Mugen87 已提交
34 35 36 37
		to do is to add the following line of code to your app.
	</p>

	<code>
M
Mugen87 已提交
38
document.body.appendChild( VRButton.createButton( renderer ) );
M
Mugen87 已提交
39 40 41
	</code>

	<p>
42
		Next, you have to tell your instance of *WebGLRenderer* to enable VR rendering.
M
Mugen87 已提交
43 44 45 46 47 48 49 50
	</p>

	<code>
renderer.vr.enabled = true;
	</code>

	<p>
		Finally, you have to adjust your animation loop since we can't use our well known
M
Mugen87 已提交
51
		*window.requestAnimationFrame()* function. For VR projects we use [page:WebGLRenderer.setAnimationLoop setAnimationLoop].
52
		The minimal code looks like this:
M
Mugen87 已提交
53 54 55
	</p>

	<code>
56
renderer.setAnimationLoop( function () {
M
Mugen87 已提交
57

58
	renderer.render( scene, camera );
M
Mugen87 已提交
59

60
} );
M
Mugen87 已提交
61 62 63 64 65 66 67
	</code>

	<h2>Next Steps</h2>

	<p>
		Have a look at one of the official WebVR examples to see this workflow in action.<br /><br />

M
Mugen87 已提交
68 69 70 71 72 73 74 75 76 77 78 79
		[example:webxr_vr_ballshooter WebXR / VR / ballshoter]<br />
		[example:webxr_vr_cubes WebXR / VR / cubes]<br />
		[example:webxr_vr_dragging WebXR / VR / dragging]<br />
		[example:webxr_vr_lorenzattractor WebXR / VR / lorenzattractor]<br />
		[example:webxr_vr_multiview WebXR / VR / multiview]<br />
		[example:webxr_vr_paint WebXR / VR / paint]<br />
		[example:webxr_vr_panorama_depth WebXR / VR / panorama_depth]<br />
		[example:webxr_vr_panorama WebXR / VR / panorama]<br />
		[example:webxr_vr_rollercoaster WebXR / VR / rollercoaster]<br />
		[example:webxr_vr_sandbox WebXR / VR / sandbox]<br />
		[example:webxr_vr_sculpt WebXR / VR / sculpt]<br />
		[example:webxr_vr_video WebXR / VR / video]
M
Mugen87 已提交
80 81 82 83 84
	</p>

</body>

</html>