当前位置: 首页 > article >正文

PICO+Unity MR空间网格

官方链接:空间网格 | PICO 开发者平台

注意:该功能只能打包成APK在PICO 4 Ultra上真机运行,无法通过串流或PICO developer center在PC上运行。使用之前要开启视频透视。

Inspector 窗口中的 PXR_Manager (Script) 面板上,勾选 Spatial Mesh 选框。

新建一个空物体名为SpatialMesh,添加PXR_Spatial Mesh Manager组件(生成网格)、SeethroughManager代码(开启透视)、SpatialMesh代码(发射球)

PXR_Spatial Mesh Manager中的Mesh Prefab 至少需要包含 Mesh Filter 组件。如果想显示扫描到的网格,则还需包含 Mesh Renderer 组件。

/
// Copyright (c) 2024 PICO Developer
// SPDX-License-Identifier: MIT
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;

public class SpatialMesh : MonoBehaviour
{
    public Text text;
    private static SpatialMesh _instance = null;
    public GameObject gun;
    public GameObject ballPrefab;
    public Transform firePoint;
    public static SpatialMesh Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType<SpatialMesh>();
            }
            return _instance;
        }
    }

    int pressCount = 0;
    bool _previousTrigger = false;
    private void Update()
    {
        var rightHandDevice = UnityEngine.XR.InputDevices.GetDeviceAtXRNode(UnityEngine.XR.XRNode.RightHand);
        // 获取扳机键是否被按下
        bool triggerValue;
        bool suc = rightHandDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out triggerValue);
        if(suc)
        {
            if (triggerValue != _previousTrigger && triggerValue)
            {
                Debug.Log("Trigger button is pressed.");
                pressCount++;
                if (pressCount > 10000)
                {
                    pressCount = 0;
                }
                text.text = pressCount.ToString();

                var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                obj.transform.position = firePoint.position;
                obj.SetActive(true);
                obj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                obj.AddComponent<Rigidbody>().velocity = gun.transform.forward*10;
            }
            _previousTrigger = triggerValue;
        }
        
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.XR.PXR;

public class SeethroughManager : MonoBehaviour
{
    // 开启透视
    void Start()
    {
        PXR_Manager.EnableVideoSeeThrough = true;        
        
    }
}


http://www.kler.cn/a/385634.html

相关文章:

  • 【LeetCode】【算法】19. 删除链表的倒数第N个结点
  • Iceberg 写入和更新模式,COW,MOR(Copy-on-Write,Merge-on-Read)
  • 【大数据学习 | HBASE高级】region split机制和策略
  • Leetcode 找出字符串中第一个匹配项的下标
  • SwiftUI(十)- 列表(分组,折叠)
  • go生成4位随机数字
  • GPT对NLP的冲击
  • Multi Agents协作机制设计及实践
  • 下载mysql的jar,添加至jmeter中,编写jdbc协议脚本1106
  • 详解Windows 11 上 CUDA 与 PyTorch 版本的兼容性
  • 内网通过公网地址访问内网服务器的设置方法
  • 前端零基础学习Day-Seven
  • Excel(图例)中使用上标下标
  • MQ的基础知识
  • 带webui的免费SSL证书管理工具
  • Docker + Python
  • 开源 - Ideal库 - 常用时间转换扩展方法(二)
  • Monkey测试
  • 重学SpringBoot3-整合 Elasticsearch 8.x (三)使用Repository
  • 知识中台赋能法律咨询服务:八大核心优势
  • OCC 拟合的平面转换为有界平面
  • AI-Prompt、RAG、微调还是重新训练?选择正确的生成式AI的使用方法
  • Jmeter的安装和使用
  • qt QFileDialog详解
  • 负载均衡式在线oj项目开发文档(个人项目)
  • 缓存、注解、分页