Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
f7c93b82
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,发现更多精彩内容 >>
提交
f7c93b82
编写于
12月 23, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'bhouston/vector-index-accessors' into dev
上级
24668969
eb25ee76
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
697 addition
and
170 deletion
+697
-170
src/math/Quaternion.js
src/math/Quaternion.js
+1
-1
src/math/Vector2.js
src/math/Vector2.js
+35
-4
src/math/Vector3.js
src/math/Vector3.js
+37
-4
src/math/Vector4.js
src/math/Vector4.js
+40
-5
test/benchmark/benchmarking_float32array.html
test/benchmark/benchmarking_float32array.html
+1
-1
test/benchmark/benchmarking_vector3components.html
test/benchmark/benchmarking_vector3components.html
+20
-0
test/benchmark/benchmarking_vector3length.html
test/benchmark/benchmarking_vector3length.html
+20
-0
test/benchmark/benchmarking_vector3storage.html
test/benchmark/benchmarking_vector3storage.html
+20
-0
test/benchmark/core/Float32Array.js
test/benchmark/core/Float32Array.js
+108
-0
test/benchmark/core/Float32ArrayAccessPatterns.js
test/benchmark/core/Float32ArrayAccessPatterns.js
+0
-155
test/benchmark/core/Vector3Components.js
test/benchmark/core/Vector3Components.js
+149
-0
test/benchmark/core/Vector3Length.js
test/benchmark/core/Vector3Length.js
+88
-0
test/benchmark/core/Vector3Storage.js
test/benchmark/core/Vector3Storage.js
+120
-0
test/unit/math/Vector2.js
test/unit/math/Vector2.js
+16
-0
test/unit/math/Vector3.js
test/unit/math/Vector3.js
+20
-0
test/unit/math/Vector4.js
test/unit/math/Vector4.js
+22
-0
未找到文件。
src/math/Quaternion.js
浏览文件 @
f7c93b82
...
...
@@ -201,7 +201,7 @@ THREE.Quaternion.prototype = {
length
:
function
()
{
return
Math
.
sqrt
(
this
.
lengthSq
()
);
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
);
},
...
...
src/math/Vector2.js
浏览文件 @
f7c93b82
...
...
@@ -41,6 +41,30 @@ THREE.Vector2.prototype = {
},
setComponent
:
function
(
index
,
value
)
{
switch
(
index
)
{
case
0
:
this
.
x
=
value
;
break
;
case
1
:
this
.
y
=
value
;
break
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
getComponent
:
function
(
index
)
{
switch
(
index
)
{
case
0
:
return
this
.
x
;
case
1
:
return
this
.
y
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
copy
:
function
(
v
)
{
this
.
x
=
v
.
x
;
...
...
@@ -106,7 +130,7 @@ THREE.Vector2.prototype = {
divideScalar
:
function
(
s
)
{
if
(
s
)
{
if
(
s
!==
0
)
{
this
.
x
/=
s
;
this
.
y
/=
s
;
...
...
@@ -205,7 +229,7 @@ THREE.Vector2.prototype = {
length
:
function
()
{
return
Math
.
sqrt
(
this
.
lengthSq
()
);
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
);
},
...
...
@@ -230,7 +254,14 @@ THREE.Vector2.prototype = {
setLength
:
function
(
l
)
{
return
this
.
normalize
().
multiplyScalar
(
l
);
var
oldLength
=
this
.
length
();
if
(
oldLength
!==
0
&&
l
!==
oldLength
)
{
this
.
multiplyScalar
(
l
/
oldLength
);
}
return
this
;
},
...
...
@@ -255,4 +286,4 @@ THREE.Vector2.prototype = {
}
};
};
\ No newline at end of file
src/math/Vector3.js
浏览文件 @
f7c93b82
...
...
@@ -54,6 +54,32 @@ THREE.Vector3.prototype = {
},
setComponent
:
function
(
index
,
value
)
{
switch
(
index
)
{
case
0
:
this
.
x
=
value
;
break
;
case
1
:
this
.
y
=
value
;
break
;
case
2
:
this
.
z
=
value
;
break
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
getComponent
:
function
(
index
)
{
switch
(
index
)
{
case
0
:
return
this
.
x
;
case
1
:
return
this
.
y
;
case
2
:
return
this
.
z
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
copy
:
function
(
v
)
{
this
.
x
=
v
.
x
;
...
...
@@ -156,7 +182,7 @@ THREE.Vector3.prototype = {
divideScalar
:
function
(
s
)
{
if
(
s
)
{
if
(
s
!==
0
)
{
this
.
x
/=
s
;
this
.
y
/=
s
;
...
...
@@ -280,7 +306,7 @@ THREE.Vector3.prototype = {
length
:
function
()
{
return
Math
.
sqrt
(
this
.
lengthSq
()
);
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
);
},
...
...
@@ -298,7 +324,14 @@ THREE.Vector3.prototype = {
setLength
:
function
(
l
)
{
return
this
.
normalize
().
multiplyScalar
(
l
);
var
oldLength
=
this
.
length
();
if
(
oldLength
!==
0
&&
l
!==
oldLength
)
{
this
.
multiplyScalar
(
l
/
oldLength
);
}
return
this
;
},
...
...
@@ -571,4 +604,4 @@ THREE.Vector3.prototype = {
}
};
};
\ No newline at end of file
src/math/Vector4.js
浏览文件 @
f7c93b82
...
...
@@ -62,6 +62,34 @@ THREE.Vector4.prototype = {
},
setComponent
:
function
(
index
,
value
)
{
switch
(
index
)
{
case
0
:
this
.
x
=
value
;
break
;
case
1
:
this
.
y
=
value
;
break
;
case
2
:
this
.
z
=
value
;
break
;
case
3
:
this
.
w
=
value
;
break
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
getComponent
:
function
(
index
)
{
switch
(
index
)
{
case
0
:
return
this
.
x
;
case
1
:
return
this
.
y
;
case
2
:
return
this
.
z
;
case
3
:
return
this
.
w
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
copy
:
function
(
v
)
{
this
.
x
=
v
.
x
;
...
...
@@ -141,7 +169,7 @@ THREE.Vector4.prototype = {
divideScalar
:
function
(
s
)
{
if
(
s
)
{
if
(
s
!==
0
)
{
this
.
x
/=
s
;
this
.
y
/=
s
;
...
...
@@ -283,13 +311,13 @@ THREE.Vector4.prototype = {
lengthSq
:
function
()
{
return
this
.
dot
(
this
)
;
return
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
;
},
length
:
function
()
{
return
Math
.
sqrt
(
this
.
lengthSq
()
);
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
);
},
...
...
@@ -307,8 +335,15 @@ THREE.Vector4.prototype = {
setLength
:
function
(
l
)
{
return
this
.
normalize
().
multiplyScalar
(
l
);
var
oldLength
=
this
.
length
();
if
(
oldLength
!==
0
&&
l
!==
oldLength
)
{
this
.
multiplyScalar
(
l
/
oldLength
);
}
return
this
;
},
lerpSelf
:
function
(
v
,
alpha
)
{
...
...
@@ -486,4 +521,4 @@ THREE.Vector4.prototype = {
}
};
};
\ No newline at end of file
test/benchmark/benchmarking_float32array
_accesspatterns
.html
→
test/benchmark/benchmarking_float32array.html
浏览文件 @
f7c93b82
...
...
@@ -30,7 +30,7 @@
<!-- add class-based unit tests below -->
<script
src=
"core/Float32Array
AccessPatterns
.js"
></script>
<script
src=
"core/Float32Array.js"
></script>
</body>
</html>
\ No newline at end of file
test/benchmark/benchmarking_vector3components.html
0 → 100644
浏览文件 @
f7c93b82
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
ThreeJS Benchmark Tests - Using Files in /src
</title>
</head>
<body>
During this Benchmarking test the browser will be unresponsive.
<br/><br/>
Benchmark output is written to the JavaScript console. To access the JavaScript console presss Ctrl-Shift-J.
<script
src=
"benchmark-1.0.0.js"
></script>
<!-- add class-based unit tests below -->
<script
src=
"core/Vector3Components.js"
></script>
</body>
</html>
\ No newline at end of file
test/benchmark/benchmarking_vector3length.html
0 → 100644
浏览文件 @
f7c93b82
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
ThreeJS Benchmark Tests - Using Files in /src
</title>
</head>
<body>
During this Benchmarking test the browser will be unresponsive.
<br/><br/>
Benchmark output is written to the JavaScript console. To access the JavaScript console presss Ctrl-Shift-J.
<script
src=
"benchmark-1.0.0.js"
></script>
<!-- add class-based unit tests below -->
<script
src=
"core/Vector3Length.js"
></script>
</body>
</html>
\ No newline at end of file
test/benchmark/benchmarking_vector3storage.html
0 → 100644
浏览文件 @
f7c93b82
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
ThreeJS Benchmark Tests - Using Files in /src
</title>
</head>
<body>
During this Benchmarking test the browser will be unresponsive.
<br/><br/>
Benchmark output is written to the JavaScript console. To access the JavaScript console presss Ctrl-Shift-J.
<script
src=
"benchmark-1.0.0.js"
></script>
<!-- add class-based unit tests below -->
<script
src=
"core/Vector3Storage.js"
></script>
</body>
</html>
\ No newline at end of file
test/benchmark/core/Float32Array.js
0 → 100644
浏览文件 @
f7c93b82
var
input
=
new
Float32Array
(
10000
*
3
);
var
output
=
new
Float32Array
(
10000
*
3
);
for
(
var
j
=
0
,
jl
=
input
.
length
;
j
<
jl
;
j
++
)
{
input
[
j
]
=
j
;
}
var
inputVectors
=
[];
var
outputVectors
=
[];
for
(
var
j
=
0
,
jl
=
input
.
length
/
3
;
j
<
jl
;
j
++
)
{
inputVectors
.
push
(
new
THREE
.
Vector3
(
j
*
3
,
j
*
3
+
1
,
j
*
3
+
2
)
);
outputVectors
.
push
(
new
THREE
.
Vector3
()
);
}
var
suite
=
new
Benchmark
.
Suite
;
suite
.
add
(
'
Float32Array-Float32Array
'
,
function
()
{
var
value3
=
new
Float32Array
(
3
);
for
(
var
i
=
0
,
il
=
input
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value3
[
0
]
=
input
[
i
+
0
];
value3
[
1
]
=
input
[
i
+
1
];
value3
[
2
]
=
input
[
i
+
2
];
value3
[
0
]
*=
1.01
;
value3
[
1
]
*=
1.03
;
value3
[
2
]
*=
0.98
;
output
[
i
+
0
]
=
value3
[
0
];
output
[
i
+
1
]
=
value3
[
1
];
output
[
i
+
2
]
=
value3
[
2
];
}
});
suite
.
add
(
'
Float32Array-Array
'
,
function
()
{
var
value2
=
[
0
,
0
,
0
];
for
(
var
i
=
0
,
il
=
input
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value2
[
0
]
=
input
[
i
+
0
];
value2
[
1
]
=
input
[
i
+
1
];
value2
[
2
]
=
input
[
i
+
2
];
value2
[
0
]
*=
1.01
;
value2
[
1
]
*=
1.03
;
value2
[
2
]
*=
0.98
;
output
[
i
+
0
]
=
value2
[
0
];
output
[
i
+
1
]
=
value2
[
1
];
output
[
i
+
2
]
=
value2
[
2
];
}
});
suite
.
add
(
'
Float32Array-Literal
'
,
function
()
{
var
x
,
y
,
z
;
for
(
var
i
=
0
,
il
=
input
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
x
=
input
[
i
+
0
];
y
=
input
[
i
+
1
];
z
=
input
[
i
+
2
];
x
*=
1.01
;
y
*=
1.03
;
z
*=
0.98
;
output
[
i
+
0
]
=
x
;
output
[
i
+
1
]
=
y
;
output
[
i
+
2
]
=
z
;
}
});
suite
.
add
(
'
Float32Array-Vector3
'
,
function
()
{
var
value
=
new
THREE
.
Vector3
();
for
(
var
i
=
0
,
il
=
input
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value
.
x
=
input
[
i
+
0
];
value
.
y
=
input
[
i
+
1
];
value
.
z
=
input
[
i
+
2
];
value
.
x
*=
1.01
;
value
.
y
*=
1.03
;
value
.
z
*=
0.98
;
output
[
i
+
0
]
=
value
.
x
;
output
[
i
+
1
]
=
value
.
y
;
output
[
i
+
2
]
=
value
.
z
;
}
});
suite
.
add
(
'
Vector3Array-Direct
'
,
function
()
{
for
(
var
i
=
0
,
il
=
inputVectors
.
length
;
i
<
il
;
i
++
)
{
outputVectors
[
i
].
copy
(
inputVectors
[
i
]
);
outputVectors
[
i
].
x
*=
1.01
;
outputVectors
[
i
].
y
*=
1.03
;
outputVectors
[
i
].
z
*=
0.98
;
}
});
suite
.
add
(
'
Vector3Array-Vector3
'
,
function
()
{
var
value
=
new
THREE
.
Vector3
();
for
(
var
i
=
0
,
il
=
inputVectors
.
length
;
i
<
il
;
i
++
)
{
value
.
copy
(
inputVectors
[
i
]
);
value
.
x
*=
1.01
;
value
.
y
*=
1.03
;
value
.
z
*=
0.98
;
outputVectors
[
i
].
copy
(
value
);
}
});
suite
.
on
(
'
cycle
'
,
function
(
event
,
bench
)
{
console
.
log
(
String
(
event
.
target
));
});
suite
.
on
(
'
complete
'
,
function
()
{
console
.
log
(
'
Fastest is
'
+
this
.
filter
(
'
fastest
'
).
pluck
(
'
name
'
));
console
.
log
(
"
Done
"
);
});
suite
.
run
(
true
);
\ No newline at end of file
test/benchmark/core/Float32ArrayAccessPatterns.js
已删除
100644 → 0
浏览文件 @
24668969
var
array
=
new
Float32Array
(
10000
*
3
);
for
(
var
j
=
0
,
jl
=
array
.
length
;
j
<
jl
;
j
++
)
{
array
[
j
]
=
j
;
}
var
vectorArray
=
[];
for
(
var
j
=
0
,
jl
=
array
.
length
/
3
;
j
<
jl
;
j
++
)
{
vectorArray
.
push
(
new
THREE
.
Vector3
(
j
*
3
,
j
*
3
+
1
,
j
*
3
+
2
)
);
}
var
Float32ArrayCopyTest
=
function
(
array
)
{
var
x
,
y
,
z
;
for
(
var
i
=
0
,
il
=
array
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
x
=
array
[
i
+
0
];
y
=
array
[
i
+
1
];
z
=
array
[
i
+
2
];
x
*=
1.01
;
y
*=
1.03
;
z
*=
0.98
;
array
[
i
+
0
]
=
x
;
array
[
i
+
1
]
=
y
;
array
[
i
+
2
]
=
z
;
}
};
var
Float32ArrayDirectTest
=
function
(
array
)
{
for
(
var
i
=
0
,
il
=
array
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
array
[
i
+
0
]
*=
1.01
;
array
[
i
+
1
]
*=
1.03
;
array
[
i
+
2
]
*=
0.98
;
}
};
var
Float32ArrayVector3CopyTest
=
function
(
array
)
{
var
value
=
new
THREE
.
Vector3
();
for
(
var
i
=
0
,
il
=
array
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value
.
x
=
array
[
i
+
0
];
value
.
y
=
array
[
i
+
1
];
value
.
z
=
array
[
i
+
2
];
value
.
x
*=
1.01
;
value
.
y
*=
1.03
;
value
.
z
*=
0.98
;
array
[
i
+
0
]
=
value
.
x
;
array
[
i
+
1
]
=
value
.
y
;
array
[
i
+
2
]
=
value
.
z
;
}
};
var
Float32ArrayArrayCopyTest
=
function
(
array
)
{
var
value2
=
[
0
,
0
,
0
];
for
(
var
i
=
0
,
il
=
array
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value2
[
0
]
=
array
[
i
+
0
];
value2
[
1
]
=
array
[
i
+
1
];
value2
[
2
]
=
array
[
i
+
2
];
value2
[
0
]
*=
1.01
;
value2
[
1
]
*=
1.03
;
value2
[
2
]
*=
0.98
;
array
[
i
+
0
]
=
value2
[
0
];
array
[
i
+
1
]
=
value2
[
1
];
array
[
i
+
2
]
=
value2
[
2
];
}
};
var
Float32ArrayFloat32ArrayCopyTest
=
function
(
array
)
{
var
value3
=
new
Float32Array
(
3
);
for
(
var
i
=
0
,
il
=
array
.
length
/
3
;
i
<
il
;
i
+=
3
)
{
value3
[
0
]
=
array
[
i
+
0
];
value3
[
1
]
=
array
[
i
+
1
];
value3
[
2
]
=
array
[
i
+
2
];
value3
[
0
]
*=
1.01
;
value3
[
1
]
*=
1.03
;
value3
[
2
]
*=
0.98
;
array
[
i
+
0
]
=
value3
[
0
];
array
[
i
+
1
]
=
value3
[
1
];
array
[
i
+
2
]
=
value3
[
2
];
}
};
var
Vector3ArrayVector3CopyTest
=
function
(
array
)
{
var
value
=
new
THREE
.
Vector3
();
for
(
var
i
=
0
,
il
=
vectorArray
.
length
;
i
<
il
;
i
++
)
{
value
.
copy
(
vectorArray
[
i
]
);
value
.
x
*=
1.01
;
value
.
y
*=
1.03
;
value
.
z
*=
0.98
;
vectorArray
[
i
].
copy
(
value
);
}
};
var
Vector3ArrayVector3RefTest
=
function
(
array
)
{
for
(
var
i
=
0
,
il
=
vectorArray
.
length
;
i
<
il
;
i
++
)
{
var
value
=
vectorArray
[
i
];
value
.
x
*=
1.01
;
value
.
y
*=
1.03
;
value
.
z
*=
0.98
;
}
};
var
Vector3ArrayVector3DirectTest
=
function
(
array
)
{
for
(
var
i
=
0
,
il
=
vectorArray
.
length
;
i
<
il
;
i
++
)
{
vectorArray
[
i
].
x
*=
1.01
;
vectorArray
[
i
].
y
*=
1.03
;
vectorArray
[
i
].
z
*=
0.98
;
}
};
var
suite
=
new
Benchmark
.
Suite
;
suite
.
add
(
'
Float32ArrayFloat32ArrayCopyTest
'
,
function
()
{
Float32ArrayFloat32ArrayCopyTest
(
array
);
});
suite
.
add
(
'
Float32DirectArray
'
,
function
()
{
Float32ArrayDirectTest
(
array
);
});
suite
.
add
(
'
Float32ArrayArrayCopyTest
'
,
function
()
{
Float32ArrayArrayCopyTest
(
array
);
});
suite
.
add
(
'
Float32CopyArray
'
,
function
()
{
Float32ArrayCopyTest
(
array
);
});
suite
.
add
(
'
Float32ArrayVector3CopyTest
'
,
function
()
{
Float32ArrayVector3CopyTest
(
array
);
});
suite
.
add
(
'
Vector3ArrayVector3Ref
'
,
function
()
{
Vector3ArrayVector3RefTest
(
array
);
});
suite
.
add
(
'
Vector3ArrayVector3Direct
'
,
function
()
{
Vector3ArrayVector3DirectTest
(
array
);
});
suite
.
add
(
'
Vector3ArrayVector3Copy
'
,
function
()
{
Vector3ArrayVector3CopyTest
(
array
);
});
suite
.
on
(
'
cycle
'
,
function
(
event
,
bench
)
{
console
.
log
(
String
(
event
.
target
));
});
suite
.
on
(
'
complete
'
,
function
()
{
console
.
log
(
'
Fastest is
'
+
this
.
filter
(
'
fastest
'
).
pluck
(
'
name
'
));
console
.
log
(
"
Done
"
);
});
suite
.
run
(
true
);
\ No newline at end of file
test/benchmark/core/Vector3Components.js
0 → 100644
浏览文件 @
f7c93b82
THREE
=
{};
THREE
.
Vector3
=
function
(
x
,
y
,
z
)
{
this
.
x
=
x
||
0
;
this
.
y
=
y
||
0
;
this
.
z
=
z
||
0
;
};
THREE
.
Vector3
.
prototype
=
{
constructor
:
THREE
.
Vector3
,
setComponent
:
function
(
index
,
value
)
{
this
[
THREE
.
Vector3
.
__indexToName
[
index
]
]
=
value
;
},
getComponent
:
function
(
index
)
{
return
this
[
THREE
.
Vector3
.
__indexToName
[
index
]
];
},
setComponent2
:
function
(
index
,
value
)
{
switch
(
index
)
{
case
0
:
this
.
x
=
value
;
break
;
case
1
:
this
.
y
=
value
;
break
;
case
2
:
this
.
z
=
value
;
break
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
getComponent2
:
function
(
index
)
{
switch
(
index
)
{
case
0
:
return
this
.
x
;
case
1
:
return
this
.
y
;
case
2
:
return
this
.
z
;
default
:
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
},
getComponent3
:
function
(
index
)
{
if
(
index
===
0
)
return
this
.
x
;
if
(
index
===
1
)
return
this
.
y
;
if
(
index
===
2
)
return
this
.
z
;
throw
new
Error
(
"
index is out of range:
"
+
index
);
},
getComponent4
:
function
(
index
)
{
if
(
index
===
0
)
return
this
.
x
;
else
if
(
index
===
1
)
return
this
.
y
;
else
if
(
index
===
2
)
return
this
.
z
;
else
throw
new
Error
(
"
index is out of range:
"
+
index
);
}
};
THREE
.
Vector3
.
__indexToName
=
{
0
:
'
x
'
,
1
:
'
y
'
,
2
:
'
z
'
};
var
a
=
[];
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
a
[
i
]
=
new
THREE
.
Vector3
(
i
*
0.01
,
i
*
2
,
i
*
-
1.3
);
}
var
suite
=
new
Benchmark
.
Suite
;
suite
.
add
(
'
IndexToName
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
getComponent
(
i
%
3
);
}
});
suite
.
add
(
'
SwitchStatement
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
getComponent2
(
i
%
3
);
}
});
suite
.
add
(
'
IfAndReturnSeries
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
getComponent3
(
i
%
3
);
}
});
suite
.
add
(
'
IfReturnElseSeries
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
getComponent4
(
i
%
3
);
}
});
suite
.
on
(
'
cycle
'
,
function
(
event
,
bench
)
{
console
.
log
(
String
(
event
.
target
));
});
suite
.
on
(
'
complete
'
,
function
()
{
console
.
log
(
'
Fastest is
'
+
this
.
filter
(
'
fastest
'
).
pluck
(
'
name
'
));
console
.
log
(
"
Done
"
);
});
suite
.
run
(
true
);
\ No newline at end of file
test/benchmark/core/Vector3Length.js
0 → 100644
浏览文件 @
f7c93b82
THREE
=
{};
THREE
.
Vector3
=
function
(
x
,
y
,
z
)
{
this
.
x
=
x
||
0
;
this
.
y
=
y
||
0
;
this
.
z
=
z
||
0
;
};
THREE
.
Vector3
.
prototype
=
{
constructor
:
THREE
.
Vector3
,
lengthSq
:
function
()
{
return
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
;
},
length
:
function
()
{
return
Math
.
sqrt
(
this
.
lengthSq
()
);
},
length2
:
function
()
{
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
);
}
};
var
a
=
[];
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
a
[
i
]
=
new
THREE
.
Vector3
(
i
*
0.01
,
i
*
2
,
i
*
-
1.3
);
}
var
suite
=
new
Benchmark
.
Suite
;
suite
.
add
(
'
NoCallTest
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
a
[
i
];
result
+=
Math
.
sqrt
(
v
.
x
*
v
.
x
+
v
.
y
*
v
.
y
+
v
.
z
*
v
.
z
);
}
});
suite
.
add
(
'
InlineCallTest
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
length2
();
}
});
suite
.
add
(
'
FunctionCallTest
'
,
function
()
{
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
result
+=
a
[
i
].
length
();
}
});
suite
.
on
(
'
cycle
'
,
function
(
event
,
bench
)
{
console
.
log
(
String
(
event
.
target
));
});
suite
.
on
(
'
complete
'
,
function
()
{
console
.
log
(
'
Fastest is
'
+
this
.
filter
(
'
fastest
'
).
pluck
(
'
name
'
));
console
.
log
(
"
Done
"
);
});
suite
.
run
(
true
);
\ No newline at end of file
test/benchmark/core/Vector3Storage.js
0 → 100644
浏览文件 @
f7c93b82
THREE
=
{};
THREE
.
Vector3
=
function
(
x
,
y
,
z
)
{
this
.
x
=
x
||
0
;
this
.
y
=
y
||
0
;
this
.
z
=
z
||
0
;
};
THREE
.
Vector3
.
prototype
=
{
constructor
:
THREE
.
Vector3
,
length
:
function
()
{
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
);
}
};
THREE
.
Vector3X
=
function
(
x
,
y
,
z
)
{
var
elements
=
this
.
elements
=
new
Float32Array
(
3
);
elements
[
0
]
=
x
||
0
;
elements
[
1
]
=
y
||
1
;
elements
[
2
]
=
z
||
2
;
};
THREE
.
Vector3X
.
prototype
=
{
constructor
:
THREE
.
Vector3X
,
length
:
function
()
{
return
Math
.
sqrt
(
this
.
elements
[
0
]
*
this
.
elements
[
0
]
+
this
.
elements
[
1
]
*
this
.
elements
[
1
]
+
this
.
elements
[
2
]
*
this
.
elements
[
2
]
);
}
};
THREE
.
Vector3Y
=
function
(
x
,
y
,
z
)
{
this
.
elements
=
[
x
||
0
,
y
||
1
,
z
||
2
];
};
THREE
.
Vector3Y
.
prototype
=
{
constructor
:
THREE
.
Vector3Y
,
length
:
function
()
{
return
Math
.
sqrt
(
this
.
elements
[
0
]
*
this
.
elements
[
0
]
+
this
.
elements
[
1
]
*
this
.
elements
[
1
]
+
this
.
elements
[
2
]
*
this
.
elements
[
2
]
);
}
};
var
suite
=
new
Benchmark
.
Suite
;
suite
.
add
(
'
Vector3-Set
'
,
function
()
{
var
array
=
[];
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
new
THREE
.
Vector3
(
i
,
i
,
i
);
array
.
push
(
v
);
}
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
array
[
i
];
result
+=
v
.
length
();
}
});
suite
.
add
(
'
Vector3-Float32Array
'
,
function
()
{
var
array
=
[];
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
new
THREE
.
Vector3X
(
i
,
i
,
i
);
array
.
push
(
v
);
}
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
array
[
i
];
result
+=
v
.
length
();
}
});
suite
.
add
(
'
Vector3-Array
'
,
function
()
{
var
array
=
[];
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
new
THREE
.
Vector3Y
(
i
,
i
,
i
);
array
.
push
(
v
);
}
var
result
=
0
;
for
(
var
i
=
0
;
i
<
100000
;
i
++
)
{
var
v
=
array
[
i
];
result
+=
v
.
length
();
}
});
suite
.
on
(
'
cycle
'
,
function
(
event
,
bench
)
{
console
.
log
(
String
(
event
.
target
));
});
suite
.
on
(
'
complete
'
,
function
()
{
console
.
log
(
'
Fastest is
'
+
this
.
filter
(
'
fastest
'
).
pluck
(
'
name
'
));
console
.
log
(
"
Done
"
);
});
suite
.
run
(
true
);
\ No newline at end of file
test/unit/math/Vector2.js
浏览文件 @
f7c93b82
...
...
@@ -48,6 +48,17 @@ test( "setX,setY", function() {
ok
(
a
.
y
==
y
,
"
Passed!
"
);
});
test
(
"
setComponent,getComponent
"
,
function
()
{
var
a
=
new
THREE
.
Vector2
();
ok
(
a
.
x
==
0
,
"
Passed!
"
);
ok
(
a
.
y
==
0
,
"
Passed!
"
);
a
.
setComponent
(
0
,
1
);
a
.
setComponent
(
1
,
2
);
ok
(
a
.
getComponent
(
0
)
==
1
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
1
)
==
2
,
"
Passed!
"
);
});
test
(
"
add
"
,
function
()
{
var
a
=
new
THREE
.
Vector2
(
x
,
y
);
var
b
=
new
THREE
.
Vector2
(
-
x
,
-
y
);
...
...
@@ -184,6 +195,11 @@ test( "setLength", function() {
ok
(
a
.
length
()
==
x
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
y
,
"
Passed!
"
);
a
=
new
THREE
.
Vector2
(
0
,
0
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
});
test
(
"
lerpSelf/clone
"
,
function
()
{
...
...
test/unit/math/Vector3.js
浏览文件 @
f7c93b82
...
...
@@ -59,6 +59,20 @@ test( "setX,setY,setZ", function() {
ok
(
a
.
z
==
z
,
"
Passed!
"
);
});
test
(
"
setComponent,getComponent
"
,
function
()
{
var
a
=
new
THREE
.
Vector3
();
ok
(
a
.
x
==
0
,
"
Passed!
"
);
ok
(
a
.
y
==
0
,
"
Passed!
"
);
ok
(
a
.
z
==
0
,
"
Passed!
"
);
a
.
setComponent
(
0
,
1
);
a
.
setComponent
(
1
,
2
);
a
.
setComponent
(
2
,
3
);
ok
(
a
.
getComponent
(
0
)
==
1
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
1
)
==
2
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
2
)
==
3
,
"
Passed!
"
);
});
test
(
"
add
"
,
function
()
{
var
a
=
new
THREE
.
Vector3
(
x
,
y
,
z
);
var
b
=
new
THREE
.
Vector3
(
-
x
,
-
y
,
-
z
);
...
...
@@ -217,6 +231,12 @@ test( "setLength", function() {
ok
(
a
.
length
()
==
x
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
y
,
"
Passed!
"
);
a
=
new
THREE
.
Vector3
(
0
,
0
,
0
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
});
test
(
"
lerpSelf/clone
"
,
function
()
{
...
...
test/unit/math/Vector4.js
浏览文件 @
f7c93b82
...
...
@@ -69,6 +69,23 @@ test( "setX,setY,setZ,setW", function() {
ok
(
a
.
w
==
w
,
"
Passed!
"
);
});
test
(
"
setComponent,getComponent
"
,
function
()
{
var
a
=
new
THREE
.
Vector4
();
ok
(
a
.
x
==
0
,
"
Passed!
"
);
ok
(
a
.
y
==
0
,
"
Passed!
"
);
ok
(
a
.
z
==
0
,
"
Passed!
"
);
ok
(
a
.
w
==
1
,
"
Passed!
"
);
a
.
setComponent
(
0
,
1
);
a
.
setComponent
(
1
,
2
);
a
.
setComponent
(
2
,
3
);
a
.
setComponent
(
3
,
4
);
ok
(
a
.
getComponent
(
0
)
==
1
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
1
)
==
2
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
2
)
==
3
,
"
Passed!
"
);
ok
(
a
.
getComponent
(
3
)
==
4
,
"
Passed!
"
);
});
test
(
"
add
"
,
function
()
{
var
a
=
new
THREE
.
Vector4
(
x
,
y
,
z
,
w
);
var
b
=
new
THREE
.
Vector4
(
-
x
,
-
y
,
-
z
,
-
w
);
...
...
@@ -254,6 +271,11 @@ test( "setLength", function() {
ok
(
a
.
length
()
==
x
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
y
,
"
Passed!
"
);
a
=
new
THREE
.
Vector4
(
0
,
0
,
0
,
0
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
a
.
setLength
(
y
);
ok
(
a
.
length
()
==
0
,
"
Passed!
"
);
});
test
(
"
lerpSelf/clone
"
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录