Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
5a871531
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,发现更多精彩内容 >>
提交
5a871531
编写于
2月 06, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplified STL loader example.
上级
51380d20
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
72 addition
and
112 deletion
+72
-112
examples/webgl_loader_stl.html
examples/webgl_loader_stl.html
+72
-112
未找到文件。
examples/webgl_loader_stl.html
浏览文件 @
5a871531
...
...
@@ -39,18 +39,7 @@
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
-
STL loader test by
<a
href=
"https://github.com/aleeper"
>
aleeper
</a>
<p></p>
<div
style=
"display:inline-block; width:310px; text-align: left"
>
<span
id=
"clickBinary"
class=
"button highlight"
>
Binary
</span>
&
nbsp- PR2 head from
<a
href=
"http://www.ros.org/wiki/pr2_description"
>
www.ros.org
</a>
</div>
<p></p>
<div
style=
"display:inline-block; width:310px; text-align: left"
>
<span
id=
"clickASCII"
class=
"button"
>
ASCII
</span>
&
nbsp- A simple CAD part.
</div>
STL loader test by
<a
href=
"https://github.com/aleeper"
>
aleeper
</a>
. PR2 head from
<a
href=
"http://www.ros.org/wiki/pr2_description"
>
www.ros.org
</a>
</div>
<script
src=
"../build/three.min.js"
></script>
...
...
@@ -66,9 +55,7 @@
var
container
,
stats
;
var
camera
,
scene
,
renderer
,
objects
=
[];
var
buttonBinary
,
buttonASCII
;
var
camera
,
cameraTarget
,
scene
,
renderer
;
init
();
animate
();
...
...
@@ -78,52 +65,89 @@
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
// Set up buttons
buttonBinary
=
document
.
getElementById
(
'
clickBinary
'
);
buttonBinary
.
addEventListener
(
"
click
"
,
loadBinaryExample
,
false
);
buttonASCII
=
document
.
getElementById
(
'
clickASCII
'
);
buttonASCII
.
addEventListener
(
"
click
"
,
loadASCIIExample
,
false
);
camera
=
new
THREE
.
PerspectiveCamera
(
35
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
15
);
camera
.
position
.
set
(
3
,
0.5
,
3
);
camera
.
position
.
set
(
3
,
0.15
,
3
);
cameraTarget
=
new
THREE
.
Vector3
(
0
,
-
0.25
,
0
);
scene
=
new
THREE
.
Scene
();
scene
.
fog
=
new
THREE
.
Fog
(
0xffffff
,
2
,
15
);
scene
.
fog
.
color
.
setHSV
(
0.06
,
0.2
,
0.45
);
// Grid
var
size
=
20
,
step
=
0.25
;
// Ground
var
geometry
=
new
THREE
.
Geometry
();
var
material
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0x000000
}
);
var
plane
=
new
THREE
.
Mesh
(
new
THREE
.
PlaneGeometry
(
40
,
40
),
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0x999999
,
color
:
0x999999
,
specular
:
0x101010
}
)
);
plane
.
rotation
.
x
=
-
Math
.
PI
/
2
;
plane
.
position
.
y
=
-
0.5
;
scene
.
add
(
plane
);
for
(
var
i
=
-
size
;
i
<=
size
;
i
+=
step
)
{
plane
.
receiveShadow
=
true
;
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
-
size
,
-
0.04
,
i
)
);
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
size
,
-
0.04
,
i
)
);
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
i
,
-
0.04
,
-
size
)
);
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
i
,
-
0.04
,
size
)
);
// ASCII file
}
var
loader
=
new
THREE
.
STLLoader
();
loader
.
addEventListener
(
'
load
'
,
function
(
event
)
{
var
line
=
new
THREE
.
Line
(
geometry
,
material
,
THREE
.
LinePieces
)
;
line
.
position
.
y
=
-
0.46
;
scene
.
add
(
line
);
var
geometry
=
event
.
content
;
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0xff5533
,
color
:
0xff5533
,
specular
:
0x111111
,
shininess
:
200
}
)
;
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
// Ground
mesh
.
position
.
set
(
0
,
-
0.25
,
0.6
);
mesh
.
rotation
.
set
(
0
,
-
Math
.
PI
/
2
,
0
);
mesh
.
scale
.
set
(
0.5
,
0.5
,
0.5
);
var
plane
=
new
THREE
.
Mesh
(
new
THREE
.
PlaneGeometry
(
40
,
40
),
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0x999999
,
color
:
0x999999
,
specular
:
0x101010
}
)
);
plane
.
rotation
.
x
=
-
Math
.
PI
/
2
;
plane
.
position
.
y
=
-
0.5
;
scene
.
add
(
plane
);
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
plane
.
receiveShadow
=
true
;
scene
.
add
(
mesh
);
}
);
loader
.
load
(
'
./models/stl/ascii/slotted_disk.stl
'
);
// Binary files
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0x555555
,
color
:
0xAAAAAA
,
specular
:
0x111111
,
shininess
:
200
}
);
var
loader
=
new
THREE
.
STLLoader
();
loader
.
addEventListener
(
'
load
'
,
function
(
event
)
{
var
geometry
=
event
.
content
;
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
set
(
0
,
-
0.37
,
-
0.6
);
mesh
.
rotation
.
set
(
-
Math
.
PI
/
2
,
0
,
0
);
mesh
.
scale
.
set
(
2
,
2
,
2
);
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
scene
.
add
(
mesh
);
}
);
loader
.
load
(
'
./models/stl/binary/pr2_head_pan.stl
'
);
var
loader
=
new
THREE
.
STLLoader
();
loader
.
addEventListener
(
'
load
'
,
function
(
event
)
{
var
geometry
=
event
.
content
;
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
set
(
0.136
,
-
0.37
,
-
0.6
);
mesh
.
rotation
.
set
(
-
Math
.
PI
/
2
,
0.3
,
0
);
mesh
.
scale
.
set
(
2
,
2
,
2
);
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
scene
.
add
(
mesh
);
}
);
loader
.
load
(
'
./models/stl/binary/pr2_head_tilt.stl
'
);
// Object
loadBinaryExample
();
// Lights
...
...
@@ -134,7 +158,7 @@
// renderer
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
clearColor
:
0x111111
,
clearAlpha
:
1
,
alpha
:
false
}
);
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
alpha
:
false
}
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
setClearColor
(
scene
.
fog
.
color
,
1
);
...
...
@@ -168,7 +192,7 @@
scene
.
add
(
directionalLight
);
directionalLight
.
castShadow
=
true
;
//directionalLight.shadowCameraVisible = true;
//
directionalLight.shadowCameraVisible = true;
var
d
=
1
;
directionalLight
.
shadowCameraLeft
=
-
d
;
...
...
@@ -179,8 +203,8 @@
directionalLight
.
shadowCameraNear
=
1
;
directionalLight
.
shadowCameraFar
=
4
;
directionalLight
.
shadowMapWidth
=
2048
;
directionalLight
.
shadowMapHeight
=
2048
;
directionalLight
.
shadowMapWidth
=
1024
;
directionalLight
.
shadowMapHeight
=
1024
;
directionalLight
.
shadowBias
=
-
0.005
;
directionalLight
.
shadowDarkness
=
0.15
;
...
...
@@ -196,70 +220,6 @@
}
function
loadBinaryExample
()
{
buttonBinary
.
className
=
"
button highlight
"
;
buttonASCII
.
className
=
"
button
"
;
// Clear out old objects
for
(
var
i
=
0
;
i
<
objects
.
length
;
i
++
)
scene
.
remove
(
objects
[
i
]);
var
scale
=
2.0
;
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0x555555
,
color
:
0xAAAAAA
,
specular
:
0x111111
,
shininess
:
200
}
);
loadFile
(
'
./models/stl/binary/pr2_head_pan.stl
'
,
scale
,
new
THREE
.
Vector3
(
0
,
0
,
0
),
new
THREE
.
Vector3
(
-
Math
.
PI
/
2
,
0
,
0
),
material
);
loadFile
(
'
./models/stl/binary/pr2_head_tilt.stl
'
,
scale
,
new
THREE
.
Vector3
(
0.068
*
scale
,
0
,
0
),
new
THREE
.
Vector3
(
-
Math
.
PI
/
2
,
0.3
,
0
),
material
);
}
function
loadASCIIExample
()
{
buttonBinary
.
className
=
"
button
"
;
buttonASCII
.
className
=
"
button highlight
"
;
// Clear out old objects
for
(
var
i
=
0
;
i
<
objects
.
length
;
i
++
)
scene
.
remove
(
objects
[
i
]);
loadFile
(
'
./models/stl/ascii/slotted_disk.stl
'
,
1.0
,
null
,
new
THREE
.
Vector3
(
-
Math
.
PI
/
2
,
0
,
0
));
}
function
loadFile
(
filename
,
scale
,
offset
,
rotate
,
material
)
{
if
(
scale
==
null
)
scale
=
1.0
;
if
(
offset
==
null
)
offset
=
new
THREE
.
Vector3
(
0
,
0
,
0
);
if
(
rotate
==
null
)
rotate
=
new
THREE
.
Vector3
(
0
,
0
,
0
);
if
(
material
==
null
)
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0xff5533
,
color
:
0xff5533
,
specular
:
0x111111
,
shininess
:
200
}
);
var
loader
=
new
THREE
.
STLLoader
();
loader
.
addEventListener
(
'
load
'
,
function
(
event
)
{
var
geometry
=
event
.
content
;
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
scale
=
new
THREE
.
Vector3
(
scale
,
scale
,
scale
);
mesh
.
position
=
offset
;
mesh
.
rotation
=
rotate
;
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
objects
.
push
(
mesh
);
scene
.
add
(
objects
[
objects
.
length
-
1
]
);
}
);
loader
.
load
(
filename
);
}
function
animate
()
{
requestAnimationFrame
(
animate
);
...
...
@@ -276,7 +236,7 @@
camera
.
position
.
x
=
Math
.
cos
(
timer
)
*
3
;
camera
.
position
.
z
=
Math
.
sin
(
timer
)
*
3
;
camera
.
lookAt
(
scene
.
position
);
camera
.
lookAt
(
cameraTarget
);
renderer
.
render
(
scene
,
camera
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录