Loading gif image in SCNNode- ARKit(SceneKit) using CALayer not rendering properly

I am working on an AR application in which i am rendering a 3D model.


Upon tapping a child node i am displaying a gif image by creating animation using CALayer and loading it in diffuse.contents by following this thread https://stackoverflow.com/questions/24125701/set-contents-of-calayer-to-animated-gif/41646638#41646638


let animation : CAKeyframeAnimation = createGIFAnimation(url: gifImageURL!)!

let layer = CALayer()

layer.bounds = CGRect(x: 0, y: 0, width:600, height:200)

layer.add(animation, forKey: "contents")


let newMaterial = SCNMaterial()

newMaterial.isDoubleSided = true

newMaterial.diffuse.contents = layer

let plane = SCNPlane(width: 5, height: 5)

plane.materials = [newMaterial]

let node = SCNNode(geometry: plane)

self.sceneView.scene.rootNode.addChildNode(node)


I am able to render the gif image in SCNNode but it is displaying only half of it(Right bottom most portion of gif is only visible). I tried below steps to rectify this but still in vain

  • Changing Plane's width/height
  • Changing the bounds of CALayer
  • Tried with different sizes of gif image


Anyone please help me how to render a full gif image in SCNPlane using CALayer.

Accepted Reply

Hi Yali, there are some known issues with setting SCNMaterialProperty diffuse contents to CALayer. In a high level attempt to rule those out, what happens if you use a `UIView` as the material contents instead? Configure the UIView's CALayer in the same manner as before, or use UIImageView properties to set the gif images. I know that setting UIView as material contents is not documented yet but it will be done soon.

Replies

Hi Yali, there are some known issues with setting SCNMaterialProperty diffuse contents to CALayer. In a high level attempt to rule those out, what happens if you use a `UIView` as the material contents instead? Configure the UIView's CALayer in the same manner as before, or use UIImageView properties to set the gif images. I know that setting UIView as material contents is not documented yet but it will be done soon.

This seems to slightly relate to another thread I just created. Bobjt : however using a UIView directly as the diffuse contents, I can't manage to obtain a transparent one, a "_SCNSnapshotWindow" gets created in the hierarchy and it's background gets default to white, changing it doesn't affect anything. Is there a workaround for that ?