Skip to content

Commit 976cafb

Browse files
committed
game
1 parent 6ada913 commit 976cafb

File tree

14 files changed

+514
-9
lines changed

14 files changed

+514
-9
lines changed

assets/bird-1.wav

351 KB
Binary file not shown.

assets/bird-2.wav

272 KB
Binary file not shown.

assets/bird-3.wav

689 KB
Binary file not shown.

assets/bird-4.wav

430 KB
Binary file not shown.

assets/bird-5.wav

3.42 MB
Binary file not shown.

assets/bird-6.wav

313 KB
Binary file not shown.

examples/basic-poly.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// THREE.JS VIEWER
2+
// import * as THREE from 'three';
3+
import {config} from "../config";
4+
5+
6+
const WIDTH = viewer.offsetWidth;
7+
const HEIGHT = viewer.offsetHeight;
8+
9+
const camera = new THREE.PerspectiveCamera( 60, WIDTH / HEIGHT, 0.01, 100 );
10+
camera.position.set( 5, 3, 5 );
11+
camera.lookAt( 0, 1.5, 0 );
12+
13+
const scene = new THREE.Scene();
14+
scene.background = new THREE.Color( 0x222222 );
15+
16+
scene.add( new THREE.GridHelper( 10, 10 ) );
17+
18+
const ambient = new THREE.HemisphereLight( 0xbbbbff, 0x886666, 0.75 );
19+
ambient.position.set( -0.5, 0.75, -1 );
20+
scene.add( ambient );
21+
22+
const light = new THREE.DirectionalLight( 0xffffff, 0.75 );
23+
light.position.set( 1, 0.75, 0.5 );
24+
scene.add( light );
25+
26+
const renderer = new THREE.WebGLRenderer();
27+
renderer.setPixelRatio( window.devicePixelRatio );
28+
renderer.setSize( WIDTH, HEIGHT );
29+
viewer.appendChild( renderer.domElement );
30+
31+
function animate() {
32+
33+
const time = performance.now() / 5000;
34+
35+
camera.position.x = Math.sin( time ) * 5;
36+
camera.position.z = Math.cos( time ) * 5;
37+
camera.lookAt( 0, 1.5, 0 );
38+
39+
renderer.render( scene, camera );
40+
requestAnimationFrame( animate );
41+
42+
}
43+
44+
requestAnimationFrame( animate );
45+
46+
// POLY REST API
47+
48+
const API_KEY = config.apiKey;
49+
50+
function loadAsset( id ) {
51+
52+
var url = `https://poly.googleapis.com/v1/assets/${id}/?key=${API_KEY}`;
53+
54+
var request = new XMLHttpRequest();
55+
request.open( 'GET', url, true );
56+
request.addEventListener( 'load', function ( event ) {
57+
58+
var asset = JSON.parse( event.target.response );
59+
60+
asset_name.textContent = asset.displayName;
61+
asset_author.textContent = asset.authorName;
62+
63+
var format = asset.formats.find( format => { return format.formatType === 'OBJ'; } );
64+
65+
if ( format !== undefined ) {
66+
67+
var obj = format.root;
68+
var mtl = format.resources.find( resource => { return resource.url.endsWith( 'mtl' ) } );
69+
70+
var path = obj.url.slice( 0, obj.url.indexOf( obj.relativePath ) );
71+
72+
var loader = new THREE.MTLLoader();
73+
loader.setCrossOrigin( true );
74+
loader.setMaterialOptions( { ignoreZeroRGBs: true } );
75+
loader.setTexturePath( path );
76+
loader.load( mtl.url, function ( materials ) {
77+
78+
var loader = new THREE.OBJLoader();
79+
loader.setMaterials( materials );
80+
loader.load( obj.url, function ( object ) {
81+
82+
var box = new THREE.Box3();
83+
box.setFromObject( object );
84+
85+
// re-center
86+
87+
var center = box.getCenter();
88+
center.y = box.min.y;
89+
object.position.sub( center );
90+
91+
// scale
92+
93+
var scaler = new THREE.Group();
94+
scaler.add( object );
95+
scaler.scale.setScalar( 6 / box.getSize().length() );
96+
scene.add( scaler );
97+
98+
} );
99+
100+
} );
101+
102+
}
103+
104+
} );
105+
request.send( null );
106+
107+
}
108+
109+
if ( API_KEY.startsWith( '**' ) ) {
110+
111+
alert( 'Sample incorrectly set up. Please enter your API Key for the Poly API in the API_KEY variable.' );
112+
113+
}
114+
115+
loadAsset( '5vbJ5vildOq' );

examples/basic-sample.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@
5555
<span id="asset_name">Title</span><br/>
5656
by <span id="asset_author">Author</span>
5757
</div>
58-
58+
<script src="../config.js"></script>
5959
<script src="../third_party/three.js/js/three.min.js"></script>
6060
<script src="../third_party/three.js/js/loaders/OBJLoader.js"></script>
6161
<script src="../third_party/three.js/js/loaders/MTLLoader.js"></script>
6262
<script>
63-
import config from '../config.js';
6463

6564
// THREE.JS VIEWER
66-
6765
const WIDTH = viewer.offsetWidth;
6866
const HEIGHT = viewer.offsetHeight;
6967

0 commit comments

Comments
 (0)