Last active
June 17, 2026 18:29
-
-
Save saaeiddev/37f3d666c341b43c1eaaea15a54954f6 to your computer and use it in GitHub Desktop.
Hero Brain AR App Prototype : AR-based iOS prototype for neuroscience education built with ARKit and RealityKit. The app visualizes brain regions in augmented reality to create an interactive and immersive learning experience about human brain structure and function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // Hero Brain AR | |
| // | |
| // Created by Amir Saeid Dehghan | |
| // | |
| // This file controls the main AR experience of the app. | |
| // این فایل تجربه اصلی واقعیت افزوده اپلیکیشن را مدیریت میکند. | |
| // | |
| import UIKit | |
| import RealityKit | |
| import ARKit | |
| class ViewController: UIViewController { | |
| @IBOutlet var arView: ARView! | |
| // MARK: - Brain Information Data | |
| // اطلاعات آموزشی مربوط به بخشهای مختلف مغز | |
| let brainInfo: [String: String] = [ | |
| "frontalLobe": "Frontal Lobe:\nResponsible for decision making, problem solving, and emotions.", | |
| "parietalLobe": "Parietal Lobe:\nProcesses sensory information such as touch and temperature.", | |
| "temporalLobe": "Temporal Lobe:\nInvolved in memory, hearing, and language comprehension.", | |
| "occipitalLobe": "Occipital Lobe:\nMain center for visual processing." | |
| ] | |
| // MARK: - Lifecycle | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| setupARSession() | |
| loadBrainModel() | |
| setupTapGesture() | |
| } | |
| // MARK: - AR Session Setup | |
| // تنظیمات اولیه AR Session | |
| func setupARSession() { | |
| let config = ARWorldTrackingConfiguration() | |
| config.planeDetection = [.horizontal] | |
| arView.session.run(config) | |
| } | |
| // MARK: - Load Brain Model | |
| // بارگذاری مدل سهبعدی مغز به صورت امن | |
| func loadBrainModel() { | |
| do { | |
| let brainEntity = try Entity.load(named: "brain") | |
| // Anchor for placing the brain in AR space | |
| let anchor = AnchorEntity(plane: .horizontal) | |
| anchor.addChild(brainEntity) | |
| arView.scene.addAnchor(anchor) | |
| } catch { | |
| print("❌ Failed to load brain model: \(error)") | |
| } | |
| } | |
| // MARK: - Gesture Setup | |
| // اضافه کردن ژست لمس به صفحه | |
| func setupTapGesture() { | |
| let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) | |
| arView.addGestureRecognizer(tap) | |
| } | |
| // MARK: - Handle Tap | |
| // مدیریت لمس کاربر روی مدل سهبعدی | |
| @objc func handleTap(_ sender: UITapGestureRecognizer) { | |
| let location = sender.location(in: arView) | |
| if let entity = arView.entity(at: location) { | |
| showBrainInfo(for: entity) | |
| } | |
| } | |
| // MARK: - Show Brain Information | |
| // نمایش اطلاعات آموزشی براساس بخش لمسشده مغز | |
| func showBrainInfo(for entity: Entity) { | |
| guard let info = brainInfo[entity.name] else { | |
| showAlert(title: "Brain Region", message: "No information available for this region.") | |
| return | |
| } | |
| showAlert(title: "Brain Information", message: info) | |
| } | |
| // MARK: - UI Alert | |
| // نمایش پنجره اطلاعات به کاربر | |
| func showAlert(title: String, message: String) { | |
| let alert = UIAlertController(title: title, | |
| message: message, | |
| preferredStyle: .alert) | |
| alert.addAction(UIAlertAction(title: "OK", style: .default)) | |
| present(alert, animated: true) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NeuronPhysiologyManager.swift | |
| // HeroBrainAR | |
| // | |
| // Created by Amir Saeid Dehghan | |
| // | |
| import Foundation | |
| import RealityKit | |
| import ARKit | |
| // MARK: - Neuron Structure Information | |
| // اطلاعات بخشهای مختلف نورون | |
| struct NeuronPart { | |
| /// Name of the neuron structure | |
| /// نام ساختار نورونی | |
| let name: String | |
| /// Educational description shown to the user | |
| /// توضیح آموزشی که به کاربر نمایش داده میشود | |
| let description: String | |
| } | |
| // MARK: - Neuron Knowledge Base | |
| // پایگاه اطلاعاتی نورون | |
| let neuronInfo: [String: NeuronPart] = [ | |
| "Dendrite": NeuronPart( | |
| name: "Dendrite", | |
| description: "Receives incoming signals from other neurons." | |
| ), | |
| "Soma": NeuronPart( | |
| name: "Cell Body", | |
| description: "Contains the nucleus and processes information." | |
| ), | |
| "Axon": NeuronPart( | |
| name: "Axon", | |
| description: "Conducts electrical impulses away from the cell body." | |
| ), | |
| "Myelin": NeuronPart( | |
| name: "Myelin Sheath", | |
| description: "Insulates the axon and increases conduction speed." | |
| ), | |
| "Synapse": NeuronPart( | |
| name: "Synapse", | |
| description: "Communication point between neurons." | |
| ) | |
| ] | |
| // MARK: - Tap Interaction | |
| // مدیریت لمس کاربر روی بخشهای نورون | |
| @objc func handleNeuronTap(_ recognizer: UITapGestureRecognizer) { | |
| // Get touch location on screen | |
| // دریافت محل لمس روی صفحه | |
| let location = recognizer.location(in: arView) | |
| // Detect tapped entity | |
| // شناسایی آبجکت لمس شده | |
| if let entity = arView.entity(at: location) { | |
| let entityName = entity.name | |
| // Check if entity exists in neuron database | |
| // بررسی وجود ساختار در دیتابیس نورون | |
| if let info = neuronInfo[entityName] { | |
| // Display educational information | |
| // نمایش اطلاعات آموزشی | |
| showInformation( | |
| title: info.name, | |
| description: info.description | |
| ) | |
| // Highlight selected structure | |
| // هایلایت کردن بخش انتخاب شده | |
| highlight(entity) | |
| } | |
| } | |
| } | |
| // MARK: - Highlight Selected Structure | |
| // برجستهسازی ساختار انتخاب شده | |
| func highlight(_ entity: Entity) { | |
| // Verify entity contains a model | |
| // اطمینان از وجود مدل سهبعدی | |
| guard var model = entity.components[ModelComponent.self] else { | |
| return | |
| } | |
| // Apply yellow material for highlighting | |
| // اعمال متریال زرد برای برجستهسازی | |
| model.materials = [ | |
| SimpleMaterial( | |
| color: .systemYellow, | |
| roughness: 0.1, | |
| isMetallic: false | |
| ) | |
| ] | |
| entity.components.set(model) | |
| } | |
| // MARK: - Action Potential Simulation | |
| // شبیهسازی پتانسیل عمل | |
| func animateActionPotential() { | |
| // Starting point of electrical signal | |
| // نقطه شروع سیگنال عصبی | |
| let startPosition = SIMD3<Float>(0,0,0) | |
| // End point along the axon | |
| // نقطه پایان در امتداد آکسون | |
| let endPosition = SIMD3<Float>(0,0,-0.5) | |
| actionPotentialEntity.position = startPosition | |
| // Animate signal propagation | |
| // انیمیشن حرکت پیام عصبی | |
| actionPotentialEntity.move( | |
| to: Transform( | |
| scale: .one, | |
| rotation: simd_quatf(), | |
| translation: endPosition | |
| ), | |
| relativeTo: nil, | |
| duration: 2.0 | |
| ) | |
| } | |
| // MARK: - Neurotransmitter Release | |
| // آزادسازی ناقلهای عصبی | |
| func releaseNeurotransmitters() { | |
| // Simulate neurotransmitter particles | |
| // شبیهسازی ذرات ناقل عصبی | |
| print("Dopamine Released") | |
| print("Serotonin Released") | |
| print("Acetylcholine Released") | |
| print("Glutamate Released") | |
| print("GABA Released") | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Designed and Optimized for iPad Experience