addBox() - Create 3D Boxes


How to create 3D Boxes with 3Dmol.js addBox() methods?



viewer.addBox() method in the $3Dmol.GLViewer class allows you to create 3D box objects. Here is the signature of the addBox() method:

{$3Dmol.GLViewer} addBox({BoxSpec} spec) -> {$3Dmol.GLShape}

Here is an HTML code example, Draw-Box.html, that uses the addBox() method:

<script src="/3Dmol-min.js"></script>
.mol-container {width: 400px; height: 400px; position: relative;}
  <div id="container-01" class="mol-container"></div>
$(function() {
  let element = $('#container-01');
  let config = { backgroundColor: 'grey' };
  let viewer = $3Dmol.createViewer( element, config );
  viewer.addBox({center:{x:0,y:0,z:0},dimensions: {w:3,h:4,d:2},color:'magenta'});
  viewer.rotate(45, {x:1,y:1,z:1});

This example HTML code will display a 3D box as shown below:

3Dmol.js Example - Draw Box
3Dmol.js Example - Draw Box


addLabel() - Create Text Labels

GLViewer Class and Instance Methods

3Dmol.js Classes and API

⇑⇑ 3Dmol.js FAQ

2023-09-07, 237🔥, 0💬