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

#gui { position: absolute; top: 20px; left: 20px; height: 140px }

            
          
!

JS

            
              // forked from siouxcitizen's "dat.gui インターフェースの座標指定テスト" http://jsdo.it/siouxcitizen/AqeH
//dat.gui インターフェースの「talk」をチェックすると「はなす」風の機能となるようにしてみました
//チェックをはずすと「はなす」状態がキャンセルされます
//
//すこしごまかし的な「はなす」機能のコードとなりましたが。。。
//
//
//以下のサイト・コードを参考にさせていただきました
//
//Dynamically create 2D text in three.js
//http://stackoverflow.com/questions/15248872/dynamically-create-2d-text-in-three-js
//
//テキストの背景色を半透明にしつつ、文字色は不透明にする方法 
//http://tips.nishishi.com/css/text-opacity-rgba.html
//
//3d under the carpet
//http://jsdo.it/tmake/1IRf
//
//Getting the country name of clicked spot
//http://jsdo.it/makc/19UWi
//
//2D overlays in three.js
//http://jsdo.it/makc/hw0L
//
//font は、フォント関連のスタイル(イタリック体、スモールキャピタル、太さ、サイズ、行の高さ、フォント)を一括で指定するプロパティです。
//http://www.tagindex.com/stylesheet/text_font/font.html

var container;
var scene; 
var camera; 
var renderer;
 
var threeDModel;
var isMouseDown = false;

var messageTile;

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.z = 50; 
    camera.position.y = 10; 

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

    var 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 );
    //objLoader.load( 'http://jsrun.it/assets/x/x/y/2/xxy2B', function ( object ) {
    //objLoader.load( '/assets/x/P/I/Z/xPIZZ', function ( object ) {
    objLoader.load( 'https://rawcdn.githack.com/siouxcitizen/3DModel/03a4883f336e9a0e80bbcf52b9cf5a3777d16e31/obj/soncho.obj', function ( object ) {

        object.traverse( function ( child ) {

            if ( child instanceof THREE.Mesh ) {

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

        } );

        object.scale.set( 2, 2, 2 );
        threeDModel = object;
        scene.add( threeDModel );

    }, onProgress, onError );
    
    var text = {
        "message": "Hello, world!",
        "size": 2,
        "display": true,
        "talk": false
    };
    //gui = new dat.GUI();
    gui = new dat.GUI();
    gui.domElement.id = 'gui';
        
    
    
    gui.add(text, "message");
    var saizu = gui.add(text, "size", 1, 5);
    var hyouji = gui.add(text, "display");
    var hanasu = gui.add(text, "talk");
    
    hyouji.onChange(function(value) {
        if (value) threeDModel.visible = true;
        
        if (!value) threeDModel.visible = false;
    });
    saizu.onChange(function(value) {
        threeDModel.scale.set( value, value, value );
    });
    hanasu.onChange(function(value) {
        if (value) messageTile.style.display = '';
        
        if (!value) messageTile.style.display = 'none';
    });

    //メッセージ表示用タイルを作成    
    messageTile = document.createElement('div');
    messageTile.classList.add( 'overlay' );
    messageTile.innerHTML = "わしが村長じゃ!";
    messageTile.style.display = 'none';
    document.body.appendChild(messageTile);
    
        // マウス、タッチ処理を呼び出すイベントリスナーをセット
    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 createScene( geometry, materials, x, y, z) {

	threeDModel = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
	threeDModel.position.set( x, y, z );
	threeDModel.scale.set( 4, 4, 4 );
	scene.add( threeDModel );

}

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

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

// マウスを動かした時
function onMouseMove(event) {
    if (isMouseDown) {
        // 3DモデルをX軸とY軸方向に回転させます
        if ( threeDModel ) {
		    threeDModel.rotation.y = getMouseX(event)/50;
		    threeDModel.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