Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
c43140f0
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,发现更多精彩内容 >>
提交
c43140f0
编写于
4月 11, 2014
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tab indentations.
上级
b90267dd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
291 addition
and
291 deletion
+291
-291
examples/js/BlendCharacter.js
examples/js/BlendCharacter.js
+5
-5
examples/webgl_animation_skinning_blending.html
examples/webgl_animation_skinning_blending.html
+164
-164
src/extras/animation/KeyFrameAnimation.js
src/extras/animation/KeyFrameAnimation.js
+1
-1
src/extras/helpers/SkeletonHelper.js
src/extras/helpers/SkeletonHelper.js
+53
-53
src/objects/Skeleton.js
src/objects/Skeleton.js
+68
-68
未找到文件。
examples/js/BlendCharacter.js
浏览文件 @
c43140f0
...
...
@@ -204,15 +204,15 @@ THREE.BlendCharacter = function () {
this
.
unPauseAll
=
function
()
{
for
(
var
a
in
this
.
animations
)
{
for
(
var
a
in
this
.
animations
)
{
if
(
this
.
animations
[
a
].
isPlaying
&&
this
.
animations
[
a
].
isPaused
)
{
if
(
this
.
animations
[
a
].
isPlaying
&&
this
.
animations
[
a
].
isPaused
)
{
this
.
animations
[
a
].
pause
();
this
.
animations
[
a
].
pause
();
}
}
}
}
};
...
...
examples/webgl_animation_skinning_blending.html
浏览文件 @
c43140f0
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - animation - skinning
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
color
:
#000
;
font-family
:
Monospace
;
font-size
:
13px
;
text-align
:
center
;
<head>
<title>
three.js webgl - animation - skinning
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
color
:
#000
;
font-family
:
Monospace
;
font-size
:
13px
;
text-align
:
center
;
background-color
:
#fff
;
margin
:
0px
;
overflow
:
hidden
;
}
background-color
:
#fff
;
margin
:
0px
;
overflow
:
hidden
;
}
#info
{
position
:
absolute
;
top
:
0px
;
width
:
100%
;
padding
:
5px
;
}
</style>
</head>
<body>
<div
id=
"container"
></div>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
- Skeletal Animation Blending
<br><br>
Adjust blend weights to affect the animations that are currently playing.
<br>
Cross fades (and warping) blend between 2 animations and end with a single animation.
</div>
#info
{
position
:
absolute
;
top
:
0px
;
width
:
100%
;
padding
:
5px
;
}
</style>
</head>
<body>
<div
id=
"container"
></div>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
- Skeletal Animation Blending
<br><br>
Adjust blend weights to affect the animations that are currently playing.
<br>
Cross fades (and warping) blend between 2 animations and end with a single animation.
</div>
<script
src=
"../build/Three.js"
></script>
<script
src=
"../build/Three.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
src=
"js/Controls/OrbitControls.js"
></script>
<script
src=
"js/BlendCharacter.js"
></script>
<script
src=
"js/BlendCharacterGui.js"
></script>
<script
src=
"js/libs/dat.gui.min.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
src=
"js/Controls/OrbitControls.js"
></script>
<script
src=
"js/BlendCharacter.js"
></script>
<script
src=
"js/BlendCharacterGui.js"
></script>
<script
src=
"js/libs/dat.gui.min.js"
></script>
<script>
<script>
if
(
!
Detector
.
webgl
)
Detector
.
addGetWebGLMessage
();
if
(
!
Detector
.
webgl
)
Detector
.
addGetWebGLMessage
();
var
container
,
stats
;
var
container
,
stats
;
var
blendMesh
,
camera
,
scene
,
renderer
,
controls
;
var
blendMesh
,
camera
,
scene
,
renderer
,
controls
;
var
clock
=
new
THREE
.
Clock
();
var
gui
=
null
;
var
clock
=
new
THREE
.
Clock
();
var
gui
=
null
;
var
isFrameStepping
=
false
;
var
timeToStep
=
0
;
var
isFrameStepping
=
false
;
var
timeToStep
=
0
;
init
();
init
();
function
init
()
{
function
init
()
{
container
=
document
.
getElementById
(
'
container
'
);
container
=
document
.
getElementById
(
'
container
'
);
scene
=
new
THREE
.
Scene
();
scene
.
add
(
new
THREE
.
AmbientLight
(
0xaaaaaa
)
);
scene
=
new
THREE
.
Scene
();
scene
.
add
(
new
THREE
.
AmbientLight
(
0xaaaaaa
)
);
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
,
1.5
);
light
.
position
=
new
THREE
.
Vector3
(
0
,
0
,
1000.0
);
scene
.
add
(
light
);
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
,
1.5
);
light
.
position
=
new
THREE
.
Vector3
(
0
,
0
,
1000.0
);
scene
.
add
(
light
);
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
alpha
:
false
}
);
renderer
.
setClearColor
(
'
#777777
'
,
1
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
autoClear
=
true
;
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
alpha
:
false
}
);
renderer
.
setClearColor
(
'
#777777
'
,
1
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
autoClear
=
true
;
container
.
appendChild
(
renderer
.
domElement
);
container
.
appendChild
(
renderer
.
domElement
);
//
//
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
container
.
appendChild
(
stats
.
domElement
);
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
container
.
appendChild
(
stats
.
domElement
);
//
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
// listen for messages from the gui
window
.
addEventListener
(
'
start-animation
'
,
onStartAnimation
);
window
.
addEventListener
(
'
stop-animation
'
,
onStopAnimation
);
window
.
addEventListener
(
'
pause-animation
'
,
onPauseAnimation
);
window
.
addEventListener
(
'
step-animation
'
,
onStepAnimation
);
window
.
addEventListener
(
'
weight-animation
'
,
onWeightAnimation
);
window
.
addEventListener
(
'
crossfade
'
,
onCrossfade
);
window
.
addEventListener
(
'
warp
'
,
onWarp
);
window
.
addEventListener
(
'
toggle-lock-camera
'
,
onLockCameraToggle
);
window
.
addEventListener
(
'
toggle-show-bones
'
,
onShowBonesToggle
);
// listen for messages from the gui
window
.
addEventListener
(
'
start-animation
'
,
onStartAnimation
);
window
.
addEventListener
(
'
stop-animation
'
,
onStopAnimation
);
window
.
addEventListener
(
'
pause-animation
'
,
onPauseAnimation
);
window
.
addEventListener
(
'
step-animation
'
,
onStepAnimation
);
window
.
addEventListener
(
'
weight-animation
'
,
onWeightAnimation
);
window
.
addEventListener
(
'
crossfade
'
,
onCrossfade
);
window
.
addEventListener
(
'
warp
'
,
onWarp
);
window
.
addEventListener
(
'
toggle-lock-camera
'
,
onLockCameraToggle
);
window
.
addEventListener
(
'
toggle-show-bones
'
,
onShowBonesToggle
);
blendMesh
=
new
THREE
.
BlendCharacter
();
blendMesh
.
load
(
"
models/skinned/marine/marine_anims.js
"
,
start
);
blendMesh
=
new
THREE
.
BlendCharacter
();
blendMesh
.
load
(
"
models/skinned/marine/marine_anims.js
"
,
start
);
}
}
function
onWindowResize
()
{
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
}
function
onStartAnimation
(
event
)
{
function
onStartAnimation
(
event
)
{
var
data
=
event
.
detail
;
var
data
=
event
.
detail
;
blendMesh
.
stopAll
();
blendMesh
.
stopAll
();
// the blend mesh will combine 1 or more animations
for
(
var
i
=
0
;
i
<
data
.
anims
.
length
;
++
i
)
{
// the blend mesh will combine 1 or more animations
for
(
var
i
=
0
;
i
<
data
.
anims
.
length
;
++
i
)
{
blendMesh
.
play
(
data
.
anims
[
i
],
data
.
weights
[
i
]);
blendMesh
.
play
(
data
.
anims
[
i
],
data
.
weights
[
i
]);
}
}
isFrameStepping
=
false
;
isFrameStepping
=
false
;
}
}
function
onStopAnimation
(
event
)
{
function
onStopAnimation
(
event
)
{
blendMesh
.
stopAll
();
isFrameStepping
=
false
;
blendMesh
.
stopAll
();
isFrameStepping
=
false
;
}
}
function
onPauseAnimation
(
event
)
{
function
onPauseAnimation
(
event
)
{
(
isFrameStepping
)
?
blendMesh
.
unPauseAll
():
blendMesh
.
pauseAll
();
(
isFrameStepping
)
?
blendMesh
.
unPauseAll
():
blendMesh
.
pauseAll
();
isFrameStepping
=
false
;
isFrameStepping
=
false
;
}
}
function
onStepAnimation
(
event
)
{
function
onStepAnimation
(
event
)
{
blendMesh
.
unPauseAll
();
isFrameStepping
=
true
;
timeToStep
=
event
.
detail
.
stepSize
;
}
blendMesh
.
unPauseAll
();
isFrameStepping
=
true
;
timeToStep
=
event
.
detail
.
stepSize
;
}
function
onWeightAnimation
(
event
)
{
function
onWeightAnimation
(
event
)
{
var
data
=
event
.
detail
;
for
(
var
i
=
0
;
i
<
data
.
anims
.
length
;
++
i
)
{
var
data
=
event
.
detail
;
for
(
var
i
=
0
;
i
<
data
.
anims
.
length
;
++
i
)
{
blendMesh
.
applyWeight
(
data
.
anims
[
i
],
data
.
weights
[
i
]);
blendMesh
.
applyWeight
(
data
.
anims
[
i
],
data
.
weights
[
i
]);
}
}
}
}
function
onCrossfade
(
event
)
{
function
onCrossfade
(
event
)
{
var
data
=
event
.
detail
;
var
data
=
event
.
detail
;
blendMesh
.
stopAll
();
blendMesh
.
crossfade
(
data
.
from
,
data
.
to
,
data
.
time
);
blendMesh
.
stopAll
();
blendMesh
.
crossfade
(
data
.
from
,
data
.
to
,
data
.
time
);
isFrameStepping
=
false
;
isFrameStepping
=
false
;
}
}
function
onWarp
(
event
)
{
function
onWarp
(
event
)
{
var
data
=
event
.
detail
;
var
data
=
event
.
detail
;
blendMesh
.
stopAll
();
blendMesh
.
warp
(
data
.
from
,
data
.
to
,
data
.
time
);
blendMesh
.
stopAll
();
blendMesh
.
warp
(
data
.
from
,
data
.
to
,
data
.
time
);
isFrameStepping
=
false
;
isFrameStepping
=
false
;
}
}
function
onLockCameraToggle
(
event
)
{
function
onLockCameraToggle
(
event
)
{
var
shouldLock
=
event
.
detail
.
shouldLock
;
controls
.
enabled
=
!
shouldLock
;
var
shouldLock
=
event
.
detail
.
shouldLock
;
controls
.
enabled
=
!
shouldLock
;
}
}
function
onShowBonesToggle
(
event
)
{
function
onShowBonesToggle
(
event
)
{
var
shouldShow
=
event
.
detail
.
shouldShow
;
blendMesh
.
toggleShowBones
(
shouldShow
);
var
shouldShow
=
event
.
detail
.
shouldShow
;
blendMesh
.
toggleShowBones
(
shouldShow
);
}
}
function
start
()
{
function
start
()
{
blendMesh
.
rotation
.
y
=
Math
.
PI
*
-
135
/
180
;
scene
.
add
(
blendMesh
);
blendMesh
.
rotation
.
y
=
Math
.
PI
*
-
135
/
180
;
scene
.
add
(
blendMesh
);
var
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
var
radius
=
blendMesh
.
geometry
.
boundingSphere
.
radius
;
var
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
var
radius
=
blendMesh
.
geometry
.
boundingSphere
.
radius
;
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
aspect
,
1
,
10000
);
camera
.
position
.
set
(
0.0
,
radius
,
radius
*
3.5
);
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
aspect
,
1
,
10000
);
camera
.
position
.
set
(
0.0
,
radius
,
radius
*
3.5
);
controls
=
new
THREE
.
OrbitControls
(
camera
);
controls
.
target
=
new
THREE
.
Vector3
(
0
,
radius
,
0
);
controls
.
update
();
controls
=
new
THREE
.
OrbitControls
(
camera
);
controls
.
target
=
new
THREE
.
Vector3
(
0
,
radius
,
0
);
controls
.
update
();
// Set default weights
// Set default weights
blendMesh
.
animations
[
'
idle
'
].
weight
=
1
/
3
;
blendMesh
.
animations
[
'
walk
'
].
weight
=
1
/
3
;
blendMesh
.
animations
[
'
run
'
].
weight
=
1
/
3
;
blendMesh
.
animations
[
'
idle
'
].
weight
=
1
/
3
;
blendMesh
.
animations
[
'
walk
'
].
weight
=
1
/
3
;
blendMesh
.
animations
[
'
run
'
].
weight
=
1
/
3
;
gui
=
new
BlendCharacterGui
(
blendMesh
.
animations
);
gui
=
new
BlendCharacterGui
(
blendMesh
.
animations
);
animate
();
}
animate
();
}
function
animate
()
{
function
animate
()
{
requestAnimationFrame
(
animate
,
renderer
.
domElement
);
requestAnimationFrame
(
animate
,
renderer
.
domElement
);
// step forward in time based on whether we're stepping and scale
// step forward in time based on whether we're stepping and scale
var
scale
=
gui
.
getTimeScale
();
var
delta
=
clock
.
getDelta
();
var
stepSize
=
(
!
isFrameStepping
)
?
delta
*
scale
:
timeToStep
;
var
scale
=
gui
.
getTimeScale
();
var
delta
=
clock
.
getDelta
();
var
stepSize
=
(
!
isFrameStepping
)
?
delta
*
scale
:
timeToStep
;
// modify blend weights
// modify blend weights
blendMesh
.
update
(
stepSize
);
gui
.
update
();
blendMesh
.
update
(
stepSize
);
gui
.
update
();
THREE
.
AnimationHandler
.
update
(
stepSize
);
THREE
.
AnimationHandler
.
update
(
stepSize
);
renderer
.
render
(
scene
,
camera
);
stats
.
update
();
renderer
.
render
(
scene
,
camera
);
stats
.
update
();
// if we are stepping, consume time
// ( will equal step size next time a single step is desired )
// if we are stepping, consume time
// ( will equal step size next time a single step is desired )
timeToStep
=
0
;
timeToStep
=
0
;
}
}
</script>
</script>
</body>
</body>
</html>
src/extras/animation/KeyFrameAnimation.js
浏览文件 @
c43140f0
...
...
@@ -137,7 +137,7 @@ THREE.KeyFrameAnimation.prototype.stop = function() {
// reset JIT matrix and remove cache
for
(
var
h
=
0
;
h
<
this
.
data
.
hierarchy
.
length
;
h
++
)
{
var
obj
=
this
.
hierarchy
[
h
];
var
node
=
this
.
data
.
hierarchy
[
h
];
...
...
src/extras/helpers/SkeletonHelper.js
浏览文件 @
c43140f0
...
...
@@ -5,48 +5,48 @@
THREE
.
SkeletonHelper
=
function
(
skeleton
,
jointBoxSize
,
scaleRatio
)
{
THREE
.
Object3D
.
call
(
this
);
THREE
.
Object3D
.
call
(
this
);
this
.
scaleRatio
=
(
scaleRatio
!==
undefined
)
?
scaleRatio
:
1
;
this
.
skeleton
=
skeleton
;
this
.
scaleRatio
=
(
scaleRatio
!==
undefined
)
?
scaleRatio
:
1
;
this
.
skeleton
=
skeleton
;
if
(
jointBoxSize
===
undefined
)
jointBoxSize
=
1
;
var
boxSize
=
jointBoxSize
*
this
.
scaleRatio
;
if
(
jointBoxSize
===
undefined
)
jointBoxSize
=
1
;
var
boxSize
=
jointBoxSize
*
this
.
scaleRatio
;
for
(
var
i
=
0
;
i
<
skeleton
.
bones
.
length
;
++
i
)
{
for
(
var
i
=
0
;
i
<
skeleton
.
bones
.
length
;
++
i
)
{
var
bone
=
skeleton
.
bones
[
i
];
var
boxGeometry
=
new
THREE
.
BoxGeometry
(
boxSize
,
boxSize
,
boxSize
);
var
boxMaterial
=
new
THREE
.
MeshBasicMaterial
();
var
bone
=
skeleton
.
bones
[
i
];
var
boxGeometry
=
new
THREE
.
BoxGeometry
(
boxSize
,
boxSize
,
boxSize
);
var
boxMaterial
=
new
THREE
.
MeshBasicMaterial
();
bone
.
helper
=
{};
bone
.
helper
.
box
=
new
THREE
.
Mesh
(
boxGeometry
,
boxMaterial
);
bone
.
helper
.
axes
=
new
THREE
.
AxisHelper
(
jointBoxSize
*
3
);
bone
.
helper
=
{};
bone
.
helper
.
box
=
new
THREE
.
Mesh
(
boxGeometry
,
boxMaterial
);
bone
.
helper
.
axes
=
new
THREE
.
AxisHelper
(
jointBoxSize
*
3
);
this
.
add
(
bone
.
helper
.
box
);
this
.
add
(
bone
.
helper
.
axes
);
this
.
add
(
bone
.
helper
.
box
);
this
.
add
(
bone
.
helper
.
axes
);
if
(
bone
.
parent
instanceof
THREE
.
Bone
)
{
if
(
bone
.
parent
instanceof
THREE
.
Bone
)
{
var
lineMaterial
=
new
THREE
.
LineBasicMaterial
();
var
lineGeometry
=
new
THREE
.
Geometry
();
var
lineMaterial
=
new
THREE
.
LineBasicMaterial
();
var
lineGeometry
=
new
THREE
.
Geometry
();
lineMaterial
.
vertexColors
=
true
;
lineMaterial
.
vertexColors
=
true
;
lineGeometry
.
vertices
.
push
(
new
THREE
.
Vector3
()
);
lineGeometry
.
vertices
.
push
(
new
THREE
.
Vector3
()
);
lineGeometry
.
colors
.
push
(
new
THREE
.
Color
(
1
,
1
,
0
)
);
lineGeometry
.
colors
.
push
(
new
THREE
.
Color
(
0
,
0
,
0
)
);
lineGeometry
.
vertices
.
push
(
new
THREE
.
Vector3
()
);
lineGeometry
.
vertices
.
push
(
new
THREE
.
Vector3
()
);
lineGeometry
.
colors
.
push
(
new
THREE
.
Color
(
1
,
1
,
0
)
);
lineGeometry
.
colors
.
push
(
new
THREE
.
Color
(
0
,
0
,
0
)
);
bone
.
helper
.
line
=
new
THREE
.
Line
(
lineGeometry
,
lineMaterial
);
this
.
add
(
bone
.
helper
.
line
);
bone
.
helper
.
line
=
new
THREE
.
Line
(
lineGeometry
,
lineMaterial
);
this
.
add
(
bone
.
helper
.
line
);
}
}
}
}
this
.
update
();
this
.
update
();
};
...
...
@@ -54,50 +54,50 @@ THREE.SkeletonHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE
.
SkeletonHelper
.
prototype
.
update
=
function
()
{
for
(
var
i
=
0
;
i
<
this
.
skeleton
.
bones
.
length
;
++
i
)
{
for
(
var
i
=
0
;
i
<
this
.
skeleton
.
bones
.
length
;
++
i
)
{
var
bone
=
this
.
skeleton
.
bones
[
i
];
var
bone
=
this
.
skeleton
.
bones
[
i
];
if
(
this
.
visible
&&
bone
.
parent
instanceof
THREE
.
Bone
)
{
if
(
this
.
visible
&&
bone
.
parent
instanceof
THREE
.
Bone
)
{
bone
.
skinMatrix
.
decompose
(
bone
.
helper
.
box
.
position
,
bone
.
helper
.
box
.
quaternion
,
bone
.
helper
.
box
.
scale
);
bone
.
helper
.
box
.
position
.
multiplyScalar
(
this
.
scaleRatio
);
bone
.
skinMatrix
.
decompose
(
bone
.
helper
.
box
.
position
,
bone
.
helper
.
box
.
quaternion
,
bone
.
helper
.
box
.
scale
);
bone
.
helper
.
box
.
position
.
multiplyScalar
(
this
.
scaleRatio
);
bone
.
helper
.
axes
.
quaternion
=
bone
.
helper
.
box
.
quaternion
;
bone
.
helper
.
axes
.
position
=
bone
.
helper
.
box
.
position
;
bone
.
helper
.
axes
.
scale
=
bone
.
helper
.
box
.
scale
;
bone
.
helper
.
axes
.
quaternion
=
bone
.
helper
.
box
.
quaternion
;
bone
.
helper
.
axes
.
position
=
bone
.
helper
.
box
.
position
;
bone
.
helper
.
axes
.
scale
=
bone
.
helper
.
box
.
scale
;
bone
.
helper
.
line
.
geometry
.
vertices
[
0
].
setFromMatrixPosition
(
bone
.
skinMatrix
);
bone
.
helper
.
line
.
geometry
.
vertices
[
0
].
multiplyScalar
(
this
.
scaleRatio
);
bone
.
helper
.
line
.
geometry
.
vertices
[
0
].
setFromMatrixPosition
(
bone
.
skinMatrix
);
bone
.
helper
.
line
.
geometry
.
vertices
[
0
].
multiplyScalar
(
this
.
scaleRatio
);
bone
.
helper
.
line
.
geometry
.
vertices
[
1
].
setFromMatrixPosition
(
bone
.
parent
.
skinMatrix
);
bone
.
helper
.
line
.
geometry
.
vertices
[
1
].
multiplyScalar
(
this
.
scaleRatio
);
bone
.
helper
.
line
.
geometry
.
vertices
[
1
].
setFromMatrixPosition
(
bone
.
parent
.
skinMatrix
);
bone
.
helper
.
line
.
geometry
.
vertices
[
1
].
multiplyScalar
(
this
.
scaleRatio
);
bone
.
helper
.
line
.
geometry
.
verticesNeedUpdate
=
true
;
bone
.
helper
.
line
.
geometry
.
verticesNeedUpdate
=
true
;
}
}
}
}
};
THREE
.
SkeletonHelper
.
prototype
.
setVisible
=
function
(
shouldBeVisible
)
{
for
(
var
i
=
0
;
i
<
this
.
skeleton
.
bones
.
length
;
++
i
)
{
for
(
var
i
=
0
;
i
<
this
.
skeleton
.
bones
.
length
;
++
i
)
{
var
bone
=
this
.
skeleton
.
bones
[
i
];
if
(
bone
.
helper
)
{
var
bone
=
this
.
skeleton
.
bones
[
i
];
if
(
bone
.
helper
)
{
bone
.
helper
.
box
.
visible
=
shouldBeVisible
;
bone
.
helper
.
axes
.
visible
=
shouldBeVisible
;
bone
.
helper
.
box
.
visible
=
shouldBeVisible
;
bone
.
helper
.
axes
.
visible
=
shouldBeVisible
;
if
(
bone
.
parent
instanceof
THREE
.
Bone
)
{
if
(
bone
.
parent
instanceof
THREE
.
Bone
)
{
bone
.
helper
.
line
.
visible
=
shouldBeVisible
;
bone
.
helper
.
line
.
visible
=
shouldBeVisible
;
}
}
}
}
}
}
}
src/objects/Skeleton.js
浏览文件 @
c43140f0
...
...
@@ -6,96 +6,96 @@
THREE
.
Skeleton
=
function
(
boneList
,
useVertexTexture
)
{
this
.
useVertexTexture
=
useVertexTexture
!==
undefined
?
useVertexTexture
:
true
;
this
.
useVertexTexture
=
useVertexTexture
!==
undefined
?
useVertexTexture
:
true
;
// init bones
// init bones
this
.
bones
=
[];
this
.
boneMatrices
=
[];
this
.
bones
=
[];
this
.
boneMatrices
=
[];
var
bone
,
gbone
,
p
,
q
,
s
;
var
bone
,
gbone
,
p
,
q
,
s
;
if
(
boneList
!==
undefined
)
{
if
(
boneList
!==
undefined
)
{
for
(
var
b
=
0
;
b
<
boneList
.
length
;
++
b
)
{
for
(
var
b
=
0
;
b
<
boneList
.
length
;
++
b
)
{
gbone
=
boneList
[
b
];
gbone
=
boneList
[
b
];
p
=
gbone
.
pos
;
q
=
gbone
.
rotq
;
s
=
gbone
.
scl
;
p
=
gbone
.
pos
;
q
=
gbone
.
rotq
;
s
=
gbone
.
scl
;
bone
=
this
.
addBone
();
bone
=
this
.
addBone
();
bone
.
name
=
gbone
.
name
;
bone
.
position
.
set
(
p
[
0
],
p
[
1
],
p
[
2
]
);
bone
.
quaternion
.
set
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
]
);
bone
.
name
=
gbone
.
name
;
bone
.
position
.
set
(
p
[
0
],
p
[
1
],
p
[
2
]
);
bone
.
quaternion
.
set
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
]
);
if
(
s
!==
undefined
)
{
if
(
s
!==
undefined
)
{
bone
.
scale
.
set
(
s
[
0
],
s
[
1
],
s
[
2
]
);
bone
.
scale
.
set
(
s
[
0
],
s
[
1
],
s
[
2
]
);
}
else
{
}
else
{
bone
.
scale
.
set
(
1
,
1
,
1
);
bone
.
scale
.
set
(
1
,
1
,
1
);
}
}
}
}
for
(
var
b
=
0
;
b
<
boneList
.
length
;
++
b
)
{
for
(
var
b
=
0
;
b
<
boneList
.
length
;
++
b
)
{
gbone
=
boneList
[
b
];
gbone
=
boneList
[
b
];
if
(
gbone
.
parent
!==
-
1
)
{
if
(
gbone
.
parent
!==
-
1
)
{
this
.
bones
[
gbone
.
parent
].
add
(
this
.
bones
[
b
]
);
this
.
bones
[
gbone
.
parent
].
add
(
this
.
bones
[
b
]
);
}
}
}
}
//
//
var
nBones
=
this
.
bones
.
length
;
var
nBones
=
this
.
bones
.
length
;
if
(
this
.
useVertexTexture
)
{
if
(
this
.
useVertexTexture
)
{
// layout (1 matrix = 4 pixels)
// RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
// with 8x8 pixel texture max 16 bones (8 * 8 / 4)
// 16x16 pixel texture max 64 bones (16 * 16 / 4)
// 32x32 pixel texture max 256 bones (32 * 32 / 4)
// 64x64 pixel texture max 1024 bones (64 * 64 / 4)
// layout (1 matrix = 4 pixels)
// RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
// with 8x8 pixel texture max 16 bones (8 * 8 / 4)
// 16x16 pixel texture max 64 bones (16 * 16 / 4)
// 32x32 pixel texture max 256 bones (32 * 32 / 4)
// 64x64 pixel texture max 1024 bones (64 * 64 / 4)
var
size
;
var
size
;
if
(
nBones
>
256
)
size
=
64
;
else
if
(
nBones
>
64
)
size
=
32
;
else
if
(
nBones
>
16
)
size
=
16
;
else
size
=
8
;
if
(
nBones
>
256
)
size
=
64
;
else
if
(
nBones
>
64
)
size
=
32
;
else
if
(
nBones
>
16
)
size
=
16
;
else
size
=
8
;
this
.
boneTextureWidth
=
size
;
this
.
boneTextureHeight
=
size
;
this
.
boneTextureWidth
=
size
;
this
.
boneTextureHeight
=
size
;
this
.
boneMatrices
=
new
Float32Array
(
this
.
boneTextureWidth
*
this
.
boneTextureHeight
*
4
);
// 4 floats per RGBA pixel
this
.
boneTexture
=
new
THREE
.
DataTexture
(
this
.
boneMatrices
,
this
.
boneTextureWidth
,
this
.
boneTextureHeight
,
THREE
.
RGBAFormat
,
THREE
.
FloatType
);
this
.
boneTexture
.
minFilter
=
THREE
.
NearestFilter
;
this
.
boneTexture
.
magFilter
=
THREE
.
NearestFilter
;
this
.
boneTexture
.
generateMipmaps
=
false
;
this
.
boneTexture
.
flipY
=
false
;
this
.
boneMatrices
=
new
Float32Array
(
this
.
boneTextureWidth
*
this
.
boneTextureHeight
*
4
);
// 4 floats per RGBA pixel
this
.
boneTexture
=
new
THREE
.
DataTexture
(
this
.
boneMatrices
,
this
.
boneTextureWidth
,
this
.
boneTextureHeight
,
THREE
.
RGBAFormat
,
THREE
.
FloatType
);
this
.
boneTexture
.
minFilter
=
THREE
.
NearestFilter
;
this
.
boneTexture
.
magFilter
=
THREE
.
NearestFilter
;
this
.
boneTexture
.
generateMipmaps
=
false
;
this
.
boneTexture
.
flipY
=
false
;
}
else
{
}
else
{
this
.
boneMatrices
=
new
Float32Array
(
16
*
nBones
);
this
.
boneMatrices
=
new
Float32Array
(
16
*
nBones
);
}
}
}
}
};
...
...
@@ -105,31 +105,31 @@ THREE.Skeleton.prototype = Object.create( THREE.Mesh.prototype );
THREE
.
Skeleton
.
prototype
.
addBone
=
function
(
bone
)
{
if
(
bone
===
undefined
)
{
if
(
bone
===
undefined
)
{
bone
=
new
THREE
.
Bone
(
this
);
bone
=
new
THREE
.
Bone
(
this
);
}
}
this
.
bones
.
push
(
bone
);
this
.
bones
.
push
(
bone
);
return
bone
;
return
bone
;
};
THREE
.
Skeleton
.
prototype
.
calculateInverses
=
function
(
bone
)
{
this
.
boneInverses
=
[];
this
.
boneInverses
=
[];
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
++
b
)
{
for
(
var
b
=
0
,
bl
=
this
.
bones
.
length
;
b
<
bl
;
++
b
)
{
var
inverse
=
new
THREE
.
Matrix4
();
var
inverse
=
new
THREE
.
Matrix4
();
inverse
.
getInverse
(
this
.
bones
[
b
].
skinMatrix
);
inverse
.
getInverse
(
this
.
bones
[
b
].
skinMatrix
);
this
.
boneInverses
.
push
(
inverse
);
this
.
boneInverses
.
push
(
inverse
);
}
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录