简体   繁体   English

如何在反应原生中桥接SceneKit?

[英]How to bridge SceneKit in react native?

I start learning react native component creation. 我开始学习反应原生组件创建。 I have a little SceneKit project which show a single plan in a 3d view (I started from this tutorial ). 我有一个SceneKit项目,在3d视图中显示单个计划(我从本教程开始)。

My goal is to bridge this view to get control over the 3D native camera with Javascript. 我的目标是桥接此视图以使用Javascript控制3D本机相机。

I don't know where to start. 我不知道从哪里开始。 All resources on the web about creating a component is far away my scope, use external lib or are not detailed enough for a newbie like me. 网络上关于创建组件的所有资源都远远不是我的范围,使用外部库或者对于像我这样的新手来说还不够详细。

My scenekit project has tree files: 我的scenekit项目有树文件:

  • a main.storyboard (but is is compabible with a react native component ?) with a single SceneKit view 使用单个SceneKit视图的main.storyboard(但是可以与react本机组件相比?)
  • a ControllerView 一个ControllerView
  • and an AppDelegate 和一个AppDelegate

App Delegate: 应用代表:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    return true
  }
}

View Controller 查看控制器

import UIKit
import SceneKit

class ViewController: UIViewController {

// UI
@IBOutlet weak
var sceneView: SCNView!

    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        sceneSetup()
    }

func sceneSetup() {
    let scene = SCNScene()

    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light!.type = SCNLightTypeAmbient
    lightNode.light!.color = UIColor(white: 0.5, alpha: 1)
    scene.rootNode.addChildNode(lightNode)

    let plan = SCNPlane(width: 20, height: 40)
    plan.firstMaterial!.diffuse.contents = UIColor.whiteColor()
    let planNode = SCNNode(geometry: plan)
    planNode.transform = SCNMatrix4MakeRotation(-90, 1, 0, 0)
    scene.rootNode.addChildNode(planNode)

    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    cameraNode.position = SCNVector3(0, 0, 50)
    scene.rootNode.addChildNode(cameraNode)

    sceneView.scene = scene
    sceneView.allowsCameraControl = true
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
}

// MARK: IBActions
@IBAction func segmentValueChanged(sender: UISegmentedControl) {

}

// MARK: Style
override func preferredStatusBarStyle() - > UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}

// MARK: Transition
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    sceneView.stop(nil)
    sceneView.play(nil)
}

}

First of all. 首先。 Is this bridgable to RN? 这对布鲁姆来说是不可思议的?

This is a really old question but being doing this myself recently and was able to get SceneKit running ok as a subview of a UIView, making use of React Native doc's iOS 'Native UI Components' tutorial as the basis for this approach...Hope it helps someone. 这是一个非常古老的问题,但最近我自己做了这个并且能够让SceneKit作为UIView的子视图运行正常,利用React Native doc的iOS“Native UI Components”教程作为这种方法的基础...希望它可以帮助某人。

Manager file 经理文件

#import <React/RCTViewManager.h>

@interface RCTDeviceManager : RCTViewManager
@end

@implementation RCTDeviceManager

RCT_EXPORT_MODULE()

DeviceView *view;

- (UIView *)view
{
  view = [[DeviceView alloc] init];
  return view;
}

@end

UIView file UIView文件

import SceneKit
import UIKit

@objc(DeviceView)
class DeviceView: UIView {

override init(frame: CGRect) {

super.init(frame: frame)

  // create a new scene
  let scene = SCNScene(named: "art.scnassets/devices.scn")!

  // add cameras, lighting etc

  // SCNView & subview
  let scnView = SCNView(frame: CGRect(x: 0, y: 0, width: 1024, height: 768))
  self.addSubview(scnView)
  scnView.scene = scene
 }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ObjectC 中为 React Native 桥接 Swift 视图 - How to bridge Swift View in ObjectC for React Native 如何从反应原生桥将参数传递给 swift class - How to pass parameter to swift class from react native bridge React Native 桥 IOS 原生模块 undefined - React Native bridge IOS native module undefined 在React Native桥上调用方法时,Bridge是nil,使用单例? - Bridge is nil when calling methods on React Native bridge, use a singleton? React-Native iOS - 如何在启动屏幕之后,在初始化 React Native Bridge (iOS) 之前显示视图控制器 - React-Native iOS - How to show a view controller after Launch screen, before initialising react native bridge (iOS) React Native错误:没有可用的桥接实现,放弃了 - React Native Error: No bridge implementation is available, giving up React Native-如果在桥类中进行初始化,则计时器功能不起作用 - React Native - Timer function is not working if init inside the bridge class 在 iOS 应用程序中使用 rct 桥来表示 React Native 中的表格视图 - Using an rct bridge in iOS app to represent table view in react native React-native:为什么JS桥是性能瓶颈 - React-native: why JS bridge is the performance bottleneck React Native - 在 Xcode 中创建桥头的正确方法 - React Native - The right way to create bridge header in Xcode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM