cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              body{
  overflow:hidden;
  display:flex;
  justify-content:center;
  align-items:center;
}

progress{
  position:absolute;
}
            
          
!
            
              window.addEventListener("load", loadGltf, false);
window.addEventListener("resize", onWindowResize, false);
const progressBar = document.querySelector("progress");

//store our imported glTF scene when loaded successfully
const gltfStore = {};

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x00804d);

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

//camera
const camera = new THREE.PerspectiveCamera(
  75,
  window.innerWidth / window.innerHeight,
  0.1,
  1000
);

camera.position.set(0, 20, 20);
camera.lookAt(0, 0, 5);

//re-establish camera view on window resize
function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}

//lighting
const lightFill = new THREE.PointLight(0xffffff, 1, 500);
lightFill.position.set(0, 20, 20);
scene.add(lightFill);

const lightKey = new THREE.PointLight(0x00804d, 1, 500);
lightKey.position.set(20, 0, 20);
scene.add(lightKey);

const loader = new THREE.GLTFLoader();

function loadGltf() {
  loader.load(
    "https://s3-us-west-2.amazonaws.com/s.cdpn.io/96252/codepen-castlescene.glb",
    //onLoad
    function(gltf) {
      scene.add(gltf.scene);
      //set material emissive to 0
      gltf.scene.children[0].material.emissive = 0;
      gltfStore.scene = gltf.scene;
      progressBar.style.display = "none";
    },
    //onProgress
    function(xhr) {
      //update progress bar with load progress
      progressBar.value = xhr.loaded;
    },
    //onError
    function(error) {
      console.log("Unable to load glTF");
    }
  );

  function animate() {
    requestAnimationFrame(animate);
    //slowly rotate the first child (the castle object)
    if (gltfStore.scene) {
      gltfStore.scene.children[0].rotation.y += 0.005;
    }
    renderer.render(scene, camera);
  }

  animate();
}

            
          
!
999px
Loading ..................

Console