ar.js - AR.js 是否可以更新 gps-entity-place 的位置?
问题描述
AR.js 中是否可以通过修改其经度和纬度来移动放置在 gps-entity-place 的对象?
我试图更改实体的属性“gps-entity-place”。它第一次工作,但之后失败。
解决方案
gps-entity-place
是只读属性
具有只读属性的实例化对象必须在显示它们之前准备好:
- 通过 HTTPS 提供要点。
geolocation
不是很准确,这里的改进可以改善场景放置。createAttribute
可用于非标准属性,带有连字符,如gps-entity-place
.gps.value
用于在与 一起应用它们之前设置值setAttributeNode
。- 调整文本,即
position="[-l 0 +r] [-lower 0 +higher] [-front 0 +behind]"
向左、垂直和远离。welcome
-30
0
-150
- 使用这种快速而肮脏的估计来定位世界空间中的测试实体。
演示:markerless.html
在控制台中,实体a-scene
显示markerless.html
设备位置 AR:
<!doctype html>
<html>
<head>
<link rel="canonical" href="https://inspiredlabs.github.io/ar.js/markerless.html" />
<!-- location based aframe v0.9.2 -->
<script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script><!-- debug -->
<script>
const log = console.log;
window.onload = () => {
let scene = document.querySelector('a-scene'); /* Apply to whole scene */
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
let gps = document.createAttribute('gps-entity-place'),
arjs = document.createAttribute('arjs'),
welcome = document.getElementById('welcome');
arjs.value = 'sourceType: webcam; sourceWidth: 1280; sourceHeight: 960; trackingMethod: best; debugUIEnabled: false;';
gps.value = `latitude: ${position.coords.latitude - 0.001}; longitude: ${position.coords.longitude + 0.001}`;
log(gps.value);
scene.setAttributeNode(gps); /* Apply to whole scene */
scene.setAttributeNode(arjs);
});
}
};
</script>
</head>
<a-scene vr-mode-ui="enabled: false">
<a-entity id="wrapper" position="0 -8 0">
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" shadow></a-box>
<a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E" shadow></a-sphere>
<a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D" shadow></a-cylinder>
<a-plane position="0 0 -5.0" rotation="-90 0 0" width="7" height="7" color="#7BC8A4" shadow></a-plane>
<a-text id="welcome" value="Welcome" scale="75 75 75" color="#000000" position="-30 0 -150"></a-text>
<!-- look-at="[gps-camera]" -->
</a-entity><!-- /wrapper -->
<a-camera camera="fov: 60;" gps-camera rotation-reader></a-camera>
</a-scene>
</body>
</html>
如果您正在寻找不同的对象方法来创建属性,您可以查看Object.defineProperties()
.
参考:
推荐阅读
- c# - ASP.NET Core 创建的签名在 Delphi 2007 中未验证
- routes - API 和路由/端点有什么区别?
- android - 如何制作使用 jni 打开 /dev/video* 或其他系统文件的 android 系统应用程序?
- oracle - 为什么 ora-archive-state 列是 varchar2 4000 字符?
- bazel - 为气隙环境创建 Bazel 归档 tar
- spring-boot - GraalVM 上的热重载
- python-3.x - 使用 Imagecodecs Python 库时将 TIFF 文件转换为 JPEG 会出错
- redux - 调用 useEffect() 时 Redux 操作(从 db 获取)未触发
- c# - 如何在 .Net Core 中根据环境控制 appsettings.json 部署
- javascript - 关闭过滤的 v-treeview 节点很慢,有很多项目