NX插件
送教程
DoTeam
培训报名
AI · CAD · PLM
首页
Portal
社区
论坛
NX技术
TC技术
Catia技术
自研系统
更多
登录
NX Toolkits
Castsim
EchoCAD
国产软件
教程
咨询
PLM之家PLMHome-工业软件践行者,大模型驱动工业生态建设
»
社区
›
PLM之家-自主工业软件/开源软件借鉴
›
AI 人工智能学习专区
›
Threejs 增加阴影的方法
返回列表
发新帖
查看:
2147
|
回复:
0
[前端框架]
Threejs 增加阴影的方法
[复制链接]
admin
admin
当前离线
积分
38
4
主题
3
回帖
38
积分
管理员
积分
38
发消息
发表于 2020-2-5 14:27:14
|
显示全部楼层
|
阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要
登录
才可以下载或查看,没有账号?
注册
×
. e! d8 T1 @( Z# T
' R0 c* I% b8 J; W7 {
官方提供的实例如下
# ]; O5 s' P" o5 L) _6 f% ?2 y
0 L o. v0 m; T; R) \- E9 t
1。 首先在Scene里面激活 渲染 ShadowMap
3 H4 c9 h7 x7 c: |; H4 v$ d
//Create a WebGLRenderer and turn on shadows in the renderer
var
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
.
shadowMap
.
enabled
=
true
;
renderer
.
shadowMap
.
type
=
THREE
.
PCFSoftShadowMap
;
// default THREE.PCFShadowMap
5 j% G- q/ k; f+ B
2 w) e/ G# q% O7 G4 d/ X) `8 i
2。 创建平行光,并可以投射Shadow
//Create a DirectionalLight and turn on shadows for the light
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
,
1
,
100
);
light
.
position
.
set
(
0
,
1
,
0
);
//default; light shining from top
light
.
castShadow
=
true
;
// default false
scene
.
add
(
light
);
# ?/ E* D9 f) ?: L
6 |2 h* J8 x4 G
//Set up shadow properties for the light
light
.
shadow
.
mapSize
.
width
=
512
;
// default
light
.
shadow
.
mapSize
.
height
=
512
;
// default
light
.
shadow
.
camera
.
near
=
0.5
;
// default
light
.
shadow
.
camera
.
far
=
500
;
// default
# H' c3 |5 I3 r" j" V, @
L' o0 z. ]/ O' z4 E: L
3. 创建接受shadow的物体
//Create a sphere that cast shadows (but does not receive them)
var
sphereGeometry
=
new
THREE
.
SphereBufferGeometry
(
5
,
32
,
32
);
var
sphereMaterial
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0xff0000
}
);
var
sphere
=
new
THREE
.
Mesh
(
sphereGeometry
,
sphereMaterial
);
sphere
.
castShadow
=
true
;
//default is false
sphere
.
receiveShadow
=
false
;
//default
scene
.
add
(
sphere
);
" I$ w# p6 J' ]5 Y3 n3 Z6 v
1 E6 r+ m4 T: F
4. 创建获取投影的平面
//Create a plane that receives shadows (but does not cast them)
var
planeGeometry
=
new
THREE
.
PlaneBufferGeometry
(
20
,
20
,
32
,
32
);
var
planeMaterial
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x00ff00
}
)
var
plane
=
new
THREE
.
Mesh
(
planeGeometry
,
planeMaterial
);
plane
.
receiveShadow
=
true
;
scene
.
add
(
plane
);
//Create a helper for the shadow camera (optional)
var
helper
=
new
THREE
.
CameraHelper
(
light
.
shadow
.
camera
);
scene
.
add
(
helper
);
$ G/ t8 s" T/ c9 k: ?0 g* R+ U
( d) t( r. c& ~* `
% |5 ^$ ]% q# N% M/ p
. v( q+ y/ Y5 H1 H
0 ?4 B% ]% L. x4 [
效果如下!
7 \7 X5 @! x" {' ~$ G9 T
$ ?# e+ B8 n+ K8 y% j. v
" m. c: p3 s* B% {8 Z$ t0 G: i
) b* L( d! _' N4 U
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复
使用道具
举报
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
在本版发帖
关注公众号
QQ客服
返回顶部
快速回复
返回顶部
返回列表