Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
469c2e39
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,发现更多精彩内容 >>
提交
469c2e39
编写于
2月 19, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved ShadowMesh to examples/js/objects by now.
上级
6c4a7877
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
58 deletion
+36
-58
examples/js/objects/ShadowMesh.js
examples/js/objects/ShadowMesh.js
+12
-14
examples/webgl_shadowmesh.html
examples/webgl_shadowmesh.html
+24
-44
未找到文件。
src
/objects/ShadowMesh.js
→
examples/js
/objects/ShadowMesh.js
浏览文件 @
469c2e39
// File:src/objects/ShadowMesh.js
/**
* @author erichlof / http://github.com/erichlof
*
* A shadow Mesh that follows a shadow-casting Mesh in the scene, but is confined to a single plane.
*/
// a shadow Mesh that follows a shadow-casting Mesh in the scene, but is confined to a single plane.
THREE
.
ShadowMesh
=
function
(
mesh
)
{
var
shadowMaterial
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x000000
,
transparent
:
true
,
opacity
:
0.6
,
depthWrite
:
false
}
);
THREE
.
Mesh
.
call
(
this
,
mesh
.
geometry
,
shadowMaterial
);
this
.
meshMatrix
=
mesh
.
matrixWorld
;
this
.
frustumCulled
=
false
;
this
.
matrixAutoUpdate
=
false
;
};
...
...
@@ -32,11 +29,12 @@ THREE.ShadowMesh.prototype.constructor = THREE.ShadowMesh;
THREE
.
ShadowMesh
.
prototype
.
update
=
function
()
{
// based on https://www.opengl.org/archives/resources/features/StencilTalk/tsld021.htm
var
shadowMatrix
=
new
THREE
.
Matrix4
();
return
function
(
plane
,
lightPosition4D
)
{
// based on https://www.opengl.org/archives/resources/features/StencilTalk/tsld021.htm
var
dot
=
plane
.
normal
.
x
*
lightPosition4D
.
x
+
plane
.
normal
.
y
*
lightPosition4D
.
y
+
plane
.
normal
.
z
*
lightPosition4D
.
z
+
...
...
@@ -63,7 +61,7 @@ THREE.ShadowMesh.prototype.update = function () {
sme
[
7
]
=
-
lightPosition4D
.
w
*
plane
.
normal
.
y
;
sme
[
11
]
=
-
lightPosition4D
.
w
*
plane
.
normal
.
z
;
sme
[
15
]
=
dot
-
lightPosition4D
.
w
*
-
plane
.
constant
;
this
.
matrix
.
multiplyMatrices
(
shadowMatrix
,
this
.
meshMatrix
);
};
...
...
examples/webgl_shadowmesh.html
浏览文件 @
469c2e39
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - ShadowMesh
</title>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, user-scalable=no"
>
<meta
charset=
"utf-8"
>
<style>
body
{
background-color
:
rgb
(
0
,
0
,
0
);
margin
:
0
;
padding
:
0
;
overflow
:
hidden
;
}
#lightButton
{
position
:
absolute
;
right
:
20px
;
top
:
20px
;
}
</style>
</head>
<body>
<div
id=
"container"
></div>
<input
id=
"lightButton"
style=
"position:fixed; right:2%; top:4%; font-size:12px;"
type=
"button"
value=
"Switch to PointLight"
onclick=
"lightButtonHandler()"
>
<div
id=
"info"
style=
"position:fixed; left:2%; bottom:7%; font-family:arial; font-type:bold; color:rgb(255,255,255);"
>
three.js webgl - ShadowMesh
</div>
<input
id=
"lightButton"
type=
"button"
value=
"Switch to PointLight"
onclick=
"lightButtonHandler()"
>
<script
src=
"../build/three.min.js"
></script>
<script
src=
"js/objects/ShadowMesh.js"
></script>
<script>
//global variables and objects
var
SCREEN_WIDTH
=
window
.
innerWidth
;
var
SCREEN_HEIGHT
=
window
.
innerHeight
;
...
...
@@ -67,14 +60,11 @@
var
frameTime
=
0
;
var
TWO_PI
=
Math
.
PI
*
2
;
init
();
animate
();
function
init
()
{
renderer
.
setClearColor
(
'
rgb(0,150,255)
'
);
renderer
.
setSize
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
document
.
getElementById
(
"
container
"
).
appendChild
(
renderer
.
domElement
);
...
...
@@ -87,7 +77,7 @@
sunLight
.
position
.
set
(
5
,
7
,
-
1
);
sunLight
.
lookAt
(
scene
.
position
);
scene
.
add
(
sunLight
);
lightPosition4D
.
x
=
sunLight
.
position
.
x
;
lightPosition4D
.
y
=
sunLight
.
position
.
y
;
lightPosition4D
.
z
=
sunLight
.
position
.
z
;
...
...
@@ -109,7 +99,7 @@
arrowPosition3
.
copy
(
sunLight
.
position
).
add
(
new
THREE
.
Vector3
(
0
,
-
0.2
,
0
)
);
arrowHelper3
=
new
THREE
.
ArrowHelper
(
arrowDirection
,
arrowPosition3
,
0.9
,
0xffff00
,
0.25
,
0.08
);
scene
.
add
(
arrowHelper3
);
// LIGHTBULB
var
lightSphereGeometry
=
new
THREE
.
SphereGeometry
(
0.09
);
var
lightSphereMaterial
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
'
rgb(255,255,255)
'
}
);
...
...
@@ -122,7 +112,7 @@
lightHolder
=
new
THREE
.
Mesh
(
lightHolderGeometry
,
lightHolderMaterial
);
scene
.
add
(
lightHolder
);
lightHolder
.
visible
=
false
;
// GROUND
var
groundGeometry
=
new
THREE
.
BoxGeometry
(
30
,
0.01
,
40
);
var
groundMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
'
rgb(0,130,0)
'
}
);
...
...
@@ -159,7 +149,7 @@
torusShadow
=
new
THREE
.
ShadowMesh
(
torus
);
scene
.
add
(
torusShadow
);
// WHITE SPHERE and SPHERE'S SHADOW
var
sphereGeometry
=
new
THREE
.
SphereGeometry
(
0.5
,
20
,
10
);
var
sphereMaterial
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
'
rgb(255,255,255)
'
,
emissive
:
0x222222
}
);
...
...
@@ -169,7 +159,7 @@
sphereShadow
=
new
THREE
.
ShadowMesh
(
sphere
);
scene
.
add
(
sphereShadow
);
// YELLOW PYRAMID and PYRAMID'S SHADOW
var
pyramidGeometry
=
new
THREE
.
CylinderGeometry
(
0
,
0.5
,
2
,
4
);
var
pyramidMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
'
rgb(255,255,0)
'
,
emissive
:
0x440000
,
shading
:
THREE
.
FlatShading
}
);
...
...
@@ -180,13 +170,12 @@
pyramidShadow
=
new
THREE
.
ShadowMesh
(
pyramid
);
scene
.
add
(
pyramidShadow
);
}
//end function init()
}
function
animate
()
{
requestAnimationFrame
(
animate
);
frameTime
=
clock
.
getDelta
();
cube
.
rotation
.
x
+=
1.0
*
frameTime
;
...
...
@@ -197,7 +186,7 @@
torus
.
rotation
.
x
-=
1.0
*
frameTime
;
torus
.
rotation
.
y
-=
1.0
*
frameTime
;
pyramid
.
rotation
.
y
+=
0.5
*
frameTime
;
horizontalAngle
+=
0.5
*
frameTime
;
...
...
@@ -220,13 +209,12 @@
torusShadow
.
update
(
groundPlane
,
lightPosition4D
);
sphereShadow
.
update
(
groundPlane
,
lightPosition4D
);
pyramidShadow
.
update
(
groundPlane
,
lightPosition4D
);
renderer
.
render
(
scene
,
camera
);
}
//end function animate()
}
function
onWindowResize
()
{
...
...
@@ -238,18 +226,14 @@
camera
.
aspect
=
SCREEN_WIDTH
/
SCREEN_HEIGHT
;
camera
.
updateProjectionMatrix
();
document
.
getElementById
(
'
lightButton
'
).
style
.
fontSize
=
SCREEN_WIDTH
*
0.02
+
"
px
"
;
document
.
getElementById
(
'
info
'
).
style
.
fontSize
=
SCREEN_WIDTH
*
0.02
+
"
px
"
;
}
function
lightButtonHandler
()
{
useDirectionalLight
=
!
useDirectionalLight
;
if
(
useDirectionalLight
)
{
renderer
.
setClearColor
(
'
rgb(0,150,255)
'
);
groundMesh
.
material
.
color
.
set
(
'
rgb(0,130,0)
'
);
sunLight
.
position
.
set
(
5
,
7
,
-
1
);
...
...
@@ -269,12 +253,11 @@
document
.
getElementById
(
'
lightButton
'
).
value
=
"
Switch to PointLight
"
;
}
else
{
}
else
{
renderer
.
setClearColor
(
'
rgb(0,0,0)
'
);
groundMesh
.
material
.
color
.
set
(
'
rgb(150,150,150)
'
);
sunLight
.
position
.
set
(
0
,
6
,
-
2
);
sunLight
.
lookAt
(
scene
.
position
);
lightSphere
.
position
.
copy
(
sunLight
.
position
);
...
...
@@ -297,11 +280,8 @@
}
}
// end function lightButtonHandler()
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录