Phi
Phi

Reputation: 157

Generating MDLMesh with crease support?

I’ve been able to create a MDLMesh and convert to SCNGeometry to render in SceneKit. But I haven’t been able to get crease support in my meshes or geometry.

I just wanted to verify that I’m taking the correct steps to add crease support for my mesh.

  1. Create MDLSubmeshTopology
  2. For the new topology object assign MDLMeshBuffers to edgeCreaseIndices, edgeCreases and Int to edgeCreaseCount properties.
  3. Create MDLSubmesh with topology object.

I’m not looking for specific solutions, just a general idea of how one would go about adding crease support to a mesh. Anyone with experience on this would be great.

Upvotes: 2

Views: 539

Answers (2)

Nick Porcino
Nick Porcino

Reputation: 61

The following should work, assuming you've prepared the data as edge pairs of four byte integers, and the crease values as floats.

    geometry.edgeCreasesSource = [SCNGeometrySource geometrySourceWithData:ecsData
                                                         semantic:SCNGeometrySourceSemanticEdgeCrease
                                                      vectorCount:creaseCount
                                                  floatComponents:YES
                                              componentsPerVector:1
                                                bytesPerComponent:4
                                                       dataOffset:0
                                                       dataStride:sizeof(float)];
    geometry.edgeCreasesElement = [SCNGeometryElement geometryElementWithData:eceData
                                                       primitiveType:SCNGeometryPrimitiveTypeLine
                                                      primitiveCount:creaseCount
                                                       bytesPerIndex:4];

Upvotes: 1

mnuages
mnuages

Reputation: 13462

SceneKit has edgeCreasesElement and edgeCreasesSource as well as the vertexCrease semantic.

You can take a look at the documentation for SCNGeometry.subdivisionLevel for more information.

Upvotes: 2

Related Questions