Exemplo n.º 1
0
        public void FetchPointerOffset(uint index, Transform pointer)
        {
            StringBuilder renderModelName = new StringBuilder(50);

            ETrackedPropertyError pError = new ETrackedPropertyError();

            OpenVR.System.GetStringTrackedDeviceProperty(index,
                                                         ETrackedDeviceProperty.Prop_RenderModelName_String, renderModelName, 50, ref pError);

            VRControllerState_t state = new VRControllerState_t();
            RenderModel_ControllerMode_State_t rState    = new RenderModel_ControllerMode_State_t();
            RenderModel_ComponentState_t       compState = new RenderModel_ComponentState_t();
            bool found = OpenVR.RenderModels.GetComponentState(renderModelName.ToString(), "tip", ref state, ref rState,
                                                               ref compState);

            if (!found)
            {
                return;
            }

            var pose = new SteamVR_Utils.RigidTransform(compState.mTrackingToComponentLocal);

            pointer.localPosition = pose.pos;
            pointer.localRotation = pose.rot;
        }
Exemplo n.º 2
0
    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();
                var componentModeState = new RenderModel_ControllerMode_State_t();
                if (!renderModels.GetComponentState(renderModelName, child.name, ref controllerState, ref componentModeState, 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);
                }
            }
        }
    }
    private void RenderMultiComponentModel(DeviceContext context, bool depthOnly, uint trackedDeviceIdx, string renderModelName)
    {
        var components = cache.LookupComponents(context, renderModelName);

        if (components == null)
        {
            return;
        }

        OpenVR.System.GetControllerState(trackedDeviceIdx, out VRControllerState_t controllerState);

        RenderModel_ControllerMode_State_t controllerMode = new RenderModel_ControllerMode_State_t {
            bScrollWheelVisible = false
        };

        for (uint componentIdx = 0; componentIdx < components.Length; ++componentIdx)
        {
            var component = components[componentIdx];

            if (component.model == null)
            {
                //this is a non-visual component
                continue;
            }

            RenderModel_ComponentState_t componentState = default(RenderModel_ComponentState_t);
            OpenVR.RenderModels.GetComponentState(renderModelName, component.name, ref controllerState, ref controllerMode, ref componentState);

            bool isVisible = ((EVRComponentProperty)componentState.uProperties).HasFlag(EVRComponentProperty.IsVisible);
            if (isVisible)
            {
                Matrix componentToObjectMatrix = componentState.mTrackingToComponentRenderModel.Convert();
                componentSpaceToObjectTransformBufferManager.Update(context, componentToObjectMatrix);
                component.model.Render(context, depthOnly);
            }
        }
    }
Exemplo n.º 4
0
 public abstract bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ControllerMode_State_t pState,ref RenderModel_ComponentState_t pComponentState);
Exemplo n.º 5
0
 public override bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ControllerMode_State_t pState,ref RenderModel_ComponentState_t pComponentState)
 {
     CheckIfUsable();
     bool result = VRNativeEntrypoints.VR_IVRRenderModels_GetComponentState(m_pVRRenderModels,pchRenderModelName,pchComponentName,ref pControllerState,ref pState,ref pComponentState);
     return result;
 }