gkjohnson / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
MIT License
601 stars 46 forks source link

Result object of csg evaluator doesn't have textures #201

Closed pceeee closed 7 months ago

pceeee commented 7 months ago

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()
            ] );

        }
    }
gkjohnson commented 7 months ago

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

pceeee commented 7 months ago

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

gkjohnson commented 7 months ago

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

pceeee commented 7 months ago

https://jsfiddle.net/lmigani/bthp50v7/38/

The project base was this: https://gkjohnson.github.io/three-bvh-csg/examples/bundle/simple.html

Texture: wood

gkjohnson commented 7 months ago

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.

pceeee commented 7 months ago

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

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

gkjohnson commented 7 months ago

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
pceeee commented 7 months ago

Thank you very much