【问题标题】:how to create accurate collision for 3d meshes? (ios arkit or realitykit)如何为 3d 网格创建准确的碰撞? (ios arkit 或 realitykit)
【发布时间】:2023-03-08 10:41:01
【问题描述】:

我想用arview.scene.raycast(origin: SIMD3<Float>, direction: SIMD3<Float>打3d模型, 使用generateCollisionShapes(recursive: true) 产生盒子碰撞 问题是:我想打模型的表面,有没有办法创建准确的碰撞

我使用的是 arkit 和 realitykit不是scenekit

【问题讨论】:

    标签: ios arkit realitykit


    【解决方案1】:

    使用generateCollisionShapes(recursive: Bool) 生成一个非常简单的盒子作为碰撞组件。 为了创建代表椅子的精确碰撞体,您需要使用模型的网格作为其 CollisionComponent:

    yourModelEntity.collision = CollisionComponent(shapes: [ShapeResource.generateConvex(from: yourModelEntity.model!.mesh)]
    

    更有效的方法是创建模型的低多边形版本并将其用作其 CollisionComponent。

    【讨论】:

      【解决方案2】:
      if let  model = arView.scene.findEntity(named: name) as? ModelEntity {
      
                  if let m = model.model {
                      model.components[CollisionComponent] =  CollisionComponent(shapes: [ShapeResource.generateConvex(from: m.mesh)])
                  }
      
              }
      

      【讨论】:

        猜你喜欢
        • 2023-01-31
        • 2020-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2013-08-10
        相关资源
        最近更新 更多