Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
16c1921e
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
提交
16c1921e
编写于
8月 16, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Trying to make STL example look less bad.
上级
d0cf6dd6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
31 deletion
+71
-31
examples/webgl_loader_stl.html
examples/webgl_loader_stl.html
+71
-31
未找到文件。
examples/webgl_loader_stl.html
浏览文件 @
16c1921e
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl -
collada
</title>
<title>
three.js webgl -
STL
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
...
...
@@ -29,7 +29,7 @@
<body>
<div
id=
"info"
>
<a
href=
"http://github.com/mrdoob/three.js"
target=
"_blank"
>
three.js
</a>
-
STL loader test by
<a
href=
"https://github.com/aleeper"
>
aleeper
</a>
STL loader test by
<a
href=
"https://github.com/aleeper"
>
aleeper
</a>
</div>
<script
src=
"../build/three.min.js"
></script>
...
...
@@ -46,7 +46,6 @@
var
container
,
stats
;
var
camera
,
scene
,
renderer
,
objects
;
var
particleLight
,
pointLight
;
init
();
animate
();
...
...
@@ -56,17 +55,20 @@
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
2000
);
camera
.
position
.
set
(
2
,
2
,
3
);
camera
=
new
THREE
.
PerspectiveCamera
(
35
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
15
);
camera
.
position
.
set
(
3
,
0.5
,
3
);
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
=
14
,
step
=
1
;
var
size
=
20
,
step
=
0.25
;
var
geometry
=
new
THREE
.
Geometry
();
var
material
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0x
cccccc
,
opacity
:
0.2
}
);
var
material
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0x
000000
}
);
for
(
var
i
=
-
size
;
i
<=
size
;
i
+=
step
)
{
...
...
@@ -79,43 +81,60 @@
}
var
line
=
new
THREE
.
Line
(
geometry
,
material
,
THREE
.
LinePieces
);
line
.
position
.
y
=
-
0.46
;
scene
.
add
(
line
);
// Ground
var
plane
=
new
THREE
.
Mesh
(
new
THREE
.
PlaneGeometry
(
40
,
40
),
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0x999999
,
color
:
0x999999
,
specular
:
0x101010
,
perPixel
:
true
}
)
);
plane
.
rotation
.
x
=
-
Math
.
PI
/
2
;
plane
.
position
.
y
=
-
0.5
;
scene
.
add
(
plane
);
plane
.
receiveShadow
=
true
;
// Object
var
loader
=
new
THREE
.
STLLoader
();
loader
.
addEventListener
(
'
load
'
,
function
(
event
)
{
var
geometry
=
event
.
content
;
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0xff0000
,
color
:
0xff0000
,
specular
:
0xffffff
}
);
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
ambient
:
0xff5533
,
color
:
0xff5533
,
specular
:
0x111111
,
shininess
:
200
,
perPixel
:
true
}
);
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
scene
.
add
(
new
THREE
.
Mesh
(
geometry
,
material
)
);
scene
.
add
(
mesh
);
}
);
loader
.
load
(
'
./models/stl/slotted_disk.stl
'
);
particleLight
=
new
THREE
.
Mesh
(
new
THREE
.
SphereGeometry
(
4
,
8
,
8
),
new
THREE
.
MeshBasicMaterial
(
{
color
:
0xffffff
}
)
);
scene
.
add
(
particleLight
);
// Lights
scene
.
add
(
new
THREE
.
AmbientLight
(
0x
cccccc
)
);
scene
.
add
(
new
THREE
.
AmbientLight
(
0x
777777
)
);
var
directionalLight
=
new
THREE
.
DirectionalLight
(
0xeeeeee
);
directionalLight
.
position
.
x
=
Math
.
random
()
-
0.5
;
directionalLight
.
position
.
y
=
Math
.
random
()
-
0.5
;
directionalLight
.
position
.
z
=
Math
.
random
()
-
0.5
;
directionalLight
.
position
.
normalize
();
scene
.
add
(
directionalLight
);
addShadowedLight
(
1
,
1
,
1
,
0xffffff
,
1.35
);
addShadowedLight
(
0.5
,
1
,
-
1
,
0xffaa00
,
1
);
pointLight
=
new
THREE
.
PointLight
(
0xffffff
,
4
);
pointLight
.
position
=
particleLight
.
position
;
scene
.
add
(
pointLight
);
// renderer
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
clearColor
:
0x111111
,
clearAlpha
:
1
,
alpha
:
false
}
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
setClearColor
(
scene
.
fog
.
color
,
1
);
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
renderer
.
physicallyBasedShading
=
true
;
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMapCullFrontFaces
=
false
;
container
.
appendChild
(
renderer
.
domElement
);
// stats
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
...
...
@@ -127,6 +146,32 @@
}
function
addShadowedLight
(
x
,
y
,
z
,
color
,
intensity
)
{
var
directionalLight
=
new
THREE
.
DirectionalLight
(
color
,
intensity
);
directionalLight
.
position
.
set
(
x
,
y
,
z
)
scene
.
add
(
directionalLight
);
directionalLight
.
castShadow
=
true
;
//directionalLight.shadowCameraVisible = true;
var
d
=
1
;
directionalLight
.
shadowCameraLeft
=
-
d
;
directionalLight
.
shadowCameraRight
=
d
;
directionalLight
.
shadowCameraTop
=
d
;
directionalLight
.
shadowCameraBottom
=
-
d
;
directionalLight
.
shadowCameraNear
=
1
;
directionalLight
.
shadowCameraFar
=
4
;
directionalLight
.
shadowMapWidth
=
2048
;
directionalLight
.
shadowMapHeight
=
2048
;
directionalLight
.
shadowBias
=
-
0.005
;
directionalLight
.
shadowDarkness
=
0.15
;
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
...
...
@@ -151,16 +196,11 @@
var
timer
=
Date
.
now
()
*
0.0005
;
camera
.
position
.
x
=
Math
.
cos
(
timer
)
*
3
;
camera
.
position
.
y
=
1
;
camera
.
position
.
z
=
Math
.
sin
(
timer
)
*
3
;
camera
.
position
.
x
=
Math
.
cos
(
timer
)
*
5
;
camera
.
position
.
z
=
Math
.
sin
(
timer
)
*
5
;
camera
.
lookAt
(
scene
.
position
);
particleLight
.
position
.
x
=
Math
.
sin
(
timer
*
4
)
*
3009
;
particleLight
.
position
.
y
=
Math
.
cos
(
timer
*
5
)
*
4000
;
particleLight
.
position
.
z
=
Math
.
cos
(
timer
*
4
)
*
3009
;
renderer
.
render
(
scene
,
camera
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录