How to support WebVR functionality in Forge Viewer
我想大声告诉你
我想大声告诉你 2017-05-19 10:29:33
0
1
756

We can browse 3D models by using Forge Viewer. Does Forge Viewer currently support VR function? Especially WebVR? How to support?

我想大声告诉你
我想大声告诉你

reply all(1)
PHPzhong

Starting from version 2.12 of Forge Viewer, Extension has been added to support WebVR, so essentially you only need to call viewer.loadExtension("Autodesk.Viewing.webVR"). However, since WebVR has not yet become a W3C standard and is still in the experimental stage, only some browsers can support it. For details, please refer to https://webvr.info.

Here we only talk about WebVR support in Forge Viewer. Since many browsers currently cannot natively support WebVR, Forge Viewer also provides WebVR Polyfill to support it, but this is starting from version 2.13 of the viewer. You can see the following in the source code Code:

Autodesk.Viewing.Extensions.WebVR.VRExtension.prototype.load = function() {
    var self = this;
    var _vrDisplay = null;

    // check if browser supports webVR1.1 natively, if not, load polyfill
    avp.loadDependency('VRFrameData', 'webvr-polyfill.min.js', function() {
        navigator.getVRDisplays().then(function(displays) {
            if (displays.length > 0) {
                _vrDisplay = displays[0];
                if (_vrDisplay.capabilities.canPresent) {

                    // VR detected, add the 'VR button'
                    var viewer = self.viewer;
                    var toolbar = viewer.getToolbar(true);
                    var avu = Autodesk.Viewing.UI;

                    // Register tool
                    self.tool = new Autodesk.Viewing.Extensions.WebVR.VRTool(viewer, self, _vrDisplay);
                    viewer.toolController.registerTool(self.tool);
                    self.createUI(toolbar);

                    // Register listeners
                    self.onToolChanged = function(e) {
                        var vrToolActive = (e.toolName === 'vr') && e.active;
                        var state = vrToolActive ? avu.Button.State.ACTIVE : avu.Button.State.INACTIVE;
                        self.vrToolButton && self.vrToolButton.setState(state);
                    };
                    viewer.addEventListener(Autodesk.Viewing.TOOL_CHANGE_EVENT, self.onToolChanged);
                    return;
                }
            }
            avp.logger.warn('Attempted to load WebVR extension, but WebVR is not supported.');
        });
    });
    return true;
};
 
 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template