Reality Composer中创建的“行为"在哪里存储在.rcproject中? [英] Where are 'behaviours' created in Reality Composer stored in .rcproject?

查看:91
本文介绍了Reality Composer中创建的“行为"在哪里存储在.rcproject中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

我正在用xcode(11.3.1)制作一个AR应用程序.我已经使用Reality Composer向场景中添加了对象(例如,立方体),并使用Reality Composer向这些对象添加了行为(即,轻按并翻转并看着相机).保存后,切换到 ViewController.swift

在ViewController中,我加载 Experience.rcproject 并通过编写 var box = try来访问默认的 Box 场景.Experience.loadBox().所有工作都按预期进行.

然后,我在层级结构中打印各种对象,以了解它们是如何构造的.因此,例如,我将编写 print(box)并查看

以下是RealityKit的代码:

  class ViewController:UIViewController {@IBOutlet var arView:ARView!覆盖func viewDidLoad(){super.viewDidLoad()让boxAnchor =试试!Experience.loadBox()arView.scene.anchors.append(boxAnchor)boxAnchor.actions.repetitive.onAction = self.remodelling}fileprivate函数重塑(_实体:实体?){守卫让实体=实体其他{返回}entity.children [0] .position.x = -0.25让modelEntity = entity.children [0]为!模型实体modelEntity.model?.mesh = .generateSphere(半径:0.1)modelEntity.model?.materials = [UnlitMaterial(color:.green)]}} 

actions 实例属性在哪里:

  public private(set)惰性var操作:操作{获取设置} 

重复是:

  public私有(设置)lazy var重复:Experience.NotifyAction {获取设置} 

onAction 是:

  public var onAction:((Entity?)-> Void)? 


其他信息

以下是 ActionsAndBehaviours.Experience.Box.Actions 的不可编辑内容:

  import合并进口基金会导入RealityKit导入SwiftOnoneSupport导入UIKit导入simd@available(iOS 13.0,macOS 10.15,*)公共枚举经验{公共类NotifyAction {公共租赁标识符:字符串public var onAction:((Entity?)-> Void)?}公共枚举LoadRealityFileError:错误{案例fileNotFound(String)}公共静态函数loadBox()抛出->行为与行为体验盒公共静态函数loadBoxAsync(完成:@转义(Result< ActionsAndBehaviours.Experience.Box,Error>)->无效)公共类Box:实体,HasAnchoring {public var steelBox:实体?{ 得到 }惰性公共私有(设置)变量操作:ActionsAndBehaviours.Experience.Box.Actions公共集体诉讼{懒惰的公共私有(设置)var重复:ActionsAndBehaviours.Experience.NotifyAction懒惰的公共私有(设置)var allActions:[ActionsAndBehaviours.Experience.NotifyAction]}}} 

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?

解决方案

Partial Solution

You can access and recreate behaviours in a certain, quite limited way. For that you need to include Notify action with definite name in action's sequence in Reality Composer.

Here's how a code for RealityKit looks like:

class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let boxAnchor = try! Experience.loadBox()
        arView.scene.anchors.append(boxAnchor)

        boxAnchor.actions.repetitive.onAction = self.remodelling
    }
    
    fileprivate func remodelling(_ entity: Entity?) {

        guard let entity = entity else { return }
        entity.children[0].position.x = -0.25
        
        let modelEntity = entity.children[0] as! ModelEntity
        modelEntity.model?.mesh = .generateSphere(radius: 0.1)
        modelEntity.model?.materials = [UnlitMaterial(color: .green)]
    }
}

Where actions instance property is:

public private(set) lazy var actions: Actions { get set }

repetitive is:

public private(set) lazy var repetitive: Experience.NotifyAction { get set }

onAction is:

public var onAction: ((Entity?) -> Void)?


Additional Info

Here's non-editable content for ActionsAndBehaviours.Experience.Box.Actions:

import Combine
import Foundation
import RealityKit
import SwiftOnoneSupport
import UIKit
import simd

@available(iOS 13.0, macOS 10.15, *)
public enum Experience {

    public class NotifyAction {

        public let identifier: String

        public var onAction: ((Entity?) -> Void)?
    }

    public enum LoadRealityFileError : Error {

        case fileNotFound(String)
    }

    public static func loadBox() throws -> ActionsAndBehaviours.Experience.Box

    public static func loadBoxAsync(completion: @escaping (Result<ActionsAndBehaviours.Experience.Box, Error>) -> Void)

    public class Box : Entity, HasAnchoring {

        public var steelBox: Entity? { get }

        lazy public private(set) var actions: ActionsAndBehaviours.Experience.Box.Actions

        public class Actions {

            lazy public private(set) var repetitive: ActionsAndBehaviours.Experience.NotifyAction

            lazy public private(set) var allActions: [ActionsAndBehaviours.Experience.NotifyAction]
        }
    }
}

这篇关于Reality Composer中创建的“行为"在哪里存储在.rcproject中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆