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;        
        
    }
}
相关推荐
橘子遇见BUG3 小时前
Unity Shader学习日记 part 3 线性代数--矩阵变换
学习·线性代数·unity·矩阵·图形渲染
Artistation Game6 小时前
一、c#基础
游戏·unity·c#·游戏引擎
成都渲染101云渲染66667 小时前
云渲染,Enscape、D5、Lumion渲染提速教程
运维·服务器·unity·电脑·图形渲染·blender·houdini
超龄魔法少女1 天前
[Unity] ShaderGraph动态修改Keyword Enum,实现不同效果一键切换
unity·技术美术·shadergraph
蔗理苦1 天前
2024-12-24 NO1. XR Interaction ToolKit 环境配置
unity·quest3·xr toolkit
花生糖@1 天前
Android XR 应用程序开发 | 从 Unity 6 开发准备到应用程序构建的步骤
android·unity·xr·android xr
向宇it1 天前
【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
开发语言·unity·c#·编辑器·游戏引擎
向宇it1 天前
【从零开始入门unity游戏开发之——unity篇01】unity6基础入门开篇——游戏引擎是什么、主流的游戏引擎、为什么选择Unity
开发语言·unity·c#·游戏引擎
向宇it2 天前
【从零开始入门unity游戏开发之——C#篇26】C#面向对象动态多态——接口(Interface)、接口里氏替换原则、密封方法(`sealed` )
java·开发语言·unity·c#·游戏引擎·里氏替换原则
神码编程2 天前
【Unity功能集】TextureShop纹理工坊(五)选区
unity·游戏引擎·shader·ps选区