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

            
              <!-- babylon.min.js v3.3.0 -->
<script src="https://cdn.jsdelivr.net/npm/babylonjs@3.3.0/babylon.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/babylonjs-gui@3.3.0/babylon.gui.min.js"></script>

<canvas id="renderCanvas"></canvas>

            
          
!

CSS

            
              html, body {
    overflow: hidden;
    width   : 100%;
    height  : 100%;
    margin  : 0;
    padding : 0;
}

#renderCanvas {
    width   : 100%;
    height  : 100%;
    touch-action: none;
}
            
          
!

JS

            
              //Babylon.js Version 3.3.0 のライブラリを使用してみました
//
//Babylon.jsのサンプルがある「Babylon.js Playground」からのコードを参考にして
//GUI機能のボタンでCubeオブジェクトを移動できるようにしてみました
//

var canvas = document.getElementById("renderCanvas");

var createScene = function () {
    
        var scene = new BABYLON.Scene(engine);

        // create a FreeCamera, and set its position to (x:0, y:5, z:-10)
        var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene);
        
        // target the camera to scene origin
        camera.setTarget(BABYLON.Vector3.Zero());
        
        // attach the camera to the canvas
        camera.attachControl(canvas, false);
        
        // create a basic light, aiming 0,1,0 - meaning, to the sky
        var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
        
        // create a built-in "sphere" shape; its constructor takes 6 params: name, segment, diameter, scene, updatable, sideOrientation 
        var sphere = BABYLON.Mesh.CreateSphere('sphere1', 16, 2, scene);
        
        // move the sphere 
        sphere.position.y = 1;
        sphere.position.z = 5;

        var box = BABYLON.Mesh.CreateBox("box", 3.0, scene);
        var material = new BABYLON.StandardMaterial("material01", scene);
        box.material = material;
        
        material.diffuseColor = new BABYLON.Color3(1, 0, 0); 

        // create a built-in "ground" shape;
        var ground = BABYLON.Mesh.CreateGround('ground1', 16, 16, 2, scene);
    
        // UI
        var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
    
        //下段 表示用ラベル ラベル部分設定 直接advancedTextureに追加
        var label = new BABYLON.GUI.Rectangle("label");
        label.background = "#00ffff";
        label.height = "60px";
        label.alpha = 0.5;
        label.width = "300px";
        label.cornerRadius = 25;
        label.thickness = 1;
        //label2.linkOffsetY = 30;
        label.top = "5%";
        label.paddingLeft = "10px";
            label.paddingRight = "10px";
        advancedTexture.addControl(label); 
        //下段 表示用ラベル テキスト部分設定 ラベルに追加
        var text = new BABYLON.GUI.TextBlock();
        text.text = "てすと";
        text.color = "black";
        text.fontSize = "20px";
        label.addControl(text); 

    
    
        //ボタンまとめ用パネル ここにボタンをまとめてからadvancedTextureに追加    
        var UiPanel = new BABYLON.GUI.StackPanel("horizontal");
        UiPanel.isVertical = false;
        UiPanel.top = "30%";
        UiPanel.width = "360px";
        UiPanel.height = "160px";
        UiPanel.fontSize = "14px";
        UiPanel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
        UiPanel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
        advancedTexture.addControl(UiPanel);

        //左ボタン
        var leftButton = BABYLON.GUI.Button.CreateSimpleButton("leftBut", "left");
        leftButton.paddingLeft = "10px";
        leftButton.width = "100px";
        leftButton.height = "50px";
        leftButton.cornerRadius = 5;
        leftButton.color = "white";
        leftButton.background = "black";
        leftButton.onPointerDownObservable.add(()=> {
            text.text = "左ぼたん \nが押されました";        
            box.position.x = box.position.x - 1;


        });
        UiPanel.addControl(leftButton);
    
        //前進ボタン
        var forwardButton = BABYLON.GUI.Button.CreateSimpleButton("forwardBut", "forward");
        forwardButton.paddingLeft = "30px";
        forwardButton.paddingTop = "-50px";
        forwardButton.paddingBottom = "50px";
        forwardButton.paddingRight = "-20px";
        forwardButton.width = "100px";
        forwardButton.height = "50px";
        forwardButton.cornerRadius = 5;
        forwardButton.color = "white";
        forwardButton.background = "black";
        forwardButton.onPointerDownObservable.add(()=> {
            text.text = "前進ぼたん \nが押されました";
            box.position.z = box.position.z + 1;
        });
        UiPanel.addControl(forwardButton);

    
        //後退ボタン
        var backwardButton = BABYLON.GUI.Button.CreateSimpleButton("backwardBut", "backward");
        backwardButton.paddingLeft = "-70px";
        backwardButton.paddingTop = "50px";
        backwardButton.paddingBottom = "-50px";
        backwardButton.paddingRight = "30px";
        backwardButton.width = "50px";
        backwardButton.height = "50px";
        backwardButton.cornerRadius = 5;
        backwardButton.color = "white";
        backwardButton.background = "black";
        backwardButton.onPointerDownObservable.add(()=> {
            text.text = "後退ぼたん \nが押されました";
            box.position.z = box.position.z - 1;

        });
        UiPanel.addControl(backwardButton);
    
        //右ボタン
        var rightButton = BABYLON.GUI.Button.CreateSimpleButton("rightButt", "right");
        rightButton.paddingRight = "10px";
        rightButton.width = "100px";
        rightButton.height = "50px";
        rightButton.cornerRadius = 5;
        rightButton.color = "white";
        rightButton.background = "black";
        rightButton.onPointerDownObservable.add(()=> {
            text.text = "右ぼたん \nが押されました";
            box.position.x = box.position.x + 1;
        });
        UiPanel.addControl(rightButton);

    
    return scene;
};

var engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
var scene = createScene();

engine.runRenderLoop(function () {
    if (scene) {
        scene.render();
    }
});

// Resize
window.addEventListener("resize", function () {
    engine.resize();
});
            
          
!
999px

Console