Как я могу получить сущность, чтобы постоянно смотреть на камеру в RealityKit, похожие на ограничения на рекламные щиты IOS

Программируем под IOS
Ответить
Anonymous
 Как я могу получить сущность, чтобы постоянно смотреть на камеру в RealityKit, похожие на ограничения на рекламные щиты

Сообщение Anonymous »

У меня есть приложение, которое я пытаюсь обновить от Scenekit до RealityKit, и одна из функций, которые мне трудно воспроизвести в RealityKit, - это предприятие постоянно смотреть на камеру. В Scenekit это было достигнуто путем добавления следующих ограничений на рекламный щит в узел: < /p>

Код: Выделить всё

let billboardConstraint = SCNBillboardConstraint()

billboardConstraint.freeAxes = [.X, .Y]
startLabelNode.constraints = [billboardConstraint]
< /code>
, что позволило бы свободно вращаться startLabelNode, чтобы он постоянно смотрел на камеру без того, чтобы StartLabelNode изменил свою позицию. Я попробовал метод «поиска», который, похоже, не дает возможности постоянно столкнуться с камерой.  Вот короткое приложение, в котором я пытался реализовать версию этого в RealityKit, но оно не дает возможности, чтобы объект постоянно сталкивался с камерой, как это было в Scenekit: < /p>
import UIKit
import RealityKit
import ARKit

class ViewController: UIViewController, ARSessionDelegate {
@IBOutlet weak var arView: ARView!

override func viewDidLoad() {
super.viewDidLoad()

arView.session.delegate = self
arView.environment.sceneUnderstanding.options = []
arView.debugOptions.insert(.showSceneUnderstanding) // Display a debug visualization of the mesh.
arView.renderOptions = [.disablePersonOcclusion, .disableDepthOfField, .disableMotionBlur] // For performance, disable render options that are not required for this app.
arView.automaticallyConfigureSession = false
let configuration = ARWorldTrackingConfiguration()
if ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh) {
configuration.sceneReconstruction = .mesh
} else {
print("Mesh Classification not available on this device")
configuration.worldAlignment = .gravity
configuration.planeDetection = [.horizontal, .vertical]
}
configuration.environmentTexturing = .automatic
arView.session.run(configuration)

UIApplication.shared.isIdleTimerDisabled = true // Prevent the screen from being dimmed to avoid interrupting the AR experience.
}

@IBAction func buttonPressed(_ sender: Any) {
let screenWidth = arView.bounds.width
let screenHeight = arView.bounds.height
let centerOfScreen = CGPoint(x: (screenWidth / 2), y: (screenHeight / 2))

if let raycastResult = arView.raycast(from: centerOfScreen, allowing: .estimatedPlane, alignment: .any).first
{
addStartLabel(at: raycastResult.worldTransform)
}
}

func addStartLabel(at result: simd_float4x4) {
let resultAnchor = AnchorEntity(world: result)
resultAnchor.addChild(clickToStartLabel())
arView.scene.addAnchor(resultAnchor)
}

func clickToStartLabel() -> ModelEntity {
let text = "Click to Start Here"
let textMesh = MeshResource.generateText(text, extrusionDepth: 0.001, font: UIFont.boldSystemFont(ofSize: 0.01))
let textMaterial = UnlitMaterial(color: .black)
let textModelEntity = ModelEntity(mesh: textMesh, materials: [textMaterial])
textModelEntity.generateCollisionShapes(recursive: true)
textModelEntity.position.x -= textMesh.width / 2
textModelEntity.position.y -= textMesh.height / 2

let planeMesh = MeshResource.generatePlane(width: (textMesh.width + 0.01), height: (textMesh.height + 0.01))
let planeMaterial = UnlitMaterial(color: .white)
let planeModelEntity = ModelEntity(mesh: planeMesh, materials: [planeMaterial])
planeModelEntity.generateCollisionShapes(recursive:true)
// move the plane up to make it sit on the anchor instead of in the middle of the anchor
planeModelEntity.position.y += planeMesh.height / 2
planeModelEntity.addChild(textModelEntity)

// This does not always keep the planeModelEntity facing the camera
planeModelEntity.look(at: arView.cameraTransform.translation, from: planeModelEntity.position, relativeTo: nil)

return planeModelEntity
}
}

extension MeshResource {
var width: Float
{
return (bounds.max.x - bounds.min.x)
}

var height: Float
{
return (bounds.max.y - bounds.min.y)
}
}
Является ли функция поиска лучшим способом получить недостающую функцию в реальности или есть лучший способ, чтобы объект постоянно сталкивался с камерой?


Подробнее здесь: https://stackoverflow.com/questions/705 ... -similar-t
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»