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

              
                <!doctype html>
<html>

<head>
  <title>HW3a GUI</title>
  <style>
    body {
      max-width: 100%;
    }

    /* feel free to style the canvas any way you want. If you want it to
      use the entire window, set width: 100% and height: 100%. */

    canvas {
      width: 800px;
      height: 500px;
      display: block;
      margin: 10px auto;
    }
  </style>
</head>

<body>

  <h1>HW3a GUI</h1>

  <p>Use this GUI to find the right camera parameters for the target views</p>

</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                // We always need a scene.
var scene = new THREE.Scene();

var barn = TW.createWireBarn(10,10,20);

scene.add(barn);


// ====================================================================

// object to store the desired camera parameters

var cameraParams = {
    near: 1,
    far: 200,
    fov: 45,                // degrees
    aspectRatio: 800/500,   // from dimensions of the canvas, see CSS
    atX: 0,
    atY: 0,
    atZ: 0,
    eyeX: 0,
    eyeY: 0,
    eyeZ: 20,
    upX: 0,
    upY: 1,
    upZ: 0
};

// setupCamera() function creates and returns a camera with the desired parameters

function setupCamera (cameraParameters) {
    // set up an abbreviation 
    var cp = cameraParameters;
    // create an initial camera with the desired shape
    var camera = new THREE.PerspectiveCamera(cp.fov, cp.aspectRatio, cp.near, cp.far);
    // set the camera location and orientation
    camera.position.set(cp.eyeX, cp.eyeY, cp.eyeZ);
    camera.up.set(cp.upX, cp.upY, cp.upZ);
    camera.lookAt(new THREE.Vector3(cp.atX, cp.atY, cp.atZ));
    return camera;
}

// ====================================================================

// We always need a renderer

var renderer = new THREE.WebGLRenderer();

TW.mainInit(renderer,scene);

// ================================================================

// create camera, add to scene, and render scene with new camera

var camera = setupCamera(cameraParams);
scene.add(camera);

function render() {
    // a render function; assume global variables scene, renderer, and camera
    renderer.render(scene,camera);
}
render();

// create a GUI to explore camera parameters

function redoCamera() {
    scene.remove(camera);
    camera = setupCamera(cameraParams);
    scene.add(camera)
    render();
}

var gui = new dat.GUI();
gui.add(cameraParams,'fov',30,90).step(5).onChange(redoCamera);
gui.add(cameraParams,'eyeX',0,60).step(1).onChange(redoCamera);
gui.add(cameraParams,'eyeY',0,60).step(1).onChange(redoCamera);
gui.add(cameraParams,'eyeZ',0,60).step(1).onChange(redoCamera);
//gui.add(cameraParams,'atX',-10,10).onChange(redoCamera);
//gui.add(cameraParams,'atY',-10,10).onChange(redoCamera);
//gui.add(cameraParams,'atZ',-20,0).onChange(redoCamera);
gui.add(cameraParams,'upX',-3,3).step(1).onChange(redoCamera);
gui.add(cameraParams,'upY',-3,3).step(1).onChange(redoCamera);
gui.add(cameraParams,'upZ',-3,3).step(1).onChange(redoCamera);


              
            
!
999px

Console