IOS - Adding a 2D image to a scenekit game

Hello, I can't let my life work on how to add a 2D image to a scene using scenekit, is this possible? What I'm trying to accomplish is to have a three-dimensional flying plane over a 2D background image, but the background image cannot cover the entire screen. Thanks to everyone who can help.

+5
source share
3 answers

Others said many good suggestions above.

Let me summarize each solution with different scenarios:

  • Using scnScene.background : The simplest, but fullscreen and static. You cannot display in a smaller area of ​​the scene, nor can you customize the transforms.

  • Using scnScene.overlaySKScene to display a 2D SKScene and add an image sprite. This probably matches your scenario. If you want a static one, but with custom conversions, this is a good choice. Notably, overlaySKScene recommends Apple create a HUD in your 3D scene.

    However, if you want 2D content to track 3D movement, you need to do some coordinate conversion from three-dimensional space to 2D space in each frame. The bad news is that the work is done by the processor, which will add drag and drop performance. (Believe me, this will also upset me!)

  • Using SCNNode with SCNNode geometry and set diffuse.content with image; add SCNBillBoardConstraint to node so that it always faces the camera.

    The most flexible. However, if your camera is not spelling, the image will increase as the camera settings change, which does not look like a two-dimensional, but rather a hanging 3D advertising billboard.

+5
source

You can use the background property in SCNScene to set the background image.

 scnScene.background.contents = UIImage(named: "myImage") 

Contents

You can set a value for this property using any of the following Types:

Color (NSColor / UIColor or CGColorRef), indicating a constant color over the surface of materials

Image (NSImage / UIImage or CGImageRef) that defines the texture applied to the surface of the material

An NSString or NSURL object that defines the location of the image file

An array of six images (NSArray) defining the faces of a cube map

Basic Animation Level (CALayer)

Texture (SKTexture, MDLTexture, MTLTexture or GLKTextureInfo)

Sprint Recruitment Script (SKScene)

+2
source

SceneKit and SpriteKit play very well together.

Embed a 2D background image as a SceneKit node with SCNPlane geometry using your image as plane material. If you want to become more attractive, use the full SpriteKit scene as SCNPlane material. Place this node at the far end of your truncated camera, in front of your 3D airplane.

You might also consider providing a cube map (skybox) as the background of the scene. See SCNScene.background .

+2
source

Source: https://habr.com/ru/post/1241755/


All Articles