Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
ef3ac9a7
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,发现更多精彩内容 >>
未验证
提交
ef3ac9a7
编写于
8月 10, 2018
作者:
M
Mr.doob
提交者:
GitHub
8月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14598 from Mugen87/dev17
ShaderMaterial: Improved serialization/deserialization
上级
67a48935
906ce137
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
113 addition
and
4 deletion
+113
-4
src/loaders/MaterialLoader.js
src/loaders/MaterialLoader.js
+52
-3
src/materials/ShaderMaterial.js
src/materials/ShaderMaterial.js
+61
-1
未找到文件。
src/loaders/MaterialLoader.js
浏览文件 @
ef3ac9a7
import
{
Color
}
from
'
../math/Color.js
'
;
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
import
{
Vector3
}
from
'
../math/Vector3.js
'
;
import
{
Vector4
}
from
'
../math/Vector4.js
'
;
import
{
Matrix4
}
from
'
../math/Matrix4.js
'
;
import
{
FileLoader
}
from
'
./FileLoader.js
'
;
import
{
DefaultLoadingManager
}
from
'
./LoadingManager.js
'
;
import
*
as
Materials
from
'
../materials/Materials.js
'
;
...
...
@@ -63,9 +67,6 @@ Object.assign( MaterialLoader.prototype, {
if
(
json
.
shininess
!==
undefined
)
material
.
shininess
=
json
.
shininess
;
if
(
json
.
clearCoat
!==
undefined
)
material
.
clearCoat
=
json
.
clearCoat
;
if
(
json
.
clearCoatRoughness
!==
undefined
)
material
.
clearCoatRoughness
=
json
.
clearCoatRoughness
;
if
(
json
.
uniforms
!==
undefined
)
material
.
uniforms
=
json
.
uniforms
;
if
(
json
.
vertexShader
!==
undefined
)
material
.
vertexShader
=
json
.
vertexShader
;
if
(
json
.
fragmentShader
!==
undefined
)
material
.
fragmentShader
=
json
.
fragmentShader
;
if
(
json
.
vertexColors
!==
undefined
)
material
.
vertexColors
=
json
.
vertexColors
;
if
(
json
.
fog
!==
undefined
)
material
.
fog
=
json
.
fog
;
if
(
json
.
flatShading
!==
undefined
)
material
.
flatShading
=
json
.
flatShading
;
...
...
@@ -100,6 +101,54 @@ Object.assign( MaterialLoader.prototype, {
if
(
json
.
visible
!==
undefined
)
material
.
visible
=
json
.
visible
;
if
(
json
.
userData
!==
undefined
)
material
.
userData
=
json
.
userData
;
// Shader Material
if
(
json
.
uniforms
!==
undefined
)
{
for
(
var
name
in
json
.
uniforms
)
{
var
uniform
=
json
.
uniforms
[
name
];
material
.
uniforms
[
name
]
=
{};
switch
(
uniform
.
type
)
{
case
'
t
'
:
material
.
uniforms
[
name
].
value
=
getTexture
(
uniform
.
value
);
break
;
case
'
c
'
:
material
.
uniforms
[
name
].
value
=
new
Color
().
setHex
(
uniform
.
value
);
break
;
case
'
v2
'
:
material
.
uniforms
[
name
].
value
=
new
Vector2
().
fromArray
(
uniform
.
value
);
break
;
case
'
v3
'
:
material
.
uniforms
[
name
].
value
=
new
Vector3
().
fromArray
(
uniform
.
value
);
break
;
case
'
v4
'
:
material
.
uniforms
[
name
].
value
=
new
Vector4
().
fromArray
(
uniform
.
value
);
break
;
case
'
m4
'
:
material
.
uniforms
[
name
].
value
=
new
Matrix4
().
fromArray
(
uniform
.
value
);
break
;
default
:
material
.
uniforms
[
name
].
value
=
uniform
.
value
;
}
}
}
if
(
json
.
vertexShader
!==
undefined
)
material
.
vertexShader
=
json
.
vertexShader
;
if
(
json
.
fragmentShader
!==
undefined
)
material
.
fragmentShader
=
json
.
fragmentShader
;
// Deprecated
if
(
json
.
shading
!==
undefined
)
material
.
flatShading
=
json
.
shading
===
1
;
// THREE.FlatShading
...
...
src/materials/ShaderMaterial.js
浏览文件 @
ef3ac9a7
...
...
@@ -116,7 +116,67 @@ ShaderMaterial.prototype.toJSON = function ( meta ) {
var
data
=
Material
.
prototype
.
toJSON
.
call
(
this
,
meta
);
data
.
uniforms
=
this
.
uniforms
;
data
.
uniforms
=
{};
for
(
var
name
in
this
.
uniforms
)
{
var
uniform
=
this
.
uniforms
[
name
];
var
value
=
uniform
.
value
;
if
(
value
.
isTexture
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
t
'
,
value
:
value
.
toJSON
(
meta
).
uuid
};
}
else
if
(
value
.
isColor
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
c
'
,
value
:
value
.
getHex
()
};
}
else
if
(
value
.
isVector2
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
v2
'
,
value
:
value
.
toArray
()
};
}
else
if
(
value
.
isVector3
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
v3
'
,
value
:
value
.
toArray
()
};
}
else
if
(
value
.
isVector4
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
v4
'
,
value
:
value
.
toArray
()
};
}
else
if
(
value
.
isMatrix4
)
{
data
.
uniforms
[
name
]
=
{
type
:
'
m4
'
,
value
:
value
.
toArray
()
};
}
else
{
data
.
uniforms
[
name
]
=
{
value
:
value
};
// note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
}
}
data
.
vertexShader
=
this
.
vertexShader
;
data
.
fragmentShader
=
this
.
fragmentShader
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录