create-playcanvas 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/engine/ar-placement/index.html +20 -0
- package/templates/engine/ar-placement/src/main.ts +22 -12
- package/templates/engine/first-person-controller/index.html +19 -0
- package/templates/engine/first-person-controller/src/main.ts +16 -11
- package/templates/engine/product-configurator/index.html +30 -0
- package/templates/engine/product-configurator/src/main.ts +33 -32
- package/templates/engine/sprite-game/index.html +19 -0
- package/templates/engine/sprite-game/src/main.ts +19 -11
- package/templates/engine/third-person-controller/index.html +19 -0
- package/templates/engine/third-person-controller/src/main.ts +16 -11
- package/templates/engine/vr-starter/index.html +20 -0
- package/templates/engine/vr-starter/src/main.ts +22 -12
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>AR Placement</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>AR Placement</h1>
|
|
14
|
+
<p id="xr-status">Checking AR support…</p>
|
|
15
|
+
<div class="controls"><button id="xr-button" disabled>Start AR</button></div>
|
|
16
|
+
</section>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module" src="/src/main.ts"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -17,24 +17,36 @@ import {
|
|
|
17
17
|
import { ArPlacement } from './ar-placement';
|
|
18
18
|
import './starter.css';
|
|
19
19
|
|
|
20
|
-
document.body.insertAdjacentHTML(
|
|
21
|
-
'beforeend',
|
|
22
|
-
'<div class="hud"><section class="panel"><h1>AR Placement</h1><p id="xr-status">Checking AR support…</p><div class="controls"><button id="xr-button" disabled>Start AR</button></div></section></div>'
|
|
23
|
-
);
|
|
24
|
-
|
|
25
20
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
21
|
+
|
|
26
22
|
const device = await createGraphicsDevice(canvas);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
24
|
+
|
|
25
|
+
const createOptions = new AppOptions();
|
|
26
|
+
createOptions.graphicsDevice = device;
|
|
27
|
+
createOptions.componentSystems = [
|
|
28
|
+
RenderComponentSystem,
|
|
29
|
+
CameraComponentSystem,
|
|
30
|
+
LightComponentSystem,
|
|
31
|
+
ScriptComponentSystem
|
|
32
|
+
];
|
|
33
|
+
createOptions.xr = XrManager;
|
|
31
34
|
|
|
32
35
|
const app = new AppBase(canvas);
|
|
33
|
-
app.init(
|
|
36
|
+
app.init(createOptions);
|
|
34
37
|
app.start();
|
|
38
|
+
|
|
39
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
35
40
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
36
41
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
37
42
|
|
|
43
|
+
// Ensure canvas is resized when window changes size
|
|
44
|
+
const resize = () => app.resizeCanvas();
|
|
45
|
+
window.addEventListener('resize', resize);
|
|
46
|
+
app.on('destroy', () => {
|
|
47
|
+
window.removeEventListener('resize', resize);
|
|
48
|
+
});
|
|
49
|
+
|
|
38
50
|
const camera = new Entity('camera');
|
|
39
51
|
camera.addComponent('camera', { clearColor: new Color(0.05, 0.08, 0.12, 1) });
|
|
40
52
|
camera.setPosition(3, 2.4, 4);
|
|
@@ -73,5 +85,3 @@ const placement = new Entity('placement');
|
|
|
73
85
|
placement.addComponent('script');
|
|
74
86
|
placement.script!.create(ArPlacement, { properties: { camera, preview } });
|
|
75
87
|
app.root.addChild(placement);
|
|
76
|
-
|
|
77
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>First-Person Controller</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>First-Person Controller</h1>
|
|
14
|
+
<p>Click the scene, then use WASD, mouse look and Space to jump.</p>
|
|
15
|
+
</section>
|
|
16
|
+
</div>
|
|
17
|
+
<script type="module" src="/src/main.ts"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -28,16 +28,14 @@ await new Promise<void>((resolve) => {
|
|
|
28
28
|
WasmModule.getInstance('Ammo', () => resolve());
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
document.body.insertAdjacentHTML(
|
|
32
|
-
'beforeend',
|
|
33
|
-
'<div class="hud"><section class="panel"><h1>First-Person Controller</h1><p>Click the scene, then use WASD, mouse look and Space to jump.</p></section></div>'
|
|
34
|
-
);
|
|
35
|
-
|
|
36
31
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
32
|
+
|
|
37
33
|
const device = await createGraphicsDevice(canvas);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
35
|
+
|
|
36
|
+
const createOptions = new AppOptions();
|
|
37
|
+
createOptions.graphicsDevice = device;
|
|
38
|
+
createOptions.componentSystems = [
|
|
41
39
|
RenderComponentSystem,
|
|
42
40
|
CameraComponentSystem,
|
|
43
41
|
LightComponentSystem,
|
|
@@ -47,11 +45,20 @@ options.componentSystems = [
|
|
|
47
45
|
];
|
|
48
46
|
|
|
49
47
|
const app = new AppBase(canvas);
|
|
50
|
-
app.init(
|
|
48
|
+
app.init(createOptions);
|
|
51
49
|
app.start();
|
|
50
|
+
|
|
51
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
52
52
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
53
53
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
54
54
|
|
|
55
|
+
// Ensure canvas is resized when window changes size
|
|
56
|
+
const resize = () => app.resizeCanvas();
|
|
57
|
+
window.addEventListener('resize', resize);
|
|
58
|
+
app.on('destroy', () => {
|
|
59
|
+
window.removeEventListener('resize', resize);
|
|
60
|
+
});
|
|
61
|
+
|
|
55
62
|
const material = (color: Color) => {
|
|
56
63
|
const result = new StandardMaterial();
|
|
57
64
|
result.diffuse = color;
|
|
@@ -134,5 +141,3 @@ const fill = new Entity('fill');
|
|
|
134
141
|
fill.addComponent('light', { type: 'directional', intensity: 0.8 });
|
|
135
142
|
fill.setEulerAngles(-25, -140, 0);
|
|
136
143
|
app.root.addChild(fill);
|
|
137
|
-
|
|
138
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Product Configurator</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>Product Configurator</h1>
|
|
14
|
+
<p>Choose a paint finish, then drag to orbit.</p>
|
|
15
|
+
<div class="controls variants" id="paints">
|
|
16
|
+
<button aria-pressed="true" data-color="#d6293e" data-shade="#9b1731">
|
|
17
|
+
<span class="finish" style="--color: #d6293e"></span>Crimson
|
|
18
|
+
</button>
|
|
19
|
+
<button data-color="#d8e4e9" data-shade="#8fa8b5">
|
|
20
|
+
<span class="finish" style="--color: #d8e4e9"></span>Arctic
|
|
21
|
+
</button>
|
|
22
|
+
<button data-color="#9acb34" data-shade="#3c742d">
|
|
23
|
+
<span class="finish" style="--color: #9acb34"></span>Volt
|
|
24
|
+
</button>
|
|
25
|
+
</div>
|
|
26
|
+
</section>
|
|
27
|
+
</div>
|
|
28
|
+
<script type="module" src="/src/main.ts"></script>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -29,33 +29,38 @@ import './product.css';
|
|
|
29
29
|
import './starter.css';
|
|
30
30
|
|
|
31
31
|
const PRODUCT_URL = 'https://developer.playcanvas.com/assets/lambo.glb';
|
|
32
|
-
const PAINTS = [
|
|
33
|
-
{ name: 'Crimson', color: '#d6293e', shade: '#9b1731' },
|
|
34
|
-
{ name: 'Arctic', color: '#d8e4e9', shade: '#8fa8b5' },
|
|
35
|
-
{ name: 'Volt', color: '#9acb34', shade: '#3c742d' }
|
|
36
|
-
];
|
|
37
32
|
const CAMERA_FOCUS = new Vec3(0, 0.8, 0);
|
|
38
33
|
const CAMERA_PITCH = new Vec2(-85, -4);
|
|
39
34
|
|
|
40
|
-
document.body.insertAdjacentHTML(
|
|
41
|
-
'beforeend',
|
|
42
|
-
`<div class="hud"><section class="panel"><h1>Product Configurator</h1><p>Choose a paint finish, then drag to orbit.</p><div class="controls variants" id="paints">${PAINTS.map(({ name, color }, i) => `<button aria-pressed="${i === 0}" data-color="${color}"><span class="finish" style="--color:${color}"></span>${name}</button>`).join('')}</div></section></div>`
|
|
43
|
-
);
|
|
44
|
-
|
|
45
35
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
36
|
+
|
|
46
37
|
const device = await createGraphicsDevice(canvas);
|
|
47
|
-
device.maxPixelRatio = Math.min(
|
|
38
|
+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
48
39
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
const createOptions = new AppOptions();
|
|
41
|
+
createOptions.graphicsDevice = device;
|
|
42
|
+
createOptions.componentSystems = [
|
|
43
|
+
RenderComponentSystem,
|
|
44
|
+
CameraComponentSystem,
|
|
45
|
+
LightComponentSystem,
|
|
46
|
+
ScriptComponentSystem
|
|
47
|
+
];
|
|
48
|
+
createOptions.resourceHandlers = [TextureHandler, ContainerHandler];
|
|
53
49
|
|
|
54
50
|
const app = new AppBase(canvas);
|
|
55
|
-
app.init(
|
|
51
|
+
app.init(createOptions);
|
|
52
|
+
|
|
53
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
56
54
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
57
55
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
58
56
|
|
|
57
|
+
// Ensure canvas is resized when window changes size
|
|
58
|
+
const resize = () => app.resizeCanvas();
|
|
59
|
+
window.addEventListener('resize', resize);
|
|
60
|
+
app.on('destroy', () => {
|
|
61
|
+
window.removeEventListener('resize', resize);
|
|
62
|
+
});
|
|
63
|
+
|
|
59
64
|
const product = new Asset('car', 'container', { url: PRODUCT_URL });
|
|
60
65
|
await new Promise<void>((resolve) => new AssetListLoader([product], app.assets).load(() => resolve()));
|
|
61
66
|
|
|
@@ -82,10 +87,18 @@ const paint = body[0].material!.clone() as StandardMaterial;
|
|
|
82
87
|
const shade = panels[0].material!.clone() as StandardMaterial;
|
|
83
88
|
body.forEach((mesh) => (mesh.material = paint));
|
|
84
89
|
panels.forEach((mesh) => (mesh.material = shade));
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
|
|
91
|
+
// Each paint button in index.html carries its finish's two colors
|
|
92
|
+
const buttons = document.querySelectorAll<HTMLButtonElement>('#paints button');
|
|
93
|
+
const choose = (button: HTMLButtonElement) => {
|
|
94
|
+
paint.diffuse.fromString(button.dataset.color!);
|
|
95
|
+
shade.diffuse.fromString(button.dataset.shade!);
|
|
96
|
+
paint.update();
|
|
97
|
+
shade.update();
|
|
98
|
+
buttons.forEach((item) => (item.ariaPressed = String(item === button)));
|
|
99
|
+
};
|
|
100
|
+
buttons.forEach((button) => (button.onclick = () => choose(button)));
|
|
101
|
+
choose(buttons[0]);
|
|
89
102
|
|
|
90
103
|
const sky = new Entity('sky');
|
|
91
104
|
sky.addComponent('script');
|
|
@@ -141,15 +154,3 @@ light.addComponent('light', {
|
|
|
141
154
|
});
|
|
142
155
|
light.setEulerAngles(45, -145, 0);
|
|
143
156
|
app.root.addChild(light);
|
|
144
|
-
|
|
145
|
-
document.querySelectorAll<HTMLButtonElement>('#paints button').forEach((button, i, buttons) => {
|
|
146
|
-
button.onclick = () => {
|
|
147
|
-
paint.diffuse.fromString(PAINTS[i].color);
|
|
148
|
-
shade.diffuse.fromString(PAINTS[i].shade);
|
|
149
|
-
paint.update();
|
|
150
|
-
shade.update();
|
|
151
|
-
buttons.forEach((item, j) => (item.ariaPressed = String(i === j)));
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Sprite Game</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>Sprite Game</h1>
|
|
14
|
+
<p>Use A/D or the arrow keys to move and Space to jump.</p>
|
|
15
|
+
</section>
|
|
16
|
+
</div>
|
|
17
|
+
<script type="module" src="/src/main.ts"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -16,25 +16,35 @@ import {
|
|
|
16
16
|
import { SpriteGame } from './sprite-game';
|
|
17
17
|
import './starter.css';
|
|
18
18
|
|
|
19
|
-
document.body.insertAdjacentHTML(
|
|
20
|
-
'beforeend',
|
|
21
|
-
'<div class="hud"><section class="panel"><h1>Sprite Game</h1><p>Use A/D or the arrow keys to move and Space to jump.</p></section></div>'
|
|
22
|
-
);
|
|
23
|
-
|
|
24
19
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
20
|
+
|
|
25
21
|
const device = await createGraphicsDevice(canvas);
|
|
26
22
|
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
27
23
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const createOptions = new AppOptions();
|
|
25
|
+
createOptions.graphicsDevice = device;
|
|
26
|
+
createOptions.componentSystems = [
|
|
27
|
+
RenderComponentSystem,
|
|
28
|
+
CameraComponentSystem,
|
|
29
|
+
SpriteComponentSystem,
|
|
30
|
+
ScriptComponentSystem
|
|
31
|
+
];
|
|
31
32
|
|
|
32
33
|
const app = new AppBase(canvas);
|
|
33
|
-
app.init(
|
|
34
|
+
app.init(createOptions);
|
|
34
35
|
app.start();
|
|
36
|
+
|
|
37
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
35
38
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
36
39
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
37
40
|
|
|
41
|
+
// Ensure canvas is resized when window changes size
|
|
42
|
+
const resize = () => app.resizeCanvas();
|
|
43
|
+
window.addEventListener('resize', resize);
|
|
44
|
+
app.on('destroy', () => {
|
|
45
|
+
window.removeEventListener('resize', resize);
|
|
46
|
+
});
|
|
47
|
+
|
|
38
48
|
const camera = new Entity('camera');
|
|
39
49
|
camera.addComponent('camera', {
|
|
40
50
|
projection: 1,
|
|
@@ -68,5 +78,3 @@ game.setPosition(0, -2.15, 0);
|
|
|
68
78
|
game.addComponent('script');
|
|
69
79
|
game.script!.create(SpriteGame);
|
|
70
80
|
app.root.addChild(game);
|
|
71
|
-
|
|
72
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Third-Person Controller</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>Third-Person Controller</h1>
|
|
14
|
+
<p>Click the scene, then use WASD to move, mouse to orbit and Space to jump.</p>
|
|
15
|
+
</section>
|
|
16
|
+
</div>
|
|
17
|
+
<script type="module" src="/src/main.ts"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -49,16 +49,14 @@ await new Promise<void>((resolve) => {
|
|
|
49
49
|
WasmModule.getInstance('Ammo', () => resolve());
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
document.body.insertAdjacentHTML(
|
|
53
|
-
'beforeend',
|
|
54
|
-
'<div class="hud"><section class="panel"><h1>Third-Person Controller</h1><p>Click the scene, then use WASD to move, mouse to orbit and Space to jump.</p></section></div>'
|
|
55
|
-
);
|
|
56
|
-
|
|
57
52
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
53
|
+
|
|
58
54
|
const device = await createGraphicsDevice(canvas);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
56
|
+
|
|
57
|
+
const createOptions = new AppOptions();
|
|
58
|
+
createOptions.graphicsDevice = device;
|
|
59
|
+
createOptions.componentSystems = [
|
|
62
60
|
RenderComponentSystem,
|
|
63
61
|
CameraComponentSystem,
|
|
64
62
|
LightComponentSystem,
|
|
@@ -68,10 +66,19 @@ options.componentSystems = [
|
|
|
68
66
|
];
|
|
69
67
|
|
|
70
68
|
const app = new AppBase(canvas);
|
|
71
|
-
app.init(
|
|
69
|
+
app.init(createOptions);
|
|
72
70
|
app.start();
|
|
71
|
+
|
|
72
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
73
73
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
74
74
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
75
|
+
|
|
76
|
+
// Ensure canvas is resized when window changes size
|
|
77
|
+
const resize = () => app.resizeCanvas();
|
|
78
|
+
window.addEventListener('resize', resize);
|
|
79
|
+
app.on('destroy', () => {
|
|
80
|
+
window.removeEventListener('resize', resize);
|
|
81
|
+
});
|
|
75
82
|
app.scene.ambientLight = new Color(0.28, 0.32, 0.38);
|
|
76
83
|
|
|
77
84
|
const groundMaterial = new StandardMaterial();
|
|
@@ -216,5 +223,3 @@ light.addComponent('light', {
|
|
|
216
223
|
});
|
|
217
224
|
light.setEulerAngles(45, 30, 0);
|
|
218
225
|
app.root.addChild(light);
|
|
219
|
-
|
|
220
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/playcanvas.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>VR Starter</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="application-canvas"></canvas>
|
|
11
|
+
<div class="hud">
|
|
12
|
+
<section class="panel">
|
|
13
|
+
<h1>VR Starter</h1>
|
|
14
|
+
<p id="xr-status">Checking VR support…</p>
|
|
15
|
+
<div class="controls"><button id="xr-button" disabled>Enter VR</button></div>
|
|
16
|
+
</section>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module" src="/src/main.ts"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -17,23 +17,35 @@ import {
|
|
|
17
17
|
import './starter.css';
|
|
18
18
|
import { setupVr } from './vr';
|
|
19
19
|
|
|
20
|
-
document.body.insertAdjacentHTML(
|
|
21
|
-
'beforeend',
|
|
22
|
-
'<div class="hud"><section class="panel"><h1>VR Starter</h1><p id="xr-status">Checking VR support…</p><div class="controls"><button id="xr-button" disabled>Enter VR</button></div></section></div>'
|
|
23
|
-
);
|
|
24
|
-
|
|
25
20
|
const canvas = document.getElementById('application-canvas') as HTMLCanvasElement;
|
|
21
|
+
|
|
26
22
|
const device = await createGraphicsDevice(canvas);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
24
|
+
|
|
25
|
+
const createOptions = new AppOptions();
|
|
26
|
+
createOptions.graphicsDevice = device;
|
|
27
|
+
createOptions.componentSystems = [
|
|
28
|
+
RenderComponentSystem,
|
|
29
|
+
CameraComponentSystem,
|
|
30
|
+
LightComponentSystem,
|
|
31
|
+
ScriptComponentSystem
|
|
32
|
+
];
|
|
33
|
+
createOptions.xr = XrManager;
|
|
31
34
|
|
|
32
35
|
const app = new AppBase(canvas);
|
|
33
|
-
app.init(
|
|
36
|
+
app.init(createOptions);
|
|
34
37
|
app.start();
|
|
38
|
+
|
|
39
|
+
// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
|
|
35
40
|
app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
|
|
36
41
|
app.setCanvasResolution(RESOLUTION_AUTO);
|
|
42
|
+
|
|
43
|
+
// Ensure canvas is resized when window changes size
|
|
44
|
+
const resize = () => app.resizeCanvas();
|
|
45
|
+
window.addEventListener('resize', resize);
|
|
46
|
+
app.on('destroy', () => {
|
|
47
|
+
window.removeEventListener('resize', resize);
|
|
48
|
+
});
|
|
37
49
|
app.scene.ambientLight = new Color(0.32, 0.34, 0.38);
|
|
38
50
|
|
|
39
51
|
const material = (color: Color) => {
|
|
@@ -97,5 +109,3 @@ light.addComponent('light', {
|
|
|
97
109
|
});
|
|
98
110
|
light.setEulerAngles(45, 30, 0);
|
|
99
111
|
app.root.addChild(light);
|
|
100
|
-
|
|
101
|
-
window.addEventListener('resize', () => app.resizeCanvas());
|