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

Javascript to color a specific part of a 3D object

New Here ,
Apr 24, 2017 Apr 24, 2017

Copy link to clipboard

Copied

Hi,

I have a 3D pdf, which icludes a large 3D cube. This large cube is made by 125 small cubes. (5x5x5) I have 3 dropdown menus which allows user to enter 3 coordinate values (x,y,z) from 1 to 5. Now I need to color the cube which has the coordinates equal to the user inputs. (eg: When user enters 1,1,1  the cube at the origin need to get a certain color (I prefer red).

How can I do that? I can't figure out how to access those small cubes by javascipt.

Can someone please help me?

TOPICS
Rich media and 3D

Views

1.4K

Translate

Translate

Report

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 ,
Apr 24, 2017 Apr 24, 2017

Copy link to clipboard

Copied

Can you share the PDF? I'll need to look at the model tree to be of any assistance.

Votes

Translate

Translate

Report

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 ,
Apr 24, 2017 Apr 24, 2017

Copy link to clipboard

Copied

Hi Joel_Geraci​ My client do not allows me to publish his file. Do you have any general instruction to howto access the coordinates of a 3D object by javascript?

and how to add the script to the file? in general way we doing in pdf form or any other method?

I'm new to 3D pdfs. Could you please help me?

Votes

Translate

Translate

Report

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 ,
Apr 24, 2017 Apr 24, 2017

Copy link to clipboard

Copied

Generally, you can't get a mesh given a set of coordinates because JavaScript only knows about the bounding box, the shape will be somewhere inside it but JavaScript can't tell you if you're actually inside or on the surface of the shape itself. The MouseEvent has a hit test that will tell you what, if anything, it hit but that's not what you're asking for.

Because all of your meshes will be cubes and the mesh bounding box and the cube dimensions should be identical, you should be able to figure out what mesh corresponds to what cube fairly easily.

From there, you just need to get the mesh either by index or by name and then set the color using an RGB value. You'll probably also want to set the transparency level of all the other cubes to something you can see the highlighted cube through.

The script get's added via the Insert 3D dialog... see the file selector at the bottom under script.

3D.png

If none of that makes sense to you, you may be over your head. 3D JavaScript for Acrobat is non-trivial, poorly documented, and there are not a lot of samples out there to infer how to do things. The task as you describe it would be challenging for me and I've been working with 3D PDF for over a decade.

That said, the easiest thing to do is to simply ignore the relationship between the model space coordinates and the coordinates requested by the user. Instead create a lookup table of X,Y,Z combinations and the corresponding mesh name of the cube it represents. When a user selects a certain combination, you select the corresponding mesh by name and color it. Super easy, super efficient, no spacial math involved.

Votes

Translate

Translate

Report

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 ,
Apr 26, 2017 Apr 26, 2017

Copy link to clipboard

Copied

Hi Joel,

Your idea is very interesting. Could you please give me the javascript code to access a small cube?

Names of cubes are named as Block1, Block2.... like this.

Also please help me with the code to color the relevant cube.

Thank you

Votes

Translate

Translate

Report

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 ,
Apr 26, 2017 Apr 26, 2017

Copy link to clipboard

Copied

I'd need to know the exact mesh names to give you code that would color it. I'd really need to look at the model tree; I doubt that the full mesh name is "Block1" etc. I don't quite understand what is so proprietary about a 5x5x5 cube that the PDF can't be shared.

Votes

Translate

Translate

Report

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 ,
Jan 03, 2020 Jan 03, 2020

Copy link to clipboard

Copied

LATEST

3D JavaScript for Acrobat is non-trivial, poorly documented

 

Is there any desire to make it more accessible? Since out of the box, customisation possibilities of 3D PDFs is quite poor really.

Votes

Translate

Translate

Report

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
Explorer ,
May 02, 2017 May 02, 2017

Copy link to clipboard

Copied

There are a couple of tools that you can use to edit the color of 3D objects in a 3D PDF. Using Tetra4D Converter/Reviewer you can edit the colors of the objects and save the changes back to the PDF. Or, you can use 3D PDF Pro Acrobat Plugin to make the changes in 3D model of the 3D PDF document.

Votes

Translate

Translate

Report

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