13 Commits

Author SHA1 Message Date
omrips 07be41a6b3 Add files via upload 2020-11-21 12:02:58 +02:00
omrips 174b37527a Add files via upload 2020-11-21 12:02:20 +02:00
omrips f29305e5e7 Add files via upload 2020-11-21 12:01:51 +02:00
omrips b87c4e78f8 Add files via upload
New version - fix bugs, 'set_grid'
2020-11-21 12:01:20 +02:00
omrips 9ab79bd47a Add files via upload
Fix issues with rotation at 0 angle
2020-10-09 12:03:48 +03:00
omrips 69780f953d Add files via upload 2020-10-09 12:02:33 +03:00
omrips 6a5b545a83 Add files via upload 2020-08-12 16:12:41 +03:00
omrips b9c0bd9435 Add files via upload
1. fix issue with colored STL on vsb
2. make all vsb ids -1
3. fixed an issue with mesh cloning
2020-08-12 16:10:37 +03:00
omrips 5d9daa6dcd Add files via upload 2020-07-30 11:35:02 +03:00
omrips 4d46da020f Add files via upload
takes 'filename' property for local file, if no 'file.name' property is available. usefull for blob files
2020-07-30 11:34:33 +03:00
omrips 7df7673429 Add files via upload
takes 'filename' property for local files, if no file.name property is avilable
2020-07-30 11:33:08 +03:00
omrips a8d0fb71e7 Add files via upload 2020-07-27 12:49:13 +03:00
omrips 5859bff3bf Add files via upload
Add units support
2020-07-27 12:48:37 +03:00
7 changed files with 142 additions and 1792 deletions
+2 -2
View File
@@ -1,2 +1,2 @@
//=========== Stl Viewer v1.10, by Omri Rips, Viewstl.com, July 2020 ; admin@viewstl.com ===========
importScripts("parser.min.js"),MSG_DATA=0,MSG_LOAD=1,MSG_ERROR=2,MSG_STL_LOADED=3,MSG_LOAD_IN_PROGRESS=4;var filename=null,local_file=null,load_from_blob_or_ab=null,x=0,y=0,z=0,model_id=-1,get_progress=!1;function isNumeric(a){return!isNaN(parseFloat(a))&&isFinite(a)}function send_error(a){postMessage({msg_type:MSG_ERROR,data:a})}function download_from_local(a){var e=new XMLHttpRequest;get_progress&&(e.onprogress=function(a){postMessage({msg_type:MSG_LOAD_IN_PROGRESS,id:model_id,loaded:a.loaded,total:a.total})}),e.onreadystatechange=function(a){4==e.readyState&&200==e.status&&after_file_load(e.response)},e.open("GET",a,!0),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.responseType="arraybuffer",e.send(null)}function after_file_load(a){var e;if(a){try{e=parse_3d_file(filename,a)}catch(a){e="Error parsing the file"}"string"!=typeof e?postMessage({msg_type:MSG_STL_LOADED,vertices:e.vertices,faces:e.faces,colors:e.colors}):send_error(e)}else send_error("no data")}function read_file(a){var e=new FileReader;e.onerror=function(a){var e="";switch(a.target.error.code){case a.target.error.NOT_FOUND_ERR:e="File not found";break;case a.target.error.NOT_READABLE_ERR:e="Can't read file - too large?";break;case a.target.error.ABORT_ERR:e="Read operation aborted";break;case a.target.error.SECURITY_ERR:e="File is locked";break;case a.target.error.ENCODING_ERR:e="File too large";break;default:e="Error reading file"}send_error(e)},e.onprogress=function(a){postMessage({msg_type:MSG_LOAD_IN_PROGRESS,id:model_id,loaded:a.loaded,total:a.total})},e.onload=function(a){after_file_load(a.target.result)},e.readAsArrayBuffer(a)}self.addEventListener("message",function(a){switch(a.data.msg_type){case MSG_DATA:if(!a.data.data){send_error("no data");break}if(!a.data.data.filename&&!a.data.data.local_file){send_error("no file");break}a.data.data.local_file?(filename=a.data.data.local_file.name,local_file=a.data.data.local_file?a.data.data.local_file:null):a.data.data.filename&&(filename=a.data.data.filename),a.data.data.x&&isNumeric(a.data.data.x)&&(x=a.data.data.x),a.data.data.y&&isNumeric(a.data.data.y)&&(y=a.data.data.y),a.data.data.y&&isNumeric(a.data.data.z)&&(z=a.data.data.z),load_from_blob_or_ab=null,a.data.load_from_blob_or_ab&&(load_from_blob_or_ab=a.data.load_from_blob_or_ab),model_id=a.data.data.id?a.data.data.id:-1,get_progress=!!a.data.get_progress&&a.data.get_progress;break;case MSG_LOAD:load_from_blob_or_ab?load_from_blob_or_ab instanceof ArrayBuffer?after_file_load(load_from_blob_or_ab):read_file(load_from_blob_or_ab):local_file?read_file(local_file):filename&&download_from_local(filename);break;default:console.log("invalid msg: "+a.data.msg_type)}});
//=========== Stl Viewer v1.11, by Omri Rips, Viewstl.com, November 2020 ; admin@viewstl.com ===========
importScripts("parser.min.js"),MSG_DATA=0,MSG_LOAD=1,MSG_ERROR=2,MSG_STL_LOADED=3,MSG_LOAD_IN_PROGRESS=4;var filename=null,local_file=null,load_from_blob_or_ab=null,x=0,y=0,z=0,model_id=-1,get_progress=!1;function isNumeric(a){return!isNaN(parseFloat(a))&&isFinite(a)}function send_error(a){postMessage({msg_type:MSG_ERROR,data:a})}function download_from_local(a){var e=new XMLHttpRequest;get_progress&&(e.onprogress=function(a){postMessage({msg_type:MSG_LOAD_IN_PROGRESS,id:model_id,loaded:a.loaded,total:a.total})}),e.onreadystatechange=function(a){4==e.readyState&&200==e.status&&after_file_load(e.response)},e.open("GET",a,!0),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.responseType="arraybuffer",e.send(null)}function after_file_load(a){var e;if(a){try{e=parse_3d_file(filename,a)}catch(a){e="Error parsing the file"}"string"!=typeof e?postMessage({msg_type:MSG_STL_LOADED,vertices:e.vertices,faces:e.faces,colors:e.colors}):send_error(e)}else send_error("no data")}function read_file(a){var e=new FileReader;e.onerror=function(a){var e="";switch(a.target.error.code){case a.target.error.NOT_FOUND_ERR:e="File not found";break;case a.target.error.NOT_READABLE_ERR:e="Can't read file - too large?";break;case a.target.error.ABORT_ERR:e="Read operation aborted";break;case a.target.error.SECURITY_ERR:e="File is locked";break;case a.target.error.ENCODING_ERR:e="File too large";break;default:e="Error reading file"}send_error(e)},e.onprogress=function(a){postMessage({msg_type:MSG_LOAD_IN_PROGRESS,id:model_id,loaded:a.loaded,total:a.total})},e.onload=function(a){after_file_load(a.target.result)},e.readAsArrayBuffer(a)}self.addEventListener("message",function(a){switch(a.data.msg_type){case MSG_DATA:if(!a.data.data){send_error("no data");break}if(!a.data.data.filename&&!a.data.data.local_file){send_error("no file");break}a.data.data.local_file?(filename=a.data.data.local_file.name?a.data.data.local_file.name:a.data.data.filename,local_file=a.data.data.local_file?a.data.data.local_file:null):a.data.data.filename&&(filename=a.data.data.filename),a.data.data.x&&isNumeric(a.data.data.x)&&(x=a.data.data.x),a.data.data.y&&isNumeric(a.data.data.y)&&(y=a.data.data.y),a.data.data.y&&isNumeric(a.data.data.z)&&(z=a.data.data.z),load_from_blob_or_ab=null,a.data.load_from_blob_or_ab&&(load_from_blob_or_ab=a.data.load_from_blob_or_ab),model_id=a.data.data.id?a.data.data.id:-1,get_progress=!!a.data.get_progress&&a.data.get_progress;break;case MSG_LOAD:load_from_blob_or_ab?load_from_blob_or_ab instanceof ArrayBuffer?after_file_load(load_from_blob_or_ab):read_file(load_from_blob_or_ab):local_file?read_file(local_file):filename&&download_from_local(filename);break;default:console.log("invalid msg: "+a.data.msg_type)}});
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -873
View File
File diff suppressed because one or more lines are too long
+1 -873
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -28,7 +28,7 @@ self.addEventListener("message", function(e)
if (e.data.data.local_file)
{
filename=e.data.data.local_file.name;
filename=e.data.data.local_file.name?e.data.data.local_file.name:e.data.data.filename; //filename property is usefull for blob files, 10x Fraser
local_file=e.data.data.local_file?e.data.data.local_file:null;
}
else if (e.data.data.filename)
+134 -40
View File
@@ -1,5 +1,12 @@
//1.10
//1.11
//**********************************************************
//New in 1.11 => set grid
//New in 1.10 => revoke dataURLs
//New in 1.10 => fix issue with rotation at 0 angle
//New in 1.10 => fix issue with colored STL on vsb
//New in 1.10 => make all vsb ids -1
//New in 1.10 => fixed issue with mesh cloning
//New in 1.10 => mm/inch settings
//New in 1.10 => Option to trigger 'no model' click event - 'send_no_model_click_event'
//New in 1.10 => Scale always 1 for vsb file, ro avoid double scalling
//New in 1.10 => define default path for loading THREE JS files by script path (and not by html page path) - thanks venkyr!
@@ -7,7 +14,6 @@
//New in 1.10 => fix rotation issues
//New in 1.09 => get_camera_state - get camera's info
//New in 1.09 => set_camera_state - set camera
//New in 1.09 => Returns 'orig_filename' optional parameter at 'get_model_info'
//New in 1.09 => 'get_vsj' - returns object current stands as json, files not included
//New in 1.09 => 'download_vsj' - download json descriptor of current scene
@@ -46,7 +52,7 @@ function StlViewer(parent_element_obj, options)
this.canvas_width="100%";
this.canvas_height="100%";
this.bg_color="transparent";
this.models_to_add=null; //at start
this.models_to_add=[]; //at start
this.models=new Array();
this.models_count=0;
this.models_ref=new Array(); //models with index - direct reference from id(comes from user) to model array (above)
@@ -65,6 +71,7 @@ function StlViewer(parent_element_obj, options)
this.camerax=0;
this.cameray=0;
this.cameraz=0;
this.camera_state=null;
this.auto_rotate=false;
this.mouse_zoom=true;
@@ -81,6 +88,7 @@ function StlViewer(parent_element_obj, options)
this.pre_loaded_vsj=null; //VSJ file content, waiting to be loaded (used when loading VSB)
this.zip_load_count=-1; //Zip files waiting to be loaded to memory (used when loading VSB)
this.send_no_model_click_event=false; //will trigger click event even if no model was clicked (just parent element was clicked)
this.grid=null; //draw grid over scene
this.set_on_model_mousedown = function (callback)
{
@@ -111,7 +119,7 @@ function StlViewer(parent_element_obj, options)
{
_this.canvas_width=_this.get_opt("width",_this.canvas_width);
_this.canvas_height=_this.get_opt("height",_this.canvas_height);
_this.bg_color=_this.get_opt("bgcolor",_this.bg_color);
_this.bg_color=_this.get_opt("bg_color",_this.bg_color);
_this.models_to_add=_this.get_opt("models",_this.models_to_add);
_this.model_loaded_callback=_this.get_opt("model_loaded_callback",_this.model_loaded_callback);
_this.all_loaded_callback=_this.get_opt("all_loaded_callback",_this.all_loaded_callback);
@@ -130,6 +138,7 @@ function StlViewer(parent_element_obj, options)
_this.on_model_drop=_this.get_opt("on_model_drop",_this.on_model_drop);
_this.center_models=_this.get_opt("center_models",_this.center_models);
_this.controls_type=_this.get_opt("controls", _this.controls_type);
_this.grid=_this.get_opt("grid",_this.grid?true:false); //now it is boolean, later it will be grid helper object
if (_this.zoom>=0)
_this.cameraz=_this.zoom;
else
@@ -170,7 +179,7 @@ function StlViewer(parent_element_obj, options)
_this.set_geo_minmax(model);
_this.recalc_dims(model);
model.color=model.mesh.material.color.getHexString();
model.color='#'+model.mesh.material.color.getHexString();
_this.scene.add(model.mesh);
_this.model_loaded(model.id);
@@ -197,7 +206,8 @@ function StlViewer(parent_element_obj, options)
if (geo)
{
//if (!geo.boundingBox) geo.computeBoundingBox();
var material=new THREE.MeshLambertMaterial({color:0x909090, overdraw: 1, wireframe: false, vertexColors: model.color?THREE.NoColors:THREE.FaceColors}); //if model color is set, ignores face colors set on the STL file itself (if any)
//var material=new THREE.MeshLambertMaterial({color:0x909090, overdraw: 1, wireframe: false, vertexColors: model.color?THREE.NoColors:THREE.FaceColors}); //if model color is set, ignores face colors set on the STL file itself (if any)
var material=new THREE.MeshLambertMaterial({color:0x909090, wireframe: false, vertexColors: model.color?THREE.NoColors:THREE.FaceColors}); //if model color is set, ignores face colors set on the STL file itself (if any)
if (!_this.is_ie) material.side = THREE.DoubleSide;
if (!model.display) model.display="flat";
_this.set_material_display(model.display, material, geo); //shading (aka display)
@@ -258,6 +268,7 @@ function StlViewer(parent_element_obj, options)
_this.camera_state=null; //it is one time thingy (next bunch of models will have to set camera state again)
_this.set_light();
_this.set_grid(_this.grid?true:false);
_this.load_session++; //from now on it is a new loading session
@@ -268,6 +279,26 @@ function StlViewer(parent_element_obj, options)
}
}
this.set_grid=function(b, size, divisions)
{
if (_this.grid) _this.scene.remove(_this.grid);
_this.grid=null;
if (b)
{
if (!size) size=Math.max(Math.abs(_this.maxx),Math.abs(_this.minx))*2.5;
if (size<=0)
{
var height = isNaN(window.innerHeight) ? window.clientHeight : window.innerHeight;
var width = isNaN(window.innerWidth) ? window.clientWidth : window.innerWidth;
size=Math.min(height, width)*0.8;
}
if (!divisions) divisions=10;
_this.grid = new THREE.GridHelper(size,divisions);
_this.scene.add(_this.grid);
}
}
this.remove_model = function(model_id)
{
if (_this.models_ref[model_id]===undefined) return _this.model_error("remove_model - id not found: "+model_id);
@@ -297,13 +328,16 @@ function StlViewer(parent_element_obj, options)
{
if (zoom) _this.zoom=zoom;
if ((_this.zoom_done)&&(!force_zoom)&&(_this.zoom>=0)) //don't do zoom for more than once
//if ((_this.zoom_done)&&(!force_zoom)&&(_this.zoom>=0)) //don't do zoom for more than once
if ((_this.zoom_done)&&(!force_zoom)) //don't do zoom for more than once
return;
_this.zoom_done=true;
var max_dim = Math.max(_this.maxx*2, _this.maxy*2, _this.maxz);
_this.camera.position.set(_this.camera.position.x,_this.camera.position.y,_this.zoom>=0?_this.zoom:(max_dim*1.2*Math.max(1,_this.camera.aspect/2))); //-1 = auto zoom
//var max_dim = Math.max(_this.maxx*2, _this.maxy*2, _this.maxz);
//_this.camera.position.set(_this.camera.position.x,_this.camera.position.y,_this.zoom>=0?_this.zoom:(max_dim*1.2*Math.max(1,_this.camera.aspect/2))); //-1 = auto zoom
var max_dim = Math.max(Math.abs(_this.maxx-_this.minx), Math.abs(_this.maxy-_this.miny), Math.abs(_this.maxz-_this.minz));
_this.camera.position.set(_this.camera.position.x,_this.camera.position.y,_this.zoom>=0?_this.zoom:max_dim*2); //-1 = auto zoom
}
//position, up and target vectors (each 3 coors vector) described camera's position
@@ -377,12 +411,14 @@ function StlViewer(parent_element_obj, options)
this.stop_auto_zoom=function ()
{
_this.zoom=_this.camera.position.z;
_this.zoom_done=true;
}
this.set_camera=function (x,y,z)
{
if (y) _this.zoom=y;
_this.camera.position.set(!_this.is_empty(x)?x:_this.camera.position.x,!_this.is_empty(y)?y:_this.camera.position.y,_this.zoom>=0?_this.zoom:Math.max(_this.maxx*3, _this.maxy*3, _this.maxz*3.5));
//_this.camera.position.set(!_this.is_empty(x)?x:_this.camera.position.x,!_this.is_empty(y)?y:_this.camera.position.y,_this.zoom>=0?_this.zoom:Math.max(_this.maxx*3, _this.maxy*3, _this.maxz*3.5));
_this.camera.position.set(!_this.is_empty(x)?x:_this.camera.position.x,!_this.is_empty(y)?y:_this.camera.position.y,!_this.is_empty(z)?z:_this.camera.position.z);
}
this.set_auto_zoom=function()
@@ -451,6 +487,10 @@ function StlViewer(parent_element_obj, options)
//set model custome properties
this.set_model_custom_props = function (model)
{
//units
model.units=model.units?model.units:'mm';
_this.set_model_units(model.id, model.units, true);
//position
model.x=model.x?model.x:0;
model.y=model.y?model.y:0;
@@ -491,7 +531,7 @@ function StlViewer(parent_element_obj, options)
_this.set_or_update_geo_edges (model, true);
//opacity
if (model.opacity)
if (typeof model.opacity !== 'undefined')
this.set_material_opacity(model.mesh.material, model.opacity);
//animation
@@ -578,6 +618,9 @@ function StlViewer(parent_element_obj, options)
if (!model) return;
if (!model.mesh) return;
if (color.length<6) return;
if (color.charAt(0)!='#') color='#'+color;
model.color=color;
_this.update_mesh_color(model.mesh, color, color?false:model.colors);
@@ -618,6 +661,8 @@ function StlViewer(parent_element_obj, options)
this.renderer.setClearColor(0x000000, 0);
else
this.renderer.setClearColor(bg_color, 1);
_this.bg_color=bg_color;
}
this.set_display = function(model_id, display)
@@ -637,10 +682,11 @@ function StlViewer(parent_element_obj, options)
this.set_opacity = function(model_id, opacity)
{
if (_this.models_ref[model_id]===undefined) return _this.model_error("set_display - id not found: "+model_id);
var model=_this.models[_this.models_ref[model_id]];
if (!model) return;
model.opacity=opacity;
this.set_material_opacity(model.mesh.material, opacity);
}
@@ -698,6 +744,41 @@ function StlViewer(parent_element_obj, options)
return (!a && a !== 0);
}
this.set_model_units = function(model_id, units, scale)
{
if (_this.models_ref[model_id]===undefined) return _this.model_error("set_model_units - id not found: "+model_id);
var model=_this.models[_this.models_ref[model_id]];
if (!model) return;
if (!model.mesh) return;
var scale_factor=1;
switch (units)
{
case 'mm':
if (scale) if (model.units=='inch') scale_factor=1/25.4;
model.units='mm';
break;
case 'inch':
if (scale) if (model.units=='mm') scale_factor=25.4;
model.units='inch';
break;
default:
return _this.model_error("set_model_units - invalid unit "+units);
}
if (scale_factor!=1)
{
_this.set_scale(model.id,
model.scalex*scale_factor,
model.scaley*scale_factor,
model.scalez*scale_factor
);
}
}
this.set_position = function(model_id, x,y,z)
{
if (_this.models_ref[model_id]===undefined) return _this.model_error("set_position - id not found: "+model_id);
@@ -729,7 +810,8 @@ function StlViewer(parent_element_obj, options)
case "smooth":
material.wireframe=false;
material.shading=THREE.SmoothShading;
//material.shading=THREE.SmoothShading;
material.flatShading=false;
if (geo)
{
geo.mergeVertices();
@@ -739,7 +821,8 @@ function StlViewer(parent_element_obj, options)
case "flat":
material.wireframe=false;
material.shading=THREE.FlatShading;
//material.shading=THREE.FlatShading;
material.flatShading=true;
if (geo)
geo.computeFlatVertexNormals();
break;
@@ -757,19 +840,19 @@ function StlViewer(parent_element_obj, options)
var c=add_to_current?1:0; //add or set angle
if (axis_x_angel)
if (axis_x_angel!==undefined)
{
model.rotationx=axis_x_angel+model.mesh.rotation.x*c;
model.mesh.rotation.x=model.rotationx;
}
if (axis_y_angel)
if (axis_y_angel!==undefined)
{
model.rotationy=axis_y_angel+model.mesh.rotation.y*c;
model.mesh.rotation.y=model.rotationy;
}
if (axis_z_angel)
if (axis_z_angel!==undefined)
{
model.rotationz=axis_z_angel+model.mesh.rotation.z*c;
model.mesh.rotation.z=model.rotationz;
@@ -795,6 +878,7 @@ function StlViewer(parent_element_obj, options)
return filename.split(/[\\/]/).pop();
}
this.get_model_filename=function(model, no_null, basename, skip_url)
{
var fn=null;
@@ -908,7 +992,7 @@ function StlViewer(parent_element_obj, options)
return _this.status;
}
this.calc_volume_and_area=function(geo)
this.calc_volume_and_area=function(geo, factor)
{
var x1,x2,x3,y1,y2,y3,z1,z2,z3,i;
var len=geo.faces.length;
@@ -918,15 +1002,15 @@ function StlViewer(parent_element_obj, options)
for (i=0;i<len;i++)
{
x1=geo.vertices[geo.faces[i].a].x;
y1=geo.vertices[geo.faces[i].a].y;
z1=geo.vertices[geo.faces[i].a].z;
x2=geo.vertices[geo.faces[i].b].x;
y2=geo.vertices[geo.faces[i].b].y;
z2=geo.vertices[geo.faces[i].b].z;
x3=geo.vertices[geo.faces[i].c].x;
y3=geo.vertices[geo.faces[i].c].y;
z3=geo.vertices[geo.faces[i].c].z;
x1=geo.vertices[geo.faces[i].a].x*factor;
y1=geo.vertices[geo.faces[i].a].y*factor;
z1=geo.vertices[geo.faces[i].a].z*factor;
x2=geo.vertices[geo.faces[i].b].x*factor;
y2=geo.vertices[geo.faces[i].b].y*factor;
z2=geo.vertices[geo.faces[i].b].z*factor;
x3=geo.vertices[geo.faces[i].c].x*factor;
y3=geo.vertices[geo.faces[i].c].y*factor;
z3=geo.vertices[geo.faces[i].c].z*factor;
totalVolume +=
(-x3 * y2 * z1 +
@@ -936,9 +1020,9 @@ function StlViewer(parent_element_obj, options)
x2 * y1 * z3 +
x1 * y2 * z3);
a=geo.vertices[geo.faces[i].a].distanceTo(geo.vertices[geo.faces[i].b]);
b=geo.vertices[geo.faces[i].b].distanceTo(geo.vertices[geo.faces[i].c]);
c=geo.vertices[geo.faces[i].c].distanceTo(geo.vertices[geo.faces[i].a]);
a=geo.vertices[geo.faces[i].a].distanceTo(geo.vertices[geo.faces[i].b])*factor;
b=geo.vertices[geo.faces[i].b].distanceTo(geo.vertices[geo.faces[i].c])*factor;
c=geo.vertices[geo.faces[i].c].distanceTo(geo.vertices[geo.faces[i].a])*factor;
s=(a+b+c)/2;
totalArea+=Math.sqrt(s*(s-a)*(s-b)*(s-c));
}
@@ -956,8 +1040,8 @@ function StlViewer(parent_element_obj, options)
if (!model.mesh) return null;
if (!model.mesh.geometry) return null;
var vol_and_area=model.mesh.geometry?_this.calc_volume_and_area(model.mesh.geometry):[0,0,0];
return {name:model.filename?model.filename:(model.local_file?model.local_file.name:""), orig_filename:model.orig_filename?model.orig_filename:null, position:{x:model.x, y:model.y, z:model.z}, dims:{x:model.mesh.geometry.maxx-model.mesh.geometry.minx, y:model.mesh.geometry.maxy-model.mesh.geometry.miny, z:model.mesh.geometry.maxz-model.mesh.geometry.minz}, rotation:{x:model.mesh.rotation.x,y:model.mesh.rotation.y,z:model.mesh.rotation.z}, display:model.display?model.display:null, color:model.color?model.color:null, scale:{x:model.scalex,y:model.scaley,z:model.scalez}, volume:vol_and_area[0], area:vol_and_area[1], triangles:vol_and_area[2]};
var vol_and_area=model.mesh.geometry?_this.calc_volume_and_area(model.mesh.geometry, model.units=='inch'?1/25.4:1):[0,0,0];
return {name:model.filename?model.filename:(model.local_file?model.local_file.name:""), orig_filename:model.orig_filename?model.orig_filename:null, position:{x:model.x, y:model.y, z:model.z}, dims:{x:model.mesh.geometry.maxx-model.mesh.geometry.minx, y:model.mesh.geometry.maxy-model.mesh.geometry.miny, z:model.mesh.geometry.maxz-model.mesh.geometry.minz}, rotation:{x:model.mesh.rotation.x,y:model.mesh.rotation.y,z:model.mesh.rotation.z}, display:model.display?model.display:null, color:model.color?model.color:null, scale:{x:model.scalex,y:model.scaley,z:model.scalez}, volume:vol_and_area[0], area:vol_and_area[1], triangles:vol_and_area[2], units:model.units, opacity:model.opacity!==undefined?model.opacity:1};
}
this.get_vsb = function()
@@ -980,18 +1064,20 @@ function StlViewer(parent_element_obj, options)
//get object info in json format
var pos=_this.camera.position;
var data={canvas_height:_this.canvas_height, bg_color:_this.bg_color, camera_state:_this.get_camera_state(), auto_rotate:_this.auto_rotate, mouse_zoom:_this.mouse_zoom, auto_resize:_this.auto_resize, center_models:_this.center_models};
if (_this.grid) data['grid']=1;
data['models']=[];
Object.keys(_this.models_ref).forEach(function(key)
{
var model=_this.models[_this.models_ref[key]];
var info={id:model.id};
var info={id:for_vsb?-1:model.id};
if (for_vsb)
{
//console.log(model);
var curr_filename=_this.get_model_filename(model, true, true, true);
if (curr_filename) info['filename']=curr_filename;
//var curr_filename=_this.get_model_filename(model, true, true, true);
//if (curr_filename) info['filename']=curr_filename;
info['filename']=model.id+'.stl';
}
else
{
@@ -999,11 +1085,13 @@ function StlViewer(parent_element_obj, options)
if (curr_filename) info['filename']=curr_filename;
if (model.local_file) info['local_file']=model.local_file;
}
if (model.x) info['x']=model.x;
if (model.y) info['y']=model.y;
if (model.z) info['z']=model.z;
if (model.display) info['display']=model.display;
if (model.color) info['color']=model.color;
if (!((model.colors)&&(model.color=='#ffffff'))) if (model.color) info['color']=model.color; //if model is colored stl and the color is #FFFFFF, skip color property (cause this is the defauly for colored STL)
if (model.units) info['units']=model.units;
if (model.rotationx) info['rotationx']=model.rotationx;
if (model.rotationy) info['rotationy']=model.rotationy;
if (model.rotationz) info['rotationz']=model.rotationz;
@@ -1048,6 +1136,7 @@ function StlViewer(parent_element_obj, options)
link.download = download_name+'.vsj';
link.click();
URL.revokeObjectURL(link.href);
}
this.load_vsj = function(filename)
@@ -1256,6 +1345,7 @@ function StlViewer(parent_element_obj, options)
link.download = download_name+'.vsb';
link.click();
URL.revokeObjectURL(link.href);
});
return;
@@ -1371,7 +1461,7 @@ function StlViewer(parent_element_obj, options)
link.href = window.URL.createObjectURL(blob);
//var download_name=filename?filename:(model.filename?model.filename:(model.local_file?model.local_file.name:"1"));
var download_name=_this.get_model_filename(model,true,true,true);
console.log(download_name);
var p=download_name.toLowerCase().indexOf('.stl');
if (p>=0) download_name=download_name.substring( 0, p );
if (download_name.length<1) download_name='1';
@@ -1385,6 +1475,7 @@ function StlViewer(parent_element_obj, options)
link.download = download_name+'.stl';
link.click();
URL.revokeObjectURL(link.href);
}
this.get_model_mesh = function(model_id)
@@ -1395,7 +1486,10 @@ function StlViewer(parent_element_obj, options)
if (!model) return;
if (!model.mesh) return;
return model.mesh.clone();
var mesh=model.mesh.clone();
mesh.geometry=model.mesh.geometry.clone();
mesh.material=model.mesh.material.clone();
return mesh;
}
@@ -1970,7 +2064,7 @@ function StlViewer(parent_element_obj, options)
}
_this.options=data;
_this.set_options();
if (_this.ready)