【问题标题】:How to render a scene with WKInterfaceSCNScene on watchOS 3?如何在 watchOS 3 上使用 WKInterfaceSCNScene 渲染场景?
【发布时间】:2016-09-30 11:40:26
【问题描述】:

我尝试将 ScenKit 场景添加到 WKInterfaceController,创建了 IBOutlet WKInterfaceSCNScene* sceneInterface; (如记录)并将场景属性放入刚刚创建的 SceneKit 场景的界面构建器中,但我没有在手表上看到该场景。

我也尝试过使用 presentScene 方法,并以编程方式设置场景如下:

SCNScene *scene = [SCNScene sceneNamed:@"circleScene.scn"];

// create and add a camera to the scene
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
[scene.rootNode addChildNode:cameraNode];

// place the camera
cameraNode.position = SCNVector3Make(0, 0, 15);

// create and add a light to the scene
SCNNode *lightNode = [SCNNode node];
lightNode.light = [SCNLight light];
lightNode.light.type = SCNLightTypeOmni;
lightNode.position = SCNVector3Make(0, 10, 10);
[scene.rootNode addChildNode:lightNode];

// create and add an ambient light to the scene
SCNNode *ambientLightNode = [SCNNode node];
ambientLightNode.light = [SCNLight light];
ambientLightNode.light.type = SCNLightTypeAmbient;
ambientLightNode.light.color = [UIColor darkGrayColor];
[scene.rootNode addChildNode:ambientLightNode];

[self.sceneInterface presentScene:scene withTransition:[SKTransition fadeWithDuration:1] incomingPointOfView:lightNode completionHandler:nil];

我做错了什么?

【问题讨论】:

    标签: watchkit scenekit watchos-3


    【解决方案1】:

    调试“我的场景为空白”问题时要检查的标准事项:

    • 场景加载是否正确?
    • 相机是否指向场景中的对象?尝试添加SCNLookAtConstraint
    • 摄像头位置是否在对象之外?
    • SCNView 是否使用您创建的相机?
    • 相机的 Z 范围设置是否正确? (设置automaticallyAdjustsZRange:YES开头)
    • sceneInterface 的插座是否已连接?

    如果您在 Playground 中运行此代码,则更容易让所有移动部件一起工作。

    【讨论】:

    • 场景在标准 SCNView(在 iOS ViewController 中)中正确渲染,但在 WKInterfaceController 中没有出现。
    • 嗯。添加几个 NSAssert 调用以确保 scenesceneInterface 不为零,并且界面的摄像头是您创建的那个怎么样?
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2010-09-27
    相关资源
    最近更新 更多