Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
5ffcc106
T
three.js
项目概览
Ablesons
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5ffcc106
编写于
12月 18, 2017
作者:
T
Tentone
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Single object, optimized code
上级
49ad9513
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
61 deletion
+69
-61
examples/js/loaders/GCodeLoader.js
examples/js/loaders/GCodeLoader.js
+69
-61
未找到文件。
examples/js/loaders/GCodeLoader.js
浏览文件 @
5ffcc106
...
...
@@ -14,6 +14,8 @@ THREE.GCodeLoader = function ( manager ) {
this
.
manager
=
(
manager
!==
undefined
)
?
manager
:
THREE
.
DefaultLoadingManager
;
this
.
splitLayer
=
false
;
};
THREE
.
GCodeLoader
.
prototype
.
load
=
function
(
url
,
onLoad
,
onProgress
,
onError
)
{
...
...
@@ -31,12 +33,12 @@ THREE.GCodeLoader.prototype.load = function ( url, onLoad, onProgress, onError )
THREE
.
GCodeLoader
.
prototype
.
parse
=
function
(
data
)
{
var
currentState
=
{
x
:
0
,
y
:
0
,
z
:
0
,
e
:
0
,
f
:
0
,
extruding
:
false
};
var
state
=
{
x
:
0
,
y
:
0
,
z
:
0
,
e
:
0
,
f
:
0
,
extruding
:
false
,
relative
:
false
};
var
layers
=
[];
var
currentLayer
=
undefined
;
var
relative
=
false
;
var
box
=
new
THREE
.
Box3
();
var
layers
=
[];
var
pathMaterial
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0xFFFF00
}
);
pathMaterial
.
name
=
'
path
'
;
...
...
@@ -46,53 +48,43 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
function
newLayer
(
line
)
{
currentLayer
=
{
lines
:
[],
currentLayer
:
layers
.
length
,
z
:
line
.
z
};
currentLayer
=
{
vertex
:
[],
pathVertex
:
[]
,
z
:
line
.
z
};
layers
.
push
(
currentLayer
);
}
function
getLineGroup
(
line
)
{
//Create lie segment between p1 and p2
function
addSegment
(
p1
,
p2
)
{
if
(
currentLayer
===
undefined
)
{
newLayer
(
line
);
newLayer
(
p1
);
}
var
grouptype
=
line
.
extruding
?
1
:
0
;
if
(
currentLayer
.
lines
[
grouptype
]
===
undefined
)
{
if
(
line
.
extruding
)
{
currentLayer
.
lines
[
grouptype
]
=
{
type
:
grouptype
,
feed
:
line
.
e
,
extruding
:
line
.
extruding
,
vertex
:
[],
material
:
line
.
extruding
?
extrudingMaterial
:
pathMaterial
,
segmentCount
:
0
};
currentLayer
.
vertex
.
push
(
p1
.
x
);
currentLayer
.
vertex
.
push
(
p1
.
y
);
currentLayer
.
vertex
.
push
(
p1
.
z
);
currentLayer
.
vertex
.
push
(
p2
.
x
);
currentLayer
.
vertex
.
push
(
p2
.
y
);
currentLayer
.
vertex
.
push
(
p2
.
z
);
}
return
currentLayer
.
lines
[
grouptype
];
}
//Create lie segment between p1 and p2
function
addSegment
(
p1
,
p2
)
{
var
group
=
getLineGroup
(
p2
);
else
{
group
.
segmentCount
++
;
group
.
vertex
.
push
(
p1
.
x
);
group
.
vertex
.
push
(
p1
.
y
);
group
.
vertex
.
push
(
p1
.
z
);
group
.
vertex
.
push
(
p2
.
x
);
group
.
vertex
.
push
(
p2
.
y
);
group
.
vertex
.
push
(
p2
.
z
);
currentLayer
.
pathVertex
.
push
(
p1
.
x
);
currentLayer
.
pathVertex
.
push
(
p1
.
y
);
currentLayer
.
pathVertex
.
push
(
p1
.
z
);
currentLayer
.
pathVertex
.
push
(
p2
.
x
);
currentLayer
.
pathVertex
.
push
(
p2
.
y
);
currentLayer
.
pathVertex
.
push
(
p2
.
z
);
}
if
(
p2
.
extruding
)
{
if
(
line
.
extruding
)
{
box
.
min
.
set
(
Math
.
min
(
box
.
min
.
x
,
p2
.
x
),
Math
.
min
(
box
.
min
.
y
,
p2
.
y
),
Math
.
min
(
box
.
min
.
z
,
p2
.
z
)
);
box
.
max
.
set
(
Math
.
max
(
box
.
max
.
x
,
p2
.
x
),
Math
.
max
(
box
.
max
.
y
,
p2
.
y
),
Math
.
max
(
box
.
max
.
z
,
p2
.
z
)
);
...
...
@@ -103,13 +95,13 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
function
delta
(
v1
,
v2
)
{
return
relative
?
v2
:
v2
-
v1
;
return
state
.
relative
?
v2
:
v2
-
v1
;
}
function
absolute
(
v1
,
v2
)
{
return
relative
?
v1
+
v2
:
v2
;
return
state
.
relative
?
v1
+
v2
:
v2
;
}
...
...
@@ -138,17 +130,17 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
if
(
cmd
===
'
G0
'
||
cmd
===
'
G1
'
)
{
var
line
=
{
x
:
args
.
x
!==
undefined
?
absolute
(
currentState
.
x
,
args
.
x
)
:
currentS
tate
.
x
,
y
:
args
.
y
!==
undefined
?
absolute
(
currentState
.
y
,
args
.
y
)
:
currentS
tate
.
y
,
z
:
args
.
z
!==
undefined
?
absolute
(
currentState
.
z
,
args
.
z
)
:
currentS
tate
.
z
,
e
:
args
.
e
!==
undefined
?
absolute
(
currentState
.
e
,
args
.
e
)
:
currentS
tate
.
e
,
f
:
args
.
f
!==
undefined
?
absolute
(
currentState
.
f
,
args
.
f
)
:
currentS
tate
.
f
,
x
:
args
.
x
!==
undefined
?
absolute
(
state
.
x
,
args
.
x
)
:
s
tate
.
x
,
y
:
args
.
y
!==
undefined
?
absolute
(
state
.
y
,
args
.
y
)
:
s
tate
.
y
,
z
:
args
.
z
!==
undefined
?
absolute
(
state
.
z
,
args
.
z
)
:
s
tate
.
z
,
e
:
args
.
e
!==
undefined
?
absolute
(
state
.
e
,
args
.
e
)
:
s
tate
.
e
,
f
:
args
.
f
!==
undefined
?
absolute
(
state
.
f
,
args
.
f
)
:
s
tate
.
f
,
};
//Layer change detection is or made by watching Z, it's made by watching when we extrude at a new Z position
if
(
delta
(
currentS
tate
.
e
,
line
.
e
)
>
0
)
{
if
(
delta
(
s
tate
.
e
,
line
.
e
)
>
0
)
{
line
.
extruding
=
delta
(
currentS
tate
.
e
,
line
.
e
)
>
0
;
line
.
extruding
=
delta
(
s
tate
.
e
,
line
.
e
)
>
0
;
if
(
currentLayer
==
undefined
||
line
.
z
!=
currentLayer
.
z
)
{
...
...
@@ -158,8 +150,8 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
}
addSegment
(
currentS
tate
,
line
);
currentS
tate
=
line
;
addSegment
(
s
tate
,
line
);
s
tate
=
line
;
}
//G2/G3 - Arc Movement ( G2 clock wise and G3 counter clock wise )
else
if
(
cmd
===
'
G2
'
||
cmd
===
'
G3
'
)
{
...
...
@@ -169,24 +161,24 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
//G90: Set to Absolute Positioning
else
if
(
cmd
===
'
G90
'
)
{
relative
=
false
;
state
.
relative
=
false
;
}
//G91: Set to
R
elative Positioning
//G91: Set to
state.r
elative Positioning
else
if
(
cmd
===
'
G91
'
)
{
relative
=
true
;
state
.
relative
=
true
;
}
//G92: Set Position
else
if
(
cmd
===
'
G92
'
)
{
var
line
=
currentS
tate
;
var
line
=
s
tate
;
line
.
x
=
args
.
x
!==
undefined
?
args
.
x
:
line
.
x
;
line
.
y
=
args
.
y
!==
undefined
?
args
.
y
:
line
.
y
;
line
.
z
=
args
.
z
!==
undefined
?
args
.
z
:
line
.
z
;
line
.
e
=
args
.
e
!==
undefined
?
args
.
e
:
line
.
e
;
currentS
tate
=
line
;
s
tate
=
line
;
}
else
{
...
...
@@ -196,30 +188,46 @@ THREE.GCodeLoader.prototype.parse = function ( data ) {
}
}
function
addObject
(
vertex
,
extruding
)
{
var
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
vertex
),
3
)
);
var
segments
=
new
THREE
.
LineSegments
(
geometry
,
extruding
?
extrudingMaterial
:
pathMaterial
);
segments
.
name
=
'
layer
'
+
i
;
object
.
add
(
segments
);
}
var
object
=
new
THREE
.
Object3D
();
object
.
name
=
'
gcode
'
;
for
(
var
i
=
0
;
i
<
layers
.
length
;
i
++
)
{
if
(
this
.
splitLayer
)
{
for
(
var
i
=
0
;
i
<
layers
.
length
;
i
++
)
{
var
layer
=
layers
[
i
];
var
layer
=
layers
[
i
];
addObject
(
layer
.
vertex
,
true
);
addObject
(
layer
.
pathVertex
,
false
);
for
(
var
j
=
0
;
j
<
layer
.
lines
.
length
;
j
++
)
{
}
var
line
=
layer
.
lines
[
j
];
}
else
{
if
(
line
!==
undefined
)
{
var
vertex
=
[],
pathVertex
=
[];
var
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
line
.
vertex
),
3
)
);
for
(
var
i
=
0
;
i
<
layers
.
length
;
i
++
)
{
var
segments
=
new
THREE
.
LineSegments
(
geometry
,
line
.
material
);
segments
.
name
=
'
layer
'
+
i
;
object
.
add
(
segments
);
var
layer
=
layers
[
i
];
}
vertex
=
vertex
.
concat
(
layer
.
vertex
);
pathVertex
=
pathVertex
.
concat
(
layer
.
pathVertex
);
}
addObject
(
vertex
,
true
);
addObject
(
pathVertex
,
false
);
}
object
.
rotation
.
set
(
-
Math
.
PI
/
2
,
0
,
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录