智创巅峰搜索 / 待分类 / zspace初级教程

分享

   

zspace初级教程

2018-10-15  智创巅峰...
  1. 先检查电脑配置(一下是最低要求)

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

处理器:Intel i3-4370

内存:8GB RAM

显卡:AMD FirePro W5170M GPU

硬盘:128GB以上

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

 

 

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

 

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

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

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

http://developer.

 

   

第一个直接安装,第二个导入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(); if (_zCore == null) { Debug.LogError('无法找到参考'); this.enabled = false; return; } //创建触控笔对象 _stylusBeamObject = new GameObject('StylusBeam'); _stylusBeamRenderer = _stylusBeamObject.AddComponent(); _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().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().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带起眼镜,拿起你手中的笔就可以操作啦,啦啦啦,开心吧!!!!

 

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

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>