Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
6c625ea7
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,发现更多精彩内容 >>
未验证
提交
6c625ea7
编写于
6月 12, 2018
作者:
M
Mr.doob
提交者:
GitHub
6月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14075 from kickblade/GLTFExporterImageCache
GLTFExporter image caching.
上级
0ee30a95
e004c503
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
14 deletion
+33
-14
examples/js/exporters/GLTFExporter.js
examples/js/exporters/GLTFExporter.js
+33
-14
未找到文件。
examples/js/exporters/GLTFExporter.js
浏览文件 @
6c625ea7
...
...
@@ -106,7 +106,8 @@ THREE.GLTFExporter.prototype = {
attributes
:
new
Map
(),
materials
:
new
Map
(),
textures
:
new
Map
()
textures
:
new
Map
(),
images
:
new
Map
()
};
...
...
@@ -622,12 +623,28 @@ THREE.GLTFExporter.prototype = {
/**
* Process image
* @param {Texture} map Texture to process
* @param {Image} image to process
* @param {Integer} format of the image (e.g. THREE.RGBFormat, THREE.RGBAFormat etc)
* @param {Boolean} flipY before writing out the image
* @return {Integer} Index of the processed texture in the "images" array
*/
function
processImage
(
map
)
{
function
processImage
(
image
,
format
,
flipY
)
{
if
(
!
cachedData
.
images
.
has
(
image
)
)
{
cachedData
.
images
.
set
(
image
,
{}
);
}
var
cachedImages
=
cachedData
.
images
.
get
(
image
);
var
mimeType
=
format
===
THREE
.
RGBAFormat
?
'
image/png
'
:
'
image/jpeg
'
;
var
key
=
mimeType
+
"
:flipY/
"
+
flipY
.
toString
();
// @TODO Cache
if
(
cachedImages
[
key
]
!==
undefined
)
{
return
cachedImages
[
key
];
}
if
(
!
outputJSON
.
images
)
{
...
...
@@ -635,19 +652,18 @@ THREE.GLTFExporter.prototype = {
}
var
mimeType
=
map
.
format
===
THREE
.
RGBAFormat
?
'
image/png
'
:
'
image/jpeg
'
;
var
gltfImage
=
{
mimeType
:
mimeType
};
if
(
options
.
embedImages
)
{
var
canvas
=
cachedCanvas
=
cachedCanvas
||
document
.
createElement
(
'
canvas
'
);
canvas
.
width
=
map
.
image
.
width
;
canvas
.
height
=
map
.
image
.
height
;
canvas
.
width
=
image
.
width
;
canvas
.
height
=
image
.
height
;
if
(
options
.
forcePowerOfTwoTextures
&&
!
isPowerOfTwo
(
map
.
image
)
)
{
if
(
options
.
forcePowerOfTwoTextures
&&
!
isPowerOfTwo
(
image
)
)
{
console
.
warn
(
'
GLTFExporter: Resized non-power-of-two image.
'
,
map
.
image
);
console
.
warn
(
'
GLTFExporter: Resized non-power-of-two image.
'
,
image
);
canvas
.
width
=
THREE
.
Math
.
floorPowerOfTwo
(
canvas
.
width
);
canvas
.
height
=
THREE
.
Math
.
floorPowerOfTwo
(
canvas
.
height
);
...
...
@@ -656,14 +672,14 @@ THREE.GLTFExporter.prototype = {
var
ctx
=
canvas
.
getContext
(
'
2d
'
);
if
(
map
.
flipY
===
true
)
{
if
(
flipY
===
true
)
{
ctx
.
translate
(
0
,
canvas
.
height
);
ctx
.
scale
(
1
,
-
1
);
}
ctx
.
drawImage
(
map
.
image
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
ctx
.
drawImage
(
image
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
if
(
options
.
binary
===
true
)
{
...
...
@@ -691,13 +707,16 @@ THREE.GLTFExporter.prototype = {
}
else
{
gltfImage
.
uri
=
map
.
image
.
src
;
gltfImage
.
uri
=
image
.
src
;
}
outputJSON
.
images
.
push
(
gltfImage
);
return
outputJSON
.
images
.
length
-
1
;
var
index
=
outputJSON
.
images
.
length
-
1
;
cachedImages
[
key
]
=
index
;
return
index
;
}
...
...
@@ -751,7 +770,7 @@ THREE.GLTFExporter.prototype = {
var
gltfTexture
=
{
sampler
:
processSampler
(
map
),
source
:
processImage
(
map
)
source
:
processImage
(
map
.
image
,
map
.
format
,
map
.
flipY
)
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录