nicklockwood/Euclid

Recommendation to make stencil work faster

chellem opened this issue · 8 comments

Hello @nicklockwood,

I've been using the stencil method, but seen a little slowness in it.

Can you help me with it ?

@chellem sure, can you share the code you are using?

@chellem also, are you testing with -O (optimize for speed)? because Euclid is much slower in debug mode.

hi @nicklockwood,

I don't have any -O passed.

The code am using is as follows:

cube = Mesh.cube(center: center, size: size, faces: .front, material: getMaterial())
let geometry = SCNGeometry(mesh.stencil(cube!))

The variables have nothing special with them. except that the 3d model am working with is within a bounding box of 426 x 676 x 180. Do you think reducing might help ?

@nicklockwood, why stencil an image on my model give me something like that. How to avoid it ?

image

@chellem for the slowness issue, I believe this is due to testing in debug mode. I think it will be fine if you run in release mode, but you can test this by ensuring the Euclid target is using -O for optimization level in the build settings.

@chellem for the stencil issue, it looks like you are still trying to apply the texture from your cube to the T-shirt model. This isn't the intended purpose of stencil - it is for use with vector shapes made from a CGPath and not textured shapes.

OK got it, then how can I accomplish this result without stencil ?

@chellem Euclid doesn't currently have a feature for doing this. The best option is to compose your texture in 2D instead using CoreGraphics.

Basically, take the existing T-shirt texture image, draw the logo into it in 2D using CGContext, then replace the texture.