Back to Demos

This demo shows how you can get and iterate through the mesh vertices.

Mesh

Axis

Clara.io demo resources:

Visit Base Scene


var sceneId = '968b8542-f94d-46f7-8b74-abb719eb1b8a';
var api = claraplayer('player');
var mesh;
var axis = 0; //axis = 0 for x, 1 for y and 2 for z
var result = document.getElementById('result');

api.sceneIO.fetchAndUse(sceneId).then(function(){
  mesh = api.scene.get({name:'Sphere', evalPlug:'PolyMesh', property:'mesh'});
  findIndex(mesh, axis);
  document.getElementById('baseScene').setAttribute('href','https://clara.io/view/'+sceneId);
});

document.getElementById('options').onchange = function(ev){
  mesh = api.scene.get({name:ev.target.value, evalPlug:'PolyMesh', property:'mesh'});
  findIndex(mesh, axis);
}

document.getElementById('axis').onchange = function(ev){
  axis = Number(ev.target.value);
  findIndex(mesh, axis);
}

function findIndex(mesh, axis){

  var vertices = mesh.positions.values;
  var maxCoord = vertices.data[0 + axis];
  var targetIndex = 0;
  for (var i=0; i<vertices.length; ++i){
    if (vertices.data[i * vertices.elementSize + axis] > maxCoord) {
      maxCoord = vertices.data[i * vertices.elementSize + axis];
      targetIndex = i;
    }
  }
  result.innerHTML = 'Max Value: ' + maxCoord + ', ' + 'Vertex Index: ' + targetIndex;
}