Hi,
i have implemented the tooltip code in my project i can even see the tooltip when hovered on the object.but the issue is the tooltip box is appearing at the extreme right corner of the screen.
can someone suggest me how to get the box at the side of the selected object rather than the top right
below is the implemented code
function showTooltip() {
// var divElement = ".tooltip";
if (divElement && latestMouseProjection) {
divElement.css({
display: "block",
opacity: 0.0
});
var canvasHalfWidth = renderer.domElement.offsetWidth / 2;
var canvasHalfHeight = renderer.domElement.offsetHeight / 2;
var tooltipPosition = latestMouseProjection.clone().project(camera);
tooltipPosition.x = (tooltipPosition.x * canvasHalfWidth) + canvasHalfWidth + renderer.domElement.offsetLeft;
tooltipPosition.y = -(tooltipPosition.y * canvasHalfHeight) + canvasHalfHeight + renderer.domElement.offsetTop;
var tootipWidth = divElement[0].offsetWidth;
var tootipHeight = divElement[0].offsetHeight;
divElement.css({
left: '${tooltipPosition.x - tootipWidth/2}px',
top: '${tooltipPosition.y - tootipHeight - 5}px'
});
setTimeout(function() {
divElement.css({
opacity: 1.0
});
}, 25);
}
}
// This will immediately hide tooltip.
function hideTooltip() {
var divElement = $("#tooltip");
if (divElement) {
divElement.css({
display: "none"
});
}
}
// Following two functions will convert mouse coordinates
// from screen to three.js system (where [0,0] is in the middle of the screen)
//var datavalue = JSON.parse('json/zc_co_ordinate.json');
//console.log('datavalue' + datavalue);
function updateMouseCoords(event, coordsObj) {
coordsObj.x = ((event.clientX - renderer.domElement.offsetLeft + 0.5) / window.innerWidth) * 2 - 1;
coordsObj.y = -((event.clientY - renderer.domElement.offsetTop + 0.5) / window.innerHeight) * 2 + 1;
}
function handleManipulationUpdate() {
raycaster.setFromCamera(mouse, camera); {
// console.log('new' + tooltipEnabledObjects[0]);
var intersects = raycaster.intersectObjects(tooltipEnabledObjects);
if (intersects.length > 0) {
latestMouseProjection = intersects[0].point;
hoveredObj = intersects[0].object;
var adjustedheight = (2*intersects[0].object.position.y) - 0.2 ;
var adjustedwidth = intersects[0].object.position.z - ((intersects[0].object.geometry.parameters.depth) /2 ) ;
var adjustedlength = intersects[0].object.position.x - ((intersects[0].object.geometry.parameters.width) / 2 ) ;
var adjustedheight = adjustedheight / Scalingvalue ;
var adjustedwidth = adjustedwidth / Scalingvalue;
var adjustedlength = adjustedlength / Scalingvalue ;
divElement.text(hoveredObj.userData.tooltipText);
hoveredObj.userData.tooltipText = 'co-ordinates:(' + 'name' + intersects[0].object.name +','+ adjustedwidth +',' + adjustedheight +','+ adjustedlength+ ')';
}
}
if (tooltipDisplayTimeout || !latestMouseProjection) {
clearTimeout(tooltipDisplayTimeout);
tooltipDisplayTimeout = undefined;
hideTooltip();
}
if (!tooltipDisplayTimeout && latestMouseProjection) {
// console.log('hi');
tooltipDisplayTimeout = setTimeout(function() {
tooltipDisplayTimeout = undefined;
showTooltip();
}, 330);
}
}
function onMouseMove(event) {
updateMouseCoords(event, mouse);
latestMouseProjection = undefined;
hoveredObj = undefined;
handleManipulationUpdate();
}
window.addEventListener('mousemove', onMouseMove, false);