Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
63e8dfc5
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,体验更适合开发者的 AI 搜索 >>
提交
63e8dfc5
编写于
1月 24, 2020
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Editor: Automatically remove unused materials from material browser.
上级
205e345b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
17 deletion
+87
-17
editor/js/Editor.js
editor/js/Editor.js
+50
-8
editor/js/Sidebar.Material.js
editor/js/Sidebar.Material.js
+12
-0
editor/js/Sidebar.Project.js
editor/js/Sidebar.Project.js
+25
-9
未找到文件。
editor/js/Editor.js
浏览文件 @
63e8dfc5
...
...
@@ -102,6 +102,8 @@ var Editor = function () {
this
.
textures
=
{};
this
.
scripts
=
{};
this
.
materialsRefCounter
=
new
Map
();
// tracks how often is a material used by a 3D object
this
.
animations
=
{};
this
.
mixer
=
new
THREE
.
AnimationMixer
(
this
.
scene
);
...
...
@@ -216,6 +218,8 @@ Editor.prototype = {
scope
.
removeCamera
(
child
);
scope
.
removeHelper
(
child
);
if
(
child
.
material
!==
undefined
)
scope
.
removeMaterial
(
child
.
material
);
}
);
object
.
parent
.
remove
(
object
);
...
...
@@ -244,15 +248,13 @@ Editor.prototype = {
for
(
var
i
=
0
,
l
=
material
.
length
;
i
<
l
;
i
++
)
{
if
(
material
[
i
].
uuid
in
this
.
materials
)
return
;
this
.
materials
[
material
[
i
].
uuid
]
=
material
[
i
];
this
.
addMaterialToRefCounter
(
material
[
i
]
);
}
}
else
{
if
(
material
.
uuid
in
this
.
materials
)
return
;
this
.
materials
[
material
.
uuid
]
=
material
;
this
.
addMaterialToRefCounter
(
material
);
}
...
...
@@ -260,19 +262,39 @@ Editor.prototype = {
},
addMaterialToRefCounter
:
function
(
material
)
{
var
materialsRefCounter
=
this
.
materialsRefCounter
;
var
count
=
materialsRefCounter
.
get
(
material
);
if
(
count
===
undefined
)
{
materialsRefCounter
.
set
(
material
,
1
);
this
.
materials
[
material
.
uuid
]
=
material
;
}
else
{
count
++
;
materialsRefCounter
.
set
(
material
,
count
);
}
},
removeMaterial
:
function
(
material
)
{
if
(
Array
.
isArray
(
material
)
)
{
for
(
var
i
=
0
,
l
=
material
.
length
;
i
<
l
;
i
++
)
{
delete
this
.
materials
[
material
[
i
].
uuid
]
;
this
.
removeMaterialFromRefCounter
(
material
[
i
]
)
;
}
}
else
{
delete
this
.
materials
[
material
.
uuid
]
;
this
.
removeMaterialFromRefCounter
(
material
)
;
}
...
...
@@ -280,6 +302,26 @@ Editor.prototype = {
},
removeMaterialFromRefCounter
:
function
(
material
)
{
var
materialsRefCounter
=
this
.
materialsRefCounter
;
var
count
=
materialsRefCounter
.
get
(
material
);
count
--
;
if
(
count
===
0
)
{
materialsRefCounter
.
delete
(
material
);
delete
this
.
materials
[
material
.
uuid
];
}
else
{
materialsRefCounter
.
set
(
material
,
count
);
}
},
getMaterialById
:
function
(
id
)
{
var
material
;
...
...
@@ -456,7 +498,7 @@ Editor.prototype = {
var
material
=
object
.
material
;
if
(
Array
.
isArray
(
material
)
)
{
if
(
Array
.
isArray
(
material
)
&&
slot
!==
undefined
)
{
material
=
material
[
slot
];
...
...
@@ -468,7 +510,7 @@ Editor.prototype = {
setObjectMaterial
:
function
(
object
,
slot
,
newMaterial
)
{
if
(
Array
.
isArray
(
object
.
material
)
)
{
if
(
Array
.
isArray
(
object
.
material
)
&&
slot
!==
undefined
)
{
object
.
material
[
slot
]
=
newMaterial
;
...
...
editor/js/Sidebar.Material.js
浏览文件 @
63e8dfc5
...
...
@@ -609,6 +609,18 @@ var SidebarMaterial = function ( editor ) {
}
if
(
Array
.
isArray
(
currentObject
.
material
)
)
{
// don't remove the entire multi-material. just the material of the selected slot
editor
.
removeMaterial
(
currentObject
.
material
[
currentMaterialSlot
]
);
}
else
{
editor
.
removeMaterial
(
currentObject
.
material
);
}
editor
.
execute
(
new
SetMaterialCommand
(
editor
,
currentObject
,
material
,
currentMaterialSlot
),
'
New Material:
'
+
materialClass
.
getValue
()
);
editor
.
addMaterial
(
material
);
// TODO Copy other references in the scene graph
...
...
editor/js/Sidebar.Project.js
浏览文件 @
63e8dfc5
...
...
@@ -112,11 +112,6 @@ var SidebarProject = function ( editor ) {
materials
.
add
(
headerRow
);
var
listbox
=
new
UIListbox
();
signals
.
materialAdded
.
add
(
function
()
{
listbox
.
setItems
(
Object
.
values
(
editor
.
materials
)
);
}
);
materials
.
add
(
listbox
);
var
buttonsRow
=
new
UIRow
();
...
...
@@ -136,13 +131,25 @@ var SidebarProject = function ( editor ) {
var
assignMaterial
=
new
UIButton
().
setLabel
(
strings
.
getKey
(
'
sidebar/project/Assign
'
)
).
setMargin
(
'
0px 5px
'
);
assignMaterial
.
onClick
(
function
()
{
if
(
editor
.
selected
!==
null
)
{
var
selectedObject
=
editor
.
selected
;
if
(
selectedObject
!==
null
)
{
var
oldMaterial
=
selectedObject
.
material
;
// only assing materials to objects with a material property (e.g. avoid assigning material to THREE.Group)
if
(
oldMaterial
!==
undefined
)
{
var
material
=
editor
.
getMaterialById
(
parseInt
(
listbox
.
getValue
()
)
);
var
material
=
editor
.
getMaterialById
(
parseInt
(
listbox
.
getValue
()
)
);
if
(
material
!==
undefined
)
{
if
(
material
!==
undefined
)
{
editor
.
execute
(
new
SetMaterialCommand
(
editor
,
editor
.
selected
,
material
)
);
editor
.
removeMaterial
(
oldMaterial
);
editor
.
execute
(
new
SetMaterialCommand
(
editor
,
selectedObject
,
material
)
);
editor
.
addMaterial
(
material
);
}
}
...
...
@@ -166,6 +173,15 @@ var SidebarProject = function ( editor ) {
}
);
signals
.
materialAdded
.
add
(
refreshMaterialBrowserUI
);
signals
.
materialRemoved
.
add
(
refreshMaterialBrowserUI
);
function
refreshMaterialBrowserUI
()
{
listbox
.
setItems
(
Object
.
values
(
editor
.
materials
)
);
}
return
container
;
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录