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

              
                
              
            
!

CSS

              
                html,
body {
  width: 100%;
  height: 100%;
  background: hsl(360, 0%, 100%);
}
body {
  margin: 0;
  overflow: hidden;
}
canvas {
  width: 100%;
  height: 100%;
}

              
            
!

JS

              
                var container = document.querySelector("body"),
  w = container.clientWidth,
  h = container.clientHeight,
  scene = new THREE.Scene(),
  camera = new THREE.PerspectiveCamera(25, w / h, 0.001, 1000),
  controls = new THREE.TrackballControls(camera, container),
  renderConfig = { antialias: true, alpha: true },
  renderer = new THREE.WebGLRenderer(renderConfig);

renderer.gammaInput = true;
renderer.gammaOutput = true;

controls.target = new THREE.Vector3(0, 0.1, 0.75);
controls.panSpeed = 0.4;
camera.position.set(0, 0, 7.5);
camera.lookAt(new THREE.Vector3(0, 0, 0));
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(w, h);
container.appendChild(renderer.domElement);

let snake,
  ring,
  geodesic,
  spring,
  puck,
  icosphere,
  diamond,
  wow,
  sphere1,
  sphere2,
  sphere3,
  tube1,
  tube2,
  light1,
  light2;

window.addEventListener("resize", function () {
  w = container.clientWidth;
  h = container.clientHeight;
  camera.aspect = w / h;
  camera.updateProjectionMatrix();
  renderer.setSize(w, h);
});

function render(a) {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
  controls.update();
}

const loader = new THREE.GLTFLoader();

function loadScene() {
  loader.load(
    "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1385231/wow.glb",
    function (gltf) {
      scene.add(gltf.scene);
      assignObjects();
      addMaterials();
      startAnimations();
    }
  );
}

function assignObjects() {
  snake = scene.getObjectByName("Plane004");
  ring = scene.getObjectByName("Torus");
  geodesic = scene.getObjectByName("geodesic");
  spring = scene.getObjectByName("spring");
  puck = scene.getObjectByName("Cylinder");
  icosphere = scene.getObjectByName("Icosphere");
  diamond = scene.getObjectByName("Cube");
  wow = scene.getObjectByName("O");
  tube1 = scene.getObjectByName("Cylinder001");
  tube2 = scene.getObjectByName("Cylinder003");
  sphere1 = scene.getObjectByName("Sphere");
  sphere2 = scene.getObjectByName("Sphere001");
  sphere3 = scene.getObjectByName("Sphere002");

  light1 = scene.getObjectByName("light1");
  light2 = scene.getObjectByName("light2");
}

function addMaterials() {
  var blue = new THREE.Color("hsl(228, 100%, 50%)");
  var green = new THREE.Color("hsl(94, 92%, 50%)");
  var red = new THREE.Color("hsl(6,80%,35%)");
  var purple = new THREE.Color("hsl(251, 95%, 70%)");
  var carolinaBlue = new THREE.Color("hsl(211, 97%, 55%)");
  var lightBlue = new THREE.Color("hsl(190, 100%, 70%)");
  var gray = new THREE.Color("hsl(220, 84%, 76%)");
  var bronze = new THREE.Color("hsl(33, 60%, 50%)");

  var bronzeMid = new THREE.MeshStandardMaterial({
    color: bronze,
    roughness: 0.5
  });

  var carolinaBlueDiffuse = new THREE.MeshStandardMaterial({
    color: carolinaBlue,
    roughness: 0.67
  });

  var lightBlueDiffuse = new THREE.MeshStandardMaterial({
    color: lightBlue,
    roughness: 0.65
  });
  var lightBlueShiny = new THREE.MeshStandardMaterial({
    color: lightBlue,
    roughness: 0.3
  });

  var greenDiffuse = new THREE.MeshStandardMaterial({
    color: green,
    roughness: 0.65
  });

  var greenShiny = new THREE.MeshStandardMaterial({
    color: green,
    roughness: 0.3
  });

  var grayDiffuse = new THREE.MeshStandardMaterial({
    color: gray,
    roughness: 0.6
  });

  var purpleDiffuse = new THREE.MeshStandardMaterial({
    color: purple,
    roughness: 0.6
  });

  var redDiffuse = new THREE.MeshStandardMaterial({
    color: red,
    roughness: 0.6
  });

  var blueDiffuse = new THREE.MeshStandardMaterial({
    color: blue,
    roughness: 0.6
  });

  wow.material = carolinaBlueDiffuse;
  wow.children.forEach((child) => (child.material = carolinaBlueDiffuse));

  ring.material = blueDiffuse;
  diamond.material = lightBlueShiny;
  puck.material = grayDiffuse;
  sphere1.material = blueDiffuse;
  sphere2.material = redDiffuse;
  sphere3.material = purpleDiffuse;
  geodesic.material = bronzeMid;
  snake.material = greenDiffuse;
  icosphere.material = purpleDiffuse;
  spring.material = redDiffuse;
  tube1.material = greenShiny;
  tube2.material = redDiffuse;
}

loadScene();
addLights();

function addLights() {
  var pointLight = new THREE.PointLight("#c2e8ff", 0.6, 100);
  pointLight.position.set(5, 5, 5);
  pointLight.name = "light1";
  scene.add(pointLight);
  var pointLightHelper = new THREE.PointLightHelper(pointLight, 1, "#ff0000");
  // scene.add(pointLightHelper);
  var pointLight = new THREE.PointLight("#fff0b8", 1, 100);
  pointLight.position.set(-5, 5, 5);
  pointLight.name = "light2";
  scene.add(pointLight);
  var pointLightHelper = new THREE.PointLightHelper(pointLight, 1, "#ff0000");
  // scene.add(pointLightHelper);

  var light = new THREE.HemisphereLight(0xffd1fd, 0x555555, 2);
  scene.add(light);
}

function startAnimations() {
  var orbitGroup = new THREE.Object3D();
  orbitGroup.add(tube1, tube2);
  scene.add(orbitGroup);

  gsap.to(orbitGroup.rotation, 8, { z: Math.PI * 2, ease: "none", repeat: -1 });

  gsap.to(sphere3.position, 10, {
    y: "-.6",
    yoyo: true,
    repeat: -1,
    ease: "power2.inOut"
  });

  gsap.to(geodesic.rotation, 9, {
    y: Math.PI * 2,
    x: Math.PI,
    repeat: -1,
    ease: "none"
  });
  gsap.to(wow.position, 5, {
    z: 2,
    repeat: -1,
    ease: "power2.inOut",
    yoyo: true
  });

  gsap.to(wow.scale, 5, {
    z: 1.3,
    x: 1.3,
    y: 1.3,
    repeat: -1,
    ease: "power2.inOut",
    yoyo: true
  });

  gsap.to(snake.rotation, 7, { z: Math.PI * 2, repeat: -1, ease: "none" });

  gsap.to(spring.rotation, 9, {
    y: Math.PI * 2,

    repeat: -1,
    ease: "none"
  });

  var springStartScale = 0.02;
  var springEndScale = 0.03;
  gsap.fromTo(
    spring.scale,
    3,
    { x: springStartScale, y: springStartScale, z: springStartScale },
    {
      x: springEndScale,
      y: springEndScale,
      z: springEndScale,
      repeat: -1,
      ease: "bounce.inOut",
      yoyo: true
    }
  );

  gsap.to(puck.position, 2, {
    y: 1.1,
    repeat: -1,
    ease: "power2.inOut",
    yoyo: true
  });

  gsap.to(icosphere.scale, 4, {
    y: 0.2,
    x: 0.2,
    z: 0.2,
    repeat: -1,
    yoyo: true,
    ease: "power3.inOut",
    delay: 2,
    repeatDelay: 2
  });

  var diamondGroup = new THREE.Object3D();
  diamond.position.set(0, 0, 0);
  diamond.rotation.set(0, 0, 0);
  diamondGroup.add(diamond);
  scene.add(diamondGroup);
  diamondGroup.position.set(
    -0.10399914532899857,
    -0.6172620058059692,
    -0.6458587646484375
  );
  diamondGroup.rotation.x = -0.3;
  diamondGroup.rotation.z = -0.2;
  gsap.fromTo(
    diamond.rotation,
    9,
    { x: 0, y: 0, z: 0 },
    { y: Math.PI * 2, repeat: -1, ease: "none" }
  );

  gsap.to(light1.position, 6, {
    x: -5,
    y: 3,
    repeat: -1,
    yoyo: true,
    ease: "power2.inOut"
  });
  gsap.to(light2.position, 6, {
    x: 5,
    y: 3,
    repeat: -1,
    yoyo: true,
    ease: "power2.inOut"
  });
}

render();

              
            
!
999px

Console