IOS 用arkit实现全景效果和粒子效果。

最近发生点小状况,因此把实现的AR全景做的demo,没有与大家分享。T_T

本文共2部分:1.全景效果;2.粒子效果。

第一部分:先看下demo实现效果吧。

gif图片效果不太好。请大家包涵。

下面开始介绍下关键代码部分吧。(如果没有arkit的基础的,请查看我之前的文章,点击这里https://www.jianshu.com/p/c379a1e48810)

创建一个球的模型 (3d全景图片素材来自网络获取,如有侵犯,请告知删除,各种模型https://www.jianshu.com/p/f1381d5cac0d)

        SCNSphere*sphere =[SCNSpheresphereWithRadius:10];

        sphere.firstMaterial.diffuse.contents= [UIImage                imageNamed:self.dataArray[index]];

        SCNNode*node = [SCNNodenodeWithGeometry:sphere];

        sphere.firstMaterial.doubleSided =YES;

        node.position= vector3;

        node.name= [NSStringstringWithFormat:@"%d",i];


上面设置模型的双面单层属性,即可贴上模型内部贴图。

基本操作就是这样了,需要实现球的自传和球围绕中心点的旋转。(请点击这里查看我之前的模型动作https://www.jianshu.com/p/fde8c1725899)


第二部分:也先看下demo实现效果吧。

这是雪花粒子效果。

主要代码部分:

    SCNParticleSystem *particle = [SCNParticleSystem particleSystemNamed:@"art.scnassets/snow/snow.scnp" inDirectory:nil];

    particle.birthLocation = SCNParticleBirthLocationSurface;

    SCNPlane*bottomFrameGeo = [SCNPlaneplaneWithWidth:30height:30];

    bottomFrameGeo.firstMaterial.diffuse.contents = [UIColor clearColor];

    SCNNode* snowNode = [SCNNodenodeWithGeometry:bottomFrameGeo];

    snowNode.castsShadow=NO;

    snowNode.position=SCNVector3Make(0,  10,0);

    SCNParticleSystem*bottomParticle = particle;

    bottomParticle.emitterShape= bottomFrameGeo;

    [snowNodeaddParticleSystem:bottomParticle];

    snowNode.eulerAngles=SCNVector3Make(-M_PI_2,0,0);

    returnsnowNode;

主要是存放在art.scnassets里的snow.scnp文件(如有需要请留言,再次就不解释了)

还有2个效果:

桃花雨

夜空加流星雨:

代码在此就不放了。如有需要,请留言。

你可能感兴趣的:(IOS 用arkit实现全景效果和粒子效果。)