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

              
                <html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <title>マテリアルサンプル</title>
          <script type="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r127/three.min.js"></script>
      <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/three@0.101.1/examples/js/controls/OrbitControls.js"></script>
               <script>
            // ページの読み込みを待つ
            window.addEventListener('load', init);
        
            function init() {
        
            
                // レンダラーを作成
                const renderer = new THREE.WebGLRenderer();
                renderer.setClearColor(new THREE.Color(0xFDFDFD));
                //sceneの大きさの通知
                renderer.setSize(window.innerWidth, window.innerHeight);
                renderer.setPixelRatio(window.devicePixelRatio);
            
            
                // シーンを作成
                const scene = new THREE.Scene();
            
                // カメラを作成
                const camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 1, 1000);
                camera.position.set(0, 0, 850);
                const controls = new THREE.OrbitControls(camera, document.body);

                // 滑らかにカメラコントローラーを制御する
                controls.enableDamping = true;
                controls.dampingFactor = 0.2;


                //箱の作成 MeshBasicMaterial
                const geometrybox = new THREE.BoxGeometry(100, 100, 100 );
                const materialbox = new THREE.MeshBasicMaterial( {
                    color: 0x3edbf0,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cube = new THREE.Mesh( geometrybox, materialbox );
                scene.add(cube);

                 //箱の作成 MeshNormalMaterial
                const materialboxN = new THREE.MeshNormalMaterial( {
                    color: 0x3edbf0,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cubeN = new THREE.Mesh( geometrybox, materialboxN );
                scene.add(cubeN);

                cubeN.position.x = -150;
                cubeN.position.y = 150;
                cubeN.position.z = 0;

                //箱の作成 MeshLambertMaterial
                const materialboxL = new THREE.MeshLambertMaterial( {
                    color: 0x3edbf0,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cubeL = new THREE.Mesh( geometrybox, materialboxL );
                scene.add(cubeL);

                cubeL.position.x = 150;
                cubeL.position.y = 150;
                cubeL.position.z = 0;

                //箱の作成 MeshPhongMaterial
                const materialboxP = new THREE.MeshPhongMaterial( {
                    color: 0x3edbf0,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cubeP = new THREE.Mesh( geometrybox, materialboxP );
                scene.add(cubeP);

                cubeP.position.x = 150;
                cubeP.position.y = -150;
                cubeP.position.z = 0;

                //箱の作成 MeshToonMaterial
                const materialboxT = new THREE.MeshToonMaterial( {
                    color: 0x3edbf0,
                    opacity: 0.5,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cubeT = new THREE.Mesh( geometrybox, materialboxT );
                scene.add(cubeT);

                cubeT.position.x = -150;
                cubeT.position.y = -150;
                cubeT.position.z = 0;

                 //箱の作成 MeshStandardMaterial
                const materialboxS = new THREE.MeshStandardMaterial( {
                    color: 0x3edbf0,
                    transparent: true,
                    side: THREE.DoubleSide,});
                const cubeS = new THREE.Mesh( geometrybox, materialboxS );
                scene.add(cubeS);

                cubeS.position.x = -250;
                cubeS.position.y = -250;
                cubeS.position.z = 0;

                 //箱の作成 MultiMaterial
                const textuer1 = new THREE.MeshPhongMaterial({color: 0xe93b81 });
                const textuer2 = new THREE.MeshPhongMaterial({color: 0xf5abc9 });
                const textuer3 = new THREE.MeshToonMaterial({color: 0xffe5e2 });
                const textuer4 = new THREE.MeshToonMaterial({color: 0xb6c9f0 });
                const textuer5 = new THREE.MeshStandardMaterial({color: 0x3edbf0 });
                const textuer6 = new THREE.MeshStandardMaterial({color: 0xc0fefc });
                const materialboxM = new THREE.MultiMaterial([textuer1, textuer2, textuer3, textuer4, textuer5, textuer6]);
                const cubeM = new THREE.Mesh( geometrybox, materialboxM );
                scene.add(cubeM);

                cubeM.position.x = 250;
                cubeM.position.y = 250;
                cubeM.position.z = 0;

                 //箱の作成 MeshDepthMaterial
                const materialboxD = new THREE.MeshDepthMaterial();
                const cubeD = new THREE.Mesh( geometrybox, materialboxD );
                scene.add(cubeD);

                cubeD.position.x = 250;
                cubeD.position.y = -250;
                cubeD.position.z = 0;

                // スポッドライト(色, 光の強さ, 距離, 照射角, ボケ具合, 減衰率)
                const spotLight = new THREE.SpotLight(0xffffff);
                spotLight.position.set( 100, 100, 450 );
                spotLight.castShadow = true;
                scene.add(spotLight);

                document.getElementById("myCanvas").appendChild(renderer.domElement);
            
                tick();
            
                // 毎フレーム時に実行されるループイベントです
                function tick() {
                    cube.rotation.x += 0.01;
                    cube.rotation.y += 0.01;
                    cubeN.rotation.x += 0.01;
                    cubeN.rotation.y += 0.01;
                    cubeL.rotation.x += 0.01;
                    cubeL.rotation.y += 0.01;
                    cubeP.rotation.x += 0.01;
                    cubeP.rotation.y += 0.01;
                    cubeT.rotation.x += 0.01;
                    cubeT.rotation.y += 0.01;
                    cubeS.rotation.x += 0.01;
                    cubeS.rotation.y += 0.01;
                    cubeM.rotation.x += 0.01;
                    cubeM.rotation.y += 0.01;
                    cubeD.rotation.x += 0.01;
                    cubeD.rotation.y += 0.01;
                    renderer.render(scene, camera); // レンダリング
            
                    requestAnimationFrame(tick);
                }
                }
                
            </script>
        <style>
            body {
                /* set margin to 0 and overflow to hidden, to go fullscreen */
                margin: 0;
            
            }

        </style>
    </head>
    <body>
        <div id="myCanvas">
        </div>
    </body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console