Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/yale-swe/f23-here
Browse files Browse the repository at this point in the history
  • Loading branch information
phucd5 committed Nov 27, 2023
2 parents bfeec15 + 436172c commit 5d8a5bd
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 289 deletions.
Binary file modified app/newHere1/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions app/newHere1/newHere.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@
"BUNDLE_LOADER[arch=*]" = "$(BUILT_PRODUCTS_DIR)/newHere.app/newHere";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = ACLZN9M2VC;
DEVELOPMENT_TEAM = A7X36A78B2;
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -620,7 +620,7 @@
"BUNDLE_LOADER[arch=*]" = "$(BUILT_PRODUCTS_DIR)/newHere.app/newHere";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = ACLZN9M2VC;
DEVELOPMENT_TEAM = A7X36A78B2;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
Expand Down
19 changes: 8 additions & 11 deletions app/newHere1/newHere/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@
//
// Created by Eric Wang on 10/28/23.
//
// Description:
// This file defines the ContentView struct, which serves as the main view for the application.
// It handles user authentication and navigation between the HomePage and Login views.

import SwiftUI

struct ContentView: View {
@State private var isAuthenticated = false
@State private var isRegistered = false
@ObservedObject var locationDataManager = LocationDataManager()
@ObservedObject var locationDataManager = LocationDataManager()

// testing
@State var friendsPresented = true
//@State var userId = ""
@State private var userId: String = ""

/// The body of the view, which conditionally presents either the HomePageView or LoginView based on authentication status.
var body: some View {
if isAuthenticated {
HomePageView()
.environmentObject(locationDataManager)
} else {
LoginView(isAuthenticated: $isAuthenticated)
LoginView(isAuthenticated: $isAuthenticated, user_id: $userId)
}
//
// if isRegistered {
// HomePageView()
// } else {
// RegistrationView(isRegistered: $isRegistered)
// }
}
}

/// A preview provider for ContentView, used for rendering the view in Xcode's canvas.
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
Expand Down
7 changes: 7 additions & 0 deletions app/newHere1/newHere/CustomARView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
//
// Created by TRACY LI on 2023/10/28.
//
// Description:
// This file defines a CustomARView class, which is a subclass of ARView from RealityKit.
// It's designed to be used for augmented reality experiences within the 'new_here' application.

import ARKit
import RealityKit
import SwiftUI

/// CustomARView is a subclass of ARView for creating custom AR experiences.
class CustomARView: ARView {
/// Initializes and returns a newly allocated view object with the specified frame rectangle.
required init (frame frameRect: CGRect){
super.init(frame: frameRect)
}

/// Returns an object initialized from data in a given unarchiver.
dynamic required init?(coder decoder: NSCoder){
fatalError("init(coder:) has not been implemented")
}

/// Convenience initializer to create a view with the main screen bounds.
convenience init(){
self.init(frame: UIScreen.main.bounds)
}
Expand Down
31 changes: 18 additions & 13 deletions app/newHere1/newHere/CustomARViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@
//
// Created by TRACY LI on 2023/10/28.
//
// Description:
// This Swift file defines a SwiftUI UIViewRepresentable for integrating ARKit functionality.
// It allows for rendering AR content, such as 3D bubbles with messages, in the 'new_here' application.
//

import SwiftUI
import ARKit

//class ARViewModel: ObservableObject {
// var messageToPlant: Message?
//
// func plantMessage(_ message: Message) {
// messageToPlant = message
// }
//}

struct CustomARViewRepresentable: UIViewRepresentable {
// Binding for user ID
@Binding var userId: String

// Environment objects for message and fetched messages states
@EnvironmentObject var messageState: MessageState
@EnvironmentObject var fetchedMessagesState: FetchedMessagesState

// Create the ARSCNView and configure it
func makeUIView(context: Context) -> ARSCNView {
// return CustomARView()
let sceneView = ARSCNView()
sceneView.delegate = context.coordinator

let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
print("user id: \(userId)")

getUserMessages(userId: "653d51478ff5b3c9ace45c26") {
// Fetch and render user's messages
getUserMessages(userId: userId) {
result in
switch result {
case .success(let response):
Expand All @@ -37,6 +39,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {
for m in response {
do {
let convertedMessage = try Message(id: m._id,
user_id: userId,
location: m.location.toCLLocation(),
messageStr: m.text)
convertedMessages.append(convertedMessage)
Expand All @@ -58,6 +61,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {
return sceneView
}

// Update the AR view when a new message is available
func updateUIView (_ uiView: ARSCNView, context: Context) {
if let messageToPlant = messageState.currentMessage {
plantBubbleNode(to: uiView, message: messageToPlant)
Expand All @@ -66,6 +70,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {

}

// Create a coordinator for handling ARSCNViewDelegate methods
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
Expand All @@ -78,6 +83,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {
}
}

// Plant a bubble node with a message at a specific position
func plantBubbleNode(to sceneView: ARSCNView, message: Message) {
// Set the position based on the provided position
if let frame = sceneView.session.currentFrame {
Expand All @@ -97,6 +103,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {
}
}

// Render a history of bubble nodes with messages at random positions
func renderBubbleNodeHistory(to sceneView: ARSCNView, messages: [Message]) {
// Create a random number generator
var randomNumberGenerator = SystemRandomNumberGenerator()
Expand All @@ -119,6 +126,7 @@ struct CustomARViewRepresentable: UIViewRepresentable {
}
}

// Create a new bubble node with a message at a specified position
func newBubbleNode(to sceneView: ARSCNView, message:Message, position:SCNVector3) {
let bubble = SCNSphere(radius: 0.05)
bubble.firstMaterial?.diffuse.contents = UIColor(red: 135.0/255.0, green: 206.0/255.0, blue: 235.0/255.0, alpha: 1.0)
Expand All @@ -130,9 +138,6 @@ struct CustomARViewRepresentable: UIViewRepresentable {
textGeometry1.firstMaterial?.diffuse.contents = UIColor.black
let textNode1 = SCNNode(geometry: textGeometry1)


// TEXT POSITIONING RELATIVE TO BUBBLE - WILL HAVE TO ADJUST LATER

// Position the first textNode inside the bubble
textNode1.position = SCNVector3(-0.05, 0, -0.05) // Adjust the position inside the bubble
textNode1.scale = SCNVector3(0.001, 0.001, 0.001)
Expand Down
Loading

0 comments on commit 5d8a5bd

Please sign in to comment.