Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
5e78337b
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,发现更多精彩内容 >>
提交
5e78337b
编写于
9月 21, 2017
作者:
M
Mr.doob
提交者:
GitHub
9月 21, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12244 from donmccurdy/feat-gltf-shallower
GLTFLoader: Remove extra Object3D wrappers on nodes.
上级
522878ea
5107c06d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
96 addition
and
137 deletion
+96
-137
examples/js/loaders/GLTFLoader.js
examples/js/loaders/GLTFLoader.js
+73
-136
examples/webgl_loader_gltf.html
examples/webgl_loader_gltf.html
+11
-1
src/objects/Mesh.js
src/objects/Mesh.js
+12
-0
未找到文件。
examples/js/loaders/GLTFLoader.js
浏览文件 @
5e78337b
...
...
@@ -1807,13 +1807,10 @@ THREE.GLTFLoader = ( function () {
]
).
then
(
function
(
dependencies
)
{
return
_each
(
json
.
meshes
,
function
(
meshDef
)
{
return
_each
(
json
.
meshes
,
function
(
meshDef
,
meshIndex
)
{
var
group
=
new
THREE
.
Group
();
if
(
meshDef
.
name
!==
undefined
)
group
.
name
=
meshDef
.
name
;
if
(
meshDef
.
extras
)
group
.
userData
=
meshDef
.
extras
;
var
primitives
=
meshDef
.
primitives
||
[];
return
scope
.
loadGeometries
(
primitives
).
then
(
function
(
geometries
)
{
...
...
@@ -1896,7 +1893,8 @@ THREE.GLTFLoader = ( function () {
}
mesh
.
name
=
group
.
name
+
'
_
'
+
i
;
mesh
.
name
=
meshDef
.
name
||
(
'
mesh_
'
+
meshIndex
);
mesh
.
name
+=
i
>
0
?
(
'
_
'
+
i
)
:
''
;
if
(
primitive
.
targets
!==
undefined
)
{
...
...
@@ -2133,144 +2131,107 @@ THREE.GLTFLoader = ( function () {
}
);
return
_each
(
json
.
nodes
,
function
(
node
)
{
var
matrix
=
new
THREE
.
Matrix4
();
var
_node
=
node
.
isBone
===
true
?
new
THREE
.
Bone
()
:
new
THREE
.
Object3D
();
if
(
node
.
name
!==
undefined
)
{
_node
.
name
=
THREE
.
PropertyBinding
.
sanitizeNodeName
(
node
.
name
);
}
return
scope
.
_withDependencies
(
[
if
(
node
.
extras
)
_node
.
userData
=
node
.
extras
;
'
meshes
'
,
'
skins
'
,
'
cameras
'
if
(
node
.
matrix
!==
undefined
)
{
]
).
then
(
function
(
dependencies
)
{
matrix
.
fromArray
(
node
.
matrix
);
_node
.
applyMatrix
(
matrix
);
return
_each
(
json
.
nodes
,
function
(
nodeDef
)
{
}
else
{
if
(
nodeDef
.
isBone
===
true
)
{
if
(
node
.
translation
!==
undefined
)
{
return
new
THREE
.
Bone
();
_node
.
position
.
fromArray
(
node
.
translation
);
}
else
if
(
nodeDef
.
mesh
!==
undefined
)
{
}
return
dependencies
.
meshes
[
nodeDef
.
mesh
].
clone
();
if
(
node
.
rotation
!==
undefined
)
{
}
else
if
(
nodeDef
.
camera
!==
undefined
)
{
_node
.
quaternion
.
fromArray
(
node
.
rotation
)
;
return
dependencies
.
cameras
[
nodeDef
.
camera
]
;
}
}
else
if
(
nodeDef
.
extensions
&&
nodeDef
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
]
&&
nodeDef
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
light
!==
undefined
)
{
if
(
node
.
scale
!==
undefined
)
{
var
lights
=
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
lights
;
return
lights
[
nodeDef
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
light
];
_node
.
scale
.
fromArray
(
node
.
scale
);
}
else
{
}
return
new
THREE
.
Object3D
();
}
return
_node
;
}
).
then
(
function
(
__nodes
)
{
return
scope
.
_withDependencies
(
[
'
meshes
'
,
'
skins
'
,
'
cameras
'
]
).
then
(
function
(
dependencies
)
{
return
_each
(
__nodes
,
function
(
_node
,
nodeId
)
{
var
node
=
json
.
nodes
[
nodeId
];
return
_each
(
__nodes
,
function
(
node
,
nodeIndex
)
{
var
mesh
=
node
.
mesh
;
var
nodeDef
=
json
.
nodes
[
nodeIndex
]
;
if
(
mesh
!==
undefined
)
{
if
(
nodeDef
.
name
!==
undefined
)
{
var
group
=
dependencies
.
meshes
[
mesh
]
;
node
.
name
=
THREE
.
PropertyBinding
.
sanitizeNodeName
(
nodeDef
.
name
)
;
if
(
group
!==
undefined
)
{
}
// do not clone children as they will be replaced anyway
var
clonedgroup
=
group
.
clone
(
false
);
if
(
nodeDef
.
extras
)
node
.
userData
=
nodeDef
.
extras
;
for
(
var
i
=
0
;
i
<
group
.
children
.
length
;
i
++
)
{
if
(
nodeDef
.
matrix
!==
undefined
)
{
var
child
=
group
.
children
[
i
];
var
originalChild
=
child
;
var
matrix
=
new
THREE
.
Matrix4
();
matrix
.
fromArray
(
nodeDef
.
matrix
);
node
.
applyMatrix
(
matrix
);
// clone Mesh to add to _node
}
else
{
var
originalMaterial
=
child
.
material
;
var
originalGeometry
=
child
.
geometry
;
var
originalInfluences
=
child
.
morphTargetInfluences
;
var
originalUserData
=
child
.
userData
;
var
originalName
=
child
.
name
;
if
(
nodeDef
.
translation
!==
undefined
)
{
var
material
=
originalMaterial
;
node
.
position
.
fromArray
(
nodeDef
.
translation
)
;
switch
(
child
.
type
)
{
}
case
'
LineSegments
'
:
child
=
new
THREE
.
LineSegments
(
originalGeometry
,
material
);
break
;
if
(
nodeDef
.
rotation
!==
undefined
)
{
case
'
LineLoop
'
:
child
=
new
THREE
.
LineLoop
(
originalGeometry
,
material
);
break
;
node
.
quaternion
.
fromArray
(
nodeDef
.
rotation
);
case
'
Line
'
:
child
=
new
THREE
.
Line
(
originalGeometry
,
material
);
break
;
}
case
'
Points
'
:
child
=
new
THREE
.
Points
(
originalGeometry
,
material
);
break
;
if
(
nodeDef
.
scale
!==
undefined
)
{
default
:
child
=
new
THREE
.
Mesh
(
originalGeometry
,
material
);
child
.
drawMode
=
originalChild
.
drawMode
;
node
.
scale
.
fromArray
(
nodeDef
.
scale
);
}
child
.
castShadow
=
true
;
child
.
morphTargetInfluences
=
originalInfluences
;
child
.
userData
=
originalUserData
;
child
.
name
=
originalName
;
}
var
skinEntry
;
if
(
nodeDef
.
skin
!==
undefined
)
{
if
(
node
.
skin
!==
undefined
)
{
var
skinnedMeshes
=
[];
skinEntry
=
dependencies
.
skins
[
node
.
skin
];
for
(
var
i
=
0
;
i
<
node
.
children
.
length
;
i
++
)
{
}
var
skinEntry
=
dependencies
.
skins
[
nodeDef
.
skin
];
// Replace Mesh with SkinnedMesh in library
if
(
skinEntry
)
{
var
geometry
=
originalGeometry
;
material
=
originalMaterial
;
// Replace Mesh with SkinnedMesh.
var
geometry
=
node
.
children
[
i
].
geometry
;
var
material
=
node
.
children
[
i
].
material
;
material
.
skinning
=
true
;
child
=
new
THREE
.
SkinnedMesh
(
geometry
,
material
);
child
.
castShadow
=
true
;
child
.
userData
=
originalU
serData
;
child
.
name
=
originalN
ame
;
var
child
=
new
THREE
.
SkinnedMesh
(
geometry
,
material
);
child
.
morphTargetInfluences
=
node
.
children
[
i
].
morphTargetInfluences
;
child
.
userData
=
node
.
children
[
i
].
u
serData
;
child
.
name
=
node
.
children
[
i
].
n
ame
;
var
bones
=
[];
var
boneInverses
=
[];
for
(
var
i
=
0
,
l
=
skinEntry
.
joints
.
length
;
i
<
l
;
i
++
)
{
for
(
var
j
=
0
,
l
=
skinEntry
.
joints
.
length
;
j
<
l
;
j
++
)
{
var
jointId
=
skinEntry
.
joints
[
i
];
var
jointId
=
skinEntry
.
joints
[
j
];
var
jointNode
=
__nodes
[
jointId
];
if
(
jointNode
)
{
...
...
@@ -2278,7 +2239,7 @@ THREE.GLTFLoader = ( function () {
bones
.
push
(
jointNode
);
var
m
=
skinEntry
.
inverseBindMatrices
.
array
;
var
mat
=
new
THREE
.
Matrix4
().
fromArray
(
m
,
i
*
16
);
var
mat
=
new
THREE
.
Matrix4
().
fromArray
(
m
,
j
*
16
);
boneInverses
.
push
(
mat
);
}
else
{
...
...
@@ -2291,40 +2252,16 @@ THREE.GLTFLoader = ( function () {
child
.
bind
(
new
THREE
.
Skeleton
(
bones
,
boneInverses
),
child
.
matrixWorld
);
}
clonedgroup
.
add
(
child
);
skinnedMeshes
.
push
(
child
);
}
_node
.
add
(
clonedgroup
);
}
else
{
console
.
warn
(
'
THREE.GLTFLoader: Could not find node "
'
+
mesh
+
'
".
'
);
}
}
if
(
node
.
camera
!==
undefined
)
{
var
camera
=
dependencies
.
cameras
[
node
.
camera
];
_node
.
add
(
camera
);
}
if
(
node
.
extensions
&&
node
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
]
&&
node
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
light
!==
undefined
)
{
var
lights
=
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
lights
;
_node
.
add
(
lights
[
node
.
extensions
[
EXTENSIONS
.
KHR_LIGHTS
].
light
]
);
node
.
remove
.
apply
(
node
,
node
.
children
);
node
.
add
.
apply
(
node
,
skinnedMeshes
);
}
return
_
node
;
return
node
;
}
);
...
...
examples/webgl_loader_gltf.html
浏览文件 @
5e78337b
...
...
@@ -274,6 +274,12 @@
}
object
.
traverse
(
function
(
node
)
{
if
(
node
.
isMesh
)
node
.
castShadow
=
true
;
}
);
cameraIndex
=
0
;
cameras
=
[];
cameraNames
=
[];
...
...
@@ -332,7 +338,11 @@
scene
.
add
(
object
);
onWindowResize
();
});
},
undefined
,
function
(
error
)
{
console
.
error
(
error
);
}
);
orbitControls
=
new
THREE
.
OrbitControls
(
defaultCamera
,
renderer
.
domElement
);
...
...
src/objects/Mesh.js
浏览文件 @
5e78337b
...
...
@@ -50,6 +50,18 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
this
.
drawMode
=
source
.
drawMode
;
if
(
source
.
morphTargetInfluences
!==
undefined
)
{
this
.
morphTargetInfluences
=
source
.
morphTargetInfluences
.
slice
();
}
if
(
source
.
morphTargetDictionary
!==
undefined
)
{
this
.
morphTargetDictionary
=
Object
.
assign
(
{},
source
.
morphTargetDictionary
);
}
return
this
;
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录