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

              
                <div id="threejs">
  
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-19784624-1', 'auto');
  ga('send', 'pageview');

</script>
              
            
!

CSS

              
                html, body
  margin: 0
  padding: 0
  width: 100%
  height: 100%
  overflow: hidden
  background: #111
              
            
!

JS

              
                #Variables
scene = undefined
camera = undefined
renderer = undefined
container = undefined
controls = undefined
clock = undefined
mesh = undefined
rotate = true

#Scene Start
start = ->
  scene = new THREE.Scene
  VIEW_ANGLE = 45
  NEAR = 0.1
  FAR = 10000
  SCREEN_WIDTH = window.innerWidth
  SCREEN_HEIGHT = window.innerHeight
  ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT
  #Create camera
  camera = new THREE.PerspectiveCamera VIEW_ANGLE, ASPECT, NEAR, FAR
  camera.position.set 107.82504298529939, 104.02121980722944, -114.02178601347767
  camera.rotation.set -2.4020274682629177, 0.6097939469542306, 2.6601321578044113
  camera.lookAt scene.position
  scene.add camera
  #Renderer
  renderer = new THREE.WebGLRenderer
    antialias: true
    alpha: true
  renderer.setSize SCREEN_WIDTH, SCREEN_HEIGHT
  #Window resize helper
  THREEx.WindowResize renderer, camera
  #Append Element
  container = document.getElementById('threejs')
  container.appendChild renderer.domElement
  #Add clock
  clock = new THREE.Clock
  #Orbit Controls
  controls = new THREE.OrbitControls camera, renderer.domElement

#
draw = ->
  #Add Hemisphere Light
  hemiLight = new THREE.HemisphereLight 0xffffff, 0xffffff, 0.6
  hemiLight.color.setHSL 0.6, 1, 0.6
  hemiLight.groundColor.setHSL 0.095, 1, 0.75
  hemiLight.position.set 0, 500, 0
  scene.add hemiLight

  #Add Directional light
  light = new THREE.DirectionalLight 0xffffff, 5
  light.position.set -2000, 0, -500
  light.castShadow = true
  scene.add light
  
  #Load Blender Model
  jsonLoader = new THREE.JSONLoader
  jsonLoader.load 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/150586/mountain.js?v=2.1', addMesh

#Add a model to the scene
addMesh = (geometry, materials) ->
  material = new THREE.MeshFaceMaterial materials
  mesh = new THREE.Mesh geometry, material
  mesh.castShadow = true
  mesh.receiveShadow = true
  mesh.scale.set 12, 12, 12
  mesh.position.set 0, 0, -18
  scene.add mesh

#Animation Loop
animate = ->
  requestAnimationFrame animate
  controls.update()
  if rotate and mesh
    mesh.rotation.y += 0.2 * clock.getDelta()
  renderer.render scene, camera

#Start all the things!
start()
draw()
animate()

              
            
!
999px

Console