एआरकेट में विमान दृश्यता को लागू करते समय मुझे एक समान समस्या का सामना करना पड़ा। मैं पता लगाया विमान को चेकरबोर्ड पैटर्न के रूप में देखना चाहता था। मैंने कस्टम SCNNode को "प्लेन नोड" नामक एक सही कॉन्फ़िगर किया गया है जिसे सही ढंग से कॉन्फ़िगर किया गया SCNMaterial है। सामग्री wraps, wrapT = .pepeat का उपयोग करती है और विमान के आकार के आधार पर सही ढंग से स्केल की गणना करती है।
इस तरह लग रहा है:
नीचे कोड पर एक नज़र डालें, इनलाइन टिप्पणी स्पष्टीकरण होते हैं।
class PlaneNode : SCNNode {
init(planeAnchor: ARPlaneAnchor) {
super.init()
// Create the 3D plane geometry with the dimensions reported
// by ARKit in the ARPlaneAnchor instance
let planeGeometry = SCNPlane(width:CGFloat(planeAnchor.extent.x), height:CGFloat(planeAnchor.extent.z))
// Instead of just visualizing the grid as a gray plane, we will render
// it in some Tron style colours.
let material = SCNMaterial()
material.diffuse.contents = PaintCode.imageOfViewARPlane
//the scale gives the number of times the image is repeated
//ARKit givest the width and height in meters, in this case we want to repeat
//the pattern each 2cm = 0.02m so we divide the width/height to find the number of patterns
//we then round this so that we always have a clean repeat and not a truncated one
let scaleX = (Float(planeGeometry.width)/0.02).rounded()
let scaleY = (Float(planeGeometry.height)/0.02).rounded()
//we then apply the scaling
material.diffuse.contentsTransform = SCNMatrix4MakeScale(scaleX, scaleY, 0)
//set repeat mode in both direction otherwise the patern is stretched!
material.diffuse.wrapS = .repeat
material.diffuse.wrapT = .repeat
//apply material
planeGeometry.materials = [material];
//make a node for it
self.geometry = planeGeometry
// Move the plane to the position reported by ARKit
position.x = planeAnchor.center.x
position.y = 0
position.z = planeAnchor.center.z
// Planes in SceneKit are vertical by default so we need to rotate
// 90 degrees to match planes in ARKit
transform = SCNMatrix4MakeRotation(-Float.pi/2.0, 1.0, 0.0, 0.0);
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func update(planeAnchor: ARPlaneAnchor) {
guard let planeGeometry = geometry as? SCNPlane else {
fatalError("update(planeAnchor: ARPlaneAnchor) called on node that has no SCNPlane geometry")
}
//update the size
planeGeometry.width = CGFloat(planeAnchor.extent.x)
planeGeometry.height = CGFloat(planeAnchor.extent.z)
//and material properties
let scaleX = (Float(planeGeometry.width)/0.02).rounded()
let scaleY = (Float(planeGeometry.height)/0.02).rounded()
planeGeometry.firstMaterial?.diffuse.contentsTransform = SCNMatrix4MakeScale(scaleX, scaleY, 0)
// Move the plane to the position reported by ARKit
position.x = planeAnchor.center.x
position.y = 0
position.z = planeAnchor.center.z
}
}
जीयूआई में ऐसा करने का कोई तरीका पता है? दुर्भाग्यवश – jfisk
@jfisk नहीं। मेरा सबसे अच्छा अनुमान किसी भी तरह से sprites का उपयोग करना होगा, लेकिन मैंने इसे एक अच्छा जवाब देने के लिए पर्याप्त नहीं देखा है। – krntz