Skip to content

Commit 9b4b82c

Browse files
committed
u
1 parent f1dbdb8 commit 9b4b82c

File tree

8 files changed

+351
-272
lines changed

8 files changed

+351
-272
lines changed

README-zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ Configuration file: E:/GitWorkSpace/blog/_config.yml
323323

324324
感谢捐赠的小伙伴!!!
325325

326+
* 2017.04.01 收到 Elvin Zeng ¥6.66
326327
* 2017.03.13 收到 微信用户 ¥6.66
327328
* 2017.03.04 收到 史莱姆 ¥9.90
328329
* 2017.03.02 收到 梦想小熊 ¥6.66

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ You can also donate me for a coffee, and I'll do better. Thanks.
312312

313313
Thanks these friends!!!
314314

315+
* 2017.04.01 received Elvin Zeng ¥6.66
315316
* 2017.03.13 received Wechat user ¥6.66
316317
* 2017.03.04 received 史莱姆 ¥9.90
317318
* 2017.03.02 received 梦想小熊 ¥6.66

_drafts/CommonJS.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

_drafts/angularJS-directive.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

_drafts/threeJS-light-shadow.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
layout: post
3+
title: "three.js 中的光与影"
4+
categories: JavaScript
5+
tags: threeJS webGL
6+
---
7+
8+
* content
9+
{:toc}
10+
11+
在了解了 three.js 中渲染器、场景、相机、几何体等基本知识后,我们来研究一下 three.js 中的光与影。
12+
13+
14+
本文是根据百度前端学院的任务安排进行探索和研究的。算是 [WebGL No. 2 - 光与影](http://ife.baidu.com/course/detail/id/28) 的学习笔记吧。
15+
16+
- 任务描述
17+
- 学习《Three.js 入门指南》第 8 章光与影;
18+
- 理解不同类型灯光的区别和适用场景;
19+
- 学会为场景添加合适的灯光;
20+
- 思考灯光的位置对哪些类型的灯光是无所谓的,以及为什么;
21+
- 思考为什么有些灯光无法形成阴影;
22+
- 在第 1 题场景的基础上,增加光照效果;
23+
- 如果你没做第 1 题,也可以随便在场景中创建一些物体;
24+
- 为物体设置合适的材质(预习第 4 章),使得物体的亮度根据光照有所区别
25+
- 创建一个地板平面,并将小车投影到地板上
26+
- 尝试并思考,一个物体(比如甜甜圈)如何将阴影投射到自身(Self-Shadow,自阴影);
27+
- 实现软阴影的效果(即阴影的边缘有明暗的渐变)。
28+
29+
##
30+
31+
构造函数:
32+
33+
```js
34+
Light(color, intensity)
35+
```
36+
37+
- 颜色 color - (optional) hexadecimal color of the light. Default is 0xffffff (white).
38+
- 强度 intensity - (optional) numeric value of the light's strength/intensity. Default is 1.
39+
40+
光的基类,被其他光类所继承。
41+
42+
### 环境光
43+
44+
AmbientLight ['æmbɪənt] 平均照亮场景中的所有物体。
45+
46+
无方向,不产生影子。
47+
48+
```js
49+
var light = new THREE.AmbientLight(0x404040); // soft white light
50+
scene.add(light);
51+
```
52+
53+
### 点光源
54+
55+
PointLight 从一个孤立的点向各个方向发射。没有遮盖的灯泡就是一个典型的例子。
56+
57+
可以产生影子。
58+
59+
```js
60+
var light = new THREE.PointLight(0xff0000, 1, 100);
61+
light.position.set(50, 50, 50);
62+
scene.add(light);
63+
```
64+
65+
### 平行光
66+
67+
DirectionalLight 有特定方向的光。光线平行,无限远。用于模拟日光。太阳足够远,可以认为是无限远的,并且发射的光线是平行的。
68+
69+
可以产生影子。[平行光的影子 DirectionalLightShadow](https://threejs.org/docs/index.html#Reference/Lights.Shadows/DirectionalLightShadow)
70+
71+
```js
72+
// White directional light at half intensity shining from the top.
73+
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
74+
scene.add(directionalLight);
75+
```
76+
77+
- 属性
78+
79+
- `.position`
80+
81+
This is set equal to Object3D.DefaultUp (0, 1, 0), so that the light shines from the top down.
82+
83+
光线从平面 (0, 1, 0) 的法向射出。
84+
85+
86+
### 聚光灯
87+
88+
SpotLight 光从孤立点射出,沿着一个椎体向远处延伸。
89+
90+
可以产生影子。
91+
92+
```js
93+
// white spotlight shining from the side, casting a shadow
94+
95+
var spotLight = new THREE.SpotLight(0xffffff);
96+
spotLight.position.set(100, 1000, 100);
97+
98+
spotLight.castShadow = true;
99+
100+
spotLight.shadow.mapSize.width = 1024;
101+
spotLight.shadow.mapSize.height = 1024;
102+
103+
spotLight.shadow.camera.near = 500;
104+
spotLight.shadow.camera.far = 4000;
105+
spotLight.shadow.camera.fov = 30;
106+
107+
scene.add(spotLight);
108+
```
109+
110+
### 半球光
111+
112+
HemisphereLight 光源位于场景上方,光线颜色从天空过度到地面。
113+
114+
不能产生影子。
115+
116+
```js
117+
var light = new THREE.HemisphereLight(0xffffbb, 0x080820, 1);
118+
scene.add(light);
119+
```
120+
121+
### 矩形光
122+
123+
RectAreaLight 从一个矩形面均匀发射的光。常被用于明亮的窗户,
124+
125+
## 影子

_sass/_reset.scss

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ h3,
2121
h4,
2222
h5,
2323
h6 {
24-
font-weight: normal;
24+
font-weight: 400;
2525
}
2626
html {
2727
height: 100%;
@@ -49,30 +49,28 @@ hr {
4949

5050
///////////
5151
h1 {
52-
font-size: 36px;
52+
font-size: 30px;
5353
}
5454
h2 {
55-
font-size: 30px;
55+
font-size: 26px;
5656
border-bottom: 1px solid #eee;
57+
margin: 50px 0 25px;
5758
}
5859
h3 {
59-
font-size: 26px;
60+
font-size: 23px;
61+
margin: 50px 0 20px;
6062
}
6163
h4 {
62-
font-size: 22px;
64+
font-size: 19px;
65+
margin: 30px 0 10px;
6366
}
6467
h5 {
65-
font-size: 20px;
66-
}
67-
h6 {
68-
font-size: 18px;
68+
font-size: 17px;
69+
margin: 20px 0 10px;
6970
}
70-
h2,
71-
h3,
72-
h4,
73-
h5,
7471
h6 {
75-
margin: 20px 0 10px;
72+
font-size: 16px;
73+
margin: 10px 0 5px;
7674
}
7775
blockquote {
7876
color: #444;

js/main.js

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,50 @@
88
* clickMenu
99
*/
1010
(function() {
11-
if (window.innerWidth <= 770) {
12-
var menuBtn = document.querySelector('#headerMenu')
13-
var nav = document.querySelector('#headerNav')
14-
menuBtn.onclick = function(e) {
15-
e.stopPropagation()
16-
if (menuBtn.classList.contains('active')) {
17-
menuBtn.classList.remove('active')
18-
nav.classList.remove('nav-show')
19-
} else {
20-
nav.classList.add('nav-show')
21-
menuBtn.classList.add('active')
22-
}
23-
}
24-
document.querySelector('body').addEventListener('click', function() {
25-
nav.classList.remove('nav-show')
26-
menuBtn.classList.remove('active')
27-
})
11+
if (window.innerWidth <= 770) {
12+
var menuBtn = document.querySelector('#headerMenu')
13+
var nav = document.querySelector('#headerNav')
14+
menuBtn.onclick = function(e) {
15+
e.stopPropagation()
16+
if (menuBtn.classList.contains('active')) {
17+
menuBtn.classList.remove('active')
18+
nav.classList.remove('nav-show')
19+
} else {
20+
nav.classList.add('nav-show')
21+
menuBtn.classList.add('active')
22+
}
2823
}
24+
document.querySelector('body').addEventListener('click', function() {
25+
nav.classList.remove('nav-show')
26+
menuBtn.classList.remove('active')
27+
})
28+
}
2929
}());
3030

31-
3231
//////////////////////////back to top////////////////////////////
3332
(function() {
34-
var backToTop = document.querySelector('.back-to-top')
35-
var backToTopA = document.querySelector('.back-to-top a')
36-
// console.log(backToTop);
37-
window.addEventListener('scroll',function () {
38-
39-
40-
// 页面顶部滚进去的距离
41-
var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
42-
43-
if (scrollTop > 200) {
44-
backToTop.classList.add('back-to-top-show')
45-
} else {
46-
backToTop.classList.remove('back-to-top-show')
47-
}
48-
})
33+
var backToTop = document.querySelector('.back-to-top')
34+
var backToTopA = document.querySelector('.back-to-top a')
35+
// console.log(backToTop);
36+
window.addEventListener('scroll', function() {
37+
38+
// 页面顶部滚进去的距离
39+
var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop)
40+
41+
if (scrollTop > 200) {
42+
backToTop.classList.add('back-to-top-show')
43+
} else {
44+
backToTop.classList.remove('back-to-top-show')
45+
}
46+
})
4947

50-
// backToTopA.addEventListener('click',function (e) {
51-
// e.preventDefault()
52-
// window.scrollTo(0,0)
53-
// })
48+
// backToTopA.addEventListener('click',function (e) {
49+
// e.preventDefault()
50+
// window.scrollTo(0,0)
51+
// })
5452
}());
5553

56-
5754
//////////////////////////hover on demo//////////////////////////////
5855
(function() {
59-
var demoItems = document.querySelectorAll('.grid-item')
56+
var demoItems = document.querySelectorAll('.grid-item')
6057
}());

0 commit comments

Comments
 (0)