1

Could someone tell me the lines of code I need to copy the UVs from one model to another (which have identical topology) in Swift?

Or how to export a UVSet from Autodesk Maya and apply it to a 3D model in Scenekit?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Geoff H
  • 3,107
  • 1
  • 28
  • 53

2 Answers2

1

Texture coordinates are stored in SCNGeometrySource instances. To copy a source to another geometry you'll have to combine them and create a new geometry using the geometryWithSources:elements: constructor.

mnuages
  • 13,049
  • 2
  • 23
  • 40
  • Is there any chance you would be able to supply the code chunk showing exactly how this is done? – Geoff H Apr 30 '18 at 15:54
  • To give the bigger picture what I'm trying to do is texture map the `ARSCNFaceGeometry` in the way that I want. I've exported the mesh to Maya. So I can texture it & alter the uv mapping there. I want to bring this new texture mapping back into scenekit & replace the uv mapping of the `ARSCNFaceGeometry`. Is `SCNGeometrySource` definitely the way to go, or is there a better way? I notice that `SCNMaterialProprty` has `mappingChannel`. Could this be used instead? Would I need to export the UV list from Maya to do this? – Geoff H Apr 30 '18 at 16:56
0

Here's a MEL code for getting .OBJ geometry and its corresponding .MTL texture from Maya:

// select poly object
select -r pSphereShape1 ;

// shift-select a procedural texture (assigned as Blinn) in Hypershade
select -tgl blinn1 ;

// assign "Edit – Convert to file texture..." command in Hypershade
convertSolidTx -resolutionX 1024 -resolutionY 1024 -fileFormat "jpg" ramp1.outColor pSphere1 ;
// This results in "file2" in Hypershade

// select new shader
select -r blinn2 ;

// "File – Export Selected Network" command in Hypershade
file -op "groups=1; ptgroups=1; materials=1; smoothing=1; normals=1; " -typ "OBJexport" -pr -es "/Users/swift/Desktop/texture.obj" ;

/* 
This results in:
/Users/swift/Desktop/texture.obj
/Users/swift/Desktop/texture.mtl
*/

Read here: How To Apply .MTL File on .OBJ 3d Model via SceneKit & Model I/O.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220