简体   繁体   English

在设备上运行时没有childNodes

[英]Don't have childNodes when running on device

I've created a simple project to try out SceneKit, added a scene which contains a man character and a camera. 我创建了一个简单的项目来试用SceneKit,并添加了一个包含人物角色和照相机的场景。

The problem is the code behaves differently on the simulator and on the device. 问题是代码在模拟器和设备上的行为不同。

When loading the man character into a SCNNode object, in the simulator this "man" node has child nodes, which themselves contain geometry. 将man角色加载到SCNNode对象时,在模拟器中,此“ man”节点具有子节点,这些子节点本身包含几何图形。

However when running on device, the man node contains no child nodes and itself have the geometry. 但是,在设备上运行时,man节点不包含任何子节点,并且本身具有几何形状。

Why is that so? 为什么会这样? Can someone explain what exactly I messed up? 有人可以解释我到底搞砸了什么吗?

I've uploaded the sample project to GitHub so you could check it out and run it on your simulator and device. 我已将示例项目上传到GitHub,因此您可以将其检出并在模拟器和设备上运行。

https://github.com/iamBlueGene/SceneKitExperiment https://github.com/iamBlueGene/SceneKitExperiment

Thanks, Eli. 谢谢,以利。

I think I've figured this one out. 我想我已经弄明白了。

The problem is that because the vertexs are split across the containers in the .dae file is due to limitations on the number of vertexes, different configuration can open the file differently. 问题在于,由于顶点在.dae文件中的各个容器之间分裂,是由于对顶点数量的限制,因此不同的配置可以不同地打开文件。

You can try opening the scene again and exporting it again (or maybe just the character if you can) and check again. 您可以尝试再次打开场景并再次导出场景(如果可以的话,也可以只是导出角色),然后再次检查。

I added the following method to your ViewController.m just to see what was going on. 我将以下方法添加到您的ViewController.m只是为了查看发生了什么。

- (void)printNodeTree: (SCNNode*)node levelIndent:(NSString*) indent{

    if (node != nil) {
        BOOL hasGeom = node.geometry == nil;
        NSString *nodeName = [NSString stringWithFormat:@"%@%@", indent, node.name];
        NSString *geomStr = [NSString stringWithFormat:@"%@ has geometry: %@", indent, hasGeom ? @"YES" : @"NO"];
        printf("%s \n", [nodeName UTF8String]);
        printf("%s \n", [geomStr UTF8String]);

        for (id childNode in [node childNodes]) {
            [self printNodeTree:childNode levelIndent:[NSString stringWithFormat:@"%@   ",indent]];
        }
    } else {
        return;
    }
}

And received the following output when running on both the simulator and device (when passing a reference to the man node). 在模拟器和设备上运行时(将引用传递给man节点时)都收到以下输出。

Model_1 
 has geometry: YES 
   Model_1-splitContainer 
    has geometry: YES 
      Model_1-splitContainer-split0 
       has geometry: NO 
      Model_1-splitContainer-split1 
       has geometry: NO 
      Model_1-splitContainer-split2 
       has geometry: NO 
      Model_1-splitContainer-split3 
       has geometry: NO 
      . . .

This seems to line up with what you saw when running on the the device. 这似乎与您在设备上运行时看到的一致。 Looking in both the XCode scene editor and Blender showed that there were several components that were apparently being merged. 在XCode场景编辑器和Blender中查看时,发现显然有多个组件被合并。

There are some options you can specify when importing a scene. 导入场景时可以指定一些选项。 The default is documented as not flattening the scene (as we observe is happening), but just to confirm I tried the following. 据记录,默认设置没有使场景变平(正如我们观察到的那样),但只是为了确认我尝试了以下操作。 This produced the same output as above. 这产生了与上述相同的输出。

NSDictionary* sceneLoadOpts = [NSDictionary dictionaryWithObjectsAndKeys:
    SCNSceneSourceFlattenSceneKey, [NSNumber numberWithBool:NO],
    nil];

SCNScene *characterScene = [SCNScene sceneNamed:@"character-male-muscle.dae"
    inDirectory:nil 
    options:sceneLoadOpts];

The device (or simulator for that matter) doesn't load the .dae file directly. 设备(或与此相关的模拟器)不会直接加载.dae文件。 This is compiled by the scntool into a c3d file. scntool将其编译为c3d文件。 I converted the dae to a c3d file, then back to a dae and found the different components remained. 我将dae转换为c3d文件,然后又转换回dae,发现保留了其他组件。 The flattening was not a result of this compression process. 扁平化不是此压缩过程的结果。

Finally I loaded the model in Blender and rearranged the model tree so that all the geometry nodes were at the same level as the parent node. 最后,我将模型加载到Blender中,并重新排列了模型树,以使所有几何节点与父节点处于同一级别。 This indeed resulted in multiple geometry components on both the simulator and device, but that's probably going a little far... 这确实在模拟器和设备上都导致了多个几何图形组件,但是可能还差得远……

The vertex counts (65535) and names of these components ("splitContainerX") seem to indicate they are only separate geometry components due to constraints on vertex indexing (2^16). 顶点计数(65535)和这些组件的名称(“ splitContainerX”)似乎表明,由于对顶点索引的限制(2 ^ 16),它们只是单独的几何组件。 In short, I don't think you really want to treat this model as separate components anyway. 简而言之,我不认为您真的想将此模型视为单独的组件。 Current theory is that there's a flag somewhere in the dae file that states these components should be merged when possible. 当前的理论是,在dae文件中的某处有一个标志,指出应尽可能合并这些组件。

暂无
暂无

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

相关问题 没有设备的特定版本时如何测试? - How do you test against a specific version when you don't have a device with the version? 即使我的iOS设备中没有Google地图,“ canOpenURL”也返回true? - 'canOpenURL' returning true even when I don't have google maps in my iOS device? 运行unittes时不要启动模拟器 - Don't launch simulator when running unittests 有没有一种方法可以设置iOS模拟器默认值,以便在重置设备时不必重置键盘和Facebook? - Is There a Way to Setup iOS Simulator Defaults so I Don't Have to Reset Keyboard & Facebook When I Reset the Device? 无法打开该文件,因为您没有查看它的权限(真实设备) - The file couldn’t be opened because you don’t have permission to view it (REAL DEVICE) 当我没有 UIViewController 时如何链接 viewDidLoad - How to link viewDidLoad when I don't have UIViewController 有没有办法从React Native的chrome控制台重新加载设备,所以我不必经常摇动它? - Is there a way to reload the device from the chrome console in React Native so I don't have to constantly shake it? 如何在没有iPhone 5s设备的情况下测试Touch ID功能 - How to test Touch ID feature while don't have iPhone 5s device 如果我没有Bluetooth LE设备,那么我是否试图编写程序就很不走运? - If I don't have a Bluetooth LE device am I just out of luck with trying to write a program? 在表格行上滑动时没有删除按钮 - Don't have delete button when swipe on table row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM