Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
8f319e4a
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,发现更多精彩内容 >>
提交
8f319e4a
编写于
2月 18, 2017
作者:
T
Takahiro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove MultiMaterial from OutlineEffect
上级
8e4507d1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
53 addition
and
98 deletion
+53
-98
examples/js/effects/OutlineEffect.js
examples/js/effects/OutlineEffect.js
+53
-98
未找到文件。
examples/js/effects/OutlineEffect.js
浏览文件 @
8f319e4a
...
...
@@ -13,11 +13,11 @@
*
* // How to set outline parameters for each material
* material.outlineParameters = {
* thickNess: 0.01,
// this paremeter won't work for MultiMaterial
* color: new THREE.Color( 0x888888 ),
// this paremeter won't work for MultiMaterial
* alpha: 0.8,
// this paremeter won't work for MultiMaterial
* thickNess: 0.01,
* color: new THREE.Color( 0x888888 ),
* alpha: 0.8,
* visible: true,
* keepAlive: true
// this paremeter won't work for Material in materials of MultiMaterial
* keepAlive: true
* };
*
* TODO
...
...
@@ -35,8 +35,8 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
var
defaultAlpha
=
parameters
.
defaultAlpha
!==
undefined
?
parameters
.
defaultAlpha
:
1.0
;
var
defaultKeepAlive
=
parameters
.
defaultKeepAlive
!==
undefined
?
parameters
.
defaultKeepAlive
:
false
;
// object.material.uuid -> outlineMaterial
//
(no mapping from children of MultiMaterial)
// object.material.uuid -> outlineMaterial
or
//
object.material[ n ].uuid -> outlineMaterial
// save at the outline material creation and release
// if it's unused removeThresholdCount frames
// unless keepAlive is true.
...
...
@@ -44,8 +44,8 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
var
removeThresholdCount
=
60
;
// outlineMaterial.uuid
(or object.uuid for invisibleMaterial) -> originalMaterial
//
including children of MultiMaterial.
// outlineMaterial.uuid
-> object.material or
//
outlineMaterial.uuid -> object.material[ n ]
// save before render and release after render.
var
originalMaterials
=
{};
...
...
@@ -55,8 +55,6 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
//this.cache = cache; // for debug
var
invisibleMaterial
=
new
THREE
.
ShaderMaterial
(
{
visible
:
false
}
);
// copied from WebGLPrograms and removed some materials
var
shaderIDs
=
{
MeshBasicMaterial
:
'
basic
'
,
...
...
@@ -139,6 +137,12 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
].
join
(
"
\n
"
);
function
createInvisibleMaterial
()
{
return
new
THREE
.
ShaderMaterial
(
{
name
:
'
invisible
'
,
visible
:
false
}
);
}
function
createMaterial
(
originalMaterial
)
{
var
shaderID
=
shaderIDs
[
originalMaterial
.
type
];
...
...
@@ -162,7 +166,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
console
.
warn
(
'
THREE.OutlineEffect requires both vec3 position and normal attributes in vertex shader,
'
+
'
does not draw outline for
'
+
originalMaterial
.
name
+
'
(uuid:
'
+
originalMaterial
.
uuid
+
'
) material.
'
);
return
invisibleMaterial
;
return
createInvisibleMaterial
()
;
}
...
...
@@ -173,7 +177,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
}
else
{
return
invisibleMaterial
;
return
createInvisibleMaterial
()
;
}
...
...
@@ -195,7 +199,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
if
(
!
/vec3
\s
+transformed
\s
*=/
.
test
(
originalVertexShader
)
&&
!
/#include
\s
+<begin_vertex>/
.
test
(
originalVertexShader
)
)
defines
.
DECLARE_TRANSFORMED
=
true
;
var
material
=
new
THREE
.
ShaderMaterial
(
{
return
new
THREE
.
ShaderMaterial
(
{
defines
:
defines
,
uniforms
:
uniforms
,
vertexShader
:
vertexShader
,
...
...
@@ -207,73 +211,61 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
fog
:
false
}
);
return
material
;
}
function
createMultiMaterial
(
originalMaterial
)
{
var
materials
=
[];
for
(
var
i
=
0
,
il
=
originalMaterial
.
materials
.
length
;
i
<
il
;
i
++
)
{
materials
.
push
(
createMaterial
(
originalMaterial
.
materials
[
i
]
)
);
}
return
new
THREE
.
MultiMaterial
(
materials
);
}
function
setOutlineMaterial
(
object
)
{
if
(
object
.
material
===
undefined
)
return
;
function
getOutlineMaterialFromCache
(
originalMaterial
)
{
var
data
=
cache
[
o
bject
.
m
aterial
.
uuid
];
var
data
=
cache
[
o
riginalM
aterial
.
uuid
];
if
(
data
===
undefined
)
{
data
=
{
material
:
object
.
material
.
isMultiMaterial
===
true
?
createMultiMaterial
(
object
.
material
)
:
createMaterial
(
object
.
m
aterial
),
material
:
createMaterial
(
originalM
aterial
),
used
:
true
,
keepAlive
:
defaultKeepAlive
,
count
:
0
};
cache
[
o
bject
.
m
aterial
.
uuid
]
=
data
;
cache
[
o
riginalM
aterial
.
uuid
]
=
data
;
}
var
outlineMaterial
=
data
.
material
;
data
.
used
=
true
;
var
uuid
=
outlineMaterial
!==
invisibleMaterial
?
outlineMaterial
.
uuid
:
object
.
uuid
;
originalMaterials
[
uuid
]
=
object
.
material
;
return
data
.
material
;
if
(
object
.
material
.
isMultiMaterial
===
true
)
{
}
for
(
var
i
=
0
,
il
=
object
.
material
.
materials
.
length
;
i
<
il
;
i
++
)
{
function
getOutlineMaterial
(
originalMaterial
)
{
// originalMaterial of leaf material of MultiMaterial is used only for
// updating outlineMaterial. so need not to save for invisibleMaterial.
if
(
outlineMaterial
.
materials
[
i
]
!==
invisibleMaterial
)
{
var
outlineMaterial
=
getOutlineMaterialFromCache
(
originalMaterial
);
originalMaterials
[
outlineMaterial
.
materials
[
i
].
uuid
]
=
object
.
material
.
materials
[
i
]
;
originalMaterials
[
outlineMaterial
.
uuid
]
=
originalMaterial
;
}
updateOutlineMaterial
(
outlineMaterial
,
originalMaterial
);
}
return
outlineMaterial
;
}
function
setOutlineMaterial
(
object
)
{
if
(
object
.
material
===
undefined
)
return
;
updateOutlineMultiMaterial
(
outlineMaterial
,
object
.
material
);
if
(
Array
.
isArray
(
object
.
material
)
)
{
for
(
var
i
=
0
,
il
=
object
.
material
.
length
;
i
<
il
;
i
++
)
{
object
.
material
[
i
]
=
getOutlineMaterial
(
object
.
material
[
i
]
);
}
}
else
{
updateOutlineMaterial
(
outlineMaterial
,
object
.
material
);
object
.
material
=
getOutlineMaterial
(
object
.
material
);
}
object
.
material
=
outlineMaterial
;
originalOnBeforeRenders
[
object
.
uuid
]
=
object
.
onBeforeRender
;
object
.
onBeforeRender
=
onBeforeRender
;
...
...
@@ -283,31 +275,29 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
if
(
object
.
material
===
undefined
)
return
;
var
originalMaterial
=
originalMaterials
[
object
.
material
.
uuid
];
if
(
Array
.
isArray
(
object
.
material
)
)
{
for
(
var
i
=
0
,
il
=
object
.
material
.
length
;
i
<
il
;
i
++
)
{
if
(
originalMaterial
===
undefined
)
{
object
.
material
[
i
]
=
originalMaterials
[
object
.
material
[
i
].
uuid
];
}
originalMaterial
=
originalMaterials
[
object
.
uuid
];
}
else
{
if
(
originalMaterial
===
undefined
)
return
;
object
.
material
=
originalMaterials
[
object
.
material
.
uuid
]
;
}
object
.
material
=
originalMaterial
;
object
.
onBeforeRender
=
originalOnBeforeRenders
[
object
.
uuid
];
}
function
onBeforeRender
(
renderer
,
scene
,
camera
,
geometry
,
material
,
group
)
{
// check some things before updating just in case
if
(
material
===
invisibleMaterial
)
return
;
if
(
material
.
isMultiMaterial
===
true
)
return
;
var
originalMaterial
=
originalMaterials
[
material
.
uuid
];
// just in case
if
(
originalMaterial
===
undefined
)
return
;
updateUniforms
(
material
,
originalMaterial
);
...
...
@@ -332,7 +322,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
function
updateOutlineMaterial
(
material
,
originalMaterial
)
{
if
(
material
===
invisibleMaterial
)
return
;
if
(
material
.
name
===
'
invisible
'
)
return
;
var
outlineParameters
=
originalMaterial
.
outlineParameters
;
...
...
@@ -354,8 +344,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
material
.
transparent
=
(
outlineParameters
.
alpha
!==
undefined
&&
outlineParameters
.
alpha
<
1.0
)
?
true
:
originalMaterial
.
transparent
;
// cache[ originalMaterial.uuid ] is undefined if originalMaterial is in materials of MultiMaterial
if
(
outlineParameters
.
keepAlive
!==
undefined
&&
cache
[
originalMaterial
.
uuid
]
!==
undefined
)
cache
[
originalMaterial
.
uuid
].
keepAlive
=
outlineParameters
.
keepAlive
;
if
(
outlineParameters
.
keepAlive
!==
undefined
)
cache
[
originalMaterial
.
uuid
].
keepAlive
=
outlineParameters
.
keepAlive
;
}
else
{
...
...
@@ -368,40 +357,6 @@ THREE.OutlineEffect = function ( renderer, parameters ) {
}
function
updateOutlineMultiMaterial
(
material
,
originalMaterial
)
{
if
(
material
===
invisibleMaterial
)
return
;
var
outlineParameters
=
originalMaterial
.
outlineParameters
;
if
(
outlineParameters
!==
undefined
)
{
if
(
originalMaterial
.
visible
===
false
)
{
material
.
visible
=
false
;
}
else
{
material
.
visible
=
(
outlineParameters
.
visible
!==
undefined
)
?
outlineParameters
.
visible
:
true
;
}
if
(
outlineParameters
.
keepAlive
!==
undefined
)
cache
[
originalMaterial
.
uuid
].
keepAlive
=
outlineParameters
.
keepAlive
;
}
else
{
material
.
visible
=
originalMaterial
.
visible
;
}
for
(
var
i
=
0
,
il
=
material
.
materials
.
length
;
i
<
il
;
i
++
)
{
updateOutlineMaterial
(
material
.
materials
[
i
],
originalMaterial
.
materials
[
i
]
);
}
}
function
cleanupCache
()
{
var
keys
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录