Last active
August 29, 2015 13:56
-
-
Save brettlangdon/8805435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @license | |
* jQuery ShapeJS Plugin | |
* version: 2.1.0-2014.02.04 | |
* Requires jQuery v1.5 or later | |
* Copyright (c) 2014 Shapeways | |
* Examples and documentation at: http://shapejs.shapeways.com | |
* Project repository: https://github.com/Shapeways/shapejs | |
* License: MIT | |
*/ | |
var executeShapeJs = function(script, params, success, failure){ | |
failure = failure || console.log; | |
var defaultParams = { | |
persistent: false, | |
pipeline: "VolumeSculptorProcessing", | |
action: "preview", | |
accuracy: "VISUAL", | |
previewQuality: "LOW", | |
regions: "ONE", | |
visRemovedRegions: false, | |
optimizeX3D: true, | |
script: script, | |
generateImage: false, | |
}; | |
var processData = true; | |
if(params instanceof FormData){ | |
processData = false; | |
for(var i in defaultParams){ | |
params.append(i, defaultParams[i]); | |
} | |
} else{ | |
jQuery.extend(params, defaultParams); | |
} | |
var options = { | |
method: "POST", | |
timeout: 180000, | |
data: params, | |
dataType: "JSON", | |
processData: processData, | |
success: function(data){ | |
if(!data || !data.state){ | |
return failure("invalid response from server"); | |
} | |
var state = data.state; | |
var results = {}; | |
for(var key in state){ | |
if(key.indexOf("VolumeSculptor.") === 0){ | |
results[key.substring(15)] = state[key]; | |
} else if(key == "Aopt.output"){ | |
for(var i in state["Aopt.output"]){ | |
var next = state["Aopt.output"][i]; | |
if(~next.indexOf(".x3d")){ | |
results.modelPreviewUrl = next; | |
break; | |
} | |
} | |
} | |
} | |
if(results.output){ | |
results.modelUrl = results.output; | |
delete results.output; | |
} | |
if(parseInt(results.exitCode) === 0){ | |
return success(results); | |
} else{ | |
return failure(results); | |
} | |
}, | |
error: function(data){ | |
failure(data); | |
}, | |
}; | |
currentCall = jQuery.ajax("http://www.shapeways.com/creator/exec_pipeline_proxy", options); | |
}; | |
var loadShapeJsPreview = function(targetSelector, modelUrl, width, height){ | |
width = width || 300; | |
height = height || 300; | |
var src = "https://images.shapeways.com/3dviewer/aopt-file?aoptFilePath="; | |
src += modelUrl + "&width=" + width + "&height=" + height; | |
var element = jQuery(targetSelector); | |
if(element.children("#shapejs-preview").length){ | |
element.children("#shapejs-preview").attr("src", src); | |
} else{ | |
element.append('<iframe id="shapejs-preview" src="' + src + '" height="100%" width="100%"></iframe>'); | |
} | |
}; | |
(function($){ | |
var currentCall = null; | |
$.fn.executeShapeJs = function(params, success, failure, abortInProgress){ | |
abortInProgress = (abortInProgress === undefined)? true : abortInProgress; | |
if(abortInProgress && currentCall){ | |
currentCall.abort(); | |
} | |
var script = JSON.stringify($(this).val()); | |
currentCall = executeShapeJs(script, params, success, failure); | |
}; | |
$.fn.loadShapeJsPreview = function(modelUrl, width, height){ | |
var target = $(this); | |
loadShapeJsPreview(target, modelUrl, width, height); | |
}; | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @license | |
* jQuery ShapeJS Plugin | |
* version: 2.1.0-2014.02.04 | |
* Requires jQuery v1.5 or later | |
* Copyright (c) 2014 Shapeways | |
* Examples and documentation at: http://shapejs.shapeways.com | |
* Project repository: https://github.com/Shapeways/shapejs | |
* License: MIT | |
*/ | |
var executeShapeJs=function(e,r,t,a){a=a||console.log;var i={persistent:false,pipeline:"VolumeSculptorProcessing",action:"preview",accuracy:"VISUAL",previewQuality:"LOW",regions:"ONE",visRemovedRegions:false,optimizeX3D:true,script:e,generateImage:false};var s=true;if(r instanceof FormData){s=false;for(var o in i){r.append(o,i[o])}}else{jQuery.extend(r,i)}var n={method:"POST",timeout:18e4,data:r,dataType:"JSON",processData:s,success:function(e){if(!e||!e.state){return a("invalid response from server")}var r=e.state;var i={};for(var s in r){if(s.indexOf("VolumeSculptor.")===0){i[s.substring(15)]=r[s]}else if(s=="Aopt.output"){for(var o in r["Aopt.output"]){var n=r["Aopt.output"][o];if(~n.indexOf(".x3d")){i.modelPreviewUrl=n;break}}}}if(i.output){i.modelUrl=i.output;delete i.output}if(parseInt(i.exitCode)===0){return t(i)}else{return a(i)}},error:function(e){a(e)}};currentCall=jQuery.ajax("http://www.shapeways.com/creator/exec_pipeline_proxy",n)};var loadShapeJsPreview=function(e,r,t,a){t=t||300;a=a||300;var i="https://images.shapeways.com/3dviewer/aopt-file?aoptFilePath=";i+=r+"&width="+t+"&height="+a;var s=jQuery(e);if(s.children("#shapejs-preview").length){s.children("#shapejs-preview").attr("src",i)}else{s.append('<iframe id="shapejs-preview" src="'+i+'" height="100%" width="100%"></iframe>')}};(function(e){var r=null;e.fn.executeShapeJs=function(t,a,i,s){s=s===undefined?true:s;if(s&&r){r.abort()}var o=JSON.stringify(e(this).val());r=executeShapeJs(o,t,a,i)};e.fn.loadShapeJsPreview=function(r,t,a){var i=e(this);loadShapeJsPreview(i,r,t,a)}})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment