Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
cd1f9ec1
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,发现更多精彩内容 >>
提交
cd1f9ec1
编写于
6月 07, 2017
作者:
M
Mr.doob
提交者:
GitHub
6月 07, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11461 from Mugen87/dev
ColladaLoader2: Added skinWeights and skinIndices
上级
ff2ce565
b689e158
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
108 addition
and
5 deletion
+108
-5
examples/js/loaders/ColladaLoader2.js
examples/js/loaders/ColladaLoader2.js
+108
-5
未找到文件。
examples/js/loaders/ColladaLoader2.js
浏览文件 @
cd1f9ec1
...
...
@@ -323,8 +323,9 @@ THREE.ColladaLoader.prototype = {
switch
(
child
.
nodeName
)
{
case
'
skin
'
:
var
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
data
.
skin
[
id
]
=
parseSkin
(
child
);
// there is exactly one skin per controller
data
.
skin
.
id
=
parseId
(
child
.
getAttribute
(
'
source
'
)
);
data
.
skin
.
data
=
parseSkin
(
child
);
break
;
}
...
...
@@ -441,11 +442,106 @@ THREE.ColladaLoader.prototype = {
function
buildController
(
data
)
{
// for now, we only return the id of the skin in order to get the corresponding geometry
var
build
=
{};
build
.
id
=
data
.
skin
.
id
;
build
.
sources
=
buildSkin
(
data
.
skin
.
data
);
var
keys
=
Object
.
keys
(
data
.
skin
);
// we enhance the 'sources' property of the corresponding geometry with our skin data
return
{
id
:
keys
[
0
]
};
var
geometry
=
library
.
geometries
[
build
.
id
];
geometry
.
sources
.
skinIndices
=
build
.
sources
.
skinIndices
;
geometry
.
sources
.
skinWeights
=
build
.
sources
.
skinWeights
;
return
build
;
}
function
buildSkin
(
data
)
{
var
BONE_LIMIT
=
4
;
var
build
=
{
skinIndices
:
{
array
:
[],
stride
:
BONE_LIMIT
},
skinWeights
:
{
array
:
[],
stride
:
BONE_LIMIT
}
};
var
sources
=
data
.
sources
;
var
vertexWeights
=
data
.
vertexWeights
;
var
vcount
=
vertexWeights
.
vcount
;
var
v
=
vertexWeights
.
v
;
var
jointOffset
=
vertexWeights
.
inputs
.
JOINT
.
offset
;
var
weightOffset
=
vertexWeights
.
inputs
.
WEIGHT
.
offset
;
var
weights
=
sources
[
vertexWeights
.
inputs
.
WEIGHT
.
id
].
array
;
var
stride
=
0
;
var
skinIndices
=
[];
var
skinWeights
=
[];
// procces skin data for each vertex
for
(
var
i
=
0
,
l
=
vcount
.
length
;
i
<
l
;
i
++
)
{
var
jointCount
=
vcount
[
i
];
// this is the amount of joints that affect a single vertex
var
vertexSkinData
=
[];
for
(
var
j
=
0
;
j
<
jointCount
;
j
++
)
{
var
skinIndex
=
v
[
stride
+
jointOffset
];
var
weightId
=
v
[
stride
+
weightOffset
];
var
skinWeight
=
weights
[
weightId
];
vertexSkinData
.
push
(
{
index
:
skinIndex
,
weight
:
skinWeight
}
);
stride
+=
2
;
}
// we sort the joints in descending order based on the weights.
// this ensures, we only procced the most important joints of the vertex
vertexSkinData
.
sort
(
descending
);
// now we provide for each vertex a set of four index and weight values.
// the order of the skin data matches the order of vertices
for
(
var
j
=
0
;
j
<
BONE_LIMIT
;
j
++
)
{
var
d
=
vertexSkinData
[
j
];
if
(
d
!==
undefined
)
{
build
.
skinIndices
.
array
.
push
(
d
.
index
);
build
.
skinWeights
.
array
.
push
(
d
.
weight
);
}
else
{
build
.
skinIndices
.
array
.
push
(
0
);
build
.
skinWeights
.
array
.
push
(
0
);
}
}
}
return
build
;
// array sort function
function
descending
(
a
,
b
)
{
return
b
.
weight
-
a
.
weight
;
}
}
...
...
@@ -1393,6 +1489,13 @@ THREE.ColladaLoader.prototype = {
geometry
.
addAttribute
(
key
.
toLowerCase
(),
buildGeometryAttribute
(
primitive
,
sources
[
vertices
[
key
]
],
input
.
offset
)
);
if
(
key
.
toLowerCase
()
===
'
position
'
&&
sources
.
skinWeights
&&
sources
.
skinIndices
)
{
geometry
.
addAttribute
(
'
skinWeight
'
,
buildGeometryAttribute
(
primitive
,
sources
.
skinWeights
,
input
.
offset
)
);
geometry
.
addAttribute
(
'
skinIndex
'
,
buildGeometryAttribute
(
primitive
,
sources
.
skinIndices
,
input
.
offset
)
);
}
}
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录