Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
dabb95b3
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,体验更适合开发者的 AI 搜索 >>
提交
dabb95b3
编写于
1月 08, 2021
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed unit tests.
上级
8c4ff573
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
0 addition
and
964 deletion
+0
-964
test/unit/src/core/BufferGeometry.tests.js
test/unit/src/core/BufferGeometry.tests.js
+0
-309
test/unit/src/core/DirectGeometry.tests.js
test/unit/src/core/DirectGeometry.tests.js
+0
-191
test/unit/src/core/Geometry.tests.js
test/unit/src/core/Geometry.tests.js
+0
-462
test/unit/three.source.unit.js
test/unit/three.source.unit.js
+0
-2
未找到文件。
test/unit/src/core/BufferGeometry.tests.js
浏览文件 @
dabb95b3
...
...
@@ -6,16 +6,9 @@ import {
Uint16BufferAttribute
,
Uint32BufferAttribute
}
from
'
../../../../src/core/BufferAttribute
'
;
import
{
Color
}
from
'
../../../../src/math/Color
'
;
import
{
Vector2
}
from
'
../../../../src/math/Vector2
'
;
import
{
Vector3
}
from
'
../../../../src/math/Vector3
'
;
import
{
Vector4
}
from
'
../../../../src/math/Vector4
'
;
import
{
Matrix4
}
from
'
../../../../src/math/Matrix4
'
;
import
{
Sphere
}
from
'
../../../../src/math/Sphere
'
;
import
{
Geometry
}
from
'
../../../../src/core/Geometry
'
;
import
{
Face3
}
from
'
../../../../src/core/Face3
'
;
import
{
Mesh
}
from
'
../../../../src/objects/Mesh
'
;
import
{
Line
}
from
'
../../../../src/objects/Line.js
'
;
import
{
x
,
y
,
...
...
@@ -86,36 +79,6 @@ function getNormalsForVertices( vertices, assert ) {
}
function
comparePositions
(
pos
,
v
)
{
return
(
pos
[
0
]
===
v
[
0
].
x
&&
pos
[
1
]
===
v
[
0
].
y
&&
pos
[
2
]
===
v
[
0
].
z
&&
pos
[
3
]
===
v
[
1
].
x
&&
pos
[
4
]
===
v
[
1
].
y
&&
pos
[
5
]
===
v
[
1
].
z
&&
pos
[
6
]
===
v
[
2
].
x
&&
pos
[
7
]
===
v
[
2
].
y
&&
pos
[
8
]
===
v
[
2
].
z
);
}
function
compareColors
(
col
,
c
)
{
return
(
col
[
0
]
===
c
[
0
].
r
&&
col
[
1
]
===
c
[
0
].
g
&&
col
[
2
]
===
c
[
0
].
b
&&
col
[
3
]
===
c
[
1
].
r
&&
col
[
4
]
===
c
[
1
].
g
&&
col
[
5
]
===
c
[
1
].
b
&&
col
[
6
]
===
c
[
2
].
r
&&
col
[
7
]
===
c
[
2
].
g
&&
col
[
8
]
===
c
[
2
].
b
);
}
function
compareUvs
(
uvs
,
u
)
{
return
(
uvs
[
0
]
===
u
[
0
].
x
&&
uvs
[
1
]
===
u
[
0
].
y
&&
uvs
[
2
]
===
u
[
1
].
x
&&
uvs
[
3
]
===
u
[
1
].
y
&&
uvs
[
4
]
===
u
[
2
].
x
&&
uvs
[
5
]
===
u
[
2
].
y
);
}
export
default
QUnit
.
module
(
'
Core
'
,
()
=>
{
QUnit
.
module
(
'
BufferGeometry
'
,
()
=>
{
...
...
@@ -356,278 +319,6 @@ export default QUnit.module( 'Core', () => {
}
);
QUnit
.
test
(
"
setFromObject
"
,
(
assert
)
=>
{
var
lineGeo
=
new
Geometry
();
lineGeo
.
vertices
.
push
(
new
Vector3
(
-
10
,
0
,
0
),
new
Vector3
(
0
,
10
,
0
),
new
Vector3
(
10
,
0
,
0
)
);
lineGeo
.
colors
.
push
(
new
Color
(
1
,
0
,
0
),
new
Color
(
0
,
1
,
0
),
new
Color
(
0
,
0
,
1
)
);
var
line
=
new
Line
(
lineGeo
,
null
);
var
geometry
=
new
BufferGeometry
().
setFromObject
(
line
);
var
pos
=
geometry
.
attributes
.
position
.
array
;
var
col
=
geometry
.
attributes
.
color
.
array
;
var
v
=
lineGeo
.
vertices
;
var
c
=
lineGeo
.
colors
;
assert
.
ok
(
// position exists
pos
!==
undefined
&&
// vertex arrays have the same size
v
.
length
*
3
===
pos
.
length
&&
// there are three complete vertices (each vertex contains three values)
geometry
.
attributes
.
position
.
count
===
3
&&
// check if both arrays contains the same data
pos
[
0
]
===
v
[
0
].
x
&&
pos
[
1
]
===
v
[
0
].
y
&&
pos
[
2
]
===
v
[
0
].
z
&&
pos
[
3
]
===
v
[
1
].
x
&&
pos
[
4
]
===
v
[
1
].
y
&&
pos
[
5
]
===
v
[
1
].
z
&&
pos
[
6
]
===
v
[
2
].
x
&&
pos
[
7
]
===
v
[
2
].
y
&&
pos
[
8
]
===
v
[
2
].
z
,
"
positions are equal
"
);
assert
.
ok
(
// color exists
col
!==
undefined
&&
// color arrays have the same size
c
.
length
*
3
===
col
.
length
&&
// there are three complete colors (each color contains three values)
geometry
.
attributes
.
color
.
count
===
3
&&
// check if both arrays contains the same data
col
[
0
]
===
c
[
0
].
r
&&
col
[
1
]
===
c
[
0
].
g
&&
col
[
2
]
===
c
[
0
].
b
&&
col
[
3
]
===
c
[
1
].
r
&&
col
[
4
]
===
c
[
1
].
g
&&
col
[
5
]
===
c
[
1
].
b
&&
col
[
6
]
===
c
[
2
].
r
&&
col
[
7
]
===
c
[
2
].
g
&&
col
[
8
]
===
c
[
2
].
b
,
"
colors are equal
"
);
}
);
QUnit
.
test
(
"
setFromObject (more)
"
,
(
assert
)
=>
{
var
lineGeo
=
new
Geometry
();
lineGeo
.
vertices
.
push
(
new
Vector3
(
-
10
,
0
,
0
),
new
Vector3
(
0
,
10
,
0
),
new
Vector3
(
10
,
0
,
0
)
);
lineGeo
.
colors
.
push
(
new
Color
(
1
,
0
,
0
),
new
Color
(
0
,
1
,
0
),
new
Color
(
0
,
0
,
1
)
);
lineGeo
.
computeBoundingBox
();
lineGeo
.
computeBoundingSphere
();
var
line
=
new
Line
(
lineGeo
);
var
geometry
=
new
BufferGeometry
().
setFromObject
(
line
);
assert
.
ok
(
geometry
.
boundingBox
.
equals
(
lineGeo
.
boundingBox
),
"
BoundingBox was set correctly
"
);
assert
.
ok
(
geometry
.
boundingSphere
.
equals
(
lineGeo
.
boundingSphere
),
"
BoundingSphere was set correctly
"
);
var
pos
=
geometry
.
attributes
.
position
.
array
;
var
col
=
geometry
.
attributes
.
color
.
array
;
var
v
=
lineGeo
.
vertices
;
var
c
=
lineGeo
.
colors
;
// adapted from setFromObject QUnit.test (way up)
assert
.
notStrictEqual
(
pos
,
undefined
,
"
Position attribute exists
"
);
assert
.
strictEqual
(
v
.
length
*
3
,
pos
.
length
,
"
Vertex arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
position
.
count
,
3
,
"
Correct number of vertices
"
);
assert
.
ok
(
comparePositions
(
pos
,
v
),
"
Positions are identical
"
);
assert
.
notStrictEqual
(
col
,
undefined
,
"
Color attribute exists
"
);
assert
.
strictEqual
(
c
.
length
*
3
,
col
.
length
,
"
Color arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
color
.
count
,
3
,
"
Correct number of colors
"
);
assert
.
ok
(
compareColors
(
col
,
c
),
"
Colors are identical
"
);
// setFromObject with a Mesh as object
lineGeo
.
faces
.
push
(
new
Face3
(
0
,
1
,
2
)
);
var
lineMesh
=
new
Mesh
(
lineGeo
);
var
geometry
=
new
BufferGeometry
().
setFromObject
(
lineMesh
);
// no colors
var
pos
=
geometry
.
attributes
.
position
.
array
;
var
v
=
lineGeo
.
vertices
;
assert
.
notStrictEqual
(
pos
,
undefined
,
"
Mesh: position attribute exists
"
);
assert
.
strictEqual
(
v
.
length
*
3
,
pos
.
length
,
"
Mesh: vertex arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
position
.
count
,
3
,
"
Mesh: correct number of vertices
"
);
assert
.
ok
(
comparePositions
(
pos
,
v
),
"
Mesh: positions are identical
"
);
}
);
QUnit
.
test
(
"
updateFromObject
"
,
(
assert
)
=>
{
var
geo
=
new
Geometry
();
geo
.
vertices
.
push
(
new
Vector3
(
-
10
,
0
,
0
),
new
Vector3
(
0
,
10
,
0
),
new
Vector3
(
10
,
0
,
0
)
);
geo
.
faces
.
push
(
new
Face3
(
0
,
1
,
2
)
);
geo
.
faces
[
0
].
vertexColors
.
push
(
new
Color
(
1
,
0
,
0
),
new
Color
(
0
,
1
,
0
),
new
Color
(
0
,
0
,
1
)
);
geo
.
faceVertexUvs
[
0
]
=
[
[
new
Vector2
(
0
,
0
),
new
Vector2
(
1
,
0
),
new
Vector2
(
1
,
1
)
]
];
geo
.
computeFaceNormals
();
geo
.
computeVertexNormals
();
geo
.
verticesNeedUpdate
=
true
;
geo
.
normalsNeedUpdate
=
true
;
geo
.
colorsNeedUpdate
=
true
;
geo
.
uvsNeedUpdate
=
true
;
geo
.
groupsNeedUpdate
=
true
;
var
mesh
=
new
Mesh
(
geo
);
var
geometry
=
new
BufferGeometry
();
geometry
.
updateFromObject
(
mesh
);
// first call to create the underlying structure (DirectGeometry)
geometry
.
updateFromObject
(
mesh
);
// second time to actually go thru the motions and update
var
pos
=
geometry
.
attributes
.
position
.
array
;
var
col
=
geometry
.
attributes
.
color
.
array
;
var
norm
=
geometry
.
attributes
.
normal
.
array
;
var
uvs
=
geometry
.
attributes
.
uv
.
array
;
var
v
=
geo
.
vertices
;
var
c
=
geo
.
faces
[
0
].
vertexColors
;
var
n
=
geo
.
faces
[
0
].
vertexNormals
;
var
u
=
geo
.
faceVertexUvs
[
0
][
0
];
assert
.
notStrictEqual
(
pos
,
undefined
,
"
Position attribute exists
"
);
assert
.
strictEqual
(
v
.
length
*
3
,
pos
.
length
,
"
Both arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
position
.
count
,
v
.
length
,
"
Correct number of vertices
"
);
assert
.
ok
(
comparePositions
(
pos
,
v
),
"
Positions are identical
"
);
assert
.
notStrictEqual
(
col
,
undefined
,
"
Color attribute exists
"
);
assert
.
strictEqual
(
c
.
length
*
3
,
col
.
length
,
"
Both arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
color
.
count
,
c
.
length
,
"
Correct number of colors
"
);
assert
.
ok
(
compareColors
(
col
,
c
),
"
Colors are identical
"
);
assert
.
notStrictEqual
(
norm
,
undefined
,
"
Normal attribute exists
"
);
assert
.
strictEqual
(
n
.
length
*
3
,
norm
.
length
,
"
Both arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
normal
.
count
,
n
.
length
,
"
Correct number of normals
"
);
assert
.
ok
(
comparePositions
(
norm
,
n
),
"
Normals are identical
"
);
assert
.
notStrictEqual
(
uvs
,
undefined
,
"
UV attribute exists
"
);
assert
.
strictEqual
(
u
.
length
*
2
,
uvs
.
length
,
"
Both arrays have the same size
"
);
assert
.
strictEqual
(
geometry
.
attributes
.
uv
.
count
,
u
.
length
,
"
Correct number of UV coordinates
"
);
assert
.
ok
(
compareUvs
(
uvs
,
u
),
"
UVs are identical
"
);
}
);
QUnit
.
test
(
"
fromGeometry/fromDirectGeometry
"
,
(
assert
)
=>
{
// geometry definition
var
geometry
=
new
Geometry
();
// vertices
var
v1
=
new
Vector3
(
1
,
-
1
,
0
);
var
v2
=
new
Vector3
(
1
,
1
,
0
);
var
v3
=
new
Vector3
(
-
1
,
1
,
0
);
var
v4
=
new
Vector3
(
-
1
,
-
1
,
0
);
// faces, normals and colors
geometry
.
vertices
.
push
(
v1
,
v2
,
v3
,
v4
);
var
f1
=
new
Face3
(
0
,
1
,
2
);
f1
.
normal
.
set
(
0
,
0
,
1
);
f1
.
color
.
set
(
0xff0000
);
var
f2
=
new
Face3
(
2
,
3
,
0
);
f2
.
normal
.
set
(
0
,
0
,
1
);
f2
.
color
.
set
(
0xff0000
);
geometry
.
faces
.
push
(
f1
,
f2
);
// uvs
var
uvs
=
geometry
.
faceVertexUvs
[
0
];
uvs
.
length
=
0
;
uvs
.
push
(
[
new
Vector2
(
1
,
0
),
new
Vector2
(
1
,
1
),
new
Vector2
(
0
,
1
)
]
);
uvs
.
push
(
[
new
Vector2
(
0
,
1
),
new
Vector2
(
0
,
0
),
new
Vector2
(
1
,
0
)
]
);
// skin weights
var
sw1
=
new
Vector4
(
0.8
,
0.2
,
0
,
0
);
var
sw2
=
new
Vector4
(
0.7
,
0.2
,
0.1
,
0
);
var
sw3
=
new
Vector4
(
0.8
,
0.1
,
0.1
,
0
);
var
sw4
=
new
Vector4
(
1
,
0
,
0
,
0
);
geometry
.
skinWeights
.
push
(
sw1
,
sw2
,
sw3
,
sw4
);
// skin indices
var
si1
=
new
Vector4
(
0
,
1
,
2
,
3
);
var
si2
=
new
Vector4
(
2
,
3
,
4
,
5
);
var
si3
=
new
Vector4
(
4
,
5
,
6
,
7
);
var
si4
=
new
Vector4
(
6
,
7
,
8
,
9
);
geometry
.
skinIndices
.
push
(
si1
,
si2
,
si3
,
si4
);
// create BufferGeometry
var
bufferGeometry
=
new
BufferGeometry
().
fromGeometry
(
geometry
);
// expected values
var
vertices
=
new
Float32Array
(
[
1
,
-
1
,
0
,
1
,
1
,
0
,
-
1
,
1
,
0
,
-
1
,
1
,
0
,
-
1
,
-
1
,
0
,
1
,
-
1
,
0
]
);
var
normals
=
new
Float32Array
(
[
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
]
);
var
colors
=
new
Float32Array
(
[
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
]
);
var
uvs
=
new
Float32Array
(
[
1
,
0
,
1
,
1
,
0
,
1
,
0
,
1
,
0
,
0
,
1
,
0
]
);
var
skinIndices
=
new
Float32Array
(
[
0
,
1
,
2
,
3
,
2
,
3
,
4
,
5
,
4
,
5
,
6
,
7
,
4
,
5
,
6
,
7
,
6
,
7
,
8
,
9
,
0
,
1
,
2
,
3
]
);
var
skindWeights
=
new
Float32Array
(
[
0.8
,
0.2
,
0
,
0
,
0.7
,
0.2
,
0.1
,
0
,
0.8
,
0.1
,
0.1
,
0
,
0.8
,
0.1
,
0.1
,
0
,
1
,
0
,
0
,
0
,
0.8
,
0.2
,
0
,
0
]
);
var
attributes
=
bufferGeometry
.
attributes
;
assert
.
deepEqual
(
attributes
.
position
.
array
,
vertices
,
"
Vertices are as expected
"
);
assert
.
deepEqual
(
attributes
.
normal
.
array
,
normals
,
"
Normals are as expected
"
);
assert
.
deepEqual
(
attributes
.
color
.
array
,
colors
,
"
Colors are as expected
"
);
assert
.
deepEqual
(
attributes
.
uv
.
array
,
uvs
,
"
Texture coordinates are as expected
"
);
assert
.
deepEqual
(
attributes
.
skinIndex
.
array
,
skinIndices
,
"
Skin indices are as expected
"
);
assert
.
deepEqual
(
attributes
.
skinWeight
.
array
,
skindWeights
,
"
Skin weights are as expected
"
);
}
);
QUnit
.
test
(
"
computeBoundingBox
"
,
(
assert
)
=>
{
var
bb
=
getBBForVertices
(
[
-
1
,
-
2
,
-
3
,
13
,
-
2
,
-
3.5
,
-
1
,
-
20
,
0
,
-
4
,
5
,
6
]
);
...
...
test/unit/src/core/DirectGeometry.tests.js
已删除
100644 → 0
浏览文件 @
8c4ff573
/* global QUnit */
import
{
DirectGeometry
}
from
'
../../../../src/core/DirectGeometry
'
;
import
{
Vector2
}
from
'
../../../../src/math/Vector2
'
;
import
{
Vector3
}
from
'
../../../../src/math/Vector3
'
;
import
{
Vector4
}
from
'
../../../../src/math/Vector4
'
;
import
{
Color
}
from
'
../../../../src/math/Color
'
;
import
{
Face3
}
from
'
../../../../src/core/Face3
'
;
import
{
Geometry
}
from
'
../../../../src/core/Geometry
'
;
export
default
QUnit
.
module
(
'
Core
'
,
()
=>
{
QUnit
.
module
(
'
DirectGeometry
'
,
()
=>
{
// INSTANCING
QUnit
.
todo
(
"
Instancing
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
// PUBLIC STUFF
QUnit
.
test
(
"
computeGroups
"
,
(
assert
)
=>
{
var
a
=
new
DirectGeometry
();
var
b
=
new
Geometry
();
var
expected
=
[
{
start
:
0
,
materialIndex
:
0
,
count
:
3
},
{
start
:
3
,
materialIndex
:
1
,
count
:
3
},
{
start
:
6
,
materialIndex
:
2
,
count
:
6
}
];
// we only care for materialIndex
b
.
faces
.
push
(
new
Face3
(
0
,
0
,
0
,
undefined
,
undefined
,
0
),
new
Face3
(
0
,
0
,
0
,
undefined
,
undefined
,
1
),
new
Face3
(
0
,
0
,
0
,
undefined
,
undefined
,
2
),
new
Face3
(
0
,
0
,
0
,
undefined
,
undefined
,
2
)
);
a
.
computeGroups
(
b
);
assert
.
deepEqual
(
a
.
groups
,
expected
,
"
Groups are as expected
"
);
}
);
QUnit
.
test
(
"
fromGeometry
"
,
(
assert
)
=>
{
// geometry definition
var
geometry
=
new
Geometry
();
// vertices
var
v1
=
new
Vector3
(
1
,
-
1
,
0
);
var
v2
=
new
Vector3
(
1
,
1
,
0
);
var
v3
=
new
Vector3
(
-
1
,
1
,
0
);
var
v4
=
new
Vector3
(
-
1
,
-
1
,
0
);
// faces, normals and colors
geometry
.
vertices
.
push
(
v1
,
v2
,
v3
,
v4
);
var
f1
=
new
Face3
(
0
,
1
,
2
);
f1
.
normal
.
set
(
0
,
0
,
1
);
f1
.
color
.
set
(
0xff0000
);
var
f2
=
new
Face3
(
2
,
3
,
0
);
f2
.
normal
.
set
(
0
,
0
,
1
);
f2
.
color
.
set
(
0xff0000
);
geometry
.
faces
.
push
(
f1
,
f2
);
// uvs
var
uvs
=
geometry
.
faceVertexUvs
[
0
];
uvs
.
length
=
0
;
uvs
.
push
(
[
new
Vector2
(
1
,
0
),
new
Vector2
(
1
,
1
),
new
Vector2
(
0
,
1
)
]
);
uvs
.
push
(
[
new
Vector2
(
0
,
1
),
new
Vector2
(
0
,
0
),
new
Vector2
(
1
,
0
)
]
);
// skin weights
var
sw1
=
new
Vector4
(
0.8
,
0.2
,
0
,
0
);
var
sw2
=
new
Vector4
(
0.7
,
0.2
,
0.1
,
0
);
var
sw3
=
new
Vector4
(
0.8
,
0.1
,
0.1
,
0
);
var
sw4
=
new
Vector4
(
1
,
0
,
0
,
0
);
geometry
.
skinWeights
.
push
(
sw1
,
sw2
,
sw3
,
sw4
);
// skin indices
var
si1
=
new
Vector4
(
0
,
1
,
2
,
3
);
var
si2
=
new
Vector4
(
2
,
3
,
4
,
5
);
var
si3
=
new
Vector4
(
4
,
5
,
6
,
7
);
var
si4
=
new
Vector4
(
6
,
7
,
8
,
9
);
geometry
.
skinIndices
.
push
(
si1
,
si2
,
si3
,
si4
);
// create DirectGeometry
var
directGeometry
=
new
DirectGeometry
().
fromGeometry
(
geometry
);
// expected values
var
vertices
=
[
// first face
new
Vector3
(
1
,
-
1
,
0
),
new
Vector3
(
1
,
1
,
0
),
new
Vector3
(
-
1
,
1
,
0
),
// second face
new
Vector3
(
-
1
,
1
,
0
),
new
Vector3
(
-
1
,
-
1
,
0
),
new
Vector3
(
1
,
-
1
,
0
)
];
var
normals
=
[
// first face
new
Vector3
(
0
,
0
,
1
),
new
Vector3
(
0
,
0
,
1
),
new
Vector3
(
0
,
0
,
1
),
// second face
new
Vector3
(
0
,
0
,
1
),
new
Vector3
(
0
,
0
,
1
),
new
Vector3
(
0
,
0
,
1
)
];
var
colors
=
[
// first face
new
Color
(
1
,
0
,
0
),
new
Color
(
1
,
0
,
0
),
new
Color
(
1
,
0
,
0
),
// second face
new
Color
(
1
,
0
,
0
),
new
Color
(
1
,
0
,
0
),
new
Color
(
1
,
0
,
0
)
];
var
uvs
=
[
// first face
new
Vector2
(
1
,
0
),
new
Vector2
(
1
,
1
),
new
Vector2
(
0
,
1
),
// second face
new
Vector2
(
0
,
1
),
new
Vector2
(
0
,
0
),
new
Vector2
(
1
,
0
)
];
var
skinIndices
=
[
// first face
new
Vector4
(
0
,
1
,
2
,
3
),
new
Vector4
(
2
,
3
,
4
,
5
),
new
Vector4
(
4
,
5
,
6
,
7
),
// second face
new
Vector4
(
4
,
5
,
6
,
7
),
new
Vector4
(
6
,
7
,
8
,
9
),
new
Vector4
(
0
,
1
,
2
,
3
)
];
var
skinWeights
=
[
// first face
new
Vector4
(
0.8
,
0.2
,
0
,
0
),
new
Vector4
(
0.7
,
0.2
,
0.1
,
0
),
new
Vector4
(
0.8
,
0.1
,
0.1
,
0
),
// second face
new
Vector4
(
0.8
,
0.1
,
0.1
,
0
),
new
Vector4
(
1
,
0
,
0
,
0
),
new
Vector4
(
0.8
,
0.2
,
0
,
0
)
];
assert
.
deepEqual
(
directGeometry
.
vertices
,
vertices
,
"
Vertices are as expected
"
);
assert
.
deepEqual
(
directGeometry
.
normals
,
normals
,
"
Normals are as expected
"
);
assert
.
deepEqual
(
directGeometry
.
colors
,
colors
,
"
Colors are as expected
"
);
assert
.
deepEqual
(
directGeometry
.
uvs
,
uvs
,
"
Texture coordinates are as expected
"
);
assert
.
deepEqual
(
directGeometry
.
skinIndices
,
skinIndices
,
"
Skin indices are as expected
"
);
assert
.
deepEqual
(
directGeometry
.
skinWeights
,
skinWeights
,
"
Skin weights are as expected
"
);
}
);
}
);
}
);
test/unit/src/core/Geometry.tests.js
已删除
100644 → 0
浏览文件 @
8c4ff573
/* global QUnit */
import
{
Geometry
}
from
'
../../../../src/core/Geometry
'
;
import
{
BufferAttribute
}
from
'
../../../../src/core/BufferAttribute
'
;
import
{
BufferGeometry
}
from
'
../../../../src/core/BufferGeometry
'
;
import
{
BoxBufferGeometry
}
from
'
../../../../src/geometries/BoxBufferGeometry
'
;
import
{
DodecahedronBufferGeometry
}
from
'
../../../../src/geometries/DodecahedronBufferGeometry
'
;
import
{
Vector3
}
from
'
../../../../src/math/Vector3
'
;
import
{
Matrix4
}
from
'
../../../../src/math/Matrix4
'
;
import
{
Face3
}
from
'
../../../../src/core/Face3
'
;
import
{
x
,
y
,
z
,
eps
}
from
'
../math/Constants.tests
'
;
function
getGeometryByParams
(
x1
,
y1
,
z1
,
x2
,
y2
,
z2
,
x3
,
y3
,
z3
)
{
var
geometry
=
new
Geometry
();
// a triangle
geometry
.
vertices
=
[
new
Vector3
(
x1
,
y1
,
z1
),
new
Vector3
(
x2
,
y2
,
z2
),
new
Vector3
(
x3
,
y3
,
z3
)
];
return
geometry
;
}
function
getGeometry
()
{
return
getGeometryByParams
(
-
0.5
,
0
,
0
,
0.5
,
0
,
0
,
0
,
1
,
0
);
}
export
default
QUnit
.
module
(
'
Core
'
,
()
=>
{
QUnit
.
module
(
'
Geometry
'
,
()
=>
{
// INHERITANCE
QUnit
.
todo
(
"
Extending
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
// INSTANCING
QUnit
.
todo
(
"
Instancing
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
// PUBLIC STUFF
QUnit
.
todo
(
"
isGeometry
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
test
(
"
applyMatrix4
"
,
(
assert
)
=>
{
var
geometry
=
getGeometry
();
geometry
.
faces
.
push
(
new
Face3
(
0
,
1
,
2
)
);
var
m
=
new
Matrix4
();
var
expectedVerts
=
[
new
Vector3
(
1.5
,
3
,
4
),
new
Vector3
(
2.5
,
3
,
4
),
new
Vector3
(
2
,
3
,
5
)
];
var
v0
,
v1
,
v2
;
m
.
makeRotationX
(
Math
.
PI
/
2
);
m
.
setPosition
(
new
Vector3
(
x
,
y
,
z
)
);
geometry
.
applyMatrix4
(
m
);
v0
=
geometry
.
vertices
[
0
];
v1
=
geometry
.
vertices
[
1
];
v2
=
geometry
.
vertices
[
2
];
assert
.
ok
(
Math
.
abs
(
v0
.
x
-
expectedVerts
[
0
].
x
)
<=
eps
&&
Math
.
abs
(
v0
.
y
-
expectedVerts
[
0
].
y
)
<=
eps
&&
Math
.
abs
(
v0
.
z
-
expectedVerts
[
0
].
z
)
<=
eps
,
"
First vertex is as expected
"
);
assert
.
ok
(
Math
.
abs
(
v1
.
x
-
expectedVerts
[
1
].
x
)
<=
eps
&&
Math
.
abs
(
v1
.
y
-
expectedVerts
[
1
].
y
)
<=
eps
&&
Math
.
abs
(
v1
.
z
-
expectedVerts
[
1
].
z
)
<=
eps
,
"
Second vertex is as expected
"
);
assert
.
ok
(
Math
.
abs
(
v2
.
x
-
expectedVerts
[
2
].
x
)
<=
eps
&&
Math
.
abs
(
v2
.
y
-
expectedVerts
[
2
].
y
)
<=
eps
&&
Math
.
abs
(
v2
.
z
-
expectedVerts
[
2
].
z
)
<=
eps
,
"
Third vertex is as expected
"
);
}
);
QUnit
.
test
(
"
rotateX
"
,
(
assert
)
=>
{
var
geometry
=
getGeometry
();
var
matrix
=
new
Matrix4
();
matrix
.
makeRotationX
(
Math
.
PI
/
2
);
// 90 degree
geometry
.
applyMatrix4
(
matrix
);
var
v0
=
geometry
.
vertices
[
0
],
v1
=
geometry
.
vertices
[
1
],
v2
=
geometry
.
vertices
[
2
];
assert
.
ok
(
v0
.
x
===
-
0.5
&&
v0
.
y
===
0
&&
v0
.
z
===
0
,
"
first vertex was rotated
"
);
assert
.
ok
(
v1
.
x
===
0.5
&&
v1
.
y
===
0
&&
v1
.
z
===
0
,
"
second vertex was rotated
"
);
assert
.
ok
(
v2
.
x
===
0
&&
v2
.
y
<
Number
.
EPSILON
&&
v2
.
z
===
1
,
"
third vertex was rotated
"
);
}
);
QUnit
.
test
(
"
rotateY
"
,
(
assert
)
=>
{
var
geometry
=
getGeometry
();
var
matrix
=
new
Matrix4
();
matrix
.
makeRotationY
(
Math
.
PI
);
// 180 degrees
geometry
.
applyMatrix4
(
matrix
);
var
v0
=
geometry
.
vertices
[
0
],
v1
=
geometry
.
vertices
[
1
],
v2
=
geometry
.
vertices
[
2
];
assert
.
ok
(
v0
.
x
===
0.5
&&
v0
.
y
===
0
&&
v0
.
z
<
Number
.
EPSILON
,
"
first vertex was rotated
"
);
assert
.
ok
(
v1
.
x
===
-
0.5
&&
v1
.
y
===
0
&&
v1
.
z
<
Number
.
EPSILON
,
"
second vertex was rotated
"
);
assert
.
ok
(
v2
.
x
===
0
&&
v2
.
y
===
1
&&
v2
.
z
===
0
,
"
third vertex was rotated
"
);
}
);
QUnit
.
test
(
"
rotateZ
"
,
(
assert
)
=>
{
var
geometry
=
getGeometry
();
var
matrix
=
new
Matrix4
();
matrix
.
makeRotationZ
(
Math
.
PI
/
2
*
3
);
// 270 degrees
geometry
.
applyMatrix4
(
matrix
);
var
v0
=
geometry
.
vertices
[
0
],
v1
=
geometry
.
vertices
[
1
],
v2
=
geometry
.
vertices
[
2
];
assert
.
ok
(
v0
.
x
<
Number
.
EPSILON
&&
v0
.
y
===
0.5
&&
v0
.
z
===
0
,
"
first vertex was rotated
"
);
assert
.
ok
(
v1
.
x
<
Number
.
EPSILON
&&
v1
.
y
===
-
0.5
&&
v1
.
z
===
0
,
"
second vertex was rotated
"
);
assert
.
ok
(
v2
.
x
===
1
&&
v2
.
y
<
Number
.
EPSILON
&&
v2
.
z
===
0
,
"
third vertex was rotated
"
);
}
);
QUnit
.
test
(
"
translate
"
,
(
assert
)
=>
{
var
a
=
getGeometry
();
var
expected
=
[
new
Vector3
(
-
2.5
,
3
,
-
4
),
new
Vector3
(
-
1.5
,
3
,
-
4
),
new
Vector3
(
-
2
,
4
,
-
4
)
];
var
v
;
a
.
translate
(
-
x
,
y
,
-
z
);
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
v
=
a
.
vertices
[
i
];
assert
.
ok
(
Math
.
abs
(
v
.
x
-
expected
[
i
].
x
)
<=
eps
&&
Math
.
abs
(
v
.
y
-
expected
[
i
].
y
)
<=
eps
&&
Math
.
abs
(
v
.
z
-
expected
[
i
].
z
)
<=
eps
,
"
Vertex #
"
+
i
+
"
was translated as expected
"
);
}
}
);
QUnit
.
test
(
"
scale
"
,
(
assert
)
=>
{
var
a
=
getGeometry
();
var
expected
=
[
new
Vector3
(
-
1
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
3
,
0
)
];
var
v
;
a
.
scale
(
2
,
3
,
4
);
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
v
=
a
.
vertices
[
i
];
assert
.
ok
(
Math
.
abs
(
v
.
x
-
expected
[
i
].
x
)
<=
eps
&&
Math
.
abs
(
v
.
y
-
expected
[
i
].
y
)
<=
eps
&&
Math
.
abs
(
v
.
z
-
expected
[
i
].
z
)
<=
eps
,
"
Vertex #
"
+
i
+
"
was scaled as expected
"
);
}
}
);
QUnit
.
test
(
"
lookAt
"
,
(
assert
)
=>
{
var
a
=
getGeometry
();
var
expected
=
[
new
Vector3
(
-
0.5
,
0
,
0
),
new
Vector3
(
0.5
,
0
,
0
),
new
Vector3
(
0
,
0.5
*
Math
.
sqrt
(
2
),
0.5
*
Math
.
sqrt
(
2
)
)
];
a
.
lookAt
(
new
Vector3
(
0
,
-
1
,
1
)
);
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
var
v
=
a
.
vertices
[
i
];
assert
.
ok
(
Math
.
abs
(
v
.
x
-
expected
[
i
].
x
)
<=
eps
&&
Math
.
abs
(
v
.
y
-
expected
[
i
].
y
)
<=
eps
&&
Math
.
abs
(
v
.
z
-
expected
[
i
].
z
)
<=
eps
,
"
Vertex #
"
+
i
+
"
was adjusted as expected
"
);
}
}
);
QUnit
.
test
(
"
fromBufferGeometry
"
,
(
assert
)
=>
{
var
bufferGeometry
=
new
BufferGeometry
();
bufferGeometry
.
setAttribute
(
'
position
'
,
new
BufferAttribute
(
new
Float32Array
(
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]
),
3
)
);
bufferGeometry
.
setAttribute
(
'
color
'
,
new
BufferAttribute
(
new
Float32Array
(
[
0
,
0
,
0
,
0.5
,
0.5
,
0.5
,
1
,
1
,
1
]
),
3
)
);
bufferGeometry
.
setAttribute
(
'
normal
'
,
new
BufferAttribute
(
new
Float32Array
(
[
0
,
1
,
0
,
1
,
0
,
1
,
1
,
1
,
0
]
),
3
)
);
bufferGeometry
.
setAttribute
(
'
uv
'
,
new
BufferAttribute
(
new
Float32Array
(
[
0
,
0
,
0
,
1
,
1
,
1
]
),
2
)
);
bufferGeometry
.
setAttribute
(
'
uv2
'
,
new
BufferAttribute
(
new
Float32Array
(
[
0
,
0
,
0
,
1
,
1
,
1
]
),
2
)
);
var
geometry
=
new
Geometry
().
fromBufferGeometry
(
bufferGeometry
);
var
colors
=
geometry
.
colors
;
assert
.
ok
(
colors
[
0
].
r
===
0
&&
colors
[
0
].
g
===
0
&&
colors
[
0
].
b
===
0
&&
colors
[
1
].
r
===
0.5
&&
colors
[
1
].
g
===
0.5
&&
colors
[
1
].
b
===
0.5
&&
colors
[
2
].
r
===
1
&&
colors
[
2
].
g
===
1
&&
colors
[
2
].
b
===
1
,
"
colors were created well
"
);
var
vertices
=
geometry
.
vertices
;
assert
.
ok
(
vertices
[
0
].
x
===
1
&&
vertices
[
0
].
y
===
2
&&
vertices
[
0
].
z
===
3
&&
vertices
[
1
].
x
===
4
&&
vertices
[
1
].
y
===
5
&&
vertices
[
1
].
z
===
6
&&
vertices
[
2
].
x
===
7
&&
vertices
[
2
].
y
===
8
&&
vertices
[
2
].
z
===
9
,
"
vertices were created well
"
);
var
vNormals
=
geometry
.
faces
[
0
].
vertexNormals
;
assert
.
ok
(
vNormals
[
0
].
x
===
0
&&
vNormals
[
0
].
y
===
1
&&
vNormals
[
0
].
z
===
0
&&
vNormals
[
1
].
x
===
1
&&
vNormals
[
1
].
y
===
0
&&
vNormals
[
1
].
z
===
1
&&
vNormals
[
2
].
x
===
1
&&
vNormals
[
2
].
y
===
1
&&
vNormals
[
2
].
z
===
0
,
"
vertex normals were created well
"
);
}
);
QUnit
.
todo
(
"
center
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
test
(
"
normalize
"
,
(
assert
)
=>
{
var
a
=
getGeometry
();
var
sqrt
=
0.5
*
Math
.
sqrt
(
2
);
var
expected
=
[
new
Vector3
(
-
sqrt
,
-
sqrt
,
0
),
new
Vector3
(
sqrt
,
-
sqrt
,
0
),
new
Vector3
(
0
,
sqrt
,
0
)
];
var
v
;
a
.
normalize
();
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
v
=
a
.
vertices
[
i
];
assert
.
ok
(
Math
.
abs
(
v
.
x
-
expected
[
i
].
x
)
<=
eps
&&
Math
.
abs
(
v
.
y
-
expected
[
i
].
y
)
<=
eps
&&
Math
.
abs
(
v
.
z
-
expected
[
i
].
z
)
<=
eps
,
"
Vertex #
"
+
i
+
"
was normalized as expected
"
);
}
}
);
QUnit
.
todo
(
"
computeFaceNormals
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
computeVertexNormals
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
computeFlatVertexNormals
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
computeMorphNormals
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
test
(
"
computeBoundingBox
"
,
(
assert
)
=>
{
var
a
=
new
Geometry
().
fromBufferGeometry
(
new
DodecahedronBufferGeometry
()
);
a
.
computeBoundingBox
();
assert
.
strictEqual
(
a
.
boundingBox
.
isEmpty
(),
false
,
"
Bounding box isn't empty
"
);
var
allIn
=
true
;
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
if
(
!
a
.
boundingBox
.
containsPoint
(
a
.
vertices
[
i
]
)
)
{
allIn
=
false
;
}
}
assert
.
strictEqual
(
allIn
,
true
,
"
All vertices are inside the box
"
);
}
);
QUnit
.
test
(
"
computeBoundingSphere
"
,
(
assert
)
=>
{
var
a
=
new
Geometry
().
fromBufferGeometry
(
new
DodecahedronBufferGeometry
()
);
a
.
computeBoundingSphere
();
var
allIn
=
true
;
for
(
var
i
=
0
;
i
<
a
.
vertices
.
length
;
i
++
)
{
if
(
!
a
.
boundingSphere
.
containsPoint
(
a
.
vertices
[
i
]
)
)
{
allIn
=
false
;
}
}
assert
.
strictEqual
(
allIn
,
true
,
"
All vertices are inside the bounding sphere
"
);
}
);
QUnit
.
todo
(
"
merge
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
mergeMesh
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
test
(
"
mergeVertices
"
,
(
assert
)
=>
{
var
a
=
new
Geometry
();
var
b
=
new
BoxBufferGeometry
(
1
,
1
,
1
);
var
verts
,
faces
,
removed
;
a
.
fromBufferGeometry
(
b
);
removed
=
a
.
mergeVertices
();
verts
=
a
.
vertices
.
length
;
faces
=
a
.
faces
.
length
;
assert
.
strictEqual
(
removed
,
16
,
"
Removed the expected number of vertices
"
);
assert
.
strictEqual
(
verts
,
8
,
"
Minimum number of vertices remaining
"
);
assert
.
strictEqual
(
faces
,
12
,
"
Minimum number of faces remaining
"
);
}
);
QUnit
.
test
(
"
sortFacesByMaterialIndex
"
,
(
assert
)
=>
{
var
box
=
new
BoxBufferGeometry
(
1
,
1
,
1
);
var
a
=
new
Geometry
().
fromBufferGeometry
(
box
);
var
expected
=
[
0
,
0
,
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
5
,
5
];
a
.
faces
.
reverse
();
// a bit too simple probably, still missing stuff like checking new UVs
a
.
sortFacesByMaterialIndex
();
var
indices
=
[];
for
(
var
i
=
0
;
i
<
a
.
faces
.
length
;
i
++
)
{
indices
.
push
(
a
.
faces
[
i
].
materialIndex
);
}
assert
.
deepEqual
(
indices
,
expected
,
"
Faces in correct order
"
);
}
);
QUnit
.
test
(
"
toJSON
"
,
(
assert
)
=>
{
var
a
=
getGeometry
();
var
gold
=
{
"
metadata
"
:
{
"
version
"
:
4.5
,
"
type
"
:
"
Geometry
"
,
"
generator
"
:
"
Geometry.toJSON
"
},
"
uuid
"
:
null
,
"
type
"
:
"
Geometry
"
,
"
data
"
:
{
"
vertices
"
:
[
-
0.5
,
0
,
0
,
0.5
,
0
,
0
,
0
,
1
,
0
],
"
normals
"
:
[
0
,
0
,
1
],
"
faces
"
:
[
50
,
0
,
1
,
2
,
0
,
0
,
0
,
0
,
0
]
}
};
var
json
;
a
.
faces
.
push
(
new
Face3
(
0
,
1
,
2
)
);
a
.
computeFaceNormals
();
a
.
computeVertexNormals
();
json
=
a
.
toJSON
();
json
.
uuid
=
null
;
assert
.
deepEqual
(
json
,
gold
,
"
Generated JSON is as expected
"
);
}
);
QUnit
.
todo
(
"
clone
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
copy
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
dispose
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
}
);
}
);
test/unit/three.source.unit.js
浏览文件 @
dabb95b3
...
...
@@ -47,10 +47,8 @@ import './src/cameras/StereoCamera.tests';
import
'
./src/core/BufferAttribute.tests
'
;
import
'
./src/core/BufferGeometry.tests
'
;
import
'
./src/core/Clock.tests
'
;
import
'
./src/core/DirectGeometry.tests
'
;
import
'
./src/core/EventDispatcher.tests
'
;
import
'
./src/core/Face3.tests
'
;
import
'
./src/core/Geometry.tests
'
;
import
'
./src/core/InstancedBufferAttribute.tests
'
;
import
'
./src/core/InstancedBufferGeometry.tests
'
;
import
'
./src/core/InstancedInterleavedBuffer.tests
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录