文章目錄
- 1.下載 zSpace 開發環境
- 1.1 zCore Unity Package
- 1.2 zView Unity Package
- 2. 導入工程
- 3. 發布設置
- 4.功能實現
- 4.1 用觸控筆來實現對模型的拖拽:
- 5. 后續更新
1.下載 zSpace 開發環境
官網地址
1.1 zCore Unity Package
- zSpace 開發核心
- 必須
1.2 zView Unity Package
- 主要用途:在zSpace設備外接顯示屏或投影時,將zSpace設備的3D畫面轉為2D畫面進行展示(zSpace顯示3D,外接設備顯示2D)
- 按需下載
2. 導入工程
將下載好的 zCore Unity Package 導入到 Unity
3. 發布設置
- Edit—ProjectSettings—Player—OtherSetting—Rendering—ColorSpace 改為 Gamma
- Edit—ProjectSettings—Player—OtherSetting—AutoGraphicsAPIforWindows 取消勾選
- Edit—ProjectSettings—Player—OtherSetting—GraphicsAPIsforWindows-添加OpenGLCore,其他全部刪除
- Edit—ProjectSettings—Player—XRSetting 中勾選 Virtual Reality Supported
- Edit—ProjectSettings—Player—XRSetting—Virtual Reality SDKs 刪除其他項添加 Stereo Display (non head-mounted)
4.功能實現
4.1 用觸控筆來實現對模型的拖拽:
//
// Copyright (C) 2007-2020 zSpace, Inc. All Rights Reserved.
//
using UnityEngine;
using UnityEngine.EventSystems;using zSpace.Core.EventSystems;
using zSpace.Core.Input;namespace zSpace.Core.Samples
{public class Draggable :ZPointerInteractable, IBeginDragHandler, IDragHandler, IEndDragHandler{// Public Methodspublic override ZPointer.DragPolicy GetDragPolicy(ZPointer pointer){if (pointer is ZMouse){return ZPointer.DragPolicy.LockToScreenAlignedPlane;}if (pointer is ZStylus){return ZPointer.DragPolicy.LockHitPosition;}return base.GetDragPolicy(pointer);}public void OnBeginDrag(PointerEventData eventData){ZPointerEventData pointerEventData = eventData as ZPointerEventData;if (pointerEventData == null ||pointerEventData.button != PointerEventData.InputButton.Left){return;}Pose pose = pointerEventData.Pointer.EndPointWorldPose;// Cache the initial grab state.this._initialGrabOffset =Quaternion.Inverse(this.transform.rotation) *(this.transform.position - pose.position);this._initialGrabRotation =Quaternion.Inverse(pose.rotation) *this.transform.rotation;// If the grabbable object has a rigidbody component,// mark it as kinematic during the grab.var rigidbody = this.GetComponent<Rigidbody>();if (rigidbody != null){this._isKinematic = rigidbody.isKinematic;rigidbody.isKinematic = true;}// Capture pointer events.pointerEventData.Pointer.CapturePointer(this.gameObject);}public void OnDrag(PointerEventData eventData){ZPointerEventData pointerEventData = eventData as ZPointerEventData;if (pointerEventData == null ||pointerEventData.button != PointerEventData.InputButton.Left){return;}Pose pose = pointerEventData.Pointer.EndPointWorldPose;// Update the grab object's rotation.this.transform.rotation =pose.rotation * this._initialGrabRotation;// Update the grab object's position.this.transform.position =pose.position + (this.transform.rotation * this._initialGrabOffset);}public void OnEndDrag(PointerEventData eventData){ZPointerEventData pointerEventData = eventData as ZPointerEventData;if (pointerEventData == null ||pointerEventData.button != PointerEventData.InputButton.Left){return;}// Release the pointer.pointerEventData.Pointer.CapturePointer(null);// If the grabbable object has a rigidbody component,// restore its original isKinematic state.var rigidbody = this.GetComponent<Rigidbody>();if (rigidbody != null){rigidbody.isKinematic = this._isKinematic;}}// Private Membersprivate Vector3 _initialGrabOffset = Vector3.zero;private Quaternion _initialGrabRotation = Quaternion.identity;private bool _isKinematic = false;}
}