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 sphereCrowd; // 追加
    var sphereUniverse; // 追加
    var camera;
    var light;
    var ambient;
    var gridHelper;
    var axisHelper;
    var lightHelper;
    var renderer;
    var loader;
    var width =  640;
    var height = 525;
    var controls;

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

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

    // 追加:雲テクスチャーを準備
    loader.load('https://82mou.github.io/threejs/img/crowd.png', function(texture) {
      createCrowd(texture);
      render();
    });
  
    // 追加:宇宙テクスチャーを準備
    loader.load('https://82mou.github.io/threejs/img/universe.jpg', function(texture) {
      createUniverse(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);
    };
  
    // 追加:雲を作る
    function createCrowd(texture) {
      sphereCrowd = new THREE.Mesh(
        	new THREE.SphereGeometry(82, 20, 20), // 形状     
        	new THREE.MeshLambertMaterial({ // 材質     
         		map: texture,
            transparent: true,
            side: THREE.DoubleSide // 裏からも見えるようにする                         
        	})
    	);
    	sphereCrowd.position.set(0, 0, 0);
    	scene.add(sphereCrowd);
    };
  
    // 追加:宇宙を作る
    function createUniverse(texture) {
      sphereUniverse = new THREE.Mesh(
        	new THREE.SphereGeometry(10000, 20, 20), // 形状     
        	new THREE.MeshLambertMaterial({ // 材質     
         		map: texture,
            side: THREE.DoubleSide // 裏からも見えるようにする
        	})
    	);
    	sphereUniverse.position.set(0, 0, 0);
    	scene.add(sphereUniverse);
    };
  
    // 追加:点光源を作る
		light = new THREE.PointLight(0xffffff, 2.5, 0);
    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, 100000);
    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.PointLightHelper(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);
      
      sphereEarth.rotation.y += 0.0005; // 追加:地球を回転させる
      sphereCrowd.rotation.y += 0.0010; // 追加:雲を回転させる
      controls.update();
      renderer.render(scene, camera);
    }

  })();
              
            
!
999px

Console