Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
408503ec
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
提交
408503ec
编写于
5月 31, 2017
作者:
M
Mr.doob
提交者:
GitHub
5月 31, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11430 from Mugen87/animation
ColladaLoader2: Parse animation data
上级
41d5cb0b
580bc9b5
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
281 addition
and
15 deletion
+281
-15
examples/js/loaders/ColladaLoader2.js
examples/js/loaders/ColladaLoader2.js
+281
-15
未找到文件。
examples/js/loaders/ColladaLoader2.js
浏览文件 @
408503ec
...
...
@@ -33,7 +33,7 @@ THREE.ColladaLoader.prototype = {
set
convertUpAxis
(
value
)
{
console
.
log
(
'
ColladaLoader.options.convertUpAxis: TODO
'
);
console
.
log
(
'
THREE.
ColladaLoader.options.convertUpAxis: TODO
'
);
}
...
...
@@ -176,6 +176,268 @@ THREE.ColladaLoader.prototype = {
}
// animation
function
parseAnimation
(
xml
)
{
var
data
=
{
sources
:
{},
samplers
:
{},
channels
:
{}
};
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
var
id
;
switch
(
child
.
nodeName
)
{
case
'
source
'
:
id
=
child
.
getAttribute
(
'
id
'
);
data
.
sources
[
id
]
=
parseSource
(
child
);
break
;
case
'
sampler
'
:
id
=
child
.
getAttribute
(
'
id
'
);
data
.
samplers
[
id
]
=
parseAnimationSampler
(
child
);
break
;
case
'
channel
'
:
id
=
child
.
getAttribute
(
'
target
'
);
data
.
channels
[
id
]
=
parseAnimationChannel
(
child
);
break
;
default
:
console
.
log
(
child
);
}
}
library
.
animations
[
xml
.
getAttribute
(
'
id
'
)
]
=
data
;
}
function
parseAnimationSampler
(
xml
)
{
var
data
=
{
inputs
:
{},
};
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
switch
(
child
.
nodeName
)
{
case
'
input
'
:
var
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
var
semantic
=
child
.
getAttribute
(
'
semantic
'
);
data
.
inputs
[
semantic
]
=
id
;
break
;
}
}
return
data
;
}
function
parseAnimationChannel
(
xml
)
{
var
data
=
{};
var
target
=
xml
.
getAttribute
(
'
target
'
);
// parsing SID Addressing Syntax
var
parts
=
target
.
split
(
'
/
'
);
var
id
=
parts
.
shift
();
var
sid
=
parts
.
shift
();
// check selection syntax
var
arraySyntax
=
(
sid
.
indexOf
(
'
(
'
)
!==
-
1
);
var
memberSyntax
=
(
sid
.
indexOf
(
'
.
'
)
!==
-
1
);
if
(
memberSyntax
)
{
// member selection access
parts
=
sid
.
split
(
'
.
'
);
sid
=
parts
.
shift
();
data
.
member
=
parts
.
shift
();
}
else
if
(
arraySyntax
)
{
// array-access syntax. can be used to express fields in one-dimensional vectors or two-dimensional matrices.
var
indices
=
sid
.
split
(
'
(
'
);
sid
=
indices
.
shift
();
for
(
var
i
=
0
;
i
<
indices
.
length
;
i
++
)
{
indices
[
i
]
=
parseInt
(
indices
[
i
].
replace
(
/
\)
/
,
''
)
);
}
data
.
indices
=
indices
;
}
data
.
id
=
id
;
data
.
sid
=
sid
;
data
.
arraySyntax
=
arraySyntax
;
data
.
memberSyntax
=
memberSyntax
;
data
.
sampler
=
parseId
(
xml
.
getAttribute
(
'
source
'
)
);
return
data
;
}
// controller
function
parseController
(
xml
)
{
var
data
=
{
skin
:
{}
};
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
switch
(
child
.
nodeName
)
{
case
'
skin
'
:
var
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
data
.
skin
[
id
]
=
parseSkin
(
child
);
break
;
}
}
library
.
controllers
[
xml
.
getAttribute
(
'
id
'
)
]
=
data
;
}
function
parseSkin
(
xml
)
{
var
data
=
{
sources
:
{}
}
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
switch
(
child
.
nodeName
)
{
case
'
bind_shape_matrix
'
:
data
.
bindShapeMatrix
=
parseFloats
(
child
.
textContent
);
break
;
case
'
source
'
:
var
id
=
child
.
getAttribute
(
'
id
'
);
data
.
sources
[
id
]
=
parseSource
(
child
);
break
;
case
'
joints
'
:
data
.
joints
=
parseJoints
(
child
);
break
;
case
'
vertex_weights
'
:
data
.
vertexWeights
=
parseVertexWeights
(
child
);
break
;
}
}
return
data
;
}
function
parseJoints
(
xml
)
{
var
data
=
{
inputs
:
{}
}
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
switch
(
child
.
nodeName
)
{
case
'
input
'
:
var
semantic
=
child
.
getAttribute
(
'
semantic
'
);
var
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
data
.
inputs
[
semantic
]
=
id
;
break
;
}
}
return
data
;
}
function
parseVertexWeights
(
xml
)
{
var
data
=
{
inputs
:
{}
}
for
(
var
i
=
0
,
l
=
xml
.
childNodes
.
length
;
i
<
l
;
i
++
)
{
var
child
=
xml
.
childNodes
[
i
];
if
(
child
.
nodeType
!==
1
)
continue
;
switch
(
child
.
nodeName
)
{
case
'
input
'
:
var
semantic
=
child
.
getAttribute
(
'
semantic
'
);
var
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
var
offset
=
parseInt
(
child
.
getAttribute
(
'
offset
'
)
);
data
.
inputs
[
semantic
]
=
{
id
:
id
,
offset
:
offset
};
break
;
case
'
vcount
'
:
data
.
vcount
=
parseInts
(
child
.
textContent
);
break
;
case
'
v
'
:
data
.
v
=
parseInts
(
child
.
textContent
);
break
;
}
}
return
data
;
}
// image
function
parseImage
(
xml
)
{
...
...
@@ -601,7 +863,7 @@ THREE.ColladaLoader.prototype = {
}
console
.
error
(
'
ColladaLoader: Undefined sampler
'
,
textureObject
.
id
);
console
.
error
(
'
THREE.
ColladaLoader: Undefined sampler
'
,
textureObject
.
id
);
return
null
;
...
...
@@ -955,7 +1217,7 @@ THREE.ColladaLoader.prototype = {
switch
(
child
.
nodeName
)
{
case
'
source
'
:
data
.
sources
[
id
]
=
parse
Geometry
Source
(
child
);
data
.
sources
[
id
]
=
parseSource
(
child
);
break
;
case
'
vertices
'
:
...
...
@@ -964,7 +1226,7 @@ THREE.ColladaLoader.prototype = {
break
;
case
'
polygons
'
:
console
.
warn
(
'
ColladaLoader: Unsupported primitive type:
'
,
child
.
nodeName
);
console
.
warn
(
'
THREE.
ColladaLoader: Unsupported primitive type:
'
,
child
.
nodeName
);
break
;
case
'
lines
'
:
...
...
@@ -985,7 +1247,7 @@ THREE.ColladaLoader.prototype = {
}
function
parse
Geometry
Source
(
xml
)
{
function
parseSource
(
xml
)
{
var
data
=
{
array
:
[],
...
...
@@ -1227,7 +1489,7 @@ THREE.ColladaLoader.prototype = {
if
(
maxcount
>
0
)
{
console
.
log
(
'
ColladaLoader: Geometry has faces with more than 4 vertices.
'
);
console
.
log
(
'
THREE.
ColladaLoader: Geometry has faces with more than 4 vertices.
'
);
}
...
...
@@ -1521,7 +1783,7 @@ THREE.ColladaLoader.prototype = {
}
console
.
time
(
'
ColladaLoader
'
);
console
.
time
(
'
THREE.
ColladaLoader
'
);
if
(
text
.
length
===
0
)
{
...
...
@@ -1529,18 +1791,18 @@ THREE.ColladaLoader.prototype = {
}
console
.
time
(
'
ColladaLoader: DOMParser
'
);
console
.
time
(
'
THREE.
ColladaLoader: DOMParser
'
);
var
xml
=
new
DOMParser
().
parseFromString
(
text
,
'
application/xml
'
);
console
.
timeEnd
(
'
ColladaLoader: DOMParser
'
);
console
.
timeEnd
(
'
THREE.
ColladaLoader: DOMParser
'
);
var
collada
=
getElementsByTagName
(
xml
,
'
COLLADA
'
)[
0
];
// metadata
var
version
=
collada
.
getAttribute
(
'
version
'
);
console
.
log
(
'
ColladaLoader: File version
'
,
version
);
console
.
log
(
'
THREE.
ColladaLoader: File version
'
,
version
);
var
asset
=
parseAsset
(
getElementsByTagName
(
collada
,
'
asset
'
)[
0
]
);
var
textureLoader
=
new
THREE
.
TextureLoader
(
this
.
manager
).
setPath
(
resourceDirectory
);
...
...
@@ -1548,6 +1810,8 @@ THREE.ColladaLoader.prototype = {
//
var
library
=
{
animations
:
{},
controllers
:
{},
images
:
{},
effects
:
{},
materials
:
{},
...
...
@@ -1558,8 +1822,10 @@ THREE.ColladaLoader.prototype = {
visualScenes
:
{}
};
console
.
time
(
'
ColladaLoader: Parse
'
);
console
.
time
(
'
THREE.
ColladaLoader: Parse
'
);
// parseLibrary( collada, 'library_animations', 'animation', parseAnimation );
// parseLibrary( collada, 'library_controllers', 'controller', parseController );
parseLibrary
(
collada
,
'
library_images
'
,
'
image
'
,
parseImage
);
parseLibrary
(
collada
,
'
library_effects
'
,
'
effect
'
,
parseEffect
);
parseLibrary
(
collada
,
'
library_materials
'
,
'
material
'
,
parseMaterial
);
...
...
@@ -1569,9 +1835,9 @@ THREE.ColladaLoader.prototype = {
parseLibrary
(
collada
,
'
library_nodes
'
,
'
node
'
,
parseNode
);
parseLibrary
(
collada
,
'
library_visual_scenes
'
,
'
visual_scene
'
,
parseVisualScene
);
console
.
timeEnd
(
'
ColladaLoader: Parse
'
);
console
.
timeEnd
(
'
THREE.
ColladaLoader: Parse
'
);
console
.
time
(
'
ColladaLoader: Build
'
);
console
.
time
(
'
THREE.
ColladaLoader: Build
'
);
buildLibrary
(
library
.
images
,
buildImage
);
buildLibrary
(
library
.
effects
,
buildEffect
);
...
...
@@ -1582,7 +1848,7 @@ THREE.ColladaLoader.prototype = {
// buildLibrary( library.nodes, buildNode );
buildLibrary
(
library
.
visualScenes
,
buildVisualScene
);
console
.
timeEnd
(
'
ColladaLoader: Build
'
);
console
.
timeEnd
(
'
THREE.
ColladaLoader: Build
'
);
// console.log( library );
...
...
@@ -1596,7 +1862,7 @@ THREE.ColladaLoader.prototype = {
scene
.
scale
.
multiplyScalar
(
asset
.
unit
);
console
.
timeEnd
(
'
ColladaLoader
'
);
console
.
timeEnd
(
'
THREE.
ColladaLoader
'
);
// console.log( scene );
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录