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.

+ add another resource


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


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.


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.

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.


                <button id="add-geom">Add Geometry</button>
<div id="viewer"></div>



html {
  margin: 0;
  padding: 0;
  height: 100vh;

button#add-geom {
  position: absolute;
  left: 1em;
  top: 1em;
  z-index: 2;



                function addGeometryV1(modelBuilder, dbId) {
  const boxGeometry = new THREE.BufferGeometry().fromGeometry(new THREE.BoxGeometry(10, 10, 10));
  const boxMaterial = new THREE.MeshPhongMaterial({ color: new THREE.Color(1, 0, 0) });
  const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
  boxMesh.matrix = new THREE.Matrix4().compose(
    new THREE.Vector3(-10, -10, 0),
    new THREE.Quaternion(0, 0, 0, 1),
    new THREE.Vector3(1, 1, 1)
  boxMesh.dbId = dbId;

function addGeometryV2(modelBuilder, dbId) {
  const sphereGeometry = new THREE.BufferGeometry().fromGeometry(new THREE.SphereGeometry(5, 8, 8));
  const sphereMaterial = new THREE.MeshPhongMaterial({ color: new THREE.Color(0, 1, 0) });
  const sphereTransform = new THREE.Matrix4().compose(
    new THREE.Vector3(0, 0, 0),
    new THREE.Quaternion(0, 0, 0, 1),
    new THREE.Vector3(1, 1, 1)
  const sphereFragId = modelBuilder.addFragment(sphereGeometry, sphereMaterial, sphereTransform);
  modelBuilder.changeFragmentsDbId(sphereFragId, dbId);

function addGeometryV3(modelBuilder, dbId) {
  const cylinderGeometry = new THREE.BufferGeometry().fromGeometry(new THREE.CylinderGeometry(5, 5, 10));
  const cylinderMaterial = new THREE.MeshPhongMaterial({ color: new THREE.Color(0, 0, 1) });
  const cylinderTransform = new THREE.Matrix4().compose(
    new THREE.Vector3(+10, +10, 0),
    new THREE.Quaternion(0, 0, 0, 1),
    new THREE.Vector3(1, 1, 1)
  modelBuilder.addMaterial('MyCustomMaterial', cylinderMaterial);
  const cylinderGeomId = modelBuilder.addGeometry(cylinderGeometry);
  const cylinderFragId = modelBuilder.addFragment(cylinderGeomId, 'MyCustomMaterial', cylinderTransform);
  modelBuilder.changeFragmentsDbId(cylinderFragId, dbId);

// Quick setup using the forgist client-side utils
// (
forgist.setup(document.getElementById('viewer'), 2).then(viewer => {
  const button = document.getElementById('add-geom');
  button.addEventListener('click', async function () {
    const sceneBuilder = await viewer.loadExtension('Autodesk.Viewing.SceneBuilder');
    const modelBuilder = await sceneBuilder.addNewModel({ conserveMemory: false, modelNameOverride: 'My Custom Model' }); 
    addGeometryV1(modelBuilder, 123456);
    addGeometryV2(modelBuilder, 123456);
    addGeometryV3(modelBuilder, 456789);
    viewer.fitToView([123456], modelBuilder.model);
    button.setAttribute('disabled', 'true');