Skip to content

Instantly share code, notes, and snippets.

@VingeB0
Created July 2, 2020 15:04
Show Gist options
  • Save VingeB0/578bc5e8bf5b040e13e3e4c4af149833 to your computer and use it in GitHub Desktop.
Save VingeB0/578bc5e8bf5b040e13e3e4c4af149833 to your computer and use it in GitHub Desktop.
import * as THREE from 'three';
import GLTFLoader from 'three/examples/js/loaders/GLTFLoader.js';
// import { DRACOLoader } from 'three';
import PhoneModel from './../public/assets/models/phone3d.glb';
var camera, scene, renderer;
var geometry, material, mesh;
init();
animate();
function init() {
const dracoLoader = new DRACOLoader();
// dracoLoader.setDecoderPath('http://localhost:8080/draco');
// loader.setDRACOLoader(dracoLoader);
//
const loader = new THREE.GLTFLoader();
loader.load(PhoneModel, function (gltf) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
scene = new THREE.Scene();
geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment