deblan.io-murph/public/stl_viewer/stl_viewer.min.js

2 lines
37 KiB
JavaScript
Raw Normal View History

2021-07-09 23:42:38 +02:00
//=========== Stl Viewer v1.13, by Omri Rips, Viewstl.com, July 2021 ; admin@viewstl.com ===========
var stl_viewer_script_path="";function StlViewer(e,t){e||console.log("error: no parent element");var o=this;this.error=null,this.options=t,this.parent_element=e,this.get_opt=function(e,t){return o.options?!1!==o.options[e]&&(o.options[e]?o.options[e]:t):t},this.canvas_width="100%",this.canvas_height="100%",this.bg_color="transparent",this.models_to_add=[],this.models=new Array,this.models_count=0,this.models_ref=new Array,this.allow_drag_and_drop=o.get_opt("allow_drag_and_drop",!0),this.model_loaded_callback=null,this.all_loaded_callback=null,this.load_error_callback=null,this.loading_progress_callback=null,this.max_model_id=0,this.load_status=new Array,this.load_session=0,this.loaded_models_arr=new Array,this.status=0,this.onmousedown_callback=null,this.zoom=-1,this.camerax=0,this.cameray=0,this.cameraz=0,this.camera_state=null,this.auto_rotate=!1,this.mouse_zoom=!0,this.load_three_files=o.get_opt("load_three_files",stl_viewer_script_path),this.ready="undefined"!=typeof THREE,this.ready_callback=null,this.jszip_path=null,this.jszip_utils_path=null,this.auto_resize=!0,this.on_model_drop=null,this.center_models=!0,this.controls_type=0,this.zoom=-1,this.pre_loaded_ab_files=null,this.pre_loaded_vsj=null,this.zip_load_count=-1,this.send_no_model_click_event=!1,this.grid=null,this.killsign=!1,this.default_face_color="#909090",this.set_on_model_mousedown=function(e){o.onmousedown_callback=e,o.onmousedown_callback&&(o.parent_element.addEventListener("mousedown",o.onmousedown),o.parent_element.addEventListener("dblclick",o.onmousedown),o.parent_element.addEventListener("touchstart",o.onmousedown))},this.set_drag_and_drop=function(e){e?(o.parent_element.addEventListener("dragover",o.handleDragOver),o.parent_element.addEventListener("drop",o.handleFileDrop)):(o.parent_element.removeEventListener("dragover",o.handleDragOver),o.parent_element.removeEventListener("drop",o.handleFileDrop))},this.set_options=function(){o.canvas_width=o.get_opt("width",o.canvas_width),o.canvas_height=o.get_opt("height",o.canvas_height),o.bg_color=o.get_opt("bg_color",o.bg_color),o.models_to_add=o.get_opt("models",o.models_to_add),o.model_loaded_callback=o.get_opt("model_loaded_callback",o.model_loaded_callback),o.all_loaded_callback=o.get_opt("all_loaded_callback",o.all_loaded_callback),o.load_error_callback=o.get_opt("load_error_callback",o.load_error_callback),o.loading_progress_callback=o.get_opt("loading_progress_callback",o.loading_progress_callback),o.onmousedown_callback=o.get_opt("on_model_mousedown",o.onmousedown_callback),o.onmousedown_callback||(o.onmousedown_callback=o.get_opt("on_model_mouseclick",null)),o.send_no_model_click_event=o.get_opt("send_no_model_click_event",o.send_no_model_click_event),o.zoom=o.get_opt("zoom",o.zoom),o.camerax=o.get_opt("camerax",o.camerax),o.cameray=o.get_opt("cameray",o.cameray),o.auto_rotate=o.get_opt("auto_rotate",o.auto_rotate),o.mouse_zoom=o.get_opt("mouse_zoom",o.mouse_zoom),o.ready_callback=o.get_opt("ready_callback",null),o.jszip_path=o.get_opt("jszip_path",null),o.jszip_utils_path=o.get_opt("jszip_utils_path",null),o.auto_resize=o.get_opt("auto_resize",o.auto_resize),o.on_model_drop=o.get_opt("on_model_drop",o.on_model_drop),o.center_models=o.get_opt("center_models",o.center_models),o.controls_type=o.get_opt("controls",o.controls_type),o.grid=o.get_opt("grid",!!o.grid),o.zoom>=0?o.cameraz=o.zoom:o.cameraz=o.get_opt("cameraz",o.cameraz),o.camera_state=o.get_opt("camera_state",o.camera_state),o.allow_drag_and_drop&&o.set_drag_and_drop(!0)},o.is_ie=!!window.MSStream,this.MSG2WORKER_DATA=0,this.MSG2WORKER_LOAD=1,this.MSG2WORKER_ERROR=2,this.MSGFROMWORKER_STL_LOADED=3,this.MSGFROMWORKER_LOAD_IN_PROGRESS=4,this.load_model=function(e){return o.max_model_id=Math.max(o.max_model_id,e.id),e.filename||e.local_file?o.load_from_stl_file(e,!1):e.mesh?o.add_from_existing_mesh(e):void o.models_count--},this.add_from_existing_mesh=function(e){o.set_model_custom_props(e),e.mesh.model_id=e.id,o.set_geo_minmax(e),o.recalc_dims(e),e.color="#"+e.mesh.material.color.getHexString(),o.scene.add(e.mesh),o.model_loaded(e.id),o.