Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
6db8a5dd
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,发现更多精彩内容 >>
提交
6db8a5dd
编写于
1月 10, 2017
作者:
M
Mr.doob
提交者:
GitHub
1月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10536 from takahirox/UpdateGLTFLoader
Update gltf loader
上级
87a8f52f
9ae8b3d4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
243 addition
and
39 deletion
+243
-39
examples/js/loaders/GLTFLoader.js
examples/js/loaders/GLTFLoader.js
+243
-39
未找到文件。
examples/js/loaders/GLTFLoader.js
浏览文件 @
6db8a5dd
...
...
@@ -2,6 +2,7 @@
* @author Rich Tibbett / https://github.com/richtr
* @author mrdoob / http://mrdoob.com/
* @author Tony Parisi / http://www.tonyparisi.com/
* @author Takahiro / https://github.com/takahirox
*/
THREE
.
GLTFLoader
=
(
function
()
{
...
...
@@ -315,6 +316,48 @@ THREE.GLTFLoader = ( function () {
10497
:
THREE
.
RepeatWrapping
};
var
WEBGL_SIDES
=
{
1028
:
THREE
.
BackSide
,
// Culling front
1029
:
THREE
.
FrontSide
// Culling back
//1032: THREE.NoSide // Culling front and back, what to do?
};
var
WEBGL_DEPTH_FUNCS
=
{
512
:
THREE
.
NeverDepth
,
513
:
THREE
.
LessDepth
,
514
:
THREE
.
EqualDepth
,
515
:
THREE
.
LessEqualDepth
,
516
:
THREE
.
GreaterEqualDepth
,
517
:
THREE
.
NotEqualDepth
,
518
:
THREE
.
GreaterEqualDepth
,
519
:
THREE
.
AlwaysDepth
};
var
WEBGL_BLEND_EQUATIONS
=
{
32774
:
THREE
.
AddEquation
,
32778
:
THREE
.
SubtractEquation
,
32779
:
THREE
.
ReverseSubtractEquation
};
var
WEBGL_BLEND_FUNCS
=
{
0
:
THREE
.
ZeroFactor
,
1
:
THREE
.
OneFactor
,
768
:
THREE
.
SrcColorFactor
,
769
:
THREE
.
OneMinusSrcColorFactor
,
770
:
THREE
.
SrcAlphaFactor
,
771
:
THREE
.
OneMinusSrcAlphaFactor
,
772
:
THREE
.
DstAlphaFactor
,
773
:
THREE
.
OneMinusDstAlphaFactor
,
774
:
THREE
.
DstColorFactor
,
775
:
THREE
.
OneMinusDstColorFactor
,
776
:
THREE
.
SrcAlphaSaturateFactor
// The followings are not supported by Three.js yet
//32769: CONSTANT_COLOR,
//32770: ONE_MINUS_CONSTANT_COLOR,
//32771: CONSTANT_ALPHA,
//32772: ONE_MINUS_CONSTANT_COLOR
};
var
WEBGL_TYPE_SIZES
=
{
'
SCALAR
'
:
1
,
'
VEC2
'
:
2
,
...
...
@@ -336,6 +379,15 @@ THREE.GLTFLoader = ( function () {
STEP
:
THREE
.
InterpolateDiscrete
};
var
STATES_ENABLES
=
{
2884
:
'
CULL_FACE
'
,
2929
:
'
DEPTH_TEST
'
,
3042
:
'
BLEND
'
,
3089
:
'
SCISSOR_TEST
'
,
32823
:
'
POLYGON_OFFSET_FILL
'
,
32926
:
'
SAMPLE_ALPHA_TO_COVERAGE
'
};
/* UTILITY FUNCTIONS */
function
_each
(
object
,
callback
,
thisObj
)
{
...
...
@@ -504,6 +556,20 @@ THREE.GLTFLoader = ( function () {
}
function
createDefaultMaterial
()
{
return
new
THREE
.
MeshPhongMaterial
(
{
color
:
0x00000
,
emissive
:
0x888888
,
specular
:
0x000000
,
shininess
:
0
,
transparent
:
false
,
depthTest
:
true
,
side
:
THREE
.
FrontSide
}
);
};
// Deferred constructor for RawShaderMaterial types
function
DeferredShaderMaterial
(
params
)
{
...
...
@@ -644,7 +710,7 @@ THREE.GLTFLoader = ( function () {
return
new
Promise
(
function
(
resolve
)
{
var
loader
=
new
THREE
.
FileLoader
();
loader
.
responseType
=
'
text
'
;
loader
.
setResponseType
(
'
text
'
)
;
loader
.
load
(
resolveURL
(
shader
.
uri
,
options
.
path
),
function
(
shaderText
)
{
resolve
(
shaderText
);
...
...
@@ -664,12 +730,12 @@ THREE.GLTFLoader = ( function () {
return
_each
(
json
.
buffers
,
function
(
buffer
)
{
if
(
buffer
.
type
===
'
arraybuffer
'
)
{
if
(
buffer
.
type
===
'
arraybuffer
'
||
buffer
.
type
===
undefined
)
{
return
new
Promise
(
function
(
resolve
)
{
var
loader
=
new
THREE
.
FileLoader
();
loader
.
responseType
=
'
arraybuffer
'
;
loader
.
setResponseType
(
'
arraybuffer
'
)
;
loader
.
load
(
resolveURL
(
buffer
.
uri
,
options
.
path
),
function
(
buffer
)
{
resolve
(
buffer
);
...
...
@@ -678,6 +744,10 @@ THREE.GLTFLoader = ( function () {
}
);
}
else
{
console
.
warn
(
'
THREE.GLTFLoader:
'
+
buffer
.
type
+
'
buffer type is not supported
'
);
}
}
);
...
...
@@ -920,7 +990,9 @@ THREE.GLTFLoader = ( function () {
if
(
WEBGL_TYPE
[
ptype
]
)
{
var
pcount
=
shaderParam
.
count
;
var
value
=
material
.
values
[
pname
];
var
value
;
if
(
material
.
values
!==
undefined
)
value
=
material
.
values
[
pname
];
var
uvalue
=
new
WEBGL_TYPE
[
ptype
]();
var
usemantic
=
shaderParam
.
semantic
;
...
...
@@ -1017,7 +1089,19 @@ THREE.GLTFLoader = ( function () {
case
WEBGL_CONSTANTS
.
SAMPLER_2D
:
uvalue
=
value
?
dependencies
.
textures
[
value
]
:
null
;
if
(
value
!==
undefined
)
{
uvalue
=
dependencies
.
textures
[
value
];
}
else
if
(
shaderParam
.
value
!==
undefined
)
{
uvalue
=
dependencies
.
textures
[
shaderParam
.
value
];
}
else
{
uvalue
=
null
;
}
break
;
...
...
@@ -1037,6 +1121,102 @@ THREE.GLTFLoader = ( function () {
}
var
states
=
technique
.
states
||
{};
var
enables
=
states
.
enable
||
[];
var
functions
=
states
.
functions
||
{};
var
enableCullFace
=
false
;
var
enableDepthTest
=
false
;
var
enableBlend
=
false
;
for
(
var
i
=
0
,
il
=
enables
.
length
;
i
<
il
;
i
++
)
{
var
enable
=
enables
[
i
];
switch
(
STATES_ENABLES
[
enable
]
)
{
case
'
CULL_FACE
'
:
enableCullFace
=
true
;
break
;
case
'
DEPTH_TEST
'
:
enableDepthTest
=
true
;
break
;
case
'
BLEND
'
:
enableBlend
=
true
;
break
;
// TODO: implement
case
'
SCISSOR_TEST
'
:
case
'
POLYGON_OFFSET_FILL
'
:
case
'
SAMPLE_ALPHA_TO_COVERAGE
'
:
break
;
default
:
throw
new
Error
(
"
Unknown technique.states.enable:
"
+
enable
);
}
}
if
(
enableCullFace
)
{
materialParams
.
side
=
functions
.
cullFace
!==
undefined
?
WEBGL_SIDES
[
functions
.
cullFace
]
:
THREE
.
FrontSide
;
}
else
{
materialParams
.
side
=
THREE
.
DoubleSide
;
}
materialParams
.
depthTest
=
enableDepthTest
;
materialParams
.
depthFunc
=
functions
.
depthFunc
!==
undefined
?
WEBGL_DEPTH_FUNCS
[
functions
.
depthFunc
]
:
THREE
.
LessDepth
;
materialParams
.
depthWrite
=
functions
.
depthMask
!==
undefined
?
functions
.
depthMask
[
0
]
:
true
;
materialParams
.
blending
=
enableBlend
?
THREE
.
CustomBlending
:
THREE
.
NoBlending
;
materialParams
.
transparent
=
enableBlend
;
var
blendEquationSeparate
=
functions
.
blendEquationSeparate
;
if
(
blendEquationSeparate
!==
undefined
)
{
materialParams
.
blendEquation
=
WEBGL_BLEND_EQUATIONS
[
blendEquationSeparate
[
0
]
];
materialParams
.
blendEquationAlpha
=
WEBGL_BLEND_EQUATIONS
[
blendEquationSeparate
[
1
]
];
}
else
{
materialParams
.
blendEquation
=
THREE
.
AddEquation
;
materialParams
.
blendEquationAlpha
=
THREE
.
AddEquation
;
}
var
blendFuncSeparate
=
functions
.
blendFuncSeparate
;
if
(
blendFuncSeparate
!==
undefined
)
{
materialParams
.
blendSrc
=
WEBGL_BLEND_FUNCS
[
blendFuncSeparate
[
0
]
];
materialParams
.
blendDst
=
WEBGL_BLEND_FUNCS
[
blendFuncSeparate
[
1
]
];
materialParams
.
blendSrcAlpha
=
WEBGL_BLEND_FUNCS
[
blendFuncSeparate
[
2
]
];
materialParams
.
blendDstAlpha
=
WEBGL_BLEND_FUNCS
[
blendFuncSeparate
[
3
]
];
}
else
{
materialParams
.
blendSrc
=
THREE
.
OneFactor
;
materialParams
.
blendDst
=
THREE
.
ZeroFactor
;
materialParams
.
blendSrcAlpha
=
THREE
.
OneFactor
;
materialParams
.
blendDstAlpha
=
THREE
.
ZeroFactor
;
}
}
}
...
...
@@ -1108,7 +1288,7 @@ THREE.GLTFLoader = ( function () {
}
var
_material
=
new
materialType
(
materialParams
);
_material
.
name
=
material
.
name
;
if
(
material
.
name
!==
undefined
)
_material
.
name
=
material
.
name
;
return
_material
;
...
...
@@ -1132,7 +1312,7 @@ THREE.GLTFLoader = ( function () {
return
_each
(
json
.
meshes
,
function
(
mesh
)
{
var
group
=
new
THREE
.
Object3D
();
group
.
name
=
mesh
.
name
;
if
(
mesh
.
name
!==
undefined
)
group
.
name
=
mesh
.
name
;
if
(
mesh
.
extras
)
group
.
userData
=
mesh
.
extras
;
...
...
@@ -1190,7 +1370,7 @@ THREE.GLTFLoader = ( function () {
}
var
material
=
dependencies
.
materials
[
primitive
.
material
]
;
var
material
=
dependencies
.
materials
!==
undefined
?
dependencies
.
materials
[
primitive
.
material
]
:
createDefaultMaterial
()
;
var
meshNode
=
new
THREE
.
Mesh
(
geometry
,
material
);
meshNode
.
castShadow
=
true
;
...
...
@@ -1282,7 +1462,7 @@ THREE.GLTFLoader = ( function () {
// yfov = ( yfov === undefined && xfov ) ? xfov / aspect_ratio : yfov;
var
_camera
=
new
THREE
.
PerspectiveCamera
(
THREE
.
Math
.
radToDeg
(
xfov
),
aspect_ratio
,
camera
.
perspective
.
znear
||
1
,
camera
.
perspective
.
zfar
||
2
e6
);
_camera
.
name
=
camera
.
name
;
if
(
camera
.
name
!==
undefined
)
_camera
.
name
=
camera
.
name
;
if
(
camera
.
extras
)
_camera
.
userData
=
camera
.
extras
;
...
...
@@ -1291,7 +1471,7 @@ THREE.GLTFLoader = ( function () {
}
else
if
(
camera
.
type
==
"
orthographic
"
&&
camera
.
orthographic
)
{
var
_camera
=
new
THREE
.
OrthographicCamera
(
window
.
innerWidth
/
-
2
,
window
.
innerWidth
/
2
,
window
.
innerHeight
/
2
,
window
.
innerHeight
/
-
2
,
camera
.
orthographic
.
znear
,
camera
.
orthographic
.
zfar
);
_camera
.
name
=
camera
.
name
;
if
(
camera
.
name
!==
undefined
)
_camera
.
name
=
camera
.
name
;
if
(
camera
.
extras
)
_camera
.
userData
=
camera
.
extras
;
...
...
@@ -1349,12 +1529,12 @@ THREE.GLTFLoader = ( function () {
var
channel
=
animation
.
channels
[
channelId
];
var
sampler
=
animation
.
samplers
[
channel
.
sampler
];
if
(
sampler
&&
animation
.
parameters
)
{
if
(
sampler
)
{
var
target
=
channel
.
target
;
var
name
=
target
.
id
;
var
input
=
animation
.
parameters
[
sampler
.
input
]
;
var
output
=
animation
.
parameters
[
sampler
.
output
]
;
var
input
=
animation
.
parameters
!==
undefined
?
animation
.
parameters
[
sampler
.
input
]
:
sampler
.
input
;
var
output
=
animation
.
parameters
!==
undefined
?
animation
.
parameters
[
sampler
.
output
]
:
sampler
.
output
;
var
inputAccessor
=
dependencies
.
accessors
[
input
];
var
outputAccessor
=
dependencies
.
accessors
[
output
];
...
...
@@ -1370,11 +1550,13 @@ THREE.GLTFLoader = ( function () {
?
THREE
.
QuaternionKeyframeTrack
:
THREE
.
VectorKeyframeTrack
;
var
targetName
=
node
.
name
?
node
.
name
:
node
.
uuid
;
// KeyframeTrack.optimize() will modify given 'times' and 'values'
// buffers before creating a truncated copy to keep. Because buffers may
// be reused by other tracks, make copies here.
tracks
.
push
(
new
TypedKeyframeTrack
(
node
.
n
ame
+
'
.
'
+
PATH_PROPERTIES
[
target
.
path
],
targetN
ame
+
'
.
'
+
PATH_PROPERTIES
[
target
.
path
],
THREE
.
AnimationUtils
.
arraySlice
(
inputAccessor
.
array
,
0
),
THREE
.
AnimationUtils
.
arraySlice
(
outputAccessor
.
array
,
0
),
INTERPOLATION
[
sampler
.
interpolation
]
...
...
@@ -1408,20 +1590,18 @@ THREE.GLTFLoader = ( function () {
if
(
node
.
jointName
)
{
_node
=
new
THREE
.
Bone
();
_node
.
name
=
node
.
name
!==
undefined
?
node
.
name
:
node
.
jointName
;
_node
.
jointName
=
node
.
jointName
;
}
else
{
_node
=
new
THREE
.
Object3D
();
if
(
node
.
name
!==
undefined
)
_node
.
name
=
node
.
name
;
}
_node
.
name
=
node
.
name
;
if
(
node
.
extras
)
_node
.
userData
=
node
.
extras
;
_node
.
matrixAutoUpdate
=
false
;
if
(
node
.
matrix
!==
undefined
)
{
matrix
.
fromArray
(
node
.
matrix
);
...
...
@@ -1531,6 +1711,22 @@ THREE.GLTFLoader = ( function () {
// Replace Mesh with SkinnedMesh in library
if
(
skinEntry
)
{
var
getJointNode
=
function
(
jointId
)
{
var
keys
=
Object
.
keys
(
__nodes
);
for
(
var
i
=
0
,
il
=
keys
.
length
;
i
<
il
;
i
++
)
{
var
n
=
__nodes
[
keys
[
i
]
];
if
(
n
.
jointName
===
jointId
)
return
n
;
}
return
null
;
}
var
geometry
=
originalGeometry
;
var
material
=
originalMaterial
;
material
.
skinning
=
true
;
...
...
@@ -1542,45 +1738,53 @@ THREE.GLTFLoader = ( function () {
var
bones
=
[];
var
boneInverses
=
[];
var
keys
=
Object
.
keys
(
__nodes
);
for
(
var
i
=
0
,
l
=
skinEntry
.
jointNames
.
length
;
i
<
l
;
i
++
)
{
var
jointId
=
skinEntry
.
jointNames
[
i
];
var
jointNode
=
getJointNode
(
jointId
);
var
jointNode
;
if
(
jointNode
)
{
for
(
var
j
=
0
,
jl
=
keys
.
length
;
j
<
jl
;
j
++
)
{
bones
.
push
(
jointNode
);
var
n
=
__nodes
[
keys
[
j
]
];
var
m
=
skinEntry
.
inverseBindMatrices
.
array
;
var
mat
=
new
THREE
.
Matrix4
().
fromArray
(
m
,
i
*
16
);
boneInverses
.
push
(
mat
);
if
(
n
.
jointName
===
jointId
)
{
}
else
{
jointNode
=
n
;
break
;
console
.
warn
(
"
WARNING: joint: ''
"
+
jointId
+
"
' could not be found
"
);
}
}
if
(
jointNode
)
{
child
.
bind
(
new
THREE
.
Skeleton
(
bones
,
boneInverses
,
false
),
skinEntry
.
bindShapeMatrix
);
jointNode
.
skin
=
child
;
bones
.
push
(
jointNode
);
var
buildBoneGraph
=
function
(
parentJson
,
parentObject
,
property
)
{
var
m
=
skinEntry
.
inverseBindMatrices
.
array
;
var
mat
=
new
THREE
.
Matrix4
().
fromArray
(
m
,
i
*
16
);
boneInverses
.
push
(
mat
);
var
children
=
parentJson
[
property
];
}
else
{
if
(
children
===
undefined
)
return
;
console
.
warn
(
"
WARNING: joint: ''
"
+
jointId
+
"
' could not be found
"
);
for
(
var
i
=
0
,
il
=
children
.
length
;
i
<
il
;
i
++
)
{
var
nodeId
=
children
[
i
];
var
bone
=
__nodes
[
nodeId
];
var
boneJson
=
json
.
nodes
[
nodeId
];
if
(
bone
!==
undefined
&&
bone
.
isBone
===
true
&&
boneJson
!==
undefined
)
{
parentObject
.
add
(
bone
);
buildBoneGraph
(
boneJson
,
bone
,
'
children
'
);
}
}
child
.
bind
(
new
THREE
.
Skeleton
(
bones
,
boneInverses
,
false
),
skinEntry
.
bindShapeMatrix
);
}
buildBoneGraph
(
node
,
child
,
'
skeletons
'
);
}
...
...
@@ -1653,7 +1857,7 @@ THREE.GLTFLoader = ( function () {
lightNode
=
new
THREE
.
PointLight
(
color
);
break
;
case
"
spot
"
:
case
"
spot
"
:
lightNode
=
new
THREE
.
SpotLight
(
color
);
lightNode
.
position
.
set
(
0
,
0
,
1
);
break
;
...
...
@@ -1719,7 +1923,7 @@ THREE.GLTFLoader = ( function () {
return
_each
(
json
.
scenes
,
function
(
scene
)
{
var
_scene
=
new
THREE
.
Scene
();
_scene
.
name
=
scene
.
name
;
if
(
scene
.
name
!==
undefined
)
_scene
.
name
=
scene
.
name
;
if
(
scene
.
extras
)
_scene
.
userData
=
scene
.
extras
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录