Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
8e94b36f
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,发现更多精彩内容 >>
提交
8e94b36f
编写于
7月 24, 2015
作者:
B
Ben Houston
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introduce the TrackBinding class for better organization.
上级
c88066f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
202 addition
and
128 deletion
+202
-128
src/animation/AnimationMixer.js
src/animation/AnimationMixer.js
+7
-43
src/animation/AnimationUtils.js
src/animation/AnimationUtils.js
+1
-85
src/animation/TrackBinding.js
src/animation/TrackBinding.js
+194
-0
未找到文件。
src/animation/AnimationMixer.js
浏览文件 @
8e94b36f
...
...
@@ -12,7 +12,7 @@ THREE.AnimationMixer = function( root ) {
this
.
root
=
root
;
this
.
actions
=
[];
this
.
track
Info
s
=
{};
this
.
track
Binding
s
=
{};
};
...
...
@@ -25,12 +25,9 @@ THREE.AnimationMixer.prototype = {
this
.
actions
.
push
(
action
);
foreach
(
var
track
in
action
.
tracks
)
{
if
(
!
this
.
trackInfos
[
track
.
name
]
)
{
this
.
trackInfos
[
track
.
name
]
=
{
node
:
THREE
.
AnimationUtils
.
findNode
(
this
.
root
,
track
.
nodeName
),
propertyName
:
track
.
propertyName
}
for
(
var
track
in
action
.
tracks
)
{
if
(
!
this
.
trackBindings
[
track
.
name
]
)
{
this
.
trackBindings
[
track
.
name
]
=
new
THREE
.
TrackBinding
(
this
.
root
,
track
.
name
);
}
}
...
...
@@ -86,42 +83,9 @@ THREE.AnimationMixer.prototype = {
var
mixerResult
=
mixerResults
[
name
];
var
trackInfo
=
this
.
trackInfos
[
name
];
var
node
=
trackInfo
.
node
;
if
(
!
node
)
{
console
.
log
(
"
trying to update node for track:
"
+
name
+
"
but it wasn't found.
"
);
continue
;
}
var
propertyName
=
trackInfo
.
propertyName
;
if
(
!
node
[
propertyName
]
)
{
console
.
log
(
"
trying to update property for track:
"
+
name
+
'
.
'
+
propertyName
+
"
but it wasn't found.
"
);
continue
;
}
// must use copy for Object3D.Euler/Quaternion
if
(
node
[
propertyName
].
copy
)
{
console
.
log
(
'
update property
'
+
name
+
'
.
'
+
propertyName
+
'
via a set() function.
'
);
node
[
propertyName
].
copy
(
mixerResult
.
value
);
}
// otherwise just copy across value
else
{
console
.
log
(
'
update property
'
+
name
+
'
.
'
+
propertyName
+
'
via assignment.
'
);
node
[
propertyName
]
=
mixerResult
.
value
;
}
// trigger node dirty
if
(
node
.
needsUpdate
)
{
// material
node
.
needsUpdate
=
true
;
}
if
(
node
.
matrixWorldNeedsUpdate
&&
!
this
.
matrixAutoUpdate
)
{
// node transform
node
.
matrixWorldNeedsUpdate
=
true
;
}
var
trackBinding
=
this
.
trackBindings
[
name
];
trackBinding
.
set
(
mixerResult
.
value
);
}
}
...
...
src/animation/AnimationUtils.js
浏览文件 @
8e94b36f
...
...
@@ -22,90 +22,6 @@
return
a
*
(
1
-
alpha
)
+
b
*
alpha
;
}
},
// TODO: Cache this at some point
findNode
:
function
(
root
,
nodeName
)
{
console
.
log
(
'
AnimationUtils.findNode(
'
+
root
.
name
+
'
, nodeName:
'
+
nodeName
+
'
)
'
);
if
(
!
nodeName
||
nodeName
===
""
||
nodeName
===
"
root
"
||
nodeName
===
"
.
"
||
nodeName
===
-
1
)
{
console
.
log
(
'
root.
'
);
return
root
;
}
// (2) search into skeleton bones.
if
(
root
.
skeleton
)
{
var
searchSkeleton
=
function
(
skeleton
)
{
for
(
var
i
=
0
;
i
<
skeleton
.
bones
.
length
;
i
++
)
{
var
bone
=
skeleton
.
bones
[
i
];
if
(
bone
.
name
===
nodeName
)
{
return
childNode
;
}
}
return
null
;
};
var
boneNode
=
searchSkeleton
(
root
.
skeleton
);
if
(
boneNode
)
{
console
.
log
(
'
bone:
'
+
bone
.
name
+
'
.
'
);
return
boneNode
;
}
}
// (3) search into node subtree.
if
(
root
.
children
)
{
var
searchNodeSubtree
=
function
(
children
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
childNode
=
children
[
i
];
if
(
childNode
.
name
===
nodeName
)
{
return
childNode
;
}
var
result
=
searchNodeSubtree
(
childNode
.
children
);
if
(
result
)
return
result
;
}
return
null
;
};
var
subTreeNode
=
searchNodeSubtree
(
root
.
children
);
if
(
subTreeNode
)
{
console
.
log
(
'
node:
'
+
subTreeNode
.
name
+
'
.
'
);
return
subTreeNode
;
}
}
console
.
log
(
"
<null>. No node found for name:
"
+
name
);
return
null
;
}
};
\ No newline at end of file
src/animation/TrackBinding.js
0 → 100644
浏览文件 @
8e94b36f
/**
*
* A track bound to a real value in the scene graph.
*
* @author Ben Houston / http://clara.io/
* @author David Sarno / http://lighthaus.us/
*/
THREE
.
TrackBinding
=
function
(
rootNode
,
trackName
)
{
this
.
rootNode
=
rootNode
;
this
.
trackName
=
trackName
;
var
parseResults
=
THREE
.
TrackBinding
.
parseTrackName
(
trackName
);
this
.
directoryName
=
parseResults
.
directoryName
||
null
;
this
.
nodeName
=
parseResults
.
nodeName
;
this
.
propertyName
=
parseResults
.
propertyName
||
null
;
this
.
propertyArrayIndex
=
parseResults
.
propertyArrayIndex
||
-
1
;
this
.
node
=
THREE
.
TrackBinding
.
findNode
(
rootNode
,
this
.
nodeName
);
};
THREE
.
TrackBinding
.
prototype
=
{
constructor
:
THREE
.
TrackBinding
,
set
:
function
(
value
)
{
console
.
log
(
"
TrackBinding.set(
"
+
value
+
"
)
"
);
// ensure there is a value node
if
(
!
this
.
node
)
{
console
.
log
(
"
trying to update node for track:
"
+
this
.
trackName
+
"
but it wasn't found.
"
);
continue
;
}
// ensure there is a value property on the node
var
nodeProperty
=
this
.
node
[
this
.
propertyName
];
if
(
!
nodeProperty
)
{
console
.
log
(
"
trying to update property for track:
"
+
this
.
nodeName
+
'
.
'
+
this
.
propertyName
+
"
but it wasn't found.
"
);
continue
;
}
// access a sub element of the property array (only primitives are supported right now)
if
(
this
.
propertyArrayIndex
>=
0
)
{
console
.
log
(
'
update property array
'
+
this
.
propertyName
+
'
[
'
+
this
.
propertyArrayIndex
+
'
] via assignment.
'
);
nodeProperty
[
this
.
propertyArrayIndex
]
=
value
;
}
// must use copy for Object3D.Euler/Quaternion
else
if
(
nodeProperty
.
copy
)
{
console
.
log
(
'
update property
'
+
this
.
name
+
'
.
'
+
this
.
propertyName
+
'
via a set() function.
'
);
nodeProperty
.
copy
(
value
);
}
// otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
else
{
console
.
log
(
'
update property
'
+
this
.
name
+
'
.
'
+
this
.
propertyName
+
'
via assignment.
'
);
node
[
this
.
propertyName
]
=
value
;
}
// trigger node dirty
if
(
this
.
node
.
needsUpdate
)
{
// material
console
.
log
(
'
triggering material as dirty
'
);
this
.
node
.
needsUpdate
=
true
;
}
if
(
this
.
node
.
matrixWorldNeedsUpdate
&&
!
this
.
node
.
matrixAutoUpdate
)
{
// node transform
console
.
log
(
'
triggering node as dirty
'
);
this
.
node
.
matrixWorldNeedsUpdate
=
true
;
}
},
get
:
function
()
{
throw
new
Error
(
"
TODO
"
);
}
};
THREE
.
TrackBinding
.
parseTrackName
=
function
(
trackName
)
{
// matches strings in the form of:
// directory/directory/directory/filename.property[index]
// created and tested via https://regex101.com/#javascript
var
re
=
/^
(([\w]
+
\/)
*
)([\w]
+
)(\.([\w]
+
)(\[([\w]
+
)\])?)?
$/
;
var
matches
=
re
.
exec
(
trackName
);
if
(
!
matches
)
{
throw
new
Error
(
"
cannot parse trackName at all:
"
+
trackName
);
}
if
(
matches
.
index
===
re
.
lastIndex
)
{
re
.
lastIndex
++
;
}
var
parseResults
=
{
directoryName
:
m
[
0
],
nodeName
:
m
[
2
],
propertyName
:
m
[
4
],
propertySubElement
:
m
[
6
]
};
console
.
log
(
"
TrackBinding.parseTrackName
"
,
trackName
,
parseResults
);
return
parseResults
;
};
// TODO: Cache this at some point
THREE
.
TrackBinding
.
findNode
=
function
(
root
,
nodeName
)
{
console
.
log
(
'
AnimationUtils.findNode(
'
+
root
.
name
+
'
, nodeName:
'
+
nodeName
+
'
)
'
);
if
(
!
nodeName
||
nodeName
===
""
||
nodeName
===
"
root
"
||
nodeName
===
"
.
"
||
nodeName
===
-
1
)
{
console
.
log
(
'
root.
'
);
return
root
;
}
// (2) search into skeleton bones.
if
(
root
.
skeleton
)
{
var
searchSkeleton
=
function
(
skeleton
)
{
for
(
var
i
=
0
;
i
<
skeleton
.
bones
.
length
;
i
++
)
{
var
bone
=
skeleton
.
bones
[
i
];
if
(
bone
.
name
===
nodeName
)
{
return
childNode
;
}
}
return
null
;
};
var
boneNode
=
searchSkeleton
(
root
.
skeleton
);
if
(
boneNode
)
{
console
.
log
(
'
bone:
'
+
bone
.
name
+
'
.
'
);
return
boneNode
;
}
}
// (3) search into node subtree.
if
(
root
.
children
)
{
var
searchNodeSubtree
=
function
(
children
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
childNode
=
children
[
i
];
if
(
childNode
.
name
===
nodeName
)
{
return
childNode
;
}
var
result
=
searchNodeSubtree
(
childNode
.
children
);
if
(
result
)
return
result
;
}
return
null
;
};
var
subTreeNode
=
searchNodeSubtree
(
root
.
children
);
if
(
subTreeNode
)
{
console
.
log
(
'
node:
'
+
subTreeNode
.
name
+
'
.
'
);
return
subTreeNode
;
}
}
console
.
log
(
"
<null>. No node found for name:
"
+
name
);
return
null
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录