Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
2c50ad36
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,发现更多精彩内容 >>
提交
2c50ad36
编写于
11月 26, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'alteredq/master'
上级
f5f9beca
38dacb0d
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
300 addition
and
272 deletion
+300
-272
build/Three.js
build/Three.js
+83
-83
build/ThreeDebug.js
build/ThreeDebug.js
+83
-83
examples/geometry_panorama_fisheye.html
examples/geometry_panorama_fisheye.html
+23
-3
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+111
-103
未找到文件。
build/Three.js
浏览文件 @
2c50ad36
此差异已折叠。
点击以展开。
build/ThreeDebug.js
浏览文件 @
2c50ad36
此差异已折叠。
点击以展开。
examples/geometry_panorama_fisheye.html
浏览文件 @
2c50ad36
...
...
@@ -98,7 +98,8 @@
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
document
.
addEventListener
(
'
mouseup
'
,
onDocumentMouseUp
,
false
);
document
.
addEventListener
(
'
mousewheel
'
,
onDocumentMouseWheel
,
false
);
document
.
addEventListener
(
'
DOMMouseScroll
'
,
onDocumentMouseWheel
,
false
);
document
.
addEventListener
(
'
touchstart
'
,
onDocumentTouchStart
,
false
);
document
.
addEventListener
(
'
touchmove
'
,
onDocumentTouchMove
,
false
);
...
...
@@ -158,8 +159,27 @@
}
function
onDocumentMouseWheel
(
event
)
{
fov
-=
event
.
wheelDeltaY
*
0.05
;
// WebKit
if
(
event
.
wheelDeltaY
)
{
fov
-=
event
.
wheelDeltaY
*
0.05
;
// Opera / Explorer 9
}
else
if
(
event
.
wheelDelta
)
{
fov
-=
event
.
wheelDelta
*
0.05
;
// Firefox
}
else
if
(
event
.
detail
)
{
fov
+=
event
.
detail
*
1.0
;
}
camera
.
projectionMatrix
=
THREE
.
Matrix4
.
makePerspective
(
fov
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
1100
);
render
();
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
2c50ad36
...
...
@@ -9,16 +9,25 @@ THREE.WebGLRenderer = function ( scene ) {
// Currently you can use just up to 4 directional / point lights total.
// Chrome barfs on shader linking when there are more than 4 lights :(
//
It seems problem comes from hav
ing too many varying vectors.
//
The problem comes from shader us
ing too many varying vectors.
// Weirdly, this is not GPU limitation as the same shader works ok in Firefox.
// This difference could come from Chrome using ANGLE on Windows,
// This is not GPU limitation as the same shader works ok in Firefox
// or Chrome with "--use-gl=desktop" flag.
// This difference comes from Chrome on Windows using by default ANGLE,
// thus going DirectX9 route (while FF uses OpenGL).
// See http://code.google.com/p/chromium/issues/detail?id=63491
var
_canvas
=
document
.
createElement
(
'
canvas
'
),
_gl
,
_program
,
_modelViewMatrix
=
new
THREE
.
Matrix4
(),
_normalMatrix
,
BASIC
=
0
,
LAMBERT
=
1
,
PHONG
=
2
,
DEPTH
=
3
,
NORMAL
=
4
,
CUBE
=
5
,
// material constants used in shader
// material constants used in shader
BASIC
=
0
,
LAMBERT
=
1
,
PHONG
=
2
,
DEPTH
=
3
,
NORMAL
=
4
,
CUBE
=
5
,
// heuristics to create shader parameters according to lights in the scene
// (not to blow over maxLights budget)
maxLightCount
=
allocateLights
(
scene
,
4
);
...
...
@@ -28,52 +37,8 @@ THREE.WebGLRenderer = function ( scene ) {
initGL
();
initProgram
(
maxLightCount
.
directional
,
maxLightCount
.
point
);
// Querying via gl.getParameter() reports different values for CH and FF for many max parameters.
// On my GPU Chrome reports MAX_VARYING_VECTORS = 8, FF reports 0 yet compiles shaders with many
// more varying vectors (up to 29 lights are ok, more start to throw warnings to FF error console
// and then crash the browser).
//alert( dumpObject( getGLParams() ) );
function
allocateLights
(
scene
,
maxLights
)
{
// heuristics to create shader parameters according to lights in the scene
// (not to blow over maxLights budget)
if
(
scene
)
{
var
l
,
ll
,
light
,
dirLights
=
pointLights
=
maxDirLights
=
maxPointLights
=
0
;
for
(
l
=
0
,
ll
=
scene
.
lights
.
length
;
l
<
ll
;
l
++
)
{
light
=
scene
.
lights
[
l
];
if
(
light
instanceof
THREE
.
DirectionalLight
)
dirLights
++
;
if
(
light
instanceof
THREE
.
PointLight
)
pointLights
++
;
}
if
(
(
pointLights
+
dirLights
)
<=
maxLights
)
{
maxDirLights
=
dirLights
;
maxPointLights
=
pointLights
;
}
else
{
maxDirLights
=
Math
.
ceil
(
maxLights
*
dirLights
/
(
pointLights
+
dirLights
)
);
maxPointLights
=
maxLights
-
maxDirLights
;
}
return
{
'
directional
'
:
maxDirLights
,
'
point
'
:
maxPointLights
};
}
return
{
'
directional
'
:
1
,
'
point
'
:
maxLights
-
1
};
};
this
.
setSize
=
function
(
width
,
height
)
{
_canvas
.
width
=
width
;
...
...
@@ -182,12 +147,10 @@ THREE.WebGLRenderer = function ( scene ) {
}
};
this
.
createBuffers
=
function
(
object
,
mf
)
{
var
f
,
fl
,
fi
,
face
,
vertexNormals
,
normal
,
uv
,
v1
,
v2
,
v3
,
v4
,
m
,
ml
,
i
,
l
,
materialFaceGroup
=
object
.
materialFaceGroup
[
mf
],
var
f
,
fl
,
fi
,
face
,
vertexNormals
,
normal
,
uv
,
v1
,
v2
,
v3
,
v4
,
m
,
ml
,
i
,
faceArray
=
[],
lineArray
=
[],
...
...
@@ -198,49 +161,9 @@ THREE.WebGLRenderer = function ( scene ) {
vertexIndex
=
0
,
useSmoothNormals
=
false
;
// need to find out if there is any material in the object
// (among all mesh materials and also face materials)
// which would need smooth normals
function
needsSmoothNormals
(
material
)
{
return
material
&&
material
.
shading
!=
undefined
&&
material
.
shading
==
THREE
.
SmoothShading
;
}
for
(
m
=
0
,
ml
=
object
.
material
.
length
;
m
<
ml
;
m
++
)
{
meshMaterial
=
object
.
material
[
m
];
if
(
meshMaterial
instanceof
THREE
.
MeshFaceMaterial
)
{
for
(
i
=
0
,
l
=
materialFaceGroup
.
material
.
length
;
i
<
l
;
i
++
)
{
if
(
needsSmoothNormals
(
materialFaceGroup
.
material
[
i
]
)
)
{
useSmoothNormals
=
true
;
break
;
}
}
}
else
{
if
(
needsSmoothNormals
(
meshMaterial
)
)
{
useSmoothNormals
=
true
;
break
;
}
}
if
(
useSmoothNormals
)
break
;
materialFaceGroup
=
object
.
materialFaceGroup
[
mf
],
}
needsSmoothNormals
=
bufferNeedsSmoothNormals
(
materialFaceGroup
,
object
);
for
(
f
=
0
,
fl
=
materialFaceGroup
.
faces
.
length
;
f
<
fl
;
f
++
)
{
...
...
@@ -248,7 +171,7 @@ THREE.WebGLRenderer = function ( scene ) {
face
=
object
.
geometry
.
faces
[
fi
];
vertexNormals
=
face
.
vertexNormals
;
n
ormal
=
face
.
normal
;
faceN
ormal
=
face
.
normal
;
uv
=
object
.
geometry
.
uvs
[
fi
];
if
(
face
instanceof
THREE
.
Face3
)
{
...
...
@@ -261,7 +184,7 @@ THREE.WebGLRenderer = function ( scene ) {
vertexArray
.
push
(
v2
.
x
,
v2
.
y
,
v2
.
z
);
vertexArray
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
if
(
vertexNormals
.
length
==
3
&&
use
SmoothNormals
)
{
if
(
vertexNormals
.
length
==
3
&&
needs
SmoothNormals
)
{
for
(
i
=
0
;
i
<
3
;
i
++
)
{
...
...
@@ -273,7 +196,7 @@ THREE.WebGLRenderer = function ( scene ) {
for
(
i
=
0
;
i
<
3
;
i
++
)
{
normalArray
.
push
(
normal
.
x
,
normal
.
y
,
n
ormal
.
z
);
normalArray
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceN
ormal
.
z
);
}
...
...
@@ -284,6 +207,7 @@ THREE.WebGLRenderer = function ( scene ) {
for
(
i
=
0
;
i
<
3
;
i
++
)
{
uvArray
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
}
}
...
...
@@ -310,7 +234,7 @@ THREE.WebGLRenderer = function ( scene ) {
vertexArray
.
push
(
v3
.
x
,
v3
.
y
,
v3
.
z
);
vertexArray
.
push
(
v4
.
x
,
v4
.
y
,
v4
.
z
);
if
(
vertexNormals
.
length
==
4
&&
use
SmoothNormals
)
{
if
(
vertexNormals
.
length
==
4
&&
needs
SmoothNormals
)
{
for
(
i
=
0
;
i
<
4
;
i
++
)
{
...
...
@@ -322,7 +246,7 @@ THREE.WebGLRenderer = function ( scene ) {
for
(
i
=
0
;
i
<
4
;
i
++
)
{
normalArray
.
push
(
normal
.
x
,
normal
.
y
,
n
ormal
.
z
);
normalArray
.
push
(
faceNormal
.
x
,
faceNormal
.
y
,
faceN
ormal
.
z
);
}
...
...
@@ -333,6 +257,7 @@ THREE.WebGLRenderer = function ( scene ) {
for
(
i
=
0
;
i
<
4
;
i
++
)
{
uvArray
.
push
(
uv
[
i
].
u
,
uv
[
i
].
v
);
}
}
...
...
@@ -478,10 +403,10 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
mMap
)
{
if
(
!
material
.
__webGLTexture
&&
material
.
map
.
image
.
loaded
)
{
if
(
!
material
.
map
.
__webGLTexture
&&
material
.
map
.
image
.
loaded
)
{
material
.
__webGLTexture
=
_gl
.
createTexture
();
_gl
.
bindTexture
(
_gl
.
TEXTURE_2D
,
material
.
__webGLTexture
);
material
.
map
.
__webGLTexture
=
_gl
.
createTexture
();
_gl
.
bindTexture
(
_gl
.
TEXTURE_2D
,
material
.
map
.
__webGLTexture
);
_gl
.
texImage2D
(
_gl
.
TEXTURE_2D
,
0
,
_gl
.
RGBA
,
_gl
.
RGBA
,
_gl
.
UNSIGNED_BYTE
,
material
.
map
.
image
);
_gl
.
texParameteri
(
_gl
.
TEXTURE_2D
,
_gl
.
TEXTURE_WRAP_S
,
paramThreeToGL
(
material
.
map
.
wrap_s
)
);
...
...
@@ -495,7 +420,7 @@ THREE.WebGLRenderer = function ( scene ) {
}
_gl
.
activeTexture
(
_gl
.
TEXTURE0
);
_gl
.
bindTexture
(
_gl
.
TEXTURE_2D
,
material
.
__webGLTexture
);
_gl
.
bindTexture
(
_gl
.
TEXTURE_2D
,
material
.
map
.
__webGLTexture
);
_gl
.
uniform1i
(
_program
.
tMap
,
0
);
_gl
.
uniform1i
(
_program
.
enableMap
,
1
);
...
...
@@ -1219,6 +1144,7 @@ THREE.WebGLRenderer = function ( scene ) {
alert
(
"
VALIDATE_STATUS:
"
+
_gl
.
getProgramParameter
(
_program
,
_gl
.
VALIDATE_STATUS
)
);
alert
(
_gl
.
getError
()
);
}
...
...
@@ -1361,8 +1287,90 @@ THREE.WebGLRenderer = function ( scene ) {
}
return
0
;
};
function
materialNeedsSmoothNormals
(
material
)
{
return
material
&&
material
.
shading
!=
undefined
&&
material
.
shading
==
THREE
.
SmoothShading
;
};
function
bufferNeedsSmoothNormals
(
materialFaceGroup
,
object
)
{
var
m
,
ml
,
i
,
l
,
needsSmoothNormals
=
false
;
for
(
m
=
0
,
ml
=
object
.
material
.
length
;
m
<
ml
;
m
++
)
{
meshMaterial
=
object
.
material
[
m
];
if
(
meshMaterial
instanceof
THREE
.
MeshFaceMaterial
)
{
for
(
i
=
0
,
l
=
materialFaceGroup
.
material
.
length
;
i
<
l
;
i
++
)
{
if
(
materialNeedsSmoothNormals
(
materialFaceGroup
.
material
[
i
]
)
)
{
needsSmoothNormals
=
true
;
break
;
}
}
}
else
{
if
(
materialNeedsSmoothNormals
(
meshMaterial
)
)
{
needsSmoothNormals
=
true
;
break
;
}
}
if
(
needsSmoothNormals
)
break
;
}
return
needsSmoothNormals
;
};
function
allocateLights
(
scene
,
maxLights
)
{
if
(
scene
)
{
var
l
,
ll
,
light
,
dirLights
=
pointLights
=
maxDirLights
=
maxPointLights
=
0
;
for
(
l
=
0
,
ll
=
scene
.
lights
.
length
;
l
<
ll
;
l
++
)
{
light
=
scene
.
lights
[
l
];
if
(
light
instanceof
THREE
.
DirectionalLight
)
dirLights
++
;
if
(
light
instanceof
THREE
.
PointLight
)
pointLights
++
;
}
if
(
(
pointLights
+
dirLights
)
<=
maxLights
)
{
maxDirLights
=
dirLights
;
maxPointLights
=
pointLights
;
}
else
{
maxDirLights
=
Math
.
ceil
(
maxLights
*
dirLights
/
(
pointLights
+
dirLights
)
);
maxPointLights
=
maxLights
-
maxDirLights
;
}
return
{
'
directional
'
:
maxDirLights
,
'
point
'
:
maxPointLights
};
}
return
{
'
directional
'
:
1
,
'
point
'
:
maxLights
-
1
};
};
/* DEBUG
function getGLParams() {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录