Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
715e7e8a
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,体验更适合开发者的 AI 搜索 >>
提交
715e7e8a
编写于
11月 27, 2019
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples: Added webxr_ar_paint.
上级
3734f616
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
349 addition
and
0 deletion
+349
-0
examples/files.js
examples/files.js
+1
-0
examples/jsm/webxr/ARButton.d.ts
examples/jsm/webxr/ARButton.d.ts
+7
-0
examples/jsm/webxr/ARButton.js
examples/jsm/webxr/ARButton.js
+173
-0
examples/webxr_ar_paint.html
examples/webxr_ar_paint.html
+168
-0
未找到文件。
examples/files.js
浏览文件 @
715e7e8a
...
...
@@ -323,6 +323,7 @@ var files = {
"
webaudio_visualizer
"
],
"
webxr
"
:
[
"
webxr_ar_paint
"
,
"
webxr_vr_ballshooter
"
,
"
webxr_vr_cubes
"
,
"
webxr_vr_dragging
"
,
...
...
examples/jsm/webxr/ARButton.d.ts
0 → 100644
浏览文件 @
715e7e8a
import
{
WebGLRenderer
}
from
'
../../../src/Three
'
;
export
namespace
ARButton
{
export
function
createButton
(
renderer
:
WebGLRenderer
):
HTMLElement
;
}
examples/jsm/webxr/ARButton.js
0 → 100644
浏览文件 @
715e7e8a
/**
* @author mrdoob / http://mrdoob.com
* @author Mugen87 / https://github.com/Mugen87
*/
var
ARButton
=
{
createButton
:
function
(
renderer
)
{
function
showEnterXR
(
/*device*/
)
{
var
currentSession
=
null
;
function
onSessionStarted
(
session
)
{
session
.
addEventListener
(
'
end
'
,
onSessionEnded
);
/*
session.updateWorldTrackingState( {
'planeDetectionState': { 'enabled': true }
} );
*/
renderer
.
vr
.
setReferenceSpaceType
(
'
local
'
);
renderer
.
vr
.
setSession
(
session
);
button
.
textContent
=
'
STOP AR
'
;
currentSession
=
session
;
}
function
onSessionEnded
(
/*event*/
)
{
currentSession
.
removeEventListener
(
'
end
'
,
onSessionEnded
);
renderer
.
vr
.
setSession
(
null
);
button
.
textContent
=
'
START AR
'
;
currentSession
=
null
;
}
//
button
.
style
.
display
=
''
;
button
.
style
.
cursor
=
'
pointer
'
;
button
.
style
.
left
=
'
calc(50% - 50px)
'
;
button
.
style
.
width
=
'
100px
'
;
button
.
textContent
=
'
START AR
'
;
button
.
onmouseenter
=
function
()
{
button
.
style
.
opacity
=
'
1.0
'
;
};
button
.
onmouseleave
=
function
()
{
button
.
style
.
opacity
=
'
0.5
'
;
};
button
.
onclick
=
function
()
{
if
(
currentSession
===
null
)
{
navigator
.
xr
.
requestSession
(
'
immersive-ar
'
).
then
(
onSessionStarted
);
}
else
{
currentSession
.
end
();
}
};
}
function
disableButton
()
{
button
.
style
.
display
=
''
;
button
.
style
.
cursor
=
'
auto
'
;
button
.
style
.
left
=
'
calc(50% - 75px)
'
;
button
.
style
.
width
=
'
150px
'
;
button
.
onmouseenter
=
null
;
button
.
onmouseleave
=
null
;
button
.
onclick
=
null
;
}
function
showXRNotFound
()
{
disableButton
();
button
.
textContent
=
'
XR NOT FOUND
'
;
}
function
stylizeElement
(
element
)
{
element
.
style
.
position
=
'
absolute
'
;
element
.
style
.
bottom
=
'
20px
'
;
element
.
style
.
padding
=
'
12px 6px
'
;
element
.
style
.
border
=
'
1px solid #fff
'
;
element
.
style
.
borderRadius
=
'
4px
'
;
element
.
style
.
background
=
'
rgba(0,0,0,0.1)
'
;
element
.
style
.
color
=
'
#fff
'
;
element
.
style
.
font
=
'
normal 13px sans-serif
'
;
element
.
style
.
textAlign
=
'
center
'
;
element
.
style
.
opacity
=
'
0.5
'
;
element
.
style
.
outline
=
'
none
'
;
element
.
style
.
zIndex
=
'
999
'
;
}
if
(
'
xr
'
in
navigator
)
{
var
button
=
document
.
createElement
(
'
button
'
);
button
.
style
.
display
=
'
none
'
;
stylizeElement
(
button
);
navigator
.
xr
.
isSessionSupported
(
'
immersive-ar
'
).
then
(
function
(
supported
)
{
if
(
supported
)
{
showEnterXR
();
}
else
{
showXRNotFound
();
}
}
);
return
button
;
}
else
{
var
message
=
document
.
createElement
(
'
a
'
);
message
.
href
=
'
https://immersive-web.github.io/webxr/
'
;
if
(
window
.
isSecureContext
===
false
)
{
message
.
innerHTML
=
'
WEBXR NEEDS HTTPS
'
;
// TODO Improve message
}
else
{
message
.
innerHTML
=
'
WEBXR NOT AVAILABLE
'
;
}
message
.
style
.
left
=
'
calc(50% - 90px)
'
;
message
.
style
.
width
=
'
180px
'
;
message
.
style
.
textDecoration
=
'
none
'
;
stylizeElement
(
message
);
return
message
;
}
}
};
export
{
ARButton
};
examples/webxr_ar_paint.html
0 → 100644
浏览文件 @
715e7e8a
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js ar - paint
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, user-scalable=no"
>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"main.css"
>
<!-- WebXR Device API (For Chrome M76+), expires 12/04/2019 -->
<meta
http-equiv=
"origin-trial"
content=
"Aq9LklhCLNUveuCr7QTpGpqwCPG817cYHdVyQuJPOZYk47iRB390lUKa5edVmgS1pZSl8HPspElEC/91Fz55dwIAAABTeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZU03NiIsImV4cGlyeSI6MTU3NTQxNzU5OX0="
>
</head>
<body>
<div
id=
"info"
>
<a
href=
"https://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
ar - paint
</div>
<script
type=
"module"
>
import
*
as
THREE
from
'
../build/three.module.js
'
;
import
{
TubePainter
}
from
'
./jsm/misc/TubePainter.js
'
;
import
{
ARButton
}
from
'
./jsm/webxr/ARButton.js
'
;
var
container
;
var
camera
,
scene
,
renderer
;
var
controller
,
painter
;
var
up
=
new
THREE
.
Vector3
(
0
,
1
,
0
);
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" rel="noopener">three.js</a> ar - paint<br/>Enable chrome://flags/#webxr-ar-module<br/>(Chrome 80+)
'
;
container
.
appendChild
(
info
);
scene
=
new
THREE
.
Scene
();
camera
=
new
THREE
.
PerspectiveCamera
(
70
,
window
.
innerWidth
/
window
.
innerHeight
,
0.01
,
20
);
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
alpha
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
vr
.
enabled
=
true
;
container
.
appendChild
(
renderer
.
domElement
);
//
document
.
body
.
appendChild
(
ARButton
.
createButton
(
renderer
)
);
// model
var
light
=
new
THREE
.
HemisphereLight
(
0xffffff
,
0xbbbbff
,
1
);
light
.
position
.
set
(
0
,
1
,
0
);
scene
.
add
(
light
);
//
painter
=
new
TubePainter
();
painter
.
setSize
(
0.4
);
painter
.
mesh
.
material
.
side
=
THREE
.
DoubleSide
;
scene
.
add
(
painter
.
mesh
);
//
function
onSelectStart
()
{
this
.
userData
.
isSelecting
=
true
;
this
.
userData
.
skipFrames
=
2
;
}
function
onSelectEnd
()
{
this
.
userData
.
isSelecting
=
false
;
}
controller
=
renderer
.
vr
.
getController
(
0
);
controller
.
addEventListener
(
'
selectstart
'
,
onSelectStart
);
controller
.
addEventListener
(
'
selectend
'
,
onSelectEnd
);
controller
.
userData
.
points
=
[
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
()
];
controller
.
userData
.
matrices
=
[
new
THREE
.
Matrix4
(),
new
THREE
.
Matrix4
()
];
controller
.
userData
.
skipFrames
=
0
;
scene
.
add
(
controller
);
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
//
function
handleController
(
controller
)
{
var
userData
=
controller
.
userData
;
var
point1
=
userData
.
points
[
0
];
var
point2
=
userData
.
points
[
1
];
var
matrix1
=
userData
.
matrices
[
0
];
var
matrix2
=
userData
.
matrices
[
1
];
point1
.
set
(
0
,
0
,
-
0.2
).
applyMatrix4
(
controller
.
matrixWorld
);
matrix1
.
lookAt
(
point2
,
point1
,
up
);
if
(
userData
.
isSelecting
===
true
)
{
if
(
userData
.
skipFrames
>=
0
)
{
// TODO(mrdoob) Revisit this
userData
.
skipFrames
--
;
}
else
{
var
count
=
painter
.
mesh
.
geometry
.
drawRange
.
count
;
painter
.
stroke
(
point1
,
point2
,
matrix1
,
matrix2
);
painter
.
updateGeometry
(
count
,
painter
.
mesh
.
geometry
.
drawRange
.
count
);
}
}
point2
.
copy
(
point1
);
matrix2
.
copy
(
matrix1
);
}
function
animate
()
{
renderer
.
setAnimationLoop
(
render
);
}
function
render
()
{
handleController
(
controller
);
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录