问题
The situation
I am making an AR app in xcode (11.3.1). I have added objects (e.g. a cube) into the scene using reality composer and added behaviours (i.e. tap and flip and look at camera) to those objects, also using reality composer. Saved that, switched to ViewController.swift
In ViewController, I load in the Experience.rcproject
and access the default Box
scene by writing var box = try! Experience.loadBox()
. All works as expected.
I am then printing the various objects in the hierachy to understand how they are constructed. So I will for example write print(box)
and see all the entities and components as they are described here
The problem
I can see things like Transform
for position etc. and ModelComponent
for the mesh, materials etc. and this all makes sense but I cannot see where the behaviours are stored within the object that the .rcproject becomes within swift.
For example, if I have added a look at camera
behaviour in reality composer, my assumption would be that there would be something like a `billboard' component attached to that object, but I don't see any difference between objects that have behaviours applied, and those that don't..
Another example would be, having addded tap and flip
to an object, I would expect to find some animation information somewhere within the object, but again I can't see it attached to the object. Nor can I see any animation info, or behaviour components any where within the scene object.
Does anywhere know where I might be able to access these? There seems to be something under box
called actions
but printing that simply returns Experience.Box.Actions
with no more info.
Am I looking in the wrong place? Or are these not exposed?
回答1:
Print Entity
to get a path containing components:
let boxAnchor = try! Experience.loadBox()
let entity = boxAnchor.steelBox!
print(entity as Any)
print(entity.components[PhysicsBodyComponent] as Any)
Then apply new values:
var physicsComponent: PhysicsBodyComponent = entity.components[PhysicsBodyComponent]!
physicsComponent.mode = .dynamic
boxAnchor.steelBox?.components.set(physicsComponent)
arView.scene.anchors.append(boxAnchor)
来源:https://stackoverflow.com/questions/60004402/reality-kit-where-are-behaviours-created-in-reality-composer-stored-in-the-r