Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

PRACTICAL-5

AIM: - Implementation to show portal planets

Visualization of Portal Planets

Introduction
In this document, we will explore the implementation of a visualization for portal planets. Portal
planets are fictional celestial bodies interconnected by portals, creating an intriguing and visually
captivating setting. We will discuss the steps involved in creating a practical implementation of
such a visualization using Python and the Plotly library.

Implementation Steps
1. Define Planet Data

The first step is to define the data structure for representing each planet. Each planet can be
described by attributes such as position, size, color, and name.

2. Generate or Load Planet Data

Next, we need to generate or load the planet data. For demonstration purposes, we can generate
random data for the planets. However, in a real-world scenario, this data could be sourced from a
file, database, or generated algorithmically based on specific criteria.

3. Choose Visualization Library

For this implementation, we will use Plotly, a powerful and versatile visualization library that
supports interactive plots. Plotly provides excellent support for 3D visualizations, making it ideal
for our portal planets visualization.

4. Plot Planets

Using Plotly, we will create a 3D scatter plot to represent the planets. Each planet will be
visualized as a sphere positioned in 3D space according to its coordinates.

5. Add Interactivity

To enhance the user experience, we will add interactivity to the visualization. Users will be able
to hover over each planet to see its name and click on planets for additional information. We can
also implement interactive features such as zooming, panning, and rotating the scene.

IT Dept, LDRP-ITR Page | 41


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

6. Implement Portal Effects

To bring the concept of portal planets to life, we can implement visual effects to represent portals
between planets. This could involve creating animated wormholes, shimmering energy fields, or
other imaginative effects.

7. Integration

Finally, we will integrate the visualization into our application or website. We will ensure that the
visualization functions smoothly and aligns with the overall user experience.

Code Implementation
Below is a simplified Python code example using Plotly to create an interactive 3D visualization
of portal planets:

import plotly.graph_objects as go

import numpy as np

# Generate sample planet data (random positions)

num_planets = 5

planet_names = [f'Planet {i}' for i in range(1, num_planets + 1)]

planet_positions = np.random.rand(num_planets, 3) * 10 # Random positions in 3D space

# Create trace for planets

trace_planets = go.Scatter3d(

x=planet_positions[:, 0],

y=planet_positions[:, 1],

z=planet_positions[:, 2],

mode='markers',

marker=dict(

size=10,

color='blue', # Color of planets

IT Dept, LDRP-ITR Page | 42


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]
opacity=0.8

),

text=planet_names, # Display planet names on hover

hoverinfo='text'

# Create layout

layout = go.Layout(

title='Portal Planets',

scene=dict(

xaxis=dict(title='X'),

yaxis=dict(title='Y'),

zaxis=dict(title='Z')

# Create figure

fig = go.Figure(data=[trace_planets], layout=layout)

# Show plot

fig.show()

IT Dept, LDRP-ITR Page | 43


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

OUTPUT

IT Dept, LDRP-ITR Page | 44


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]
PRACTICAL-6

AIM: - Explore project in unity 2D and 3D

Creating a Portal Planets Project in Unity: A Comprehensive Guide

Introduction

In this guide, we'll explore the process of creating a portal planets project in Unity, a versatile
game development engine. We'll cover both 2D and 3D implementations, providing step-by-step
instructions, tips, and examples to help you bring your vision to life.

Unity Project Setup

Before diving into the specifics of creating a portal planets project, let's start by setting up a new
Unity project. Follow these steps:

1. Create a New Unity Project : Launch Unity and select "New" to create a new project.
2. Project Configuration : Choose a project name, location, and template. You can select either 2D
or 3D depending on your preference and project requirements.

2D Implementation

1. Sprite Creation
In a 2D implementation, graphics are represented as flat images known as sprites. To create a
portal planets project in 2D, you'll need to design or obtain sprites for your planets and portals.
Consider the following:

• Planet Sprites : Design or find images representing different planets. Ensure consistency in style
and scale for visual coherence.
• Portal Sprites: Create sprites for portal effects. This could include animated textures or particle
effects representing swirling energy.
2. Scene Setup
Once you have your sprites ready, it's time to set up your scene in Unity:

Create a 2D Scene : In the Unity editor, go to "File" > "New Scene" to create a new 2D scene.
Import Sprites : Import your planet and portal sprites into the Unity project. You can do this by
dragging them into the "Assets" folder in the Unity editor.
3. Add Planets
With your scene set up, you can now add planets to the environment:

Place Planet Sprites: Drag planet sprites from the project folder into the scene view to place
them at desired locations.
Adjust Properties: Customize properties such as position, scale, and rotation to achieve the
desired layout for your portal planets environment.

IT Dept, LDRP-ITR Page | 45


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

4. Implement Portal Effects


Portal effects are a crucial aspect of the portal planets experience. Here's how you can implement
them:

• Create Portal Objects : Use sprite-based or particle-based effects to create portal objects in the
scene.
• Animate Effects: Add animations or particle systems to portal objects to create dynamic and
visually appealing effects.
• Trigger Effects: Implement logic to trigger portal effects when the player interacts with specific
objects or areas.
5. Player Interaction
Player interaction is essential for navigating the portal planets environment:

Implement Controls : Set up player controls for movement and interaction. This could involve
keyboard input, touch controls, or gamepad support depending on your target platform.
Detect Interactions: Use Unity's collision detection system to detect when the player interacts
with planets or portals.
Handle Transitions: Implement logic to transition the player between planets when they interact
with portals.

3D Implementation

1. Modeling
In a 3D implementation, objects are represented as three-dimensional models. Here's how you
can create or obtain models for your portal planets project:

• Create 3D Models : Use modeling software such as Blender or Unity's ProBuilder to create 3D
models of planets and portals.
• Acquire Models: Alternatively, you can find pre-made 3D models online or purchase them from
asset stores to use in your project.
2. Scene Setup
Once you have your 3D models ready, set up your scene in Unity:

Create a 3D Scene : Start by creating a new 3D scene in Unity.


Import Models : Import your 3D models into the Unity project. Ensure that they are properly
textured and optimized for real-time rendering.
3. Add Planets
With your scene set up, add the 3D models of planets to the environment:

Place Planet Models: Drag planet models from the project folder into the scene view to position
them at desired locations.
Adjust Properties: Customize properties such as position, scale, and rotation to create a visually
appealing layout for your portal planets environment.

IT Dept, LDRP-ITR Page | 46


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

4. Implement Portal Effects


Implementing portal effects in a 3D environment requires careful attention to visual fidelity and
performance:

Create Portal Objects : Model or use pre-made assets for portal objects in the scene.
Apply Visual Effects : Utilize shaders, particle systems, or animations to create portal effects that
convey the sense of traversing between worlds.
Optimize Performance: Ensure that portal effects are optimized for performance to maintain a
smooth frame rate, especially on lower-end devices.
5. Player Interaction
Player interaction in a 3D environment involves navigating the space and interacting with
objects:

Implement Movement: Set up player movement controls for navigating the 3D environment.
This could include first-person or third-person controls depending on your game design.
Collision Detection: Use Unity's physics system to handle collisions between the player character
and planets or portals.
Teleportation Logic: Implement logic to teleport the player between planets when they interact
with portals.
Additional Features

Interactivity
Enhance the player experience with interactive elements:

• Clickable Planets : Implement logic to allow players to click on planets for information or
interactions.
• Interactive UI: Create user interface elements such as menus, HUDs, and tooltips to provide
feedback and information to the player.
• Puzzle Elements: Introduce puzzles or challenges that require the player to interact with the
environment to progress.
Audio
Audio plays a crucial role in creating an immersive experience:

Sound Effects : Add sound effects for interactions, movements, and environmental elements.
Background Music : Incorporate background music to set the mood and atmosphere of the portal
planets environment.
UI Design
A well-designed user interface enhances usability and engagement:

Menu Design: Create menus for starting the game, adjusting settings, and accessing additional
features.
HUD Elements: Design a heads-up display (HUD) to provide essential information such as
health, inventory, and objectives during gameplay.

IT Dept, LDRP-ITR Page | 47


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

Optimization
Optimize your project for performance and compatibility:

• Resource Management : Manage assets efficiently to minimize memory usage and loading times.
• Level of Detail (LOD) : Implement LOD systems to optimize rendering performance for distant
objects.
• Occlusion Culling: Use occlusion culling techniques to optimize rendering by only rendering
objects that are visible to the camera.
Testing and Iteration

Testing
Thorough testing is essential to ensure a polished and bug-free experience:

• Functional Testing: Test all gameplay mechanics, interactions, and features to ensure they work
as intended.
Performance Testing: Test performance on different devices and platforms to identify and
address performance issues.
User Testing: Gather feedback from playtesters to identify areas for improvement and refinement.

IT Dept, LDRP-ITR Page | 48


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]
PRACTICAL-7

AIM: - Mini project on augmented reality or virtual reality

Creating an augmented reality (AR) project involves using tools and frameworks such as Unity
with AR Foundation, Vuforia, or ARKit/ARCore for mobile AR applications. Below is a
simplified example of how you might set up an AR project using Unity with AR Foundation,
which allows for cross-platform development targeting both iOS and Android devices.

Steps to Create an Augmented Reality Project in Unity with AR Foundation:

1. Install Unity : If you haven't already, download and install Unity Hub from the official
Unity website. Create a new Unity project or open an existing one.

2. Install AR Foundation : In the Unity Editor, navigate to Window > Package Manager .
Search for "AR Foundation" and install it.

3. Import ARCore or ARKit XR Plugin : Depending on your target platform (Android or


iOS), install the corresponding XR plugin. For Android, install "ARCore XR Plugin." For
iOS, install "ARKit XR Plugin."

4. Set Up AR Session : In your Unity scene, create an empty GameObject and add the "AR
Session" component to it. This sets up the AR session for tracking the device's position
and orientation.

5. Add AR Session Origin : Create another empty GameObject and add the "AR Session
Origin" component to it. This serves as the origin point for the AR experience and
handles camera tracking and AR plane detection.

6. Add AR Session Origin Components : To enable features such as plane detection and
object tracking, add components like "AR Plane Manager," "AR Raycast Manager," and
"AR Anchor Manager" to the AR Session Origin GameObject.

7. Import 3D Models and Assets : Import 3D models, textures, and other assets you want to
use in your AR scene. Ensure they are optimized for real-time rendering and suitable for
AR experiences.

8. Scripting : Write scripts to handle interactions, animations, and any custom behavior in
your AR project. For example, you might write scripts to place virtual objects in the AR
scene, detect user input, or trigger animations.

IT Dept, LDRP-ITR Page | 49


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]

9. Testing and Deployment : Test your AR project in the Unity Editor using the AR
simulation mode. Once you're satisfied with the results, build and deploy your project to a
compatible device (iOS or Android).

Code for Placing Virtual Objects in AR:

Here's a basic example of how you might script the placement of virtual objects in an AR scene
using AR Foundation:

using UnityEngine;

using UnityEngine.XR.ARFoundation;

using UnityEngine.XR.ARSubsystems;

public class ARObjectPlacement : MonoBehaviour

public ARRaycastManager raycastManager;

public GameObject objectPrefab;

void Update()

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)

Vector2 touchPosition = Input.GetTouch(0).position;

List<ARRaycastHit> hits = new List<ARRaycastHit>();

if (raycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))

Pose hitPose = hits[0].pose;

Instantiate(objectPrefab, hitPose.position, hitPose.rotation);

IT Dept, LDRP-ITR Page | 50


BE 8th Sem IT [20BEIT30012] Augmented and Virtual Reality [IT803D-N]
}

Conclusion:

Creating an augmented reality project in Unity with AR Foundation involves setting up the AR
session, importing assets, scripting interactions, testing, and deployment. The provided example
demonstrates how to place virtual objects in the AR scene, but you can extend this to create a
wide range of AR experiences, such as interactive games, educational apps, or marketing
demonstrations. Experiment with different features and techniques to create engaging and
immersive AR content.

IT Dept, LDRP-ITR Page | 51

You might also like