How to use
This pages shows how to use the Filament render plugin on Android
On this page, we will go through on how to use the render plugin in a simple Android app which only contains a MainActivity. The basic usage of the plugin is easy, but we have to pay attention on several tasks.
Add dependency
The render plug-in is placed into a separate module called apefilamentrender. This means that when building our application, we do not just have to add the apertusvr module to our dependency list, but the apefilamentrender, as well:
Import classes
The plug-in itself contains sever classes, but when we using this module, our only concern is about the apeFilamentRenderPlugin
. This is the one class, which contains everything we need to render on Android:
So in our MainActivity.java file we import this class:
Init the plugin
It is not a surprise that we have to create every resource and init the plug-in, before using it. Assuming we want to use the plugin right from the application's starting, we have to do our job in the MainActivity.onCreate(/*...*/) funciton. So gather what resources we have to obtain there:
The context, which is the reference to the activity, which started the plugin,
the context's lifecycle,
a
SurfaceView
, which we can render onto,the context's resources folder
the context's asset folder,
an optional
userNode
.
The first five is pretty trivial if our MainActivity
is derived from AppCompatActivity
:
The context is a reference to our MainActivity.
AppCompatActivity implements the LifecycleOwner interface, therefore it has getLifecycle() method.
We can easily get the activity's SurfaceView by
new SurfaceView(this)
.The resource folder can be obtained with the getResources() method.
The asset folder can be obtained with the getAssets() method.
So what about the 6th parameter, the userNode? We need this in order to be able to propagate our camera's position into ApertusVR. If we do not need this feature in our application, just set the 6th parameter to null
. Otherwise, we have to use the ApertusVR Java-API to create a userNode, possibly with some avatar geometry (e.g. a cone). Without further explanation the following code block shows an example for this:
Now we have userNode
, so just we set it as the 6th parameter.
Great! What is left? The only task remained is to add our plugin as a lifecycle observer:
If you did everything as discussed and also paid attention on how to set up the ApertusVR system for applications, then the render plugin will give response for all the events occouring in ApertusVR while MainActivity
is running.
For basic usage this is all you need to know. However to be able to custumize the plug-in for your own wish, see the next page on how to configure.
Last updated