Hi,
I have a problem with scaling objects. In my 3D software I have objects that scale to zero within an animation. So in the 3d software they are not visible anymore. When I export the animated geometries as fbx, load them into RealityComposer and play the animation, the objects no longer scale to zero, they just become very small. But they are still visible.
Does anyone also have this problem and does anyone know a solution?
Thanks
Post not yet marked as solved
Hi,
I have a question about how to control behaviors from Xcode .
I have loaded a RealityComposer file (.rcproject-file) to Xcode. In Xcode storyboard I made a button and executed a behavior, which I have implemented in RealityComposer before.
This works great.
@IBAction func button(_ sender: Any) {
Anchor!.notifications.actionname.post()
}
But now I want the notification be executed when the rcproject file starts. So, when the .rcproject file starts, this behavior should be executed first.
How can I do this??
Thanks
Post not yet marked as solved
Hi, it's me again. I have now solved my three problems.
i can load .rcproject files in Xcode.
i can assign gestures to a group of objects created in RealityComposer (the group contains two spirals. One
I can use a menu button to affect behaviors of objects I created in RealityComposer. (A spiral fades out at startup and fades back in when the button is clicked).
Individually, this all works the way I thought it would.
But now I want to bring it all together.
So I put everything together in a ViewController. But now I see two groups of objects on my device. One group reacts to the gestures and the other reacts to the button and the notifications. How do I get both the notifications and the gesture control to work together on one group.
You can find me project here:
https://wetransfer.com/downloads/2e217e5d86d273360fb50a7298e986b520220203152701/26a044d7ffc54197ac6055c4065f6f1c20220203152827/cf5ad8
Thanks for your help.
Thomas
Hello,
after a lot of trial and error, I managed to move/scale/rotate a simple object with gestures. In retrospect, it was actually quite simple. If you know how to do it.
But now I have a new problem. Maybe you would be so kind again and help me.
I took the Augmented Reality base file in Xcode (the one with the Experience.rcproject file in it). I entered this code in the ViewController:
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
if let box = boxAnchor.steelBox?.children.first as? ModelEntity {
box.generateCollisionShapes(recursive: true)
arView.installGestures(.all, for: box)
}
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
}
And it works. The object, that is the cube, can be controlled with gestures.
Then I created a second object (I duplicated the cube) in RealityComposer (from Xcode), renamed it and grouped it with the first cube. I named the group "boxGroup." Then I adjusted the code accordingly so that the reference no longer goes to "steelBox", but to "boxGroup". But now the gesture control doesn't work.
Here is the code for it:
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
if let box = boxAnchor.boxGroup?.children.first as? ModelEntity {
box.generateCollisionShapes(recursive: true)
arView.installGestures(.all, for: box)
}
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
}
What am I doing wrong?
Thanks for your help.
Thomas
Post not yet marked as solved
Hi, it's me again. I try to understand gestures but perhaps i have a knot in my brain.
I have completed a tutorial in which I had to load an usdz-file into Xcode and then add gestures to it. It worked fine. But if I replace the usdz-file with a .reality-file or .rcproject-file I created in RealityComposer it fails with the message: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: RealityKit.Entity.LoadError.resourceNotFound("TestSpiralr") (TestSpiralr is the .reality-file)
how do I get the script running.
Thanks
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// LOAD MODEL
// let entity = try! ModelEntity.loadModel(named: "cup_saucer_set"/*usdz-file*/)
let entity = try! ModelEntity.loadModel(named: "TestSpiralr"/*reality-file*/)
// ENABLE GESTURES
entity.generateCollisionShapes(recursive: true)
arView.installGestures([.translation, .rotation, .scale], for: entity)
// CREATE ANCHOR
let anchor: AnchorEntity = AnchorEntity(plane: .horizontal, classification: .any)
// PLACE ANCHOR IN THE SCENE
arView.scene.addAnchor(anchor)
// ADD ENTITY TO ANCHOR
anchor.addChild(entity)
}
}
Post not yet marked as solved
Hi, i'm new in xcode and swift and I tried to add gestures to my AR View. But it failed. I can see the modell (a helix) when opening with my iPhone and move around but I can't rotate the modell with my fingers. I didn't get any error message in xcode.
TestSpiral is a simple .rcproject file I generated in RealityComposer.
I use xcode 12.4.
Thanks for your help.
Sorry. I tried to attach the project but this is not possible. This is the code:
code-block
import UIKit
import RealityKit
import ARKit
import SceneKit
class ViewController: UIViewController {
@IBOutlet var gestureRecognizer: UIRotationGestureRecognizer!
// DECLARE VARIABLE MODELANCHOR
var modelAnchor: TestSpiral.MainScene?
// ALLOW INTERACTION
var isUserInteractionEnabled = Bool (true)
// DECLARE VARIABLE ARVIEW
@IBOutlet weak var sceneView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// GESTURE ROTATION
func rotatePiece(_ gestureRecognizer: UIRotationGestureRecognizer) {
guard gestureRecognizer.view != nil else {return}
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
gestureRecognizer.view?.transform = gestureRecognizer.view!.transform.rotated(by: gestureRecognizer.rotation)
gestureRecognizer.rotation = 0
}}
// LOAD MODELL
modelAnchor = try! TestSpiral.loadMainScene()
sceneView.scene.anchors.append(modelAnchor!)
}
}
Post not yet marked as solved
Hi, I'm new to Xcode and I have a little problem I can't solve.
I used the code that I attached. If I load the SpiralTest.usdz file everything works fine. If I load the SpiralTest.rcproject file it fails. But I have to use the rcproject-file. How do I have to customize the code.
I tried to send the files with this message, but i can't choose .usdz or zip. But you can test ist with any other usdz and rcproject file.
Thanks for your help.
Thomas
import UIKit
import RealityKit
import ARKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool){
super.viewWillAppear(true)
arView.session.delegate = self
setupCustomObjectView()
let tabGesture = UITapGestureRecognizer(target: self, action: #selector(onTap))
arView.addGestureRecognizer(tabGesture)
}
func setupCustomObjectView () {
arView.automaticallyConfigureSession = false
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.horizontal, .vertical]
configuration.environmentTexturing = .automatic
arView.session.run(configuration)
}
@IBAction func onTap(recognizer: UITapGestureRecognizer) {
let location = recognizer.location(in: arView)
let results = arView.raycast(from: location, allowing: .estimatedPlane, alignment: .horizontal)
if let firstResult = results.first {
let anchor = ARAnchor(name: "SpiralTest.rcproject“, transform: firstResult.worldTransform)
arView.session.add(anchor: anchor)
} else {
print("Object placement failed")
}
}
func placeObject(name entityName: String, for anchor:ARAnchor){
let entity = try! ModelEntity.loadModel(named: entityName)
entity.generateCollisionShapes(recursive: true)
arView.installGestures([.rotation, .scale], for: entity)
let anchorEntity = AnchorEntity(anchor: anchor)
anchorEntity.addChild(entity)
arView.scene.addAnchor(anchorEntity)
}
}
extension ViewController: ARSessionDelegate {
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
for anchor in anchors {
if let anchorObject = anchor.name, anchorObject == "SpiralTest.rcproject“ {
placeObject(name: anchorObject, for: anchor)
}
}
}
}
Post not yet marked as solved
Hi,
I have two questions about USDZ/USDA, Xcode and html5.
I have created an object in Reality Composer and animated it. The actions are started via notifications.This works perfectly when I open the Reality Composer file (.rcproject) in Xcode and program the buttons accordingly.
Now my questions are:
is there a possibility to open USDZ/USDA files in Xcode instead of the .rcproject file? If so, how does this work?
is there a possibility to create a web page with buttons in html5 and execute the actions in a USDZ/USDA file with these buttons, using the notifications?
Thanks a lot
Post not yet marked as solved
Hello all,
I have a question about WebAR and Reality Composer. I have built a WebAR configurator. The configurator has of course a menu with which I can call different colours and functions. At the moment I put the menu in the scene and it rotates of course when the viewer moves around the object. But that is not nice. Now my question is: Is it possible to create a menu that lies over the scene as an overlay and does not rotate with the object? Or is it possible to create a menu in HTML5 and use it to control the behaviour in the WebAr application?
Thank you for your answers.
Thomas
Post not yet marked as solved
Hi,
I have a problem with reality composer. Everything's works fine but when I look at the AR-result in a browser white objects look yellowish/greyish. This is particularly noticeable when viewed in AR on a background with white walls.
This also happens with objects (white cubes) that I create in reality composer.
Is this done intentionally to contrast with white backgrounds?
Or am I doing something wrong?
Does anyone have a solution to the problem?
Thanks