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

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

              
                <div id="stage"></div>
<script src="https://82mou.github.io/threejs/js/three.js"></script>
<script src="https://82mou.github.io/threejs/js/OrbitControls.js"></script> <!-- 追加 -->
              
            
!

CSS

              
                
              
            
!

JS

              
                (function() {
    var scene;
    var sphereEarth;
    var camera;
    var light;
    var ambient;
    var gridHelper;
    var axisHelper;
    var lightHelper;
    var renderer;
    var loader;
    var width = 640;
    var height = 330;
    var controls; // 追加

    // ステージを作る
    scene = new THREE.Scene();

    // 地球テクスチャーを準備
    loader = new THREE.TextureLoader();
    loader.load('https://82mou.github.io/threejs/img/earth.jpg', function(texture) {
      createEarth(texture);
      render();
    });

    // 地球を作る
    function createEarth(texture) {
      sphereEarth = new THREE.Mesh(
        	new THREE.SphereGeometry(80, 20, 20), // 形状     
        	new THREE.MeshLambertMaterial({ // 材質     
         		map: texture                           
        	})
    	);
    	sphereEarth.position.set(0, 0, 0);
    	scene.add(sphereEarth);
    };
    
    // 平方光源を作る
		light = new THREE.DirectionalLight(0xffffff, 1);
    light.position.set(100, 130, 80);
    scene.add(light);
    
      // 環境光源を作る
    ambient = new THREE.AmbientLight(0x222222);
    scene.add(ambient);
    
    // カメラを作る
    camera = new THREE.PerspectiveCamera(60, width / height, 1, 1000);
    camera.position.set(200, 100, 300);
    camera.lookAt(scene.position);

    // helper
    gridHelper = new THREE.GridHelper(200, 20);
    scene.add(gridHelper);
    axisHelper = new THREE.AxisHelper(1000);
    scene.add(axisHelper);
    lightHelper = new THREE.DirectionalLightHelper(light, 20);
    scene.add(lightHelper);
  
    // 追加:controls
    controls = new THREE.OrbitControls(camera);
    
    // renderer
    renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(width, height);
    renderer.setClearColor(0xefefef);
    renderer.setPixelRatio(window.devicePixelRatio);
    document.getElementById('stage').appendChild(renderer.domElement);
    
    function render() {
      requestAnimationFrame(render);
      
      controls.update(); // 追加
      renderer.render(scene, camera);
    }

  })();
              
            
!
999px

Console