Skip to main content
Participant
June 30, 2025
Question

Javascript - Interactive 3D

  • June 30, 2025
  • 3 replies
  • 690 views

Hey guys, I'm new with adobe and I have a project that I need help with. My goal is to have a PDF with a 3D model of an object and each surface would be clickable. When you click on a surface, I want an instruction pannel to pop up. I already have my object with different surfaces that are clickable but I can't get to recognize surfaces and make a pannel appear when I click on one. I have a few scritps thanks to chatGPT but nohting is working.

 

Thanks !

3 replies

Participant
July 2, 2025

I have a question after going a bit through the manual, is it possible to detect a click on a 3D object in my pdf ? I can't see the function addEventHandler in the manual, thus I assume that it's not possible, but do you have any way to bypass the problem ?

Thom Parker
Community Expert
Community Expert
July 2, 2025

The answer is yes and no.  The 3D API is not well explained. Once you understand the overall structure of API it all makes sense, but you have to get there first. 

 

So all events are set through the "runtime" object, which is a standalone global object.  First create a MouseEvent handler and then use the runtime.addEventHandler function to add it.  The Event handler object includes an OnEvent function that you add. This function is called anytime the user clicks the mouse on the 3D annotation.   The MouseEventHandler object provides a "target" property that reports the thing hit by the mouse.  

 

The runtime object is inside the 3D scripting context. If you add your script directly to the 3D annotation, then that script operates in the 3D scripting context.  But if your script is on a regular PDF form field button, then the script is operating in the Document context.  The 3D context is acquired using the "this.getAnnot3D().context3D".  The "this" keyword is always the current context, which is why "getAnnot3D" was undefined. It was being used in the wrong context. 

 

I'm an not crystal clear on all the details because I haven't done this in a very long time, but that's the basic method. 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 1, 2025

here is an example of a script I tried to put in my 3D :

// Réagit au clic sur une surface du modèle 3D
var annots = this.getAnnots3D(0);
if (annots != null) {
var context3D = annots[0].context3D;

context3D.runtime.setOnMouseDown(function(hit) {
if (!hit) return;

var nodeName = hit.getNode().name;
console.println("Objet cliqué : " + nodeName);

if (nodeName === "vis1") {
app.alert("⚙️ Ceci est une vis. Veuillez vérifier son serrage.");
} else if (nodeName === "panneau2") {
app.alert("📄 Ceci est un panneau de contrôle.");
}
});
}

I get an error that the function "this.getAnnots3D" is undefined

try67
Community Expert
Community Expert
July 1, 2025

The function is undefined? From where are you executing this code?

Participant
July 1, 2025

I understood that I was already in the 3D model thus this function couldn't work. However my 3D model dosen't have any children eventhough I have different objects in my tree model, so when I try to detect a surface with a click, no object is found.

Thom Parker
Community Expert
Community Expert
June 30, 2025

So, clue #1, Read the manual, don't use ChatGPT

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 1, 2025

I just want to know if anyone has already used a javascript with a 3D model on adobe.