Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
39c7e8da
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
39c7e8da
编写于
12月 17, 2010
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
差异文件
Synced with mrdoob's branch.
上级
5e9bce83
9f668dea
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
441 addition
and
386 deletion
+441
-386
build/Three.js
build/Three.js
+77
-78
build/ThreeDebug.js
build/ThreeDebug.js
+77
-78
build/ThreeExtras.js
build/ThreeExtras.js
+117
-118
src/core/Geometry.js
src/core/Geometry.js
+37
-37
src/extras/primitives/Cube.js
src/extras/primitives/Cube.js
+5
-2
src/objects/Mesh.js
src/objects/Mesh.js
+6
-2
src/renderers/WebGLRenderer2.js
src/renderers/WebGLRenderer2.js
+106
-68
src/scenes/Scene.js
src/scenes/Scene.js
+16
-3
未找到文件。
build/Three.js
浏览文件 @
39c7e8da
此差异已折叠。
点击以展开。
build/ThreeDebug.js
浏览文件 @
39c7e8da
此差异已折叠。
点击以展开。
build/ThreeExtras.js
浏览文件 @
39c7e8da
此差异已折叠。
点击以展开。
src/core/Geometry.js
浏览文件 @
39c7e8da
...
...
@@ -13,7 +13,7 @@ THREE.Geometry = function () {
this
.
geometryChunks
=
{};
this
.
hasTangents
=
false
;
};
THREE
.
Geometry
.
prototype
=
{
...
...
@@ -170,35 +170,35 @@ THREE.Geometry.prototype = {
},
computeTangents
:
function
()
{
// based on http://www.terathon.com/code/tangent.html
// tangents go to vertices
var
f
,
fl
,
v
,
vl
,
face
,
uv
,
vA
,
vB
,
vC
,
uvA
,
uvB
,
uvC
,
x1
,
x2
,
y1
,
y2
,
z1
,
z2
,
s1
,
s2
,
t1
,
t2
,
r
,
t
,
n
,
tan1
=
[],
tan2
=
[],
sdir
=
new
THREE
.
Vector3
(),
tdir
=
new
THREE
.
Vector3
(),
tmp
=
new
THREE
.
Vector3
(),
tmp2
=
new
THREE
.
Vector3
(),
tmp
=
new
THREE
.
Vector3
(),
tmp2
=
new
THREE
.
Vector3
(),
n
=
new
THREE
.
Vector3
(),
w
;
for
(
v
=
0
,
vl
=
this
.
vertices
.
length
;
v
<
vl
;
v
++
)
{
tan1
[
v
]
=
new
THREE
.
Vector3
();
tan2
[
v
]
=
new
THREE
.
Vector3
();
}
function
handleTriangle
(
context
,
a
,
b
,
c
)
{
vA
=
context
.
vertices
[
a
].
position
;
vB
=
context
.
vertices
[
b
].
position
;
vC
=
context
.
vertices
[
c
].
position
;
uvA
=
uv
[
0
];
uvB
=
uv
[
1
];
uvC
=
uv
[
2
];
x1
=
vB
.
x
-
vA
.
x
;
x2
=
vC
.
x
-
vA
.
x
;
y1
=
vB
.
y
-
vA
.
y
;
...
...
@@ -212,41 +212,41 @@ THREE.Geometry.prototype = {
t2
=
uvC
.
v
-
uvA
.
v
;
r
=
1.0
/
(
s1
*
t2
-
s2
*
t1
);
sdir
.
set
(
(
t2
*
x1
-
t1
*
x2
)
*
r
,
sdir
.
set
(
(
t2
*
x1
-
t1
*
x2
)
*
r
,
(
t2
*
y1
-
t1
*
y2
)
*
r
,
(
t2
*
z1
-
t1
*
z2
)
*
r
);
tdir
.
set
(
(
s1
*
x2
-
s2
*
x1
)
*
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
);
}
for
(
f
=
0
,
fl
=
this
.
faces
.
length
;
f
<
fl
;
f
++
)
{
face
=
this
.
faces
[
f
];
uv
=
this
.
uvs
[
f
];
if
(
face
instanceof
THREE
.
Face3
)
{
handleTriangle
(
this
,
face
.
a
,
face
.
b
,
face
.
c
);
this
.
vertices
[
face
.
a
].
normal
.
copy
(
face
.
vertexNormals
[
0
]
);
this
.
vertices
[
face
.
b
].
normal
.
copy
(
face
.
vertexNormals
[
1
]
);
this
.
vertices
[
face
.
c
].
normal
.
copy
(
face
.
vertexNormals
[
2
]
);
}
else
if
(
face
instanceof
THREE
.
Face4
)
{
handleTriangle
(
this
,
face
.
a
,
face
.
b
,
face
.
c
);
// this messes up everything
// quads need to be handled differently
//handleTriangle( this, face.a, face.c, face.d );
...
...
@@ -255,41 +255,41 @@ THREE.Geometry.prototype = {
this
.
vertices
[
face
.
b
].
normal
.
copy
(
face
.
vertexNormals
[
1
]
);
this
.
vertices
[
face
.
c
].
normal
.
copy
(
face
.
vertexNormals
[
2
]
);
this
.
vertices
[
face
.
d
].
normal
.
copy
(
face
.
vertexNormals
[
3
]
);
}
}
for
(
v
=
0
,
vl
=
this
.
vertices
.
length
;
v
<
vl
;
v
++
)
{
n
.
copy
(
this
.
vertices
[
v
].
normal
);
t
=
tan1
[
v
];
// Gram-Schmidt orthogonalize
tmp
.
copy
(
t
);
tmp
.
subSelf
(
n
.
multiplyScalar
(
n
.
dot
(
t
)
)
).
normalize
();
// Calculate handedness
tmp2
.
cross
(
this
.
vertices
[
v
].
normal
,
t
);
test
=
tmp2
.
dot
(
tan2
[
v
]
);
w
=
(
test
<
0.0
)
?
-
1.0
:
1.0
;
this
.
vertices
[
v
].
tangent
.
set
(
tmp
.
x
,
tmp
.
y
,
tmp
.
z
,
w
);
}
this
.
hasTangents
=
true
;
},
computeBoundingBox
:
function
()
{
if
(
this
.
vertices
.
length
>
0
)
{
this
.
bbox
=
{
'
x
'
:
[
this
.
vertices
[
0
].
position
.
x
,
this
.
vertices
[
0
].
position
.
x
],
'
y
'
:
[
this
.
vertices
[
0
].
position
.
y
,
this
.
vertices
[
0
].
position
.
y
],
'
y
'
:
[
this
.
vertices
[
0
].
position
.
y
,
this
.
vertices
[
0
].
position
.
y
],
'
z
'
:
[
this
.
vertices
[
0
].
position
.
z
,
this
.
vertices
[
0
].
position
.
z
]
};
for
(
var
v
=
1
,
vl
=
this
.
vertices
.
length
;
v
<
vl
;
v
++
)
{
...
...
src/extras/primitives/Cube.js
浏览文件 @
39c7e8da
...
...
@@ -64,13 +64,16 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
function
buildPlane
(
u
,
v
,
udir
,
vdir
,
width
,
height
,
depth
,
material
)
{
var
gridX
=
segments_width
||
1
,
var
w
,
gridX
=
segments_width
||
1
,
gridY
=
segments_height
||
1
,
gridX1
=
gridX
+
1
,
gridY1
=
gridY
+
1
,
width_half
=
width
/
2
,
height_half
=
height
/
2
,
segment_width
=
width
/
gridX
,
segment_height
=
height
/
gridY
,
offset
=
scope
.
vertices
.
length
,
w
;
offset
=
scope
.
vertices
.
length
;
if
(
(
u
==
'
x
'
&&
v
==
'
y
'
)
||
(
u
==
'
y
'
&&
v
==
'
x
'
)
)
{
...
...
src/objects/Mesh.js
浏览文件 @
39c7e8da
...
...
@@ -3,7 +3,7 @@
* @author alteredq / http://alteredqualia.com/
*/
THREE
.
Mesh
=
function
(
geometry
,
material
,
normUVs
)
{
THREE
.
Mesh
=
function
(
geometry
,
material
/*, normUVs*/
)
{
THREE
.
Object3D
.
call
(
this
);
...
...
@@ -15,7 +15,7 @@ THREE.Mesh = function ( geometry, material, normUVs ) {
this
.
overdraw
=
false
;
if
(
normUVs
)
this
.
normalizeUVs
();
//
if ( normUVs ) this.normalizeUVs();
this
.
geometry
.
computeBoundingBox
();
...
...
@@ -24,6 +24,9 @@ THREE.Mesh = function ( geometry, material, normUVs ) {
THREE
.
Mesh
.
prototype
=
new
THREE
.
Object3D
();
THREE
.
Mesh
.
prototype
.
constructor
=
THREE
.
Mesh
;
/*
TODO: This doesn't completely fix the issue. Needs to be handled directly in the CanvasRenderer
THREE.Mesh.prototype.normalizeUVs = function () {
var i, il, j, jl, uvs;
...
...
@@ -45,3 +48,4 @@ THREE.Mesh.prototype.normalizeUVs = function () {
}
};
*/
src/renderers/WebGLRenderer2.js
浏览文件 @
39c7e8da
...
...
@@ -99,6 +99,7 @@ THREE.WebGLRenderer2 = function () {
_normalMatrix
=
THREE
.
Matrix4
.
makeInvert3x3
(
_modelViewMatrix
).
transpose
();
_normalMatrixArray
.
set
(
_normalMatrix
.
m
);
if
(
object
instanceof
THREE
.
Mesh
)
{
geometry
=
object
.
geometry
;
...
...
@@ -158,43 +159,51 @@ THREE.WebGLRenderer2 = function () {
_gl
.
uniformMatrix4fv
(
program
.
uniforms
.
modelViewMatrix
,
false
,
_modelViewMatrixArray
);
_gl
.
uniformMatrix3fv
(
program
.
uniforms
.
normalMatrix
,
false
,
_normalMatrixArray
);
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometry
.
__webglBuffers
.
vertexBuffer
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
var
buffer
,
buffers
=
geometry
.
__webglBuffers
;
if
(
attributes
.
normal
>=
0
)
{
for
(
var
i
=
0
,
l
=
buffers
.
length
;
i
<
l
;
i
++
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometry
.
__webglBuffers
.
normalBuffer
);
_gl
.
vertexAttribPointer
(
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
buffer
=
buffers
[
i
];
}
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
vertices
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
if
(
attributes
.
normal
>=
0
)
{
if
(
attributes
.
uv
>=
0
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
normals
);
_gl
.
vertexAttribPointer
(
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
if
(
geometry
.
__webglBuffers
.
uvBuffer
)
{
}
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometry
.
__webglBuffers
.
uvBuffer
);
if
(
attributes
.
uv
>=
0
)
{
_gl
.
enableVertexAttribArray
(
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
if
(
buffer
.
uvs
)
{
}
else
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
uvs
);
_gl
.
enableVertexAttribArray
(
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
disableVertexAttribArray
(
attributes
.
uv
);
}
else
{
_gl
.
disableVertexAttribArray
(
attributes
.
uv
);
}
}
}
if
(
!
material
.
wireframe
)
{
if
(
!
material
.
wireframe
)
{
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffer
.
faces
);
_gl
.
drawElements
(
_gl
.
TRIANGLES
,
buffer
.
faceCount
,
_gl
.
UNSIGNED_SHORT
,
0
);
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
geometry
.
__webglBuffers
.
faceBuffer
);
_gl
.
drawElements
(
_gl
.
TRIANGLES
,
geometry
.
__webglBuffers
.
faceCount
,
_gl
.
UNSIGNED_SHORT
,
0
);
}
else
{
}
else
{
_gl
.
lineWidth
(
material
.
wireframe_linewidth
);
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffer
.
lines
);
_gl
.
drawElements
(
_gl
.
LINES
,
buffer
.
lineCount
,
_gl
.
UNSIGNED_SHORT
,
0
);
_gl
.
lineWidth
(
material
.
wireframe_linewidth
);
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
geometry
.
__webglBuffers
.
lineBuffer
);
_gl
.
drawElements
(
_gl
.
LINES
,
geometry
.
__webglBuffers
.
lineCount
,
_gl
.
UNSIGNED_SHORT
,
0
);
}
}
...
...
@@ -208,9 +217,11 @@ THREE.WebGLRenderer2 = function () {
function
buildBuffers
(
geometry
)
{
var
f
,
fl
,
face
,
v1
,
v2
,
v3
,
vertexNormals
,
normal
,
uv
,
vertexIndex
=
0
,
verticesArray
=
[],
facesArray
=
[],
linesArray
=
[],
normalsArray
=
[],
uvsArray
=
[],
// TODO: Handle 65535
var
vertexIndex
=
0
,
group
,
f
,
fl
,
face
,
v1
,
v2
,
v3
,
vertexNormals
,
normal
,
uv
,
vertices
=
[],
faces
=
[],
lines
=
[],
normals
=
[],
uvs
=
[],
buffers
=
{};
for
(
f
=
0
,
fl
=
geometry
.
faces
.
length
;
f
<
fl
;
f
++
)
{
...
...
@@ -226,15 +237,15 @@ THREE.WebGLRenderer2 = function () {
v2
=
geometry
.
vertices
[
face
.
b
].
position
;
v3
=
geometry
.
vertices
[
face
.
c
].
position
;
vertices
Array
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
vertices
Array
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertices
Array
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
vertices
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
vertices
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertices
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
if
(
vertexNormals
.
length
==
3
)
{
for
(
i
=
0
;
i
<
3
;
i
++
)
{
normals
Array
.
push
(
vertexNormals
[
i
].
x
,
vertexNormals
[
i
].
y
,
vertexNormals
[
i
].
z
);
normals
.
push
(
vertexNormals
[
i
].
x
,
vertexNormals
[
i
].
y
,
vertexNormals
[
i
].
z
);
}
...
...
@@ -242,7 +253,7 @@ THREE.WebGLRenderer2 = function () {
for
(
i
=
0
;
i
<
3
;
i
++
)
{
normals
Array
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceNormal
.
z
);
normals
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceNormal
.
z
);
}
...
...
@@ -252,39 +263,51 @@ THREE.WebGLRenderer2 = function () {
for
(
i
=
0
;
i
<
3
;
i
++
)
{
uvs
Array
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
uvs
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
}
}
faces
Array
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
faces
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
// TODO: don't add lines that already exist (faces sharing edge)
lines
Array
.
push
(
vertexIndex
,
vertexIndex
+
1
);
lines
Array
.
push
(
vertexIndex
,
vertexIndex
+
2
);
lines
Array
.
push
(
vertexIndex
+
1
,
vertexIndex
+
2
);
lines
.
push
(
vertexIndex
,
vertexIndex
+
1
);
lines
.
push
(
vertexIndex
,
vertexIndex
+
2
);
lines
.
push
(
vertexIndex
+
1
,
vertexIndex
+
2
);
vertexIndex
+=
3
;
}
else
if
(
face
instanceof
THREE
.
Face4
)
{
group
=
Math
.
floor
(
vertexIndex
/
65535
);
if
(
!
vertices
)
{
vertices
=
[];
faces
=
[];
normals
=
[];
lines
=
[];
uvs
=
[];
}
v1
=
geometry
.
vertices
[
face
.
a
].
position
;
v2
=
geometry
.
vertices
[
face
.
b
].
position
;
v3
=
geometry
.
vertices
[
face
.
c
].
position
;
v4
=
geometry
.
vertices
[
face
.
d
].
position
;
vertices
Array
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
vertices
Array
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertices
Array
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
vertices
Array
.
push
(
v4
.
x
,
v4
.
y
,
v4
.
z
);
vertices
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
vertices
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertices
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
vertices
.
push
(
v4
.
x
,
v4
.
y
,
v4
.
z
);
if
(
vertexNormals
.
length
==
4
)
{
for
(
i
=
0
;
i
<
4
;
i
++
)
{
normals
Array
.
push
(
vertexNormals
[
i
].
x
,
vertexNormals
[
i
].
y
,
vertexNormals
[
i
].
z
);
normals
.
push
(
vertexNormals
[
i
].
x
,
vertexNormals
[
i
].
y
,
vertexNormals
[
i
].
z
);
}
...
...
@@ -292,7 +315,7 @@ THREE.WebGLRenderer2 = function () {
for
(
i
=
0
;
i
<
4
;
i
++
)
{
normals
Array
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceNormal
.
z
);
normals
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceNormal
.
z
);
}
...
...
@@ -302,22 +325,22 @@ THREE.WebGLRenderer2 = function () {
for
(
i
=
0
;
i
<
4
;
i
++
)
{
uvs
Array
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
uvs
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
}
}
faces
Array
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
faces
Array
.
push
(
vertexIndex
,
vertexIndex
+
2
,
vertexIndex
+
3
);
faces
.
push
(
vertexIndex
,
vertexIndex
+
1
,
vertexIndex
+
2
);
faces
.
push
(
vertexIndex
,
vertexIndex
+
2
,
vertexIndex
+
3
);
// TODO: don't add lines that already exist (faces sharing edge)
lines
Array
.
push
(
vertexIndex
,
vertexIndex
+
1
);
lines
Array
.
push
(
vertexIndex
,
vertexIndex
+
2
);
lines
Array
.
push
(
vertexIndex
,
vertexIndex
+
3
);
lines
Array
.
push
(
vertexIndex
+
1
,
vertexIndex
+
2
);
lines
Array
.
push
(
vertexIndex
+
2
,
vertexIndex
+
3
);
lines
.
push
(
vertexIndex
,
vertexIndex
+
1
);
lines
.
push
(
vertexIndex
,
vertexIndex
+
2
);
lines
.
push
(
vertexIndex
,
vertexIndex
+
3
);
lines
.
push
(
vertexIndex
+
1
,
vertexIndex
+
2
);
lines
.
push
(
vertexIndex
+
2
,
vertexIndex
+
3
);
vertexIndex
+=
4
;
...
...
@@ -325,34 +348,49 @@ THREE.WebGLRenderer2 = function () {
}
if
(
!
vertices
Array
.
length
)
return
false
;
if
(
!
vertices
.
length
)
return
false
;
buffers
.
vertexBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffers
.
vertexBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
verticesArray
),
_gl
.
STATIC_DRAW
);
var
buffer
,
buffers
=
[];
buffers
.
normalBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffers
.
normalBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
normalsArray
),
_gl
.
STATIC_DRAW
);
// for ( var i = 0, l = group; i <= l; i ++ ) {
if
(
uvsArray
.
length
>
0
)
{
buffer
=
{
vertices
:
null
,
faces
:
null
,
faceCount
:
faces
.
length
,
normals
:
null
,
lines
:
null
,
lineCount
:
lines
.
length
,
uvs
:
null
};
buffer
s
.
uvBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
s
.
uvBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
uvsArray
),
_gl
.
STATIC_DRAW
);
buffer
.
vertices
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
vertices
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
vertices
),
_gl
.
STATIC_DRAW
);
}
buffer
.
normals
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
normals
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
normals
),
_gl
.
STATIC_DRAW
);
if
(
uvs
.
length
>
0
)
{
buffer
.
uvs
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
buffer
.
uvs
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
uvs
),
_gl
.
STATIC_DRAW
);
}
buffer
.
faces
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffer
.
faces
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
new
Uint16Array
(
faces
),
_gl
.
STATIC_DRAW
);
buffers
.
faceBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffers
.
faceBuffer
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
new
Uint16Array
(
facesArray
),
_gl
.
STATIC_DRAW
);
buffer
.
lines
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffer
.
lines
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
new
Uint16Array
(
lines
),
_gl
.
STATIC_DRAW
);
buffers
.
lineBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
buffers
.
lineBuffer
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
new
Uint16Array
(
linesArray
),
_gl
.
STATIC_DRAW
);
buffers
.
push
(
buffer
);
buffers
.
faceCount
=
facesArray
.
length
;
buffers
.
lineCount
=
linesArray
.
length
;
// }
geometry
.
__webglBuffers
=
buffers
;
...
...
src/scenes/Scene.js
浏览文件 @
39c7e8da
...
...
@@ -9,7 +9,13 @@ THREE.Scene = function () {
this
.
addObject
=
function
(
object
)
{
this
.
objects
.
push
(
object
);
var
i
=
this
.
objects
.
indexOf
(
object
);
if
(
i
===
-
1
)
{
this
.
objects
.
push
(
object
);
}
};
...
...
@@ -22,12 +28,18 @@ THREE.Scene = function () {
this
.
objects
.
splice
(
i
,
1
);
}
};
this
.
addLight
=
function
(
light
)
{
this
.
lights
.
push
(
light
);
var
i
=
this
.
lights
.
indexOf
(
light
);
if
(
i
===
-
1
)
{
this
.
lights
.
push
(
light
);
}
};
...
...
@@ -46,6 +58,7 @@ THREE.Scene = function () {
this
.
toString
=
function
()
{
return
'
THREE.Scene (
'
+
this
.
objects
+
'
)
'
;
};
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录