zspace初级教程

  1. 先检查电脑配置(一下是最低要求)

https://support.zspace.com/hc/en-us/articles/204780665-zSpace-System-Requirements

处理器:Intel i3-4370

内存:8GB RAM

显卡:AMD FirePro W5170M GPU

硬盘:128GB以上

或者你还可以下载一个zspace系统配置检查,就是它啦

https://zspace.com/downloads

 

 

2.满足要求了,打开显卡设置,NVIDIA控制面板—》3D设置—》管理3D设置—》立体-启用—》开

 

NOW 现在你就可以去官方下载一个demo试试效果了,地址

https://zspace.com/downloads

3.看完官方的demo之后,有木有心动,是不是也想自己动手做一个,好的,本菜鸟看完之后就想自己做一个,继续往下走

4.安装完unity3d后,我安装的版本是unity3d2017.1.0p5,其余的版本类似,进入zspace官方,下载两个开发包

http://developer.zspace.com/downloads

 

   

第一个直接安装,第二个导入unity3d

 

5.导入之后,在资源里边找到zCore,将zCore拖入Hierarchy窗口

6.找到Inspector属性面板-》shereo Carmera-》current Camera将Main Camera为其赋值

 

7.接下来,很重要一步,有了它,立体效果才会出现Edit->Project Settings->Player-Settings for PC->Other Settings->Rendering->Virtual Reality SDKs添加 Stereo Display

 

8.接下来进入开发阶段,向场景中拖入一个cube,在创建一个空物体,将RayGrapGameObject拖到空物体下,RayGrapGameObject代码如下

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using zSpace.Core;

public class RayGrapGameObject : MonoBehaviour {
    private GameObject _stylusBeamObject=null;
    private LineRenderer _stylusBeamRenderer=null;
    //private StylusState RayGrapGameObject.Ra_stylusState = StylusState.Idle;
    private StylusState _stylusState = StylusState.Idle;

    // Use this for initialization(初始化)
    private ZCore _zCore = null;
    private bool _wasButtonPressed = false;

    private static readonly float DEFAULT_STYLUS_BEAM_WIDTH = 0.0002f;
    private static readonly float DEFAULT_STYLUS_BEAM_LENGTH = 0.3f;

    private float _stylusBeamLength = DEFAULT_STYLUS_BEAM_LENGTH;
    private GameObject _grabObject=null;
    private Vector3 _initialGrabOffset = Vector3.zero;
    private Quaternion _initialGrabRotation=Quaternion.identity;
    private float _initialGrabDistance = 0.0f;

    public GameObject Cube;

    void Start()
    {
        _zCore = GameObject.FindObjectOfType<ZCore>();
        if (_zCore == null)
        {
            Debug.LogError("无法找到参考");
            this.enabled = false;
            return;
        }

        //创建触控笔对象
        _stylusBeamObject = new GameObject("StylusBeam");
        _stylusBeamRenderer = _stylusBeamObject.AddComponent<LineRenderer>();
        _stylusBeamRenderer.material = new Material(Shader.Find("Transparent/Diffuse"));

        _stylusBeamRenderer.startColor = Color.green;
        _stylusBeamRenderer.endColor = Color.black;
    }

    void Update()
    {
        //获取触控笔按钮状态信息
        ZCore.Pose pose = _zCore.GetTargetPose(ZCore.TargetType.Primary,ZCore.CoordinateSpace.World);
        bool isButtonPressed = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary,0);

        switch (_stylusState)
        {
            case StylusState.Idle:
                {
                    _stylusBeamLength = DEFAULT_STYLUS_BEAM_WIDTH;
                    RaycastHit hit;
                    if (Physics.Raycast(pose.Position, pose.Direction, out hit))
                    {
                        _stylusBeamLength = hit.distance / _zCore.ViewerScale;     
                        if (isButtonPressed && !_wasButtonPressed)
                        {
                            Cube.GetComponent<Renderer>().material.color = Color.red;
                            //开始抓取
                            this.BeginGrab(hit.collider.gameObject, hit.distance, pose.Position, pose.Rotation);
                            _stylusState = StylusState.Grab;
                        }
                    }
                }
                break;

            case StylusState.Grab:
                {
                    //抓取
                    this.UpdateGrab(pose.Position, pose.Rotation);
                    //如果前面的触控笔按钮被释放,就结束抓取
                    if (!isButtonPressed && _wasButtonPressed)
                    {
                        _stylusState = StylusState.Idle;
                        Cube.GetComponent<Renderer>().material.color = Color.white;
                    }
                }
                break;

            default:
                break;
        }
        //更新光线
        this.UpdateStylusBeam(pose.Position, pose.Direction);
        _wasButtonPressed = isButtonPressed;
    }

    private void UpdateStylusBeam(Vector3 stylusPosition, Vector3 stylusDirection)
    {
        if (_stylusBeamRenderer != null)
        {
            float stylusBeamWidth = DEFAULT_STYLUS_BEAM_WIDTH * _zCore.ViewerScale;
            float stylusBeamLength = _stylusBeamLength * _zCore.ViewerScale;

            #if UNITY_5_4
                            _stylusBeamRenderer.SetWidth(stylusBeamWidth, stylusBeamWidth);
            #else
                        _stylusBeamRenderer.startWidth = stylusBeamWidth;
                        _stylusBeamRenderer.endWidth = stylusBeamWidth;
            #endif
                        _stylusBeamRenderer.SetPosition(0, stylusPosition);
                        _stylusBeamRenderer.SetPosition(1, stylusPosition + (stylusDirection * stylusBeamLength));
        }
    }
    private void UpdateGrab(Vector3 inputPosition, Quaternion inputRotation)
    {
        Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * _initialGrabDistance));
        //更新物体的角度
        Quaternion objectRotation = inputRotation * _initialGrabRotation;
        _grabObject.transform.rotation = objectRotation;

        //更新抓取位置
        Vector3 objectPosition = inputEndPosition + (objectRotation * _initialGrabOffset);
        _grabObject.transform.position = objectPosition;
    }

    private void BeginGrab(GameObject hitObject, float hitDistance, Vector3 inputPosition, Quaternion inputRotation)
    {
        Vector3 inputEndPosition = inputPosition + (inputRotation * (Vector3.forward * hitDistance));
        //储存初始抓取状态
        _grabObject = hitObject;
        _initialGrabOffset = Quaternion.Inverse(hitObject.transform.rotation)*(hitObject.transform.position-inputEndPosition);
        _initialGrabRotation = Quaternion.Inverse(inputRotation) * hitObject.transform.rotation;
        _initialGrabDistance = hitDistance;
    }
    private enum StylusState
    {
        Idle=0,
        Grab=1,
    }

 

将cube赋值,打开运行窗口,打开zspace->Open Priview Windows带起眼镜,拿起你手中的笔就可以操作啦,啦啦啦,开心吧!!!!

 

第一次书写博客,如有不当,请各位批评指正

(注:相关技术参考来自官方的文档)

转载于:https://www.cnblogs.com/MaoHui/p/7895054.html

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值