Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a53ad5a7
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,发现更多精彩内容 >>
提交
a53ad5a7
编写于
9月 09, 2010
作者:
N
Nicolas Garcia Belmonte
提交者:
Mr.doob
9月 09, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added normals to WebGLRenderer
上级
78561a35
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
3 deletion
+30
-3
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+30
-3
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
a53ad5a7
...
...
@@ -6,7 +6,7 @@
THREE
.
WebGLRenderer
=
function
()
{
var
_canvas
=
document
.
createElement
(
'
canvas
'
),
_gl
,
_program
,
viewMatrix
=
new
THREE
.
Matrix4
();
viewMatrix
=
new
THREE
.
Matrix4
()
,
normalMatrix
;
this
.
domElement
=
_canvas
;
this
.
autoClear
=
true
;
...
...
@@ -30,8 +30,8 @@ THREE.WebGLRenderer = function () {
this
.
render
=
function
(
scene
,
camera
)
{
var
face
,
faceColor
,
object
,
material
,
vertexArray
,
faceArray
,
colorArray
,
vertexIndex
,
var
face
,
faceColor
,
object
,
material
,
normal
,
vertexArray
,
faceArray
,
colorArray
,
normalArray
,
vertexIndex
,
o
,
ol
,
f
,
fl
,
m
,
ml
,
i
,
v1
,
v2
,
v3
,
v4
;
if
(
this
.
autoClear
)
{
...
...
@@ -51,12 +51,14 @@ THREE.WebGLRenderer = function () {
vertexArray
=
[];
faceArray
=
[];
colorArray
=
[];
normalArray
=
[];
vertexIndex
=
0
;
for
(
f
=
0
,
fl
=
object
.
geometry
.
faces
.
length
;
f
<
fl
;
f
++
)
{
face
=
object
.
geometry
.
faces
[
f
];
faceColor
=
face
.
color
;
normal
=
face
.
normal
;
if
(
face
instanceof
THREE
.
Face3
)
{
...
...
@@ -68,6 +70,10 @@ THREE.WebGLRenderer = function () {
vertexArray
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertexArray
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
...
...
@@ -88,6 +94,11 @@ THREE.WebGLRenderer = function () {
vertexArray
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
vertexArray
.
push
(
v4
.
x
,
v4
.
y
,
v4
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
normalArray
.
push
(
n
.
x
,
n
.
y
,
n
.
z
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
colorArray
.
push
(
faceColor
.
r
,
faceColor
.
g
,
faceColor
.
b
,
faceColor
.
a
);
...
...
@@ -110,6 +121,10 @@ THREE.WebGLRenderer = function () {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webGLVertexBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
vertexArray
),
_gl
.
STATIC_DRAW
);
object
.
__webGLNormalBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webGLNormalBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
normalArray
),
_gl
.
STATIC_DRAW
);
object
.
__webGLColorBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webGLColorBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
colorArray
),
_gl
.
STATIC_DRAW
);
...
...
@@ -128,12 +143,18 @@ THREE.WebGLRenderer = function () {
_program
.
viewMatrixArray
=
new
Float32Array
(
viewMatrix
.
flatten
()
);
_program
.
projectionMatrixArray
=
new
Float32Array
(
camera
.
projectionMatrix
.
flatten
()
);
normalMatrix
=
Matrix4
.
makeInvert
(
viewMatrix
).
transpose
();
_program
.
normalMatrixArray
=
new
Float32Array
(
normalMatrix
.
flatten
()
);
_gl
.
uniformMatrix4fv
(
_program
.
viewMatrix
,
false
,
_program
.
viewMatrixArray
);
_gl
.
uniformMatrix4fv
(
_program
.
projectionMatrix
,
false
,
_program
.
projectionMatrixArray
);
_gl
.
uniformMatrix4fv
(
_program
.
normalMatrix
,
false
,
_program
.
normalMatrixArray
);
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webGLVertexBuffer
);
_gl
.
vertexAttribPointer
(
_program
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
object
.
__webGLNormalBuffer
);
_gl
.
vertexAttribPointer
(
_program
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
for
(
m
=
0
,
ml
=
object
.
material
.
length
;
m
<
ml
;
m
++
)
{
...
...
@@ -225,10 +246,12 @@ THREE.WebGLRenderer = function () {
_gl
.
attachShader
(
_program
,
getShader
(
"
vertex
"
,
[
"
attribute vec3 position;
"
,
"
attribute vec3 normal;
"
,
"
attribute vec4 color;
"
,
"
uniform mat4 viewMatrix;
"
,
"
uniform mat4 projectionMatrix;
"
,
"
uniform mat4 normalMatrix;
"
,
"
varying vec4 vcolor;
"
,
"
void main(void) {
"
,
...
...
@@ -250,6 +273,7 @@ THREE.WebGLRenderer = function () {
_program
.
viewMatrix
=
_gl
.
getUniformLocation
(
_program
,
"
viewMatrix
"
);
_program
.
projectionMatrix
=
_gl
.
getUniformLocation
(
_program
,
"
projectionMatrix
"
);
_program
.
normalMatrix
=
_gl
.
getUniformLocation
(
_program
,
"
normalMatrix
"
);
_program
.
color
=
_gl
.
getAttribLocation
(
_program
,
"
color
"
);
_gl
.
enableVertexAttribArray
(
_program
.
color
);
...
...
@@ -257,6 +281,9 @@ THREE.WebGLRenderer = function () {
_program
.
position
=
_gl
.
getAttribLocation
(
_program
,
"
position
"
);
_gl
.
enableVertexAttribArray
(
_program
.
position
);
_program
.
normal
=
_gl
.
getAttribLocation
(
_program
,
"
normal
"
);
_gl
.
enableVertexAttribArray
(
_program
.
normal
);
_program
.
viewMatrixArray
=
new
Float32Array
(
16
);
_program
.
projectionMatrixArray
=
new
Float32Array
(
16
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录