Create a WebEngine to add an interactive website, PDFs, or HTML content to a VRED scene. The content streams into a material texture channel in real-time and uses the properties of the material for display.
In the Menu Bar, select Scene > Media Editor to open the Media Editor.
Select the + icon in the bottom Icon Bar, then WebEngine to create a WebEngine.
Double-click the WebEngine and name it.
Set the Width and Height:
Add a URL for the content:
From the Material Editor, drag the assigned material for the WebEngine onto the Material field.
Set the texture type:
Diffuse:
The environment is reflected in this texture.
Incandescence:
In raytracing, the material emits light into the scene when Use as Light Source is activated.
Diffuse + Incandescence:
This texture is used when the properties of incandescence and an alpha channel, that is only available in Diffuse, are needed.
This HTML example code sets the background of a webpage transparent (alpha):
<style>
body{
background-color: rgba(0, 0, 0, 0);
}
</style>
A decoupled service was added in 2021.3 to access WebEngines and expose them in Python, so you can automatically reload a WebEngine in VRED. This is needed when an external application streams its UI to VRED, it has changes, and needs to be reloaded.
Use vrWebEngineService
and vrdWebEngine
. Now a sceneplate WebEngine shares the name of its sceneplate, making it possible to find it with the new service.
There is a two-way communication and interaction between VRED and HTML5. Here is an example of VRED to HTML5.
Executing the Variant Set (Home\_Button)
with an associated Python function (sendToWebEngine)
, triggers a specific WebEngine (Webengine\_A)
and sends an HTML event (VRED\_HOME\_Btn)
to the web page. The web page must have an Event Listener to receive the message.
The following is an example of HTML code to receive a message:
<script>
document.addEventListener("VRED\_HOME\_Btn", Icon_HomeClick);
</script>
An img element and a URL can be used to send Python commands from the webpage to VRED, using the webserver. For example, src = "http://localhost:8888?.....
The webserver must be enabled in the preferences.
HTML code to set the Switch Material to choice 0
:
<script>
function r(){
var i = document.createElement("img");
i.src = "http://localhost:8888/python?value=setSwitchMaterialChoice('SwitchColor', 0)";
};
</script>
HTML code to trigger a VariantSet named Icon_Anim
:
<script>
Icon_Click = function(event) {
var i = document.createElement("img");
i.src = "http://localhost:8888/variants?value=selectVariantSet('Icon_Anim')";
};
</script>
You can interact with a PDF using a frontplate to display it in a WebEngine.
This feature only work with VRED 2021.3, as it requires Qt 5.15 or higher.