Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <script src="https://cdn.jsdelivr.net/npm/aframe@1.4.1/dist/aframe-master.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/aframe-environment-component@1.3.2/dist/aframe-environment-component.min.js"></script>
<script>
  if (!window.__extendAnimationLoop) {
    window.__extendAnimationLoop = () => {};
  }
  AFRAME.registerSystem("extend-animation-loop", {
    tick: function(time, timeDelta) {
      window.__extendAnimationLoop(time, timeDelta);
    },
  });
</script>
<script src="https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@2.0.0/lib/three-vrm.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@verseengine/verse-three@1.0.7/dist/index.min.js"></script>

<a-scene environment="ground: flat" renderer="colorManagement: true;">
  <a-entity id="player">
    <a-entity id="headOffset">
      <a-entity id="head" camera position="0 1.6 0"></a-entity>
    </a-entity>
  </a-entity>
  <a-box class="wall" color="#FF6347" position="-2 0 -5" side="double" depth="2" height="4" width="5"></a-box>
  <a-box class="ground" color="#9ACD32" position="2 0.25 -4" side="double" depth="2" height="0.5" width="5"></a-box>
  <a-box class="ground" color="#9ACD32" position="4 0.75 -4" side="double" depth="2" height="0.5" width="5"></a-box>

</a-scene>
<template id="gui2d-slots">
  <button slot="after" class="custom-button" id="toggle-fps">
    <!-- iconoir https://github.com/iconoir-icons/iconoir/blob/main/LICENSE -->
    <svg width="24px" height="24px" stroke-width="1" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor">
      <path d="M15 12v4.4a.6.6 0 01-.6.6H3.6a.6.6 0 01-.6-.6V7.6a.6.6 0 01.6-.6h10.8a.6.6 0 01.6.6V12zm0 0l5.016-4.18a.6.6 0 01.984.461v7.438a.6.6 0 01-.984.46L15 12z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
    </svg>
  </button>
</template>
<div style="position: fixed; left: 0; top: 0; z-index: 1">
  <a href="https://verseengine.cloud/"><img style="height: 35px" src="https://verseengine.cloud/images/logo.svg" alt="Verse Engine - Web-based Metaverse Engine on P2P overlay network" /></a>
</div>
              
            
!

CSS

              
                html,
body {
  overscroll-behavior-y: none;
}
body {
  margin: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
canvas {
  user-select: none;
  -webkit-user-select: none;
}
.a-enter-ar {
  display: none;
}
.custom-button > svg {
  width: 1.5rem;
  height: 1.5rem;
}

              
            
!

JS

              
                (() => {
  const { VerseThree, THREE } = window;
  const VERSE_WASM_URL =
    "https://cdn.jsdelivr.net/npm/@verseengine/verse-three@1.0.7/dist/verse_core_bg.wasm";
  const ENTRANCE_SERVER_URL = "https://entrance.verseengine.cloud";
  const ANIMATION_MAP = {
    idle: "https://static.verseengine.cloud/codepen/animation/idle.fbx",
    walk: "https://static.verseengine.cloud/codepen/animation/walk.fbx"
  };
  const range = (n) => [...Array(n).keys()];
  const PRESET_AVATARS = [
    ...range(3).map((i) => `f${i}`),
    ...range(3).map((i) => `m${i}`)
  ].map((n) => ({
    thumbnailURL: `https://static.verseengine.cloud/codepen/avatar/${n}.png`,
    avatarURL: `https://static.verseengine.cloud/codepen/avatar/${n}.vrm`
  }));
  const DEFAULT_AVATAR_URL =
    PRESET_AVATARS[Math.floor(Math.random() * PRESET_AVATARS.length)].avatarURL;
  const ICE_SERVERS = [
    {
      urls: "stun:stun.l.google.com:19302"
    },
    {
      urls: "stun:stun1.l.google.com:19302"
    }
  ];

  async function waitForAframeLoad(scene) {
    if (scene.hasLoaded) {
      return;
    }
    return new Promise((resolve) => scene.addEventListener("loaded", resolve));
  }

  main();

  function main() {
    if (document.readyState === "loading") {
      document.addEventListener("DOMContentLoaded", _main);
    } else {
      _main();
    }
  }

  async function _main() {
    const scene = document.querySelector("a-scene");
    await waitForAframeLoad(scene);

    let collisionObjects = [];
    let teleportTargetObjects = [];
    let interactableObjects = [];
    let collisionBoxes = [];

    const updateCollisionBoxes = () => {
      collisionBoxes.length = 0;
      [...collisionObjects, ...teleportTargetObjects].map((el) => {
        el.traverse((c) => {
          if (!c.isMesh) {
            return;
          }
          collisionBoxes.push(new THREE.Box3().setFromObject(c));
        });
      });
    };
    const queryObjects = (q) =>
      [...scene.querySelectorAll(q)]
        .map((v) => v.object3D)
        .filter((v) => v.visible);
    const updateCollisionObjects = () => {
      collisionObjects = queryObjects(".collider,.wall");
      teleportTargetObjects = queryObjects(".ground,.environmentGround");
      interactableObjects = queryObjects(".clickable");
      updateCollisionBoxes();
    };
    scene.object3D.updateMatrixWorld();
    updateCollisionObjects();

    const adapter = new VerseThree.AFrameEnvAdapter(
      scene,
      document.getElementById("headOffset").object3D,
      document.getElementById("player").object3D,
      () => collisionBoxes,
      () => collisionObjects,
      () => teleportTargetObjects,
      {
        getInteractableObjects: () => interactableObjects,
        onSelectDown: (o, _point) => {
          if (!o.el || !o.el.classList.contains("clickable")) {
            return;
          }
          o.el.emit("click", {
            intersectedEl: o.el
          });
        },
        isLowSpecMode: true
      }
    );
    const mayBeLowSpecDevice = VerseThree.isLowSpecDevice();
    const res = await VerseThree.start(
      adapter,
      scene.object3D,
      VERSE_WASM_URL,
      ENTRANCE_SERVER_URL,
      DEFAULT_AVATAR_URL,
      ANIMATION_MAP,
      ICE_SERVERS,
      {
        maxNumberOfPeople: mayBeLowSpecDevice ? 8 : 16,
        maxNumberOfParallelFileTransfers: mayBeLowSpecDevice ? 1 : 4,
        presetAvatars: PRESET_AVATARS,
        gui2dSlots: document.querySelector("#gui2d-slots").innerHTML
      }
    );

    setupToggleFPS(adapter, res.player);

    // @see index.html/extend-animation-loop
    window.__extendAnimationLoop = (_time, timeDelta) => {
      res.tick(timeDelta / 1000);
    };
  }

  function setupToggleFPS(adapter, player) {
    let isFirstPerson = true;
    const f = () => {
      if (isFirstPerson) {
        player.avatar.setFirstPersonMode([adapter.getCamera()]);
        adapter.getHead().position.set(0, player.avatar.getHeadHeight(), 0);
        adapter.getHead().parent.rotation.set(0, 0, 0);
      } else {
        player.avatar.setThirdPersonMode([adapter.getCamera()]);
        adapter.getHead().position.set(0.0, player.avatar.getHeadHeight() + 0.2, 2.0);
        adapter.getHead().parent.rotation.set(-0.2, 0, 0);
      }
    };

    adapter.addAvatarChangedListener((avatar) => {
      if (!adapter.getRenderer().xr.isPresenting) {
        f();
      }
    });

    document.querySelector("#toggle-fps").addEventListener(
      "click",
      () => {
        isFirstPerson = !isFirstPerson;
        f();
      },
      false
    );
  }
})();

              
            
!
999px

Console