Pen Settings



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


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


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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


                <!-- 来自 learning three.js -->
<script src=""></script>
<script src=""></script>
<script src=""></script>

<!-- Div which will hold the Output -->
<div id="webgl">


                * {
  margin: 0;
  padding: 0;

body {
  overflow: hidden;


                function init() {
        // 创建一个场景
        var scene = new THREE.Scene();

        // 创建一个摄像机,它定义了我们的观察位置
        var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.x = 300;
        camera.position.y = 200;
        camera.position.z = 100;

        // 创建一个渲染器并设置其大小
        var renderer = new THREE.WebGLRenderer();

        renderer.setSize(window.innerWidth, window.innerHeight);
        var cubeGeometry = new THREE.CubeGeometry(30,30,30);
        var sphereGeometry = new THREE.SphereGeometry(20, 100, 100);
        const mixers = [];
        const clock = new THREE.Clock();
        // 线框
        var cubeWireMaterial = new THREE.MeshBasicMaterial({ wireframe: true, color: 0x666666 });
        var cubeMeshWire = new THREE.Mesh(cubeGeometry, cubeWireMaterial);
        cubeMeshWire.position.set(0, 0, 0);
        // 上下移动动画
        const mixer = new THREE.AnimationMixer(cubeMeshWire);
        const action = mixer.clipAction(getClip());
        action.timeScale = 1;
        action.loop = THREE.LoopPingPong;;
        // 创建一个平行光并设置其位置
        var directionalLight = new THREE.DirectionalLight(0xffffff, 0.7);
        directionalLight.position.set(-20, 40, 60);

        // 增加一个环境光,提亮整个场景
        var ambientLight = new THREE.AmbientLight(0x292929);

        // 将渲染器的输入(canvas)插入到特定 DOM 元素下

        // 确保摄像机第一时刻是看向场景中心(0,0,0)
        function getClip() {
          const times = [0, 1]; // 关键帧时间数组,离散的时间点序列
          const values = [0, 0, 0, 0, 10, 0]; // 与时间点对应的值组成的数组
          // 创建位置关键帧对象:0时刻对应位置0, 0, 0   10时刻对应位置150, 0, 0
          const posTrack = new THREE.VectorKeyframeTrack('stone.position', times, values);
          const duration = 1;
          return new THREE.AnimationClip('stonePosClip', duration, [posTrack]);

        function render() {
            const delta = clock.getDelta();
            mixers.forEach((mixer) => mixer.update(delta))
            // render using requestAnimationFrame
            renderer.render(scene, camera);
    window.onload = init