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

JS

            
              // forked from siouxcitizen's "forked: dat.gui test" http://jsdo.it/siouxcitizen/3ZUq
// forked from phi's "dat.gui test" http://jsdo.it/phi/sqjc
//dat.gui インターフェースと Three.jsによる3Dモデルを同時に表示するテストを行ってみました
//
//以下のサイト・コードを参考にさせていただきました
//dat.gui test
//http://jsdo.it/phi/sqjc
//
//dat.gui.js サンプル
//http://jsdo.it/cx20/85EI
//
//箱根山周辺の3Dデータを表示してみる(その5)
//http://jsdo.it/cx20/1FkX
var container;
var scene; 
var camera; 
var renderer;
 
var threeDModel;
var isMouseDown = 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,
        "explode": function() {
            alert("explode!");
        }
    };
    var gui = new dat.GUI();
    gui.add(text, "message");
    var saizu = gui.add(text, "size", 1, 5);
    var hyouji = gui.add(text, "display");
    gui.add(text, "explode");
    
    hyouji.onChange(function(value) {
        if (value) threeDModel.visible = true;
        
        if (!value) threeDModel.visible = false;
    });
    saizu.onChange(function(value) {
        threeDModel.scale.set( value, value, value );
    });
    
        // マウス、タッチ処理を呼び出すイベントリスナーをセット
    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