Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
8f2c2fa0
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,发现更多精彩内容 >>
提交
8f2c2fa0
编写于
5月 02, 2018
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added basic WebXR support.
上级
bbfbe98c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
220 addition
and
19 deletion
+220
-19
examples/js/vr/WebVR.js
examples/js/vr/WebVR.js
+46
-4
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+19
-14
src/renderers/webvr/WebVRManager.js
src/renderers/webvr/WebVRManager.js
+9
-1
src/renderers/webvr/WebXRManager.js
src/renderers/webvr/WebXRManager.js
+145
-0
utils/build/externs.js
utils/build/externs.js
+1
-0
未找到文件。
examples/js/vr/WebVR.js
浏览文件 @
8f2c2fa0
...
...
@@ -9,7 +9,7 @@ var WEBVR = {
createButton
:
function
(
renderer
)
{
function
showEnterVR
(
d
isplay
)
{
function
showEnterVR
(
d
evice
)
{
button
.
style
.
display
=
''
;
...
...
@@ -24,11 +24,29 @@ var WEBVR = {
button
.
onclick
=
function
()
{
display
.
isPresenting
?
display
.
exitPresent
()
:
display
.
requestPresent
(
[
{
source
:
renderer
.
domElement
}
]
);
if
(
'
xr
'
in
navigator
)
{
device
.
requestSession
(
{
exclusive
:
true
}
).
then
(
function
(
session
)
{
renderer
.
vr
.
setSession
(
session
);
session
.
addEventListener
(
'
end
'
,
function
(
event
)
{
renderer
.
vr
.
setSession
(
null
);
}
);
}
);
}
else
{
device
.
isPresenting
?
device
.
exitPresent
()
:
device
.
requestPresent
(
[
{
source
:
renderer
.
domElement
}
]
);
}
};
renderer
.
vr
.
setDevice
(
d
isplay
);
renderer
.
vr
.
setDevice
(
d
evice
);
}
...
...
@@ -68,7 +86,31 @@ var WEBVR = {
}
if
(
'
getVRDisplays
'
in
navigator
)
{
var
isWebXR
=
false
;
if
(
'
xr
'
in
navigator
)
{
isWebXR
=
true
;
var
button
=
document
.
createElement
(
'
button
'
);
button
.
style
.
display
=
'
none
'
;
stylizeElement
(
button
);
navigator
.
xr
.
requestDevice
().
then
(
function
(
device
)
{
device
.
supportsSession
(
{
exclusive
:
true
}
).
then
(
function
()
{
showEnterVR
(
device
);
button
.
textContent
=
'
ENTER XR
'
;
// TODO
}
).
catch
(
showVRNotFound
);
}
).
catch
(
showVRNotFound
);
return
button
;
}
else
if
(
'
getVRDisplays
'
in
navigator
)
{
var
button
=
document
.
createElement
(
'
button
'
);
button
.
style
.
display
=
'
none
'
;
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
8f2c2fa0
...
...
@@ -42,6 +42,7 @@ import { WebGLTextures } from './webgl/WebGLTextures.js';
import
{
WebGLUniforms
}
from
'
./webgl/WebGLUniforms.js
'
;
import
{
WebGLUtils
}
from
'
./webgl/WebGLUtils.js
'
;
import
{
WebVRManager
}
from
'
./webvr/WebVRManager.js
'
;
import
{
WebXRManager
}
from
'
./webvr/WebXRManager.js
'
;
/**
* @author supereggbert / http://www.paulbrunt.co.uk/
...
...
@@ -288,7 +289,7 @@ function WebGLRenderer( parameters ) {
// vr
var
vr
=
new
WebVRManager
(
_this
);
var
vr
=
(
'
xr
'
in
navigator
)
?
new
WebXRManager
(
_gl
)
:
new
WebVRManager
(
_this
);
this
.
vr
=
vr
;
...
...
@@ -353,9 +354,7 @@ function WebGLRenderer( parameters ) {
this
.
setSize
=
function
(
width
,
height
,
updateStyle
)
{
var
device
=
vr
.
getDevice
();
if
(
device
&&
device
.
isPresenting
)
{
if
(
vr
.
isPresenting
()
)
{
console
.
warn
(
'
THREE.WebGLRenderer: Can
\'
t change size while VR device is presenting.
'
);
return
;
...
...
@@ -1037,11 +1036,9 @@ function WebGLRenderer( parameters ) {
function
requestAnimationLoopFrame
()
{
var
device
=
vr
.
getDevice
();
if
(
device
&&
device
.
isPresenting
)
{
if
(
vr
.
isPresenting
()
)
{
device
.
requestAnimationFrame
(
animationLoop
);
vr
.
requestAnimationFrame
(
animationLoop
);
}
else
{
...
...
@@ -1388,14 +1385,22 @@ function WebGLRenderer( parameters ) {
if
(
object
.
layers
.
test
(
camera2
.
layers
)
)
{
var
bounds
=
camera2
.
bounds
;
if
(
'
viewport
'
in
camera2
)
{
// XR
state
.
viewport
(
_currentViewport
.
copy
(
camera2
.
viewport
)
);
}
else
{
var
bounds
=
camera2
.
bounds
;
var
x
=
bounds
.
x
*
_width
;
var
y
=
bounds
.
y
*
_height
;
var
width
=
bounds
.
z
*
_width
;
var
height
=
bounds
.
w
*
_height
;
var
x
=
bounds
.
x
*
_width
;
var
y
=
bounds
.
y
*
_height
;
var
width
=
bounds
.
z
*
_width
;
var
height
=
bounds
.
w
*
_height
;
state
.
viewport
(
_currentViewport
.
set
(
x
,
y
,
width
,
height
).
multiplyScalar
(
_pixelRatio
)
);
state
.
viewport
(
_currentViewport
.
set
(
x
,
y
,
width
,
height
).
multiplyScalar
(
_pixelRatio
)
);
}
renderObject
(
object
,
scene
,
camera2
,
geometry
,
material
,
group
);
...
...
src/renderers/webvr/WebVRManager.js
浏览文件 @
8f2c2fa0
...
...
@@ -3,8 +3,8 @@
*/
import
{
Matrix4
}
from
'
../../math/Matrix4.js
'
;
import
{
Vector4
}
from
'
../../math/Vector4.js
'
;
import
{
Vector3
}
from
'
../../math/Vector3.js
'
;
import
{
Vector4
}
from
'
../../math/Vector4.js
'
;
import
{
Quaternion
}
from
'
../../math/Quaternion.js
'
;
import
{
ArrayCamera
}
from
'
../../cameras/ArrayCamera.js
'
;
import
{
PerspectiveCamera
}
from
'
../../cameras/PerspectiveCamera.js
'
;
...
...
@@ -226,6 +226,14 @@ function WebVRManager( renderer ) {
};
this
.
isPresenting
=
isPresenting
;
this
.
requestAnimationFrame
=
function
(
callback
)
{
device
.
requestAnimationFrame
(
callback
);
};
this
.
submitFrame
=
function
()
{
if
(
isPresenting
()
)
device
.
submitFrame
();
...
...
src/renderers/webvr/WebXRManager.js
0 → 100644
浏览文件 @
8f2c2fa0
/**
* @author mrdoob / http://mrdoob.com/
*/
import
{
Matrix4
}
from
'
../../math/Matrix4.js
'
;
import
{
Vector4
}
from
'
../../math/Vector4.js
'
;
import
{
Vector3
}
from
'
../../math/Vector3.js
'
;
import
{
Quaternion
}
from
'
../../math/Quaternion.js
'
;
import
{
ArrayCamera
}
from
'
../../cameras/ArrayCamera.js
'
;
import
{
PerspectiveCamera
}
from
'
../../cameras/PerspectiveCamera.js
'
;
function
WebXRManager
(
gl
)
{
var
scope
=
this
;
var
device
=
null
;
var
session
=
null
;
var
frameOfRef
=
null
;
var
isExclusive
=
false
;
var
pose
=
null
;
function
isPresenting
()
{
return
session
!==
null
&&
frameOfRef
!==
null
;
}
//
var
cameraL
=
new
PerspectiveCamera
();
cameraL
.
layers
.
enable
(
1
);
cameraL
.
viewport
=
new
Vector4
();
var
cameraR
=
new
PerspectiveCamera
();
cameraR
.
layers
.
enable
(
2
);
cameraR
.
viewport
=
new
Vector4
();
var
cameraVR
=
new
ArrayCamera
(
[
cameraL
,
cameraR
]
);
cameraVR
.
layers
.
enable
(
1
);
cameraVR
.
layers
.
enable
(
2
);
//
this
.
enabled
=
false
;
this
.
getDevice
=
function
()
{
return
device
;
};
this
.
setDevice
=
function
(
value
)
{
if
(
value
!==
undefined
)
device
=
value
;
gl
.
setCompatibleXRDevice
(
value
);
};
this
.
setSession
=
function
(
value
)
{
session
=
value
;
if
(
session
!==
null
)
{
session
.
baseLayer
=
new
XRWebGLLayer
(
session
,
gl
);
session
.
requestFrameOfReference
(
'
stage
'
).
then
(
function
(
value
)
{
frameOfRef
=
value
;
isExclusive
=
session
.
exclusive
;
console
.
log
(
0
);
}
);
}
};
this
.
getCamera
=
function
(
camera
)
{
return
isPresenting
()
?
cameraVR
:
camera
;
};
this
.
isPresenting
=
isPresenting
;
this
.
requestAnimationFrame
=
function
(
callback
)
{
console
.
log
(
1
);
function
onFrame
(
time
,
frame
)
{
pose
=
frame
.
getDevicePose
(
frameOfRef
);
var
layer
=
session
.
baseLayer
;
var
views
=
frame
.
views
;
for
(
var
i
=
0
;
i
<
views
.
length
;
i
++
)
{
var
view
=
views
[
i
];
var
viewport
=
layer
.
getViewport
(
view
);
var
viewMatrix
=
pose
.
getViewMatrix
(
view
);
var
camera
=
cameraVR
.
cameras
[
i
];
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
matrixWorldInverse
.
fromArray
(
viewMatrix
);
camera
.
matrixWorld
.
getInverse
(
camera
.
matrixWorldInverse
);
camera
.
viewport
.
set
(
viewport
.
x
,
viewport
.
y
,
viewport
.
width
,
viewport
.
height
);
if
(
i
===
0
)
{
cameraVR
.
matrixWorld
.
copy
(
camera
.
matrixWorld
);
cameraVR
.
matrixWorldInverse
.
copy
(
camera
.
matrixWorldInverse
);
// HACK (mrdoob)
// https://github.com/w3c/webvr/issues/203
cameraVR
.
projectionMatrix
.
copy
(
camera
.
projectionMatrix
);
}
}
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
session
.
baseLayer
.
framebuffer
);
callback
();
}
session
.
requestAnimationFrame
(
onFrame
);
};
this
.
submitFrame
=
function
()
{
// if ( device && device.isPresenting ) device.submitFrame();
};
}
export
{
WebXRManager
};
utils/build/externs.js
浏览文件 @
8f2c2fa0
...
...
@@ -5,3 +5,4 @@ var exports;
var
performance
;
var
createImageBitmap
;
var
WebGL2RenderingContext
;
var
XRWebGLLayer
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录