Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- three.min.js r87 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>

<!-- three.min.js r87 -->
<script src="https://s.cdpn.io/25480/OrbitControls.js"></script>

<!-- GLTFLoader.js -->
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r88/examples/js/loaders/GLTFLoader.js"></script>
              
            
!

CSS

              
                
              
            
!

JS

              
                var width = window.innerWidth,
    height = window.innerHeight;

// Create a renderer and add it to the DOM.
var renderer = new THREE.WebGLRenderer({ antialias : true});
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
// Create the scene 
var scene = new THREE.Scene();
// Create a camera
var camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 10000);
camera.position.z = 130;
camera.position.x = 130;
camera.position.y = 130;

scene.add(camera);

// Create a light, set its position, and add it to the scene.
var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene.add(light);

    var light = new THREE.DirectionalLight("#c1582d", 1);
    var ambient = new THREE.AmbientLight("#85b2cd");
    light.position.set( 0, -70, 100 ).normalize();
    scene.add(light);
    scene.add(ambient);

// Add OrbitControls so that we can pan around with the mouse.
var controls = new THREE.OrbitControls(camera, renderer.domElement);

// Add axes
// var axes = new THREE.AxisHelper(50);
// scene.add( axes );

// var geometry = new THREE.BoxGeometry(5,5,5);
// var cubeMaterial = new THREE.MeshNormalMaterial(); 

// var mesh = new THREE.Mesh( geometry, cubeMaterial );
// scene.add( mesh );

// Planes
THREE.ImageUtils.crossOrigin = '';
var planeGeometry = new THREE.PlaneGeometry(40, 30, 1, 1);


const loader = new THREE.TextureLoader();

// Images

var planeMaterial = new THREE.MeshLambertMaterial({map: loader.load('https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/magasin2-min.png'), side: THREE.DoubleSide});

var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.receiveShadow = true;
// plane.rotation.y = -0.5 * Math.PI;
plane.position.set(-40,40,0);
plane.material.side = THREE.DoubleSide;
scene.add(plane);


var planeGeometry2 = new THREE.PlaneGeometry(22.5, 28, 1, 1);
var planeMaterial2 = new THREE.MeshLambertMaterial({map: loader.load('https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/magasin4-min.png'), side: THREE.DoubleSide});
var plane2 = new THREE.Mesh(planeGeometry2, planeMaterial2);
plane2.receiveShadow = false;
// plane.rotation.y = -0.5 * Math.PI;
plane2.position.set(30,34,0);
plane2.material.side = THREE.DoubleSide;
scene.add(plane2);

var planeMaterial3 = new THREE.MeshLambertMaterial({map: loader.load('https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/magasin3-min.png'), side: THREE.DoubleSide});
var plane3 = new THREE.Mesh(planeGeometry, planeMaterial3);
plane3.receiveShadow = false;
plane3.rotation.y = -0.5 * Math.PI;
plane3.position.set(0,-34,40);
scene.add(plane3);

var planeGeometry4 = new THREE.PlaneGeometry(51, 76, 1, 1);
var planeMaterial4 = new THREE.MeshLambertMaterial({map: loader.load('https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/magasin5-min.png'), side: THREE.DoubleSide});
var plane4 = new THREE.Mesh(planeGeometry4, planeMaterial4);
plane4.receiveShadow = false;
plane4.rotation.y = -0.5 * Math.PI;
plane4.position.set(0,-44,-40);
scene.add(plane4);



// Cylinders

const cylGeometry = new THREE.CylinderGeometry( 1, 1, 200, 32 );
const cylMaterial = new THREE.MeshBasicMaterial( {color: 0xffffff} );
const cylinder = new THREE.Mesh( cylGeometry, cylMaterial );
const cylinder2 = new THREE.Mesh( cylGeometry, cylMaterial );
const cylinder3 = new THREE.Mesh( cylGeometry, cylMaterial );
cylinder2.rotation.x = -0.5 * Math.PI;
cylinder3.rotation.z = -0.5 * Math.PI;
scene.add( cylinder );
scene.add( cylinder2 );
scene.add( cylinder3 );



// Models

const modelLoader = new THREE.GLTFLoader();

modelLoader.load( 'https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/TREE_STUMP_CARVED_5K.gltf', function ( gltf ) {

  
  mesh = gltf.scene;
  mesh.scale.set( 20, 20, 20 );
  mesh.position.set( 50, 0, 50 );
  scene.add( mesh );
  
  
	// gltf.scale.set( 3, 3, 3 );
	// gltf.position.set( 10, 10, 10 );
	// scene.add( gltf.scene );

}, undefined, function ( error ) {

	console.error( error );

} );

modelLoader.load( 'https://codepen-mathias.s3-eu-west-1.amazonaws.com/w/RED_BRICK_PILE_MEDUIM_5K.gltf', function ( gltf ) {

  
  mesh = gltf.scene;
  mesh.scale.set( 20, 20, 20 );
  mesh.position.set( -40, -80, -40 );
  scene.add( mesh );
  
  
	// gltf.scale.set( 3, 3, 3 );
	// gltf.position.set( 10, 10, 10 );
	// scene.add( gltf.scene );

}, undefined, function ( error ) {

	console.error( error );

} );



var cubeGeometry = new THREE.BoxGeometry( 6, 6, 6 );
var cubeMaterial = new THREE.MeshLambertMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( cubeGeometry, cubeMaterial );
cube.position.set( -30, 0, 50 );
scene.add( cube );

const geometry = new THREE.BoxGeometry( 20, 20, 20 );
const edges = new THREE.EdgesGeometry( geometry );
const line = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( { color: 0xffffff } ) );
line.position.set( -30, 0, 50 );
scene.add( line );




resize();
animate();
window.addEventListener('resize',resize);

function resize(){
  let w = window.innerWidth;
  let h = window.innerHeight;
  
  renderer.setSize(w,h);
  camera.aspect = w / h;
  camera.updateProjectionMatrix();
}

// Renders the scene
function animate() {
line.rotation.y += 0.02
  // line.rotation.x += 0.02
  cube.rotation.y += 0.01
  cube.rotation.x += 0.01
  line.position.y = Math.cos(cube.rotation.y) * 2
  renderer.render( scene, camera );
  controls.update();

  requestAnimationFrame( animate );
}
              
            
!
999px

Console