Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
28f37d71
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,发现更多精彩内容 >>
提交
28f37d71
编写于
1月 26, 2017
作者:
K
Kyle Larson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed "ForEach" usage for all arrays.
上级
0225f7ff
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
42 deletion
+80
-42
examples/js/loaders/FBXLoader2.js
examples/js/loaders/FBXLoader2.js
+80
-42
未找到文件。
examples/js/loaders/FBXLoader2.js
浏览文件 @
28f37d71
...
...
@@ -163,7 +163,9 @@
* @type {[number, number, string][]}
*/
var
connectionArray
=
FBXTree
.
Connections
.
properties
.
connections
;
connectionArray
.
forEach
(
function
(
connection
)
{
for
(
var
connectionArrayIndex
=
0
,
connectionArrayLength
=
connectionArray
.
length
;
connectionArrayIndex
<
connectionArrayLength
;
++
connectionArrayIndex
)
{
var
connection
=
connectionArray
[
connectionArrayIndex
];
if
(
!
connectionMap
.
has
(
connection
[
0
]
)
)
{
...
...
@@ -189,7 +191,7 @@
var
childRelationship
=
{
ID
:
connection
[
0
],
relationship
:
connection
[
2
]
};
connectionMap
.
get
(
connection
[
1
]
).
children
.
push
(
childRelationship
);
}
);
}
}
...
...
@@ -370,7 +372,9 @@
}
childrenRelationships
.
forEach
(
function
(
relationship
)
{
for
(
var
childrenRelationshipsIndex
=
0
,
childrenRelationshipsLength
=
childrenRelationships
.
length
;
childrenRelationshipsIndex
<
childrenRelationshipsLength
;
++
childrenRelationshipsIndex
)
{
var
relationship
=
childrenRelationships
[
childrenRelationshipsIndex
];
var
type
=
relationship
.
relationship
;
switch
(
type
)
{
...
...
@@ -389,7 +393,7 @@
}
}
);
}
return
parameters
;
...
...
@@ -440,7 +444,9 @@
var
subDeformers
=
new
Map
();
var
subDeformerArray
=
[];
connections
.
children
.
forEach
(
function
(
child
)
{
for
(
var
childrenIndex
=
0
,
childrenLength
=
connections
.
children
.
length
;
childrenIndex
<
childrenLength
;
++
childrenIndex
)
{
var
child
=
connections
.
children
[
childrenIndex
];
var
subDeformerNode
=
DeformerNodes
[
child
.
ID
];
var
subDeformer
=
{
...
...
@@ -454,7 +460,7 @@
subDeformers
.
set
(
child
.
ID
,
subDeformer
);
subDeformerArray
.
push
(
subDeformer
);
}
);
}
return
{
map
:
subDeformers
,
...
...
@@ -812,11 +818,11 @@
// we expect. So we create an intermediate buffer that points to the index in the buffer,
// for conforming with the other functions we've written for other data.
var
materialIndices
=
[];
materialIndexBuffer
.
forEach
(
function
(
materialIndex
,
i
ndex
)
{
for
(
var
materialIndexBufferIndex
=
0
,
materialIndexBufferLength
=
materialIndexBuffer
.
length
;
materialIndexBufferIndex
<
materialIndexBufferLength
;
++
materialIndexBufferI
ndex
)
{
materialIndices
.
push
(
i
ndex
);
materialIndices
.
push
(
materialIndexBufferI
ndex
);
}
);
}
return
{
dataSize
:
1
,
...
...
@@ -978,12 +984,14 @@
var
vertices
=
curve
.
getPoints
(
controlPoints
.
length
*
1.5
);
var
vertexBuffer
=
[];
vertices
.
forEach
(
function
(
position
)
{
for
(
var
verticesIndex
=
0
,
verticesLength
=
vertices
.
length
;
verticesIndex
<
verticesLength
;
++
verticesIndex
)
{
var
position
=
vertices
[
verticesIndex
];
var
array
=
position
.
toArray
();
vertexBuffer
=
vertexBuffer
.
concat
(
array
);
}
);
}
var
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
vertexBuffer
),
3
)
);
...
...
@@ -1066,7 +1074,9 @@
*/
var
materials
=
[];
conns
.
children
.
forEach
(
function
(
child
)
{
for
(
var
childrenIndex
=
0
,
childrenLength
=
conns
.
children
.
length
;
childrenIndex
<
childrenLength
;
++
childrenIndex
)
{
var
child
=
conns
.
children
[
childrenIndex
];
if
(
geometryMap
.
has
(
child
.
ID
)
)
{
...
...
@@ -1080,7 +1090,7 @@
}
}
);
}
if
(
materials
.
length
>
1
)
{
material
=
new
THREE
.
MultiMaterial
(
materials
);
...
...
@@ -1096,11 +1106,13 @@
}
if
(
geometry
.
FBX_Deformer
)
{
materials
.
forEach
(
function
(
material
)
{
for
(
var
materialsIndex
=
0
,
materialsLength
=
materials
.
length
;
materialsIndex
<
materialsLength
;
++
materialsIndex
)
{
var
material
=
materials
[
materialsIndex
];
material
.
skinning
=
true
;
}
);
}
material
.
skinning
=
true
;
model
=
new
THREE
.
SkinnedMesh
(
geometry
,
material
);
...
...
@@ -1114,7 +1126,9 @@
case
"
NurbsCurve
"
:
var
geometry
=
null
;
conns
.
children
.
forEach
(
function
(
child
)
{
for
(
var
childrenIndex
=
0
,
childrenLength
=
conns
.
children
.
length
;
childrenIndex
<
childrenLength
;
++
childrenIndex
)
{
var
child
=
conns
.
children
[
childrenIndex
];
if
(
geometryMap
.
has
(
child
.
ID
)
)
{
...
...
@@ -1122,7 +1136,7 @@
}
}
);
}
// FBX does not list materials for Nurbs lines, so we'll just put our own in here.
material
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0x3300ff
,
linewidth
:
5
}
);
...
...
@@ -1145,7 +1159,9 @@
}
modelArray
.
forEach
(
function
(
model
)
{
for
(
var
modelArrayIndex
=
0
,
modelArrayLength
=
modelArray
.
length
;
modelArrayIndex
<
modelArrayLength
;
++
modelArrayIndex
)
{
var
model
=
modelArray
[
modelArrayIndex
];
var
node
=
ModelNode
[
model
.
FBX_ID
];
...
...
@@ -1195,7 +1211,7 @@
}
}
);
}
// Now with the bones created, we can update the skeletons and bind them to the skinned meshes.
...
...
@@ -1218,19 +1234,24 @@
var
PoseNode
=
BindPoseNode
.
subNodes
.
PoseNode
;
var
worldMatrices
=
new
Map
();
PoseNode
.
forEach
(
function
(
node
)
{
for
(
var
PoseNodeIndex
=
0
,
PoseNodeLength
=
PoseNode
.
length
;
PoseNodeIndex
<
PoseNodeLength
;
++
PoseNodeIndex
)
{
var
node
=
PoseNode
[
PoseNodeIndex
];
var
rawMatWrd
=
parseMatrixArray
(
node
.
subNodes
.
Matrix
.
properties
.
a
);
worldMatrices
.
set
(
parseInt
(
node
.
id
),
rawMatWrd
);
}
);
}
}
deformerMap
.
forEach
(
function
(
deformer
,
FBX_ID
)
{
deformer
.
array
.
forEach
(
function
(
subDeformer
,
subDeformerIndex
)
{
for
(
var
deformerArrayIndex
=
0
,
deformerArrayLength
=
deformer
.
array
.
length
;
deformerArrayIndex
<
deformerArrayLength
;
++
deformerArrayIndex
)
{
//var subDeformer = deformer.array[ deformerArrayIndex ];
var
subDeformerIndex
=
deformerArrayIndex
;
/**
* @type {THREE.Bone}
...
...
@@ -1238,18 +1259,20 @@
var
bone
=
deformer
.
bones
[
subDeformerIndex
];
if
(
!
worldMatrices
.
has
(
bone
.
FBX_ID
)
)
{
return
;
break
;
}
var
mat
=
worldMatrices
.
get
(
bone
.
FBX_ID
);
bone
.
matrixWorld
.
copy
(
mat
);
}
);
}
// Now that skeleton is in bind pose, bind to model.
deformer
.
skeleton
=
new
THREE
.
Skeleton
(
deformer
.
bones
);
var
conns
=
connections
.
get
(
FBX_ID
);
conns
.
parents
.
forEach
(
function
(
parent
)
{
for
(
var
parentsIndex
=
0
,
parentsLength
=
conns
.
parents
.
length
;
parentsIndex
<
parentsLength
;
++
parentsIndex
)
{
var
parent
=
conns
.
parents
[
parentsIndex
];
if
(
geometryMap
.
has
(
parent
.
ID
)
)
{
...
...
@@ -1270,13 +1293,15 @@
}
}
);
}
}
);
// Skeleton is now bound, we are now free to set up the
// scene graph.
modelArray
.
forEach
(
function
(
model
)
{
for
(
var
modelArrayIndex
=
0
,
modelArrayLength
=
modelArray
.
length
;
modelArrayIndex
<
modelArrayLength
;
++
modelArrayIndex
)
{
var
model
=
modelArray
[
modelArrayIndex
];
var
node
=
ModelNode
[
model
.
FBX_ID
];
...
...
@@ -1304,7 +1329,7 @@
}
}
);
}
// Silly hack with the animation parsing. We're gonna pretend the scene graph has a skeleton
// to attach animations to, since FBXs treat animations as animations for the entire scene,
...
...
@@ -2013,7 +2038,9 @@
var
currentLayer
=
returnObject
.
layers
.
get
(
children
[
childIndex
].
ID
);
layers
.
push
(
currentLayer
);
currentLayer
.
forEach
(
function
(
layer
)
{
for
(
var
currentLayerIndex
=
0
,
currentLayerLength
=
currentLayer
.
length
;
currentLayerIndex
<
currentLayerLength
;
++
currentLayerIndex
)
{
var
layer
=
currentLayer
[
currentLayerIndex
];
if
(
layer
)
{
...
...
@@ -2228,7 +2255,7 @@
}
}
);
}
}
...
...
@@ -2771,7 +2798,9 @@
var
bones
=
group
.
skeleton
.
bones
;
bones
.
forEach
(
function
(
bone
)
{
for
(
var
bonesIndex
=
0
,
bonesLength
=
bones
.
length
;
bonesIndex
<
bonesLength
;
++
bonesIndex
)
{
var
bone
=
bones
[
bonesIndex
];
var
name
=
bone
.
name
.
replace
(
/.*:/
,
''
);
var
parentIndex
=
bones
.
findIndex
(
function
(
parentBone
)
{
...
...
@@ -2781,15 +2810,20 @@
}
);
animationData
.
hierarchy
.
push
(
{
parent
:
parentIndex
,
name
:
name
,
keys
:
[]
}
);
}
);
}
for
(
var
frame
=
0
;
frame
<
stack
.
frames
;
frame
++
)
{
bones
.
forEach
(
function
(
bone
,
boneIndex
)
{
for
(
var
bonesIndex
=
0
,
bonesLength
=
bones
.
length
;
bonesIndex
<
bonesLength
;
++
bonesIndex
)
{
var
bone
=
bones
[
bonesIndex
];
var
boneIndex
=
bonesIndex
;
var
animationNode
=
stack
.
layers
[
0
][
boneIndex
];
animationData
.
hierarchy
.
forEach
(
function
(
node
)
{
for
(
var
hierarchyIndex
=
0
,
hierarchyLength
=
animationData
.
hierarchy
.
length
;
hierarchyIndex
<
hierarchyLength
;
++
hierarchyIndex
)
{
var
node
=
animationData
.
hierarchy
[
hierarchyIndex
];
if
(
node
.
name
===
bone
.
name
)
{
...
...
@@ -2797,9 +2831,9 @@
}
}
);
}
}
);
}
}
...
...
@@ -3042,7 +3076,9 @@
var
skinIndexBuffer
=
[];
var
skinWeightBuffer
=
[];
this
.
vertices
.
forEach
(
function
(
vertex
)
{
for
(
var
verticesIndex
=
0
,
verticesLength
=
this
.
vertices
.
length
;
verticesIndex
<
verticesLength
;
++
verticesIndex
)
{
var
vertex
=
this
.
vertices
[
verticesIndex
];
var
flatVertex
=
vertex
.
flattenToBuffers
();
vertexBuffer
=
vertexBuffer
.
concat
(
flatVertex
.
vertexBuffer
);
...
...
@@ -3051,7 +3087,7 @@
skinIndexBuffer
=
skinIndexBuffer
.
concat
(
flatVertex
.
skinIndexBuffer
);
skinWeightBuffer
=
skinWeightBuffer
.
concat
(
flatVertex
.
skinWeightBuffer
);
}
);
}
return
{
vertexBuffer
:
vertexBuffer
,
...
...
@@ -3122,8 +3158,9 @@
var
materialIndex
=
this
.
materialIndex
;
this
.
triangles
.
forEach
(
function
(
triangle
)
{
for
(
var
triangleIndex
=
0
,
triangleLength
=
this
.
triangles
.
length
;
triangleIndex
<
triangleLength
;
++
triangleIndex
)
{
var
triangle
=
this
.
triangles
[
triangleIndex
];
var
flatTriangle
=
triangle
.
flattenToBuffers
();
vertexBuffer
=
vertexBuffer
.
concat
(
flatTriangle
.
vertexBuffer
);
normalBuffer
=
normalBuffer
.
concat
(
flatTriangle
.
normalBuffer
);
...
...
@@ -3132,7 +3169,7 @@
skinWeightBuffer
=
skinWeightBuffer
.
concat
(
flatTriangle
.
skinWeightBuffer
);
materialIndexBuffer
=
materialIndexBuffer
.
concat
(
[
materialIndex
,
materialIndex
,
materialIndex
]
);
}
);
}
return
{
vertexBuffer
:
vertexBuffer
,
...
...
@@ -3179,8 +3216,9 @@
var
materialIndexBuffer
=
[];
this
.
faces
.
forEach
(
function
(
face
)
{
for
(
var
faceIndex
=
0
,
faceLength
=
this
.
faces
.
length
;
faceIndex
<
faceLength
;
++
faceIndex
)
{
var
face
=
this
.
faces
[
faceIndex
];
var
flatFace
=
face
.
flattenToBuffers
();
vertexBuffer
=
vertexBuffer
.
concat
(
flatFace
.
vertexBuffer
);
normalBuffer
=
normalBuffer
.
concat
(
flatFace
.
normalBuffer
);
...
...
@@ -3189,7 +3227,7 @@
skinWeightBuffer
=
skinWeightBuffer
.
concat
(
flatFace
.
skinWeightBuffer
);
materialIndexBuffer
=
materialIndexBuffer
.
concat
(
flatFace
.
materialIndexBuffer
);
}
);
}
return
{
vertexBuffer
:
vertexBuffer
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录