Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript - Interactive 3D

New Here ,
Jun 30, 2025 Jun 30, 2025

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 !

TOPICS
How to , JavaScript , Modern Acrobat , PDF
283
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2025 Jun 30, 2025

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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2025 Jul 01, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2025 Jul 01, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2025 Jul 01, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 2025

Without seeing the file it's very hard to help you with this issue.

 

Also, you can't include emojis in your alerts. Only plain-text characters.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 2025

The function name is "getAnnot3D", no "s".

Here's the reference entry:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#getannot3d

 

This function is meant to be run from the document context. For example, a button on the PDF. It also has two input parameters, the page number and the annot name. I suspect that both are required since the return value is the 3d annotation object.  

 

You're code looks reasonable, i.e., there are no obvious syntax or structure errors and it follows the pattern I rember from when I was doing 3d programming in PDF.  However,  the JS model has be revamped since that time, so I couldn't comment on the specifics.  

 

3D scripting is a highly specialized topic and requires spending some time learning the details. That said, your code might just work as is, once you fix the function name. 

 

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 2025
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 2025

That is correct. Missed it in the Ref. 

However, if it's "undefined", then it is not being run from the document context. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2025 Jul 02, 2025

Ok thanks for the help guys, I'll try my best.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2025 Jul 02, 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2025 Jul 02, 2025
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines