Skip to content

Instantly share code, notes, and snippets.

View lukas-ruzicka's full-sized avatar

Lukas Ruzicka lukas-ruzicka

View GitHub Profile
@lukas-ruzicka
lukas-ruzicka / CocoaPods_WeakImport.ruby
Last active February 3, 2020 09:55
If you want to import framework for higher OS version than your app's deployment target, you need to add this snippet in your Podfile. It makes the framework import weak, so it is ignored for the cases, where the framework is not available. Otherwise, your app will crash immediately, when it tries to import the framework.
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == '_The pod name_'
target.build_configurations.each do |config|
config.build_settings['OTHER_LDFLAGS'] = ["-weak_framework", "\"_The native framework name_\""]
end
end
end
end
@lukas-ruzicka
lukas-ruzicka / RealityKit_AddingRCProjectContentToDetectedObjectAnchor_cz.swift
Last active February 3, 2020 08:26
Implementace metody `ARSessionDelegate`, která je volána pokaždé, když je detekována nová kotva. Pokud chcete přidat obsah Reality Composer projektu do scény, stačí jen ověřit jestli je nalezená kotva typu `ARObjectAnchor` a pak jen přidat obsah RC projektu do scény se změněnou kotvou. Toto je je jednoduchá implementace k demonstraci použití.
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
// `ARObjectAnchor` je kotva definovaného referenčního objektu
guard let objectAnchor = (anchors.first(where: { $0 is ARObjectAnchor })) as? ARObjectAnchor else { return }
let entity = try! Entity.loadScene()
// Následujícím přiřazením `AnchoringComponent` (s identifikátorem nalezené kotvy) definujeme pozici přidané entity
entity.anchoring = AnchoringComponent(.anchor(identifier: objectAnchor.identifier))
arView.scene.addAnchor(entity)
}
@lukas-ruzicka
lukas-ruzicka / RealityKit_AddingRCProjectContentToDetectedObjectAnchor.swift
Last active February 3, 2020 08:18
Implementation of `ARSessionDelegate`'s method, which is called every time new anchor is detected. If you want to add Reality Composer project content, you just need to make sure, that the detected anchor is `ARObjectAnchor`, then add the RC project content to the scene with changed anchor. Just base implementation to demonstrate the usage.
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
// `ARObjectAnchor` is the anchor of the defined reference model
guard let objectAnchor = (anchors.first(where: { $0 is ARObjectAnchor })) as? ARObjectAnchor else { return }
let entity = try! Entity.loadScene()
// With the following assignment of the `AnchoringComponent` (with found anchor identifier) we define the position of the added entity
entity.anchoring = AnchoringComponent(.anchor(identifier: objectAnchor.identifier))
arView.scene.addAnchor(entity)
}
@lukas-ruzicka
lukas-ruzicka / RealityKit_AddingReferenceObjectsToDetect_cz.swift
Last active February 3, 2020 08:30
Načtení a přiřazení referenčních objektů (naskenovaných reálných objektů) do AR session.
// Načtení referenčních objektů z assetů
guard let referenceObjects = ARReferenceObject.referenceObjects(inGroupNamed: "AppParade33Exhibition",
bundle: nil) else { return }
config.detectionObjects = referenceObjects
// Pro "poslouchání" vývoje scény je nutné přiřadit delegáta session
arView.session.delegate = self
arView.session.run(config, options: options)
@lukas-ruzicka
lukas-ruzicka / RealityKit_AddingReferenceObjectsToDetect.swift
Last active February 3, 2020 08:29
Loading and assigning of reference objects (scanned real-world objects) to the AR session.
// Loading reference objects from assets
guard let referenceObjects = ARReferenceObject.referenceObjects(inGroupNamed: "AppParade33Exhibition",
bundle: nil) else { return }
config.detectionObjects = referenceObjects
// In order "to listen" to the scene development, there needs to be a session delegate assigned
arView.session.delegate = self
arView.session.run(config, options: options)
@lukas-ruzicka
lukas-ruzicka / RealityKit_AddingRCProjectToARSession.swift
Created February 3, 2020 07:56
Base adding of Reality Composer project content to the AR session
let entity = try! Entity.loadScene()
arView.scene.anchors.append(entity)
arView.session.run(config, options: options)