[英]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项目有树文件:
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.