nicklockwood / Euclid

A Swift library for creating and manipulating 3D geometry
MIT License
644 stars 53 forks source link

Multiple Materials for Individual Faces in SCNGeometry Converted from Mesh #121

Closed Theophania closed 7 months ago

Theophania commented 8 months ago

Hello,

my goal is to assign different materials to individual faces of a resulting SCNGeometry. From what I've tried, I can only associate a single material with the entire Mesh, leading to SCNGeometry always being created with just one element in its elements array.

Is there a recommended way within Euclid to assign multiple materials to a Mesh so that, upon conversion to SCNGeometry, it would contain a corresponding number of elements to support different materials for different faces? Thanks a lot!

nicklockwood commented 8 months ago

You can assign materials per polygon. Euclid can load meshes with multiple materials, or you can create them yourself e.g. by combining multiple meshes with different materials using CSG operations.

The cube in the example app demonstrates this - the resultant mesh has both a color and checkerboard texture material applied.

nicklockwood commented 8 months ago

Another way would be to grab the .polygons from the Mesh, set materials on them individually, and then create a new mesh from the updated polygons.

Theophania commented 7 months ago

Thanks a lot!

Another way would be to grab the .polygons from the Mesh, set materials on them individually, and then create a new mesh from the updated polygons.

Thanks for the help, this was the method I chose in the end.