Copy link to clipboard
Copied
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 !
Copy link to clipboard
Copied
So, clue #1, Read the manual, don't use ChatGPT
Copy link to clipboard
Copied
I just want to know if anyone has already used a javascript with a 3D model on adobe.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
The function is undefined? From where are you executing this code?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The function name is "getAnnot3D", no "s".
Here's the reference entry:
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.
Copy link to clipboard
Copied
Both functions exist:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#getannots3d
Copy link to clipboard
Copied
That is correct. Missed it in the Ref.
However, if it's "undefined", then it is not being run from the document context.
Copy link to clipboard
Copied
Ok thanks for the help guys, I'll try my best.
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now