Skip to main content
Participant
April 8, 2025
Question

3D PDF showing CAD model with colored faces: Extract RGB values of faces‘ colors using JavaScript

  • April 8, 2025
  • 1 reply
  • 191 views

Hi everyone,

 

I have a 3D PDF which was created from a CATIA model. The model itself is one single body with one color property which' RGB value is 210/210/255.

A few faces of this solid body however, have different colors. Let's say there is an area which is green (RGB 067/224/054) and another one brown (RGB 210/170/109).

 

My goal is to call a function by a button which I created. The function is called get3DColors(). And the purpose is to analyze the diffuse colors of the 3D content and store them in an object for further processing. This is what I got so far:

 

var c3d = this.getAnnots3D(this.pageNum)[0].context3D;

 

function get3DColors() {
     var usedColors = {};

 

     for (var i = 0; i <= c3d.scene.meshes.count; i++) {
          var mesh = c3d.scene.meshes.getByIndex(i);

 

          var r = Math.round(mesh.material.diffuseColor.r * 256);

          var g = Math.round(mesh.material.diffuseColor.g * 256);

          var b = Math.round(mesh.material.diffuseColor.b * 256);

 

          var colorString = r + "/" + g + "/" + b;

 

          if (!usedColors[colorString]) {
               console.println(colorString);

               usedColors[colorString] = true;

          }
     }
}

get3DColors();

 

Now the color of the body is being printed correctly as "210/210/255". But the colors of the faces are not accessed by the mesh.material.diffuseColor.

I figured that the color property of the faces must be stored somewhere else in the 3D object. But neither in the community nor in the documentation I could find any answers how to access surface colors.

 

Can anyone help?

 

P.S. my daily business is not coding. I learned some JavaScript and C# basics in university back in the days but don't know exactly what I'm doing. I try to find my way using Google Gemini and threads in the acrobat community. 

1 reply

JR Boulay
Community Expert
Community Expert
April 14, 2025

[MOVED TO THE ACROBAT DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe