ThinkTech en Barcelona

Con 7 enormes pabellones, el 4YFN y el MWC se celebraron este año en una misma sede (Fira Gran Vía Barcelona): esto nos permitió maximizar nuestro contacto con el mundo de las startups (más de 600…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How To Build Your First Android AR App In One Hour

Here are examples of the app:

Travel Hack 101

Android Studio will build the HelloAR project into a debuggable APK, installs the APK, and then runs the app on your device. ARCore will automatically be installed on your device.

In this tutorial, we will be focusing on the relevant functions to allow us to create an Animal 3D Object and a Portal (in ProductARActivity.java).

When the app is launched, init3DModelProduct function will be called to create the Portal. The Portal’s appearance, where the Portal leads to and many other customisable features relating to the Portal can be found in this function.

First, we initalise a Node called mProductModelGroup. We create Spotlight for our Portal so that it does not appear dark on our screen. We reference the Spotlight to the mProductModelGroup with the addLight function.

Next, we create a shadow for our Portal so it appears more realistic. We will then add the shadow as a child node to the mProductModelGroup using addChildNode function.

We then create a Portal object and add it as a child node to the portalModel. Here comes the fun part, the Portal Scene. This is what makes your Portal a portal. I have added sound effects to make the experience a more immersive one, feel free to change “jungle.mp3” to your own. The image inside the Portal is defined by the Bitmap object. You can change the “jungle.jpg” to any 360 images or videos of your preference. Set the image as the background of the Portal by using the setBackgroundTexture function.

Note: The -2 in portalScene.setPosition(new Vector(0, 0, -2)) means that the Portal will be created 2 metres away from you.

Finally, set the whole group (shadow, light, portal, etc) we created to be invisible when the app launches. We will only reveal the Portal when we touch the cross hair on the screen to give a magical effect, as seen in the examples.

Whenever you tap on the crosshair on the screen, your very own Portal will now appear! This is made possible by adding a update3DModelProduct() function in the onClick function of the crosshair as shown below:

update3dModelProduct function makes the Portal visible by using setOpacity(1).

By understanding the structure and how we create our Portal object previously, creating your own 3D Animal Object can be very easy.

Before we begin, you should have a 3D model file available in the assets folder. You can use the Dog 3D model I provided, create your own or find free sources online. For each 3D model, you should at least have these 3 files:

We will be creating our own function, createObject, to simplify the process of creating the 3D model. While it may not be compulsory, we add the Spotlight and Shadow to the object. You can experiment with them to see what works best. If you are using your own 3D model, do remember to change “dog.obj” to your OBJ file and the texture file “Diffuse.png” to your model texture file. The .mtl file will not be referenced in the code but it is compulsory to have it in your assets file. In simple words, the .obj file tells the code to look at .mtl file and .mtl file tells the code to look at the respective texture files.

Now, let’s bind this createObject function to a button!

The position of the object will be determined by the position of the crosshair. This allows us to look around using the camera and mass produce cute animals at our fingertips.

Now that you have a taste of what you can do in an hour, I encourage you to spend a slightly longer amount of time to understand the code and the concept of AR. Try changing some parts of the code, see what works and what doesn’t. You will be surprised at how simple AR can be to pick up!

Here are some things you can explore:

Add a comment

Related posts:

17 ideas de contenido para redes sociales

Idear contenido puede parecer sencillo al principio, sin embargo, todos nos hemos visto en la complicada situación donde se nos agotaron las ideas y todavía nos faltan 15 o 20 post por programar, de…

Transforming the Health Care Industry with Digital Pill Technologies

Human life is indispensable — which is why health care has soared to the forefront of technological innovation. Over the past decade, medicine has become entirely focused on data and accuracy but…

Taylor Swift Tribute At Leeds Minster

For UK fans of Taylor Swift, the wait for the arrival of the Eras tour is painfully ongoing. However, in the meantime there was another way to hear her best songs in a breathtakingly unique setting…