2
votes

Is it possible with ARKit/SceneKit to texture a DAE/SCN model programatically, on-the-fly?

Use case is: I will have 1 model that I would like to "skin" with potentially thousands of similar-yet-different textures. And I can either:

  • Texture the models ahead of time and force either my app or my backend to host thousands of bulky textured model files (the all use the same heavier 3D model/mesh file and each combine it with a different lighter 2D texture file); or
  • Allow my app/backend to ship with 1 heavy/bulky 3D mesh/model file, and thousands of lighter 2D texture files, and then use some SceneKit/ARKit API to apply the correct texture to the model in-memory, on-the-fly

Is this dynamic texturing capablity possible? If so, how? If not, then why (curious!)?

2

2 Answers

2
votes

Yes, changing the texture image(s) for a 3D object at runtime is a basic capability of nearly all high-level 3D engines, including SceneKit.

In short, find the material you want to change, and set its diffuse.contents to the texture image you want to use.

For a more thorough understanding, read up on materials in the SceneKit documentation, or go back to the WWDC videos from 2013 and 2014 that introduce the basics of SceneKit.

1
votes

Yes, of course you can change the texture of a model programmatically. Simply assign the texture image to the .diffuse.contents property of the SCNMaterial that is assigned to the geometry. I.e. yourModel.firstMaterial.diffuse.contents = someImage

Additionally, “similar-yet-different” textures sounds like a job for shaders. Using scenekit shaderModifiers you can modify a texture image on~the-fly by using the processing power of the GPU, with endless possibilities.