Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a2ca7ab9
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,发现更多精彩内容 >>
提交
a2ca7ab9
编写于
7月 13, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added computeTangents to BufferGeometry.
上级
01c31ae9
变更
5
展开全部
显示空白变更内容
内联
并排
Showing
5 changed file
with
778 addition
and
543 deletion
+778
-543
build/Three.js
build/Three.js
+352
-348
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+17
-13
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+183
-178
src/extras/core/BufferGeometry.js
src/extras/core/BufferGeometry.js
+205
-3
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+21
-1
未找到文件。
build/Three.js
浏览文件 @
a2ca7ab9
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
build/custom/ThreeExtras.js
浏览文件 @
a2ca7ab9
此差异已折叠。
点击以展开。
build/custom/ThreeWebGL.js
浏览文件 @
a2ca7ab9
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
src/extras/core/BufferGeometry.js
浏览文件 @
a2ca7ab9
...
...
@@ -19,6 +19,8 @@ THREE.BufferGeometry = function () {
this
.
boundingBox
=
null
;
this
.
boundingSphere
=
null
;
this
.
hasTangents
=
false
;
// for compatibility
this
.
morphTargets
=
[];
...
...
@@ -162,15 +164,15 @@ THREE.BufferGeometry.prototype = {
var
i
,
il
;
var
j
,
jl
;
var
nVert
ice
s
=
this
.
attributes
[
"
position
"
].
array
.
length
;
var
nVert
exElement
s
=
this
.
attributes
[
"
position
"
].
array
.
length
;
if
(
this
.
attributes
[
"
normal
"
]
===
undefined
)
{
this
.
attributes
[
"
normal
"
]
=
{
itemSize
:
3
,
array
:
new
Float32Array
(
nVert
ice
s
),
numItems
:
nVert
ices
*
3
array
:
new
Float32Array
(
nVert
exElement
s
),
numItems
:
nVert
exElements
};
...
...
@@ -268,6 +270,206 @@ THREE.BufferGeometry.prototype = {
}
},
computeTangents
:
function
()
{
// based on http://www.terathon.com/code/tangent.html
// (per vertex tangents)
if
(
this
.
attributes
[
"
index
"
]
===
undefined
||
this
.
attributes
[
"
position
"
]
===
undefined
||
this
.
attributes
[
"
normal
"
]
===
undefined
||
this
.
attributes
[
"
uv
"
]
===
undefined
)
{
console
.
warn
(
"
Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()
"
);
return
;
}
var
indices
=
this
.
attributes
[
"
index
"
].
array
;
var
positions
=
this
.
attributes
[
"
position
"
].
array
;
var
normals
=
this
.
attributes
[
"
normal
"
].
array
;
var
uvs
=
this
.
attributes
[
"
uv
"
].
array
;
var
nVertices
=
positions
.
length
/
3
;
if
(
this
.
attributes
[
"
tangent
"
]
===
undefined
)
{
var
nTangentElements
=
4
*
nVertices
;
this
.
attributes
[
"
tangent
"
]
=
{
itemSize
:
4
,
array
:
new
Float32Array
(
nTangentElements
),
numItems
:
nTangentElements
};
}
var
tangents
=
this
.
attributes
[
"
tangent
"
].
array
;
var
tan1
=
[],
tan2
=
[];
for
(
var
k
=
0
;
k
<
nVertices
;
k
++
)
{
tan1
[
k
]
=
new
THREE
.
Vector3
();
tan2
[
k
]
=
new
THREE
.
Vector3
();
}
var
xA
,
yA
,
zA
,
xB
,
yB
,
zB
,
xC
,
yC
,
zC
,
uA
,
vA
,
uB
,
vB
,
uC
,
vC
,
x1
,
x2
,
y1
,
y2
,
z1
,
z2
,
s1
,
s2
,
t1
,
t2
,
r
;
var
sdir
=
new
THREE
.
Vector3
(),
tdir
=
new
THREE
.
Vector3
();
function
handleTriangle
(
a
,
b
,
c
)
{
xA
=
positions
[
a
*
3
];
yA
=
positions
[
a
*
3
+
1
];
zA
=
positions
[
a
*
3
+
2
];
xB
=
positions
[
b
*
3
];
yB
=
positions
[
b
*
3
+
1
];
zB
=
positions
[
b
*
3
+
2
];
xC
=
positions
[
c
*
3
];
yC
=
positions
[
c
*
3
+
1
];
zC
=
positions
[
c
*
3
+
2
];
uA
=
uvs
[
a
*
2
];
vA
=
uvs
[
a
*
2
+
1
];
uB
=
uvs
[
b
*
2
];
vB
=
uvs
[
b
*
2
+
1
];
uC
=
uvs
[
c
*
2
];
vC
=
uvs
[
c
*
2
+
1
];
x1
=
xB
-
xA
;
x2
=
xC
-
xA
;
y1
=
yB
-
yA
;
y2
=
yC
-
yA
;
z1
=
zB
-
zA
;
z2
=
zC
-
zA
;
s1
=
uB
-
uA
;
s2
=
uC
-
uA
;
t1
=
vB
-
vA
;
t2
=
vC
-
vA
;
r
=
1.0
/
(
s1
*
t2
-
s2
*
t1
);
sdir
.
set
(
(
t2
*
x1
-
t1
*
x2
)
*
r
,
(
t2
*
y1
-
t1
*
y2
)
*
r
,
(
t2
*
z1
-
t1
*
z2
)
*
r
);
tdir
.
set
(
(
s1
*
x2
-
s2
*
x1
)
*
r
,
(
s1
*
y2
-
s2
*
y1
)
*
r
,
(
s1
*
z2
-
s2
*
z1
)
*
r
);
tan1
[
a
].
addSelf
(
sdir
);
tan1
[
b
].
addSelf
(
sdir
);
tan1
[
c
].
addSelf
(
sdir
);
tan2
[
a
].
addSelf
(
tdir
);
tan2
[
b
].
addSelf
(
tdir
);
tan2
[
c
].
addSelf
(
tdir
);
}
var
i
,
il
;
var
j
,
jl
;
var
iA
,
iB
,
iC
;
var
offsets
=
this
.
offsets
;
for
(
j
=
0
,
jl
=
offsets
.
length
;
j
<
jl
;
++
j
)
{
var
start
=
offsets
[
j
].
start
;
var
count
=
offsets
[
j
].
count
;
var
index
=
offsets
[
j
].
index
;
for
(
i
=
start
,
il
=
start
+
count
;
i
<
il
;
i
+=
3
)
{
iA
=
index
+
indices
[
i
];
iB
=
index
+
indices
[
i
+
1
];
iC
=
index
+
indices
[
i
+
2
];
handleTriangle
(
iA
,
iB
,
iC
);
}
}
var
tmp
=
new
THREE
.
Vector3
(),
tmp2
=
new
THREE
.
Vector3
();
var
n
=
new
THREE
.
Vector3
(),
n2
=
new
THREE
.
Vector3
();
var
w
,
t
,
test
;
var
nx
,
ny
,
nz
;
function
handleVertex
(
v
)
{
n
.
x
=
normals
[
v
*
3
];
n
.
y
=
normals
[
v
*
3
+
1
];
n
.
z
=
normals
[
v
*
3
+
2
];
n2
.
copy
(
n
);
t
=
tan1
[
v
];
// Gram-Schmidt orthogonalize
tmp
.
copy
(
t
);
tmp
.
subSelf
(
n
.
multiplyScalar
(
n
.
dot
(
t
)
)
).
normalize
();
// Calculate handedness
tmp2
.
cross
(
n2
,
t
);
test
=
tmp2
.
dot
(
tan2
[
v
]
);
w
=
(
test
<
0.0
)
?
-
1.0
:
1.0
;
tangents
[
v
*
4
]
=
tmp
.
x
;
tangents
[
v
*
4
+
1
]
=
tmp
.
y
;
tangents
[
v
*
4
+
2
]
=
tmp
.
z
;
tangents
[
v
*
4
+
3
]
=
w
;
}
for
(
j
=
0
,
jl
=
offsets
.
length
;
j
<
jl
;
++
j
)
{
var
start
=
offsets
[
j
].
start
;
var
count
=
offsets
[
j
].
count
;
var
index
=
offsets
[
j
].
index
;
for
(
i
=
start
,
il
=
start
+
count
;
i
<
il
;
i
+=
3
)
{
iA
=
index
+
indices
[
i
];
iB
=
index
+
indices
[
i
+
1
];
iC
=
index
+
indices
[
i
+
2
];
handleVertex
(
iA
);
handleVertex
(
iB
);
handleVertex
(
iC
);
}
}
this
.
hasTangents
=
true
;
this
.
tangentsNeedUpdate
=
true
;
}
};
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
a2ca7ab9
...
...
@@ -2916,6 +2916,7 @@ THREE.WebGLRenderer = function ( parameters ) {
var
normal
=
attributes
[
"
normal
"
];
var
uv
=
attributes
[
"
uv
"
];
var
color
=
attributes
[
"
color
"
];
var
tangent
=
attributes
[
"
tangent
"
];
if
(
geometry
.
elementsNeedUpdate
&&
index
!==
undefined
)
{
...
...
@@ -2952,6 +2953,12 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if
(
geometry
.
tangentsNeedUpdate
&&
tangent
!==
undefined
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
tangent
.
buffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
tangent
.
array
,
hint
);
}
if
(
dispose
)
{
...
...
@@ -3154,6 +3161,18 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
color
.
buffer
);
_gl
.
vertexAttribPointer
(
attributes
.
color
,
colorSize
,
_gl
.
FLOAT
,
false
,
0
,
startIndex
*
colorSize
*
4
);
}
// tangents
var
tangent
=
geometry
.
attributes
[
"
tangent
"
];
if
(
attributes
.
tangent
>=
0
&&
tangent
)
{
var
tangentSize
=
tangent
.
itemSize
;
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
tangent
.
buffer
);
_gl
.
vertexAttribPointer
(
attributes
.
tangent
,
tangentSize
,
_gl
.
FLOAT
,
false
,
0
,
startIndex
*
tangentSize
*
4
);
}
...
...
@@ -4260,7 +4279,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
geometry
.
verticesNeedUpdate
||
geometry
.
elementsNeedUpdate
||
geometry
.
uvsNeedUpdate
||
geometry
.
normalsNeedUpdate
||
geometry
.
colorsNeedUpdate
)
{
geometry
.
colorsNeedUpdate
||
geometry
.
tangentsNeedUpdate
)
{
setDirectBuffers
(
geometry
,
_gl
.
DYNAMIC_DRAW
,
!
geometry
.
dynamic
);
...
...
@@ -4271,6 +4290,7 @@ THREE.WebGLRenderer = function ( parameters ) {
geometry
.
uvsNeedUpdate
=
false
;
geometry
.
normalsNeedUpdate
=
false
;
geometry
.
colorsNeedUpdate
=
false
;
geometry
.
tangentsNeedUpdate
=
false
;
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录