NX插件
送教程
DoTeam
培训报名
AI · CAD · PLM
首页
Portal
社区
论坛
NX技术
TC技术
Catia技术
自研系统
更多
登录
NX Toolkits 「PLM之家插件」
Castsim「铸造PLM系统」
EchoCAD「大模型CAD」
视频在线
实践教程
前沿咨询
高清购买
国产软件
PLM之家PLMHome-工业软件践行者,大模型驱动工业生态建设
»
社区
›
PLM之家-自主工业软件/开源软件借鉴
›
AI 人工智能学习专区
›
Threejs 增加阴影的方法
返回列表
发新帖
查看:
2282
|
回复:
0
[前端框架]
Threejs 增加阴影的方法
[复制链接]
admin
admin
当前离线
积分
60
6
主题
4
回帖
60
积分
管理员
积分
60
发消息
发表于 2020-2-5 14:27:14
|
显示全部楼层
|
阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要
登录
才可以下载或查看,没有账号?
注册
×
2 I* M B P% c2 q
2 Z! i* e5 D- k" {+ V9 o- E
官方提供的实例如下
! ~5 R! x4 `& s, O/ }& b' r
/ J: \+ |& a$ K! K" k
1。 首先在Scene里面激活 渲染 ShadowMap
) |4 I' I9 g" L- W" h j( R
//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
4 M8 t. X8 a* `% u% u
! M! G) K7 q2 e
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
);
) J5 ?2 n1 ?+ l: P
6 s0 \+ o0 g/ t/ G- _7 j
//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
. Q b5 M- Y) E0 ?- t) T5 P$ K
1 B1 O l9 j( g" P: ~
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
);
' ~# G$ _% q2 i1 L) J6 s6 p" [: E
! l( H3 x+ A9 h3 I
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
);
7 N$ y9 w0 ^# k) C6 y/ J4 y1 L
5 Z2 N0 f' v+ g3 @3 B X/ j$ t
& f* L4 ~! y. H# r% E5 B
3 e1 k/ y2 X! h, G
5 V9 t3 t5 y, o$ X
效果如下!
6 Q, k! H k( c7 J4 k: V$ A: ]
. G& c4 w3 [6 G3 e" D% r
5 ]; w1 d# D" u
9 ^0 L: H! h6 F& J5 x8 b
上海点团信息科技有限公司,承接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客服
返回顶部
快速回复
返回顶部
返回列表