123

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE 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 Viewer v2</title>
  
  <!-- ShapeDiver Viewer -->
  <script defer src="https://viewer.shapediver.com/v2/2.15.0/sdv.concat.min.js"></script>
  <link rel='stylesheet' type='text/css' href='https://viewer.shapediver.com/v2/2.15.0/sdv.css'>
  
  <!-- ShapeDiver Viewer Controls and Export Modal Dialog Dependencies -->
  <!-- UIkit CSS -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/css/uikit.min.css"
    integrity="sha256-sO/kKFCHPL4rhYHDyHC2dwGlaIBttifOfQ0ZaGLAheo=" crossorigin="anonymous" />
  <!-- UIkit JS -->
  <script defer src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/js/uikit.min.js"
    integrity="sha256-jN++RwBoYassp9qTuZDfQuptszFdL1Pm4dKZWS5KjjY=" crossorigin="anonymous"></script>
  <script defer src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/js/uikit-icons.min.js"
    integrity="sha256-6pktS+jePPdXx9oCn8r4hS5jR1eq0Ry7vbifYtG0LDU=" crossorigin="anonymous"></script>
  
</head>

<body>
  <!-- ShapeDiver Viewer Main Container -->
  <div id='sdv-container' class='shapediver-container-flex shapediver-container-fullsize'
    sdv-fullscreen="true">
    <!-- ShapeDiver Viewer Settings Controls Container -->
    <div id='sdv-container-settings' class='shapediver-settings-flex' style='display: none;'></div>
    <!-- ShapeDiver Viewer Viewport Container -->
    <div class='shapediver-viewport-flex'>
      <div id='sdv-container-viewport' class='shapediver-container-fullsize' style='opacity: 0;' 
           logginglevel=0 messagelogginglevel=2>
      </div>
      <!-- The loading icon will be created here -->
    </div>
    <!-- ShapeDiver Viewer Parameter Controls Container -->
    <div id='sdv-container-controls' class='shapediver-controls-flex' style='display: none;'></div>
  </div>
</body>
  
</html>

            
          
!
            
              /* 
 * This example demonstrates how to add custom controls to the parameter widget of the ShapeDiver Viewer. 
 */

/* 
 * 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 settings = {
    ticket: "2c4fee2a0d9d180ad450b3ec972b088f5ec73f397bff89083623200b2f63bca0d6012f5ded54dc489e3b9ba9923f0caaef289e5c617184246a6788011ca424fafb2a9b13d8f4f767494e4de4ab4a4388376fb1694fd36e8f8198d344df79e1f5df70812492801d88d2c0102989e6f506892546afdc9a-80de84ce75080789b5bf54d4abfc5f07",
    modelViewUrl: "eu-central-1",
    showControlsInitial: true,
    showSettingsInitial: false,
  };
  // 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 are various controls types. Available types are as follows, which can be set by enum ParameterType ( api.apps.controls.parameterTypes ) or simple string.
  // ParameterType.BUTTON     | 'button',
  // ParameterType.CHECKBOX   | 'checkbox',
  // ParameterType.CHECKLIST  | 'checklist',
  // ParameterType.COLOR      | 'color',
  // ParameterType.DROPDOWN   | 'dropdown',
  // ParameterType.FILE       | 'file',
  // ParameterType.GROUP      | 'group',
  // ParameterType.MODAL      | 'modal',
  // ParameterType.SLIDER     | 'slider'
  // ParameterType.STATICHTML | 'statichtml',
  // ParameterType.STRING     | 'string',
  // ParameterType.VECTOR3    | 'vector3',


  // All parameters have order property of type number, which sorts parameters in ascending order.

  // In case of 'button' parameter type and update need to be defined. If not defined error will be thrown. 
  // Buttons are affected by type,update,name and order properties. Other properties are ignored.
  // Update call back function has boolean as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.BUTTON,
    update: function(booleanVal) { console.log(booleanVal); },
    name: 'Button test',
    order: 1
  });

  // In case of 'checkbox' parameter type and update need to be defined.
  // Checkbox types are affected by type,update,name and order properties. Other properties are ignored.
  // Update call back function has boolean as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.CHECKBOX,
    update: function(booleanVal) { console.log(booleanVal); },
    name: 'Checkbox test',
    order: 2
  });

  // In case of 'checklist' parameter type, choices and update need to be defined.
  // Choices parameter needs to be of type array, otherwise error is thrown.
  // Value parameter is optional and is defined as array of preselected values.
  // Checklist types are affected by type,update,name,choices, value and order properties. Other properties are ignored.
  // Update call back function has selected values array as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.CHECKLIST,
    update: function(selectedValuesArray) { console.log(selectedValuesArray); },
    name: 'Checkbox test',
    choices: ['Joe', 'Jane', 'Mark'],
    value: ['Jane', 'Mark'],
    order: 3
  });

  // In case of 'color' parameter type and update need to be defined.
  // Color types are affected by type,update,name, value and order properties. Other properties are ignored.
  // Update call back function has color in 'rgb' format as parameter. For example for red 'rgb(255,0,0)'
  // Color can be passed as hex format '#cc00cc', rgb format 'rgb(255,0,0)', rgba format 'rgba(255,0,0,1)',  css color name format 'blue' 
  // You can use window.api.utils.toTinyColor to parse and convert color values in various formats
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.COLOR,
    update: function(rgbColorVal) { console.log(rgbColorVal); },
    value: '#cc00cc',
    name: 'Color test',
    order: 4
  });

  // In case of 'dropdown' parameter type, choices and update need to be defined.
  // Choices parameter needs to be of type array, otherwise error is thrown.
  // Value parameter is optional and is defined according to some of corresponding values in choices array.
  // Checklist types are affected by type,update,name,choices, value and order properties. Other properties are ignored.
  // Update call back function has selected value as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.DROPDOWN,
    update: function(selecetedVal) { console.log(selecetedVal); },
    choices: ['Joe', 'Jane', 'Mark'],
    value: 'Jane',
    name: 'Dropdown test',
    order: 5
  });

  // In case of 'file' parameter, type and update need to be defined.
  // File types are affected by type,update,name, accept and order properties. Other properties are ignored.
  // Accept properties can be checked here https://www.w3schools.com/tags/att_input_accept.asp. It can be added as a single string or array of extensions.
  // Update call back function has file list as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.FILE,
    update: function(fileList) { console.log(fileList); },
    name: 'File test',
    accept: [".jpg", ".png"],
    order: 6
  });

  // In case of 'group' parameter, type and parameters need to be defined.
  // Group types are affected by type,name and order properties. Other properties are ignored.
  // parameters property is of type ParameterDefinition which corresponds to other parameters. For example parameters: [ { type: 'button' ...}, { type: 'checklist' ... }]
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.GROUP,
    name: 'Group test',
    parameters: [
      {
        type: api.apps.controls.parameterTypes.BUTTON,
        update: function(booleanVal) { console.log(booleanVal); },
        name: 'Group Button test',
        order: 3
      },
      {
        type: api.apps.controls.parameterTypes.CHECKBOX,
        update: function(booleanVal) { console.log(booleanVal); },
        name: 'Group checkbox test',
        order: 1
      },
      {
        type: api.apps.controls.parameterTypes.COLOR,
        update: function(rgbColorVal) { console.log(rgbColorVal); },
        value: 'blue',
        name: 'Group Color test',
        order: 4
      }
    ],
    order: 7
  });

  // In case of 'modal' parameters type and modalContent need to be defined.
  // Internally UIKit is being used for modal, please refer to https://getuikit.com/docs/modal to see how to use one.
  // Modal is created with shapediver_modal_${id} id such as shapediver_modal_f1b69b85-7cf5-4aaa-9f6c-b912d1e01082 
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.MODAL,
    order: 8,
    name: 'Modal test',
    modalContent: '<h2 class="uk-modal-title">Headline</h2>' 
    + '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'
    + '<p class="uk-text-right">'
    + '    <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>'
    + '    <button id="jq-test-modal-submit" class="uk-button uk-button-primary" type="button">Save</button>'
    + '</p>' 
  }).then(function(id){
    document.getElementById("jq-test-modal-submit").onclick = function(){
      UIkit.modal('#shapediver_modal_' + id).hide();
    }
  });

  // In case of 'slider' parameter type and update need to be defined. If not defined error will be thrown. 
  // Sliders are affected by type,update,name,value,min,max,step and order properties. Other properties are ignored.
  // Optional value property is of type number
  // Min, max and step correspond to min, max and step properties of html input of types 'number' and 'range'
  // Update call back function has number as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.SLIDER,
    update: function(val) { console.log(val); },
    value: 50,
    name: 'Slider test',
    min: -100,
    max: 100,
    step: 0.5,
    order: 9
  });

  // In case of 'statichtml' parameter type and content need to be defined. If not defined error will be thrown. 
  // Static html is affected by type, content and order properties. Other properties are ignored.
  // Content is any html valid string
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.STATICHTML,
    content: '<h1><span class="uk-label">Static HTML test</span></h1>',
    order: 10
  });

  // In case of 'string' parameter type and update need to be defined. If not defined error will be thrown. 
  // String is affected by type, name, value, update and order properties. Other properties are ignored.
  // Name can be any string
  // Update callback has a string as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.STRING,
    name: 'Test string',
    value: 'Joe',
    update: function(val) { console.log(val); },
    order: 11
  });

  // In case of 'vector3' parameter type and update need to be defined. If not defined error will be thrown. 
  // Vector3 is affected by type, name, value, step, min, max, update and order properties. Other properties are ignored.
  // Name can be any string
  // Min, max and step correspond to min, max and step properties of html input of type 'number'
  // Values needs to be an object with x,y,z properties. Such as { x: -5, y: 10, z: -77}
  // Update callback has an objects with x,y,z properties as parameter as parameter.
  window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.VECTOR3,
    name: 'Test vector',
    value: { x: -5, y: 17, z: -25 },
    update: function(val) { console.log(val); },
    step: 0.5,
    min: -100,
    max: 100,
    order: 12
  });
  
  // createParameter returns a promise resolving to an id, which can be used to call removeParameter
  let id = window.api.apps.controls.createParameter({
    type: api.apps.controls.parameterTypes.COLOR,
    update: function(rgbColorVal) { console.log(rgbColorVal); },
    value: 'blue',
    name: 'Another Color test',
    order: -10
  })
  .then(id => {
    console.log('Added parameter with id ' + id);
    console.log('Successfully removed parameter?', window.api.apps.controls.removeParameter(id));
  });
  
};

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

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console