You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playgrounds App中SCNSceneSource的identifiersOfEntries功能异常求助

可验证的DAE示例与SCNSceneSource标识符提取解决方案

我先给你一个极简且可直接验证的DAE文件内容,你可以把它保存为test.dae并添加到Playgrounds的Resources目录中,测试sceneSource.identifiersOfEntries(withClass: SCNGeometry.self)是否能正常返回标识符:

<?xml version="1.0" encoding="UTF-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
  <library_geometries>
    <geometry id="cube_geometry" name="CubeGeometry">
      <mesh>
        <source id="cube_vertices">
          <float_array id="cube_vertices_array" count="24">
            1 1 1 -1 1 1 -1 -1 1 1 -1 1 1 1 -1 -1 1 -1 -1 -1 -1 1 -1 -1
          </float_array>
          <technique_common>
            <accessor source="#cube_vertices_array" count="8" stride="3">
              <param name="X" type="float"/>
              <param name="Y" type="float"/>
              <param name="Z" type="float"/>
            </accessor>
          </technique_common>
        </source>
        <source id="cube_normals">
          <float_array id="cube_normals_array" count="24">
            0 0 1 0 0 1 0 0 1 0 0 1 0 0 -1 0 0 -1 0 0 -1 0 0 -1
          </float_array>
          <technique_common>
            <accessor source="#cube_normals_array" count="8" stride="3">
              <param name="X" type="float"/>
              <param name="Y" type="float"/>
              <param name="Z" type="float"/>
            </accessor>
          </technique_common>
        </source>
        <vertices id="cube_vertex_bindings">
          <input semantic="POSITION" source="#cube_vertices"/>
          <input semantic="NORMAL" source="#cube_normals"/>
        </vertices>
        <triangles count="12">
          <input semantic="VERTEX" source="#cube_vertex_bindings" offset="0"/>
          <p>0 1 2 0 2 3 4 5 6 4 6 7 0 4 7 0 7 3 1 5 4 1 4 0 1 0 3 1 3 2 2 3 7 2 7 6</p>
        </triangles>
      </mesh>
    </geometry>
  </library_geometries>
  <library_nodes>
    <node id="cube_node" name="CubeNode">
      <instance_geometry url="#cube_geometry"/>
    </node>
  </library_nodes>
  <scene>
    <instance_node url="#cube_node"/>
  </scene>
</COLLADA>

测试步骤

  1. 将上述内容复制到文本编辑器,保存为test.dae
  2. 在Playgrounds中,把这个文件添加到Resources目录
  3. 运行你的代码(修改文件名对应为test):
guard let url = Bundle.main.url(forResource: "test", withExtension: "dae") else { fatalError("Failed to find model file") }
let sceneSource = SCNSceneSource(url: url, options: nil)!
let identifiers = sceneSource.identifiersOfEntries(withClass: SCNGeometry.self) as [String]
print("Geometry identifiers: \(identifiers)")

运行后你应该能看到输出:Geometry identifiers: ["cube_geometry"]

关于你SketchUp导出问题的分析

从你的描述来看,问题大概率出在SketchUp导出DAE时的格式映射上:

  • 虽然原始DAE的XML里有id="geometry1",但Xcode的SceneKit在导入时,可能没有将这个XML的id映射为SCNGeometry的identifier属性
  • 你手动修改XML后仍无效,可能是因为SceneKit对DAE的解析不仅看几何元素的id,还要求几何在节点实例化时的关联方式符合它的预期,或者SketchUp导出时默认没有保留能被SceneKit识别的标识符元数据
  • 建议你在SketchUp导出DAE时,检查导出选项:确保勾选了保留组件名称/标识符相关的选项(不同版本的SketchUp选项名称可能略有不同),或者尝试导出为Collada 1.5版本再测试

另外,你也可以用上述测试用的DAE文件转换为SCN格式,再测试identifiersOfEntries,验证转换后的文件是否能正常返回标识符,以此排除格式转换环节的问题。

内容的提问来源于stack exchange,提问作者Clay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:26:45