6 Replies
      Latest reply on Nov 3, 2015 1:51 AM by WarpRulez
      WarpRulez Level 1 Level 1 (0 points)

        Normally I use cocos2d, but in this one project I need to use SpriteKit.

         

        It seems to me that in SpriteKit you can draw sprites and... well, basically nothing else, really. At least that I can find.

         

        In cocos2d you have always been able to draw custom triangle meshes. (In older versions you had to use OpenGL ES directly for this, but it was perfectly possible, although slightly more inefficient than could be. In newer versions there is direct support for defining custom textured triangle meshes, which are automatically batched.) This has been extremely useful, as it allows extreme freedom of creating various objects that are very difficult, if not even impossible, to implement as sprites.

         

        Is it possible, somehow, to draw custom textured triangle meshes in a SpriteKit project? And of course preferably as efficiently as the underlying hardware allows (ie. calling directly OpenGL or Metal triangle mesh drawing, whichever SpriteKit is using.)

        • Re: Drawing textured triangle meshes
          greven Apple Staff Apple Staff (70 points)

          Hi WarpRulez,

           

          If SKShapeNode does not fit your need then you can use SceneKit directly. SpriteKit and SceneKit are aspects of the same thing. SpriteKit is for 2D sprites and SceneKit is for more complex 3D meshes. You can render 3D mesh content directly into your SpriteKit scene via SK3DNode

          https://developer.apple.com/library/prerelease/tvos/documentation/SpriteKit/Reference/SK3DNode/index.html#//apple_ref/occ/cl/SK3DNode

           

          That should give you complete control over 3D meshes to make any effect you like.

           

          Cheers

            • Re: Drawing textured triangle meshes
              WarpRulez Level 1 Level 1 (0 points)

              So this effectively renders a SceneKit scene into a texture, and then draws that texture as a sprite in SpriteKit? How efficient is that method?

                • Re: Drawing textured triangle meshes
                  deeeds Level 2 Level 2 (30 points)

                  He doesn't understand your question, hence the tangential nature of the answer.

                   

                  That 2D drawing exists in Cocos2D is a minor miracle.

                   

                  Anyone from Apple, search for this, and consider it, it's true to its name, a very primitive type of 2D drawing this could be done much better if anyone was interested in providing dynamic drawing in 2D - I'm not posting a link because they get stuck waiting for needless approval:

                   

                  ----------------------

                  Primitive

                  Primitive is added to support Points,Lines,Triangles rendering. Previously, if we want to draw a custom geometry(sphere, line), we can only do this by using CustomCommand. Now, what is need is to create a Primitive, set datas, and use the corresponding PrimitiveCommand to draw the Primitive.

                  -----------------------------------

                   

                  Most programmers of 2D games and game engines have no idea what animated 2D drawing is, and why animators considering designing games might want it, let alone how it might be used.


                  But the fault doesn't start there.

                   

                  Once 3D became a thing, 2D optimisations and empowerment became a thing of the past, and all graphics hardware focused its efforts on 3D.

                   

                  So there's no efficient way to do 2D drawing, and to do it well (with the kind of flexibility and dynamism you probably desire) requires someone to build an engine that constricts OpenGL triangle creation to a 2D plane and starts creating your drawings with triangles on that plane.

                   

                  For that to then work for custom lines and animating them requires a lot more work, and is the subject of many interesting articles on how to then anti-alias these flat textured polygons in 2D space so they look like lines we're comfortable viewing.

                   

                  Sound ridiculous? It is.

                   

                  It gets funnier, of course. This problem has extended far outside realtime engines: Adobe's After Effects doesn't have decent 2D dynamic drawing either. Nodes (vertices) of a 2D drawing are not individually addressable, only editable in what amounts to an "analogue" manner.

                   

                  Sprite Kit has SKShapeNode, which I'm sure you've found, but it's performance is barely even good enough for debugging physics bodies, and immutable. It was never intended to be a drawing facility in the sense you're asking about.

                   

                  I'm not sure it's possible to articulate to a programmer how a desirable, truly flexible dynamic drawing facility should work in under 50 back and forth exchanges because they have odd misconceptions and are primarily against it because it's a technical nightmare and much work to make something truly great in terms of dynamic 2D drawing.

                   

                  Interestingly, the same immutablity problem exists in Scene Kit's geometry creation facilities. They really don't care for dynamic geometry, let alone dynamic drawing.

                    • Re: Drawing textured triangle meshes
                      WarpRulez Level 1 Level 1 (0 points)

                      My question is not related to free 2D drawing. I am perfectly aware of using OpenGL (or Metal) for emulating 2D games, which is what libraries like cocos2d and SpriteKit do, and its limitations.

                       

                      My question was related to being able to define my own (textured) triangle meshes (either constricted to the 2D plane, or even 3D meshes). In cocos2d you could always do this in the past by writing OpenGL ES calls directly, and with the current version there's even direct support (which makes it more efficient by using batching, or something like that.)

                    • Re: Drawing textured triangle meshes
                      greven Apple Staff Apple Staff (70 points)

                      Hi WarpRulez,

                       

                      When using an SK3DNode SceneKit draws directly into the same context, not to a texture.

                       

                      To draw to a texture and use that as a sprite is another possible solution, but more cumbersome and less performant to using an SK3DNode.

                       

                      Cheers