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>

<!-- 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:200px; left:300px;
    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;

}
.overlayButton:hover {
  background-color: #fff;
  color: #7f8c8d;
  -webkit-transform: scale(1.05);
  -moz-transform: scale(1.05);
  -ms-transform: scale(1.05);
  transform: scale(1.05);
}

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

              
            
!

JS

              
                // forked from siouxcitizen's "dat.gui インターフェースで「はなす」的な機能を作成" http://jsdo.it/siouxcitizen/djbU
//「はなす」ボタンを追加してみました
//
//以下のサイト・コードを参考にさせていただきました
//

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

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.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
    };
    //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");
    
    hyouji.onChange(function(value) {
        if (value) threeDModel.visible = true;
        
        if (!value) threeDModel.visible = false;
    });
    saizu.onChange(function(value) {
        threeDModel.scale.set( value, value, value );
    });

    //メッセージ表示用タイルを作成    
    messageTile = document.createElement('div');
    messageTile.classList.add( 'overlay' );
    messageTile.innerHTML = "わしが村長じゃ!";
    messageTile.style.display = 'none';
    document.body.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;
            
        }
    };
    document.body.appendChild(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 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