gkjohnson/three-bvh-csg

Result object of csg evaluator doesn't have textures

pceeee opened this issue · 8 comments

Hi, my mesh "sportello" has a texture, but "resultObject" takes only the primary color from the texture, is it possibile to apply the texture to the result of the csg evaluator?
I have tried applying the texture directly to "resultObject" using the map: texture or material.map = texture, but i get the same result.

    if ( needsUpdate ) {

        needsUpdate = false;

        sportello.updateMatrixWorld();
        foro.updateMatrixWorld();
        foro2.updateMatrixWorld();
        foro3.updateMatrixWorld();
        foro4.updateMatrixWorld();
        divisore.updateMatrixWorld();

	let finalBrush = brushes[0];
        csgEvaluator.useGroups = params.useGroups;
        csgEvaluator.consolidateGroups = params.consolidateGroups;
		
	for (let i = 1, l = brushes.length; i < l; i++) {
		  const b = brushes[i];
		  finalBrush = csgEvaluator.evaluate(finalBrush, b, ADDITION);
		  finalBrush.material = foro.material;
	}
	csgEvaluator.evaluate(sportello, finalBrush, params.operation, resultObject);
		
        resultObject.material = materialMap.get(sportello.material);

        if ( enableDebugTelemetry ) {

            edgesHelper.setEdges( csgEvaluator.debug.intersectionEdges );

            trisHelper.setTriangles( [
                ...csgEvaluator.debug.triangleIntersectsA.getTrianglesAsArray(),
                ...csgEvaluator.debug.triangleIntersectsA.getIntersectionsAsArray()
            ] );

        }
    }

Please provide a live example of what you're having issues with.

The "resultObject" should have the material of the borders, but it seems that only the primary color from the texture is being taken

Screenshot 2024-02-12 alle 09 35 24
Screenshot 2024-02-12 alle 09 35 43
Screenshot 2024-02-12 alle 09 35 51
Screenshot 2024-02-12 alle 09 35 57

This is not a live example. Please make an editable example using jsfiddle, codesandbox, etc.

Your demo page does not work. Have you tested it? I'm happy to take a look but I'm not planning to spend my time fixing your broken demonstration code just so I can understand your issue. If you'd like help you need to make an effort to provide a live, working demonstration that shows your problem, as I've asked for twice now.

Sorry for the inconvenience, the preview it's working now.

https://jsfiddle.net/lmigani/52afyg7z/3/

You're removing the UVs from the result which are needed for textures. Make sure the UVs are included:

    csgEvaluator.attributes = [ 'position', 'normal' ]; // make sure "uv" is included in the set of attributes

Thank you very much