Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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="main"></div>
              
            
!

CSS

              
                html, body, #main {
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                
const main = document.querySelector('#main')
const scene = new THREE.Scene()

// 新建渲染器并设置大小
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
main.appendChild(renderer.domElement)

// 设置相机和位置,并将视线转向场景中央
const camera = new THREE.PerspectiveCamera(75, window.innerHeight / window.innerWidth, 1, 1000)
camera.position.set(0, 0, 10)
camera.lookAt(scene.position)

// 新建一个立方体
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1)
const cubeMaterial = new THREE.MeshBasicMaterial({ color: 0x123abc })
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial)
scene.add(cube)

// 旋转立方体
function animation() {
  window.requestAnimationFrame(animation)

  renderer.render(scene, camera)
  cube.rotation.z += 0.01
  cube.rotation.y += 0.01
}

animation()

              
            
!
999px

Console