Today, let's briefly SceneKit the texture map.
1, the simplest way to directly open a DAE or SCN file directly set
For example, there is only one geometry in this Dae file, only one material ball in the geometry, and then the diffuse property of the material ball is set.
2, code settings, or for this simplest Dae file
Ceilnode. Geometry. firstmaterial.Diffuse. contents = [Uicolor redcolor];//You can set the color Ceilnode. Geometry . firstmaterial. Diffuse. Contents = @"20151026n222-zw-dmax_ms_400-280-390_n_muv-0_lyx.jpg";// You can set the picture (name) Ceilnode. Geometry.firstmaterial. Diffuse.contents = [UIImage imagenamed:@] 20151026n222-zw-dmax_ms_400-280-390_n_muv-0_lyx.jpg "];//You can set the picture
The two run the same effect:
Above is the simplest case, there is only one material ball, we can also set a number of material balls, such as the box of six faces, each face of the pattern is different, then we use a number of material ball to achieve this effect
SCNMaterial *allMaterial = [SCNMaterial new]; allMaterial.diffuse.contents = @"allwall.png"; SCNMaterial *smallMaterial1 = [SCNMaterial new]; smallMaterial1.diffuse.contents [email protected]"bottomWall.png"; rightwall.geometry.materials = @[smallMaterial1,allMaterial,[smallMaterial1 copy],allMaterial,allMaterial,allMaterial];
Note the position of each face of the box: @[front,right,back,left,top,bottom];
My demo I created a wall, but also found a problem, such as:
Obviously, two of the windows are inconsistent, in reality it is unreasonable, so we need to change the map.
We adjust the texture of this material ball:
NSArray *allMaterial = rightwall.geometry.materials; SCNMaterial *smallMaterial2= allMaterial[1]; smallMaterial2.diffuse.contentsTransform = SCNMatrix4MakeScale(-1,1,1); //就是这句,调整一下贴图的方向 smallMaterial2.diffuse.wrapT = SCNWrapModeRepeat; smallMaterial2.diffuse.wrapS = SCNWrapModeRepeat;
Scnmaterial also has a lot of properties, you can go to see the official documents on their own.
OK, simple stickers simply say this.
But the reality is, we often use the complex model, there are many geometry, a geometry and a lot of material balls, so there will be a lot of posters, if the above method, to map themselves, it will be very troublesome.
In fact, the modeler has helped you to put a good picture. You may later encounter how to let the modeler export to you a Dae file suitable for scenekit use.
A preliminary study of the Ios-scenekit3d engine-to the material map