# Can I exert simple Three.js stencil-coloring while clipping a GLTF-object with coded mesh?

**URL:** <https://discourse.threejs.org/t/can-i-exert-simple-three-js-stencil-coloring-while-clipping-a-gltf-object-with-coded-mesh/73497>\
**Category:** Questions\
**Tags:** materials, geometry\
**Created:** [October 31, 2024, 6:28am UTC](https://discourse.threejs.org/t/can-i-exert-simple-three-js-stencil-coloring-while-clipping-a-gltf-object-with-coded-mesh/73497 "2024-10-31T06:28:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Due\_Nielsen](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/thomas_due_nielsen/32/11961_2.png) [@Thomas\_Due\_Nielsen](https://discourse.threejs.org/u/Thomas_Due_Nielsen)\
**Post date:** [October 31, 2024, 6:28am UTC](https://discourse.threejs.org/t/can-i-exert-simple-three-js-stencil-coloring-while-clipping-a-gltf-object-with-coded-mesh/73497/1 "2024-10-31T06:28:47Z")

</div>

While taking offset in this Three.js stencil example, …

[https://threejs.org/examples/?q=clip#webgl\_clipping\_stencil](https://threejs.org/examples/?q=clip#webgl_clipping_stencil)

- that uses a coded torus mesh, and clipping planes, I need to go a step further. As such I wish to expand my clipping-example, by means of a coded BoxGeometry, that clips GLTF.

Found this example:

> [@Stencil Clipping GLTF - Weird Backfaces](https://discourse.threejs.org/t/stencil-clipping-gltf-weird-backfaces/41936/3):
>
> Hmm that’s interesting, but I’m not getting flickering on the GLTF. It looks more like there is an issue with how it is being rendered. Here is a short video of the damaged helmet GLTF

- but it only shader-codes the clipping.

Have tried it a this link: [...](https://www.amfibios.dk/TJS_Renw/three.js-master/examples/occludeClip_StackOverflowQ.html) (click the three dots)  
Works - slide downwards to watch how.

The code to reproduce:

```
    const loader3 = new GLTFLoader().setPath( '.../TJS_Renw/three.js-master/examples/models/renw/' );
            mesh3 = new THREE.Object3D();
            loader3.load( 'DunkelFlaute_05_Cav.gltf', async function ( gltf ) {
            mesh3 = gltf.scene;

           const ldrU1 = genCubeUrls( 'textures/cube/pisa/', '.png' );
           new THREE.CubeTextureLoader().load( ldrU1, function ( ldrCubeMap ) {
                mesh3.traverse((node) => {
                  if (node.isMesh) {
                                  node.material = new THREE.MeshPhongMaterial({
                                        color: "#320", side: THREE.BackSide, transparent: false, roughness: 1.0, metalness: 0.0, depthTest: true, depthWrite: true, needsUpdate : true
                                  });
                            // node.material.envMap = ldrCubeMap;
                  }
                });
            });
             mesh3.renderOrder =2; scene.add( mesh3 ); mesh3.scale.set(5.3,5.3,5.3); 
             mesh3.translateY(0.3);
          } );

        var material4 = new THREE.MeshPhongMaterial();
                        var geometry = new THREE.BoxGeometry( 1, 6, 1 );
          meshBOC = new THREE.Mesh( geometry, material4.clone() );
          meshBOC.material.color.set( 0x0000ff );
          meshBOC.material.colorWrite = false; 
          meshBOC.renderOrder = 6;
          meshBOC.position.x = 0;
          meshBOC.position.y = -3;
          meshBOC.position.z = 0;
          scene.add( meshBOC );

```

I need a full moveable BoxGeometry to exert clipping. I am looking for a solution, that colors the area, where BoxGeometry clips imported GLTF-file.
