Skip to content

Instantly share code, notes, and snippets.

@sdras
Created September 16, 2019 23:00
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sdras/4d33b9328ca2d544ad429b27e4c2bf59 to your computer and use it in GitHub Desktop.
Save sdras/4d33b9328ca2d544ad429b27e4c2bf59 to your computer and use it in GitHub Desktop.
// Remember to bring in three.js and here is the script for the trackball controls as well:
// https://cdn.rawgit.com/mrdoob/three.js/dev/examples/js/controls/TrackballControls.js
//RENDERER
const renderer = new THREE.WebGLRenderer({
canvas: document.getElementById('canvas'),
antialias: true
});
renderer.setClearColor(0x25c8ce);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
//CAMERA
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
3000
);
//SCENE
const scene = new THREE.Scene();
//LIGHTS
const light1 = new THREE.AmbientLight(0xffffff, 0.5),
light2 = new THREE.PointLight(0xffffff, 1);
scene.add(light1);
scene.add(light2);
//OBJECT
const geometry = new THREE.CubeGeometry(100, 100, 100);
const material = new THREE.MeshLambertMaterial({ color: 0xf3ffe2 });
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 0, -1000); //set the view position backwards in space so we can see it
scene.add(mesh);
//RENDER LOOP
requestAnimationFrame(render);
function render() {
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.03;
renderer.render(scene, camera);
requestAnimationFrame(render);
}
window.addEventListener( 'resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}, false );
@bovas85
Copy link

bovas85 commented Jun 8, 2020

no idea, try copying this as boilerplate and removing the bits you don't need
https://codepen.io/vcomics/pen/yLyXQJG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment