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 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.

HTML

              
                <!-- 来自 learning three.js -->
<script src="https://unpkg.com/three@0.111.0/build/three.js"></script>
<script src="https://unpkg.com/stats.js"></script>
<script src="https://cdn.bootcss.com/dat-gui/0.6.5/dat.gui.min.js"></script>

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

CSS

              
                * {
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
}
              
            
!

JS

              
                function TextureAnimator(texture, tilesHoriz, tilesVert, numTiles, tileDispDuration) {
    this.tilesHorizontal = tilesHoriz;
    this.tilesVertical = tilesVert;
    this.numberOfTiles = numTiles;
    texture.wrapS = THREE.RepeatWrapping;
    texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(1 / this.tilesHorizontal, 1 / this.tilesVertical);

    this.tileDisplayDuration = tileDispDuration;

    this.currentDisplayTime = 0;

    this.currentTile = 0;

    this.update = (milliSec) => {
        this.currentDisplayTime += milliSec;
        while (this.currentDisplayTime > this.tileDisplayDuration) {
            this.currentDisplayTime -= this.tileDisplayDuration;
            this.currentTile++;
            if (this.currentTile === this.numberOfTiles) { this.currentTile = 0; }
            const currentColumn = this.currentTile % this.tilesHorizontal;
            texture.offset.x = currentColumn / this.tilesHorizontal;
            const currentRow = Math.floor(this.currentTile / this.tilesHorizontal);
            texture.offset.y = currentRow / this.tilesVertical;
        }
    };
}

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 = -500;

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

        renderer.setClearColor(0xffffff);
        renderer.setSize(window.innerWidth, window.innerHeight);
  
        const arrowSrc = 'https://p1.music.126.net/NBwpm3-g3isuPkL98Eqqug==/109951164532405066.png';
  
        const mixers = [];
        const clock = new THREE.Clock();
  
        const arrowTexture = new THREE.TextureLoader().load(arrowSrc);
        const arrowAni = new TextureAnimator(arrowTexture, 13, 1, 13, 75);
        const material = new THREE.SpriteMaterial({ map: arrowTexture, color: 0xffffff });
        const arrow = new THREE.Sprite(material);
        arrow.scale.set(33, 15, 1);
        scene.add(arrow);
  
  
        // 创建一个平行光并设置其位置
        var directionalLight = new THREE.DirectionalLight(0xffffff, 0.7);
        directionalLight.position.set(-20, 40, 60);
        scene.add(directionalLight);

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

        // 将渲染器的输入(canvas)插入到特定 DOM 元素下
        document.getElementById("webgl").appendChild(renderer.domElement);

 
        // 确保摄像机第一时刻是看向场景中心(0,0,0)
        camera.lookAt(scene.position);
        render();
  
        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));
            arrowAni.update(delta * 1000);
            // render using requestAnimationFrame
            requestAnimationFrame(render);
            renderer.render(scene, camera);
        }
    }
    window.onload = init

              
            
!
999px

Console