Nikesh Jha
Nikesh Jha

Reputation: 281

How to add image texture to 3D asset in Xcode using SceneKit

I have a 3D model for a coffee mug which is in .dae format. Now what I need is - to place a logo (a png image) in on it. How can I achieve this?

Upvotes: 1

Views: 1254

Answers (2)

Xartec
Xartec

Reputation: 2415

This isn’t really a Scenekit or IOS question. To apply a texture to a 3D model the model needs UV coordinates per vertex. The process of mapping a 3d model to a 2d texture is known as UV mapping ( https://en.m.wikipedia.org/wiki/UV_mapping ) and is done in 3d software like Blender, 3D studio max and similar packages, before the assets (model and textures) are used in Scenekit.

That said, in this case, because a mug is largely a cylinder, you could perhaps get away with using a SCNCylinder (which automatically comes with UV coords) and using the image with the logo, with a transparent background, as a texture for the cylinder. And then scale and position the cylinder over the mug and add it as a child node of the mug.

Upvotes: 2

norman784
norman784

Reputation: 2221

If you have your model in a node, yo can access the material trough the geometry like this

node.geometry?.firstMaterial?.diffuse.contents = <put your image here>

with this you will replace the texture of your geometry, don't really know if thats you want.

Upvotes: 1

Related Questions