Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b02db06c
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,发现更多精彩内容 >>
提交
b02db06c
编写于
7月 24, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Animation: Removed JITCompile stuff.
上级
e3f0f1e9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
179 deletion
+82
-179
src/extras/animation/Animation.js
src/extras/animation/Animation.js
+82
-179
未找到文件。
src/extras/animation/Animation.js
浏览文件 @
b02db06c
...
...
@@ -4,7 +4,7 @@
* @author alteredq / http://alteredqualia.com/
*/
THREE
.
Animation
=
function
(
root
,
name
,
interpolationType
,
JITCompil
e
)
{
THREE
.
Animation
=
function
(
root
,
name
,
interpolationTyp
e
)
{
this
.
root
=
root
;
this
.
data
=
THREE
.
AnimationHandler
.
get
(
name
);
...
...
@@ -18,16 +18,15 @@ THREE.Animation = function( root, name, interpolationType, JITCompile ) {
this
.
loop
=
true
;
this
.
interpolationType
=
interpolationType
!==
undefined
?
interpolationType
:
THREE
.
AnimationHandler
.
LINEAR
;
this
.
JITCompile
=
JITCompile
!==
undefined
?
JITCompile
:
true
;
this
.
points
=
[];
this
.
target
=
new
THREE
.
Vector3
();
};
THREE
.
Animation
.
prototype
.
play
=
function
(
loop
,
startTimeMS
)
{
THREE
.
Animation
.
prototype
.
play
=
function
(
loop
,
startTimeMS
)
{
if
(
!
this
.
isPlaying
)
{
if
(
this
.
isPlaying
===
false
)
{
this
.
isPlaying
=
true
;
this
.
loop
=
loop
!==
undefined
?
loop
:
true
;
...
...
@@ -85,7 +84,7 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
THREE
.
Animation
.
prototype
.
pause
=
function
()
{
if
(
this
.
isPaused
)
{
if
(
this
.
isPaused
===
true
)
{
THREE
.
AnimationHandler
.
addToUpdate
(
this
);
...
...
@@ -106,37 +105,14 @@ THREE.Animation.prototype.stop = function() {
this
.
isPaused
=
false
;
THREE
.
AnimationHandler
.
removeFromUpdate
(
this
);
// reset JIT matrix and remove cache
for
(
var
h
=
0
;
h
<
this
.
hierarchy
.
length
;
h
++
)
{
if
(
this
.
hierarchy
[
h
].
animationCache
!==
undefined
)
{
if
(
this
.
hierarchy
[
h
]
instanceof
THREE
.
Bone
)
{
this
.
hierarchy
[
h
].
skinMatrix
=
this
.
hierarchy
[
h
].
animationCache
.
originalMatrix
;
}
else
{
this
.
hierarchy
[
h
].
matrix
=
this
.
hierarchy
[
h
].
animationCache
.
originalMatrix
;
}
delete
this
.
hierarchy
[
h
].
animationCache
;
}
}
};
THREE
.
Animation
.
prototype
.
update
=
function
(
deltaTimeMS
)
{
THREE
.
Animation
.
prototype
.
update
=
function
(
deltaTimeMS
)
{
// early out
if
(
!
this
.
isPlaying
)
return
;
if
(
this
.
isPlaying
===
false
)
return
;
// vars
...
...
@@ -155,217 +131,144 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
var
currentPoint
,
forwardPoint
,
angle
;
// update
this
.
currentTime
+=
deltaTimeMS
*
this
.
timeScale
;
unloopedCurrentTime
=
this
.
currentTime
;
currentTime
=
this
.
currentTime
=
this
.
currentTime
%
this
.
data
.
length
;
frame
=
parseInt
(
Math
.
min
(
currentTime
*
this
.
data
.
fps
,
this
.
data
.
length
*
this
.
data
.
fps
),
10
);
currentTime
=
this
.
currentTime
=
this
.
currentTime
%
this
.
data
.
length
;
frame
=
parseInt
(
Math
.
min
(
currentTime
*
this
.
data
.
fps
,
this
.
data
.
length
*
this
.
data
.
fps
),
10
);
// update
for
(
var
h
=
0
,
hl
=
this
.
hierarchy
.
length
;
h
<
hl
;
h
++
)
{
object
=
this
.
hierarchy
[
h
];
animationCache
=
object
.
animationCache
;
// use JIT?
if
(
this
.
JITCompile
&&
JIThierarchy
[
h
][
frame
]
!==
undefined
)
{
if
(
object
instanceof
THREE
.
Bone
)
{
object
.
skinMatrix
=
JIThierarchy
[
h
][
frame
];
object
.
matrixAutoUpdate
=
false
;
object
.
matrixWorldNeedsUpdate
=
false
;
}
else
{
object
.
matrix
=
JIThierarchy
[
h
][
frame
];
object
.
matrixAutoUpdate
=
false
;
object
.
matrixWorldNeedsUpdate
=
true
;
}
// use interpolation
}
else
{
// make sure so original matrix and not JIT matrix is set
if
(
this
.
JITCompile
)
{
if
(
object
instanceof
THREE
.
Bone
)
{
object
.
skinMatrix
=
object
.
animationCache
.
originalMatrix
;
}
else
{
object
.
matrix
=
object
.
animationCache
.
originalMatrix
;
}
}
// loop through pos/rot/scl
// loop through pos/rot/scl
for
(
var
t
=
0
;
t
<
3
;
t
++
)
{
for
(
var
t
=
0
;
t
<
3
;
t
++
)
{
// get keys
// get keys
type
=
types
[
t
];
prevKey
=
animationCache
.
prevKey
[
type
];
nextKey
=
animationCache
.
nextKey
[
type
];
type
=
types
[
t
];
prevKey
=
animationCache
.
prevKey
[
type
];
nextKey
=
animationCache
.
nextKey
[
type
];
// switch keys?
// switch keys?
if
(
nextKey
.
time
<=
unloopedCurrentTime
)
{
if
(
nextKey
.
time
<=
unloopedCurrentTime
)
{
// did we loop?
// did we loop?
if
(
currentTime
<
unloopedCurrentTime
)
{
if
(
currentTime
<
unloopedCurrentTime
)
{
if
(
this
.
loop
)
{
if
(
this
.
loop
)
{
prevKey
=
this
.
data
.
hierarchy
[
h
].
keys
[
0
];
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
1
);
prevKey
=
this
.
data
.
hierarchy
[
h
].
keys
[
0
];
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
1
);
while
(
nextKey
.
time
<
currentTime
)
{
while
(
nextKey
.
time
<
currentTime
)
{
prevKey
=
nextKey
;
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
nextKey
.
index
+
1
);
}
}
else
{
this
.
stop
();
return
;
prevKey
=
nextKey
;
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
nextKey
.
index
+
1
);
}
}
else
{
do
{
prevKey
=
nextKey
;
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
nextKey
.
index
+
1
);
}
while
(
nextKey
.
time
<
currentTime
)
this
.
stop
();
return
;
}
animationCache
.
prevKey
[
type
]
=
prevKey
;
animationCache
.
nextKey
[
type
]
=
nextKey
;
}
object
.
matrixAutoUpdate
=
true
;
object
.
matrixWorldNeedsUpdate
=
true
;
scale
=
(
currentTime
-
prevKey
.
time
)
/
(
nextKey
.
time
-
prevKey
.
time
);
prevXYZ
=
prevKey
[
type
];
nextXYZ
=
nextKey
[
type
];
}
else
{
// check scale error
do
{
if
(
scale
<
0
||
scale
>
1
)
{
prevKey
=
nextKey
;
nextKey
=
this
.
getNextKeyWith
(
type
,
h
,
nextKey
.
index
+
1
);
console
.
log
(
"
THREE.Animation.update: Warning! Scale out of bounds:
"
+
scale
+
"
on bone
"
+
h
);
scale
=
scale
<
0
?
0
:
1
;
}
while
(
nextKey
.
time
<
currentTime
)
}
// interpolate
if
(
type
===
"
pos
"
)
{
vector
=
object
.
position
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
LINEAR
)
{
animationCache
.
prevKey
[
type
]
=
prevKey
;
animationCache
.
nextKey
[
type
]
=
nextKey
;
vector
.
x
=
prevXYZ
[
0
]
+
(
nextXYZ
[
0
]
-
prevXYZ
[
0
]
)
*
scale
;
vector
.
y
=
prevXYZ
[
1
]
+
(
nextXYZ
[
1
]
-
prevXYZ
[
1
]
)
*
scale
;
vector
.
z
=
prevXYZ
[
2
]
+
(
nextXYZ
[
2
]
-
prevXYZ
[
2
]
)
*
scale
;
}
else
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM
||
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
this
.
points
[
0
]
=
this
.
getPrevKeyWith
(
"
pos
"
,
h
,
prevKey
.
index
-
1
)[
"
pos
"
];
this
.
points
[
1
]
=
prevXYZ
;
this
.
points
[
2
]
=
nextXYZ
;
this
.
points
[
3
]
=
this
.
getNextKeyWith
(
"
pos
"
,
h
,
nextKey
.
index
+
1
)[
"
pos
"
];
scale
=
scale
*
0.33
+
0.33
;
}
currentPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
);
vector
.
x
=
currentPoint
[
0
];
vector
.
y
=
currentPoint
[
1
];
vector
.
z
=
currentPoint
[
2
];
object
.
matrixAutoUpdate
=
true
;
object
.
matrixWorldNeedsUpdate
=
true
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
scale
=
(
currentTime
-
prevKey
.
time
)
/
(
nextKey
.
time
-
prevKey
.
time
);
prevXYZ
=
prevKey
[
type
];
nextXYZ
=
nextKey
[
type
];
forwardPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
*
1.01
);
this
.
target
.
set
(
forwardPoint
[
0
],
forwardPoint
[
1
],
forwardPoint
[
2
]
);
this
.
target
.
subSelf
(
vector
);
this
.
target
.
y
=
0
;
this
.
target
.
normalize
();
// check scale error
angle
=
Math
.
atan2
(
this
.
target
.
x
,
this
.
target
.
z
);
object
.
rotation
.
set
(
0
,
angle
,
0
);
if
(
scale
<
0
||
scale
>
1
)
{
}
console
.
log
(
"
THREE.Animation.update: Warning! Scale out of bounds:
"
+
scale
+
"
on bone
"
+
h
);
scale
=
scale
<
0
?
0
:
1
;
}
}
}
else
if
(
type
===
"
rot
"
)
{
// interpolate
THREE
.
Quaternion
.
slerp
(
prevXYZ
,
nextXYZ
,
object
.
quaternion
,
scale
);
if
(
type
===
"
pos
"
)
{
}
else
if
(
type
===
"
scl
"
)
{
vector
=
object
.
position
;
vector
=
object
.
scale
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
LINEAR
)
{
vector
.
x
=
prevXYZ
[
0
]
+
(
nextXYZ
[
0
]
-
prevXYZ
[
0
]
)
*
scale
;
vector
.
y
=
prevXYZ
[
1
]
+
(
nextXYZ
[
1
]
-
prevXYZ
[
1
]
)
*
scale
;
vector
.
z
=
prevXYZ
[
2
]
+
(
nextXYZ
[
2
]
-
prevXYZ
[
2
]
)
*
scale
;
}
}
else
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM
||
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
}
this
.
points
[
0
]
=
this
.
getPrevKeyWith
(
"
pos
"
,
h
,
prevKey
.
index
-
1
)[
"
pos
"
];
this
.
points
[
1
]
=
prevXYZ
;
this
.
points
[
2
]
=
nextXYZ
;
this
.
points
[
3
]
=
this
.
getNextKeyWith
(
"
pos
"
,
h
,
nextKey
.
index
+
1
)[
"
pos
"
];
}
scale
=
scale
*
0.33
+
0.33
;
}
currentPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
);
// update JIT?
vector
.
x
=
currentPoint
[
0
];
vector
.
y
=
currentPoint
[
1
];
vector
.
z
=
currentPoint
[
2
];
if
(
this
.
JITCompile
)
{
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
if
(
JIThierarchy
[
0
][
frame
]
===
undefined
)
{
forwardPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
*
1.01
);
this
.
hierarchy
[
0
].
updateMatrixWorld
(
true
);
this
.
target
.
set
(
forwardPoint
[
0
],
forwardPoint
[
1
],
forwardPoint
[
2
]
);
this
.
target
.
subSelf
(
vector
);
this
.
target
.
y
=
0
;
this
.
target
.
normalize
();
for
(
var
h
=
0
;
h
<
this
.
hierarchy
.
length
;
h
++
)
{
angle
=
Math
.
atan2
(
this
.
target
.
x
,
this
.
target
.
z
);
object
.
rotation
.
set
(
0
,
angle
,
0
);
if
(
this
.
hierarchy
[
h
]
instanceof
THREE
.
Bone
)
{
}
JIThierarchy
[
h
][
frame
]
=
this
.
hierarchy
[
h
].
skinMatrix
.
clone
();
}
}
else
{
}
else
if
(
type
===
"
rot
"
)
{
JIThierarchy
[
h
][
frame
]
=
this
.
hierarchy
[
h
].
matrix
.
clone
(
);
THREE
.
Quaternion
.
slerp
(
prevXYZ
,
nextXYZ
,
object
.
quaternion
,
scale
);
}
}
else
if
(
type
===
"
scl
"
)
{
vector
=
object
.
scale
;
vector
.
x
=
prevXYZ
[
0
]
+
(
nextXYZ
[
0
]
-
prevXYZ
[
0
]
)
*
scale
;
vector
.
y
=
prevXYZ
[
1
]
+
(
nextXYZ
[
1
]
-
prevXYZ
[
1
]
)
*
scale
;
vector
.
z
=
prevXYZ
[
2
]
+
(
nextXYZ
[
2
]
-
prevXYZ
[
2
]
)
*
scale
;
}
...
...
@@ -408,7 +311,7 @@ THREE.Animation.prototype.interpolateCatmullRom = function ( points, scale ) {
};
THREE
.
Animation
.
prototype
.
interpolate
=
function
(
p0
,
p1
,
p2
,
p3
,
t
,
t2
,
t3
)
{
THREE
.
Animation
.
prototype
.
interpolate
=
function
(
p0
,
p1
,
p2
,
p3
,
t
,
t2
,
t3
)
{
var
v0
=
(
p2
-
p0
)
*
0.5
,
v1
=
(
p3
-
p1
)
*
0.5
;
...
...
@@ -421,7 +324,7 @@ THREE.Animation.prototype.interpolate = function( p0, p1, p2, p3, t, t2, t3 ) {
// Get next key with
THREE
.
Animation
.
prototype
.
getNextKeyWith
=
function
(
type
,
h
,
key
)
{
THREE
.
Animation
.
prototype
.
getNextKeyWith
=
function
(
type
,
h
,
key
)
{
var
keys
=
this
.
data
.
hierarchy
[
h
].
keys
;
...
...
@@ -452,7 +355,7 @@ THREE.Animation.prototype.getNextKeyWith = function( type, h, key ) {
// Get previous key with
THREE
.
Animation
.
prototype
.
getPrevKeyWith
=
function
(
type
,
h
,
key
)
{
THREE
.
Animation
.
prototype
.
getPrevKeyWith
=
function
(
type
,
h
,
key
)
{
var
keys
=
this
.
data
.
hierarchy
[
h
].
keys
;
...
...
@@ -480,4 +383,4 @@ THREE.Animation.prototype.getPrevKeyWith = function( type, h, key ) {
return
this
.
data
.
hierarchy
[
h
].
keys
[
keys
.
length
-
1
];
};
\ No newline at end of file
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录