Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
afa38487
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,发现更多精彩内容 >>
提交
afa38487
编写于
1月 30, 2017
作者:
M
Mr.doob
提交者:
GitHub
1月 30, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10679 from Mugen87/dev
Daydream: Controller and Example
上级
7d847de7
0fffe7e4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
363 addition
and
0 deletion
+363
-0
examples/files.js
examples/files.js
+1
-0
examples/js/vr/DaydreamController.js
examples/js/vr/DaydreamController.js
+108
-0
examples/webvr_daydream.html
examples/webvr_daydream.html
+254
-0
未找到文件。
examples/files.js
浏览文件 @
afa38487
...
...
@@ -272,6 +272,7 @@ var files = {
],
"
webvr
"
:
[
"
webvr_cubes
"
,
"
webvr_daydream
"
,
"
webvr_panorama
"
,
"
webvr_rollercoaster
"
,
"
webvr_shadow
"
,
...
...
examples/js/vr/DaydreamController.js
0 → 100644
浏览文件 @
afa38487
/**
* @author Mugen87 / https://github.com/Mugen87
*/
THREE
.
DaydreamController
=
function
()
{
THREE
.
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
touchpadIsPressed
=
false
;
var
angularVelocity
=
new
THREE
.
Vector3
();
this
.
matrixAutoUpdate
=
false
;
function
findGamepad
()
{
// iterate across gamepads as the Daydream Controller may not be in position 0
var
gamepads
=
navigator
.
getGamepads
();
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
!==
null
&&
(
gamepad
.
id
===
'
Daydream Controller
'
)
)
{
return
gamepad
;
}
}
}
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getTouchPadState
=
function
()
{
return
touchpadIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
();
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
if
(
pose
===
null
)
return
;
// no user action yet
var
pose
=
gamepad
.
pose
;
// orientation
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
updateMatrix
();
scope
.
visible
=
true
;
// angular velocity
if
(
pose
.
angularVelocity
!==
null
||
!
angularVelocity
.
equals
(
pose
.
angularVelocity
)
)
{
angularVelocity
.
fromArray
(
pose
.
angularVelocity
);
scope
.
dispatchEvent
(
{
type
:
'
angularvelocitychanged
'
,
angularVelocity
:
angularVelocity
}
);
}
// axes (touchpad)
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
axes
[
1
]
=
gamepad
.
axes
[
1
];
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
// button (touchpad)
if
(
touchpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
touchpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
touchpadIsPressed
?
'
touchpaddown
'
:
'
touchpadup
'
}
);
}
// app button not available, reserved for use by the browser
}
else
{
scope
.
visible
=
false
;
}
};
};
THREE
.
DaydreamController
.
prototype
=
Object
.
create
(
THREE
.
Object3D
.
prototype
);
THREE
.
DaydreamController
.
prototype
.
constructor
=
THREE
.
DaydreamController
;
examples/webvr_daydream.html
0 → 100644
浏览文件 @
afa38487
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webvr - daydream
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, user-scalable=no"
>
<style>
body
{
font-family
:
Monospace
;
background-color
:
#101010
;
color
:
#fff
;
margin
:
0px
;
overflow
:
hidden
;
}
a
{
color
:
#f00
;
}
</style>
</head>
<body>
<script
src=
"../build/three.js"
></script>
<script
src=
"js/controls/VRControls.js"
></script>
<script
src=
"js/effects/VREffect.js"
></script>
<script
src=
"js/vr/DaydreamController.js"
></script>
<script
src=
"js/vr/WebVR.js"
></script>
<script>
if
(
WEBVR
.
isAvailable
()
===
false
)
{
document
.
body
.
appendChild
(
WEBVR
.
getMessage
()
);
}
//
var
clock
=
new
THREE
.
Clock
();
var
container
;
var
camera
,
scene
,
ray
,
raycaster
,
renderer
;
var
effect
,
controls
,
gamepad
;
var
room
;
var
INTERSECTED
;
init
();
animate
();
function
init
()
{
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
var
info
=
document
.
createElement
(
'
div
'
);
info
.
style
.
position
=
'
absolute
'
;
info
.
style
.
top
=
'
10px
'
;
info
.
style
.
width
=
'
100%
'
;
info
.
style
.
textAlign
=
'
center
'
;
info
.
innerHTML
=
'
<a href="https://threejs.org" target="_blank">three.js</a> webvr - daydream
'
;
container
.
appendChild
(
info
);
scene
=
new
THREE
.
Scene
();
camera
=
new
THREE
.
PerspectiveCamera
(
70
,
window
.
innerWidth
/
window
.
innerHeight
,
0.1
,
10
);
scene
.
add
(
camera
);
room
=
new
THREE
.
Mesh
(
new
THREE
.
BoxGeometry
(
6
,
6
,
6
,
8
,
8
,
8
),
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x404040
,
wireframe
:
true
}
)
);
scene
.
add
(
room
);
scene
.
add
(
new
THREE
.
HemisphereLight
(
0x606060
,
0x404040
)
);
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
);
light
.
position
.
set
(
1
,
1
,
1
).
normalize
();
scene
.
add
(
light
);
var
geometry
=
new
THREE
.
BoxGeometry
(
0.15
,
0.15
,
0.15
);
for
(
var
i
=
0
;
i
<
200
;
i
++
)
{
var
object
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshLambertMaterial
(
{
color
:
Math
.
random
()
*
0xffffff
}
)
);
object
.
position
.
x
=
Math
.
random
()
*
4
-
2
;
object
.
position
.
y
=
Math
.
random
()
*
4
-
2
;
object
.
position
.
z
=
Math
.
random
()
*
4
-
2
;
object
.
rotation
.
x
=
Math
.
random
()
*
2
*
Math
.
PI
;
object
.
rotation
.
y
=
Math
.
random
()
*
2
*
Math
.
PI
;
object
.
rotation
.
z
=
Math
.
random
()
*
2
*
Math
.
PI
;
object
.
scale
.
x
=
Math
.
random
()
+
0.5
;
object
.
scale
.
y
=
Math
.
random
()
+
0.5
;
object
.
scale
.
z
=
Math
.
random
()
+
0.5
;
object
.
userData
.
velocity
=
new
THREE
.
Vector3
();
object
.
userData
.
velocity
.
x
=
Math
.
random
()
*
0.01
-
0.005
;
object
.
userData
.
velocity
.
y
=
Math
.
random
()
*
0.01
-
0.005
;
object
.
userData
.
velocity
.
z
=
Math
.
random
()
*
0.01
-
0.005
;
room
.
add
(
object
);
}
//
raycaster
=
new
THREE
.
Raycaster
();
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setClearColor
(
0x505050
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
sortObjects
=
false
;
container
.
appendChild
(
renderer
.
domElement
);
//
controls
=
new
THREE
.
VRControls
(
camera
);
effect
=
new
THREE
.
VREffect
(
renderer
);
if
(
navigator
.
getVRDisplays
)
{
navigator
.
getVRDisplays
()
.
then
(
function
(
displays
)
{
effect
.
setVRDisplay
(
displays
[
0
]
);
controls
.
setVRDisplay
(
displays
[
0
]
);
}
)
.
catch
(
function
()
{
// no displays
}
);
document
.
body
.
appendChild
(
WEBVR
.
getButton
(
effect
)
);
}
//
gamepad
=
new
THREE
.
DaydreamController
();
gamepad
.
position
.
set
(
0.25
,
-
0.5
,
0
);
scene
.
add
(
gamepad
);
//
var
gamepadHelper
=
new
THREE
.
Line
(
new
THREE
.
BufferGeometry
(),
new
THREE
.
LineBasicMaterial
(
{
linewidth
:
4
}
)
);
gamepadHelper
.
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
Float32BufferAttribute
(
[
0
,
0
,
0
,
0
,
0
,
-
10
],
3
)
);
gamepad
.
add
(
gamepadHelper
);
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
effect
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
//
function
animate
()
{
effect
.
requestAnimationFrame
(
animate
);
render
();
gamepad
.
update
();
}
function
render
()
{
var
delta
=
clock
.
getDelta
()
*
60
;
// find intersections
raycaster
.
ray
.
origin
.
copy
(
gamepad
.
position
);
raycaster
.
ray
.
direction
.
set
(
0
,
0
,
-
1
).
applyQuaternion
(
gamepad
.
quaternion
);
var
intersects
=
raycaster
.
intersectObjects
(
room
.
children
);
if
(
intersects
.
length
>
0
)
{
if
(
INTERSECTED
!=
intersects
[
0
].
object
)
{
if
(
INTERSECTED
)
INTERSECTED
.
material
.
emissive
.
setHex
(
INTERSECTED
.
currentHex
);
INTERSECTED
=
intersects
[
0
].
object
;
INTERSECTED
.
currentHex
=
INTERSECTED
.
material
.
emissive
.
getHex
();
INTERSECTED
.
material
.
emissive
.
setHex
(
0xff0000
);
}
}
else
{
if
(
INTERSECTED
)
INTERSECTED
.
material
.
emissive
.
setHex
(
INTERSECTED
.
currentHex
);
INTERSECTED
=
undefined
;
}
// keep cubes inside room
for
(
var
i
=
0
;
i
<
room
.
children
.
length
;
i
++
)
{
var
cube
=
room
.
children
[
i
];
cube
.
userData
.
velocity
.
multiplyScalar
(
1
-
(
0.001
*
delta
)
);
cube
.
position
.
add
(
cube
.
userData
.
velocity
);
if
(
cube
.
position
.
x
<
-
3
||
cube
.
position
.
x
>
3
)
{
cube
.
position
.
x
=
THREE
.
Math
.
clamp
(
cube
.
position
.
x
,
-
3
,
3
);
cube
.
userData
.
velocity
.
x
=
-
cube
.
userData
.
velocity
.
x
;
}
if
(
cube
.
position
.
y
<
-
3
||
cube
.
position
.
y
>
3
)
{
cube
.
position
.
y
=
THREE
.
Math
.
clamp
(
cube
.
position
.
y
,
-
3
,
3
);
cube
.
userData
.
velocity
.
y
=
-
cube
.
userData
.
velocity
.
y
;
}
if
(
cube
.
position
.
z
<
-
3
||
cube
.
position
.
z
>
3
)
{
cube
.
position
.
z
=
THREE
.
Math
.
clamp
(
cube
.
position
.
z
,
-
3
,
3
);
cube
.
userData
.
velocity
.
z
=
-
cube
.
userData
.
velocity
.
z
;
}
cube
.
rotation
.
x
+=
cube
.
userData
.
velocity
.
x
*
2
*
delta
;
cube
.
rotation
.
y
+=
cube
.
userData
.
velocity
.
y
*
2
*
delta
;
cube
.
rotation
.
z
+=
cube
.
userData
.
velocity
.
z
*
2
*
delta
;
}
controls
.
update
();
effect
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录