Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
9c68545b
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,发现更多精彩内容 >>
提交
9c68545b
编写于
4月 08, 2011
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'empaempa/master' into experimental
上级
b2d39cf8
d8e5678e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
164 addition
and
18 deletion
+164
-18
src/objects/ShadowVolume.js
src/objects/ShadowVolume.js
+158
-13
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+4
-4
src/renderers/WebGLShaders.js
src/renderers/WebGLShaders.js
+2
-1
未找到文件。
src/objects/ShadowVolume.js
浏览文件 @
9c68545b
...
...
@@ -2,12 +2,20 @@
* @author mikael emtinger / http://gomo.se/
*/
THREE
.
ShadowVolume
=
function
(
mesh
,
isStatic
)
{
THREE
.
ShadowVolume
=
function
(
mesh
OrGeometry
,
isStatic
)
{
THREE
.
Mesh
.
call
(
this
,
mesh
.
geometry
,
isStatic
?
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
:
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
);
mesh
.
addChild
(
this
);
this
.
calculateShadowVolumeGeometry
(
mesh
.
geometry
);
if
(
meshOrGeometry
instanceof
THREE
.
Mesh
)
{
THREE
.
Mesh
.
call
(
this
,
meshOrGeometry
.
geometry
,
isStatic
?
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
:
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
);
meshOrGeometry
.
addChild
(
this
);
}
else
{
THREE
.
Mesh
.
call
(
this
,
meshOrGeometry
,
isStatic
?
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
:
[
new
THREE
.
ShadowVolumeDynamicMaterial
()
]
);
}
this
.
calculateShadowVolumeGeometry
();
};
...
...
@@ -17,10 +25,153 @@ THREE.ShadowVolume.prototype.supr = THREE.Mesh.prototype;
/*
* Calculate
Geometry
* Calculate
Shadow Faces
*/
THREE
.
ShadowVolume
.
prototype
.
calculateShadowVolumeGeometry
=
function
(
originalGeometry
)
{
THREE
.
ShadowVolume
.
prototype
.
calculateShadowVolumeGeometry
=
function
()
{
if
(
this
.
geometry
.
edges
&&
this
.
geometry
.
edges
.
length
)
{
var
f
,
fl
,
face
,
faceA
,
faceB
,
faceAIndex
,
faceBIndex
,
vertexA
,
vertexB
;
var
faceACombination
,
faceBCombination
;
var
faceAvertexAIndex
,
faceAvertexBIndex
,
faceBvertexAIndex
,
faceBvertexBIndex
;
var
e
,
el
,
edge
,
temp
;
var
newGeometry
=
new
THREE
.
Geometry
();
var
vertices
=
newGeometry
.
vertices
=
this
.
geometry
.
vertices
;
var
faces
=
newGeometry
.
faces
=
this
.
geometry
.
faces
;
var
edges
=
newGeometry
.
egdes
=
this
.
geometry
.
edges
;
var
edgeFaces
=
newGeometry
.
edgeFaces
=
[];
var
vertexOffset
=
0
;
var
vertexOffsetPerFace
=
[];
for
(
f
=
0
,
fl
=
faces
.
length
;
f
<
fl
;
f
++
)
{
face
=
faces
[
f
];
// calculate faces vertex offset
vertexOffsetPerFace
.
push
(
vertexOffset
);
vertexOffset
+=
face
instanceof
THREE
.
Face3
?
3
:
4
;
// set vertex normals to face normal
face
.
vertexNormals
[
0
]
=
face
.
normal
;
face
.
vertexNormals
[
1
]
=
face
.
normal
;
face
.
vertexNormals
[
2
]
=
face
.
normal
;
if
(
face
instanceof
THREE
.
Face4
)
face
.
vertexNormals
[
3
]
=
face
.
normal
;
}
// setup edge faces
for
(
e
=
0
,
el
=
edges
.
length
;
e
<
el
;
e
++
)
{
edge
=
edges
[
e
];
faceA
=
edge
.
faces
[
0
];
faceB
=
edge
.
faces
[
1
];
faceAIndex
=
edge
.
faceIndices
[
0
];
faceBIndex
=
edge
.
faceIndices
[
1
];
vertexA
=
edge
.
vertexIndices
[
0
];
vertexB
=
edge
.
vertexIndices
[
1
];
// find combination and processed vertex index (vertices are split up by renderer)
if
(
faceA
.
a
===
vertexA
)
{
faceACombination
=
"
a
"
;
faceAvertexAIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
0
;
}
else
if
(
faceA
.
b
===
vertexA
)
{
faceACombination
=
"
b
"
;
faceAvertexAIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
1
;
}
else
if
(
faceA
.
c
===
vertexA
)
{
faceACombination
=
"
c
"
;
faceAvertexAIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
2
;
}
else
if
(
faceA
.
d
===
vertexA
)
{
faceACombination
=
"
d
"
;
faceAvertexAIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
3
;
}
if
(
faceA
.
a
===
vertexB
)
{
faceACombination
+=
"
a
"
;
faceAvertexBIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
0
;
}
else
if
(
faceA
.
b
===
vertexB
)
{
faceACombination
+=
"
b
"
;
faceAvertexBIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
1
;
}
else
if
(
faceA
.
c
===
vertexB
)
{
faceACombination
+=
"
c
"
;
faceAvertexBIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
2
;
}
else
if
(
faceA
.
d
===
vertexB
)
{
faceACombination
+=
"
d
"
;
faceAvertexBIndex
=
vertexOffsetPerFace
[
faceAIndex
]
+
3
;
}
if
(
faceB
.
a
===
vertexA
)
{
faceBCombination
=
"
a
"
;
faceBvertexAIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
0
;
}
else
if
(
faceB
.
b
===
vertexA
)
{
faceBCombination
=
"
b
"
;
faceBvertexAIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
1
;
}
else
if
(
faceB
.
c
===
vertexA
)
{
faceBCombination
=
"
c
"
;
faceBvertexAIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
2
;
}
else
if
(
faceB
.
d
===
vertexA
)
{
faceBCombination
=
"
d
"
;
faceBvertexAIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
3
;
}
if
(
faceB
.
a
===
vertexB
)
{
faceBCombination
+=
"
a
"
;
faceBvertexBIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
0
;
}
else
if
(
faceB
.
b
===
vertexB
)
{
faceBCombination
+=
"
b
"
;
faceBvertexBIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
1
;
}
else
if
(
faceB
.
c
===
vertexB
)
{
faceBCombination
+=
"
c
"
;
faceBvertexBIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
2
;
}
else
if
(
faceB
.
d
===
vertexB
)
{
faceBCombination
+=
"
d
"
;
faceBvertexBIndex
=
vertexOffsetPerFace
[
faceBIndex
]
+
3
;
}
if
(
faceACombination
===
"
ac
"
||
faceACombination
===
"
ad
"
||
faceACombination
===
"
ca
"
||
faceACombination
===
"
da
"
)
{
if
(
faceAvertexAIndex
>
faceAvertexBIndex
)
{
temp
=
faceAvertexAIndex
;
faceAvertexAIndex
=
faceAvertexBIndex
;
faceAvertexBIndex
=
temp
;
}
}
else
{
if
(
faceAvertexAIndex
<
faceAvertexBIndex
)
{
temp
=
faceAvertexAIndex
;
faceAvertexAIndex
=
faceAvertexBIndex
;
faceAvertexBIndex
=
temp
;
}
}
if
(
faceBCombination
===
"
ac
"
||
faceBCombination
===
"
ad
"
||
faceBCombination
===
"
ca
"
||
faceBCombination
===
"
da
"
)
{
if
(
faceBvertexAIndex
>
faceBvertexBIndex
)
{
temp
=
faceBvertexAIndex
;
faceBvertexAIndex
=
faceBvertexBIndex
;
faceBvertexBIndex
=
temp
;
}
}
else
{
if
(
faceBvertexAIndex
<
faceBvertexBIndex
)
{
temp
=
faceBvertexAIndex
;
faceBvertexAIndex
=
faceBvertexBIndex
;
faceBvertexBIndex
=
temp
;
}
}
face
=
new
THREE
.
Face4
(
faceAvertexAIndex
,
faceAvertexBIndex
,
faceBvertexAIndex
,
faceBvertexBIndex
);
face
.
normal
.
set
(
1
,
0
,
0
);
edgeFaces
.
push
(
face
);
}
this
.
geometry
=
newGeometry
;
}
else
{
this
.
calculateShadowVolumeGeometryWithoutEdgeInfo
(
this
.
geometry
);
}
}
THREE
.
ShadowVolume
.
prototype
.
calculateShadowVolumeGeometryWithoutEdgeInfo
=
function
(
originalGeometry
)
{
// create geometry
...
...
@@ -103,11 +254,6 @@ THREE.ShadowVolume.prototype.calculateShadowVolumeGeometry = function( originalG
};
/*
* Faces share edge?
*/
THREE
.
ShadowVolume
.
prototype
.
facesShareEdge
=
function
(
vertices
,
faceA
,
faceB
)
{
var
indicesA
,
...
...
@@ -199,4 +345,3 @@ THREE.ShadowVolume.prototype.facesShareEdge = function( vertices, faceA, faceB )
return
undefined
;
};
src/renderers/WebGLRenderer.js
浏览文件 @
9c68545b
...
...
@@ -748,7 +748,7 @@ THREE.WebGLRenderer = function ( parameters ) {
obj_skinVerticesB
=
geometry
.
skinVerticesB
,
obj_skinIndices
=
geometry
.
skinIndices
,
obj_skinWeights
=
geometry
.
skinWeights
,
obj_edgeFaces
=
geometry
.
edgeFaces
,
obj_edgeFaces
=
object
instanceof
THREE
.
ShadowVolume
?
geometry
.
edgeFaces
:
undefined
;
morphTargets
=
geometry
.
morphTargets
;
...
...
@@ -2413,9 +2413,9 @@ THREE.WebGLRenderer = function ( parameters ) {
var
dirLight
=
m_uniforms
.
directionalLightDirection
.
value
;
dirLight
[
0
]
=
-
lights
.
position
.
x
;
dirLight
[
1
]
=
-
lights
.
position
.
y
;
dirLight
[
2
]
=
-
lights
.
position
.
z
;
dirLight
[
0
]
=
-
lights
[
1
]
.
position
.
x
;
dirLight
[
1
]
=
-
lights
[
1
]
.
position
.
y
;
dirLight
[
2
]
=
-
lights
[
1
]
.
position
.
z
;
_gl
.
uniform3fv
(
p_uniforms
.
directionalLightDirection
,
dirLight
);
_gl
.
uniformMatrix4fv
(
p_uniforms
.
objectMatrix
,
false
,
object
.
_objectMatrixArray
);
...
...
src/renderers/WebGLShaders.js
浏览文件 @
9c68545b
...
...
@@ -852,6 +852,7 @@ THREE.ShaderLib = {
"
vec4 pos = objectMatrix * vec4( position, 1.0 );
"
,
"
vec3 norm = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;
"
,
"
vec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm )), 0.0 );
"
,
"
gl_Position = projectionMatrix * viewMatrix * ( pos + extruded );
"
,
"
}
"
...
...
@@ -861,7 +862,7 @@ THREE.ShaderLib = {
"
void main() {
"
,
"
gl_FragColor = vec4( 1
, 1, 1, 1
);
"
,
"
gl_FragColor = vec4( 1
.0
);
"
,
"
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录