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」からのコードを参考にして
//Babylon.js のSound再生機能をテストしています
//
//移動するMeshに設定されたサウンドの音の大きさが、Meshからの距離によって変化するようです
//Playgroundではカメラを移動させて、さらにMeshからの距離を変えて音の大小の変化を確認できるようですが、jsdo.itではなぜかカメラ移動できなくなってます。。。
//追記→Fullscreen画面では↑↓←→ボタンで動かせるようです
//
//サウンドはループして再生され続けます
//Playgroundのサイトから直接wavファイルを読み込んでいるので、再生されるまで少し時間がかかるかもしれません
//
//
//以下の「Babylon.js Playground」のコードをそのまま流用させてもらいました
//
//Sound on mesh
//https://playground.babylonjs.com/indexStable.html#EDVU95#0
//

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

var createScene = function () {
    // This creates a basic Babylon Scene object (non-mesh)
    var scene = new BABYLON.Scene(engine);

    // Lights
    var light0 = new BABYLON.DirectionalLight("Omni", new BABYLON.Vector3(-2, -5, 2), scene);
    var light1 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(2, -5, -2), scene);

    // Need a free camera for collisions
    var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, -8, -20), scene);
    camera.attachControl(canvas, true);

    //Ground
    var ground = BABYLON.Mesh.CreatePlane("ground", 400.0, scene);
    ground.material = new BABYLON.StandardMaterial("groundMat", scene);
    ground.material.diffuseColor = new BABYLON.Color3(1, 1, 1);
    ground.material.backFaceCulling = false;
    ground.position = new BABYLON.Vector3(5, -10, -15);
    ground.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);

    //Simple crate
    var box = BABYLON.Mesh.CreateBox("crate", 2, scene);
    box.material = new BABYLON.StandardMaterial("Mat", scene);
    box.material.diffuseTexture = new BABYLON.Texture("https://playground.babylonjs.com/textures/crate.png", scene);
    box.position = new BABYLON.Vector3(10, -9, 0);

    // Create and load the sound async
    var music = new BABYLON.Sound("Violons", "https://rawcdn.githack.com/BabylonJS/Babylon.js/824824036e157cfde96e881ca09c424d9b16cc4a/Playground/sounds/violons11.wav", scene, function () {
        // Call with the sound is ready to be played (loaded & decoded)
        // TODO: add your logic
        console.log("Sound ready to be played!");
    }, { loop: true, autoplay: true });

    // Sound will now follow the mesh position
    music.attachToMesh(box);

    //Set gravity for the scene (G force like, on Y-axis)
    scene.gravity = new BABYLON.Vector3(0, -0.9, 0);

    // Enable Collisions
    scene.collisionsEnabled = true;

    //Then apply collisions and gravity to the active camera
    camera.checkCollisions = true;
    camera.applyGravity = true;

    //Set the ellipsoid around the camera (e.g. your player's size)
    camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);

    //finally, say which mesh will be collisionable
    ground.checkCollisions = true;

    var alpha = 0;

    scene.registerBeforeRender(function () {
        // Moving the box will automatically move the associated sound attached to it
        box.position = new BABYLON.Vector3(Math.cos(alpha) * 30, -9, Math.sin(alpha) * 30);
        alpha += 0.01;
    });

    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