diff -r d26669bf424e -r 098335a1d510 stlviewer.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stlviewer.js Tue Apr 04 00:47:22 2017 +0200 @@ -0,0 +1,199 @@ +$( function() { + $( "#sortable1 li" ).draggable({ + helper: "clone", + containment:"document" + }); + $( "#sortable2" ).droppable({ + accept: "#sortable1 li", + drop: function( event, ui ) { + ui.draggable.clone(false).appendTo($(this)); + for (i =0; i<10; i++) clear_scene(); + window.setTimeout(update_scene,500); + } + }); + $( "#sortable2" ).sortable({ + placeholder: "ui-state-highlight", + start: clear_scene, + stop: function() { + for (i =0; i<10; i++) clear_scene(); + window.setTimeout(update_scene,500) + } + }); + $( "#sortable2" ).disableSelection(); +} ); + +function clear_scene() { + scene.children.forEach(function(v){ + if(v.stlfile === true) { + v.material.dispose(); + v.geometry.dispose(); + scene.remove(v); + } + //scene.remove(object); + }); +} + +function update_scene() { + var cylinders = []; + $("#sortable2 li").each(function(idx, e){ + cylinders.push($(e).attr('key')); + }); + if (cylinders.length < 2) return; + + // fetch new objects list + $.ajax({ + url: "#", + method: 'post', + dataType: 'json', + data: { + action: 'calculate', + cylinders: cylinders + }, + success: function(data) { + //console.log(data); + // remove all meshes + clear_scene(); + // append the objects with positioning + for (i = 0; i