cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

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

<script id="vs" type="x-shader/x-vertex">
  attribute vec3 position; 
  uniform mat4 projectionMatrix; 
  uniform mat4 modelViewMatrix; 
  void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }
</script>
<script id="fs" type="x-shader/x-fragment">
  void main() { gl_FragColor =vec4(1.0, 1.0, 1.0, 1.0);; }
</script>
            
          
!
            
              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 CAMERA_PARAMETER = {
            // カメラに関するパラメータ
            fovy: 90,
            aspect: width / height,
            near: 0.1,
            far: 20.0,
            x: 4.0, // + 右 , - 左
            y: 0, // + 上, - 下
            z: 7.5, // + 手前, - 奥
            lookAt: new THREE.Vector3(0.0, 0.0, 0.0) //x,y,z
        };
        let RENDERER_PARAMETER = {
            // レンダラに関するパラメータ
            clearColor: 0x000000, //背景のリセットに使う色
            width: width,
            height: height
        };

        let LIGHT_PARAMETER = {
            directional: {
                positionX: -0.5,
                positionY: 4,
                positionZ: 13
            },
            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を挿入する

        //ライト
        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);

        axis = new THREE.AxisHelper(1000);
        axis.position.set(0, 0, 0);

        var geometry = new THREE.PlaneGeometry(3, 3, 10, 10);

        var material = new THREE.RawShaderMaterial({
            vertexShader: document.getElementById('vs').textContent,
            fragmentShader: document.getElementById('fs').textContent
        });
        var cube = new THREE.Mesh(geometry, material);
        scene.add(cube);


        render();

        //描画
        function render() {
            renderer.render(scene, camera);

            // animation
            requestAnimationFrame(render);
        }

            
          
!
999px
Loading ..................

Console