Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cqiang1993
AR.js
提交
aa9d201e
A
AR.js
项目概览
cqiang1993
/
AR.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AR.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aa9d201e
编写于
3月 11, 2017
作者:
J
Jerome Etienne
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
741932ff
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
3 addition
and
318 deletion
+3
-318
README.md
README.md
+3
-3
three.js/examples/markercache.html
three.js/examples/markercache.html
+0
-211
three.js/threex-armarkercache.js
three.js/threex-armarkercache.js
+0
-104
未找到文件。
README.md
浏览文件 @
aa9d201e
...
@@ -105,9 +105,9 @@ Three.js Examples:
...
@@ -105,9 +105,9 @@ Three.js Examples:
-
[
refraction
](
https://jeromeetienne.github.io/AR.js/three.js/examples/refraction.html
)
:
-
[
refraction
](
https://jeromeetienne.github.io/AR.js/three.js/examples/refraction.html
)
:
three.js example for refraction
three.js example for refraction
(
[
source
](
https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/refraction.html
)
)
(
[
source
](
https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/refraction.html
)
)
-
[
markerc
ache
](
https://jeromeetienne.github.io/AR.js/three.js/examples/markercache
.html
)
:
-
[
markerc
loak
](
https://jeromeetienne.github.io/AR.js/three.js/examples/markercloak
.html
)
:
three.js example for markerc
ache
three.js example for markerc
loak
(
[
source
](
https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/markerc
ache
.html
)
)
(
[
source
](
https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/markerc
loak
.html
)
)
a-frame Examples:
a-frame Examples:
...
...
three.js/examples/markercache.html
已删除
100644 → 0
浏览文件 @
741932ff
<!DOCTYPE html>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<!-- three.js library -->
<script
src=
'vendor/three.js/build/three.js'
></script>
<script
src=
"vendor/three.js/examples/js/libs/stats.min.js"
></script>
<!-- jsartookit -->
<script
src=
"../vendor/jsartoolkit5/build/artoolkit.min.js"
></script>
<script
src=
"../vendor/jsartoolkit5/js/artoolkit.api.js"
></script>
<!-- include threex.artoolkit -->
<script
src=
"../threex-artoolkitsource.js"
></script>
<script
src=
"../threex-artoolkitcontext.js"
></script>
<script
src=
"../threex-artoolkitprofile.js"
></script>
<script
src=
"../threex-armarkercontrols.js"
></script>
<script
src=
"../threex-armarkercache.js"
></script>
<body
style=
'margin : 0px; overflow: hidden; font-family: Monospace;'
><div
style=
'position: absolute; top: 10px; width:100%; text-align: center;z-index:1'
;
>
<a
href=
"https://github.com/jeromeetienne/AR.js/"
target=
"_blank"
>
AR.js
</a>
- developement playground
<br/>
Contact me any time at
<a
href=
'https://twitter.com/jerome_etienne'
target=
'_blank'
>
@jerome_etienne
</a>
</div><script>
//////////////////////////////////////////////////////////////////////////////////
// Init
//////////////////////////////////////////////////////////////////////////////////
// init renderer
var
renderer
=
new
THREE
.
WebGLRenderer
({
// antialias : true,
alpha
:
true
});
renderer
.
setClearColor
(
new
THREE
.
Color
(
'
lightgrey
'
),
0
)
// renderer.setPixelRatio( 2 );
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
domElement
.
style
.
position
=
'
absolute
'
renderer
.
domElement
.
style
.
top
=
'
0px
'
renderer
.
domElement
.
style
.
left
=
'
0px
'
document
.
body
.
appendChild
(
renderer
.
domElement
);
renderer
.
autoClear
=
false
;
// array of functions for the rendering loop
var
onRenderFcts
=
[];
// init scene and camera
var
scene
=
new
THREE
.
Scene
();
var
ambient
=
new
THREE
.
AmbientLight
(
0x666666
);
scene
.
add
(
ambient
);
var
directionalLight
=
new
THREE
.
DirectionalLight
(
0x887766
);
directionalLight
.
position
.
set
(
-
1
,
1
,
1
).
normalize
();
scene
.
add
(
directionalLight
);
//////////////////////////////////////////////////////////////////////////////////
// Initialize a basic camera
//////////////////////////////////////////////////////////////////////////////////
// Create a camera
var
camera
=
new
THREE
.
Camera
();
scene
.
add
(
camera
);
//////////////////////////////////////////////////////////////////////////////
// Code Separator
//////////////////////////////////////////////////////////////////////////////
var
orthoCamera
=
new
THREE
.
OrthographicCamera
(
-
1
,
1
,
1
,
-
1
,
-
100
,
+
100
);
var
orthoScene
=
new
THREE
.
Scene
();
////////////////////////////////////////////////////////////////////////////////
// handle arToolkitSource
////////////////////////////////////////////////////////////////////////////////
var
arToolkitSource
=
new
THREEx
.
ArToolkitSource
({
// to read from the webcam
sourceType
:
'
webcam
'
,
// to read from an image
// sourceType : 'image',
// sourceUrl : '../../data/images/img.jpg',
// to read from a video
// sourceType : 'video',
// sourceUrl : '../../data/videos/headtracking.mp4',
sourceWidth
:
80
*
3
,
sourceHeight
:
60
*
3
,
})
arToolkitSource
.
init
(
function
onReady
(){
console
.
log
(
'
source is ready
'
)
// handle resize of renderer
arToolkitSource
.
onResize
(
renderer
.
domElement
)
})
// handle resize
window
.
addEventListener
(
'
resize
'
,
function
(){
// handle arToolkitSource resize
arToolkitSource
.
onResize
(
renderer
.
domElement
)
})
////////////////////////////////////////////////////////////////////////////////
// initialize arToolkitContext
////////////////////////////////////////////////////////////////////////////////
// create atToolkitContext
var
arToolkitContext
=
new
THREEx
.
ArToolkitContext
({
cameraParametersUrl
:
'
../../data/data/camera_para.dat
'
,
detectionMode
:
'
mono
'
,
sourceWidth
:
arToolkitSource
.
parameters
.
sourceWidth
,
sourceHeight
:
arToolkitSource
.
parameters
.
sourceHeight
,
})
// initialize it
arToolkitContext
.
init
(
function
onCompleted
(){
// copy projection matrix to camera
camera
.
projectionMatrix
.
copy
(
arToolkitContext
.
getProjectionMatrix
()
);
})
// update artoolkit on every frame
onRenderFcts
.
push
(
function
(){
if
(
arToolkitSource
.
ready
===
false
)
return
arToolkitContext
.
update
(
arToolkitSource
.
domElement
)
})
////////////////////////////////////////////////////////////////////////////////
// Create a ArMarkerControls
////////////////////////////////////////////////////////////////////////////////
var
markerRoot
=
new
THREE
.
Group
scene
.
add
(
markerRoot
)
var
artoolkitMarker
=
new
THREEx
.
ArMarkerControls
(
arToolkitContext
,
markerRoot
,
{
type
:
'
pattern
'
,
patternUrl
:
'
../../data/data/patt.hiro
'
,
// patternUrl : '../../data/data/patt.kanji',
})
//////////////////////////////////////////////////////////////////////////////////
// add an object in the scene
//////////////////////////////////////////////////////////////////////////////////
// arToolkitSource.domElement.pause()
var
videoTexture
=
new
THREE
.
VideoTexture
(
arToolkitSource
.
domElement
)
// TODO to remove if webgl2
videoTexture
.
minFilter
=
THREE
.
NearestFilter
var
markerCache
=
new
THREEx
.
ArMarkerCache
(
videoTexture
);
markerRoot
.
add
(
markerCache
.
cacheMesh
)
orthoScene
.
add
(
markerCache
.
orthoMesh
)
onRenderFcts
.
push
(
function
(){
markerCache
.
update
(
markerRoot
.
matrix
,
camera
.
projectionMatrix
)
})
//////////////////////////////////////////////////////////////////////////////////
// add an object in the scene
//////////////////////////////////////////////////////////////////////////////////
// add a torus knot
var
geometry
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
material
=
new
THREE
.
MeshNormalMaterial
({
transparent
:
true
,
opacity
:
0.5
,
side
:
THREE
.
DoubleSide
});
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
z
=
geometry
.
parameters
.
height
/
2
markerRoot
.
add
(
mesh
);
var
geometry
=
new
THREE
.
TorusKnotGeometry
(
0.3
,
0.1
,
32
,
32
);
var
material
=
new
THREE
.
MeshNormalMaterial
();
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
z
=
0.5
markerRoot
.
add
(
mesh
);
onRenderFcts
.
push
(
function
(){
mesh
.
rotation
.
x
+=
0.1
})
//////////////////////////////////////////////////////////////////////////////////
// render the whole thing on the page
//////////////////////////////////////////////////////////////////////////////////
var
stats
=
new
Stats
();
// document.body.appendChild( stats.dom );
// render the scene
onRenderFcts
.
push
(
function
(){
renderer
.
clear
();
renderer
.
render
(
scene
,
camera
);
renderer
.
render
(
orthoScene
,
orthoCamera
);
stats
.
update
();
})
// run the rendering loop
var
lastTimeMsec
=
null
requestAnimationFrame
(
function
animate
(
nowMsec
){
// keep looping
requestAnimationFrame
(
animate
);
// measure time
lastTimeMsec
=
lastTimeMsec
||
nowMsec
-
1000
/
60
var
deltaMsec
=
Math
.
min
(
200
,
nowMsec
-
lastTimeMsec
)
lastTimeMsec
=
nowMsec
// call each update function
onRenderFcts
.
forEach
(
function
(
onRenderFct
){
onRenderFct
(
deltaMsec
/
1000
,
nowMsec
/
1000
)
})
})
</script></body>
three.js/threex-armarkercache.js
已删除
100644 → 0
浏览文件 @
741932ff
var
THREEx
=
THREEx
||
{}
THREEx
.
ArMarkerCache
=
function
(
videoTexture
){
var
material
=
new
THREE
.
MeshNormalMaterial
({
transparent
:
true
,
opacity
:
0.5
,
side
:
THREE
.
DoubleSide
});
var
geometry
=
new
THREE
.
PlaneGeometry
(
1
,
1
);
var
orthoMesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
this
.
orthoMesh
=
orthoMesh
var
geometry
=
new
THREE
.
PlaneGeometry
(
1.3
+
0.2
,
1.85
+
0.2
,
1
,
8
);
var
material
=
new
THREE
.
MeshBasicMaterial
({
transparent
:
true
,
opacity
:
0.5
,
side
:
THREE
.
DoubleSide
,
map
:
videoTexture
,
});
var
cacheMesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
cacheMesh
.
position
.
y
=
-
0.3
this
.
cacheMesh
=
cacheMesh
//////////////////////////////////////////////////////////////////////////////
// Code Separator
//////////////////////////////////////////////////////////////////////////////
var
xMin
=
-
0.65
var
xMax
=
0.65
var
yMin
=
0.75
var
yMax
=
1.05
var
originalUvs
=
[]
originalUvs
.
push
(
new
THREE
.
Vector3
(
xMin
,
yMax
,
0
))
originalUvs
.
push
(
new
THREE
.
Vector3
(
xMax
,
yMax
,
0
))
originalUvs
.
push
(
new
THREE
.
Vector3
(
xMin
,
yMin
,
0
))
originalUvs
.
push
(
new
THREE
.
Vector3
(
xMax
,
yMin
,
0
))
this
.
update
=
function
(
modelViewMatrix
,
cameraProjectionMatrix
){
var
transformedUvs
=
[]
originalUvs
.
forEach
(
function
(
originalUvs
,
index
){
var
transformedUv
=
originalUvs
.
clone
()
// apply modelViewMatrix and projectionMatrix
transformedUv
.
applyMatrix4
(
modelViewMatrix
)
transformedUv
.
applyMatrix4
(
cameraProjectionMatrix
)
// apply perspective
transformedUv
.
x
/=
transformedUv
.
z
transformedUv
.
y
/=
transformedUv
.
z
// store it
transformedUvs
.
push
(
transformedUv
)
})
// change orthoMesh vertices
for
(
var
i
=
0
;
i
<
transformedUvs
.
length
;
i
++
){
orthoMesh
.
geometry
.
vertices
[
i
].
copy
(
transformedUvs
[
i
])
}
orthoMesh
.
geometry
.
computeBoundingSphere
()
orthoMesh
.
geometry
.
verticesNeedUpdate
=
true
// change cacheMesh UVs
for
(
var
i
=
0
;
i
<
cacheMesh
.
geometry
.
parameters
.
heightSegments
/
2
;
i
++
){
// normale orientation
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
0
][
0
].
copy
(
convertUvs
(
0
,
1
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
0
][
1
].
copy
(
convertUvs
(
0
,
0
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
0
][
2
].
copy
(
convertUvs
(
1
,
1
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
1
][
0
].
copy
(
convertUvs
(
0
,
0
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
1
][
1
].
copy
(
convertUvs
(
1
,
0
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
1
][
2
].
copy
(
convertUvs
(
1
,
1
)
)
// swapy orientation
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
2
][
0
].
copy
(
convertUvs
(
0
,
0
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
2
][
1
].
copy
(
convertUvs
(
0
,
1
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
2
][
2
].
copy
(
convertUvs
(
1
,
0
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
3
][
0
].
copy
(
convertUvs
(
0
,
1
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
3
][
1
].
copy
(
convertUvs
(
1
,
1
)
)
cacheMesh
.
geometry
.
faceVertexUvs
[
0
][
i
*
4
+
3
][
2
].
copy
(
convertUvs
(
1
,
0
)
)
}
cacheMesh
.
geometry
.
uvsNeedUpdate
=
true
function
convertUvs
(
x
,
y
){
if
(
x
===
0
&&
y
===
0
){
var
transformedUv
=
transformedUvs
[
2
]
}
else
if
(
x
===
0
&&
y
===
1
){
var
transformedUv
=
transformedUvs
[
0
]
}
else
if
(
x
===
1
&&
y
===
1
){
var
transformedUv
=
transformedUvs
[
1
]
}
else
if
(
x
===
1
&&
y
===
0
){
var
transformedUv
=
transformedUvs
[
3
]
}
else
{
console
.
assert
(
false
)
}
var
Uv
=
new
THREE
.
Vector2
()
Uv
.
x
=
transformedUv
.
x
/
2
+
0.5
Uv
.
y
=
transformedUv
.
y
/
2
+
0.5
return
Uv
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录