-
Notifications
You must be signed in to change notification settings - Fork 2
Receipt_AR Waste Management
Rawan Ramdan Said edited this page Feb 11, 2025
·
10 revisions
The AR Cooking Book is an interactive Augmented Reality (AR) experience that allows users to place, move, rotate, and scale virtual kitchen objects while following a step-by-step cooking guide. Using Unity’s AR Foundation and XR Interaction Toolkit, users can engage in a realistic AR cooking simulation, interacting with utensils and ingredients in their real-world space.
- Setting Up the Project
- Deploying to Android
- Placing and Manipulating Objects in AR
- Gesture Controls: Move, Rotate, Scale
- Implementing Cooking Steps in AR
- Testing and Debugging
- Future Enhancements
- Open Unity Hub and create a new 3D project.
-
Install AR Foundation & XR Interaction Toolkit:
- Go to "Window → Package Manager".
- Install:
- AR Foundation
- XR Interaction Toolkit
- ARCore XR Plugin (Android) / ARKit XR Plugin (iOS)
- Enable XR Plugin Management:
- Open "Edit → Project Settings → XR Plug-in Management".
- Under Android, enable ARCore.
- Under iOS, enable ARKit.
- Overview of Unity's AR Foundation package.
- AR Foundation supports Android, iOS (ARKit), and HoloLens.
- Features include plane detection, image tracking, object tracking, face tracking, body tracking, and more.
-
Subsystems and Providers:
- Unity provides subsystems (interfaces with required functions).
- Providers (e.g., ARCore for Android, ARKit for iOS) implement these functions.
-
Managers:
- Help Unity access subsystem data via game objects.
- Example: Plane Manager creates a game object when a plane is detected.
- Start a new project with Unity's AR Template (pre-installed AR packages & sample scene).
-
Installing Necessary Modules:
- For Android: Install Android Build Support.
- For iOS: Install iOS Build Support.
-
Adding AR Foundation in an Existing Project:
- Open Package Manager → Download AR Foundation.
- Install ARCore XR Plugin (for Android) or ARKit XR Plugin (for iOS).
-
Enabling Input System:
- Helps with better control and interaction.
- Switch to the Target Platform (Android/iOS).
- Enable Development Build (for easy testing).
-
Adjust Player Settings:
- iOS: Set Minimum iOS Version to 11.0, enable ARKit Support, add Bundle Identifier.
- Android: Set Minimum API Level (24 for AR apps, 19 for non-AR apps).
- Remove Vulkan Graphics API (not supported in AR).
- Set IL2CPP as the scripting backend for Android Play Store builds.
- Go to XR Plugin Management in Player Settings.
- Enable ARCore (Android) or ARKit (iOS).
- Check settings such as face tracking if needed.
-
Create AR Session Game Object:
- Add AR Session Component (Manages AR lifecycle).
- Add AR Input Manager (Handles user interactions).
-
Create AR Session Origin:
- Converts AR session space to Unity world coordinates.
- Attach an AR Camera (with AR Camera Manager & Tracked Pose Driver).
-
Adding Objects in AR Space:
- Place a 3D object (Cube) in front of the camera for proper positioning.
- Go to Build Settings → Select correct platform → Add open scenes.
- Click Build, create a Builds Folder, and export the project.
-
For iOS:
- Open in Xcode, enable Automatic Signing, and deploy to a connected iPhone.
-
For Android:
- Build directly to phone.
- Ensure Developer Mode is enabled on the device.
- Launch the AR app on the phone.
- Grant camera access (iOS).
- The placed 3D Cube appears in AR space.
- Unity provides sample AR projects on GitHub.
- Download the sample scenes (e.g., image tracking, plane detection) for reference.
- Future tutorials will cover advanced AR features.
--
-
Add an AR Camera:
-
Hierarchy → XR → AR Session Origin. - Inside AR Session Origin, add:
- AR Camera Manager
- AR Raycast Manager
- AR Pose Driver
-
-
Enable Plane Detection:
-
Hierarchy → Create Empty → Rename it "AR Plane Manager". - Add:
- AR Plane Manager -AR Raycast Manager
-
Now, Unity is ready for AR development! 🎉
- Open Settings → About Phone → Tap "Build Number" 7 times.
- Enable USB Debugging in Developer Options.
- Connect your phone to your PC via USB.
- In Unity, go to "File → Build Settings".
- Select Android and click Switch Platform.
- Install Android Build Support & SDK via Unity Hub.
- Set Player Settings:
- Minimum API Level: Android 7.0 or higher.
- Scripting Backend: IL2CPP.
- Click Build & Run to install the app on your Android device.
- Create an "AR Placement Manager" GameObject.
- Attach the following script to enable object placement:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using System.Collections.Generic;
public class ARPlacement : MonoBehaviour
{
public GameObject objectToPlace;
public ARRaycastManager raycastManager;
private List<ARRaycastHit> hits = new List<ARRaycastHit>();
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
Touch touch = Input.GetTouch(0);
if (raycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
{
Pose hitPose = hits[0].pose;
Instantiate(objectToPlace, hitPose.position, hitPose.rotation);
}
}
}
}- Assign a prefab (e.g., pot, knife, or ingredient) to
objectToPlace.
Now, users can tap on surfaces to place kitchen items!
- Open your cooking object prefab (e.g., pot).
- Add:
- XR Grab Interactable
-
Rigidbody (
Use Gravity = False) - Collider
- Attach this script to all interactable objects:
using UnityEngine;
public class PinchToScale : MonoBehaviour
{
private float initialDistance;
private Vector3 initialScale;
void Update()
{
if (Input.touchCount == 2)
{
Touch touch0 = Input.GetTouch(0);
Touch touch1 = Input.GetTouch(1);
if (touch0.phase == TouchPhase.Moved || touch1.phase == TouchPhase.Moved)
{
float currentDistance = Vector2.Distance(touch0.position, touch1.position);
if (initialDistance == 0)
{
initialDistance = currentDistance;
initialScale = transform.localScale;
}
else
{
float factor = currentDistance / initialDistance;
transform.localScale = initialScale * factor;
}
}
}
else
{
initialDistance = 0;
}
}
}- Display step-by-step instructions in a UI overlay.
- Implement voice commands (e.g., "Next Step") to move through the recipe.
- Add animations for ingredient mixing and food preparation.
Student Name: Rawan Gomaa