Draw textured circle / 2D shape

I have the following code to create a circle Path and a SCNShape from this path. orbit_gradient.png is a horizontal 1px high image that represents a gradient.


let material = SCNMaterial()
material.isDoubleSided = true
material.lightingModel = .constant     
material.diffuse.contents = UIImage(named: "art.scnassets/orbit_gradient.png")

let shapePath = Path.circle(radius: radius, segments: 512)

let orbitShape = SCNShape(shapePath)
orbitShape.materials = [material]  
self.orbitNode.geometry = orbitShape


The problem I have is that when applying the texture to this geometry I'm just left with a white circle. If I set the diffuse to be UIColor.red it displays as red. What I want to accomplish is a stroked circle that appears to gradually fade, creating a rotating trail effect.

Accepted Reply

Got there in the end by using SCNGeometrySource and SCNGeometryElement.


  1. Generate vertices
  2. Generate texture coordinates
  3. Generate indices
  4. Set material (my horizontal, 1px tall gradient)


I've made a gist of an SCNNode subclass I made incase it's useful to anyone else.


https://gist.github.com/kemalenver/79523e5606f62c5958fcf5e9bedc48a5

Replies

Got there in the end by using SCNGeometrySource and SCNGeometryElement.


  1. Generate vertices
  2. Generate texture coordinates
  3. Generate indices
  4. Set material (my horizontal, 1px tall gradient)


I've made a gist of an SCNNode subclass I made incase it's useful to anyone else.


https://gist.github.com/kemalenver/79523e5606f62c5958fcf5e9bedc48a5