Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

HTML

              
                <html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>ShapeDiver API - First Example</title>
    <!-- ShapeDiver Viewer -->
    <script src="https://viewer.shapediver.com/v2/2.23.0/sdv.concat.min.js"></script>
  </head>

  <body>
    <!-- ShapeDiver Viewer Main Container -->
    <div id='sdv-container' style="width:100%;height:300px;">
    </div>
    <div>
      <label for="length">Length</label>
      <input id="length" type="range" min="120" max="216" step="1" value="162" onchange="changeLength(this.value)" oninput="this.nextElementSibling.value = this.value">
      <output>162</output>
      <br>
       <label for="depth">Depth</label>
       <input id="depth" type="range" min="109" max="133" step="1" value="133" onchange="changeDepth(this.value)" oninput="this.nextElementSibling.value = this.value">
      <output>133</output>
      <br>
      <button onclick="api.scene.camera.zoomAsync();">
    Recenter Camera
  </button>
      <button onclick="exportFile();">
    Download 3D model
  </button>
      <button onclick="getData();">
    Get Data
  </button>
      <span id="dataresult"></span>
    </div>
  </body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                // This example is compatible with the following ShapeDiver model: https://app.shapediver.com/m/shapediver-api-demo-first-example

// ShapeDiver Viewer Initialisation
var initSdvApp = function(/*event*/) {
  // Settings can be defined here, or as attributes of the viewport container. Settings defined here take precedence.
  let _container = document.getElementById('sdv-container'); 
  let settings = {
    container: _container,
    ticket: "85d9977f5426033e058a60c8b81c2c91d331d5eec7bdfed66d354132539d4efb0d01bd6e5d7bc61bc8894b820fff1922d2a2e7e6b7f5883d244f93f0c9ce73daa540ccd7b6d1a1d9ccc40307c3549ff3bbce1a7e902ac438abb53b472d73f2fd2578881f8846e73c4af238f34b9725c41232a2e3129d-d34ace0dbe577c6152ee63654b9e807c",
    modelViewUrl: "eu-central-1",
    brandedMode: true
  };
  // See https://viewer.shapediver.com/v2/2.14.0/doc/SDVApp.ParametricViewer.html for all settings available via the constructor.
  window.api = new SDVApp.ParametricViewer(settings);
};

// there is a slight chance that loading has been completed already
if (document.readyState === "loading") {
  document.addEventListener("DOMContentLoaded", initSdvApp, false);
} else {
  initSdvApp();
}

function changeLength(val) {
  api.parameters.updateAsync({name: "Couch Length (cm)", value: val});
}
function changeDepth(val) {
  api.parameters.updateAsync({name: "Depth (cm)", value: val});
}

function getData() {
  var res = api.scene.getData();
  document.getElementById('dataresult').innerHTML=res.data[0].name + ": " + res.data[0].data;
}

function exportFile() {
  api.exports.requestAsync({name: "Download 3D Model"}).then(
    function(response){ 
      let link = response.data.content[0].href;
      console.log("Use this link to download the file: " + link);
      window.location=link;
    }
  );
}



              
            
!
999px

Console