Swift'de çekirdek grafikleriyle bir 3D nesneyi (tercihen bir dikdörtgen) nasıl çizebilirim?Swift'de 3B nesneyi çekirdek grafiklerle nasıl çizebilirsiniz?
Bu mümkün mü yoksa farklı bir kütüphane mi kullanmalıyım?
UIKit ile mümkün mü?
Swift'de çekirdek grafikleriyle bir 3D nesneyi (tercihen bir dikdörtgen) nasıl çizebilirim?Swift'de 3B nesneyi çekirdek grafiklerle nasıl çizebilirsiniz?
Bu mümkün mü yoksa farklı bir kütüphane mi kullanmalıyım?
UIKit ile mümkün mü?
Bu yanıt Borçlanma: https://stackoverflow.com/a/24127282/887210
anahtar bölümü sorunuza içindir:
SCNBox(width: 1, height: 4, length: 9, chamferRadius: 0)
Bu SceneKit ve UIKit ile dikdörtgen kutu çizer. Projenizde özel bir UIViewController'da kullanılmak üzere ayarlanmıştır, ancak diğer kullanımlara kolayca uyarlanabilir.
örnek kod:
override func loadView() {
// create a scene view with an empty scene
let sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
let scene = SCNScene()
sceneView.scene = scene
// default lighting
sceneView.autoenablesDefaultLighting = true
// a camera
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
scene.rootNode.addChildNode(cameraNode)
// a geometry object
let box = SCNBox(width: 1, height: 4, length: 9, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
scene.rootNode.addChildNode(boxNode)
// configure the geometry object
box.firstMaterial?.diffuse.contents = UIColor.redColor()
box.firstMaterial?.specular.contents = UIColor.whiteColor()
// set a rotation axis (no angle) to be able to
// use a nicer keypath below and avoid needing
// to wrap it in an NSValue
boxNode.rotation = SCNVector4(x: 1, y: 1, z: 0.0, w: 0.0)
// animate the rotation of the torus
let spin = CABasicAnimation(keyPath: "rotation.w") // only animate the angle
spin.toValue = 2.0*M_PI
spin.duration = 10
spin.repeatCount = HUGE // for infinity
boxNode.addAnimation(spin, forKey: "spin around")
view = sceneView // Set the view property to the sceneView created here.
}
Bu yüzden bir oyun değil bir projeye bu kapsadığını nasıl. ViewViewer – Tob
için sceneView eklemek Eğer örnek UIViewController alt sınıf içine gömmek için nasıl görebileceğinizi güncelledim. 'LoadView() 'yöntemini temel olarak geçersiz kılarsınız ve' view' özelliğini 'sceneView' değişkenine ayarlayınız. – ColGraff
Teşekkürler harika çalışıyor :) – Tob