Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
5511659b
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,发现更多精彩内容 >>
提交
5511659b
编写于
6月 19, 2017
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed Mirror in VR.
上级
111faafa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
22 deletion
+39
-22
examples/js/Mirror.js
examples/js/Mirror.js
+19
-15
examples/webgl_mirror.html
examples/webgl_mirror.html
+12
-2
examples/webvr_sandbox.html
examples/webvr_sandbox.html
+4
-1
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+4
-4
未找到文件。
examples/js/Mirror.js
浏览文件 @
5511659b
...
...
@@ -27,10 +27,13 @@ THREE.Mirror = function ( width, height, options ) {
var
lookAtPosition
=
new
THREE
.
Vector3
(
0
,
0
,
-
1
);
var
clipPlane
=
new
THREE
.
Vector4
();
var
view
=
new
THREE
.
Vector3
();
var
target
=
new
THREE
.
Vector3
();
var
q
=
new
THREE
.
Vector4
();
var
textureMatrix
=
new
THREE
.
Matrix4
();
var
mirrorCamera
=
new
THREE
.
PerspectiveCamera
();
mirrorCamera
.
matrixAutoUpdate
=
true
;
var
parameters
=
{
minFilter
:
THREE
.
LinearFilter
,
...
...
@@ -106,11 +109,6 @@ THREE.Mirror = function ( width, height, options ) {
function
updateTextureMatrix
(
camera
)
{
camera
.
updateMatrixWorld
();
mirrorCamera
.
copy
(
camera
);
mirrorCamera
.
updateProjectionMatrix
();
scope
.
updateMatrixWorld
();
mirrorWorldPosition
.
setFromMatrixPosition
(
scope
.
matrixWorld
);
...
...
@@ -121,7 +119,7 @@ THREE.Mirror = function ( width, height, options ) {
normal
.
set
(
0
,
0
,
1
);
normal
.
applyMatrix4
(
rotationMatrix
);
v
ar
view
=
mirrorWorldPosition
.
clone
().
sub
(
cameraWorldPosition
);
v
iew
.
subVectors
(
mirrorWorldPosition
,
cameraWorldPosition
);
view
.
reflect
(
normal
).
negate
();
view
.
add
(
mirrorWorldPosition
);
...
...
@@ -131,7 +129,7 @@ THREE.Mirror = function ( width, height, options ) {
lookAtPosition
.
applyMatrix4
(
rotationMatrix
);
lookAtPosition
.
add
(
cameraWorldPosition
);
var
target
=
mirrorWorldPosition
.
clone
().
sub
(
lookAtPosition
);
target
.
subVectors
(
mirrorWorldPosition
,
lookAtPosition
);
target
.
reflect
(
normal
).
negate
();
target
.
add
(
mirrorWorldPosition
);
...
...
@@ -141,8 +139,11 @@ THREE.Mirror = function ( width, height, options ) {
mirrorCamera
.
up
.
reflect
(
normal
).
negate
();
mirrorCamera
.
lookAt
(
target
);
mirrorCamera
.
updateProjectionMatrix
();
mirrorCamera
.
near
=
camera
.
near
;
mirrorCamera
.
far
=
camera
.
far
;
mirrorCamera
.
updateMatrixWorld
();
mirrorCamera
.
updateProjectionMatrix
();
// Update the texture matrix
textureMatrix
.
set
(
...
...
@@ -161,7 +162,6 @@ THREE.Mirror = function ( width, height, options ) {
clipPlane
.
set
(
mirrorPlane
.
normal
.
x
,
mirrorPlane
.
normal
.
y
,
mirrorPlane
.
normal
.
z
,
mirrorPlane
.
constant
);
var
q
=
new
THREE
.
Vector4
();
var
projectionMatrix
=
mirrorCamera
.
projectionMatrix
;
q
.
x
=
(
Math
.
sign
(
clipPlane
.
x
)
+
projectionMatrix
.
elements
[
8
]
)
/
projectionMatrix
.
elements
[
0
];
...
...
@@ -170,13 +170,13 @@ THREE.Mirror = function ( width, height, options ) {
q
.
w
=
(
1.0
+
projectionMatrix
.
elements
[
10
]
)
/
projectionMatrix
.
elements
[
14
];
// Calculate the scaled plane vector
var
c
=
clipPlane
.
multiplyScalar
(
2.0
/
clipPlane
.
dot
(
q
)
);
clipPlane
.
multiplyScalar
(
2.0
/
clipPlane
.
dot
(
q
)
);
// Replacing the third row of the projection matrix
projectionMatrix
.
elements
[
2
]
=
c
.
x
;
projectionMatrix
.
elements
[
6
]
=
c
.
y
;
projectionMatrix
.
elements
[
10
]
=
c
.
z
+
1.0
-
clipBias
;
projectionMatrix
.
elements
[
14
]
=
c
.
w
;
projectionMatrix
.
elements
[
2
]
=
c
lipPlane
.
x
;
projectionMatrix
.
elements
[
6
]
=
c
lipPlane
.
y
;
projectionMatrix
.
elements
[
10
]
=
c
lipPlane
.
z
+
1.0
-
clipBias
;
projectionMatrix
.
elements
[
14
]
=
c
lipPlane
.
w
;
}
...
...
@@ -186,9 +186,13 @@ THREE.Mirror = function ( width, height, options ) {
scope
.
visible
=
false
;
var
currentVrEnabled
=
renderer
.
vr
.
enabled
;
var
currentRenderTarget
=
renderer
.
getRenderTarget
();
renderer
.
vr
.
enabled
=
false
;
// Avoid camera modification and recursion
renderer
.
render
(
scene
,
mirrorCamera
,
renderTarget
,
true
);
renderer
.
vr
.
enabled
=
currentVrEnabled
;
renderer
.
setRenderTarget
(
currentRenderTarget
);
scope
.
visible
=
true
;
...
...
examples/webgl_mirror.html
浏览文件 @
5511659b
...
...
@@ -88,11 +88,21 @@
// MIRROR planes
var
groundMirror
=
new
THREE
.
Mirror
(
100
,
100
,
{
clipBias
:
0.003
,
textureWidth
:
WIDTH
,
textureHeight
:
HEIGHT
,
color
:
0x777777
}
);
var
groundMirror
=
new
THREE
.
Mirror
(
100
,
100
,
{
clipBias
:
0.003
,
textureWidth
:
WIDTH
*
window
.
devicePixelRatio
,
textureHeight
:
HEIGHT
*
window
.
devicePixelRatio
,
color
:
0x777777
}
);
groundMirror
.
rotateX
(
-
Math
.
PI
/
2
);
scene
.
add
(
groundMirror
);
var
verticalMirror
=
new
THREE
.
Mirror
(
60
,
60
,
{
clipBias
:
0.003
,
textureWidth
:
WIDTH
,
textureHeight
:
HEIGHT
,
color
:
0x889999
}
);
var
verticalMirror
=
new
THREE
.
Mirror
(
60
,
60
,
{
clipBias
:
0.003
,
textureWidth
:
WIDTH
*
window
.
devicePixelRatio
,
textureHeight
:
HEIGHT
*
window
.
devicePixelRatio
,
color
:
0x889999
}
);
verticalMirror
.
position
.
y
=
35
;
verticalMirror
.
position
.
z
=
-
45
;
scene
.
add
(
verticalMirror
);
...
...
examples/webvr_sandbox.html
浏览文件 @
5511659b
...
...
@@ -87,7 +87,10 @@
//
mirror
=
new
THREE
.
Mirror
(
1.4
,
1.4
,
{
textureWidth
:
window
.
innerWidth
,
textureHeight
:
window
.
innerHeight
}
);
mirror
=
new
THREE
.
Mirror
(
1.4
,
1.4
,
{
textureWidth
:
window
.
innerWidth
*
window
.
devicePixelRatio
,
textureHeight
:
window
.
innerHeight
*
window
.
devicePixelRatio
}
);
mirror
.
position
.
x
=
1
;
mirror
.
position
.
y
=
0.5
;
mirror
.
position
.
z
=
-
3
;
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
5511659b
...
...
@@ -1474,8 +1474,6 @@ function WebGLRenderer( parameters ) {
var
material
=
overrideMaterial
===
undefined
?
renderItem
.
material
:
overrideMaterial
;
var
group
=
renderItem
.
group
;
object
.
onBeforeRender
(
_this
,
scene
,
camera
,
geometry
,
material
,
group
);
if
(
camera
.
isArrayCamera
)
{
var
cameras
=
camera
.
cameras
;
...
...
@@ -1504,8 +1502,6 @@ function WebGLRenderer( parameters ) {
}
object
.
onAfterRender
(
_this
,
scene
,
camera
,
geometry
,
material
,
group
);
}
}
...
...
@@ -1515,6 +1511,8 @@ function WebGLRenderer( parameters ) {
object
.
modelViewMatrix
.
multiplyMatrices
(
camera
.
matrixWorldInverse
,
object
.
matrixWorld
);
object
.
normalMatrix
.
getNormalMatrix
(
object
.
modelViewMatrix
);
object
.
onBeforeRender
(
_this
,
scene
,
camera
,
geometry
,
material
,
group
);
if
(
object
.
isImmediateRenderObject
)
{
state
.
setMaterial
(
material
);
...
...
@@ -1531,6 +1529,8 @@ function WebGLRenderer( parameters ) {
}
object
.
onAfterRender
(
_this
,
scene
,
camera
,
geometry
,
material
,
group
);
}
function
initMaterial
(
material
,
fog
,
object
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录