Skip to content

Commit

Permalink
Refactor 3d models loading
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Jan 15, 2025
1 parent 768112c commit 4611893
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions labs/pd3d/3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
return txt;
}

function download(url, callback){
const xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
function ajax_download(url, callback){
const xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4){
if (xmlhttp.status == 200) callback(xmlhttp.responseText);
Expand Down Expand Up @@ -159,6 +159,7 @@

// object
loader = new VRMLLoader();
loader.setWithCredentials(true);
loader.load(load_url, function(object){

object.position.set(x_shift, y_shift, z_shift);
Expand Down Expand Up @@ -257,6 +258,7 @@
}

function load_sim_legend(){
// TODO refactor wrt ajax_download
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4){
Expand All @@ -276,7 +278,8 @@
}
}
xhr.open('GET', data_server + JSON.stringify({elements: target, classes: n_els == 4 ? 'tetrahedron' : 'prism'}));
xhr.send(null);
xhr.withCredentials = true;
xhr.send(1);
}

function render_sim(dataset, pos){ // dataset can be false or []
Expand Down Expand Up @@ -374,7 +377,7 @@
// onload production
load_url = model_url;

download(meta_url, function(meta){
ajax_download(meta_url, function(meta){
meta = JSON.parse(meta);
//console.log(meta);

Expand Down

0 comments on commit 4611893

Please sign in to comment.