@@ -18,6 +18,7 @@ var supressCube = false;
1818var isASCII = false ;
1919var landscape = true ;
2020var cordinatesDiv = document . getElementById ( 'cordinates' ) ;
21+ var nromalTitle = "STL Gcode Viewer" ;
2122// 创建球体对象
2223// var cursor3D = new THREE.Group();
2324// cursor3D.name = "cursor";
@@ -43,59 +44,59 @@ var cordinatesDiv = document.getElementById('cordinates');
4344// sizeAttenuation: false, // 关闭点的大小衰减
4445// transparent: true // 开启透明度
4546// })));
46- var canvas = document . createElement ( 'canvas' ) ;
47- canvas . width = 64 ;
48- canvas . height = 64 ;
49- var context = canvas . getContext ( '2d' ) ;
50-
51- // 绘制十字光标 - 改成亮黄色
52- context . strokeStyle = '#ffff00' ;
53- context . lineWidth = 3 ;
54-
55- // 左横线
56- context . beginPath ( ) ;
57- context . moveTo ( 10 , 32 ) ;
58- context . lineTo ( 28 , 32 ) ;
59- context . stroke ( ) ;
60-
61- // 右横线
62- context . beginPath ( ) ;
63- context . moveTo ( 36 , 32 ) ;
64- context . lineTo ( 54 , 32 ) ;
65- context . stroke ( ) ;
66-
67- // 上竖线
68- context . beginPath ( ) ;
69- context . moveTo ( 32 , 10 ) ;
70- context . lineTo ( 32 , 28 ) ;
71- context . stroke ( ) ;
72-
73- // 下竖线
74- context . beginPath ( ) ;
75- context . moveTo ( 32 , 36 ) ;
76- context . lineTo ( 32 , 54 ) ;
77- context . stroke ( ) ;
78-
79- // 中心圆形 - 镂空边框
80- context . strokeStyle = 'rgba(247, 113, 113, 1)' ;
81- context . lineWidth = 1 ;
82- context . beginPath ( ) ;
83- context . arc ( 32 , 32 , 2 , 0 , 2 * Math . PI ) ;
84- context . stroke ( ) ;
85-
86- var cursorMap = new THREE . CanvasTexture ( canvas ) ;
87- var spriteMaterial = new THREE . SpriteMaterial ( {
88- map : cursorMap ,
89- transparent : true ,
90- opacity : 0.8 ,
91- depthTest : false , // 关键:不受深度测试影响
92- depthWrite : false // 关键:不写入深度缓冲区
93- } ) ;
94-
95- cursor3D = new THREE . Sprite ( spriteMaterial ) ;
96- cursor3D . name = "cursor" ;
97- cursor3D . scale . set ( 20 , 20 , 1 ) ; // 屏幕空间尺寸(像素)
98- cursor3D . visible = false ;
47+ var canvas = document . createElement ( 'canvas' ) ;
48+ canvas . width = 64 ;
49+ canvas . height = 64 ;
50+ var context = canvas . getContext ( '2d' ) ;
51+
52+ // 绘制十字光标 - 改成亮黄色
53+ context . strokeStyle = '#ffff00' ;
54+ context . lineWidth = 3 ;
55+
56+ // 左横线
57+ context . beginPath ( ) ;
58+ context . moveTo ( 10 , 32 ) ;
59+ context . lineTo ( 28 , 32 ) ;
60+ context . stroke ( ) ;
61+
62+ // 右横线
63+ context . beginPath ( ) ;
64+ context . moveTo ( 36 , 32 ) ;
65+ context . lineTo ( 54 , 32 ) ;
66+ context . stroke ( ) ;
67+
68+ // 上竖线
69+ context . beginPath ( ) ;
70+ context . moveTo ( 32 , 10 ) ;
71+ context . lineTo ( 32 , 28 ) ;
72+ context . stroke ( ) ;
73+
74+ // 下竖线
75+ context . beginPath ( ) ;
76+ context . moveTo ( 32 , 36 ) ;
77+ context . lineTo ( 32 , 54 ) ;
78+ context . stroke ( ) ;
79+
80+ // 中心圆形 - 镂空边框
81+ context . strokeStyle = 'rgba(247, 113, 113, 1)' ;
82+ context . lineWidth = 1 ;
83+ context . beginPath ( ) ;
84+ context . arc ( 32 , 32 , 4 , 0 , 2 * Math . PI ) ;
85+ context . stroke ( ) ;
86+
87+ var cursorMap = new THREE . CanvasTexture ( canvas ) ;
88+ var spriteMaterial = new THREE . SpriteMaterial ( {
89+ map : cursorMap ,
90+ transparent : true ,
91+ opacity : 0.8 ,
92+ depthTest : false , // 关键:不受深度测试影响
93+ depthWrite : false // 关键:不写入深度缓冲区
94+ } ) ;
95+
96+ cursor3D = new THREE . Sprite ( spriteMaterial ) ;
97+ cursor3D . name = "cursor" ;
98+ cursor3D . scale . set ( 20 , 20 , 1 ) ; // 屏幕空间尺寸(像素)
99+ cursor3D . visible = false ;
99100// 定义一个射线投射器
100101var raycaster = new THREE . Raycaster ( ) ;
101102var mouse = new THREE . Vector2 ( ) ;
@@ -1171,7 +1172,6 @@ function jumpToLayer(layerNumber) {
11711172 txar . setCursor ( startLine , 0 ) ;
11721173 markLine ( startLine , true ) ;
11731174 layerData . currentLayer = layerNumber ;
1174-
11751175 // 更新进度条显示
11761176 updateProgressBarDisplay ( ) ;
11771177
@@ -1207,10 +1207,40 @@ function extractLayerNumber(line) {
12071207 var match = line . match ( / ; L A Y E R : ( \d + ) / ) ;
12081208 return match ? parseInt ( match [ 1 ] ) : - 1 ;
12091209}
1210-
1211- function bt_cut ( ) {
1212-
1210+ const worker = new Worker ( './worker.js' ) ;
1211+ function bt_cut ( ) {
1212+ if ( machineType !== "3DPRINT" ) return ;
1213+ if ( document . title === nromalTitle ) return ;
1214+ var cutBt = document . getElementById ( "cuthere" ) ;
1215+ //disable cutBt after been used
1216+ cutBt . disabled = true ;
1217+ cutBt . innerText = "processing..." ;
1218+ const cursorPos = txar . getCursor ( ) ;
1219+ const text = txar . getValue ( ) ; // CodeMirror 文本
1220+ const cursorLine = txar . getCursor ( ) . line ; // 当前光标行
1221+ const title = document . title ; // 页面标题
1222+
1223+ // 发送给 worker
1224+ worker . postMessage ( {
1225+ text,
1226+ cursorLine,
1227+ title
1228+ } ) ;
12131229}
1230+ // 接收处理结果并下载
1231+ worker . onmessage = e => {
1232+ const { fileName, content } = e . data ;
1233+ const blob = new Blob ( [ content ] , { type : 'text/plain' } ) ;
1234+ const a = document . createElement ( 'a' ) ;
1235+ a . href = URL . createObjectURL ( blob ) ;
1236+ a . download = fileName ;
1237+ a . click ( ) ;
1238+ URL . revokeObjectURL ( a . href ) ;
1239+ var cutBt = document . getElementById ( "cuthere" ) ;
1240+ cutBt . innerText = "cut here" ;
1241+ cutBt . disabled = false ;
1242+ } ;
1243+
12141244
12151245function bt_open ( ) {
12161246 //pop open file diaglog to open local file accept extension in plainTextFile and STL
@@ -1248,6 +1278,7 @@ function read_file(file) {
12481278 alert ( "file size is too big" ) ;
12491279 return ;
12501280 }
1281+ document . title = file . name ;
12511282 scene . remove ( sampleCube ) ;
12521283 if ( gCode !== undefined ) {
12531284 gCodeClear ( ) ;
0 commit comments