Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
aac04380
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,发现更多精彩内容 >>
提交
aac04380
编写于
5月 01, 2010
作者:
P
Paul Brunt
提交者:
Mr.doob
5月 01, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first attempt at webGL renderer - not working yet
上级
1186a312
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
192 addition
and
2 deletion
+192
-2
build/three.js
build/three.js
+1
-1
src/renderers/GLRenderer.js
src/renderers/GLRenderer.js
+189
-0
src/renderers/Renderer.js
src/renderers/Renderer.js
+1
-1
utils/deployer.py
utils/deployer.py
+1
-0
未找到文件。
build/three.js
浏览文件 @
aac04380
此差异已折叠。
点击以展开。
src/renderers/GLRenderer.js
0 → 100644
浏览文件 @
aac04380
var
GLRenderer
=
Renderer
.
extend
({
init
:
function
()
{
this
.
_super
();
this
.
viewport
=
document
.
createElement
(
"
canvas
"
);
this
.
viewport
.
style
.
position
=
"
absolute
"
;
try
{
this
.
gl
=
this
.
viewport
.
getContext
(
"
experimental-webgl
"
);
}
catch
(
e
)
{}
if
(
!
this
.
gl
)
{
alert
(
"
WebGL not supported
"
);
throw
"
cannot create webgl context
"
;
}
this
.
gl
.
enable
(
this
.
gl
.
DEPTH_TEST
);
this
.
createProgram
();
},
createProgram
:
function
()
{
var
gl
=
this
.
gl
;
var
vtxShader
=
[
"
attribute vec3 position;
"
,
"
attribute vec4 color;
"
,
"
uniform mat4 mvMatrix;
"
,
"
uniform mat4 pMatrix;
"
,
"
varying vec4 vcolor;
"
,
"
void main(){
"
,
"
vcolor=color;
"
,
"
gl_Position = pMatrix*mvMatrix*vec4(position,1.0);
"
,
"
}
"
].
join
(
""
);
frgShader
=
[
"
varying vec4 vcolor;
"
,
"
void main(){
"
,
"
gl_FragColor=vcolor;
"
,
"
}
"
].
join
(
""
);
var
vertexShader
=
gl
.
createShader
(
gl
.
VERTEX_SHADER
);
var
fragmentShader
=
gl
.
createShader
(
gl
.
FRAGMENT_SHADER
);
gl
.
shaderSource
(
vertexShader
,
vtxShader
);
gl
.
shaderSource
(
fragmentShader
,
frgShader
);
gl
.
compileShader
(
fragmentShader
);
this
.
program
=
gl
.
createProgram
();
gl
.
attachShader
(
this
.
program
,
vertexShader
);
gl
.
attachShader
(
this
.
program
,
fragmentShader
);
gl
.
linkProgram
(
this
.
program
);
this
.
program
.
mvMatrix
=
gl
.
getUniformLocation
(
this
.
program
,
"
mvMatrix
"
);
this
.
program
.
pMatrix
=
gl
.
getUniformLocation
(
this
.
program
,
"
pMatrix
"
);
this
.
program
.
position
=
gl
.
getAttribLocation
(
this
.
program
,
"
position
"
);
this
.
program
.
color
=
gl
.
getAttribLocation
(
this
.
program
,
"
color
"
);
this
.
program
.
mvMatrixArray
=
new
WebGLFloatArray
(
16
);
this
.
program
.
pMatrixArray
=
new
WebGLFloatArray
(
16
);
},
matrix2Array
:
function
(
matrix
,
array
)
{
array
[
0
]
=
matrix
.
n11
;
array
[
1
]
=
matrix
.
n12
;
array
[
3
]
=
matrix
.
n13
;
array
[
4
]
=
matrix
.
n14
;
array
[
5
]
=
matrix
.
n21
;
array
[
6
]
=
matrix
.
n22
;
array
[
7
]
=
matrix
.
n23
;
array
[
8
]
=
matrix
.
n24
;
array
[
9
]
=
matrix
.
n31
;
array
[
10
]
=
matrix
.
n32
;
array
[
11
]
=
matrix
.
n33
;
array
[
12
]
=
matrix
.
n34
;
array
[
13
]
=
matrix
.
n41
;
array
[
14
]
=
matrix
.
n42
;
array
[
15
]
=
matrix
.
n43
;
array
[
16
]
=
matrix
.
n44
;
},
render
:
function
(
scene
,
camera
)
{
var
gl
=
this
.
gl
;
gl
.
viewport
(
0
,
0
,
this
.
width
,
this
.
height
);
gl
.
clear
(
gl
.
COLOR_BUFFER_BIT
|
gl
.
DEPTH_BUFFER_BIT
);
for
(
var
i
=
0
;
i
<
scene
.
objects
.
length
;
i
++
)
{
object
=
scene
.
objects
[
i
];
if
(
object
instanceof
Mesh
)
{
// Very inefficient but easiest way initially
var
vertexArray
=
[];
var
faceArray
=
[];
var
colorArray
=
[];
var
vertexIndex
=
0
;
var
color
;
for
(
j
=
0
;
j
<
object
.
geometry
.
faces
.
length
;
j
++
)
{
face
=
object
.
geometry
.
faces
[
j
];
color
=
face
.
color
;
if
(
face
instanceof
Face3
){
vertexArray
.
push
(
face
.
a
.
x
,
face
.
a
.
y
,
face
.
a
.
z
);
vertexArray
.
push
(
face
.
b
.
x
,
face
.
b
.
y
,
face
.
b
.
z
);
vertexArray
.
push
(
face
.
c
.
x
,
face
.
c
.
y
,
face
.
c
.
z
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
faceArray
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
vertexIndex
+=
3
;
}
else
if
(
face
instanceof
Face4
)
{
vertexArray
.
push
(
face
.
a
.
x
,
face
.
a
.
y
,
face
.
a
.
z
);
vertexArray
.
push
(
face
.
b
.
x
,
face
.
b
.
y
,
face
.
b
.
z
);
vertexArray
.
push
(
face
.
c
.
x
,
face
.
c
.
y
,
face
.
c
.
z
);
vertexArray
.
push
(
face
.
d
.
x
,
face
.
d
.
y
,
face
.
d
.
z
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
colorArray
.
push
(
color
.
r
,
color
.
g
,
color
.
b
,
color
.
a
);
faceArray
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
faceArray
.
push
(
vertexIndex
,
vertexIndex
+
3
,
vertexIndex
+
3
);
vertexIndex
+=
4
;
}
}
var
vertexArray
=
new
WebGLFloatArray
(
vertexArray
);
var
colorArray
=
new
WebGLFloatArray
(
colorArray
);
var
faceArray
=
new
WebGLUnsignedShortArray
(
faceArray
);
if
(
!
object
.
WebGLVertexBuffer
)
object
.
WebGLVertexBuffer
=
gl
.
createBuffer
();
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
object
.
WebGLVertexBuffer
);
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
vertexArray
,
gl
.
DYNAMIC_DRAW
);
if
(
!
object
.
WebGLColorBuffer
)
object
.
WebGLColorBuffer
=
gl
.
createBuffer
();
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
object
.
WebGLColorBuffer
);
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
vertexArray
,
gl
.
DYNAMIC_DRAW
);
if
(
!
object
.
WebGLFaceBuffer
)
object
.
WebGLFaceBuffer
=
gl
.
createBuffer
();
gl
.
bindBuffer
(
gl
.
ELEMENT_ARRAY_BUFFER
,
object
.
WebGLFaceBuffer
);
gl
.
bufferData
(
gl
.
ELEMENT_ARRAY_BUFFER
,
faceArray
,
gl
.
DYNAMIC_DRAW
);
gl
.
useProgram
(
this
.
program
);
this
.
matrix
.
multiply
(
camera
.
matrix
,
object
.
matrix
);
this
.
matrix2Array
(
this
.
matrix
,
this
.
program
.
mvMatrixArray
);
this
.
matrix2Array
(
camera
.
projectionMatrix
,
this
.
program
.
pMatrixArray
);
gl
.
uniformMatrix4fv
(
this
.
program
.
pMatrix
,
true
,
this
.
program
.
pMatrixArray
);
gl
.
uniformMatrix4fv
(
this
.
program
.
mvMatrix
,
true
,
this
.
program
.
mvMatrixArray
);
for
(
var
i
=
0
;
i
<
8
;
i
++
)
gl
.
disableVertexAttribArray
(
i
);
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
object
.
WebGLVertexBuffer
);
gl
.
enableVertexAttribArray
(
this
.
program
.
position
);
gl
.
vertexAttribPointer
(
this
.
program
.
position
,
3
,
gl
.
FLOAT
,
false
,
0
,
0
);
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
object
.
WebGLColorBuffer
);
gl
.
enableVertexAttribArray
(
this
.
program
.
color
);
gl
.
vertexAttribPointer
(
this
.
program
.
color
,
4
,
gl
.
FLOAT
,
false
,
0
,
0
);
gl
.
bindBuffer
(
gl
.
ELEMENT_ARRAY_BUFFER
,
object
.
WebGLFaceBuffer
);
alert
(
faceArray
.
length
);
gl
.
drawElements
(
gl
.
TRIANGLES
,
faceArray
.
length
,
gl
.
UNSIGNED_SHORT
,
0
);
}
//TODO Particles!!
}
}
});
src/renderers/Renderer.js
浏览文件 @
aac04380
...
...
@@ -143,7 +143,7 @@ var Renderer = Class.extend
if
(
object
.
screen
.
z
>
0
&&
object
.
screen
.
z
<
1
&&
object
.
screen
.
x
+
object
.
zsize
>
-
1
&&
object
.
screen
.
x
-
object
.
zsize
<
1
&&
object
.
screen
.
y
+
object
.
zsize
>
-
1
&&
object
.
screen
.
y
-
object
.
zsize
<
1
){
object
.
zsize
*=
this
.
height
Half
;
object
.
zsize
*=
this
.
width
Half
;
object
.
screen
.
x
*=
this
.
widthHalf
;
object
.
screen
.
y
*=
this
.
heightHalf
;
this
.
renderList
.
push
(
object
);
...
...
utils/deployer.py
浏览文件 @
aac04380
...
...
@@ -27,6 +27,7 @@ files.append('scenes/Scene.js');
files
.
append
(
'renderers/Renderer.js'
);
files
.
append
(
'renderers/CanvasRenderer.js'
);
files
.
append
(
'renderers/SVGRenderer.js'
);
files
.
append
(
'renderers/GLRenderer.js'
);
string
=
''
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录