Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
95f1599f
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
95f1599f
编写于
11月 05, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sprite/SpriteMAterial: Removed useScreenCoordinates, sizeAttenuation and alignment.
上级
004145b7
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
17 addition
and
87 deletion
+17
-87
examples/webgl_sprites.html
examples/webgl_sprites.html
+7
-3
src/extras/renderers/plugins/SpritePlugin.js
src/extras/renderers/plugins/SpritePlugin.js
+6
-39
src/extras/shaders/ShaderSprite.js
src/extras/shaders/ShaderSprite.js
+4
-16
src/materials/SpriteMaterial.js
src/materials/SpriteMaterial.js
+0
-29
未找到文件。
examples/webgl_sprites.html
浏览文件 @
95f1599f
...
...
@@ -100,9 +100,11 @@
var
scaleX
=
mapA
.
image
.
width
;
var
scaleY
=
mapA
.
image
.
height
;
var
materialA1
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
useScreenCoordinates
:
true
,
alignment
:
THREE
.
SpriteAlignment
.
topLeft
,
opacity
:
0.25
}
);
var
materialA2
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
useScreenCoordinates
:
true
,
alignment
:
THREE
.
SpriteAlignment
.
topLeft
,
opacity
:
0.5
}
);
var
materialA3
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
useScreenCoordinates
:
true
,
alignment
:
THREE
.
SpriteAlignment
.
topLeft
,
opacity
:
1
}
);
var
materialA1
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
opacity
:
0.25
}
);
var
materialA2
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
opacity
:
0.5
}
);
var
materialA3
=
new
THREE
.
SpriteMaterial
(
{
map
:
mapA
,
opacity
:
1
}
);
/*
sprite = new THREE.Sprite( materialA1 );
sprite.position.set( 100, 100, 0 );
...
...
@@ -119,6 +121,8 @@
sprite.scale.set( scaleX, scaleY, 1 );
scene.add( sprite );
*/
}
// renderer
...
...
src/extras/renderers/plugins/SpritePlugin.js
浏览文件 @
95f1599f
...
...
@@ -58,16 +58,12 @@ THREE.SpritePlugin = function () {
_sprite
.
uniforms
.
rotation
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
rotation
"
);
_sprite
.
uniforms
.
scale
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
scale
"
);
_sprite
.
uniforms
.
alignment
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
alignment
"
);
_sprite
.
uniforms
.
halfViewport
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
halfViewport
"
);
_sprite
.
uniforms
.
color
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
color
"
);
_sprite
.
uniforms
.
map
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
map
"
);
_sprite
.
uniforms
.
opacity
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
opacity
"
);
_sprite
.
uniforms
.
useScreenCoordinates
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
useScreenCoordinates
"
);
_sprite
.
uniforms
.
sizeAttenuation
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
sizeAttenuation
"
);
_sprite
.
uniforms
.
screenPosition
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
screenPosition
"
);
_sprite
.
uniforms
.
modelViewMatrix
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
modelViewMatrix
"
);
_sprite
.
uniforms
.
projectionMatrix
=
_gl
.
getUniformLocation
(
_sprite
.
program
,
"
projectionMatrix
"
);
...
...
@@ -153,7 +149,7 @@ THREE.SpritePlugin = function () {
// update positions and sort
var
i
,
sprite
,
material
,
screenPosition
,
fogType
,
scale
=
[];
var
i
,
sprite
,
material
,
fogType
,
scale
=
[];
for
(
i
=
0
;
i
<
nSprites
;
i
++
)
{
...
...
@@ -162,17 +158,9 @@ THREE.SpritePlugin = function () {
if
(
!
sprite
.
visible
||
material
.
opacity
===
0
)
continue
;
if
(
!
material
.
useScreenCoordinates
)
{
sprite
.
_modelViewMatrix
.
multiplyMatrices
(
camera
.
matrixWorldInverse
,
sprite
.
matrixWorld
);
sprite
.
z
=
-
sprite
.
_modelViewMatrix
.
elements
[
14
];
}
else
{
sprite
.
z
=
-
sprite
.
position
.
z
;
}
}
sprites
.
sort
(
painterSortStable
);
...
...
@@ -189,31 +177,11 @@ THREE.SpritePlugin = function () {
if
(
material
.
map
&&
material
.
map
.
image
&&
material
.
map
.
image
.
width
)
{
_gl
.
uniform1f
(
uniforms
.
alphaTest
,
material
.
alphaTest
);
if
(
material
.
useScreenCoordinates
===
true
)
{
_gl
.
uniform1i
(
uniforms
.
useScreenCoordinates
,
1
);
_gl
.
uniform3f
(
uniforms
.
screenPosition
,
(
(
sprite
.
position
.
x
*
_renderer
.
devicePixelRatio
)
-
halfViewportWidth
)
/
halfViewportWidth
,
(
halfViewportHeight
-
(
sprite
.
position
.
y
*
_renderer
.
devicePixelRatio
)
)
/
halfViewportHeight
,
Math
.
max
(
0
,
Math
.
min
(
1
,
sprite
.
position
.
z
)
)
);
scale
[
0
]
=
_renderer
.
devicePixelRatio
*
sprite
.
scale
.
x
;
scale
[
1
]
=
_renderer
.
devicePixelRatio
*
sprite
.
scale
.
y
;
}
else
{
_gl
.
uniform1i
(
uniforms
.
useScreenCoordinates
,
0
);
_gl
.
uniform1i
(
uniforms
.
sizeAttenuation
,
material
.
sizeAttenuation
?
1
:
0
);
_gl
.
uniformMatrix4fv
(
uniforms
.
modelViewMatrix
,
false
,
sprite
.
_modelViewMatrix
.
elements
);
scale
[
0
]
=
sprite
.
scale
.
x
;
scale
[
1
]
=
sprite
.
scale
.
y
;
}
if
(
scene
.
fog
&&
material
.
fog
)
{
fogType
=
sceneFogType
;
...
...
@@ -233,7 +201,6 @@ THREE.SpritePlugin = function () {
_gl
.
uniform2f
(
uniforms
.
uvScale
,
material
.
uvScale
.
x
,
material
.
uvScale
.
y
);
_gl
.
uniform2f
(
uniforms
.
uvOffset
,
material
.
uvOffset
.
x
,
material
.
uvOffset
.
y
);
_gl
.
uniform2f
(
uniforms
.
alignment
,
material
.
alignment
.
x
,
material
.
alignment
.
y
);
_gl
.
uniform1f
(
uniforms
.
opacity
,
material
.
opacity
);
_gl
.
uniform3f
(
uniforms
.
color
,
material
.
color
.
r
,
material
.
color
.
g
,
material
.
color
.
b
);
...
...
src/extras/shaders/ShaderSprite.js
浏览文件 @
95f1599f
...
...
@@ -10,14 +10,10 @@ THREE.ShaderSprite = {
vertexShader
:
[
"
uniform int useScreenCoordinates;
"
,
"
uniform int sizeAttenuation;
"
,
"
uniform vec3 screenPosition;
"
,
"
uniform mat4 modelViewMatrix;
"
,
"
uniform mat4 projectionMatrix;
"
,
"
uniform float rotation;
"
,
"
uniform vec2 scale;
"
,
"
uniform vec2 alignment;
"
,
"
uniform vec2 uvOffset;
"
,
"
uniform vec2 uvScale;
"
,
"
uniform vec2 halfViewport;
"
,
...
...
@@ -31,7 +27,7 @@ THREE.ShaderSprite = {
"
vUV = uvOffset + uv * uvScale;
"
,
"
vec2 alignedPosition =
( position + alignment )
* scale;
"
,
"
vec2 alignedPosition =
position
* scale;
"
,
"
vec2 rotatedPosition;
"
,
"
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
"
,
...
...
@@ -39,18 +35,10 @@ THREE.ShaderSprite = {
"
vec4 finalPosition;
"
,
"
if( useScreenCoordinates != 0 ) {
"
,
"
finalPosition = vec4( screenPosition.xy + ( rotatedPosition / halfViewport ), screenPosition.z, 1.0 );
"
,
"
} else {
"
,
"
finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
"
,
"
finalPosition.xy += rotatedPosition * ( sizeAttenuation == 1 ? 1.0 : finalPosition.z )
;
"
,
"
finalPosition.xy += rotatedPosition
;
"
,
"
finalPosition = projectionMatrix * finalPosition;
"
,
"
}
"
,
"
gl_Position = finalPosition;
"
,
"
}
"
...
...
src/materials/SpriteMaterial.js
浏览文件 @
95f1599f
...
...
@@ -10,10 +10,6 @@
* depthTest: <bool>,
* depthWrite: <bool>,
*
* useScreenCoordinates: <bool>,
* sizeAttenuation: <bool>,
* alignment: THREE.SpriteAlignment.center,
*
* uvOffset: new THREE.Vector2(),
* uvScale: new THREE.Vector2(),
*
...
...
@@ -30,10 +26,8 @@ THREE.SpriteMaterial = function ( parameters ) {
this
.
color
=
new
THREE
.
Color
(
0xffffff
);
this
.
map
=
new
THREE
.
Texture
();
this
.
useScreenCoordinates
=
false
;
this
.
depthTest
=
true
;
this
.
sizeAttenuation
=
true
;
this
.
alignment
=
THREE
.
SpriteAlignment
.
center
.
clone
();
this
.
rotation
=
0
;
this
.
fog
=
false
;
...
...
@@ -45,13 +39,6 @@ THREE.SpriteMaterial = function ( parameters ) {
this
.
setValues
(
parameters
);
// override coupled defaults if not specified explicitly by parameters
parameters
=
parameters
||
{};
if
(
parameters
.
depthTest
===
undefined
)
this
.
depthTest
=
this
.
useScreenCoordinates
===
false
;
if
(
parameters
.
sizeAttenuation
===
undefined
)
this
.
sizeAttenuation
=
this
.
useScreenCoordinates
===
false
;
};
THREE
.
SpriteMaterial
.
prototype
=
Object
.
create
(
THREE
.
Material
.
prototype
);
...
...
@@ -65,9 +52,6 @@ THREE.SpriteMaterial.prototype.clone = function () {
material
.
color
.
copy
(
this
.
color
);
material
.
map
=
this
.
map
;
material
.
useScreenCoordinates
=
this
.
useScreenCoordinates
;
material
.
sizeAttenuation
=
this
.
sizeAttenuation
;
material
.
alignment
.
copy
(
this
.
alignment
);
material
.
rotation
=
this
.
rotation
;
material
.
uvOffset
.
copy
(
this
.
uvOffset
);
...
...
@@ -78,16 +62,3 @@ THREE.SpriteMaterial.prototype.clone = function () {
return
material
;
};
// Alignment enums
THREE
.
SpriteAlignment
=
{};
THREE
.
SpriteAlignment
.
topLeft
=
new
THREE
.
Vector2
(
0.5
,
-
0.5
);
THREE
.
SpriteAlignment
.
topCenter
=
new
THREE
.
Vector2
(
0
,
-
0.5
);
THREE
.
SpriteAlignment
.
topRight
=
new
THREE
.
Vector2
(
-
0.5
,
-
0.5
);
THREE
.
SpriteAlignment
.
centerLeft
=
new
THREE
.
Vector2
(
0.5
,
0
);
THREE
.
SpriteAlignment
.
center
=
new
THREE
.
Vector2
(
0
,
0
);
THREE
.
SpriteAlignment
.
centerRight
=
new
THREE
.
Vector2
(
-
0.5
,
0
);
THREE
.
SpriteAlignment
.
bottomLeft
=
new
THREE
.
Vector2
(
0.5
,
0.5
);
THREE
.
SpriteAlignment
.
bottomCenter
=
new
THREE
.
Vector2
(
0
,
0.5
);
THREE
.
SpriteAlignment
.
bottomRight
=
new
THREE
.
Vector2
(
-
0.5
,
0.5
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录