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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

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

<!-- OBJLoader.js -->
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r87/examples/js/loaders/OBJLoader.js"></script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js" type="text/javascript"></script>

            
          
!

CSS

            
              body { background-color: #DDDDDD; font: 30px sans-serif; }

.overlay {
    position:absolute; top:250px; left:50px; width:350px; height:150px;    
    padding: 5px;
    background: rgba(0, 0, 0, 0.8);
    color: rgb(255,255,255);
    border-radius: 5px;
    font: 20px bold 80%/150%  sans-serif;
}

.overlayButton {
    position:absolute; top:150px; left:310px;
    font: 20px bold 80%/150% sans-serif;
    font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
    background: rgba(0, 0, 0, 0.8);
    color: rgb(255,255,255);
    letter-spacing: 5px;
    padding: 5px 15px;
    border-radius: 25px;
    margin-bottom: 0.5em;

}




            
          
!

JS

            
              // forked from siouxcitizen's "Three.js r70 で3Dモデル表示とカメラ操作の機能を作成(WebGL使用)" http://jsdo.it/siouxcitizen/9QjK
//
//タイトルのとおり複数3Dモデルを同時に表示してみました
//
//
//以下の自分のコードを参考にしました
//Three.js r70(WebGL使用) Planeによるマップ上に複数OBJモデルを表示
//http://jsdo.it/siouxcitizen/t3rU

var container;
var scene; 
var camera; 
var renderer;

//読み込みリソース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]];


//3Dモデル共用テクスチャ
var texture;
//3Dモデル保持用
var yuushaModel;
var sonchoModel;

var rot = 0; // 角度
// マウスを押した状態かどうかを判別するフラグ
var isMouseDown = false;
// 一時的なマウスの値を格納する変数
var oldX = 0;
var targetRot = 0;

// メッセージ表示タイル
var messageTile;
// 「はなす」ボタン
var talkButton;
// 「はなす」状態かどうか判定
var isTalk = false;

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 = 5.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("#ffeedd", 1);
    var ambient = new THREE.AmbientLight("#221100");
    light.position.set( 0, -70, 100 ).normalize();
    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() ); 

            }

        }
    }

    // 3Dモデル用テクスチャ画像の読込(の準備?)
    texture = new THREE.Texture();
    var manager = new THREE.LoadingManager();
    manager.onProgress = function ( item, loaded, total ) {};
    var onProgress = function ( xhr ) {};
    var onError = function ( xhr ) {};

    
    // 3Dモデル用の共通テクスチャ画像の読込
    var imageLoader = new THREE.ImageLoader( manager );
    //imageLoader.load( 'http://jsrun.it/assets/9/9/W/G/99WGE.png', function ( image ) {
    //imageLoader.load( '/assets/9/9/W/G/99WGE.png', function ( image ) {
    imageLoader.load( 'https://cdn.jsdelivr.net/gh/siouxcitizen/3DModel@master/yuusha.png', function ( image ) {

        texture.image = image;
        texture.needsUpdate = true;

    } );

    // 3Dモデル読込
    var objLoader = new THREE.OBJLoader( manager );

    var callbackYuushaModel = function ( object ) { createObj( object, -1 ); };
    var callbackSonchoModel = function ( object ) { createObj( object, 1 ); };

    //objLoader.load( '/assets/g/U/i/X/gUiXN', callbackYuushaModel); 
    //objLoader.load( '/assets/x/I/9/L/xI9L8', callbackSonchoModel); 
    objLoader.load( 'https://cdn.jsdelivr.net/gh/siouxcitizen/3DModel@master/yuusha.obj', callbackYuushaModel); 
    objLoader.load( 'https://rawcdn.githack.com/siouxcitizen/3DModel/03a4883f336e9a0e80bbcf52b9cf5a3777d16e31/obj/soncho.obj', callbackSonchoModel); 

    //dat.gui作成
    var text = {
        "message": "Hello, world!",
        "displayOne": true,
        "displayTwo": true
    };

    gui = new dat.GUI();
    gui.domElement.id = 'gui';
    
    gui.add(text, "message");
    var hyoujiOne = gui.add(text, "displayOne");
    var hyoujiTwo = gui.add(text, "displayTwo");
    
    hyoujiOne.onChange(function(value) {
        if (value) yuushaModel.visible = true;
        
        if (!value) yuushaModel.visible = false;
    });

    hyoujiTwo.onChange(function(value) {
        if (value) sonchoModel.visible = true;
        
        if (!value) sonchoModel.visible = false;
    });

    //メッセージ表示用タイルを作成    
    messageTile = document.createElement('div');
    messageTile.classList.add( 'overlay' );
    messageTile.innerHTML = "よくぞまいった勇者よ!<br>わしがこの村の村長じゃ!";
    messageTile.style.display = 'none';
    container.appendChild(messageTile);
  
    //「はなす」ボタンを作成    
    talkButton = document.createElement('div');
    talkButton.classList.add( 'overlayButton' );
    talkButton.innerHTML = "はなす";
    talkButton.onclick = function() {
        
        if (isTalk) {
        
            messageTile.style.display = 'none';
            isTalk = false;
        
        } else {
            
            messageTile.style.display = '';
            isTalk = true;
            
        }
    };
    container.appendChild(talkButton);
    //container.removeChild(talkButton);
    
        // マウス、タッチ処理を呼び出すイベントリスナーをセット
    document.addEventListener("mousedown", onMouseDown);
    document.addEventListener("touchstart", onMouseDown);
    document.addEventListener("mouseup", onMouseUp);
    document.addEventListener("touchend", onMouseUp);
    document.addEventListener("mousemove", onMouseMove);
    document.addEventListener("touchmove", onMouseMove);
    
}

// 3Dモデル読込時コールバック関数
function createObj( object, x ) {

    object.traverse( function ( child ) {

        if ( child instanceof THREE.Mesh ) {

            child.material.map = texture;
            child.material.wireframe = false;
        }

        } );

        object.scale.set( 1.5, 1.5, 1.5 );

        //勇者3Dモデルを作成・設置
        if(x == -1) {
            object.scale.set( 0.1, 0.1, 0.1 );
            yuushaModel = object;
            yuushaModel.position.set( 5, 0, -2 );
            yuushaModel.rotation.y =Math.PI;
            scene.add( yuushaModel );

        //村長3Dモデルを作成・設置
        } else if (x == 1) {
            object.scale.set( 0.1, 0.1, 0.1 );
            sonchoModel = object;
            sonchoModel.position.set( 5, 0, -5 );
            scene.add( sonchoModel );

        }

}

function render() { 

    requestAnimationFrame( render ); 

    //rot += 0.5; // 毎フレーム角度を0.5度ずつ足していく
    // イージングの公式を用いて滑らかにする
    // 値 += (目標値 - 現在の値) * 減速値
    rot += (targetRot - rot) * 0.05;

    // 角度に応じてカメラの位置を設定
    camera.position.x = yuushaModel.position.x + 5 * Math.sin(rot * Math.PI / 180);
    camera.position.z = yuushaModel.position.z + 5 * Math.cos(rot * Math.PI / 180);
    // キャラクタ方向を見つめる
    camera.lookAt({x:yuushaModel.position.x,  y:yuushaModel.position.y,  z:yuushaModel.position.z});

    renderer.render(scene, camera);
    
}

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

// マウスを動かした時
function onMouseMove(event) {
    if (isMouseDown) {
        // 3DモデルをX軸とY軸方向に回転させます
        var dy = event.pageX - oldX;
        targetRot += dy * 0.25;
        oldX = event.pageX;
    }
}

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

Console