I’m trying to implement an event that triggers when you click a gui button. Here is my code below which is currently only in HTML:
scene.onPointerDown = function(evt, pickResult) {
if (pickResult.hit) {
console.log("pickResult.hit: " + pickResult.pickedMesh.name);
if (meshContent[pickResult.pickedMesh.name]) {
console.log(“In the list”); // YES! Our mesh is in the list (ground is not there)
How can I change PointerDown to be doubletap or similar so that you have to double click the mouse for the button trigger the event. I’ve seen the playground below but I struggle implementing this into my code with my knowledge:
Hi, Yes, I also had a look at this page too. So how would I change my code to incorporate this functionality? bearing in mind I’m not the best coder, do I swap OnPointerDown with something in here? or am I way off the mark (code below from that link you shared):
//add PointerClickObservable to distinquish between single and double click
button.onPointerClickObservable.add(() => {
handleSingleDoubleClick();
});
advancedTexture.addControl(button);
//simple vanilla js double click implementation taken from
//https://stackoverflow.com/questions/5497073/how-to-differentiate-single-click-event-and-double-click-event
var count = 0;
function handleSingleDoubleClick() {
if (!count) setTimeout(TimerFcn, 400); // 400 ms click delay
count += 1;
}
function TimerFcn() {
if (count > 1) console.log('you double clicked!')
else console.log('you single clicked')
count = 0;
}
scene.onPointerClickObserbable = function(evt, pickResult) {
if (pickResult.hit) {
console.log("pickResult.hit: " + pickResult.pickedMesh.name);
if (meshContent[pickResult.pickedMesh.name]) {
console.log(“In the list”); // YES! Our mesh is in the list (ground is not there)
I’m not sure it’s as easy as plugging that line in as I’m only looking to validate the click if it was a double click. Any chance you could give me a steer with the code? I can see if I can add a playground I used.
This is a playground I created with the onpointerdown. the text box appears when you single click on the building. I’ve tried the above and can’t get it to work as I don’t have a button but rather 100’s of different buildings in my main file all with different names.
You’re right I probably wasn’t too clear. I have buildings / mesh’s in my playground/website and I want to be able to double click them, rather than single click them for the pop-up / text box to appear. As per my playground, it’s relatively similar to my website version, however, in the website a pop-up window appears. If someone could help me understand how the double click works in the playground I shared when clicking on the mesh, that would really help me implement it on to my website.
Thanks Raananw. The text box doesn’t appear to be showing up if I double click however. If you check the first playground I shared, it appears on a single click of the building/mesh. The code is quite old and I’ve improved it on other playgrounds
Thank you that works great Just one final thing, and you will hate me for this no doubt, the code is slightly different in HTML I thought it would be an easy transfer over but there’s differences in the approach to the code I think.
scene.onPointerDown = function(evt, pickResult) {
if (pickResult.hit) {
console.log("pickResult.hit: " + pickResult.pickedMesh.name);
if (meshContent[pickResult.pickedMesh.name]) {
console.log("In the list"); // YES! Our mesh is in the list (ground is not there)
toggleModal(); // If there was no modal before, it will be shown; it there was modal already, it will be invisible
console.log("Mesh: " + pickResult.pickedMesh.name + "; Content: " + meshContent[pickResult.pickedMesh.name]);
document.getElementById("modal-iframe").innerHTML = "<iframe src=\"https://"+meshContent[pickResult.pickedMesh.name] + "\" title=\"Modal\"frameborder=\"0\" style=\"overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:40px;left:0px;right:0px;bottom:0px\" height=\"100%\" width=\"100%\"></iframe>"
}
}
}
It’s for my website, I’ve got a larger city model and currently that code works to load popup window upon single clicking a building. The only thing is, with 600 buildings in my main scene, single clicks are easy to do and pop ups appear all over the place
That HTML is my main code and the playgrounds I just use for different elements of testing. I’ll see if I can get my head around transferring the playground code into how it currently works HTML. There’s a difference in naming conventions which is confusing me.