---
title: [2023 ver.] Getting Started with WebXR using Babylon.js
tags: 
author: [Takashi Yoshinaga](https://www.docswell.com/user/Tks_Yoshinaga)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/LE1VL9YN7G.jpg?width=480
description: [2023 ver.] Getting Started with WebXR using Babylon.js by Takashi Yoshinaga
published: February 11, 23
canonical: https://www.docswell.com/s/Tks_Yoshinaga/ZJLGL4-webxr-en
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/LE1VL9YN7G.jpg)

Getting Started with WebXR using Babylon.js
for HoloLens 2 / Meta Quest


# Page. 2

![Page Image](https://bcdn.docswell.com/page/GEWLVQ1M72.jpg)

Download sample files
https://github.com/TakashiYoshinaga/AR-Fukuoka/
raw/main/Babylonjs_20230211/Sample.zip


# Page. 3

![Page Image](https://bcdn.docswell.com/page/47ZM4WPME3.jpg)

Todayʼs Goal
https://youtu.be/iok646xGtd0
Introduction to the basic usage of Babylon.js and the use of MRTK for interaction


# Page. 4

![Page Image](https://bcdn.docswell.com/page/YJ6N3GM5JV.jpg)

Duplicate Template Source Code
https://glitch.com/~babylon-template
GET STARTED


# Page. 5

![Page Image](https://bcdn.docswell.com/page/GJ55LVZGJ4.jpg)

Duplicate Template Source Code
Remix Your Own


# Page. 6

![Page Image](https://bcdn.docswell.com/page/LE3NLD9PE5.jpg)

Duplicate Template Source Code
Click on index.html and confirm that the code is displayed
index.html


# Page. 7

![Page Image](https://bcdn.docswell.com/page/8EDWNPG37G.jpg)

Duplicate Template Source Code
Click on index.html and confirm that the code is displayed
Editor
Preview


# Page. 8

![Page Image](https://bcdn.docswell.com/page/V7P95N3PJ8.jpg)

Tip: If Preview is Not Displayed
PREVIEW


# Page. 9

![Page Image](https://bcdn.docswell.com/page/2JVMPK4VJQ.jpg)

Tip: If Preview is Not Displayed
Open preview pane


# Page. 10

![Page Image](https://bcdn.docswell.com/page/5EGGPQ11EL.jpg)

Exercise Procedure
Web browser on PC
Creation of 3D space
HoloLens/Quest
XR Mode
Interaction by MRTK
Visualize Hands


# Page. 11

![Page Image](https://bcdn.docswell.com/page/4JQX2KDNEP.jpg)

Check the Template


# Page. 12

![Page Image](https://bcdn.docswell.com/page/K746LPZ3E1.jpg)

Check the Template
Loading Library
Description of
drawing and
interaction
(today&#039;s main focus)
Layout of drawing area


# Page. 13

![Page Image](https://bcdn.docswell.com/page/LJ1VL9RZEG.jpg)

Check the Template
Layout of drawing area


# Page. 14

![Page Image](https://bcdn.docswell.com/page/GJWLVQ16E2.jpg)

Explanation of HTML Description
&lt;!-- Area to be drawn --&gt;
&lt;canvas id=&quot;renderCanvas&quot; style=&quot;width: 100%; height: 100%;&quot;&gt;&lt;/canvas&gt;
ID is used when accessing from javascript
Paste the canvas in the window at the full size.


# Page. 15

![Page Image](https://bcdn.docswell.com/page/4EZM4WPRJ3.jpg)

Check the Template
Loading Library


# Page. 16

![Page Image](https://bcdn.docswell.com/page/Y76N3GM17V.jpg)

テンプレートの確認
Description of drawing
and interaction
(today&#039;s main focus)


# Page. 17

![Page Image](https://bcdn.docswell.com/page/G755LVZL74.jpg)

Exercise Procedure
Web browser on PC
Creation of 3D space
HoloLens/Quest
XR Mode
Interaction by MRTK
Visualize Hands


# Page. 18

![Page Image](https://bcdn.docswell.com/page/9J2NL3R3ER.jpg)

Declaration of Variables
Add variable here
//Initialization of variables after page loading is completed
window.onload = function() {
}
//Initialization of 3D scene
function createScene() {
}
//Initialization of WebXR settings
async function initializeXR(){
}
//Initialization of 3D objects to be drawn
function addObjects(){
}


# Page. 19

![Page Image](https://bcdn.docswell.com/page/DEYPQ1D8EM.jpg)

Declaration of Variables
let canvas; //canvas element (drawing area) ← &quot;where&quot; to draw
let engine; //Drawing functionality with Babylon.js ← &quot;What&quot; to draw with
let scene; //Virtual 3D space ← &quot;What&quot; to draw
//Initialization of variables after page loading is completed
window.onload = function() {
}
//Initialization of 3D scene
function createScene() {
}
//Initialization of WebXR settings
async function initializeXR(){
}
Lesson02


# Page. 20

![Page Image](https://bcdn.docswell.com/page/VJN5K26978.jpg)

Initialization of Drawing Functions of Babylon.js
let canvas; //canvas element (drawing area) ← &quot;where&quot; to draw
let engine; //Drawing functionality with Babylon.js ← &quot;What&quot; to draw with
let scene; //Virtual 3D space ← &quot;What&quot; to draw
//Initialization of variables after page loading is completed
window.onload = function() {
//Obtain the drawing area (canvas element) from HTML
canvas = document.getElementById(&quot;renderCanvas&quot;);
//Preparation for drawing with Babylon.js (Arguments: destination, anti-aliasing)
engine = new BABYLON.Engine(canvas, true);
//カメラやライトの設定を⾏ったscene(3D空間)を取得
scene= createScene();
}
//Initialization of 3D scene
function createScene() {
}
Lesson03


# Page. 21

![Page Image](https://bcdn.docswell.com/page/YE9YV1L3J3.jpg)

Initialization of Scene (3D Space)
let canvas; //canvas element (drawing area) ← &quot;where&quot; to draw
let engine; //Drawing functionality with Babylon.js ← &quot;What&quot; to draw with
let scene; //Virtual 3D space ← &quot;What&quot; to draw
//Initialization of variables after page loading is completed
window.onload = function() {
//Obtain the drawing area (canvas element) from HTML
canvas = document.getElementById(&quot;renderCanvas&quot;);
//Preparation for drawing with Babylon.js (Arguments: destination, anti-aliasing)
engine = new BABYLON.Engine(canvas, true);
//Create a scene (3D space) with camera and light settings
createScene();
}
// Initialization of 3D scene
function createScene() {
}
Description of the initialization process of a scene (next page)
Lesson04


# Page. 22

![Page Image](https://bcdn.docswell.com/page/GE86P4XL7D.jpg)

Initialization of Scene (3D Space)
function createScene() {
//Create 3D space
scene = new BABYLON.Scene(engine);
//Set background color
scene.clearColor = new BABYLON.Color3.Black();
//Set Light (arguments: name, direction of reflection, destination)
let light = new BABYLON.HemisphericLight(&quot;light&quot;,
new BABYLON.Vector3(1, 1, -0.5) ,scene);
//Create a camera[Details]
let camera = new BABYLON.ArcRotateCamera(
&quot;camera&quot;,
//name of camea
-Math.PI/2, Math.PI/2, 3, //alpha,beta,distance form origin
new BABYLON.Vector3(0, 0, 0)); //look at
// Enables camera operation with mouse or keyboard
camera.attachControl(canvas, true);
}
Lesson05


# Page. 23

![Page Image](https://bcdn.docswell.com/page/LEL9168QJR.jpg)

Start Drawing
//Initialization of variables after page loading is completed
window.onload = function() {
//Obtain the drawing area (canvas element) from HTML
canvas = document.getElementById(&quot;renderCanvas&quot;);
//Preparation for drawing with Babylon.js (Arguments: destination, anti-aliasing)
engine = new BABYLON.Engine(canvas, true);
//Create a scene (3D space) with camera and light settings
createScene();
//Update drawing every frame
engine.runRenderLoop(function () {
if (scene &amp;&amp; scene.activeCamera) {
scene.render(); //Drawing!
}
});
}
Lesson06


# Page. 24

![Page Image](https://bcdn.docswell.com/page/4JMZW5XKEW.jpg)

Operation Check
Preview background becomes
the specified color (=black)


# Page. 25

![Page Image](https://bcdn.docswell.com/page/PJR6Y3N679.jpg)

Adding a Display Object
// Initialization of variables after page loading is completedう
window.onload = function() {
//Obtain the drawing area (canvas element) from HTML
canvas = document.getElementById(&quot;renderCanvas&quot;);
//Preparation for drawing with Babylon.js (Arguments: destination, anti-aliasing)
engine = new BABYLON.Engine(canvas, true);
//Create a scene (3D space) with camera and light settings
createScene();
//Creating Drawing Objects
addObjects();
//Update drawing every frame
engine.runRenderLoop(function () {
if (scene &amp;&amp; scene.activeCamera) {
scene.render();
}
});
Lesson07
}


# Page. 26

![Page Image](https://bcdn.docswell.com/page/PEXMG4ND7X.jpg)

Adding a Display Object
Edit here next


# Page. 27

![Page Image](https://bcdn.docswell.com/page/3EKG4ZNDJD.jpg)

Adding a Display Object
function addObjects(){
}
// Create ground (for visual checking the location of the origin.)
let ground = BABYLON.MeshBuilder.CreateGround(
&quot;ground&quot;, {width: 1, height: 1});
//箱状のオブジェクト作成 (30cm)
let box = BABYLON.MeshBuilder.CreateBox(
&quot;box&quot;, {width: 0.3, height: 0.3, depth: 0.3});
box.position.x = 0.0;
box.position.y = 1; //地⾯(ground)から1mの⾼さ
//マテリアルを作成
let boxMaterial = new BABYLON.StandardMaterial(&quot;material&quot;);
//箱の⾊を設定 (今回はランダムに変化)、そのあとboxに適⽤
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;
//8⾯体を作成
let octa = BABYLON.MeshBuilder.CreatePolyhedron(&quot;octa&quot;, {type:1,size: 0.15});
octa.position.x=0.5;
octa.position.y=1;
Lesson08


# Page. 28

![Page Image](https://bcdn.docswell.com/page/L73NLDVP75.jpg)

Operation Check
The board that corresponds to the ground can be observed by
changing the viewpoint with the mouse operation.
Initial Viewpoint
Left-click and drag
to rotate
Scroll back and
forward
Right-click and drag
to move
vertical/horizontal


# Page. 29

![Page Image](https://bcdn.docswell.com/page/87DWNP83JG.jpg)

Adding a Display Object
function addObjects(){
}
// Create ground (for visual checking the location of the origin.)
let ground = BABYLON.MeshBuilder.CreateGround(
&quot;ground&quot;, {width: 1, height: 1});
// Creation of Box object (30cm)
let box = BABYLON.MeshBuilder.CreateBox(
&quot;box&quot;, {width: 0.3, height: 0.3, depth: 0.3});
box.position.x = 0.0;
box.position.y = 1; // 1m above the ground
// Create Material
let boxMaterial = new BABYLON.StandardMaterial(&quot;material&quot;);
// Set the color of the box (in this case randomly changing) and apply it to the box
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;
//8⾯体を作成
let octa = BABYLON.MeshBuilder.CreatePolyhedron(&quot;octa&quot;, {type:1,size: 0.15});
octa.position.x=0.5;
octa.position.y=1;
Lesson09


# Page. 30

![Page Image](https://bcdn.docswell.com/page/VJP95N8PE8.jpg)

Operation Check
Box is shown


# Page. 31

![Page Image](https://bcdn.docswell.com/page/2EVMPKNVEQ.jpg)

Adding a Display Object
function addObjects(){
}
//地⾯を作成 (原点の位置確認⽤。後で削除してOK)
let ground = BABYLON.MeshBuilder.CreateGround(
&quot;ground&quot;, {width: 1, height: 1});
//箱状のオブジェクト作成 (30cm)
let box = BABYLON.MeshBuilder.CreateBox(
&quot;box&quot;, {width: 0.3, height: 0.3, depth: 0.3});
box.position.x = 0.0;
box.position.y = 1; //地⾯(ground)から1mの⾼さ
//マテリアルを作成
let boxMaterial = new BABYLON.StandardMaterial(&quot;material&quot;);
//箱の⾊を設定 (今回はランダムに変化)、そのあとboxに適⽤
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;
//8⾯体を作成 [詳細]
let octa = BABYLON.MeshBuilder.CreatePolyhedron(&quot;octa&quot;, {type:1,size: 0.15});
octa.position.x=0.5;
octa.position.y=1;
Lesson10


# Page. 32

![Page Image](https://bcdn.docswell.com/page/57GGPQK17L.jpg)

Operation Check
Box and octahedron is shown


# Page. 33

![Page Image](https://bcdn.docswell.com/page/4EQX2KNN7P.jpg)

Exercise Procedure
Web browser on PC
Creation of 3D space
HoloLens/Quest
XR Mode
Interaction by MRTK
Visualize Hands


# Page. 34

![Page Image](https://bcdn.docswell.com/page/KJ46LPG371.jpg)

Experience the Content on Quest or HoloLens2
window.onload = function() {
/* Omitted */
//Creating Drawing Objects
addObjects();
//Initialization of WebXR settings
initializeXR();
}
//Update drawing every frame
engine.runRenderLoop(function () {
if (scene &amp;&amp; scene.activeCamera) {
scene.render();
}
});
//Initialization of WebXR settings
async function initializeXR(){
let xr = await scene.createDefaultXRExperienceAsync({ /*options*/ });
}
Lesson11


# Page. 35

![Page Image](https://bcdn.docswell.com/page/LE1VL9DZ7G.jpg)

Change the URL Before Testing on a Device
Click Settings


# Page. 36

![Page Image](https://bcdn.docswell.com/page/GEWLVQY672.jpg)

Change the URL Before Testing on a Device
Edit project details
Change the name to something
easy to remember
Save


# Page. 37

![Page Image](https://bcdn.docswell.com/page/47ZM4WXRE3.jpg)

Check URL of Your XR Content
Click
Copy Link


# Page. 38

![Page Image](https://bcdn.docswell.com/page/YJ6N3G41JV.jpg)

Check URL of Your XR Content
Check the URL by pasting it into a text editor, etc.
https://your-content.glitch.me/


# Page. 39

![Page Image](https://bcdn.docswell.com/page/GJ55LVQLJ4.jpg)

Operation Check
HoloLens2
Input the URL
Goggle Button
Quest
Input the URL
Goggle Button


# Page. 40

![Page Image](https://bcdn.docswell.com/page/9E2NL3P37R.jpg)

Operation Check


# Page. 41

![Page Image](https://bcdn.docswell.com/page/D7YPQ1587M.jpg)

How to Exit
HoloLens2
Home Button
Quest
Close Button
Exit content via Home window shown by wrist tap (HoloLens2) or Oculus button (Quest)


# Page. 42

![Page Image](https://bcdn.docswell.com/page/VEN5K2N9J8.jpg)

Exercise Procedure
Web browser on PC
Creation of 3D space
HoloLens/Quest
XR Mode
Interaction by MRTK
Visualize Hands


# Page. 43

![Page Image](https://bcdn.docswell.com/page/Y79YV1R3E3.jpg)

Object Manipulation
function addObjects(){
/*Omitted*/
// Set box color randomly
let boxMaterial = new BABYLON.StandardMaterial(&quot;material&quot;);
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;
//Create an octahedron
let octa = BABYLON.MeshBuilder.CreatePolyhedron(&quot;octa&quot;, {type:1,size: 0.15});
octa.position.x=0.5;
octa.position.y=1;
//Add manipulatable attribute to the box object
let dragBehavior = new BABYLON.SixDofDragBehavior();
dragBehavior.allowMultiPointer = false;
dragBehavior.rotateWithMotionController = false;
box.addBehavior(dragBehavior);
}
Lesson12


# Page. 44

![Page Image](https://bcdn.docswell.com/page/G786P4WLJD.jpg)

Operaton Check on PC
Only objects to which DragBehavior
is applied can be manipulated


# Page. 45

![Page Image](https://bcdn.docswell.com/page/L7L916NQER.jpg)

Operation Check on HMD
Reload
Reload
Please click the Reload button everytime before testing


# Page. 46

![Page Image](https://bcdn.docswell.com/page/4EMZW5QK7W.jpg)

Operation Check on HMD
Quest users currently have hand tracking displaying hands incorrectly (to be fixed later)


# Page. 47

![Page Image](https://bcdn.docswell.com/page/PER6Y386J9.jpg)

Exercise Procedure
Web browser on PC
Creation of 3D space
HoloLens/Quest
XR Mode
Interaction by MRTK
Visualize Hands


# Page. 48

![Page Image](https://bcdn.docswell.com/page/P7XMG48DJX.jpg)

Turn On Hand Visualization (For Quest)
//Initialization of WebXR settings
async function initializeXR() {
let xr = await scene.createDefaultXRExperienceAsync({});
// Check if XR mode available or not
if (!xr.baseExperience) { }
else {
//Turn on hand tracking if XR mode available
xr.baseExperience.featuresManager.enableFeature(
BABYLON.WebXRFeatureName.HAND_TRACKING,
&quot;latest&quot;,
{xrInput: xr.input}
);
}
}
Lesson13


# Page. 49

![Page Image](https://bcdn.docswell.com/page/37KG4ZKDED.jpg)

Operation Check on XR Device


# Page. 50

![Page Image](https://bcdn.docswell.com/page/LJ3NLDZPJ5.jpg)

That&#039;s it for the basic steps!


# Page. 51

![Page Image](https://bcdn.docswell.com/page/8JDWNPR3EG.jpg)

Extra Tutorial


# Page. 52

![Page Image](https://bcdn.docswell.com/page/VEP95NWP78.jpg)

Using 3D Models (GLB, OBJ, etc.)


# Page. 53

![Page Image](https://bcdn.docswell.com/page/27VMPK8V7Q.jpg)

Loading a 3D Model File
Loading Libraries
Enables the object loading
functionality provided by Babylon.js


# Page. 54

![Page Image](https://bcdn.docswell.com/page/5JGGPQ51JL.jpg)

Loading a 3D Model File
&lt;!– Loading babylon.js--&gt;
&lt;script src=&quot;https://cdn.babylonjs.com/babylon.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js&quot;&gt;&lt;/script&gt;
&lt;!-- Actual process implementation --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
let canvas; //canvas element (drawing area) ← &quot;where&quot; to draw
let engine; //Drawing functionality with Babylon.js ← &quot;What&quot; to draw with
let scene; //Virtual 3D space ← &quot;What&quot; to draw
// Initialization of variables after page loading is completed
window.onload = function () {
//Obtain the drawing area (canvas element) from HTML
canvas = document.getElementById(&quot;renderCanvas&quot;);
//Preparation for drawing with Babylon.js (Arguments: destination, anti-aliasing)
engine = new BABYLON.Engine(canvas, true);
/*Omitted below */
Lesson14


# Page. 55

![Page Image](https://bcdn.docswell.com/page/47QX2KZNJP.jpg)

Upload 3D Model to Glitch
Assets


# Page. 56

![Page Image](https://bcdn.docswell.com/page/KE46LP33J1.jpg)

Upload 3D Model to Glitch
Drag and drop in the browser
figure.glb


# Page. 57

![Page Image](https://bcdn.docswell.com/page/L71VL91ZJG.jpg)

Upload 3D Model to Glitch
Back to index.html


# Page. 58

![Page Image](https://bcdn.docswell.com/page/G7WLVQ86J2.jpg)

Loading a 3D Model File
function addObjects(){
/* Omitted due to space limitation. */
let boxMaterial = new BABYLON.StandardMaterial(&quot;material&quot;);
boxMaterial.diffuseColor = BABYLON.Color3.Random();
box.material = boxMaterial;
// Create octahedron
let octa = BABYLON.MeshBuilder.CreatePolyhedron(&quot;octa&quot;, {type:1,size: 0.15});
octa.position.x=0.5;
octa.position.y=1;
// Added a hand-grabable attribute to the box.
let dragBehavior = new BABYLON.SixDofDragBehavior();
dragBehavior.allowMultiPointer=false;
dragBehavior.rotateWithMotionController=false;
box.addBehavior(dragBehavior);
}
Add code to load object (next page)


# Page. 59

![Page Image](https://bcdn.docswell.com/page/4JZM4W8R73.jpg)

Loading a 3D Model File
function addObjects(){
/* Omitted due to space limitation */
dragBehavior.rotateWithMotionController=false;
box.addBehavior(dragBehavior);
// Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer(
&quot;URL of 3D Model &quot;, // Folder where the 3D model is placed OR URL of the 3D model
&quot;&quot;, //File name of the 3D model. Empty is OK if you specified the URL of the model above.
scene, // Scene to which the object is added
function (container) {
//For Babylon.js, the 0th mesh is just the root; the 1st is the model entity.[Detail]
let glbMesh = container.meshes[1];
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
}
Lesson15


# Page. 60

![Page Image](https://bcdn.docswell.com/page/YE6N3GP1EV.jpg)

Getting the URL of 3D Model
function addObjects(){
/* Omitted due to space limitation */
dragBehavior.rotateWithMotionController=false;
box.addBehavior(dragBehavior);
// Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer(
&quot;URL of 3D Model &quot;, // Folder where the 3D model is placed OR URL of the 3D model
&quot;&quot;, //File name of the 3D model. Empty is OK if you specified the URL of the model above.
scene, // Scene to which the object is added
function (container) {
//For Babylon.js, the 0th mesh is just the root; the 1st is the model entity.[Detail]
let glbMesh = container.meshes[1];
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
}


# Page. 61

![Page Image](https://bcdn.docswell.com/page/GE55LVKLE4.jpg)

Getting the URL of 3D Model
Assets


# Page. 62

![Page Image](https://bcdn.docswell.com/page/972NL3W3JR.jpg)

Getting the URL of 3D Model
Click figure.glb


# Page. 63

![Page Image](https://bcdn.docswell.com/page/DJYPQ1L8JM.jpg)

Getting the URL of 3D Model
Copy URL


# Page. 64

![Page Image](https://bcdn.docswell.com/page/V7N5K249E8.jpg)

Getting the URL of 3D Model
Close


# Page. 65

![Page Image](https://bcdn.docswell.com/page/YJ9YV1Q373.jpg)

Getting the URL of 3D Model
Back to index.html


# Page. 66

![Page Image](https://bcdn.docswell.com/page/GJ86P4GLED.jpg)

Loading a 3D Model File
function addObjects(){
/* Omitted due to space limitation */
dragBehavior.rotateWithMotionController=false;
box.addBehavior(dragBehavior);
// Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer(
&quot;URL of 3D Model &quot;, // Folder where the 3D model is placed OR URL of the 3D model
&quot;&quot;, //File name of the 3D model. Empty is OK if you specified the URL of the model above.
Paste URL between &quot; and &quot;.
scene, // Scene to which the object is added
function (container) {
//For Babylon.js, the 0th mesh is just the root; the 1st is the model entity.[Detail]
let glbMesh = container.meshes[1];
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
}


# Page. 67

![Page Image](https://bcdn.docswell.com/page/LJL916GQ7R.jpg)

Operation Checl
Too Small


# Page. 68

![Page Image](https://bcdn.docswell.com/page/47MZW5LKJW.jpg)

Modification
//Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer(
&quot;URL of 3D Model&quot;, // Folder where the 3D model is placed OR URL of the 3D model
&quot;&quot;, //File name of the 3D model. Empty is OK if you specified the URL of the model above.
scene, //Scene to which the object is added
function (container) {
// For Babylon.js, the 0th mesh is just the root; the 1st is the model entity
let glbMesh = container.meshes[1];
//Scale x10
glbMesh.scaling=new BABYLON.Vector3(10,10,10);
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
Lesson16


# Page. 69

![Page Image](https://bcdn.docswell.com/page/P7R6Y3K6E9.jpg)

Modification
//Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer(
&quot;URL of 3D Model &quot;, // Folder where the 3D model is placed OR URL of the 3D model
&quot;&quot;, //File name of the 3D model. Empty is OK if you specified the URL of the model above.
scene, //Scene to which the object is added
function (container) {
// For Babylon.js, the 0th mesh is just the root; the 1st is the model entity
let glbMesh = container.meshes[1];
//Scale x10
glbMesh.scaling=new BABYLON.Vector3(10,10,10);
// Rotate 180 degrees (=π radians) around Y-axis (=vertical axis)
glbMesh.rotation =new BABYLON.Vector3(0, Math.PI, 0);
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
Lesson17


# Page. 70

![Page Image](https://bcdn.docswell.com/page/PJXMG4LDEX.jpg)

Make 3D Model Manipulatable
// Load 3D models using SceneLoader
BABYLON.SceneLoader.LoadAssetContainer( &quot;URL of 3D Model&quot;, &quot;&quot;, scene,
function (container) {
//For Babylon.js, the 0th mesh is just the root; the 1st is the model entity
let glbMesh = container.meshes[1];
// Scale x10
glbMesh.scaling=new BABYLON.Vector3(10,10,10);
//Rotate 180 degrees (=π radians) around Y-axis (=vertical axis)
glbMesh.rotation =new BABYLON.Vector3(0, Math.PI, 0);
// Create manipulation behavior for loaded objects
let dragBehavior2 = new BABYLON.SixDofDragBehavior();
dragBehavior2.allowMultiPointer=false;
dragBehavior2.rotateWithMotionController=false;
glbMesh.addBehavior(dragBehavior2);
//Add object to scene (3D space)
scene.addMesh(glbMesh);
}
);
Lesson18


# Page. 71

![Page Image](https://bcdn.docswell.com/page/3JKG4ZLD7D.jpg)

Operation Check


# Page. 72

![Page Image](https://bcdn.docswell.com/page/LE3NLD3PE5.jpg)

参考
Camera
https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
WebXR Experience Helper
https://doc.babylonjs.com/divingDeeper/webXR/webXRExperienceHelpers#webxr-defaultexperience-helper
MRTK
https://doc.babylonjs.com/divingDeeper/gui/mrtk
SixDofDragBehaviour
https://doc.babylonjs.com/typedoc/classes/BABYLON.SixDofDragBehavior
Hand Tracking
https://doc.babylonjs.com/divingDeeper/webXR/WebXRSelectedFeatures#hand-tracking
SceneLoader
https://doc.babylonjs.com/typedoc/classes/BABYLON.SceneLoader
AR mode (Quest pass-through supported)
https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRARFeatures#features


# Page. 73

![Page Image](https://bcdn.docswell.com/page/8EDWNP437G.jpg)

Source code is available on GitHub
https://github.com/TakashiYoshinaga/babylonjs-webxr


