稀疏空间地图的做用主要是定位,而稠密空间地图主要做用就是重建。利用RGB相机图像对周围环境进行三维稠密重建,获得稠密的点云地图和网格地图,再利用网络地图对虚拟物体实现遮挡和碰撞。html
稠密空间地图官方没有提供持久化的方法。bash
官方给出了稠密空间地图的介绍和使用建议。help.easyar.cn/EasyAR%20Se…网络
稠密空间地图结构很简单,在DenseSpatialMapBuilder游戏对象下,DenseSpatialMapBuilderFrameFilter脚本处理网络地图。ide
在场景中添加两个切换按钮(Toggle)。ui
添加一个球体,并给球体添加上刚体(Rigidbody)组件,以后将其拖成预制件(Prefab)。spa
添加脚本3d
当点击屏幕的时候,添加一个球体并给它一个向前的力。切换按钮(Toggle)RenderMesh和MeshColor属性。code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using easyar;
public class DenseController : MonoBehaviour
{
public GameObject prefab;
public DenseSpatialMapBuilderFrameFilter dense;
void Start()
{
dense.MeshColor = Color.gray;
}
void Update()
{
if (Input.GetMouseButtonDown(0) && Input.touchCount > 0
&& !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
var launchPoint = Camera.main.transform;
var ball = Instantiate(prefab, launchPoint.position, launchPoint.rotation);
var rigid = ball.GetComponent<Rigidbody>();
rigid.velocity = Vector3.zero;
rigid.AddForce(ray.direction * 15f + Vector3.up * 5f);
}
}
public void RenderMesh(bool show)
{
if (!dense)
{
return;
}
dense.RenderMesh = show;
}
public void TransparentMesh(bool trans)
{
if (!dense)
{
return;
}
if (trans)
{
dense.MeshColor = Color.gray;
}
else
{
dense.MeshColor = Color.clear;
}
}
}
复制代码
运行结果以下:orm
默认是将网格显示为灰色而且有阻挡效果。cdn
取消MeshColor选项后,网格变成透明的,看上去的效果就是真实物体对虚拟物体进行了阻挡。
取消Render选项后,没有了网格的效果,虚拟物体始终会在真实内容前方。