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 组件。

cs 复制代码
/
// 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;
        }
        
    }
}
cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.XR.PXR;

public class SeethroughManager : MonoBehaviour
{
    // 开启透视
    void Start()
    {
        PXR_Manager.EnableVideoSeeThrough = true;        
        
    }
}
相关推荐
omegayy14 小时前
Unity 2022.3.x部分Android设备播放视频黑屏问题
android·unity·视频播放·黑屏
与火星的孩子对话19 小时前
Unity3D开发AI桌面精灵/宠物系列 【三】 语音识别 ASR 技术、语音转文本多平台 - 支持科大讯飞、百度等 C# 开发
人工智能·unity·c#·游戏引擎·语音识别·宠物
向宇it20 小时前
【零基础入门unity游戏开发——2D篇】2D 游戏场景地形编辑器——TileMap的使用介绍
开发语言·游戏·unity·c#·编辑器·游戏引擎
牙膏上的小苏打23331 天前
Unity Surround开关后导致获取主显示器分辨率错误
unity·主屏幕
Unity大海2 天前
诠视科技Unity SDK开发环境配置、项目设置、apk打包。
科技·unity·游戏引擎
浅陌sss2 天前
Unity中 粒子系统使用整理(一)
unity·游戏引擎
维度攻城狮2 天前
实现在Unity3D中仿真汽车,而且还能使用ros2控制
python·unity·docker·汽车·ros2·rviz2
为你写首诗ge2 天前
【Unity网络编程知识】FTP学习
网络·unity
神码编程2 天前
【Unity】 HTFramework框架(六十四)SaveDataRuntime运行时保存组件参数、预制体
unity·编辑器·游戏引擎
菲fay2 天前
Unity 单例模式写法
unity·单例模式