コード例 #1
0
        public void UpdateComponents(CVRRenderModels renderModels)
        {
            if (renderModels == null)
            {
                return;
            }

            if (transform.childCount == 0)
            {
                return;
            }

            if (nameCache == null)
            {
                nameCache = new Dictionary <int, string>();
            }

            for (int childIndex = 0; childIndex < transform.childCount; childIndex++)
            {
                Transform child = transform.GetChild(childIndex);

                // Cache names since accessing an object's name allocate memory.
                string componentName;
                if (!nameCache.TryGetValue(child.GetInstanceID(), out componentName))
                {
                    componentName = child.name;
                    nameCache.Add(child.GetInstanceID(), componentName);
                }

                var componentState = new RenderModel_ComponentState_t();
                if (!renderModels.GetComponentStateForDevicePath(renderModelName, componentName,
                                                                 SteamVR_Input_Source.GetHandle(inputSource), ref controllerModeState, ref componentState))
                {
                    continue;
                }

                child.localPosition = SteamVR_Utils.GetPosition(componentState.mTrackingToComponentRenderModel);
                child.localRotation = SteamVR_Utils.GetRotation(componentState.mTrackingToComponentRenderModel);

                Transform attach = null;
                for (int childChildIndex = 0; childChildIndex < child.childCount; childChildIndex++)
                {
                    Transform childChild      = child.GetChild(childChildIndex);
                    int       childInstanceID = childChild.GetInstanceID();
                    string    childName;
                    if (!nameCache.TryGetValue(childInstanceID, out childName))
                    {
                        childName = childChild.name;
                        nameCache.Add(childInstanceID, componentName);
                    }

                    if (childName == SteamVR_RenderModel.k_localTransformName)
                    {
                        attach = childChild;
                    }
                }

                if (attach != null)
                {
                    attach.position =
                        transform.TransformPoint(SteamVR_Utils.GetPosition(componentState.mTrackingToComponentLocal));
                    attach.rotation = transform.rotation *
                                      SteamVR_Utils.GetRotation(componentState.mTrackingToComponentLocal);

                    initializedAttachPoints = true;
                }

                bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0;
                if (visible != child.gameObject.activeSelf)
                {
                    child.gameObject.SetActive(visible);
                }
            }
        }
コード例 #2
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	public abstract bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ComponentState_t pComponentState);
コード例 #3
0
    void Update()
    {
        #if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            // See if anything has changed since this gets called whenever anything gets touched.
            var fields = GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            bool modified = false;

            if (values == null)
            {
                modified = true;
            }
            else
            {
                foreach (var f in fields)
                {
                    if (!values.Contains(f) || !f.GetValue(this).Equals(values[f]))
                    {
                        modified = true;
                        break;
                    }
                }
            }

            if (modified)
            {
                SetModel(modelOverride);

                values = new Hashtable();
                foreach (var f in fields)
                    values[f] = f.GetValue(this);
            }

            return; // Do not update transforms (below) when not playing in Editor (to avoid keeping OpenVR running all the time).
        }
        #endif
        // Update component transforms dynamically.
        if (updateDynamically)
        {
            using (var holder = new RenderModelInterfaceHolder())
            {
                var controllerState = SteamVR_Controller.Input((int)index).GetState();

                var t = transform;
                var baseTransform = new SteamVR_Utils.RigidTransform(t);

                for (int i = 0; i < t.childCount; i++)
                {
                    var child = t.GetChild(i);

                    var renderModels = holder.instance;
                    if (renderModels == null)
                        break;

                    var componentState = new RenderModel_ComponentState_t();
                    if (!renderModels.GetComponentState(renderModelName, child.name, ref controllerState, ref componentState))
                        continue;

                    var componentTransform = new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentRenderModel);
                    child.localPosition = componentTransform.pos;
                    child.localRotation = componentTransform.rot;

                    var attach = child.FindChild(k_localTransformName);
                    if (attach != null)
                    {
                        var attachTransform = baseTransform * new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentLocal);
                        attach.position = attachTransform.pos;
                        attach.rotation = attachTransform.rot;
                    }

                    bool visible = (componentState.uProperties & (uint)EVRComponentProperty.VRComponentProperty_IsVisible) != 0;
                    if (visible != child.gameObject.activeSelf)
                    {
                        child.gameObject.SetActive(visible);
                    }
                }
            }
        }
    }
コード例 #4
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	public override bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ComponentState_t pComponentState)
	{
		CheckIfUsable();
		bool result = VRNativeEntrypoints.VR_IVRRenderModels_GetComponentState(m_pVRRenderModels,pchRenderModelName,pchComponentName,ref pControllerState,ref pComponentState);
		return result;
	}
コード例 #5
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	internal static extern bool VR_IVRRenderModels_GetComponentState(IntPtr instancePtr, string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ComponentState_t pComponentState);
コード例 #6
0
	public bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ControllerMode_State_t pState,ref RenderModel_ComponentState_t pComponentState)
	{
		bool result = FnTable.GetComponentState(pchRenderModelName,pchComponentName,ref pControllerState,ref pState,ref pComponentState);
		return result;
	}
コード例 #7
0
ファイル: SteamVR_RenderModel.cs プロジェクト: Chazman11/SGJ
	public void UpdateComponents()
	{
		var t = transform;
		if (t.childCount == 0)
			return;

		using (var holder = new RenderModelInterfaceHolder())
		{
			var controllerState = (index != SteamVR_TrackedObject.EIndex.None) ?
				SteamVR_Controller.Input((int)index).GetState() : new VRControllerState_t();

			for (int i = 0; i < t.childCount; i++)
			{
				var child = t.GetChild(i);

				var renderModels = holder.instance;
				if (renderModels == null)
					break;

				var componentState = new RenderModel_ComponentState_t();
                if (!renderModels.GetComponentState(renderModelName, child.name, ref controllerState, ref controllerModeState, ref componentState))
					continue;

				var componentTransform = new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentRenderModel);
				child.localPosition = componentTransform.pos;
				child.localRotation = componentTransform.rot;

				var attach = child.FindChild(k_localTransformName);
				if (attach != null)
				{
					var attachTransform = new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentLocal);
					attach.position = t.TransformPoint(attachTransform.pos);
					attach.rotation = t.rotation * attachTransform.rot;
				}

				bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0;
				if (visible != child.gameObject.activeSelf)
				{
					child.gameObject.SetActive(visible);
				}
			}
		}
	}
コード例 #8
0
 public uint GetComponentRenderModelName(string pchRenderModelName, string pchComponentName, StringBuilder pchComponentRenderModelName, uint unComponentRenderModelNameLen) => default;                                                   // 0x00000001811DF2F0-0x00000001811DF320
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState) => default; // 0x00000001811DF320-0x00000001811DF4C0
コード例 #9
0
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState)
 {
     return(this.FnTable.GetComponentState(pchRenderModelName, pchComponentName, ref pControllerState, ref pState, ref pComponentState));
 }
コード例 #10
0
 // Token: 0x06001FDB RID: 8155 RVA: 0x0009E15C File Offset: 0x0009C35C
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState)
 {
     if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
     {
         VRControllerState_t_Packed             vrcontrollerState_t_Packed = new VRControllerState_t_Packed(pControllerState);
         CVRRenderModels.GetComponentStateUnion getComponentStateUnion;
         getComponentStateUnion.pGetComponentStatePacked = null;
         getComponentStateUnion.pGetComponentState       = this.FnTable.GetComponentState;
         bool result = getComponentStateUnion.pGetComponentStatePacked(pchRenderModelName, pchComponentName, ref vrcontrollerState_t_Packed, ref pState, ref pComponentState);
         vrcontrollerState_t_Packed.Unpack(ref pControllerState);
         return(result);
     }
     return(this.FnTable.GetComponentState(pchRenderModelName, pchComponentName, ref pControllerState, ref pState, ref pComponentState));
 }