Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cqiang1993
AR.js
提交
4fd3d4bd
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,发现更多精彩内容 >>
提交
4fd3d4bd
编写于
4月 25, 2017
作者:
J
Jerome Etienne
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
ff37bdba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
133 deletion
+27
-133
three.js/examples/multimarker-custom/threex-armultimarkercontrols.js
...amples/multimarker-custom/threex-armultimarkercontrols.js
+25
-132
three.js/examples/multimarker-custom/threex-armultimarkerlearning.js
...amples/multimarker-custom/threex-armultimarkerlearning.js
+2
-1
未找到文件。
three.js/examples/multimarker-custom/threex-armultimarkercontrols.js
浏览文件 @
4fd3d4bd
var
THREEx
=
THREEx
||
{}
var
THREEx
=
THREEx
||
{}
THREEx
.
ArMultiMarkerControls
=
function
(
object3d
,
markersControls
,
markersPose
){
THREEx
.
ArMultiMarkerControls
=
function
(
object3d
,
markersControls
,
markersPose
){
var
_this
=
this
var
_this
=
this
...
@@ -55,9 +53,6 @@ THREEx.ArMultiMarkerControls.fromJSON = function(arToolkitContext, scene, marker
...
@@ -55,9 +53,6 @@ THREEx.ArMultiMarkerControls.fromJSON = function(arToolkitContext, scene, marker
return
multiMarkerControls
return
multiMarkerControls
}
}
// (nElement/(nElements+1))(averageValue + newValue/nElements)*
//
/**
/**
* from http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
* from http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
*/
*/
...
@@ -110,29 +105,21 @@ THREEx.ArMultiMarkerControls.averageVector3 = function(vector3Sum, vector3, coun
...
@@ -110,29 +105,21 @@ THREEx.ArMultiMarkerControls.averageVector3 = function(vector3Sum, vector3, coun
*/
*/
THREEx
.
ArMultiMarkerControls
.
prototype
.
_onSourceProcessed
=
function
(){
THREEx
.
ArMultiMarkerControls
.
prototype
.
_onSourceProcessed
=
function
(){
var
_this
=
this
var
_this
=
this
var
positionSum
=
new
THREE
.
Vector3
()
var
stats
=
{
var
positionAverage
=
new
THREE
.
Vector3
()
countVisible
:
0
,
var
quaternionSum
=
new
THREE
.
Quaternion
(
0
,
0
,
0
,
0
)
position
:
{
var
quaternionAverage
=
new
THREE
.
Quaternion
(
0
,
0
,
0
,
0
)
sum
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
var
scaleSum
=
new
THREE
.
Vector3
average
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
var
scaleAverage
=
new
THREE
.
Vector3
},
var
countVisible
=
0
quaternion
:
{
sum
:
new
THREE
.
Quaternion
(
0
,
0
,
0
,
0
),
// var data = {
average
:
new
THREE
.
Quaternion
(
0
,
0
,
0
,
0
),
// countVisible: 0,
},
// position : {
scale
:
{
// sum: new THREE.Vector3(0,0,0),
sum
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
// average: new THREE.Vector3(0,0,0),
average
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
// },
},
// quaternion : {
}
// sum: new THREE.Quaternion(0,0,0,0),
// average: new THREE.Quaternion(0,0,0,0),
// },
// scale : {
// sum: new THREE.Vector3(0,0,0),
// average: new THREE.Vector3(0,0,0),
// },
// }
var
firstQuaternion
=
_this
.
markersControls
[
0
].
object3d
.
quaternion
var
firstQuaternion
=
_this
.
markersControls
[
0
].
object3d
.
quaternion
...
@@ -154,33 +141,22 @@ THREEx.ArMultiMarkerControls.prototype._onSourceProcessed = function(){
...
@@ -154,33 +141,22 @@ THREEx.ArMultiMarkerControls.prototype._onSourceProcessed = function(){
matrix
.
decompose
(
position
,
quaternion
,
scale
)
matrix
.
decompose
(
position
,
quaternion
,
scale
)
// http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
// http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
countVisible
++
stats
.
countVisible
++
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
positionSum
,
position
,
countVisible
,
positionAverage
)
THREEx
.
ArMultiMarkerControls
.
averageQuaternion
(
quaternionSum
,
quaternion
,
firstQuaternion
,
countVisible
,
quaternionAverage
)
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
scaleSum
,
scale
,
countVisible
,
scaleAverage
)
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
stats
.
position
.
sum
,
position
,
stats
.
countVisible
,
stats
.
position
.
average
)
THREEx
.
ArMultiMarkerControls
.
averageQuaternion
(
stats
.
quaternion
.
sum
,
quaternion
,
firstQuaternion
,
stats
.
countVisible
,
stats
.
quaternion
.
average
)
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
stats
.
scale
.
sum
,
scale
,
stats
.
countVisible
,
stats
.
scale
.
average
)
})
})
// if at least one sub-marker has been detected, make the average of all detected markers
// if at least one sub-marker has been detected, make the average of all detected markers
if
(
countVisible
>
0
){
if
(
stats
.
countVisible
>
0
){
_this
.
object3d
.
position
.
copy
(
stats
.
position
.
average
)
// var lerpPosition = 0.3
_this
.
object3d
.
quaternion
.
copy
(
stats
.
quaternion
.
average
)
// var lerpQuaternion = 0.6
_this
.
object3d
.
scale
.
copy
(
stats
.
scale
.
average
)
// var lerpScale = 0.6
// var position = _this.object3d.position.clone().lerp(positionAverage, lerpPosition)
// var quaternion = _this.object3d.quaternion.clone().slerp(quaternionAverage, lerpQuaternion)
// var scale = _this.object3d.scale.clone().lerp(scaleAverage, lerpScale)
// _this.object3d.position.copy(position)
// _this.object3d.scale.copy(scale)
// _this.object3d.quaternion.copy(quaternion)
_this
.
object3d
.
position
.
copy
(
positionAverage
)
_this
.
object3d
.
quaternion
.
copy
(
quaternionAverage
)
_this
.
object3d
.
scale
.
copy
(
scaleAverage
)
}
}
// honor _this.object3d.visible
// honor _this.object3d.visible
if
(
countVisible
>
0
){
if
(
stats
.
countVisible
>
0
){
_this
.
object3d
.
visible
=
true
_this
.
object3d
.
visible
=
true
// dispatchEvent
// dispatchEvent
_this
.
dispatchEvent
(
{
type
:
'
markerFound
'
}
);
_this
.
dispatchEvent
(
{
type
:
'
markerFound
'
}
);
...
@@ -188,86 +164,3 @@ THREEx.ArMultiMarkerControls.prototype._onSourceProcessed = function(){
...
@@ -188,86 +164,3 @@ THREEx.ArMultiMarkerControls.prototype._onSourceProcessed = function(){
_this
.
object3d
.
visible
=
false
_this
.
object3d
.
visible
=
false
}
}
}
}
// /**
// * What to do when a image source is fully processed
// */
// THREEx.ArMultiMarkerControls.prototype._onSourceProcessed = function(){
// var _this = this
// var positionSum = new THREE.Vector3
// var quaternionSum = new THREE.Quaternion(0,0,0,0)
// var scaleSum = new THREE.Vector3
// var countVisible = 0
//
// this.markersControls.forEach(function(markerControls, markerIndex){
//
// var object3d = markerControls.object3d
// // if this marker is not visible, ignore it
// if( object3d.visible === false ) return
//
// // transformation matrix of this.object3d according to this sub-markers
// var matrix = object3d.matrix.clone()
// var markerPose = _this.markersPose[markerIndex]
// matrix.multiply(markerPose)
//
// // decompose the matrix into .position, .quaternion, .scale
// var position = new THREE.Vector3
// var quaternion = new THREE.Quaternion()
// var scale = new THREE.Vector3
// matrix.decompose(position, quaternion, scale)
//
// // http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
// countVisible++
// positionSum.add(position)
// scaleSum.add(scale)
//
// // from http://wiki.unity3d.com/index.php/Averaging_Quaternions_and_Vectors
// if( _this.markersControls[0].object3d.quaternion.dot(quaternion) > 0 ){
// quaternion = new THREE.Quaternion(-quaternion.x, -quaternion.y, -quaternion.z, -quaternion.w)
// }
//
// quaternionSum.x += quaternion.x
// quaternionSum.y += quaternion.y
// quaternionSum.z += quaternion.z
// quaternionSum.w += quaternion.w
// })
//
// // if at least one sub-marker has been detected, make the average of all detected markers
// if( countVisible > 0 ){
//
// // average position
// var targetPosition = new THREE.Vector3().copy( positionSum ).multiplyScalar( 1/countVisible )
// // average quaternion
// var targetQuaternion = new THREE.Quaternion().copy(quaternionSum)
// targetQuaternion.x /= countVisible
// targetQuaternion.y /= countVisible
// targetQuaternion.z /= countVisible
// targetQuaternion.w /= countVisible
// // average scale
// var targetScale = new THREE.Vector3().copy( scaleSum ).multiplyScalar( 1/countVisible )
//
//
// var lerpPosition = 0.3
// var lerpQuaternion = 0.6
// var lerpScale = 0.6
// var position = _this.object3d.position.clone().lerp(targetPosition, lerpPosition)
// var quaternion = _this.object3d.quaternion.clone().slerp(targetQuaternion, lerpQuaternion)
// var scale = _this.object3d.scale.clone().lerp(targetScale, lerpScale)
// _this.object3d.position.copy(position)
// _this.object3d.scale.copy(scale)
// _this.object3d.quaternion.copy(quaternion)
//
// // _this.object3d.position.copy(targetPosition)
// // _this.object3d.quaternion.copy(targetQuaternion)
// // _this.object3d.scale.copy(targetScale)
// }
//
// // honor _this.object3d.visible
// if( countVisible > 0 ){
// _this.object3d.visible = true
// // dispatchEvent
// _this.dispatchEvent( { type: 'markerFound' } );
// }else{
// _this.object3d.visible = false
// }
// }
three.js/examples/multimarker-custom/threex-armultimarkerlearning.js
浏览文件 @
4fd3d4bd
...
@@ -41,6 +41,7 @@ THREEx.ArMultiMakersLearning.prototype.toJSON = function(){
...
@@ -41,6 +41,7 @@ THREEx.ArMultiMakersLearning.prototype.toJSON = function(){
data
.
markersControls
.
push
({
data
.
markersControls
.
push
({
parameters
:
{
parameters
:
{
// TODO here be more generic, what about bar code
// TODO here be more generic, what about bar code
// - depends on the
type
:
markerControls
.
parameters
.
type
,
type
:
markerControls
.
parameters
.
type
,
patternUrl
:
markerControls
.
parameters
.
patternUrl
,
patternUrl
:
markerControls
.
parameters
.
patternUrl
,
},
},
...
@@ -145,7 +146,7 @@ THREEx.ArMultiMakersLearning.prototype._onSourceProcessed = function(){
...
@@ -145,7 +146,7 @@ THREEx.ArMultiMakersLearning.prototype._onSourceProcessed = function(){
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
var
stats
=
multiMarkerStats
[
markerControls2
.
id
]
var
stats
=
multiMarkerStats
[
markerControls2
.
id
]
// update the count
// update the count
stats
.
count
++
stats
.
count
++
// update the average of position/rotation/scale
// update the average of position/rotation/scale
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
stats
.
position
.
sum
,
positionDelta
,
stats
.
count
,
stats
.
position
.
average
)
THREEx
.
ArMultiMarkerControls
.
averageVector3
(
stats
.
position
.
sum
,
positionDelta
,
stats
.
count
,
stats
.
position
.
average
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录