This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtiltbrush-sample.html
144 lines (103 loc) · 3.31 KB
/
tiltbrush-sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<!--
Copyright 2017 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html {
height: 100%;
}
body {
height: 100%;
font-family: sans-serif;
line-height: 24px;
}
#viewer {
width: 100%;
height: calc(100% - 80px);
}
#info {
padding: 12px;
text-align: center;
}
#asset_name {
font-size: 22px;
font-weight: bold;
}
#asset_author {
color: #888;
}
</style>
</head>
<body>
<div id="viewer"></div>
<div id="info">
<span id="asset_name">Title</span><br/>
by <span id="asset_author">Author</span>
</div>
<script src="third_party/three.js/js/three.min.js"></script>
<script src="third_party/three.js/js/LegacyGLTFLoader.js"></script>
<script>
// THREE.JS VIEWER
const WIDTH = viewer.offsetWidth;
const HEIGHT = viewer.offsetHeight;
var camera = new THREE.PerspectiveCamera( 60, WIDTH / HEIGHT, 0.01, 100 );
camera.position.set( 5, 3, 5 );
camera.lookAt( 0, 1.5, 0 );
var scene = new THREE.Scene();
scene.background = new THREE.Color( 0x222222 );
scene.add( new THREE.GridHelper( 10, 10 ) );
var renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( WIDTH, HEIGHT );
viewer.appendChild( renderer.domElement );
function animate() {
var time = performance.now() / 5000;
camera.position.x = Math.sin( time ) * 5;
camera.position.z = Math.cos( time ) * 5;
camera.lookAt( 0, 1.5, 0 );
renderer.render( scene, camera );
requestAnimationFrame( animate );
}
requestAnimationFrame( animate );
// POLY REST API
const API_KEY = '*** INSERT YOUR API KEY HERE ***';
function loadAsset( id ) {
var url = `https://poly.googleapis.com/v1/assets/${id}/?key=${API_KEY}`;
var request = new XMLHttpRequest();
request.open( 'GET', url, true );
request.addEventListener( 'load', function ( event ) {
var asset = JSON.parse( event.target.response );
asset_name.textContent = asset.displayName;
asset_author.textContent = asset.authorName;
var format = asset.formats.find( format => { return format.formatType === 'GLTF'; } );
if ( format !== undefined ) {
var url = format.root.url;
var loader = new THREE.LegacyGLTFLoader();
loader.load( url, function ( response ) {
scene.add( response.scene );
} );
}
} );
request.send( null );
}
if ( API_KEY.startsWith( '**' ) ) {
alert( 'Sample incorrectly set up. Please enter your API Key for the Poly API in the API_KEY variable.' );
}
loadAsset( 'dBL4e9Ik5NA' );
</script>
</body>
</html>