To display mesh1 on top of mesh 2 where the z of mesh1 is more than the z of mesh 2

Hello, I have the surface plot created i need to display the 3d group mesh that i created to display on he top the surface mesh. Means like the 3d group is behind the surface but the visibility of mesh should be on top of surface how can I do that.here is my js code
import * as THREE from ‘…/modules/three.module.js’
import { OrbitControls } from “…/modules/OrbitControls.js”;
import { FontLoader } from ‘…/modules/FontLoader.js’;
import { TextGeometry } from ‘…/modules/TextGeometry.js’;
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 50);
var renderer = new THREE.WebGLRenderer({ antialias: true, resolution: window.devicePixelRatio, alpha: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
scene.rotation.x = -Math.PI / 2.4;
scene.rotation.z = Math.PI / 5.5;
let controls = new OrbitControls(camera, renderer.domElement);
var axesGroup = new THREE.Group();
scene.add(axesGroup)
var point = [[0, -20, 0], [0, 20, 0]];
var line = new MeshLine();
line.setPoints(point.flat());
var mat = new MeshLineMaterial({ color: 0x0000ff, lineWidth: 0.2, dashArray: 0.02, dashRatio: 0.1 });
mat.transparent = true
var line = new THREE.Mesh(line, mat);
line.name = “line”
line.visible = false;
scene.add(line);
var textGroup = new THREE.Group();
scene.add(textGroup)
var toolTipMesh = new THREE.Group();
toolTipMesh.name = “ToolTip”
toolTipMesh.rendererOrder = 10000
scene.add(toolTipMesh)
class Main{
createSurface() {
var times = data.timestamps;
this.time = Object.keys(times);
var harmonics = times[this.time[0]];
this.freq = ;
this.amp = ;
for (let i = 0; i < harmonics.length; i++) {
this.freq.push(harmonics[i].frequency);
this.amp.push(harmonics[i].amplitude);
}
this.fmax = Math.max(…this.freq)
this.fmin = Math.min(…this.freq)
this.amax = Math.max(…this.amp)
this.amin = Math.min(…this.amp)
this.yScale = d3.scaleBand().domain(this.time).range([20, -20])
this.xScale = d3.scaleLinear().domain([this.fmin, this.fmax]).range([-30, 30])
this.zScale = d3.scaleLinear().domain([this.amin, this.amax]).range([0.0562, 13])

            const points = [];
            for (let i = this.time.length - 1; i >= 0; i--) {
                for (let j = 0; j < this.freq.length; j++) {
                    points.push(this.xScale(this.freq[j]), this.yScale(this.time[i]), this.zScale(this.amp[j]))
                }
            }

            var widthsegments = this.freq.length;
            var heightsegments = this.time.length;
            var planeGeometry = new THREE.PlaneGeometry(60, 40, widthsegments - 1, heightsegments - 1);
            var positionAttribute = planeGeometry.attributes.position, l = positionAttribute.count;
            planeGeometry.setAttribute('position', new THREE.Float32BufferAttribute(points, 3));
            var planeMaterial = this.shader(planeGeometry);
            this.planeMesh = new THREE.Mesh(planeGeometry, planeMaterial);
            scene.add(this.planeMesh);
            animate()
        }
        shader(geometry) {
            geometry.computeBoundingBox();
            var color0 = "#a3a3fa";
            var color2 = "#ef7171";
            var color0 = "#1a1a62";
            var color2 = "#735757";
            var pos = `vPos.z/10.9+0.5`;
            var bgColor = 0xffffff;
            var bgColor = 0xe5e5e5;
            var bgColor = 0x000000;
            scene.background = new THREE.Color(bgColor);

            var material = new THREE.ShaderMaterial({
                uniforms: {
                    color0: {
                        value: new THREE.Color(color0)
                    },
                    color2: {
                        value: new THREE.Color(color2)
                    },
                },
                side: THREE.DoubleSide,
                vertexShader: `
            uniform vec3 bboxMin;
            uniform vec3 bboxMax;

            varying vec3 vPos;

            void main() {
            vPos = position;
            gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
            }
        `,
                fragmentShader: `
            uniform vec3 color0;
            uniform vec3 color2;
            uniform vec3 color1;

            varying vec3 vPos;
            
            void main() {
                float depth = ${pos};
                gl_FragColor = vec4(mix(color0, color2, depth), 0.9);
            }
        `,
                wireframe: false,
            });
            return material
        }
    }
    var loader = new FontLoader();
    toolTipMesh.position.set(0, 20, 1);
    var box = new THREE.BoxGeometry(15, 0, 7);
    var boxMat = new THREE.MeshBasicMaterial({ color: "white", deptheTest: false })
    var boxMesh = new THREE.Mesh(box, boxMat)
    console.log(boxMesh);
    boxMesh.position.set(0, 0, 5);
    toolTipMesh.add(boxMesh);
    var x;
    var obj = new Main()
    loader.load('../fonts/Open Sans Semibold_Regular.json', (font) => {

        const extrudeSettings = {
            depth: 0.0,
            bevelEnabled: true,
            bevelEnabled: true,
            bevelThickness: 0.0,
            bevelSize: 0.006,
            bevelSegments: 2
        };
        x = font;
        const textMaterial = new THREE.MeshBasicMaterial({ color: "red" });
        const ampShape = font.generateShapes('Amplitude:', 0.5);
        var ampText = new TextGeometry("Amplitude:", { font: font, size: 0.9, height: 0 })
        var amplitudeToolTip = new THREE.Mesh(ampText, textMaterial);
        amplitudeToolTip.rotation.x = Math.PI / 2
        amplitudeToolTip.position.set(-7.0, -0.1, 4.5)
        toolTipMesh.add(amplitudeToolTip);
        const freqShape = font.generateShapes('Frequency:', 0.9);
        const freqText = new THREE.ExtrudeGeometry(freqShape, extrudeSettings);
        var frequencyToolTip = new THREE.Mesh(freqText, textMaterial);
        frequencyToolTip.rotation.x = Math.PI / 2
        frequencyToolTip.position.set(-7.0, -0.1, 6.5)
        toolTipMesh.add(frequencyToolTip);
        boxMesh.renderOrder = 0
        boxMesh.material.depthTest = true
        frequencyToolTip.renderOrder = 1
        frequencyToolTip.material.depthTest = true;
        const differenceShape = font.generateShapes('Difference(%):', 0.9);
        const differenceText = new THREE.ExtrudeGeometry(differenceShape, extrudeSettings);
        var differenceToolTip = new THREE.Mesh(differenceText, textMaterial);
        differenceToolTip.rotation.x = Math.PI / 2
        differenceToolTip.position.set(-7.0, -0.1, 2.5)
        toolTipMesh.add(differenceToolTip);
        obj.createSurface();
    });
    console.log(toolTipMesh);
    function animate() {
        controls.update()
        requestAnimationFrame(animate)
        renderer.render(scene, camera)
    }

(the data is huge so im unable to display it).

the z position should be same but it should be visible on top. can you help me with that

Try:
toolTipMesh.rendererOrder = -1;

No its not working.

material.depthTest=false;
or
material.depthWrite=false;

is that how magic spells work

1 Like

Thanx. Good movie.