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

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

问题描述

情况

我正在 xcode (11.3.1) 中制作 AR 应用.我已经使用现实编辑器将对象(例如立方体)添加到场景中,并使用现实编辑器向这些对象添加了行为(即点击和翻转并查看相机).保存,切换到 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 = 尝试!经验.loadBox()arView.scene.anchors.append(boxAnchor)boxAnchor.actions.repetitive.onAction = self.remodelling}fileprivate func 重塑(_ 实体:实体?){守卫让实体=实体其他{返回}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)lazy var actions: Actions { get set }

repetitive 是:

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

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 :错误 {案例文件未找到(字符串)}公共静态 func loadBox() 抛出 ->ActionsAndBehaviours.Experience.Boxpublic static func loadBoxAsync(完成:@escaping (Result<ActionsAndBehaviours.Experience.Box, Error>) -> Void)公共类框:实体,HasAnchoring {public var steelBox:实体?{ 得到 }懒惰的公共私有(设置)var 动作: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天全站免登陆