Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <head>
    <meta charset="utf-8">
    <title>頂点の取得</title>
        <style>
            * {
            margin: 0;
            padding: 0;
            }
            html,body {
                overflow: hidden;
                height: 100%;
            }
        </style>
</head>
    
    <body>
    <div id="WebGL-output"></div>
<script type="module">
    import * as THREE from'https://unpkg.com/three@0.126.1/build/three.module.js';
    import { OrbitControls } from 'https://unpkg.com/three@0.126.1/examples/jsm/controls/OrbitControls.js';

    let camera;
    let scene;
    let renderer;
    let dirLight;
   // let gridHelper;
   // let axisHelper;

    init();
    
    function init() {
        
        //シーンの作成
        scene = new THREE.Scene();

        //カメラの作成
        camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
        //カメラセット
        camera.position.set(20, 30, 50);
        camera.lookAt(new THREE.Vector3(0, 0, 0));

        //光源
        dirLight = new THREE.SpotLight(0xffffff,1.5);//color,強度
            dirLight.position.set(-30, 40, 30);
            scene.add(dirLight);

        
        //レンダラー
        renderer = new THREE.WebGLRenderer({ 
            alpha: true,
            antialias: true
        });
        renderer.setClearColor(new THREE.Color(0x000000));
        renderer.setSize(window.innerWidth, window.innerHeight);  
        
        // 滑らかにカメラコントローラーを制御する
        const controls = new OrbitControls(camera, document.body);
        controls.enableDamping = true;
        controls.dampingFactor = 0.2;

        // gridHelper 
       /* gridHelper = new THREE.GridHelper(80, 50,0xffff00) //大きさ・分割数・センタラインcolor・マスカラ―
        scene.add(gridHelper);*/

        // axisHelper
       /* axisHelper = new THREE.AxisHelper(50);  // 軸のサイズ
        scene.add(axisHelper);*/

        //Geometryを生成
        const geometry = new THREE.BoxGeometry(10,10,10);
        const material = new THREE.MeshNormalMaterial({wireframe: true});
        const box = new THREE.Mesh(geometry,material);
        scene.add(box);
       

        // ジオメトリの頂点座標の配列
        const attribute = geometry.attributes.position;
    
        for (let i = 0; i < attribute.count; i++) {
            // 立方体の頂点座標を取得
            const x = attribute.getX(i);
            const y = attribute.getY(i);
            const z = attribute.getZ(i);
            console.log(x,y,z);//出力結果の確認(5 5 5・・・)
        }
      
        document.getElementById("WebGL-output").appendChild(renderer.domElement);
        
        animate();

        function animate() {
        requestAnimationFrame(animate);
        renderer.render(scene, camera);
    }
    
    }
   
    </script>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console