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 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="//code.createjs.com/easeljs-0.8.0.min.js"></script>
<canvas id="myCanvas" width="465" height="150"></canvas>
              
            
!

CSS

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

body {
  background: #ffffff;
}
              
            
!

JS

              
                // forked from siouxcitizen's "Three.js r70 で自前でカメラ操作機能作成(WebGL使用)" http://jsdo.it/siouxcitizen/8bYv
//Three.js r70(WebGL使用)とCreateJSでインターフェース実験
//
//Three.js r70(WebGL使用)とCreateJSでインターフェース的なものが作れないか試してみました
//
//なぜかAway3Dでは画面の下側に配置できたCreateJS部分が上側にしか配置できませんでした。。。
//3D部分もなんかつぶれてしまったように見える。。。
//まぁでもこれでなんとか進めていく予定です
//
//操作方法:
//青ボタンで勇者キャラ左まわりにカメラが移動
//赤ボタンで勇者キャラ右まわりにカメラが移動
//黄色ボタンでカメラの距離を変更
//緑ボタンでカメラを元の位置へ移動
//
//
//下記の自分のサイト・コードを参考にしました
//
//Away3Dで他にもいろいろインターフェース実験
//http://jsdo.it/siouxcitizen/kGU5
//
var container;
var scene; 
var camera; 
var renderer;
 
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]];

//3Dモデル保持用
var threeDModel;

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

var cameraDistance = 4;

//CreateJS(EaselJS)用
var easelJSStage;
var easelJSMainMessage;

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 ); 
    renderer.setSize( window.innerWidth, 315 ); 
    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() ); 

            }

        }
    }

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

    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 );
    //objLoader.load( 'http://jsrun.it/assets/g/U/i/X/gUiXN', function ( object ) {
    //objLoader.load( '/assets/g/U/i/X/gUiXN', function ( object ) {
    objLoader.load( 'https://cdn.jsdelivr.net/gh/siouxcitizen/3DModel@master/yuusha.obj', function ( object ) {

        object.traverse( function ( child ) {

            if ( child instanceof THREE.Mesh ) {

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

        } );

        object.scale.set( 0.1, 0.1, 0.1 );
        threeDModel = object;
        scene.add( threeDModel );
        threeDModel.position.set( 5, 0, -1 );

    }, onProgress, onError );

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

    //CreateJS(EaselJS)用ステージを作成
    var canvas = document.getElementById("myCanvas");
    easelJSStage = new createjs.Stage(canvas).set({x:canvas.width / 2, y:canvas.height / 2});

    initCreateJSParts();
}

function render() { 

    requestAnimationFrame( render ); 

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

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

    renderer.render(scene, camera);
    
    easelJSStage.update();
}

// マウスを押したとき
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;
}

//CreateJS(EaselJS)関連オブジェクト初期化
function initCreateJSParts() {

    //メッセージ作成・表示
    easelJSMainMessage = new createjs.Text("EaselJSでつくるAway3Dインターフェース", "20px Arial", "#000000");
    easelJSMainMessage.x = -200;
    easelJSMainMessage.y = 5;
    easelJSStage.addChild(easelJSMainMessage);

    //青ボタン作成
    var blueXBtn = new createjs.Shape(); 
    easelJSStage.addChild(blueXBtn);
    blueXBtn.addEventListener("click", function(){ 
                                          targetRot = targetRot - 60; 
                                          easelJSMainMessage.text = "青ボタン押下 カメラ位置回転移動";
                                      }
                            );

    var myGraphics = blueXBtn.graphics;
    var fillCommand = myGraphics.beginFill("blue").command;
    var circleCommand = myGraphics.drawCircle(0, 0, 25).command;
    blueXBtn.x = -180;
    blueXBtn.y = -35;

    //赤ボタン作成
    var redABtn = new createjs.Shape(); 
    easelJSStage.addChild(redABtn);
    redABtn.addEventListener("click", function(){ 
                                          targetRot = targetRot + 60; 
                                          easelJSMainMessage.text = "赤ボタン押下 カメラ位置回転移動";
                                      }
                            );

    myGraphics = redABtn.graphics;
    fillCommand = myGraphics.beginFill("red").command;
    circleCommand = myGraphics.drawCircle(0, 0, 25).command;
    redABtn.x = -80;
    redABtn.y = -35;

    //黄色ボタン作成
    var yellowBBtn = new createjs.Shape(); 
    easelJSStage.addChild(yellowBBtn);
    yellowBBtn.addEventListener("click", function(){ 
                                             cameraDistance = cameraDistance - 1;
                                             if (cameraDistance < 2){
                                                 cameraDistance = 6;
                                             } 
                                             easelJSMainMessage.text = "黄色ボタン押下 カメラ距離移動";
                                         }
                               );

    myGraphics = yellowBBtn.graphics;
    fillCommand = myGraphics.beginFill("yellow").command;
    circleCommand = myGraphics.drawCircle(0, 0, 25).command;
    yellowBBtn.x = 20;
    yellowBBtn.y = -35;

    //緑ボタン作成
    var greenYBtn = new createjs.Shape(); 
    easelJSStage.addChild(greenYBtn);
    greenYBtn.addEventListener("click", function(){ 
                                             targetRot = 0;
                                             cameraDistance = 4; 
                                             easelJSMainMessage.text = "緑ボタン押下 カメラ初期位置";
                                         }
                               );

    myGraphics = greenYBtn.graphics;
    fillCommand = myGraphics.beginFill("green").command;
    circleCommand = myGraphics.drawCircle(0, 0, 25).command;
    greenYBtn.x = 120;
    greenYBtn.y = -35;

    easelJSStage.update();
}

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