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

              
                    <body>
        <div id="webgl"></div>
    </body>
              
            
!

CSS

              
                   * {margin: 0; padding: 0;}
            html, body {
                overflow: hidden;
            }
              
            
!

JS

              
                (() => {

    window.addEventListener('load', () => {

            // 汎用変数の宣言
            let width = window.innerWidth; // ブラウザのクライアント領域の幅
            let height = window.innerHeight; // ブラウザのクライアント領域の高さ
            let targetDOM = document.getElementById('webgl'); // スクリーンとして使う DOM

            // three.js 定義されているオブジェクトに関連した変数を宣言
            let scene; // シーン
            let camera; // カメラ
            let renderer; // レンダラ
            let axis; //ガイド
            let grid; //ガイド
            let directional;
            let ambient;
            let composer;
            let renderPass;


            // 各種パラメータを設定するために定数オブジェクトを定義
            let CAMERA_PARAMETER = { // カメラに関するパラメータ
                fovy: 90,
                aspect: width / height,
                near: 0.1,
                far: 100.0,
                x: 0.0, // + 右 , - 左
                y: 2, // + 上, - 下
                z: 12.5, // + 手前, - 奥
                lookAt: new THREE.Vector3(0.0, 0.0, 0.0) //x,y,z
            };
            let RENDERER_PARAMETER = { // レンダラに関するパラメータ
                clearColor: 0xFFFFFF, //背景のリセットに使う色
                width: width,
                height: height
            };

            let LIGHT_PARAMETER = {
                directional: {
                    positionX: 0,
                    positionY: 4,
                    positionZ: 5
                },
                ambient: {
                    positionY: 1
                }
            };

            scene = new THREE.Scene();

            camera = new THREE.PerspectiveCamera(
                CAMERA_PARAMETER.fovy,
                CAMERA_PARAMETER.aspect,
                CAMERA_PARAMETER.near,
                CAMERA_PARAMETER.far
            );

            camera.position.x = CAMERA_PARAMETER.x;
            camera.position.y = CAMERA_PARAMETER.y;
            camera.position.z = CAMERA_PARAMETER.z;
            camera.lookAt(CAMERA_PARAMETER.lookAt); //注視点(どこをみてるの?)

            renderer = new THREE.WebGLRenderer();
            renderer.setClearColor(new THREE.Color(RENDERER_PARAMETER.clearColor));
            renderer.setSize(RENDERER_PARAMETER.width, RENDERER_PARAMETER.height);

            targetDOM.appendChild(renderer.domElement); //canvasを挿入する

            let controls = new THREE.OrbitControls(camera, render.domElement);

            //ライト
            directional = new THREE.DirectionalLight(0xffffff);
            ambient = new THREE.AmbientLight(0xffffff, 0.25);

            directional.position.y = LIGHT_PARAMETER.directional.positionY;
            directional.position.z = LIGHT_PARAMETER.directional.positionZ;
            directional.position.x = LIGHT_PARAMETER.directional.positionX;
            ambient.position.y = LIGHT_PARAMETER.ambient.positionY;
            scene.add(directional);
            scene.add(ambient);

            var directionalLightHelper = new THREE.DirectionalLightHelper(directional);
            scene.add(directionalLightHelper);

            var triangles = 100000;
            var baseSize = 10;
            var baseSizeHalf = baseSize / 2;
            var triangleSize = 0.2;
            var triangleSizeHalf = triangleSize / 2;

            var geometry = new THREE.BufferGeometry();

            var positions = new Float32Array(triangles * 3 * 3);
            var indices = new Uint32Array(triangles * 3);


            for (var i = 0; i < positions.length; i += 9) {
                //ポリゴンの位置を決める
                var baseX = Math.random() * baseSize - baseSizeHalf;
                var baseY = Math.random() * baseSize - baseSizeHalf;
                var baseZ = Math.random() * baseSize - baseSizeHalf;

                //ポリゴンの座標を決める
                var x1 = baseX + Math.random() * triangleSize - triangleSizeHalf;
                var y1 = baseY + Math.random() * triangleSize - triangleSizeHalf;
                var z1 = baseZ + Math.random() * triangleSize - triangleSizeHalf;

                var x2 = baseX + Math.random() * triangleSize - triangleSizeHalf;
                var y2 = baseY + Math.random() * triangleSize - triangleSizeHalf;
                var z2 = baseZ + Math.random() * triangleSize - triangleSizeHalf;

                var x3 = baseX + Math.random() * triangleSize - triangleSizeHalf;
                var y3 = baseY + Math.random() * triangleSize - triangleSizeHalf;
                var z3 = baseZ + Math.random() * triangleSize - triangleSizeHalf;

                //座標データをpositionsに入れる
                positions[i] = x1;
                positions[i + 1] = y1;
                positions[i + 2] = z1;

                positions[i + 3] = x2;
                positions[i + 4] = y2;
                positions[i + 5] = z2;

                positions[i + 6] = x3;
                positions[i + 7] = y3;
                positions[i + 8] = z3;
            }

            for (var i = 0; i < indices.length; i++) {
                //indexを入れる
                indices[i] = i;
            }

            //型付配列に変換した頂点データを、THREE.BufferAttributeのインスタンスにして追加
            geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
            geometry.setIndex(new THREE.BufferAttribute(indices, 1));
            geometry.computeVertexNormals();

            var material = new THREE.MeshPhongMaterial({
                color: 0x404040,
                specular: 0x808080,
                shininess: 30,
                side: THREE.DoubleSide
            });

            var mesh = new THREE.Mesh(geometry, material);

            scene.add(mesh);



            render();

            //描画
            function render() {

                renderer.render(scene, camera);

                mesh.rotation.x += 0.02;
                mesh.rotation.y += 0.02;
                mesh.rotation.z += 0.01;

                // animation
                requestAnimationFrame(render);

            }



        },
        false);
})();
              
            
!
999px

Console