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;        
        
    }
}
相关推荐
咩咩觉主1 小时前
尽量通俗易懂地概述.Net && U nity跨语言/跨平台相关知识
unity·c#·.net·.netcore
墨笺染尘缘2 小时前
Unity——对RectTransform进行操作
ui·unity·c#·游戏引擎
AgilityBaby2 小时前
FairyGUI和Unity联动(入门篇)
unity·游戏引擎
一步一个foot-print15 小时前
C# unity 星期几 年月日控制
unity·c#
无敌最俊朗@21 小时前
unity3d————Sprite(精灵图片)
学习·游戏·unity·c#·游戏引擎
声网1 天前
脑机接口、嵌入式 AI 、工业级 MR、空间视频和下一代 XR 浏览器丨RTE2024 空间计算和新硬件专场回顾
人工智能·音视频·mr
皮皮陶1 天前
Unity WebGL交互通信
unity·交互·webgl
程序员正茂1 天前
PICO+Unity MR空间锚点
unity·pico·空间锚点
三菱-Liu1 天前
三菱MR-J4-B伺服连接器和信号排列
网络·驱动开发·硬件工程·制造·mr