← Commit history

3d viewer: frame camera on the model once geometry loads

Ray ·4f8bff55b4 ·3mo ago ·parent 7d9f2dd
1 file changed +10−3
viewers/3d.html+10−3
@@ -41518,11 +41518,18 @@ Check the top-level render call using <`+bt+">.")}return $e}function Rn(Ee,$e){i <script> var MPN="STM32F103C8T6", GLB="../stm32f103c8t6-board.glb"; var v=null;+function rmPh(){var p=document.getElementById('ph');if(p)p.remove();} try{   v=Adom3DViewer.init(document.getElementById('stage'),{modelUrl:GLB,zUp:true,showGround:false,showViewCube:true,initialViewMode:"perspective"});-  var scn=v.getScene&&v.getScene();-  if(scn&&scn.onDataLoadedObservable){scn.onDataLoadedObservable.add(function(){var p=document.getElementById('ph');if(p)p.remove();});}-  setTimeout(function(){var p=document.getElementById('ph');if(p)p.remove();},2500);+  // wait for real geometry, then frame the camera on it+  var tries=0, iv=setInterval(function(){+    tries++;+    try{+      var s=v.getScene(), real=(s.meshes||[]).filter(function(m){return m.getTotalVertices&&m.getTotalVertices()>0;});+      if(real.length){ try{v.frameModel&&v.frameModel();}catch(_){} try{v.goHome&&v.goHome();}catch(_){} rmPh(); clearInterval(iv); }+    }catch(_){}+    if(tries>60){ clearInterval(iv); var p=document.getElementById('ph'); if(p)p.textContent='3D: model did not load ('+GLB+')'; }+  },200); }catch(err){var p=document.getElementById('ph');if(p)p.textContent='3D unavailable: '+err;} function meshes(){try{return (v.getScene().meshes)||[];}catch(_){return [];}} [].slice.call(document.querySelectorAll('.lyrtog')).forEach(function(b){