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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- three.min.js r87 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/87/three.min.js"></script>


              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

body {
  background: #000;
}
              
            
!

JS

              
                // forked from siouxcitizen's "Three.js r70 で3種類のテクスチャを貼り付けたPlaneを表示(WebGL使用)" http://jsdo.it/siouxcitizen/t9A4
//Three.js r70 でPlaneとテクスチャによるマップ表示
//
//草原、砂漠、水辺をイメージしたテクスチャをPlaneに貼り付けて
//マップ絵っぽいものを表示してみました 
//
//Planeのrotationの設定のしかたがイマイチわからない。。。
//Math.PI = 180度?
//
var container;
var scene; 
var camera; 
var renderer;
 
//var plane;
var isMouseDown = false;

//読み込みリソースURL
//フィールドマップ用テクスチャ画像URL
//var planeFieldPngURL = "http://jsrun.it/assets/d/c/u/e/dcue2.png";
//var planeDesertPngURL = "http://jsrun.it/assets/s/t/h/2/sth2z.png";
//var planeWaterPngURL = "http://jsrun.it/assets/5/z/t/g/5ztgk.png";
var planeFieldPngURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAdUlEQVR4nGMo/Cz9fyAxw6gD0AWsJzOAMbUtwmUu1hCgtiPwmYfXAdRwBCGzcKYBaocA0WmA3njUAaMOGHUA2Q5AztuUlBkUOYAaJSZZDoBZiGw5uY4YulFALTzqgFEHjDpgcDbJBrxROqDN8kHRMaEnHnUAADjp2hzJ3BYuAAAAAElFTkSuQmCC";
var planeDesertPngURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAUklEQVR4nGP4v1r3/0BihlEHjDpg1AH4JN/3M4AxuYYTo3/wO4DSIKbIAQOeBkYdMOqAUQeMOmDUAQNeFwz52hDmAHzmDO40MOqAUQeMOoAeGAArslGyN38s2wAAAABJRU5ErkJggg==";
var planeWaterPngURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACTklEQVR4nK2X3VHDMBCEDQRCgBkqYRJIQuCJMiiCRiiFFqgqSgUmZ1ixWt/JDuHhxpaseD+d7sdpbp53rdnHZ5sNc2a3L21nfO9ZM992dvfa5ivMxnj32/u3YdywOO4jgAgC4grBY7NOcD82AEA1vHOQMYBntmb2mHrCkbE3IA5PZA/YwO7ZPTUAs9PFtuoR3OtxAKIbq7iKeOKAnDykUUfCEL2jgitswBCeJ7xAqgHgzCOg7h4vMwFAeAAsrmsikRzp8/5RZQgIQ5zvIaYZgucXq5QFPBAO8BCABT0A9gR7SqM6EsbzKsBQ2gFEj2qyTDm/2QPqjcgDnUW7x5jPXJ+f3W9zWnm75iroeaoAsCuXXN49uxzzV5tdFtHiwuu1FKtnGt6dll4NTAaYrlOxS96hl/NcPwqveK5lD0QAUXXTXqAwgMjrvUqncxw8Nr5cJ1cgqnYMyfGR64BXfhmEAa6fdu3Jot50huaqANVmtBe3+u9Vt7EtWY+u0d1z8VGA82UqIrkGoJBhu0ZgQRxppQCTH3GOZAXA1esBHCcFFItzDuMls81vwVEP1ZqQlmA+CszlLyItsewF3pECRgBeu+bnBQDELbrtxdNVKtLGK638zGtCvQ/PoFl17/VSRHdTy2utbOwlrzExQO6GvLuoium8upo7JtZ43wp6nE2RkwISVTmvvHo5jljyIPPvOTC8/I4CyPu4iDYTQRZHMCQwtvJ5FdBrVCFAzcbsWtdFYHnuEADvBUMAuq73m7+K145s6M9JAfHfAIc+PxrgWMAvxUC/XyZ/924AAAAASUVORK5CYII=";

//マップ配列 0:草原 1:砂漠 2:水辺
//マップ配列はマップの縦横の長さが一定(10*10)になるように設定
var mapData = [[ 1, 2, 1, 1, 1, 1, 0, 0, 2, 2],
               [ 1, 2, 1, 1, 1, 1, 1, 1, 0, 2],
               [ 1, 2, 1, 1, 1, 1, 1, 1, 1, 1],
               [ 1, 2, 1, 1, 1, 0, 0, 0, 0, 0],
               [ 2, 2, 1, 1, 1, 0, 0, 1, 1, 1],
               [ 2, 1, 1, 1, 0, 0, 0, 1, 0, 1],
               [ 2, 1, 1, 1, 0, 0, 0, 0, 1, 1],
               [ 2, 1, 1, 1, 1, 1, 0, 1, 0, 1],
               [ 2, 1, 1, 0, 1, 1, 0, 1, 0, 0],
               [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]];

init();
render();

function init() {

    container = document.createElement( 'div' );
    document.body.appendChild( container );

    // 3Dシーン作成
    scene = new THREE.Scene(); 

    // カメラ設定
    camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 ); 
    camera.position.x = 4.5;
    camera.position.y = 3; 
    camera.position.z = 15.5; 
    
    // 3D描画用レンダラ設定
    renderer = new THREE.WebGLRenderer(); 
    renderer.setSize( window.innerWidth, window.innerHeight ); 
    document.body.appendChild( renderer.domElement ); 
    //背景を水色にする
    renderer.setClearColor(0x00ffff, 1); 

    // 光源の設定
    var light = new THREE.DirectionalLight("#ffffff", 1);
    var ambient = new THREE.AmbientLight("#771111");
    light.position.set(0, 100, 30);
    scene.add(light);
    scene.add(ambient);


    // PLANEオブジェクト作成
    // 共通PLANEジオメトリ作成
    var geometry = new THREE.PlaneGeometry( 1, 1, 1 ); 

    // 草原テクスチャの作成
    var fieldTexture = THREE.ImageUtils.loadTexture( planeFieldPngURL );
    var fieldMaterial = new THREE.MeshBasicMaterial( { map: fieldTexture, side: THREE.DoubleSide } );

    // 砂漠テクスチャの作成
    var desertTexture = THREE.ImageUtils.loadTexture( planeDesertPngURL );
    var desertMaterial = new THREE.MeshBasicMaterial( { map: desertTexture, side: THREE.DoubleSide } );

    // 水辺テクスチャの作成
    var waterTexture = THREE.ImageUtils.loadTexture( planeWaterPngURL );
    var waterMaterial = new THREE.MeshBasicMaterial( { map: waterTexture, side: THREE.DoubleSide } );

    // マップ配列を読み取り、Planeにマップ用テクスチャ画像を貼り付けて表示
    for (var xCounter = 0; xCounter < mapData.length; xCounter++) {

        for (var zCounter = 0; zCounter < mapData[0].length; zCounter++) {

            if(mapData[xCounter][zCounter] == 0) {
	            
	            var fieldPlane = new THREE.Mesh( geometry, fieldMaterial ); 
	            fieldPlane.position.x = xCounter;
	            fieldPlane.position.z = zCounter;
	            fieldPlane.rotation.x =  Math.PI / 360 * 180;
	            scene.add( fieldPlane ); 

            } else if (mapData[xCounter][zCounter] == 1) {

	            var desertPlane = new THREE.Mesh( geometry, desertMaterial ); 
	            desertPlane.position.x = xCounter;
	            desertPlane.position.z = zCounter;
	            desertPlane.rotation.x = Math.PI / 360 * 180;
	            scene.add( desertPlane ); 

            } else if (mapData[xCounter][zCounter] == 2) {

	            var waterPlane = new THREE.Mesh( geometry, waterMaterial ); 
	            waterPlane.position.x = xCounter;
	            waterPlane.position.z = zCounter;
	            waterPlane.rotation.x =  Math.PI / 360 * 180;
	            scene.add( waterPlane.clone() ); 

            }

        }
    }

    document.addEventListener("mousedown", onMouseDown);
    document.addEventListener("touchstart", onMouseDown);
    document.addEventListener("mouseup", onMouseUp);
    document.addEventListener("touchend", onMouseUp);
    document.addEventListener("mousemove", onMouseMove);
    document.addEventListener("touchmove", onMouseMove);
}

function render() { 
    
    requestAnimationFrame( render ); 
    renderer.render(scene, camera);
    
}

// マウスを押したとき
function onMouseDown(event) {
    isMouseDown = true;
}

// マウスを動かした時
function onMouseMove(event) {
    if (isMouseDown) {
        // 3DモデルをX軸とY軸方向に回転させます
        //if ( plane ) {
	//	    plane.rotation.y = getMouseX(event)/50;
	//	    plane.rotation.x = getMouseY(event)/50;
	//    }
    }
}

// マウスを離したとき
function onMouseUp(event) {
    isMouseDown = false;
}

function getMouseX(event) {
    if (event.type.indexOf("touch") == -1)
        return event.clientX;
    else
        return event.touches[0].clientX;
}

function getMouseY(event) {
    if (event.type.indexOf("touch") == -1)
        return event.clientY;
    else
        return event.touches[0].clientY;
}
              
            
!
999px

Console