SceneKit: Simple 3D game Scene setup

Source: Internet
Author: User

Scenekit is the framework Apple uses to develop casual 3D games, unlike the underlying OpenGL libraries, where you can quickly see the actual 3D scene effects with very little code. Here's a quick chat about what you need to do to build a 3D game scene.

First you have to use other 3D modeling tools to generate the 3D model you need, with a DAE or SCN, and a texture picture attached.

You can import the three-dimensional model file along with the texture picture into Xcode, here's an example

Some children's shoes may not know how to open the scene graph interface, just click on the next line of the local button to the left of the box button:

You can add lights, cameras, and other elements attached to the Scnnode in the scene diagram interface:

Scenekit also comes with some simple 3D geometry classes, such as spheres, cones, and so on. You can combine them into a more complex 3D form and put them into a 3D scene. I'll give you some examples later.

Below we can import the scene into the view:

let"art.scnassets/hero.scn")letastruetrue

For the sake of fun, let's add a few simple geometries to the scene:

Func Boxnode ()->scnnode{Let box = Scnbox (width:Ten, Height:Ten, Length:Ten, Chamferradius:1) Let Boxnode = Scnnode (geometry:box) Boxnode. Geometry?. Firstmaterial?. Diffuse. Contents= Uicolor. Browncolor() Boxnode. Position= SCNVector3 (x:0,y:Ten,Z: - -) Return Boxnode}mainscene. RootNode. Addchildnode(Boxnode ())

Similar to several other simple geometries, the settings are the same.

In the end, we scenekit also built in a class scntext that directly transforms the string into a geometry, so we can easily generate 3D text in the game scene.

Func createstartingtext ()->scnnode{Let Starttext = Scntext (string:"Giant panda pig Patty", Extrusiondepth:5) Starttext. Chamferradius=0.5Starttext. Flatness=0.3Starttext. Font= Uifont (Name:"Copperplate", Size: -) Starttext. Firstmaterial?. Specular. Contents= Uicolor. Bluecolor() Starttext. Firstmaterial?. Diffuse. Contents= Uicolor. Yellowcolor() Starttext. Firstmaterial?. shininess=0.4Let Textnode = Scnnode (geometry:starttext) textnode. scale= SCNVector3 (x:0.75,y:0.75,Z:0.75) Textnode. Position= SCNVector3 (x:0,y: -,Z: - -) Return Textnode}

Finally run the app to see the effect:

It's pretty good, isn't it?]

SceneKit: Simple 3D game Scene setup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.